Skip to content

Commit

Permalink
optimize tx params
Browse files Browse the repository at this point in the history
  • Loading branch information
zkJoaquin committed Mar 20, 2024
1 parent 5b522b2 commit 58b9ee0
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 165 deletions.
57 changes: 22 additions & 35 deletions examples/base/scripts/baseTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ async function initMessenger() {
},
});

return { l1Wallet, l2Wallet, messenger, ethereumName, baseName };
return { messenger, ethereumName, baseName };
}

task('syncBatchRoot', 'Forward message to L2').setAction(async (_, hre) => {
const { l1Wallet, l2Wallet, messenger, ethereumName, baseName } = await initMessenger();
const { messenger, ethereumName, baseName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await syncBatchRoot(hre, messenger, l1Wallet, l2Wallet.provider, ethereumName, baseName, 'base');
const message = await syncBatchRoot(hre, messenger, ethereumName, baseName, 'base');
// Waiting for the official base bridge to forward the message to L2
await messenger.waitForMessageStatus(message, base.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
Expand All @@ -63,13 +61,9 @@ task('syncL2Requests', 'Send sync point to arbitrator')
const txs = taskArgs.txs;
console.log(`The sync point: txs: ${txs}`);

const { l2Wallet, messenger, ethereumName, baseName } = await initMessenger();

const l2WalletAddress = await l2Wallet.getAddress();
const l2WalletBalance = ethers.utils.formatEther(await l2Wallet.getBalance());
console.log(`${l2WalletAddress} balance on l2: ${l2WalletBalance} ether`);
const { messenger, ethereumName, baseName } = await initMessenger();

await syncL2Requests(hre, messenger, l2Wallet, ethereumName, baseName, 'base', txs);
await syncL2Requests(hre, messenger, ethereumName, baseName, 'base', txs);

console.log('Done!');

Expand All @@ -86,38 +80,31 @@ task('setValidator', 'Set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { l1Wallet, l2Wallet, messenger, ethereumName, baseName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

const message = await setValidator(
hre,
messenger,
l2Wallet,
ethereumName,
baseName,
'base',
validatorAddr,
isActive,
);
const { messenger, ethereumName, baseName } = await initMessenger();

const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await setValidator(hre, messenger, ethereumName, baseName, 'base', validatorAddr, isActive);
// Waiting for the official base bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
await messenger.waitForMessageStatus(message, base.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`);
console.log('Done');
});

task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => {
const { l1Wallet, messenger, ethereumName, baseName } = await initMessenger();
const { messenger, ethereumName, baseName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await changeFeeParams(hre, messenger, l1Wallet, ethereumName, baseName, 'base');
const message = await changeFeeParams(hre, messenger, ethereumName, baseName, 'base');
// Waiting for the official base bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
await messenger.waitForMessageStatus(message, base.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`);
console.log('Done');
});
Expand Down
69 changes: 33 additions & 36 deletions examples/blast/scripts/blastTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,17 @@ async function initMessenger() {
},
});

return { l1Wallet, l2Wallet, messenger, messengerL1Contracts, yieldManagerAddress, ethereumName, blastName };
return { messenger, messengerL1Contracts, yieldManagerAddress, ethereumName, blastName };
}

