1- import { waitForPXE , getContractInstanceFromInstantiationParams , Fr , ContractInstanceWithAddress , AztecAddress , SponsoredFeePaymentMethod , createAztecNodeClient , Fq } from "@aztec/aztec.js" ;
1+ import { Fr , GrumpkinScalar } from "@aztec/aztec.js/fields" ;
2+ import { getContractInstanceFromInstantiationParams } from "@aztec/aztec.js/contracts" ;
3+ import { ContractInstanceWithAddress } from "@aztec/stdlib/contract" ;
4+ import { AztecAddress } from "@aztec/stdlib/aztec-address" ;
5+ import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing" ;
6+ import { createAztecNodeClient } from "@aztec/aztec.js/node" ;
27import { TokenContract } from "@aztec/noir-contracts.js/Token"
38import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js" ;
4- import { getSchnorrAccount } from "@aztec/accounts/schnorr" ;
59import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC" ;
6- import { createPXEService , getPXEServiceConfig } from ' @aztec/pxe/server' ;
7- import { createStore } from "@aztec/kv-store/lmdb"
10+ import { getPXEConfig } from " @aztec/pxe/config" ;
11+ import { createStore } from "@aztec/kv-store/lmdb"
812import { getEnv , getAztecNodeUrl } from "../config/config.js" ;
13+ import { TestWallet } from "@aztec/test-wallet/server" ;
914
1015const nodeUrl = getAztecNodeUrl ( ) ;
1116const node = createAztecNodeClient ( nodeUrl )
1217const l1Contracts = await node . getL1ContractAddresses ( ) ;
13- const config = getPXEServiceConfig ( )
18+ const config = getPXEConfig ( )
1419const fullConfig = { ...config , l1Contracts }
1520fullConfig . proverEnabled = getEnv ( ) !== 'sandbox' ;
1621
1722const store1 = await createStore ( 'pxe1' , {
1823 dataDirectory : 'store' ,
19- dataStoreMapSizeKB : 1e6 ,
24+ dataStoreMapSizeKb : 1e6 ,
2025} ) ;
2126
2227const store2 = await createStore ( 'pxe2' , {
2328 dataDirectory : 'store' ,
24- dataStoreMapSizeKB : 1e6 ,
29+ dataStoreMapSizeKb : 1e6 ,
2530} ) ;
2631
27- const setupPxe1 = async ( ) => {
28- const pxe = await createPXEService ( node , fullConfig , { store : store1 } ) ;
29- await waitForPXE ( pxe ) ;
30- return pxe ;
32+ const setupWallet1 = async ( ) => {
33+ return await TestWallet . create ( node , fullConfig , { store : store1 } ) ;
3134} ;
3235
33- const setupPxe2 = async ( ) => {
34- const pxe = await createPXEService ( node , fullConfig , { store : store2 } ) ;
35- await waitForPXE ( pxe ) ;
36- return pxe ;
36+ const setupWallet2 = async ( ) => {
37+ return await TestWallet . create ( node , fullConfig , { store : store2 } ) ;
3738} ;
3839
3940const L2_TOKEN_CONTRACT_SALT = Fr . random ( ) ;
@@ -56,49 +57,48 @@ export async function getL2TokenContractInstance(deployerAddress: any, ownerAzte
5657
5758async function main ( ) {
5859
59- const pxe1 = await setupPxe1 ( ) ;
60- const pxe2 = await setupPxe2 ( ) ;
60+ const wallet1 = await setupWallet1 ( ) ;
61+ const wallet2 = await setupWallet2 ( ) ;
6162 const sponsoredFPC = await getSponsoredFPCInstance ( ) ;
62- await pxe1 . registerContract ( { instance : sponsoredFPC , artifact : SponsoredFPCContract . artifact } ) ;
63- await pxe2 . registerContract ( { instance : sponsoredFPC , artifact : SponsoredFPCContract . artifact } ) ;
63+ await wallet1 . registerContract ( { instance : sponsoredFPC , artifact : SponsoredFPCContract . artifact } ) ;
64+ await wallet2 . registerContract ( { instance : sponsoredFPC , artifact : SponsoredFPCContract . artifact } ) ;
6465 const paymentMethod = new SponsoredFeePaymentMethod ( sponsoredFPC . address ) ;
6566 // deploy token contract
6667
6768 let secretKey = Fr . random ( ) ;
68- let signingKey = Fq . random ( ) ;
69+ let signingKey = GrumpkinScalar . random ( ) ;
6970 let salt = Fr . random ( ) ;
70- let schnorrAccount = await getSchnorrAccount ( pxe1 , secretKey , signingKey , salt ) ;
71- let tx = await schnorrAccount . deploy ( { fee : { paymentMethod } } ) . wait ( ) ;
72- let ownerWallet = await schnorrAccount . getWallet ( ) ;
73- let ownerAddress = ownerWallet . getAddress ( ) ;
74- const token = await TokenContract . deploy ( ownerWallet , ownerAddress , 'Clean USDC' , 'USDC' , 6 ) . send ( {
71+ let schnorrAccount = await wallet1 . createSchnorrAccount ( secretKey , salt , signingKey ) ;
72+ let tx = await ( await schnorrAccount . getDeployMethod ( ) ) . send ( { from : AztecAddress . ZERO , fee : { paymentMethod } } ) . wait ( ) ;
73+ let ownerAddress = schnorrAccount . address ;
74+ const token = await TokenContract . deploy ( wallet1 , ownerAddress , 'Clean USDC' , 'USDC' , 6 ) . send ( {
7575 from : ownerAddress ,
7676 contractAddressSalt : L2_TOKEN_CONTRACT_SALT ,
7777 fee : { paymentMethod }
7878 } ) . wait ( )
7979
8080 // setup account on 2nd pxe
8181
82- await pxe2 . registerSender ( ownerAddress )
82+ await wallet2 . registerSender ( ownerAddress )
8383
8484 let secretKey2 = Fr . random ( ) ;
85- let signingKey2 = Fq . random ( ) ;
85+ let signingKey2 = GrumpkinScalar . random ( ) ;
8686 let salt2 = Fr . random ( ) ;
87- let schnorrAccount2 = await getSchnorrAccount ( pxe2 , secretKey2 , signingKey2 , salt2 ) ;
87+ let schnorrAccount2 = await wallet2 . createSchnorrAccount ( secretKey2 , salt2 , signingKey2 ) ;
8888
8989 // deploy account on 2nd pxe
90- let tx2 = await schnorrAccount2 . deploy ( { fee : { paymentMethod } } ) . wait ( ) ;
91- let wallet2 = await schnorrAccount2 . getWallet ( ) ;
90+ let tx2 = await ( await schnorrAccount2 . getDeployMethod ( ) ) . send ( { from : AztecAddress . ZERO , fee : { paymentMethod } } ) . wait ( ) ;
91+ let wallet2Address = schnorrAccount2 . address ;
9292 await wallet2 . registerSender ( ownerAddress )
9393
9494 // mint to account on 2nd pxe
9595
96- const private_mint_tx = await token . contract . methods . mint_to_private ( schnorrAccount2 . getAddress ( ) , 100 ) . send ( {
96+ const private_mint_tx = await token . contract . methods . mint_to_private ( schnorrAccount2 . address , 100 ) . send ( {
9797 from : ownerAddress ,
9898 fee : { paymentMethod }
9999 } ) . wait ( )
100- console . log ( await pxe1 . getTxEffect ( private_mint_tx . txHash ) )
101- await token . contract . methods . mint_to_public ( schnorrAccount2 . getAddress ( ) , 100 ) . send ( {
100+ console . log ( await node . getTxEffect ( private_mint_tx . txHash ) )
101+ await token . contract . methods . mint_to_public ( schnorrAccount2 . address , 100 ) . send ( {
102102 from : ownerAddress ,
103103 fee : { paymentMethod }
104104 } ) . wait ( )
@@ -118,20 +118,20 @@ async function main() {
118118 )
119119
120120 await l2TokenContract . methods . sync_private_state ( ) . simulate ( {
121- from : wallet2 . getAddress ( )
121+ from : wallet2Address
122122 } )
123123
124- const notes = await pxe2 . getNotes ( { txHash : private_mint_tx . txHash , contractAddress : l2TokenContractInstance . address } ) ;
124+ const notes = await wallet2 . getNotes ( { contractAddress : l2TokenContractInstance . address } ) ;
125125 console . log ( notes )
126126
127127 // returns 0n
128- const balance = await l2TokenContract . methods . balance_of_private ( wallet2 . getAddress ( ) ) . simulate ( {
129- from : wallet2 . getAddress ( )
128+ const balance = await l2TokenContract . methods . balance_of_private ( wallet2Address ) . simulate ( {
129+ from : wallet2Address
130130 } )
131131 console . log ( "private balance should be 100" , balance )
132132 // errors
133- await l2TokenContract . methods . balance_of_public ( wallet2 . getAddress ( ) ) . simulate ( {
134- from : wallet2 . getAddress ( )
133+ await l2TokenContract . methods . balance_of_public ( wallet2Address ) . simulate ( {
134+ from : wallet2Address
135135 } )
136136
137137}
0 commit comments