-
Notifications
You must be signed in to change notification settings - Fork 75
feat(Scroll): add rescue script for stuck txns #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
james-a-morris
merged 3 commits into
master
from
james/acx-1818-add-ability-to-rescue-scroll-funds
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* eslint-disable camelcase */ | ||
| import { task } from "hardhat/config"; | ||
| import { Contract, Signer, ethers } from "ethers"; | ||
| import { L1_ADDRESS_MAP } from "../deploy/consts"; | ||
|
|
||
| require("dotenv").config(); | ||
|
|
||
| const relayMessengerAbi = [ | ||
| { | ||
| anonymous: false, | ||
| inputs: [ | ||
| { | ||
| indexed: true, | ||
| internalType: "address", | ||
| name: "sender", | ||
| type: "address", | ||
| }, | ||
| { | ||
| indexed: true, | ||
| internalType: "address", | ||
| name: "target", | ||
| type: "address", | ||
| }, | ||
| { | ||
| indexed: false, | ||
| internalType: "uint256", | ||
| name: "value", | ||
| type: "uint256", | ||
| }, | ||
| { | ||
| indexed: false, | ||
| internalType: "uint256", | ||
| name: "messageNonce", | ||
| type: "uint256", | ||
| }, | ||
| { | ||
| indexed: false, | ||
| internalType: "uint256", | ||
| name: "gasLimit", | ||
| type: "uint256", | ||
| }, | ||
| { | ||
| indexed: false, | ||
| internalType: "bytes", | ||
| name: "message", | ||
| type: "bytes", | ||
| }, | ||
| ], | ||
| name: "SentMessage", | ||
| type: "event", | ||
| }, | ||
| { | ||
| inputs: [ | ||
| { | ||
| internalType: "address", | ||
| name: "_from", | ||
| type: "address", | ||
| }, | ||
| { | ||
| internalType: "address", | ||
| name: "_to", | ||
| type: "address", | ||
| }, | ||
| { | ||
| internalType: "uint256", | ||
| name: "_value", | ||
| type: "uint256", | ||
| }, | ||
| { | ||
| internalType: "uint256", | ||
| name: "_messageNonce", | ||
| type: "uint256", | ||
| }, | ||
| { | ||
| internalType: "bytes", | ||
| name: "_message", | ||
| type: "bytes", | ||
| }, | ||
| { | ||
| internalType: "uint32", | ||
| name: "_newGasLimit", | ||
| type: "uint32", | ||
| }, | ||
| { | ||
| internalType: "address", | ||
| name: "_refundAddress", | ||
| type: "address", | ||
| }, | ||
| ], | ||
| name: "replayMessage", | ||
| outputs: [], | ||
| stateMutability: "payable", | ||
| type: "function", | ||
| }, | ||
| ]; | ||
|
|
||
| task("rescue-stuck-scroll-txn", "Rescue a failed Scroll transaction") | ||
| .addParam("l1Hash", "Txn of the L1 message to rescue") | ||
| .addParam("gasLimit", "Gas limit to use for the rescue transaction") | ||
| .setAction(async function (taskArguments, hre_: any) { | ||
| const chainId = await hre_.getChainId(); | ||
| if (!["1", "11155111"].includes(String(chainId))) { | ||
| throw new Error("This script can only be run on Sepolia or Ethereum mainnet"); | ||
| } | ||
| const signer = (await hre_.ethers.getSigners())[0] as unknown as Signer; | ||
| const messengerContract = new Contract(L1_ADDRESS_MAP[chainId].scrollMessengerRelay, relayMessengerAbi, signer); | ||
|
|
||
| const txn = await signer.provider?.getTransactionReceipt(taskArguments.l1Hash); | ||
| const relevantEvent = txn?.logs?.find( | ||
| (log) => log.topics[0] === messengerContract.interface.getEventTopic("SentMessage") | ||
| ); | ||
| if (!relevantEvent) { | ||
| throw new Error("No relevant event found. Is this a Scroll bridge transaction?"); | ||
| } | ||
| const decodedEvent = messengerContract.interface.parseLog(relevantEvent); | ||
| const { sender, target, value, messageNonce, message } = decodedEvent.args; | ||
| const refundAddress = await signer.getAddress(); | ||
|
|
||
| console.debug("Log found. Event Decoded."); | ||
| console.debug("Will replay with these parameters:", { | ||
| _from: sender, | ||
| _to: target, | ||
| _value: value.toString(), | ||
| _messageNonce: messageNonce.toString(), | ||
| _message: message.toString(), | ||
| _newGasLimit: taskArguments.gasLimit, | ||
| _refundAddress: refundAddress, | ||
| }); | ||
| console.debug("Replaying message (sending with 0.001ETH )..."); | ||
| const resultingTxn = await messengerContract.replayMessage( | ||
| sender, // _from | ||
| target, // _to | ||
| value, // _value | ||
| messageNonce, // _messageNonce | ||
| message, // _message | ||
| ethers.BigNumber.from(taskArguments.gasLimit), // _newGasLimit | ||
| refundAddress, // _refundAddress | ||
| { | ||
| // 0.001 ETH to be sent to the Scroll relayer (to cover L1 gas costs) | ||
| // Using recommended value default as described here: https://docs.scroll.io/en/developers/l1-and-l2-bridging/eth-and-erc20-token-bridge/ | ||
| // *Any* leftover ETH will be immediately refunded to the signer - this is just the L1 gas cost for submitting the transaction | ||
| value: ethers.utils.parseEther("0.001"), | ||
| } | ||
| ); | ||
| console.log("Replay transaction hash:", resultingTxn.hash); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.