Skip to content

Commit 24a4c00

Browse files
committed
chore: improved program deployments
1 parent dccde22 commit 24a4c00

5 files changed

Lines changed: 60 additions & 57 deletions

File tree

typescript/aleo-sdk/scripts/generate-artifacts.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ export const programRegistry: Record<string, string> = {
7676
validator_announce,
7777
};
7878
79-
export function loadProgramsInDeployOrder(programName: string): Program[] {
79+
export function loadProgramsInDeployOrder(
80+
programName: string,
81+
coreSalt: string,
82+
warpSalt?: string,
83+
): { id: string, program: string }[] {
8084
const visited = new Set<string>();
8185
const programs: Program[] = [];
8286
@@ -98,7 +102,20 @@ export function loadProgramsInDeployOrder(programName: string): Program[] {
98102
}
99103
100104
visit(programName);
101-
return programs;
105+
106+
return programs.map((p) => ({
107+
id: p.id(),
108+
program: p
109+
.toString()
110+
.replaceAll(
111+
/(mailbox|dispatch_proxy|validator_announce).aleo/g,
112+
(_, p1) => \`\${p1}_\${coreSalt}.aleo\`,
113+
)
114+
.replaceAll(
115+
/(hyp_native|hyp_collateral|hyp_synthetic).aleo/g,
116+
(_, p1) => \`\${p1}_\${warpSalt || coreSalt}.aleo\`,
117+
),
118+
}));
102119
}
103120
`;
104121

typescript/aleo-sdk/src/artifacts.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export const programRegistry: Record<string, string> = {
2424
validator_announce,
2525
};
2626

27-
export function loadProgramsInDeployOrder(programName: string): Program[] {
27+
export function loadProgramsInDeployOrder(
28+
programName: string,
29+
coreSalt: string,
30+
warpSalt?: string,
31+
): { id: string; program: string }[] {
2832
const visited = new Set<string>();
2933
const programs: Program[] = [];
3034

@@ -46,5 +50,18 @@ export function loadProgramsInDeployOrder(programName: string): Program[] {
4650
}
4751

4852
visit(programName);
49-
return programs;
53+
54+
return programs.map((p) => ({
55+
id: p.id(),
56+
program: p
57+
.toString()
58+
.replaceAll(
59+
/(mailbox|dispatch_proxy|validator_announce).aleo/g,
60+
(_, p1) => `${p1}_${coreSalt}.aleo`,
61+
)
62+
.replaceAll(
63+
/(hyp_native|hyp_collateral|hyp_synthetic).aleo/g,
64+
(_, p1) => `${p1}_${warpSalt || coreSalt}.aleo`,
65+
),
66+
}));
5067
}

typescript/aleo-sdk/src/clients/base.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export class AleoBase {
5858
: new AleoMainnetNetworkClient(rpcUrls[0]);
5959
}
6060

61-
protected get Program() {
62-
return this.chainId ? TestnetProgram : MainnetProgram;
63-
}
64-
6561
protected get Plaintext() {
6662
return this.chainId ? TestnetPlaintext : MainnetPlaintext;
6763
}

typescript/aleo-sdk/src/clients/signer.ts

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,27 @@ export class AleoSigner
4242
coreSalt: string,
4343
warpSalt?: string,
4444
): Promise<string[]> {
45-
let programs = loadProgramsInDeployOrder(programName);
46-
47-
programs = programs.map((p) => {
48-
return this.Program.fromString(
49-
p
50-
.toString()
51-
.replaceAll(
52-
/(mailbox|dispatch_proxy|validator_announce)\.aleo/g,
53-
(_, p1) => `${p1}_${coreSalt}.aleo`,
54-
)
55-
.replaceAll(
56-
/(hyp_native|hyp_collateral|hyp_synthetic)\.aleo/g,
57-
(_, p1) => `${p1}_${warpSalt || coreSalt}.aleo`,
58-
),
59-
);
60-
});
61-
62-
for (const program of programs) {
63-
const isDeployed = await this.isProgramDeployed(program.id());
64-
65-
// if the program is already deployed (which can be the case for some imports)
66-
// we simply skip it
67-
if (isDeployed) {
68-
continue;
45+
const programs = loadProgramsInDeployOrder(programName, coreSalt, warpSalt);
46+
47+
for (const { id, program } of programs) {
48+
try {
49+
const txId = await this.programManager.deploy(program, 0, false);
50+
51+
await this.aleoClient.waitForTransactionConfirmation(txId);
52+
} catch (err) {
53+
if (
54+
err instanceof Error &&
55+
err.message ===
56+
`Error validating program: Program ${id} already exists on the network, please rename your program`
57+
) {
58+
continue;
59+
}
60+
61+
throw err;
6962
}
70-
71-
const txId = await this.programManager.deploy(
72-
program.toString(),
73-
0,
74-
false,
75-
);
76-
77-
await this.aleoClient.waitForTransactionConfirmation(txId);
7863
}
7964

80-
return programs.map((p) => p.id());
65+
return programs.map((p) => p.id);
8166
}
8267

8368
getSignerAddress(): string {
@@ -109,15 +94,6 @@ export class AleoSigner
10994

11095
// ### TX CORE ###
11196

112-
private async isProgramDeployed(program: string) {
113-
try {
114-
await this.aleoClient.getProgram(program);
115-
return true;
116-
} catch {
117-
return false;
118-
}
119-
}
120-
12197
async createMailbox(
12298
req: Omit<AltVM.ReqCreateMailbox, 'signer'>,
12399
): Promise<AltVM.ResCreateMailbox> {

typescript/aleo-sdk/src/deploy.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ const main = async () => {
2626
});
2727
console.log('signer credits balance: ', balance);
2828

29-
// const { mailboxAddress } = await signer.createMailbox({
30-
// domainId: 1337,
31-
// defaultIsmAddress: '',
32-
// });
33-
// console.log('mailboxAddress', mailboxAddress);
34-
35-
const mailboxAddress = 'mailbox_ympq4slu6xiq.aleo';
29+
const { mailboxAddress } = await signer.createMailbox({
30+
domainId: 1337,
31+
});
32+
console.log('mailboxAddress', mailboxAddress);
3633

3734
const { tokenAddress } = await signer.createSyntheticToken({
3835
mailboxAddress,

0 commit comments

Comments
 (0)