Skip to content

Commit 477f0d9

Browse files
committed
chore: changed deploy ids
1 parent 1eaf564 commit 477f0d9

3 files changed

Lines changed: 55 additions & 81 deletions

File tree

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

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ export class AleoProvider implements AltVM.IProvider {
3737
this.aleoClient = new AleoNetworkClient(rpcUrls[0]);
3838
}
3939

40-
protected getProgramSalt(address: string): string {
41-
// get the program salt by hashing the address with bhp256 and take the first 12
42-
// characters from the hex hash
40+
protected getNewProgramSalt(): string {
4341
return new BHP256()
44-
.hash(Plaintext.fromString(address).toBitsLe())
42+
.hash(new Account().address().toBitsLe())
4543
.toBytesLe()
4644
.reduce((acc, b) => acc + b.toString(16).padStart(2, '0'), '')
4745
.slice(0, 12);
4846
}
4947

48+
protected getProgramSaltFromAddress(address: string): string {
49+
return address.split('_').at(-1) || '';
50+
}
51+
5052
// ### QUERY BASE ###
5153

5254
async isHealthy() {
@@ -67,7 +69,7 @@ export class AleoProvider implements AltVM.IProvider {
6769
const balanceKey = new BHP256()
6870
.hash(
6971
Plaintext.fromString(
70-
`{account: ${req.address},token_id: ${req.denom}}`,
72+
`{account: ${req.address},token_id:${req.denom}}`,
7173
).toBitsLe(),
7274
)
7375
.toString();
@@ -128,7 +130,7 @@ export class AleoProvider implements AltVM.IProvider {
128130
let res;
129131
try {
130132
res = await this.aleoClient.getProgramMappingPlaintext(
131-
`mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
133+
req.mailboxAddress,
132134
'mailbox',
133135
'true',
134136
);
@@ -162,9 +164,9 @@ export class AleoProvider implements AltVM.IProvider {
162164
const messageKey = getMessageKey(req.messageId);
163165

164166
const res = await this.aleoClient.getProgramMappingPlaintext(
165-
'mailbox.aleo',
167+
req.mailboxAddress,
166168
'deliveries',
167-
`{ id: [ ${messageKey[0].toString()}, ${messageKey[1].toString()} ]}`,
169+
`{id:[${messageKey[0].toString()},${messageKey[1].toString()}]}`,
168170
);
169171

170172
const obj = res.toObject();
@@ -373,7 +375,7 @@ export class AleoProvider implements AltVM.IProvider {
373375
const gasConfigKey = await this.aleoClient.getProgramMappingPlaintext(
374376
programId,
375377
'destination_gas_config_iter',
376-
`{ hook: ${req.hookAddress}, index: ${i}u32}`,
378+
`{hook:${req.hookAddress},index:${i}u32}`,
377379
);
378380

379381
const destinationGasConfig =
@@ -433,33 +435,6 @@ export class AleoProvider implements AltVM.IProvider {
433435

434436
// ### QUERY WARP ###
435437

436-
private async getTokenProgram(tokenAddress: string): Promise<Program> {
437-
try {
438-
const program = await this.aleoClient.getProgram(
439-
`hyp_native_${this.getProgramSalt(tokenAddress)}.aleo`,
440-
);
441-
return Program.fromString(program);
442-
} catch {}
443-
444-
try {
445-
const program = await this.aleoClient.getProgram(
446-
`hyp_collateral_${this.getProgramSalt(tokenAddress)}.aleo`,
447-
);
448-
return Program.fromString(program);
449-
} catch {}
450-
451-
try {
452-
const program = await this.aleoClient.getProgram(
453-
`hyp_synthetic_${this.getProgramSalt(tokenAddress)}.aleo`,
454-
);
455-
return Program.fromString(program);
456-
} catch {}
457-
458-
throw new Error(
459-
`Failed to get token program for token address ${tokenAddress}`,
460-
);
461-
}
462-
463438
private async getTokenMetadata(tokenId: string): Promise<{
464439
name: string;
465440
symbol: string;
@@ -485,8 +460,6 @@ export class AleoProvider implements AltVM.IProvider {
485460
}
486461

487462
async getToken(req: AltVM.ReqGetToken): Promise<AltVM.ResGetToken> {
488-
const tokenProgram = await this.getTokenProgram(req.tokenAddress);
489-
490463
const token = {
491464
address: req.tokenAddress,
492465
owner: '',
@@ -501,7 +474,7 @@ export class AleoProvider implements AltVM.IProvider {
501474

502475
try {
503476
const tokenMetadata = await this.aleoClient.getProgramMappingPlaintext(
504-
tokenProgram.id(),
477+
req.tokenAddress,
505478
'token_metadata',
506479
'true',
507480
);
@@ -530,7 +503,7 @@ export class AleoProvider implements AltVM.IProvider {
530503
break;
531504
}
532505
} catch {
533-
throw new Error(`Found no token for program: ${tokenProgram}`);
506+
throw new Error(`Found no token for address: ${req.tokenAddress}`);
534507
}
535508

536509
return token;
@@ -667,7 +640,7 @@ export class AleoProvider implements AltVM.IProvider {
667640
req: AltVM.ReqSetDefaultIsm,
668641
): Promise<AleoTransaction> {
669642
return {
670-
programName: `mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
643+
programName: req.mailboxAddress,
671644
functionName: 'set_default_ism',
672645
priorityFee: 0,
673646
privateFee: false,
@@ -679,7 +652,7 @@ export class AleoProvider implements AltVM.IProvider {
679652
req: AltVM.ReqSetDefaultHook,
680653
): Promise<AleoTransaction> {
681654
return {
682-
programName: `mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
655+
programName: req.mailboxAddress,
683656
functionName: 'set_default_hook',
684657
priorityFee: 0,
685658
privateFee: false,
@@ -691,7 +664,7 @@ export class AleoProvider implements AltVM.IProvider {
691664
req: AltVM.ReqSetRequiredHook,
692665
): Promise<AleoTransaction> {
693666
return {
694-
programName: `mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
667+
programName: req.mailboxAddress,
695668
functionName: 'set_required_hook',
696669
priorityFee: 0,
697670
privateFee: false,
@@ -703,7 +676,7 @@ export class AleoProvider implements AltVM.IProvider {
703676
req: AltVM.ReqSetMailboxOwner,
704677
): Promise<AleoTransaction> {
705678
return {
706-
programName: `mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
679+
programName: req.mailboxAddress,
707680
functionName: 'set_owner',
708681
priorityFee: 0,
709682
privateFee: false,
@@ -823,10 +796,7 @@ export class AleoProvider implements AltVM.IProvider {
823796
privateFee: false,
824797
inputs: [
825798
Program.fromString(
826-
mailbox.replaceAll(
827-
'mailbox.aleo',
828-
`mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
829-
),
799+
mailbox.replaceAll('mailbox.aleo', req.mailboxAddress),
830800
)
831801
.address()
832802
.to_string(),
@@ -888,10 +858,7 @@ export class AleoProvider implements AltVM.IProvider {
888858
privateFee: false,
889859
inputs: [
890860
Program.fromString(
891-
mailbox.replaceAll(
892-
'mailbox.aleo',
893-
`mailbox_${this.getProgramSalt(req.mailboxAddress)}.aleo`,
894-
),
861+
mailbox.replaceAll('mailbox.aleo', req.mailboxAddress),
895862
)
896863
.address()
897864
.to_string(),

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

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class AleoSigner
5555

5656
private async deployProgram(
5757
programName: string,
58-
coreAddress: string,
59-
warpAddress?: string,
60-
): Promise<Program> {
58+
coreSalt: string,
59+
warpSalt?: string,
60+
): Promise<Program[]> {
6161
let programs = loadProgramsInDeployOrder(programName);
6262

6363
programs = programs.map((p) => {
@@ -66,12 +66,11 @@ export class AleoSigner
6666
.toString()
6767
.replaceAll(
6868
/(mailbox|dispatch_proxy|validator_announce|hyp_synthetic)\.aleo/g,
69-
(_, p1) => `${p1}_${this.getProgramSalt(coreAddress)}.aleo`,
69+
(_, p1) => `${p1}_${coreSalt}.aleo`,
7070
)
7171
.replaceAll(
7272
/(hyp_native|hyp_collateral|hyp_synthetic)\.aleo/g,
73-
(_, p1) =>
74-
`${p1}_${this.getProgramSalt(warpAddress || coreAddress)}.aleo`,
73+
(_, p1) => `${p1}_${warpSalt || coreSalt}.aleo`,
7574
),
7675
);
7776
});
@@ -94,7 +93,7 @@ export class AleoSigner
9493
await this.aleoClient.waitForTransactionConfirmation(txId);
9594
}
9695

97-
return programs[programs.length - 1];
96+
return programs;
9897
}
9998

10099
getSignerAddress(): string {
@@ -138,26 +137,26 @@ export class AleoSigner
138137
async createMailbox(
139138
req: Omit<AltVM.ReqCreateMailbox, 'signer'>,
140139
): Promise<AltVM.ResCreateMailbox> {
141-
const mailboxAddress = new Account().address().to_string();
142-
const program = await this.deployProgram('dispatch_proxy', mailboxAddress);
140+
const mailboxSalt = this.getNewProgramSalt();
141+
const programs = await this.deployProgram('dispatch_proxy', mailboxSalt);
143142

144143
const tx = await this.getCreateMailboxTransaction({
145144
signer: this.getSignerAddress(),
146145
...req,
147146
});
148147

149-
const mailboxId = `mailbox_${this.getProgramSalt(mailboxAddress)}.aleo`;
150-
tx.programName = mailboxId;
148+
const mailboxAddress = programs[programs.length - 2].id();
149+
tx.programName = mailboxAddress;
151150

152151
const txId = await this.programManager.execute(tx);
153152
await this.aleoClient.waitForTransactionConfirmation(txId);
154153

155154
const setDispatchProxyTxId = await this.programManager.execute({
156-
programName: mailboxId,
155+
programName: mailboxAddress,
157156
functionName: 'set_dispatch_proxy',
158157
priorityFee: 0,
159158
privateFee: false,
160-
inputs: [program.id()],
159+
inputs: [programs[programs.length - 1].id()],
161160
});
162161
await this.aleoClient.waitForTransactionConfirmation(setDispatchProxyTxId);
163162

@@ -509,18 +508,19 @@ export class AleoSigner
509508
async createValidatorAnnounce(
510509
req: Omit<AltVM.ReqCreateValidatorAnnounce, 'signer'>,
511510
): Promise<AltVM.ResCreateValidatorAnnounce> {
512-
const validatorAnnounceId = new Account().address().to_string();
513-
const program = await this.deployProgram(
511+
const validatorAnnounceSalt = this.getNewProgramSalt();
512+
const programs = await this.deployProgram(
514513
'validator_announce',
515-
validatorAnnounceId,
514+
validatorAnnounceSalt,
516515
);
517516

518517
const tx = await this.getCreateValidatorAnnounceTransaction({
519518
signer: this.getSignerAddress(),
520519
...req,
521520
});
522521

523-
tx.programName = program.id();
522+
const validatorAnnounceId = programs[programs.length - 1].id();
523+
tx.programName = validatorAnnounceId;
524524

525525
const txId = await this.programManager.execute(tx);
526526
await this.aleoClient.waitForTransactionConfirmation(txId);
@@ -535,19 +535,22 @@ export class AleoSigner
535535
async createCollateralToken(
536536
req: Omit<AltVM.ReqCreateCollateralToken, 'signer'>,
537537
): Promise<AltVM.ResCreateCollateralToken> {
538-
const tokenAddress = new Account().address().to_string();
539-
const program = await this.deployProgram(
538+
const tokenSalt = this.getNewProgramSalt();
539+
const mailboxSalt = this.getProgramSaltFromAddress(req.mailboxAddress);
540+
541+
const programs = await this.deployProgram(
540542
'hyp_collateral',
541-
req.mailboxAddress,
542-
tokenAddress,
543+
mailboxSalt,
544+
tokenSalt,
543545
);
544546

545547
const tx = await this.getCreateCollateralTokenTransaction({
546548
signer: this.getSignerAddress(),
547549
...req,
548550
});
549551

550-
tx.programName = program.id();
552+
const tokenAddress = programs[programs.length - 1].id();
553+
tx.programName = tokenAddress;
551554

552555
const txId = await this.programManager.execute(tx);
553556
await this.aleoClient.waitForTransactionConfirmation(txId);
@@ -560,19 +563,22 @@ export class AleoSigner
560563
async createSyntheticToken(
561564
req: Omit<AltVM.ReqCreateSyntheticToken, 'signer'>,
562565
): Promise<AltVM.ResCreateSyntheticToken> {
563-
const tokenAddress = new Account().address().to_string();
564-
const program = await this.deployProgram(
566+
const tokenSalt = this.getNewProgramSalt();
567+
const mailboxSalt = this.getProgramSaltFromAddress(req.mailboxAddress);
568+
569+
const programs = await this.deployProgram(
565570
'hyp_synthetic',
566-
req.mailboxAddress,
567-
tokenAddress,
571+
mailboxSalt,
572+
tokenSalt,
568573
);
569574

570575
const tx = await this.getCreateSyntheticTokenTransaction({
571576
signer: this.getSignerAddress(),
572577
...req,
573578
});
574579

575-
tx.programName = program.id();
580+
const tokenAddress = programs[programs.length - 1].id();
581+
tx.programName = tokenAddress;
576582

577583
const txId = await this.programManager.execute(tx);
578584
await this.aleoClient.waitForTransactionConfirmation(txId);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// enforce order of test suites
22
// import './1_interchain_security.e2e-test.js';
3-
// import './2_core.e2e-test.js';
4-
import './3_post_dispatch.e2e-test';
3+
import './2_core.e2e-test.js';
4+
5+
// import './3_post_dispatch.e2e-test';

0 commit comments

Comments
 (0)