Skip to content

Commit

Permalink
add encode calldata for arbitrator
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Mar 14, 2024
1 parent 22355f8 commit b311ccc
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 2 deletions.
55 changes: 54 additions & 1 deletion examples/blast/scripts/changeFeeParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { readDeployContract, getLogName } = require('../../../script/utils');
const logName = require('../../../script/deploy_log_name');
const { L1_MAINNET_CONTRACTS, L1_TESTNET_CONTRACTS } = require('./constants');
const { task } = require('hardhat/config');
const { INIT_FEE_PARAMS } = require('../../../script/zksync_era');
require('dotenv').config();

task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArgs, hre) => {
Expand Down Expand Up @@ -77,7 +78,6 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArg

// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr, l2Wallet);
const { INIT_FEE_PARAMS } = require('../../../script/zksync_era');
const executeCalldata = zkLink.interface.encodeFunctionData('changeFeeParams', [INIT_FEE_PARAMS]);
const gateway = await hre.ethers.getContractAt('OptimismGateway', blastL1GatewayAddr, l1Wallet);
const sendData = gateway.interface.encodeFunctionData('claimMessageCallback', [0, executeCalldata]);
Expand Down Expand Up @@ -106,3 +106,56 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArg
console.log('Done');
// Waiting for the official blast bridge to forward the message to L2
});

task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (taskArgs, hre) => {
const blastName = process.env.BLAST;
const ethereumName = process.env.ETHEREUM;
const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, blastName);
const blastL1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName);
if (blastL1GatewayAddr === undefined) {
console.log('blast l1 gateway address not exist');
return;
}
console.log(`The blast l1 gateway address: ${blastL1GatewayAddr}`);

const zkLinkFactory = await hre.ethers.getContractFactory('ZkLink');
const executeCalldata = zkLinkFactory.interface.encodeFunctionData('changeFeeParams', [INIT_FEE_PARAMS]);
const gatewayFactory = await hre.ethers.getContractFactory('OptimismGateway');
const sendData = gatewayFactory.interface.encodeFunctionData('claimMessageCallback', [0, executeCalldata]);

const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC);
const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC);
const messengerL1Contracts = ethereumName !== 'ETHEREUM' ? L1_TESTNET_CONTRACTS : L1_MAINNET_CONTRACTS;
const messenger = new blast.CrossChainMessenger({
l1ChainId: (await l1Provider.getNetwork()).chainId, // 11155111 for Sepolia, 1 for Ethereum
l2ChainId: (await l2Provider.getNetwork()).chainId, // 168587773 for Blast Testnet, 81457 for Blast Mainnet
l1SignerOrProvider: l1Provider,
l2SignerOrProvider: l2Provider,
bedrock: false,
bridges: {
Standard: {
Adapter: blast.StandardBridgeAdapter,
l1Bridge: messengerL1Contracts.L1StandardBridge,
l2Bridge: '0x4200000000000000000000000000000000000010',
},
},
contracts: {
l1: messengerL1Contracts,
},
});

const gasLimit = await messenger.estimateGas.sendMessage({
direction: 0, // L1_TO_L2, Estimating the Gas Required on L2
target: blastL1GatewayAddr,
message: sendData,
});
console.log(`The gas limit: ${gasLimit}`);
const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [gasLimit]);
const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const calldata = arbitratorFactory.interface.encodeFunctionData('changeFeeParams', [
blastL1GatewayAddr,
INIT_FEE_PARAMS,
adapterParams,
]);
console.log(`The changeFeeParams calldata: ${calldata}`);
});
61 changes: 61 additions & 0 deletions examples/blast/scripts/setValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,64 @@ task('setValidator', 'Set validator for zkLink')
console.log('Done');
// Waiting for the official blast bridge to forward the message to L2
});

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 blastName = process.env.BLAST;
const ethereumName = process.env.ETHEREUM;
const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, blastName);
const blastL1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName);
if (blastL1GatewayAddr === undefined) {
console.log('blast l1 gateway address not exist');
return;
}
console.log(`The blast l1 gateway address: ${blastL1GatewayAddr}`);

