diff --git a/examples/manta/scripts/mantaTasks.js b/examples/manta/scripts/mantaTasks.js index 700092d..5f74fd5 100644 --- a/examples/manta/scripts/mantaTasks.js +++ b/examples/manta/scripts/mantaTasks.js @@ -25,8 +25,8 @@ async function initMessenger() { // https://github.com/Manta-Network/bridging-tutorial/blob/ad640a17264e2f009065811a0ff0872d8063b27b/standard-bridge-custom-token/README.md?plain=1#L152 const messengerL1Contracts = ethereumName !== 'ETHEREUM' ? L1_TESTNET_CONTRACTS : L1_MAINNET_CONTRACTS; const messenger = new manta.CrossChainMessenger({ - l1ChainId: await l1Wallet.getChainId(), // 5 for Goerli, 1 for Ethereum - l2ChainId: await l2Wallet.getChainId(), // 3441005 for Manta Pacific Testnet, 169 for Manta Pacific Mainnet + l1ChainId: await l1Wallet.getChainId(), + l2ChainId: await l2Wallet.getChainId(), l1SignerOrProvider: l1Wallet, l2SignerOrProvider: l2Wallet, bedrock: true, diff --git a/examples/mantle/hardhat.config.js b/examples/mantle/hardhat.config.js index cbac017..f80332a 100644 --- a/examples/mantle/hardhat.config.js +++ b/examples/mantle/hardhat.config.js @@ -1,9 +1,5 @@ require('@nomiclabs/hardhat-ethers'); -require('./scripts/syncL2Requests'); -require('./scripts/syncBatchRoot'); -require('./scripts/setValidator'); -require('./scripts/changeFeeParams'); -require('./scripts/governance'); +require('./scripts/mantleTasks'); const BaseConfig = require('../../hardhat.base.config'); diff --git a/examples/mantle/scripts/changeFeeParams.js b/examples/mantle/scripts/changeFeeParams.js deleted file mode 100644 index 2d0328e..0000000 --- a/examples/mantle/scripts/changeFeeParams.js +++ /dev/null @@ -1,82 +0,0 @@ -const mantle = require('@mantleio/sdk'); -const ethers = require('ethers'); -const { readDeployContract, getLogName } = require('../../../script/utils'); -const logName = require('../../../script/deploy_log_name'); -const { task } = require('hardhat/config'); -require('dotenv').config(); - -task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArgs, hre) => { - const walletPrivateKey = process.env.DEVNET_PRIVKEY; - const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC); - const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC); - const ethereumName = process.env.ETHEREUM; - const mantleName = process.env.MANTLE; - const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); - const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); - - const messenger = new mantle.CrossChainMessenger({ - l1ChainId: ethereumName !== 'ETHEREUM' ? 5 : 1, // 5 for Goerli, 1 for Ethereum - l2ChainId: ethereumName !== 'ETHEREUM' ? 5001 : 5000, // 5001 for Mantle Testnet, 5000 for Mantle Mainnet - l1SignerOrProvider: l1Wallet, - l2SignerOrProvider: l2Wallet, - bedrock: true, - }); - - const l1WalletAddress = await l1Wallet.getAddress(); - const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance()); - console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`); - - const arbitratorAddr = readDeployContract( - logName.DEPLOY_ARBITRATOR_LOG_PREFIX, - logName.DEPLOY_LOG_ARBITRATOR, - ethereumName, - ); - if (arbitratorAddr === undefined) { - console.log('The arbitrator address not exist'); - return; - } - console.log(`The arbitrator address: ${arbitratorAddr}`); - - const zkLinkAddr = readDeployContract(logName.DEPLOY_ZKLINK_LOG_PREFIX, logName.DEPLOY_LOG_ZKLINK_PROXY, mantleName); - if (zkLinkAddr === undefined) { - console.log('zkLink address not exist'); - return; - } - console.log(`The zkLink address: ${zkLinkAddr}`); - - const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, mantleName); - const mantleL1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName); - if (mantleL1GatewayAddr === undefined) { - console.log('mantle l1 gateway address not exist'); - return; - } - console.log(`The mantle l1 gateway address: ${mantleL1GatewayAddr}`); - - const mantleL2GatewayAddr = readDeployContract( - logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, - logName.DEPLOY_GATEWAY, - mantleName, - ); - if (mantleL2GatewayAddr === undefined) { - console.log('mantle l2 gateway address not exist'); - return; - } - console.log(`The mantle l2 gateway address: ${mantleL2GatewayAddr}`); - - // forward message to L2 - const arbitrator = await hre.ethers.getContractAt('Arbitrator', arbitratorAddr, l1Wallet); - const gasLimit = 400000; - const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [gasLimit]); - console.log('Prepare to forward the message to L2...'); - const { INIT_FEE_PARAMS } = require('../../../script/zksync_era'); - let tx = await arbitrator.changeFeeParams(mantleL1GatewayAddr, INIT_FEE_PARAMS, adapterParams); - const txHash = tx.hash; - console.log(`The tx hash: ${txHash}`); - await tx.wait(); - console.log(`The transaction has been executed on L1`); - - // Waiting for the official mantle bridge to forward the message to L2 - const rec = await messenger.waitForMessageReceipt(txHash); - console.log(`The tx receipt: ${JSON.stringify(rec)}`); - console.log('Done'); -}); diff --git a/examples/mantle/scripts/constants.js b/examples/mantle/scripts/constants.js deleted file mode 100644 index 5f3f268..0000000 --- a/examples/mantle/scripts/constants.js +++ /dev/null @@ -1,28 +0,0 @@ -// Testnet -const L1_TESTNET_CONTRACTS = { - StateCommitmentChain: '0x0000000000000000000000000000000000000000', - BondManager: '0x0000000000000000000000000000000000000000', - CanonicalTransactionChain: '0x0000000000000000000000000000000000000000', - AddressManager: '0x0000000000000000000000000000000000000000', - L1CrossDomainMessenger: '0x536beD6283500BF93BA4428c18a7A629425a5c7e', - L1StandardBridge: '0xf26e9932106E6477a4Ae15dA0eDDCdB985065a1a', - OptimismPortal: '0xB3db4bd5bc225930eD674494F9A4F6a11B8EFBc8', - L2OutputOracle: '0x4121dc8e48Bc6196795eb4867772A5e259fecE07', -}; - -// Mainnet -const L1_MAINNET_CONTRACTS = { - StateCommitmentChain: '0x0000000000000000000000000000000000000000', - BondManager: '0x0000000000000000000000000000000000000000', - CanonicalTransactionChain: '0x0000000000000000000000000000000000000000', - AddressManager: '0x0000000000000000000000000000000000000000', - L1CrossDomainMessenger: '0xb8DE82551fA4BA3bE4B3d9097763EDBeED541308', - L1StandardBridge: '0xb4133552BA49dFb60DA6eb5cA0102d0f94ce071f', - OptimismPortal: '0xc54cb22944F2bE476E02dECfCD7e3E7d3e15A8Fb', - L2OutputOracle: '0x31d543e7BE1dA6eFDc2206Ef7822879045B9f481', -}; - -module.exports = { - L1_TESTNET_CONTRACTS, - L1_MAINNET_CONTRACTS, -}; diff --git a/examples/mantle/scripts/governance.js b/examples/mantle/scripts/mantleTasks.js similarity index 56% rename from examples/mantle/scripts/governance.js rename to examples/mantle/scripts/mantleTasks.js index 3bf27c8..6cafefd 100644 --- a/examples/mantle/scripts/governance.js +++ b/examples/mantle/scripts/mantleTasks.js @@ -1,39 +1,120 @@ const mantle = require('@mantleio/sdk'); -const { DepositTx, applyL1ToL2Alias } = require('@mantleio/core-utils'); +const { applyL1ToL2Alias } = require('@mantleio/core-utils'); +const ethers = require('ethers'); +const { BigNumber, Contract } = require('ethers'); +const { + syncBatchRoot, + syncL2Requests, + setValidator, + changeFeeParams, + encodeSetValidator, + encodeChangeFeeParams, + checkL1TxStatus, +} = require('../../optimism/scripts/opstack-utils'); +const { zkLinkConfig } = require('../../../script/zklink_config'); const { readDeployContract } = require('../../../script/utils'); const logName = require('../../../script/deploy_log_name'); const { task, types } = require('hardhat/config'); -const { zkLinkConfig } = require('../../../script/zklink_config'); -const ethers = require('ethers'); -const { L1_TESTNET_CONTRACTS, L1_MAINNET_CONTRACTS } = require('./constants'); -const { BigNumber, Contract } = require('ethers'); - require('dotenv').config(); async function initMessenger() { const walletPrivateKey = process.env.DEVNET_PRIVKEY; const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC); const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC); - const ethereumName = process.env.ETHEREUM; const mantleName = process.env.MANTLE; + const ethereumName = process.env.ETHEREUM; const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); - // https://docs-v2.mantle.xyz/intro/system-components/on-chain-system - const messengerL1Contracts = ethereumName !== 'ETHEREUM' ? L1_TESTNET_CONTRACTS : L1_MAINNET_CONTRACTS; const messenger = new mantle.CrossChainMessenger({ l1ChainId: await l1Wallet.getChainId(), l2ChainId: await l2Wallet.getChainId(), l1SignerOrProvider: l1Wallet, l2SignerOrProvider: l2Wallet, bedrock: true, - contracts: { - l1: messengerL1Contracts, - }, }); return { messenger, ethereumName, mantleName }; } +task('syncBatchRoot', 'Forward message to L2').setAction(async (_, hre) => { + const { messenger, ethereumName, mantleName } = await initMessenger(); + + const message = await syncBatchRoot(hre, messenger, ethereumName, mantleName); + // Waiting for the official manta bridge to forward the message to L2 + const rec = await messenger.waitForMessageReceipt(message); + console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`); + console.log('Done'); + + // Example txs: + // https://sepolia.etherscan.io/tx/0x021a7a2eb1bf46dbfc1fe91da1c4f85b2891195482fa097d69b7b53bd8b4f041 + // https://sepolia.mantlescan.xyz/tx/0x97e054f0c3bc5b9033834eb88c59730716e275e460849b489bc7eff86b332225 +}); + +task('syncL2Requests', 'Send sync point to arbitrator') + .addParam('txs', 'New sync point', 100, types.int, true) + .setAction(async (taskArgs, hre) => { + const txs = taskArgs.txs; + console.log(`The sync point: txs: ${txs}`); + + const { messenger, ethereumName, mantleName } = await initMessenger(); + + await syncL2Requests(hre, messenger, ethereumName, mantleName, txs); + + console.log('Done!'); + + // Example txs: + // https://sepolia.mantlescan.xyz/tx/0xfacef5c27c52fc60e059e36c7fb5fd897cd3b85b0861cbaa0fe299c1ca23101b + // https://sepolia.etherscan.io/tx/0x1a0f721a5d0c4bcc334ad6d54a60ae4ce4b5e52c71f3e48f62e2f2c980885b61 + }); + +task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => { + const { messenger, ethereumName, mantleName } = await initMessenger(); + + const message = await changeFeeParams(hre, messenger, ethereumName, mantleName); + + // Waiting for the official manta bridge to forward the message to L2 + const rec = await messenger.waitForMessageReceipt(message); + console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`); + console.log('Done'); +}); + +task('setValidator', 'Set validator for zkLink') + .addParam('validator', 'Validator Address', undefined, types.string) + .addOptionalParam('active', 'Whether to activate the validator address', true, types.boolean) + .setAction(async (taskArgs, hre) => { + const validatorAddr = taskArgs.validator; + const isActive = taskArgs.active; + console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`); + + const { messenger, ethereumName, mantleName } = await initMessenger(); + + const message = await setValidator(hre, messenger, ethereumName, mantleName, validatorAddr, isActive); + + // Waiting for the official manta bridge to forward the message to L2 + const rec = await messenger.waitForMessageReceipt(message); + console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`); + console.log('Done'); + }); + +task('encodeSetValidator', 'Get the calldata of set validator for zkLink') + .addParam('validator', 'Validator Address', undefined, types.string) + .addOptionalParam('active', 'Whether to activate the validator address', true, types.boolean) + .setAction(async (taskArgs, hre) => { + const validatorAddr = taskArgs.validator; + const isActive = taskArgs.active; + console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`); + + const { ethereumName, mantleName } = await initMessenger(); + + await encodeSetValidator(hre, ethereumName, mantleName, validatorAddr, isActive); + }); + +task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (_, hre) => { + const { ethereumName, mantleName } = await initMessenger(); + + await encodeChangeFeeParams(hre, ethereumName, mantleName); +}); + task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2') .addParam('to', 'The l2 target address', undefined, types.string) .addParam('l2CallData', 'The l2 call data to target address', undefined, types.string) @@ -125,25 +206,10 @@ task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2') task('checkL1TxStatus', 'Check the l1 tx status') .addParam('l1TxHash', 'The l1 tx hash', undefined, types.string) - .setAction(async taskArgs => { + .setAction(async (taskArgs, hre) => { const l1TxHash = taskArgs.l1TxHash; console.log(`The l1 tx hash: ${l1TxHash}`); - const { messenger } = await initMessenger(); - - const l1Provider = messenger.l1Provider; - const l2Provider = messenger.l2Provider; - const l1TxReceipt = await l1Provider.getTransactionReceipt(l1TxHash); - const eventFilter = - 'TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData)'; - const event = ( - await messenger.contracts.l1.OptimismPortal.queryFilter( - eventFilter, - l1TxReceipt.blockNumber, - l1TxReceipt.blockNumber, - ) - ).pop(); - const deposit = DepositTx.fromL1Event(event); - await l2Provider.waitForTransaction(deposit.hash()); - console.log(`L1 to l2 tx is executed 🥳`); + const { messenger, ethereumName, mantleName } = await initMessenger(); + await checkL1TxStatus(hre, messenger, ethereumName, mantleName, l1TxHash); }); diff --git a/examples/mantle/scripts/setValidator.js b/examples/mantle/scripts/setValidator.js deleted file mode 100644 index 63744d2..0000000 --- a/examples/mantle/scripts/setValidator.js +++ /dev/null @@ -1,92 +0,0 @@ -const mantle = require('@mantleio/sdk'); -const ethers = require('ethers'); -const { readDeployContract, getLogName } = require('../../../script/utils'); -const logName = require('../../../script/deploy_log_name'); -const { task, types } = require('hardhat/config'); -require('dotenv').config(); - -task('setValidator', 'Set validator for zkLink') - .addParam('validator', 'Validator Address', undefined, types.string) - .addOptionalParam('active', 'Whether to activate the validator address', true, types.boolean) - .setAction(async (taskArgs, hre) => { - const validatorAddr = taskArgs.validator; - const isActive = taskArgs.active; - console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`); - - const walletPrivateKey = process.env.DEVNET_PRIVKEY; - const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC); - const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC); - const ethereumName = process.env.ETHEREUM; - const mantleName = process.env.MANTLE; - const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); - const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); - - const messenger = new mantle.CrossChainMessenger({ - l1ChainId: ethereumName !== 'ETHEREUM' ? 5 : 1, // 5 for Goerli, 1 for Ethereum - l2ChainId: ethereumName !== 'ETHEREUM' ? 5001 : 5000, // 5001 for Mantle Testnet, 5000 for Mantle Mainnet - l1SignerOrProvider: l1Wallet, - l2SignerOrProvider: l2Wallet, - bedrock: true, - }); - - const l1WalletAddress = await l1Wallet.getAddress(); - const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance()); - console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`); - - const arbitratorAddr = readDeployContract( - logName.DEPLOY_ARBITRATOR_LOG_PREFIX, - logName.DEPLOY_LOG_ARBITRATOR, - ethereumName, - ); - if (arbitratorAddr === undefined) { - console.log('The arbitrator address not exist'); - return; - } - console.log(`The arbitrator address: ${arbitratorAddr}`); - - const zkLinkAddr = readDeployContract( - logName.DEPLOY_ZKLINK_LOG_PREFIX, - logName.DEPLOY_LOG_ZKLINK_PROXY, - mantleName, - ); - if (zkLinkAddr === undefined) { - console.log('zkLink address not exist'); - return; - } - console.log(`The zkLink address: ${zkLinkAddr}`); - - const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, mantleName); - const mantleL1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName); - if (mantleL1GatewayAddr === undefined) { - console.log('mantle l1 gateway address not exist'); - return; - } - console.log(`The mantle l1 gateway address: ${mantleL1GatewayAddr}`); - - const mantleL2GatewayAddr = readDeployContract( - logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, - logName.DEPLOY_GATEWAY, - mantleName, - ); - if (mantleL2GatewayAddr === undefined) { - console.log('mantle l2 gateway address not exist'); - return; - } - console.log(`The mantle l2 gateway address: ${mantleL2GatewayAddr}`); - - // forward message to L2 - const arbitrator = await hre.ethers.getContractAt('Arbitrator', arbitratorAddr, l1Wallet); - const gasLimit = 400000; - const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [gasLimit]); - console.log('Prepare to forward the message to L2...'); - let tx = await arbitrator.setValidator(mantleL1GatewayAddr, validatorAddr, isActive, adapterParams); - const txHash = tx.hash; - console.log(`The tx hash: ${txHash}`); - await tx.wait(); - console.log(`The transaction has been executed on L1`); - - // Waiting for the official mantle bridge to forward the message to L2 - const rec = await messenger.waitForMessageReceipt(txHash); - console.log(`The tx receipt: ${JSON.stringify(rec)}`); - console.log('Done'); - }); diff --git a/examples/mantle/scripts/syncBatchRoot.js b/examples/mantle/scripts/syncBatchRoot.js deleted file mode 100644 index fd1e648..0000000 --- a/examples/mantle/scripts/syncBatchRoot.js +++ /dev/null @@ -1,98 +0,0 @@ -const mantle = require('@mantleio/sdk'); -const ethers = require('ethers'); -const { readDeployContract, getLogName } = require('../../../script/utils'); -const logName = require('../../../script/deploy_log_name'); -const { task } = require('hardhat/config'); -require('dotenv').config(); - -task('syncBatchRoot', 'Forward message to L2').setAction(async (taskArgs, hre) => { - const walletPrivateKey = process.env.DEVNET_PRIVKEY; - const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC); - const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC); - const ethereumName = process.env.ETHEREUM; - const mantleName = process.env.MANTLE; - const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); - const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); - - const messenger = new mantle.CrossChainMessenger({ - l1ChainId: ethereumName !== 'ETHEREUM' ? 5 : 1, // 5 for Goerli, 1 for Ethereum - l2ChainId: ethereumName !== 'ETHEREUM' ? 5001 : 5000, // 5001 for Mantle Testnet, 5000 for Mantle Mainnet - l1SignerOrProvider: l1Wallet, - l2SignerOrProvider: l2Wallet, - bedrock: true, - }); - - const l1WalletAddress = await l1Wallet.getAddress(); - const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance()); - console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`); - - const arbitratorAddr = readDeployContract( - logName.DEPLOY_ARBITRATOR_LOG_PREFIX, - logName.DEPLOY_LOG_ARBITRATOR, - ethereumName, - ); - if (arbitratorAddr === undefined) { - console.log('The arbitrator address not exist'); - return; - } - console.log(`The arbitrator address: ${arbitratorAddr}`); - - const zkLinkAddr = readDeployContract(logName.DEPLOY_ZKLINK_LOG_PREFIX, logName.DEPLOY_LOG_ZKLINK_PROXY, mantleName); - if (zkLinkAddr === undefined) { - console.log('zkLink address not exist'); - return; - } - console.log(`The zkLink address: ${zkLinkAddr}`); - - const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, mantleName); - const mantleL1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName); - if (mantleL1GatewayAddr === undefined) { - console.log('mantle l1 gateway address not exist'); - return; - } - console.log(`The mantle l1 gateway address: ${mantleL1GatewayAddr}`); - - const mantleL2GatewayAddr = readDeployContract( - logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, - logName.DEPLOY_GATEWAY, - mantleName, - ); - if (mantleL2GatewayAddr === undefined) { - console.log('mantle l2 gateway address not exist'); - return; - } - console.log(`The mantle l2 gateway address: ${mantleL2GatewayAddr}`); - - // pre-execution calldata - const zkLink = await hre.ethers.getContractAt('DummyZkLink', zkLinkAddr, l2Wallet); - const zklinkIface = zkLink.interface; - const blockNumber = await l2Provider.getBlockNumber(); - console.log(`The current block number: ${blockNumber}`); - const l2LogsRootHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`L2 logs root hash ${blockNumber}`)); - console.log(`The l2 logs root hash: ${l2LogsRootHash}`); - const executeCalldata = zklinkIface.encodeFunctionData('syncBatchRoot', [blockNumber, l2LogsRootHash, 0]); - console.log(`The call data: ${executeCalldata}`); - - // forward message to L2 - const gasLimit = 400000; - const arbitrator = await hre.ethers.getContractAt('DummyArbitrator', arbitratorAddr, l1Wallet); - const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [gasLimit]); - console.log('Prepare to forward the message to L2...'); - let tx = await arbitrator.forwardMessage(mantleL1GatewayAddr, 0, executeCalldata, adapterParams); - const txHash = tx.hash; - console.log(`The tx hash: ${txHash}`); - await tx.wait(); - console.log(`The transaction has been executed on L1`); - - /** - * Query the message receipt on L1 via txHash. - */ - // Waiting for the official mantle bridge to forward the message to L2 - const rec = await messenger.waitForMessageReceipt(txHash); - console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`); - console.log('Done'); - - // Example txs: - // https://goerli.etherscan.io/tx/0xf9293e70159720af00a35e0d9a1b0fcd917d075e1b87c2136048ba22d94b5721 - // https://explorer.testnet.mantle.xyz/tx/0xfc6c4da2fe72ce3eb474e5c8371e947cbaeb026ac77fbdb49ca8a3ad70458dfc -}); diff --git a/examples/mantle/scripts/syncL2Requests.js b/examples/mantle/scripts/syncL2Requests.js deleted file mode 100644 index 235c29d..0000000 --- a/examples/mantle/scripts/syncL2Requests.js +++ /dev/null @@ -1,83 +0,0 @@ -const mantle = require('@mantleio/sdk'); -const ethers = require('ethers'); -const { readDeployContract } = require('../../../script/utils'); -const logName = require('../../../script/deploy_log_name'); -const { task, types } = require('hardhat/config'); - -require('dotenv').config(); - -task('syncL2Requests', 'Send sync point to arbitrator') - .addParam('txs', 'New sync point', 100, types.int, true) - .setAction(async (taskArgs, hre) => { - const txs = taskArgs.txs; - console.log(`The sync point: txs: ${txs}`); - - const walletPrivateKey = process.env.DEVNET_PRIVKEY; - const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC); - const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC); - const mantleName = process.env.MANTLE; - const ethereumName = process.env.ETHEREUM; - const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); - const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); - const messenger = new mantle.CrossChainMessenger({ - l1ChainId: ethereumName !== 'ETHEREUM' ? 5 : 1, // 5 for Goerli, 1 for Ethereum - l2ChainId: ethereumName !== 'ETHEREUM' ? 5001 : 5000, // 5001 for Mantle Testnet, 5000 for Mantle Mainnet - l1SignerOrProvider: l1Wallet, - l2SignerOrProvider: l2Wallet, - bedrock: true, - }); - - const l2WalletAddress = await l2Wallet.getAddress(); - const l2WalletBalance = ethers.utils.formatEther(await l2Wallet.getBalance()); - console.log(`${l2WalletAddress} balance on l2: ${l2WalletBalance} $MNT`); - - const mantleL2GatewayAddr = readDeployContract( - logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, - logName.DEPLOY_GATEWAY, - mantleName, - ); - if (mantleL2GatewayAddr === undefined) { - console.log('mantle l2 gateway address not exist'); - return; - } - console.log(`The mantle l2 gateway address: ${mantleL2GatewayAddr}`); - - const zkLinkAddr = readDeployContract( - logName.DEPLOY_ZKLINK_LOG_PREFIX, - logName.DEPLOY_LOG_ZKLINK_PROXY, - mantleName, - ); - if (zkLinkAddr === undefined) { - console.log('zkLink address not exist'); - return; - } - console.log(`The zkLink address: ${zkLinkAddr}`); - - // send txs - const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr, l2Wallet); - console.log(`Send a l2 message to l1...`); - let tx = await zkLink.syncL2Requests(txs); - let txHash = tx.hash; - console.log(`The tx hash: ${txHash}`); - await tx.wait(); - console.log(`The transaction has been executed on L2`); - - /** - * Wait until the message is ready for relay - */ - await messenger.waitForMessageStatus(txHash, mantle.MessageStatus.READY_FOR_RELAY); - /** - * Relay the message on L1 - * Finalizes a cross chain message that was sent from L2 to L1. Only applicable for L2 to L1 messages. Will throw an error if the message has not completed its challenge period yet. - */ - await messenger.finalizeMessage(txHash); - - // Waiting for the official mantle bridge to forward the message to L2 - const rec = await messenger.waitForMessageReceipt(txHash); - console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`); - console.log('Done! Your transaction is executed'); - - // Example txs: - // https://explorer.testnet.mantle.xyz/tx/0xb181480c55d230963ddd19e72e2f24edb6e14ee1616febbef5eb9324af848617 - // https://goerli.etherscan.io/tx/0x866fb187ea541cae276d85964e0c386fb9b1149b2b7c8bb881c3ae3cc360e944 - }); diff --git a/examples/optimism/scripts/opstack-utils.js b/examples/optimism/scripts/opstack-utils.js index a0ebbf2..28aae09 100644 --- a/examples/optimism/scripts/opstack-utils.js +++ b/examples/optimism/scripts/opstack-utils.js @@ -258,7 +258,7 @@ async function syncL2Requests(hre, messenger, ethereumName, opChainName, txs) { console.log(`The prove tx hash: ${tx.hash}`); await tx.wait(); console.log(`The message has been proven`); - await sleep(60 * 1000); // wait for 60 seconds + await sleep(5 * 60 * 1000); // wait for 5 minutes /** * Wait until the message is ready for relay * The final step to sending messages from L2 to L1 is to relay the messages on L1. This can only happen after the fault proof period has elapsed. On OP Sepolia, this is only a few seconds. On OP Mainnet, this takes 7 days. diff --git a/examples/optimism/scripts/optimismTasks.js b/examples/optimism/scripts/optimismTasks.js index 01db2e2..60e4cb7 100644 --- a/examples/optimism/scripts/optimismTasks.js +++ b/examples/optimism/scripts/optimismTasks.js @@ -22,8 +22,8 @@ async function initMessenger() { const l1Wallet = new ethers.Wallet(walletPrivateKey, l1Provider); const l2Wallet = new ethers.Wallet(walletPrivateKey, l2Provider); const messenger = new optimism.CrossChainMessenger({ - l1ChainId: await l1Wallet.getChainId(), // 11155111 for Sepolia, 1 for Ethereum - l2ChainId: await l2Wallet.getChainId(), // 11155420 for OP Sepolia, 10 for OP Mainnet + l1ChainId: await l1Wallet.getChainId(), + l2ChainId: await l2Wallet.getChainId(), l1SignerOrProvider: l1Wallet, l2SignerOrProvider: l2Wallet, });