Skip to content

Commit

Permalink
add encode call data for scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Jun 10, 2024
1 parent e8c1afd commit e4d2843
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/scroll/scripts/changeFeeParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { readDeployContract, getLogName } = require('../../../script/utils');
const logName = require('../../../script/deploy_log_name');
const { task } = require('hardhat/config');
const { ScrollSDK } = require('./scrollSDK');
const { INIT_FEE_PARAMS } = require('../../../script/zksync_era');

require('dotenv').config();

Expand Down Expand Up @@ -52,7 +53,6 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArg
* finalizeMessageGasLimit: the gas limit for the L2 to finalize the message.
*/
const zkLink = await hre.ethers.getContractFactory('ZkLink');
const { INIT_FEE_PARAMS } = require('../../../script/zksync_era');
const zkLinkCallValue = BigInt(0);
const zkLinkCallData = zkLink.interface.encodeFunctionData('changeFeeParams', [INIT_FEE_PARAMS]);
const l2GatewayFactory = await hre.ethers.getContractFactory('ScrollL2Gateway');
Expand Down Expand Up @@ -81,3 +81,25 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArg
// Waiting for the official Scroll bridge to forward the message to L2
// No user action is required for follow-up.
});

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

const adapterParams = AbiCoder.defaultAbiCoder().encode(['uint256'], [200000]);

const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const calldata = arbitratorFactory.interface.encodeFunctionData('changeFeeParams', [
l1GatewayAddr,
INIT_FEE_PARAMS,
adapterParams,
]);
console.log(`The changeFeeParams calldata: ${calldata}`);
});
30 changes: 30 additions & 0 deletions examples/scroll/scripts/setValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,33 @@ task('setValidator', 'Set validator for zkLink')
// Waiting for the official Scroll bridge to forward the message to L2
// No user action is required for follow-up.
});

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

const adapterParams = AbiCoder.defaultAbiCoder().encode(['uint256'], [200000]);

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

0 comments on commit e4d2843

Please sign in to comment.