1
- import { type AztecAddress , type EthAddress } from '@aztec/circuits.js' ;
1
+ import { type AztecAddress , type EthAddress , type Fr } from '@aztec/circuits.js' ;
2
2
import { createEthereumChain , createL1Clients } from '@aztec/ethereum' ;
3
3
import { type DebugLogger , type LogFn } from '@aztec/foundation/log' ;
4
4
5
5
import { prettyPrintJSON } from '../../utils/commands.js' ;
6
- import { ERC20PortalManager } from '../../utils/portal_manager.js' ;
6
+ import { L1PortalManager } from '../../utils/portal_manager.js' ;
7
7
8
8
export async function bridgeERC20 (
9
9
amount : bigint ,
@@ -14,6 +14,7 @@ export async function bridgeERC20(
14
14
mnemonic : string ,
15
15
tokenAddress : EthAddress ,
16
16
portalAddress : EthAddress ,
17
+ privateTransfer : boolean ,
17
18
mint : boolean ,
18
19
json : boolean ,
19
20
log : LogFn ,
@@ -24,14 +25,19 @@ export async function bridgeERC20(
24
25
const { publicClient, walletClient } = createL1Clients ( chain . rpcUrl , privateKey ?? mnemonic , chain . chainInfo ) ;
25
26
26
27
// Setup portal manager
27
- const portal = await ERC20PortalManager . create ( tokenAddress , portalAddress , publicClient , walletClient , debugLogger ) ;
28
- const { secret } = await portal . prepareTokensOnL1 ( amount , amount , recipient , mint ) ;
28
+ const manager = new L1PortalManager ( portalAddress , tokenAddress , publicClient , walletClient , debugLogger ) ;
29
+ let claimSecret : Fr ;
30
+ if ( privateTransfer ) {
31
+ ( { claimSecret } = await manager . bridgeTokensPrivate ( recipient , amount , mint ) ) ;
32
+ } else {
33
+ ( { claimSecret } = await manager . bridgeTokensPublic ( recipient , amount , mint ) ) ;
34
+ }
29
35
30
36
if ( json ) {
31
37
log (
32
38
prettyPrintJSON ( {
33
39
claimAmount : amount ,
34
- claimSecret : secret ,
40
+ claimSecret : claimSecret ,
35
41
} ) ,
36
42
) ;
37
43
} else {
@@ -40,7 +46,7 @@ export async function bridgeERC20(
40
46
} else {
41
47
log ( `Bridged ${ amount } tokens to L2 portal` ) ;
42
48
}
43
- log ( `claimAmount=${ amount } ,claimSecret=${ secret } \n` ) ;
49
+ log ( `claimAmount=${ amount } ,claimSecret=${ claimSecret } \n` ) ;
44
50
log ( `Note: You need to wait for two L2 blocks before pulling them from the L2 side` ) ;
45
51
}
46
52
}
0 commit comments