task('syncBatchRoot', 'Forward message to L2').setAction(async (_, hre) => {
const { l1Wallet, l2Wallet, messenger, ethereumName, blastName } = await initMessenger();
const { messenger, ethereumName, blastName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await syncBatchRoot(hre, messenger, l1Wallet, l2Wallet.provider, ethereumName, blastName, 'blast');
const message = await syncBatchRoot(hre, messenger, ethereumName, blastName, 'blast');

await messenger.waitForMessageStatus(message, blast.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
Expand All @@ -81,8 +79,9 @@ task('syncL2Requests', 'Send sync point to arbitrator')
const txs = taskArgs.txs;
console.log(`The sync point: txs: ${txs}`);

const { l1Wallet, l2Wallet, messenger, messengerL1Contracts, yieldManagerAddress, ethereumName, blastName } =
await initMessenger();
const { messenger, messengerL1Contracts, yieldManagerAddress, ethereumName, blastName } = await initMessenger();
const l1Wallet = messenger.l1Signer;
const l2Wallet = messenger.l2Signer;

const optimismPortalContract = await hre.ethers.getContractAt(
OPTIMISM_PORTAL_ABI,
Expand Down Expand Up @@ -147,6 +146,7 @@ task('syncL2Requests', 'Send sync point to arbitrator')
const message = (await messenger.getMessagesByTransaction(txHash)).pop();
let status = await messenger.getMessageStatus(message);
console.log(`The message status update to: ${blast.MessageStatus[status]}`);
const feeData = await l1Wallet.getFeeData();

/**
* Wait until the message is ready to prove
Expand All @@ -157,7 +157,10 @@ task('syncL2Requests', 'Send sync point to arbitrator')
* 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...`);
tx = await messenger.proveMessage(message);
tx = await messenger.proveMessage(message, {
maxFeePerGas: feeData.maxFeePerGas.mul(2),
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas.mul(2),
});
console.log(`The prove tx hash: ${tx.hash}`);
await tx.wait();
console.log(`The message has been proven`);
Expand Down Expand Up @@ -188,14 +191,21 @@ task('syncL2Requests', 'Send sync point to arbitrator')
hintId = await yieldManagerContract.findCheckpointHint(requestId, 1, lastCheckPoint);
}
console.log(`The hint id: ${hintId}`);
tx = await optimismPortalContract.finalizeWithdrawalTransaction(hintId, [
messageInfos.nonce,
messageInfos.sender,
messageInfos.target,
messageInfos.value,
messageInfos.gasLimit,
messageInfos.data,
]);
tx = await optimismPortalContract.finalizeWithdrawalTransaction(
hintId,
[
messageInfos.nonce,
messageInfos.sender,
messageInfos.target,
messageInfos.value,
messageInfos.gasLimit,
messageInfos.data,
],
{
maxFeePerGas: feeData.maxFeePerGas.mul(2),
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas.mul(2),
},
);
console.log(`The relay tx hash: ${tx.hash}`);
await tx.wait();
console.log(`The message has been relayed`);
Expand All @@ -214,24 +224,13 @@ task('setValidator', 'Set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { l1Wallet, l2Wallet, messenger, ethereumName, blastName } = await initMessenger();
const { messenger, ethereumName, blastName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await setValidator(
hre,
messenger,
l1Wallet,
ethereumName,
blastName,
'blast',
validatorAddr,
isActive,
);
const message = await setValidator(hre, messenger, ethereumName, blastName, 'blast', validatorAddr, isActive);

await messenger.waitForMessageStatus(message, blast.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
Expand All @@ -240,15 +239,13 @@ task('setValidator', 'Set validator for zkLink')
});

task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArgs, hre) => {
const { l1Wallet, l2Wallet, messenger, ethereumName, blastName } = await initMessenger();
const { messenger, ethereumName, blastName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const l2Wallet = messenger.l2Signer;
const l2CurrentBlock = await l2Wallet.provider.getBlockNumber();
console.log(`Current block on l2: ${l2CurrentBlock}`);

const message = await changeFeeParams(hre, messenger, l1Wallet, ethereumName, blastName, 'blast');
const message = await changeFeeParams(hre, messenger, ethereumName, blastName, 'blast');

await messenger.waitForMessageStatus(message, blast.MessageStatus.RELAYED);
const rec = await messenger.getMessageReceipt(message, 0, l2CurrentBlock, 'latest');
Expand Down
45 changes: 10 additions & 35 deletions examples/manta/scripts/mantaTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ async function initMessenger() {
},
});

return { l1Wallet, l2Wallet, messenger, ethereumName, mantaName };
return { messenger, ethereumName, mantaName };
}

task('syncBatchRoot', 'Forward message to L2').setAction(async (_, hre) => {
const { l1Wallet, l2Wallet, messenger, ethereumName, mantaName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const { messenger, ethereumName, mantaName } = await initMessenger();

const message = await syncBatchRoot(hre, messenger, l1Wallet, l2Wallet.provider, ethereumName, mantaName, 'manta');
const message = await syncBatchRoot(hre, messenger, ethereumName, mantaName, 'manta');
// 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)}`);
Expand All @@ -60,13 +56,9 @@ task('syncL2Requests', 'Send sync point to arbitrator')
const txs = taskArgs.txs;
console.log(`The sync point: txs: ${txs}`);

const { l2Wallet, messenger, ethereumName, mantaName } = await initMessenger();

const l2WalletAddress = await l2Wallet.getAddress();
const l2WalletBalance = ethers.utils.formatEther(await l2Wallet.getBalance());
console.log(`${l2WalletAddress} balance on l2: ${l2WalletBalance} ether`);
const { messenger, ethereumName, mantaName } = await initMessenger();

await syncL2Requests(hre, messenger, l2Wallet, ethereumName, mantaName, 'manta', txs);
await syncL2Requests(hre, messenger, ethereumName, mantaName, 'manta', txs);

console.log('Done!');

Expand All @@ -76,13 +68,9 @@ task('syncL2Requests', 'Send sync point to arbitrator')
});

task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => {
const { l1Wallet, messenger, ethereumName, mantaName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const { messenger, ethereumName, mantaName } = await initMessenger();

const message = await changeFeeParams(hre, messenger, l1Wallet, ethereumName, mantaName, 'manta');
const message = await changeFeeParams(hre, messenger, ethereumName, mantaName, 'manta');

// Waiting for the official manta bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
Expand All @@ -98,22 +86,9 @@ task('setValidator', 'Set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { l1Wallet, messenger, ethereumName, mantaName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

const message = await setValidator(
hre,
messenger,
l1Wallet,
ethereumName,
mantaName,
'manta',
validatorAddr,
isActive,
);
const { messenger, ethereumName, mantaName } = await initMessenger();

const message = await setValidator(hre, messenger, ethereumName, mantaName, 'manta', validatorAddr, isActive);

// Waiting for the official manta bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
Expand Down
55 changes: 11 additions & 44 deletions examples/optimism/scripts/optimismTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,13 @@ async function initMessenger() {
l2SignerOrProvider: l2Wallet,
});

return { l1Wallet, l2Wallet, messenger, ethereumName, optimismName };
return { messenger, ethereumName, optimismName };
}

task('syncBatchRoot', 'Forward message to L2').setAction(async (_, hre) => {
const { l1Wallet, l2Wallet, messenger, ethereumName, optimismName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

const message = await syncBatchRoot(
hre,
messenger,
l1Wallet,
l2Wallet.provider,
ethereumName,
optimismName,
'optimism',
);
const { messenger, ethereumName, optimismName } = await initMessenger();

const message = await syncBatchRoot(hre, messenger, ethereumName, optimismName, 'optimism');
// Waiting for the official optimism bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
console.log(`The tx receipt: ${JSON.stringify(rec, null, 2)}`);
Expand All @@ -61,13 +49,9 @@ task('syncL2Requests', 'Send sync point to arbitrator')
const txs = taskArgs.txs;
console.log(`The sync point: txs: ${txs}`);

const { l2Wallet, messenger, ethereumName, optimismName } = await initMessenger();

const l2WalletAddress = await l2Wallet.getAddress();
const l2WalletBalance = ethers.utils.formatEther(await l2Wallet.getBalance());
console.log(`${l2WalletAddress} balance on l2: ${l2WalletBalance} ether`);
const { messenger, ethereumName, optimismName } = await initMessenger();

await syncL2Requests(hre, messenger, l2Wallet, ethereumName, optimismName, 'optimism', txs);
await syncL2Requests(hre, messenger, ethereumName, optimismName, 'optimism', txs);

console.log('Done! Your transaction is executed');

Expand All @@ -84,36 +68,19 @@ task('setValidator', 'Set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { l1Wallet, messenger, ethereumName, optimismName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

const message = await setValidator(
hre,
messenger,
l1Wallet,
ethereumName,
optimismName,
'optimism',
validatorAddr,
isActive,
);
const { messenger, ethereumName, optimismName } = await initMessenger();

const message = await setValidator(hre, messenger, ethereumName, optimismName, 'optimism', validatorAddr, isActive);
// Waiting for the official optimism 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('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre) => {
const { l1Wallet, messenger, ethereumName, optimismName } = await initMessenger();

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.utils.formatEther(await l1Wallet.getBalance());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);
const { messenger, ethereumName, optimismName } = await initMessenger();

const message = await changeFeeParams(hre, messenger, l1Wallet, ethereumName, optimismName, 'optimism');
const message = await changeFeeParams(hre, messenger, ethereumName, optimismName, 'optimism');

// Waiting for the official optimism bridge to forward the message to L2
const rec = await messenger.waitForMessageReceipt(message);
Expand Down
Loading

0 comments on commit 58b9ee0

Please sign in to comment.