1+ import { AccountWallet , CompleteAddress , createLogger , L1FeeJuicePortalManager , PXE , waitForPXE , createPXEClient , Logger } from "@aztec/aztec.js" ;
2+ import { getInitialTestAccountsWallets } from "@aztec/accounts/testing" ;
3+ import {
4+ createPublicClient ,
5+ createWalletClient ,
6+ getContract ,
7+ http ,
8+ } from 'viem' ;
9+ import { foundry } from 'viem/chains'
10+ import { mnemonicToAccount } from 'viem/accounts' ;
11+ import { FeeJuiceContract } from "@aztec/noir-contracts.js/FeeJuice" ;
12+
13+ const setupSandbox = async ( ) => {
14+ const { PXE_URL = 'http://localhost:8080' } = process . env ;
15+ const pxe = await createPXEClient ( PXE_URL ) ;
16+ await waitForPXE ( pxe ) ;
17+ return pxe ;
18+ } ;
19+
20+ const MNEMONIC = 'test test test test test test test test test test test junk' ;
21+
22+ let walletClient = getL1WalletClient ( foundry . rpcUrls . default . http [ 0 ] , 0 ) ;
23+ const ownerEthAddress = walletClient . account . address ;
24+
25+ const publicClient = createPublicClient ( {
26+ chain : foundry ,
27+ transport : http ( "http://127.0.0.1:8545" ) ,
28+ } ) ;
29+
30+ async function main ( ) {
31+
32+ let pxe : PXE ;
33+ let wallets : AccountWallet [ ] = [ ] ;
34+ let accounts : CompleteAddress [ ] = [ ] ;
35+ let logger : Logger ;
36+
37+ const amount = 100n ;
38+
39+ logger = createLogger ( 'aztec:aztec-starter' ) ;
40+
41+ pxe = await setupSandbox ( ) ;
42+ wallets = await getInitialTestAccountsWallets ( pxe ) ;
43+ const nodeInfo = ( await pxe . getNodeInfo ( ) )
44+ const l1ContractAddresses = nodeInfo . l1ContractAddresses ;
45+
46+ const feeJuiceReceipient = wallets [ 0 ] . getAddress ( )
47+
48+ const feeJuicePortalManager = new L1FeeJuicePortalManager (
49+ l1ContractAddresses . feeJuicePortalAddress ,
50+ l1ContractAddresses . feeJuiceAddress ,
51+ //@ts -ignore
52+ publicClient ,
53+ walletClient ,
54+ logger ,
55+ ) ;
56+
57+ let feeJuiceTokenManager = feeJuicePortalManager . getTokenManager ( )
58+ await feeJuicePortalManager . bridgeTokensPublic ( feeJuiceReceipient , amount , true ) ;
59+
60+ const feeJuice = await FeeJuiceContract . at ( nodeInfo . protocolContractAddresses . feeJuice , wallets [ 0 ] )
61+ const balance = await feeJuice . methods . balance_of_public ( feeJuiceReceipient ) . simulate ( )
62+ logger . info ( `${ balance } Fee Juice minted to ${ feeJuiceReceipient } on L2.` )
63+ }
64+
65+ main ( ) ;
66+
67+ // from here: https://github.com/AztecProtocol/aztec-packages/blob/ecbd59e58006533c8885a8b2fadbd9507489300c/yarn-project/end-to-end/src/fixtures/utils.ts#L534
68+ function getL1WalletClient ( rpcUrl : string , index : number ) {
69+ const hdAccount = mnemonicToAccount ( MNEMONIC , { addressIndex : index } ) ;
70+ return createWalletClient ( {
71+ account : hdAccount ,
72+ chain : foundry ,
73+ transport : http ( rpcUrl ) ,
74+ } ) ;
75+ }
0 commit comments