( network: string, amount: string, receiverAddress: string | undefined, tokenAddress: string, mnemonic?: string )
| 65 | } |
| 66 | |
| 67 | export async function bridgeToLayer2( |
| 68 | network: string, |
| 69 | amount: string, |
| 70 | receiverAddress: string | undefined, |
| 71 | tokenAddress: string, |
| 72 | mnemonic?: string |
| 73 | ): Promise<void> { |
| 74 | const amountInWei = toWei(amount); |
| 75 | |
| 76 | let web3 = await getWeb3(network, mnemonic); |
| 77 | let tokenBridge = await getSDK('TokenBridgeForeignSide', web3); |
| 78 | let assets = await getSDK('Assets', web3); |
| 79 | let { symbol } = await assets.getTokenInfo(tokenAddress); |
| 80 | receiverAddress = receiverAddress ?? (await web3.eth.getAccounts())[0]; |
| 81 | |
| 82 | let blockExplorer = await getConstant('blockExplorer', web3); |
| 83 | |
| 84 | { |
| 85 | console.log(`Sending approve transaction request for ${amount} ${symbol}`); |
| 86 | let result = await tokenBridge.unlockTokens(tokenAddress, amountInWei); |
| 87 | console.log(`Approve transaction hash: ${blockExplorer}/tx/${result.transactionHash}`); |
| 88 | } |
| 89 | |
| 90 | { |
| 91 | console.log( |
| 92 | `Sending relay tokens transaction request for ${amount} ${symbol} into layer 2 safe owned by ${receiverAddress}` |
| 93 | ); |
| 94 | let result = await tokenBridge.relayTokens(tokenAddress, receiverAddress, amountInWei); |
| 95 | console.log(`Relay tokens transaction hash: ${blockExplorer}/tx/${result.transactionHash}`); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | export async function awaitBridgedToLayer2( |
| 100 | network: string, |
no test coverage detected