55 Plaintext ,
66 Program ,
77 ProgramManager ,
8+ getOrInitConsensusVersionTestHeights ,
9+ initThreadPool ,
810} from '@provablehq/sdk' ;
911import { BigNumber } from 'bignumber.js' ;
1012
@@ -14,12 +16,8 @@ import { mailbox } from '../artifacts.js';
1416import { formatAddress , getMessageKey } from '../utils/helper.js' ;
1517import { AleoTransaction } from '../utils/types.js' ;
1618
17- // TODO: make denom in AltVM optional
18- // TODO: add remove destination gas config method in AltVM
19- // TODO: only allow domainId in createMailox in AltVM
20- // TODO: add createNoopHook method in AltVM
21- // TODO: add getTokenMetadata method in AltVM
22- // TODO: don't allow routes in create routing ism
19+ getOrInitConsensusVersionTestHeights ( '0,1,2,3,4,5,6,7,8,9,10' ) ;
20+ await initThreadPool ( ) ;
2321
2422export class AleoProvider implements AltVM . IProvider {
2523 protected readonly aleoClient : AleoNetworkClient ;
@@ -39,6 +37,16 @@ export class AleoProvider implements AltVM.IProvider {
3937 this . aleoClient = new AleoNetworkClient ( rpcUrls [ 0 ] ) ;
4038 }
4139
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
43+ return new BHP256 ( )
44+ . hash ( Plaintext . fromString ( address ) . toBitsLe ( ) )
45+ . toBytesLe ( )
46+ . reduce ( ( acc , b ) => acc + b . toString ( 16 ) . padStart ( 2 , '0' ) , '' )
47+ . slice ( 0 , 12 ) ;
48+ }
49+
4250 // ### QUERY BASE ###
4351
4452 async isHealthy ( ) {
@@ -120,7 +128,7 @@ export class AleoProvider implements AltVM.IProvider {
120128 let res ;
121129 try {
122130 res = await this . aleoClient . getProgramMappingPlaintext (
123- req . mailboxAddress ,
131+ `mailbox_ ${ this . getProgramSalt ( req . mailboxAddress ) } .aleo` ,
124132 'mailbox' ,
125133 'true' ,
126134 ) ;
@@ -584,7 +592,7 @@ export class AleoProvider implements AltVM.IProvider {
584592 req : AltVM . ReqCreateMailbox ,
585593 ) : Promise < AleoTransaction > {
586594 return {
587- programName : 'mailbox.aleo ' ,
595+ programName : '' ,
588596 functionName : 'init' ,
589597 priorityFee : 0 ,
590598 privateFee : false ,
@@ -596,7 +604,7 @@ export class AleoProvider implements AltVM.IProvider {
596604 req : AltVM . ReqSetDefaultIsm ,
597605 ) : Promise < AleoTransaction > {
598606 return {
599- programName : 'mailbox. aleo' ,
607+ programName : `mailbox_ ${ this . getProgramSalt ( req . mailboxAddress ) } . aleo` ,
600608 functionName : 'set_default_ism' ,
601609 priorityFee : 0 ,
602610 privateFee : false ,
@@ -608,7 +616,7 @@ export class AleoProvider implements AltVM.IProvider {
608616 req : AltVM . ReqSetDefaultHook ,
609617 ) : Promise < AleoTransaction > {
610618 return {
611- programName : 'mailbox. aleo' ,
619+ programName : `mailbox_ ${ this . getProgramSalt ( req . mailboxAddress ) } . aleo` ,
612620 functionName : 'set_default_hook' ,
613621 priorityFee : 0 ,
614622 privateFee : false ,
@@ -620,7 +628,7 @@ export class AleoProvider implements AltVM.IProvider {
620628 req : AltVM . ReqSetRequiredHook ,
621629 ) : Promise < AleoTransaction > {
622630 return {
623- programName : 'mailbox. aleo' ,
631+ programName : `mailbox_ ${ this . getProgramSalt ( req . mailboxAddress ) } . aleo` ,
624632 functionName : 'set_required_hook' ,
625633 priorityFee : 0 ,
626634 privateFee : false ,
@@ -632,7 +640,7 @@ export class AleoProvider implements AltVM.IProvider {
632640 req : AltVM . ReqSetMailboxOwner ,
633641 ) : Promise < AleoTransaction > {
634642 return {
635- programName : 'mailbox. aleo' ,
643+ programName : `mailbox_ ${ this . getProgramSalt ( req . mailboxAddress ) } . aleo` ,
636644 functionName : 'set_owner' ,
637645 priorityFee : 0 ,
638646 privateFee : false ,
@@ -743,15 +751,23 @@ export class AleoProvider implements AltVM.IProvider {
743751 }
744752
745753 async getCreateMerkleTreeHookTransaction (
746- _req : AltVM . ReqCreateMerkleTreeHook ,
754+ req : AltVM . ReqCreateMerkleTreeHook ,
747755 ) : Promise < AleoTransaction > {
748- // TODO: replace default mailbox id with real one
749756 return {
750757 programName : 'hook_manager.aleo' ,
751758 functionName : 'init_merkle_tree' ,
752759 priorityFee : 0 ,
753760 privateFee : false ,
754- inputs : [ Program . fromString ( mailbox ) . address ( ) . to_string ( ) ] ,
761+ inputs : [
762+ Program . fromString (
763+ mailbox . replaceAll (
764+ 'mailbox.aleo' ,
765+ `mailbox_${ this . getProgramSalt ( req . mailboxAddress ) } .aleo` ,
766+ ) ,
767+ )
768+ . address ( )
769+ . to_string ( ) ,
770+ ] ,
755771 } ;
756772 }
757773
@@ -803,12 +819,19 @@ export class AleoProvider implements AltVM.IProvider {
803819 } ) ;
804820
805821 return {
806- programName : 'validator_announce.aleo ' ,
822+ programName : '' ,
807823 functionName : 'init' ,
808824 priorityFee : 0 ,
809825 privateFee : false ,
810826 inputs : [
811- Program . fromString ( mailbox ) . address ( ) . to_string ( ) ,
827+ Program . fromString (
828+ mailbox . replaceAll (
829+ 'mailbox.aleo' ,
830+ `mailbox_${ this . getProgramSalt ( req . mailboxAddress ) } .aleo` ,
831+ ) ,
832+ )
833+ . address ( )
834+ . to_string ( ) ,
812835 `${ localDomain } u32` ,
813836 ] ,
814837 } ;
0 commit comments