const zkLinkFactory = await hre.ethers.getContractFactory('ZkLink');
const executeCalldata = zkLinkFactory.interface.encodeFunctionData('setValidator', [validatorAddr, isActive]);
const gatewayFactory = await hre.ethers.getContractFactory('OptimismGateway');
const sendData = gatewayFactory.interface.encodeFunctionData('claimMessageCallback', [0, executeCalldata]);

const l1Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L1RPC);
const l2Provider = new ethers.providers.StaticJsonRpcProvider(process.env.L2RPC);
const messengerL1Contracts = ethereumName !== 'ETHEREUM' ? L1_TESTNET_CONTRACTS : L1_MAINNET_CONTRACTS;
const messenger = new blast.CrossChainMessenger({
l1ChainId: (await l1Provider.getNetwork()).chainId, // 11155111 for Sepolia, 1 for Ethereum
l2ChainId: (await l2Provider.getNetwork()).chainId, // 168587773 for Blast Testnet, 81457 for Blast Mainnet
l1SignerOrProvider: l1Provider,
l2SignerOrProvider: l2Provider,
bedrock: false,
bridges: {
Standard: {
Adapter: blast.StandardBridgeAdapter,
l1Bridge: messengerL1Contracts.L1StandardBridge,
l2Bridge: '0x4200000000000000000000000000000000000010',
},
},
contracts: {
l1: messengerL1Contracts,
},
});

const gasLimit = await messenger.estimateGas.sendMessage({
direction: 0, // L1_TO_L2, Estimating the Gas Required on L2
target: blastL1GatewayAddr,
message: sendData,
});
console.log(`The gas limit: ${gasLimit}`);
const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [gasLimit]);
const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const calldata = arbitratorFactory.interface.encodeFunctionData('setValidator', [
blastL1GatewayAddr,
validatorAddr,
isActive,
adapterParams,
]);
console.log(`The changeFeeParams calldata: ${calldata}`);
});
42 changes: 41 additions & 1 deletion examples/linea/scripts/setSecondaryGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

task('setSecondaryGateway', 'Send secondary gateway')
task('setSecondaryGateway', 'Set secondary gateway')
.addOptionalParam(
'arbitrator',
'The arbitrator address (default get from arbitrator deploy log)',
Expand Down Expand Up @@ -113,3 +113,43 @@ task('setSecondaryGateway', 'Send secondary gateway')
}
console.log('Done');
});

task('encodeSetSecondaryGateway', 'Get the calldata of set secondary gateway')
.addParam('targetNetwork', 'L2 network name', undefined, types.string, false)
.addOptionalParam('active', 'Enable the gateway?', true, types.boolean)
.setAction(async (taskArgs, hre) => {
const ethereumName = process.env.ETHEREUM;
const lineaName = process.env.LINEA;
console.log(`Ethereum net name: ${ethereumName}`);
console.log(`Linea net name: ${lineaName}`);

let targetNetwork = taskArgs.targetNetwork;
const active = taskArgs.active;
console.log(`Enable the gateway? ${active}`);
if (targetNetwork === lineaName) {
console.log('Can not set for primary chain');
return;
}

let l1GatewayAddr;
if (targetNetwork === ethereumName) {
l1GatewayAddr = readDeployContract(logName.DEPLOY_ETH_GATEWAY_LOG_PREFIX, logName.DEPLOY_GATEWAY, ethereumName);
} else {
const l1GatewayLogName = getLogName(logName.DEPLOY_L1_GATEWAY_LOG_PREFIX, targetNetwork);
l1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, ethereumName);
}
if (l1GatewayAddr === undefined) {
console.log('L1 gateway address not found');
return;
}
console.log(`The secondary chain l1 gateway address: ${l1GatewayAddr}`);

const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const adapterParams = '0x';
const calldata = arbitratorFactory.interface.encodeFunctionData('setSecondaryChainGateway', [
l1GatewayAddr,
active,
adapterParams,
]);
console.log(`The setSecondaryChainGateway calldata: ${calldata}`);
});

0 comments on commit b311ccc

Please sign in to comment.