From d17844989f3d38a2d214abcb50918025fa309213 Mon Sep 17 00:00:00 2001 From: zkJoaquin Date: Sat, 13 Apr 2024 19:39:42 +0800 Subject: [PATCH] add proveL2Tx task for mantle/manta --- examples/manta/package-lock.json | 22 ++++++++++++++++ examples/manta/package.json | 1 + examples/manta/scripts/mantaTasks.js | 35 ++++++++++++++++++++++++++ examples/mantle/package-lock.json | 22 ++++++++++++++++ examples/mantle/package.json | 1 + examples/mantle/scripts/mantleTasks.js | 35 ++++++++++++++++++++++++++ 6 files changed, 116 insertions(+) diff --git a/examples/manta/package-lock.json b/examples/manta/package-lock.json index 3ff4ab4..e03a4dc 100644 --- a/examples/manta/package-lock.json +++ b/examples/manta/package-lock.json @@ -15,6 +15,7 @@ "devDependencies": { "@eth-optimism/sdk": "^3.2.3", "@nomiclabs/hardhat-ethers": "^2.0.2", + "@rainbow-me/fee-suggestions": "^2.1.0", "ethers": "^5.7.2", "hardhat": "^2.9.1" } @@ -1212,6 +1213,18 @@ "hardhat": "^2.0.0" } }, + "node_modules/@rainbow-me/fee-suggestions": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/@rainbow-me/fee-suggestions/-/fee-suggestions-2.1.0.tgz", + "integrity": "sha512-Eo2E3BtlKOeeS8kwmX1tgoeLY97Qf10FUZHnXNx38Yxbe+RgOLYyftbtjwhjttKI6CEYfJ7mEP+lbh/BlgPUAg==", + "dev": true, + "dependencies": { + "@ethersproject/providers": "^5.5.0", + "bignumber.js": "^9.0.1", + "ethers": "^5.4.2", + "moving-averages": "^4.0.6" + } + }, "node_modules/@scure/base": { "version": "1.1.5", "resolved": "https://registry.npmmirror.com/@scure/base/-/base-1.1.5.tgz", @@ -3150,6 +3163,15 @@ "node": ">=10" } }, + "node_modules/moving-averages": { + "version": "4.0.6", + "resolved": "https://registry.npmmirror.com/moving-averages/-/moving-averages-4.0.6.tgz", + "integrity": "sha512-Jv+mH0emTFP40Q5ONsBqTfIO9NuUyK9zuW4pWbOzWJm8jEqpLBtAH2CnE2MFIuH/G9f9nDugmnDVUJaHx9jckw==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", diff --git a/examples/manta/package.json b/examples/manta/package.json index e576784..6aaad3c 100644 --- a/examples/manta/package.json +++ b/examples/manta/package.json @@ -6,6 +6,7 @@ "devDependencies": { "@eth-optimism/sdk": "^3.2.3", "@nomiclabs/hardhat-ethers": "^2.0.2", + "@rainbow-me/fee-suggestions": "^2.1.0", "ethers": "^5.7.2", "hardhat": "^2.9.1" }, diff --git a/examples/manta/scripts/mantaTasks.js b/examples/manta/scripts/mantaTasks.js index 5f74fd5..0215264 100644 --- a/examples/manta/scripts/mantaTasks.js +++ b/examples/manta/scripts/mantaTasks.js @@ -12,6 +12,7 @@ const { } = require('../../optimism/scripts/opstack-utils'); const { L1_MAINNET_CONTRACTS, L1_TESTNET_CONTRACTS } = require('./constants'); const { task, types } = require('hardhat/config'); +const { suggestFees } = require('@rainbow-me/fee-suggestions'); require('dotenv').config(); async function initMessenger() { @@ -69,6 +70,40 @@ task('syncL2Requests', 'Send sync point to arbitrator') // https://goerli.etherscan.io/tx/0x54ce6421e1d9c1e7d2c35af292c9e3bbaf632b60115556a94b7fb61e53905599 }); +task('proveL2Tx', 'Prove L2 tx') + .addParam('txHash', 'The tx hash to prove', undefined, types.string) + .setAction(async taskArgs => { + const txHash = taskArgs.txHash; + console.log(`The l2 tx hash: ${txHash}`); + + const { messenger } = await initMessenger(); + + const status = await messenger.getMessageStatus(txHash); + console.log(`The message status update to: ${manta.MessageStatus[status]}`); + + const fees = await suggestFees(messenger.l1Provider); + console.log(`The suggest fees: ${JSON.stringify(fees)}`); + const baseFee = ethers.BigNumber.from(fees.baseFeeSuggestion); + const maxPriorityFeePerGas = ethers.BigNumber.from(fees.maxPriorityFeeSuggestions.fast); + const maxFeePerGas = maxPriorityFeePerGas.add(baseFee.mul(ethers.BigNumber.from(2))); + /** + * Wait until the message is ready to prove + * This step can take a few minutes. + */ + await messenger.waitForMessageStatus(txHash, manta.MessageStatus.READY_TO_PROVE); + /** + * Once the message is ready to be proven, you'll send an L1 transaction to prove that the message was sent on L2. + */ + console.log(`Proving the message...`); + const tx = await messenger.proveMessage(txHash, { + maxFeePerGas: maxFeePerGas, + maxPriorityFeePerGas: maxPriorityFeePerGas, + }); + console.log(`The prove tx hash: ${tx.hash}`); + await tx.wait(); + console.log(`The message has been proven`); + }); + task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => { const { messenger, ethereumName, mantaName } = await initMessenger(); diff --git a/examples/mantle/package-lock.json b/examples/mantle/package-lock.json index ec9c79d..391bbf3 100644 --- a/examples/mantle/package-lock.json +++ b/examples/mantle/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@mantleio/sdk": "^1.0.3", "@nomiclabs/hardhat-ethers": "^2.0.2", + "@rainbow-me/fee-suggestions": "^2.1.0", "ethers": "^5.7.2", "hardhat": "^2.9.1" } @@ -1235,6 +1236,18 @@ "integrity": "sha512-+wuegAMaLcZnLCJIvrVUDzA9z/Wp93f0Dla/4jJvIhijRrPabjQbZe6fWiECLaJyfn5ci9fqf9vTw3xpQOad2A==", "dev": true }, + "node_modules/@rainbow-me/fee-suggestions": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/@rainbow-me/fee-suggestions/-/fee-suggestions-2.1.0.tgz", + "integrity": "sha512-Eo2E3BtlKOeeS8kwmX1tgoeLY97Qf10FUZHnXNx38Yxbe+RgOLYyftbtjwhjttKI6CEYfJ7mEP+lbh/BlgPUAg==", + "dev": true, + "dependencies": { + "@ethersproject/providers": "^5.5.0", + "bignumber.js": "^9.0.1", + "ethers": "^5.4.2", + "moving-averages": "^4.0.6" + } + }, "node_modules/@scure/base": { "version": "1.1.5", "resolved": "https://registry.npmmirror.com/@scure/base/-/base-1.1.5.tgz", @@ -3183,6 +3196,15 @@ "node": ">=10" } }, + "node_modules/moving-averages": { + "version": "4.0.6", + "resolved": "https://registry.npmmirror.com/moving-averages/-/moving-averages-4.0.6.tgz", + "integrity": "sha512-Jv+mH0emTFP40Q5ONsBqTfIO9NuUyK9zuW4pWbOzWJm8jEqpLBtAH2CnE2MFIuH/G9f9nDugmnDVUJaHx9jckw==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", diff --git a/examples/mantle/package.json b/examples/mantle/package.json index 5bb7028..3a2d9c1 100644 --- a/examples/mantle/package.json +++ b/examples/mantle/package.json @@ -6,6 +6,7 @@ "devDependencies": { "@mantleio/sdk": "^1.0.3", "@nomiclabs/hardhat-ethers": "^2.0.2", + "@rainbow-me/fee-suggestions": "^2.1.0", "ethers": "^5.7.2", "hardhat": "^2.9.1" }, diff --git a/examples/mantle/scripts/mantleTasks.js b/examples/mantle/scripts/mantleTasks.js index 6cafefd..2f32553 100644 --- a/examples/mantle/scripts/mantleTasks.js +++ b/examples/mantle/scripts/mantleTasks.js @@ -2,6 +2,7 @@ const mantle = require('@mantleio/sdk'); const { applyL1ToL2Alias } = require('@mantleio/core-utils'); const ethers = require('ethers'); const { BigNumber, Contract } = require('ethers'); +const { suggestFees } = require('@rainbow-me/fee-suggestions'); const { syncBatchRoot, syncL2Requests, @@ -67,6 +68,40 @@ task('syncL2Requests', 'Send sync point to arbitrator') // https://sepolia.etherscan.io/tx/0x1a0f721a5d0c4bcc334ad6d54a60ae4ce4b5e52c71f3e48f62e2f2c980885b61 }); +task('proveL2Tx', 'Prove L2 tx') + .addParam('txHash', 'The tx hash to prove', undefined, types.string) + .setAction(async taskArgs => { + const txHash = taskArgs.txHash; + console.log(`The l2 tx hash: ${txHash}`); + + const { messenger } = await initMessenger(); + + const status = await messenger.getMessageStatus(txHash); + console.log(`The message status update to: ${mantle.MessageStatus[status]}`); + + const fees = await suggestFees(messenger.l1Provider); + console.log(`The suggest fees: ${JSON.stringify(fees)}`); + const baseFee = BigNumber.from(fees.baseFeeSuggestion); + const maxPriorityFeePerGas = BigNumber.from(fees.maxPriorityFeeSuggestions.fast); + const maxFeePerGas = maxPriorityFeePerGas.add(baseFee.mul(BigNumber.from(2))); + /** + * Wait until the message is ready to prove + * This step can take a few minutes. + */ + await messenger.waitForMessageStatus(txHash, mantle.MessageStatus.READY_TO_PROVE); + /** + * Once the message is ready to be proven, you'll send an L1 transaction to prove that the message was sent on L2. + */ + console.log(`Proving the message...`); + const tx = await messenger.proveMessage(txHash, { + maxFeePerGas: maxFeePerGas, + maxPriorityFeePerGas: maxPriorityFeePerGas, + }); + console.log(`The prove tx hash: ${tx.hash}`); + await tx.wait(); + console.log(`The message has been proven`); + }); + task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => { const { messenger, ethereumName, mantleName } = await initMessenger();