Skip to content

Commit

Permalink
feat: add claimL1Tx for linea
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed May 20, 2024
1 parent ac8d0e2 commit 8bf7fa7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/linea/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require('./scripts/setValidator');
require('./scripts/changeFeeParams');
require('./scripts/setSecondaryGateway');
require('./scripts/governance');
require('./scripts/claimL1Tx');

const BaseConfig = require('../../hardhat.base.config');

Expand Down
16 changes: 16 additions & 0 deletions examples/linea/scripts/claimL1Tx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { task, types } = require('hardhat/config');
const { claimL1ToL2Message } = require('./common');

require('dotenv').config();

task('claimL1Tx', 'Claim l1 tx')
.addParam('txHash', 'The l2 to l1 tx hash', undefined, types.string)
.addOptionalParam('index', 'The l2 to l1 message index', 0, types.int)
.setAction(async taskArgs => {
const l2ToL1TxHash = taskArgs.txHash;
const messageIndex = taskArgs.index;
console.log(`The l2 to l1 tx hash: ${l2ToL1TxHash}`);
console.log(`The message index: ${messageIndex}`);

await claimL1ToL2Message(l2ToL1TxHash, messageIndex);
});
6 changes: 4 additions & 2 deletions examples/linea/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ function initSDK() {
return { lineaL1Contract, lineaL2Contract, lineaL1ClaimingService };
}

async function claimL1ToL2Message(l1TxHash) {
async function claimL1ToL2Message(l1TxHash, messageIndex) {
const sdkInit = initSDK();
const lineaL1Contract = sdkInit.lineaL1Contract;
const lineaL2Contract = sdkInit.lineaL2Contract;

/**
* Query the transaction status on L2 via messageHash.
*/
const message = (await lineaL1Contract.getMessagesByTransactionHash(l1TxHash)).pop();
messageIndex = messageIndex ?? 0;
const messages = await lineaL1Contract.getMessagesByTransactionHash(l1TxHash);
const message = messages[messageIndex];

// Waiting for the official Linea bridge to forward the message to L2
// And manually claim the message on L2
Expand Down

0 comments on commit 8bf7fa7

Please sign in to comment.