diff --git a/package.json b/package.json index d709c84..6c9fac7 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@ethersproject/providers": "^5.6.8", "@lidofinance/evm-script-decoder": "^0.2.2", "@openzeppelin/contracts": "4.6.0", - "chalk": "4.1.2" + "chalk": "4.1.2", + "p-limit": "3.1.0" } } diff --git a/scripts/optimism/check-deposits-concurrent.ts b/scripts/optimism/check-deposits-concurrent.ts new file mode 100644 index 0000000..a9ac14a --- /dev/null +++ b/scripts/optimism/check-deposits-concurrent.ts @@ -0,0 +1,213 @@ +import { ethers } from "ethers"; +// import { ethers } from "hardhat"; +import pLimit from "p-limit"; + +async function main() { + + //http://localhost:8545 + const ethereumNode = process.env["ETHEREUM_NODE"] + const optimismNode = process.env["OPTIMISM_NODE"] + + + + // Set up providers + // const ethereumProvider = new ethers.providers.JsonRpcProvider(ethereumNode); + const ethereumProvider = new ethers.providers.JsonRpcProvider({ url: ethereumNode, timeout: 5*60*1000 } as any); + const optimismProvider = new ethers.providers.JsonRpcProvider({ url: optimismNode, timeout: 5*60*1000 } as any); + // ethereumProvider.timeout = 12; + // optimismProvider.; + + // Mainnet + // const ethBridgeAddress = "0x76943C0D61395d8F2edF9060e1533529cAe05dE6" + // const optBridgeAddress = "0x8e01013243a96601a86eb3153f0d9fa4fbfb6957" + + // Sepolia + const ethBridgeAddress = "0x4Abf633d9c0F4aEebB4C2E3213c7aa1b8505D332" + const optBridgeAddress = "0x635B054A092F6aE61Ce0Fddc397A704F6626510D" + + // Define the ABI on the Ethereum + const ethBridgeAbi = [ + "event ERC20DepositInitiated(address indexed _l1Token,address indexed _l2Token,address indexed _from,address _to,uint256 _amount, bytes _data)", + "event ERC20WithdrawalFinalized(address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data)" + ]; + const ethInterface = new ethers.utils.Interface(ethBridgeAbi); + const topicEthDeposit = ethers.utils.id("ERC20DepositInitiated(address,address,address,address,uint256,bytes)") + const topicEthWithdraw = ethers.utils.id("ERC20WithdrawalFinalized(address,address,address,address,uint256,bytes)") + + + // Define the ABI on the Optimism + const optBridgeAbi = [ + "event DepositFinalized(address indexed _l1Token,address indexed _l2Token,address indexed _from,address _to,uint256 _amount,bytes _data)", + "event WithdrawalInitiated(address indexed _l1Token,address indexed _l2Token,address indexed _from,address _to,uint256 _amount,bytes _data)" + ]; + const optInterface = new ethers.utils.Interface(optBridgeAbi); + const topicOptDeposit = ethers.utils.id("DepositFinalized(address,address,address,address,uint256,bytes)") + const topicOptWithdraw = ethers.utils.id("WithdrawalInitiated(address,address,address,address,uint256,bytes)") + + + // Define the starting and ending block numbers + // creation code + // MAINNET + // https://etherscan.io/tx/0x1bc90e7c6fe12e03691f7eccf025f3a244ea5a4888c7fb274f45f5e1004110ca + // const startEthBlock = 15281202; + + // creation code + // https://optimistic.etherscan.io/tx/0xd0a75128fcedaa0acfe5ccb2740a1a47a6a8e47bca844dee23e7b4cc747ea4d1 + // const startOptBlock = 17831155; + + + + // + // L1 + // https://sepolia.etherscan.io/tx/0x477453faea59acf4517a2c1abfaba450449316c587009671540e538572eb85ff + const startEthBlock = 5272290; + // L2 + // https://sepolia-optimism.etherscan.io/tx/0x792eaf25c68e91879854ab4ca9b6c933a49d25bdf78a858a1c87a8d64e5c99a3 + const startOptBlock = 7967186; + // const startOptBlock = 15000000; + + const optBlockStep = 10000; // higher value leads to rpc error "no backends available for method" + const ethBlockStep = 100000; + + // Get the latest block numbers from both networks + const latestEthBlock = await ethereumProvider.getBlockNumber(); + const latestOptBlock = await optimismProvider.getBlockNumber(); + + const fetchLogs = async ( + provider: ethers.providers.JsonRpcProvider, + startBlock: number, + latestBlock: number, + blockStep: number, + bridgeAddress: string, + logsInterface: ethers.utils.Interface, + topicDeposit: string, + topicWithdraw: string, + networkName: string + ) => { + + console.log(`Get Ethereum logs:`); + console.log(` address: ${bridgeAddress}`); + console.log(` startBlock: ${startBlock}`); + console.log(` endBlock: ${latestBlock}`); + console.log(` topicDeposit: ${topicDeposit}`); + console.log(` topicWithdraw: ${topicWithdraw}`); + + let depositsCount = 0; + let withdrawalsCount = 0; + let depositsTotal = ethers.BigNumber.from(0); + let withdrawalsTotal = ethers.BigNumber.from(0); + + // Limit concurrency to 10 threads + const limit = pLimit(10); + + // Array to hold promises for each block range iteration + const promises = []; + + for (let fromBlock = startBlock; fromBlock < latestBlock; fromBlock += blockStep) { + const toBlock = Math.min(fromBlock + blockStep - 1, latestBlock) + + // Create promise for fetching logs in this block range + const promise = limit(async () => { + const filterDeposit = { + address: bridgeAddress, + topics: [ + topicDeposit + ], + fromBlock, + toBlock + }; + + const filterWithdraw = { + address: bridgeAddress, + topics: [ + topicWithdraw + ], + fromBlock, + toBlock + }; + + // Fetch logs from the forked network + const logsDeposits = await provider.getLogs(filterDeposit); + logsDeposits.forEach((log) => { + const parsedLog = logsInterface.parseLog(log); + + depositsCount++ + depositsTotal = depositsTotal.add(parsedLog.args._amount) + }); + + // Fetch logs from the forked network + const logsWithdraw = await provider.getLogs(filterWithdraw); + logsWithdraw.forEach((log) => { + const parsedLog = logsInterface.parseLog(log); + withdrawalsCount++ + withdrawalsTotal = withdrawalsTotal.add(parsedLog.args._amount) + }); + + console.log(`${networkName} processed blocks ${fromBlock}-${toBlock} of ${latestBlock}`) + }); + + // Push promise into array + promises.push(promise); + } + + // Execute all promises in parallel + await Promise.all(promises); + + const balance = depositsTotal.sub(withdrawalsTotal) + + console.log(' ') + + return { + depositsCount, + depositsTotal, + withdrawalsCount, + withdrawalsTotal, + balance, + } + } + + const promises = [ + // Promise for Ethereum + fetchLogs(ethereumProvider, startEthBlock, latestEthBlock, ethBlockStep, ethBridgeAddress, ethInterface, topicEthDeposit, topicEthWithdraw, "Ethereum"), + fetchLogs(optimismProvider, startOptBlock, latestOptBlock, optBlockStep, optBridgeAddress, optInterface, topicOptDeposit, topicOptWithdraw, "Optimism"), + ]; + + // Execute all promises in parallel and wait for all blocks to be processed + const results = await Promise.all(promises); + + const fromEthereum = results[0] + const fromOptimism = results[1] + + // const fromOptimism = results[0] + + const table: any = {} + table.L1 = { + deposits: fromEthereum.depositsTotal.toString(), + depCount: fromEthereum.depositsCount, + withdrawals: fromEthereum.withdrawalsTotal.toString(), + wthCount: fromEthereum.withdrawalsCount, + balance: fromEthereum.balance.toString(), + } + table.L2 = { + deposits: fromOptimism.depositsTotal.toString(), + depCount: fromOptimism.depositsCount, + withdrawals: fromOptimism.withdrawalsTotal.toString(), + wthCount: fromOptimism.withdrawalsCount, + balance: fromOptimism.balance.toString() + } + table.diff = { + deposits: fromEthereum.depositsTotal.sub(fromOptimism.depositsTotal).toString(), + depCount: fromEthereum.depositsCount-fromOptimism.depositsCount, + withdrawals: fromEthereum.withdrawalsTotal.sub(fromOptimism.withdrawalsTotal).toString(), + wthCount: fromEthereum.withdrawalsCount-fromOptimism.withdrawalsCount, + balance: fromEthereum.balance.sub(fromOptimism.balance).toString() + } + console.table(table) + + console.log(' ') +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/optimism/do-deposit.ts b/scripts/optimism/do-deposit.ts new file mode 100644 index 0000000..6cc5c86 --- /dev/null +++ b/scripts/optimism/do-deposit.ts @@ -0,0 +1,74 @@ +import { ethers, BigNumber } from "ethers"; +import { readFileSync } from "fs"; +import assert from "assert"; +// import { ethers } from "hardhat"; +import pLimit from "p-limit"; + + +const L1_BRIDGE_ABI = JSON.parse('[{"inputs":[{"internalType":"address","name":"messenger_","type":"address"},{"internalType":"address","name":"l2TokenBridge_","type":"address"},{"internalType":"address","name":"l1Token_","type":"address"},{"internalType":"address","name":"l2Token_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ErrorAccountIsZeroAddress","type":"error"},{"inputs":[],"name":"ErrorAlreadyInitialized","type":"error"},{"inputs":[],"name":"ErrorDepositsDisabled","type":"error"},{"inputs":[],"name":"ErrorDepositsEnabled","type":"error"},{"inputs":[],"name":"ErrorSenderNotEOA","type":"error"},{"inputs":[],"name":"ErrorUnauthorizedMessenger","type":"error"},{"inputs":[],"name":"ErrorUnsupportedL1Token","type":"error"},{"inputs":[],"name":"ErrorUnsupportedL2Token","type":"error"},{"inputs":[],"name":"ErrorWithdrawalsDisabled","type":"error"},{"inputs":[],"name":"ErrorWithdrawalsEnabled","type":"error"},{"inputs":[],"name":"ErrorWrongCrossDomainSender","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"disabler","type":"address"}],"name":"DepositsDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"enabler","type":"address"}],"name":"DepositsEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_l1Token","type":"address"},{"indexed":true,"internalType":"address","name":"_l2Token","type":"address"},{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ERC20DepositInitiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_l1Token","type":"address"},{"indexed":true,"internalType":"address","name":"_l2Token","type":"address"},{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ERC20WithdrawalFinalized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"disabler","type":"address"}],"name":"WithdrawalsDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"enabler","type":"address"}],"name":"WithdrawalsEnabled","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEPOSITS_DISABLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEPOSITS_ENABLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWALS_DISABLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWALS_ENABLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"l1Token_","type":"address"},{"internalType":"address","name":"l2Token_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint32","name":"l2Gas_","type":"uint32"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"depositERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"l1Token_","type":"address"},{"internalType":"address","name":"l2Token_","type":"address"},{"internalType":"address","name":"to_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint32","name":"l2Gas_","type":"uint32"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"depositERC20To","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enableDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enableWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"l1Token_","type":"address"},{"internalType":"address","name":"l2Token_","type":"address"},{"internalType":"address","name":"from_","type":"address"},{"internalType":"address","name":"to_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"finalizeERC20Withdrawal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"admin_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isDepositsEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isWithdrawalsEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l1Token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2Token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l2TokenBridge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"messenger","outputs":[{"internalType":"contract ICrossDomainMessenger","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]'); +const L1_WSTETH_ABI = JSON.parse('[{"inputs":[{"internalType":"contract IStETH","name":"_stETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wstETHAmount","type":"uint256"}],"name":"getStETHByWstETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_stETHAmount","type":"uint256"}],"name":"getWstETHByStETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stETH","outputs":[{"internalType":"contract IStETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stEthPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokensPerStEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wstETHAmount","type":"uint256"}],"name":"unwrap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_stETHAmount","type":"uint256"}],"name":"wrap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]'); + + +async function main() { + + //http://localhost:8545 + const ethereumNode = process.env["ETHEREUM_NODE"] + const optimismNode = process.env["OPTIMISM_NODE"] + const DEV_PK = readFileSync("./key", "utf-8").trim() + assert(DEV_PK.length === 64); + + // Set up providers + // const ethereumProvider = new ethers.providers.JsonRpcProvider(ethereumNode); + const ethereumProvider = new ethers.providers.JsonRpcProvider({ url: ethereumNode, timeout: 5*60*1000 } as any); + const optimismProvider = new ethers.providers.JsonRpcProvider({ url: optimismNode, timeout: 5*60*1000 } as any); + // ethereumProvider.timeout = 12; + // optimismProvider.; + + // Mainnet + // const ethBridgeAddress = "0x76943C0D61395d8F2edF9060e1533529cAe05dE6" + // const optBridgeAddress = "0x8e01013243a96601a86eb3153f0d9fa4fbfb6957" + + const devAddress = "0x69632D495Ab4eD0dDf070a8bE55621DFe07901fF" + const wallet = new ethers.Wallet(DEV_PK, ethereumProvider); + assert(await wallet.getAddress() === devAddress) + + // Sepolia + const ethWstethAddress = "0xB82381A3fBD3FaFA77B3a7bE693342618240067b" + const ethBridgeAddress = "0x4Abf633d9c0F4aEebB4C2E3213c7aa1b8505D332" + + const optWstethAddress = "0x24B47cd3A74f1799b32B2de11073764Cb1bb318B" + const optBridgeAddress = "0x635B054A092F6aE61Ce0Fddc397A704F6626510D" + + const ethBridge = new ethers.Contract(ethBridgeAddress, L1_BRIDGE_ABI, ethereumProvider); + const ethWsteth = new ethers.Contract(ethWstethAddress, L1_WSTETH_ABI, ethereumProvider); + + const wstethAmountToDeposit = BigNumber.from(888000) + const currentWstethBalance = await ethWsteth.balanceOf(devAddress) + let currentAllowance = await ethWsteth.allowance(devAddress, ethBridgeAddress) + // currentAllowance = currentAllowance.toString() + console.debug({ currentAllowance: currentAllowance.toString() }) + + assert(currentWstethBalance.gte(wstethAmountToDeposit)) + assert(currentAllowance.gte(wstethAmountToDeposit)) + + // function depositERC20( + // address l1Token_, + // address l2Token_, + // uint256 amount_, + // uint32 l2Gas_, + // bytes calldata data_ + const gasLimitArg = 1_000_000 + const tx = await ethBridge.connect(wallet).depositERC20(ethWstethAddress, optWstethAddress, wstethAmountToDeposit, gasLimitArg, "0x") + const receipt = await tx.wait() + console.debug({ receipt }) + +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); + + + +