@@ -6,22 +6,21 @@ import { foundry } from 'viem/chains'
66import { mnemonicToAccount } from 'viem/accounts' ;
77import { FeeJuiceContract } from "@aztec/noir-contracts.js/FeeJuice" ;
88import { FPCContract } from "@aztec/noir-contracts.js/FPC" ;
9- import { EasyPrivateVotingContract } from "../src/artifacts/EasyPrivateVoting .js"
9+ import { PrivateVotingContract } from "../src/artifacts/PrivateVoting .js"
1010import { TokenContract } from "@aztec/noir-contracts.js/Token" ;
1111// TODO: replace with import from aztec.js when published
1212import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee/testing'
1313import { getDeployedSponsoredFPCAddress , getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js" ;
1414import { createEthereumChain , createExtendedL1Client } from "@aztec/ethereum" ;
1515import { deploySchnorrAccount } from "../src/utils/deploy_account.js" ;
1616import { setupPXE } from "../src/utils/setup_pxe.js" ;
17- import { createLogger , FeeJuicePaymentMethod , FeeJuicePaymentMethodWithClaim , Fr , L1FeeJuicePortalManager , Logger , PrivateFeePaymentMethod , PublicFeePaymentMethod , PXE } from '@aztec/aztec.js' ;
17+ import { createLogger , FeeJuicePaymentMethod , FeeJuicePaymentMethodWithClaim , Fq , Fr , L1FeeJuicePortalManager , Logger , PrivateFeePaymentMethod , PublicFeePaymentMethod , PXE } from '@aztec/aztec.js' ;
1818import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC' ;
1919import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice' ;
2020import { getSchnorrAccount } from '@aztec/accounts/schnorr' ;
21- import { deriveSigningKey } from '@aztec/stdlib/keys' ;
2221
2322const MNEMONIC = 'test test test test test test test test test test test junk' ;
24- const FEE_FUNDING_FOR_TESTER_ACCOUNT = 1000000000000000000n ;
23+ const FEE_FUNDING_FOR_TESTER_ACCOUNT = 1000000000000000000000n ;
2524
2625async function main ( ) {
2726
@@ -43,8 +42,9 @@ async function main() {
4342 const wallet1 = await account1 . getWallet ( ) ;
4443
4544 let secretKey = Fr . random ( ) ;
45+ let signingKey = Fq . random ( ) ;
4646 let salt = Fr . random ( ) ;
47- let account2 = await getSchnorrAccount ( pxe , secretKey , deriveSigningKey ( secretKey ) , salt ) ;
47+ let account2 = await getSchnorrAccount ( pxe , secretKey , signingKey , salt ) ;
4848 const wallet2 = await account2 . getWallet ( ) ;
4949 const feeJuiceRecipient = account2 . getAddress ( ) ;
5050
@@ -67,8 +67,14 @@ async function main() {
6767 const paymentMethod = new SponsoredFeePaymentMethod ( sponsoredFPC . address ) ;
6868
6969 // Two arbitrary txs to make the L1 message available on L2
70- const votingContract = await EasyPrivateVotingContract . deploy ( wallet1 , wallet1 . getAddress ( ) ) . send ( { fee : { paymentMethod } } ) . deployed ( ) ;
71- const bananaCoin = await TokenContract . deploy ( wallet1 , wallet1 . getAddress ( ) , "bananaCoin" , "BNC" , 18 ) . send ( { fee : { paymentMethod } } ) . deployed ( )
70+ const votingContract = await PrivateVotingContract . deploy ( wallet1 , wallet1 . getAddress ( ) ) . send ( {
71+ from : wallet1 . getAddress ( ) ,
72+ fee : { paymentMethod }
73+ } ) . deployed ( ) ;
74+ const bananaCoin = await TokenContract . deploy ( wallet1 , wallet1 . getAddress ( ) , "bananaCoin" , "BNC" , 18 ) . send ( {
75+ from : wallet1 . getAddress ( ) ,
76+ fee : { paymentMethod }
77+ } ) . deployed ( )
7278
7379 // Claim Fee Juice & Pay Fees yourself
7480
@@ -80,7 +86,10 @@ async function main() {
8086
8187 // Create a new voting contract instance, interacting from the newWallet
8288 const useFeeJuice = new FeeJuicePaymentMethod ( account2 . getAddress ( ) )
83- await votingContract . withWallet ( wallet2 ) . methods . cast_vote ( wallet1 . getAddress ( ) ) . send ( { fee : { paymentMethod : useFeeJuice } } ) . wait ( )
89+ await votingContract . withWallet ( wallet2 ) . methods . cast_vote ( wallet1 . getAddress ( ) ) . send ( {
90+ from : wallet2 . getAddress ( ) ,
91+ fee : { paymentMethod : useFeeJuice }
92+ } ) . wait ( )
8493 logger . info ( `Vote cast from new account, paying fees via newWallet.` )
8594
8695 // Private Fee Payments via FPC
@@ -89,40 +98,62 @@ async function main() {
8998 // Need to deploy an FPC to use Private Fee payment methods
9099
91100 // This uses bananaCoin as the fee paying asset that will be exchanged for fee juice
92- const fpc = await FPCContract . deploy ( wallet1 , bananaCoin . address , wallet1 . getAddress ( ) ) . send ( { fee : { paymentMethod } } ) . deployed ( )
101+ const fpc = await FPCContract . deploy ( wallet1 , bananaCoin . address , wallet1 . getAddress ( ) ) . send ( {
102+ from : wallet1 . getAddress ( ) ,
103+ fee : { paymentMethod }
104+ } ) . deployed ( )
93105 const fpcClaim = await feeJuicePortalManager . bridgeTokensPublic ( fpc . address , FEE_FUNDING_FOR_TESTER_ACCOUNT , true ) ;
94106 // 2 public txs to make the bridged fee juice available
95107 // Mint some bananaCoin and send to the newWallet to pay fees privately
96- await bananaCoin . methods . mint_to_private ( wallet1 . getAddress ( ) , wallet2 . getAddress ( ) , FEE_FUNDING_FOR_TESTER_ACCOUNT ) . send ( { fee : { paymentMethod } } ) . wait ( )
108+ await bananaCoin . methods . mint_to_private ( wallet2 . getAddress ( ) , FEE_FUNDING_FOR_TESTER_ACCOUNT ) . send ( {
109+ from : wallet1 . getAddress ( ) ,
110+ fee : { paymentMethod }
111+ } ) . wait ( )
97112 // mint some public bananaCoin to the newWallet to pay fees publicly
98- await bananaCoin . methods . mint_to_public ( wallet2 . getAddress ( ) , FEE_FUNDING_FOR_TESTER_ACCOUNT ) . send ( { fee : { paymentMethod } } ) . wait ( )
99- const bananaBalance = await bananaCoin . withWallet ( wallet2 ) . methods . balance_of_private ( wallet2 . getAddress ( ) ) . simulate ( )
113+ await bananaCoin . methods . mint_to_public ( wallet2 . getAddress ( ) , FEE_FUNDING_FOR_TESTER_ACCOUNT ) . send ( {
114+ from : wallet1 . getAddress ( ) ,
115+ fee : { paymentMethod }
116+ } ) . wait ( )
117+ const bananaBalance = await bananaCoin . withWallet ( wallet2 ) . methods . balance_of_private ( wallet2 . getAddress ( ) ) . simulate ( {
118+ from : wallet2 . getAddress ( )
119+ } )
100120
101121 logger . info ( `BananaCoin balance of newWallet is ${ bananaBalance } ` )
102122
103123 const feeJuiceInstance = await getCanonicalFeeJuice ( ) ;
104124 const feeJuice = await FeeJuiceContract . at ( feeJuiceInstance . address , wallet2 )
105- await feeJuice . methods . claim ( fpc . address , fpcClaim . claimAmount , fpcClaim . claimSecret , fpcClaim . messageLeafIndex ) . send ( ) . wait ( )
125+ await feeJuice . methods . claim ( fpc . address , fpcClaim . claimAmount , fpcClaim . claimSecret , fpcClaim . messageLeafIndex ) . send ( { from : wallet2 . getAddress ( ) } ) . wait ( )
106126
107- logger . info ( `Fpc fee juice balance ${ await feeJuice . methods . balance_of_public ( fpc . address ) . simulate ( ) } ` )
127+ logger . info ( `Fpc fee juice balance ${ await feeJuice . methods . balance_of_public ( fpc . address ) . simulate ( {
128+ from : wallet2 . getAddress ( )
129+ } ) } `)
108130
109131 const privateFee = new PrivateFeePaymentMethod ( fpc . address , wallet2 )
110- await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( { fee : { paymentMethod : privateFee } } ) . wait ( )
132+ await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( {
133+ from : wallet2 . getAddress ( ) ,
134+ fee : { paymentMethod : privateFee }
135+ } ) . wait ( )
111136
112137 logger . info ( `Transfer paid with fees via the FPC, privately.` )
113138
114139 // Public Fee Payments via FPC
115140
116141 const publicFee = new PublicFeePaymentMethod ( fpc . address , wallet2 )
117- await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( { fee : { paymentMethod : publicFee } } ) . wait ( )
142+ await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( {
143+ from : wallet2 . getAddress ( ) ,
144+ fee : { paymentMethod : publicFee }
145+ } ) . wait ( )
118146 logger . info ( `Transfer paid with fees via the FPC, publicly.` )
119147
120148 // Sponsored Fee Payment
121149
122150 // This method will only work in environments where there is a sponsored fee contract deployed
123151 const deployedSponsoredFPC = await getDeployedSponsoredFPCAddress ( pxe ) ;
124152 const sponsoredPaymentMethod = new SponsoredFeePaymentMethod ( deployedSponsoredFPC ) ;
125- await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( { fee : { paymentMethod : sponsoredPaymentMethod } } ) . wait ( )
153+ await bananaCoin . withWallet ( wallet2 ) . methods . transfer_in_private ( wallet2 . getAddress ( ) , wallet1 . getAddress ( ) , 10 , 0 ) . send ( {
154+ from : wallet2 . getAddress ( ) ,
155+ fee : { paymentMethod : sponsoredPaymentMethod }
156+ } ) . wait ( )
126157 logger . info ( `Transfer paid with fees from Sponsored FPC.` )
127158}
128159
@@ -137,4 +168,3 @@ function getL1WalletClient(rpcUrl: string, index: number) {
137168 transport : http ( rpcUrl ) ,
138169 } ) ;
139170}
140-
0 commit comments