Skip to content

Commit

Permalink
add gateway config tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Feb 3, 2024
1 parent ff78e5b commit 6931d8d
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contracts/gateway/ethereum/EthereumGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract EthereumGateway is L1BaseGateway, L2BaseGateway, OwnableUpgradeable, Re
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function getRemoteGateway() external view returns (address) {
return address(this);
return address(0);
}

function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
Expand Down
10 changes: 2 additions & 8 deletions script/ChainConfig.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
{
"SCROLL": {
"mainnet": true
},
"LINEA": {
"mainnet": true
},
"ZKPOLYGON": {
"mainnet": true
},
"ARBITRUM": {
"mainnet": true
},
"ZKSYNCTEST": {
"mainnet": false,
"l2Gateway": {
"contractName": "ZkSyncL2Gateway",
"initializeParams": []
},
"l1Gateway": {
"netName": "SEPOLIA",
"contractName": "ZkSyncL1Gateway",
"initializeParams": [
"0x9A6DE0f62Aa270A8bCB1e2610078650D539B1Ef9"
]
}
},
"SCROLLTEST": {
"mainnet": false
},
"ZKPOLYGONTEST": {
"mainnet": false
},
"ARBITRUMTEST": {
"mainnet": false,
"l2Gateway": {
"contractName": "ArbitrumL2Gateway",
"initializeParams": []
},
"l1Gateway": {
"netName": "SEPOLIA",
"contractName": "ArbitrumL1Gateway",
"initializeParams": [
"0xaAe29B0366299461418F5324a79Afc425BE5ae21"
Expand Down
58 changes: 56 additions & 2 deletions script/deploy_l1_gateway.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require("fs");
const { getImplementationAddress } = require("@openzeppelin/upgrades-core");
const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, readDeployLogField} = require("./utils");
const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, readDeployLogField,
readDeployContract
} = require("./utils");
const logName = require("./deploy_log_name");
const {zkLinkConfig} = require("./zklink_config");

Expand Down Expand Up @@ -141,4 +143,56 @@ task("upgradeL1Gateway","Upgrade l1 gateway")
deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true;
fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2));
}
});
});

task("setL1GatewayRemoteGateway","Set remote gateway for L1 gateway")
.addParam("targetNetwork", "L2 network name", undefined, types.string, false)
.setAction(async (taskArgs, hardhat)=>{
let targetNetwork = taskArgs.targetNetwork;
console.log("targetNetwork", targetNetwork);

const chainInfo = zkLinkConfig[targetNetwork];
if (chainInfo === undefined) {
console.log('current net not support');
return;
}

const l1GatewayInfo = chainInfo.l1Gateway;
if (l1GatewayInfo === undefined) {
console.log('l1 gateway config not exist');
return;
}

const l2GatewayInfo = chainInfo.l2Gateway;
if (l2GatewayInfo === undefined) {
console.log('l2 gateway config not exist');
return;
}

const l1GatewayLogName = logName.DEPLOY_L1_GATEWAY_LOG_PREFIX + "_" + targetNetwork;
const l1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY);
if (l1GatewayAddr === undefined) {
console.log('l1 gateway address not exist');
return;
}
console.log('l1 gateway', l1GatewayAddr);

const l2GatewayAddr = readDeployContract(logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, logName.DEPLOY_GATEWAY, targetNetwork);
if (l2GatewayAddr === undefined) {
console.log('l2 gateway address not exist');
return;
}
console.log('l2 gateway', l2GatewayAddr);

const l1Gateway = await hardhat.ethers.getContractAt(l1GatewayInfo.contractName, l1GatewayAddr);
const existL2GatewayAddr = await l1Gateway.getRemoteGateway();
if (existL2GatewayAddr !== hardhat.ethers.ZeroAddress) {
console.log('l2 gateway has been set to', existL2GatewayAddr);
return;
}

console.log('set remote gateway...');
const tx = await l1Gateway.setRemoteGateway(l2GatewayAddr);
await tx.wait();
console.log("tx:", tx.hash);
})
52 changes: 50 additions & 2 deletions script/deploy_l2_gateway.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const { getImplementationAddress } = require("@openzeppelin/upgrades-core");
const { verifyContractCode, getDeployTx, createOrGetDeployLog, readDeployLogField, ChainContractDeployer} = require("./utils");
const { verifyContractCode, getDeployTx, createOrGetDeployLog, readDeployContract, readDeployLogField, ChainContractDeployer} = require("./utils");
const logName = require("./deploy_log_name");
const {zkLinkConfig} = require("./zklink_config");

Expand Down Expand Up @@ -88,7 +88,7 @@ task("deployL2Gateway", "Deploy L2 Gateway")

task("upgradeL2Gateway","Upgrade L2 gateway")
.addParam("skipVerify", "Skip verify", false, types.boolean, true)
.setAction(async (taskArgs,hardhat)=>{
.setAction(async (taskArgs, hardhat)=>{
let skipVerify = taskArgs.skipVerify;
console.log("skipVerify", skipVerify);

Expand Down Expand Up @@ -135,4 +135,52 @@ task("upgradeL2Gateway","Upgrade L2 gateway")
deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true;
fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2));
}
})

task("setL2GatewayRemoteGateway","Set remote gateway for L2 gateway")
.setAction(async (taskArgs, hardhat)=>{
const chainInfo = zkLinkConfig[process.env.NET];
if (chainInfo === undefined) {
console.log('current net not support');
return;
}

const l1GatewayInfo = chainInfo.l1Gateway;
if (l1GatewayInfo === undefined) {
console.log('l1 gateway config not exist');
return;
}

const l2GatewayInfo = chainInfo.l2Gateway;
if (l2GatewayInfo === undefined) {
console.log('l2 gateway config not exist');
return;
}

const l2GatewayAddr = readDeployContract(logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, logName.DEPLOY_GATEWAY);
if (l2GatewayAddr === undefined) {
console.log('l2 gateway address not exist');
return;
}
console.log('l2 gateway', l2GatewayAddr);

const l1GatewayLogName = logName.DEPLOY_L1_GATEWAY_LOG_PREFIX + "_" + process.env.NET;
const l1GatewayAddr = readDeployContract(l1GatewayLogName, logName.DEPLOY_GATEWAY, l1GatewayInfo.netName);
if (l1GatewayAddr === undefined) {
console.log('l1 gateway address not exist');
return;
}
console.log('l1 gateway', l1GatewayAddr);

const l2Gateway = await hardhat.ethers.getContractAt(l2GatewayInfo.contractName, l2GatewayAddr);
const existL1GatewayAddr = await l2Gateway.getRemoteGateway();
if (existL1GatewayAddr !== hardhat.ethers.ZeroAddress) {
console.log('l1 gateway has been set to', existL1GatewayAddr);
return;
}

console.log('set remote gateway...');
const tx = await l2Gateway.setRemoteGateway(l1GatewayAddr);
await tx.wait();
console.log("tx:", tx.hash);
})
31 changes: 30 additions & 1 deletion script/deploy_zklink.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const { getImplementationAddress } = require("@openzeppelin/upgrades-core");
const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils");
const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, readDeployContract} = require("./utils");
const logName = require("./deploy_log_name");

function getZkLinkContractName(dummy) {
Expand Down Expand Up @@ -115,4 +115,33 @@ task("upgradeZkLink","Upgrade zkLink")
deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true;
fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2));
}
})

task("setGateway","Set gateway for zkLink")
.setAction(async (taskArgs, hardhat)=>{
const l2GatewayAddr = readDeployContract(logName.DEPLOY_L2_GATEWAY_LOG_PREFIX, logName.DEPLOY_GATEWAY);
if (l2GatewayAddr === undefined) {
console.log('l2 gateway address not exist');
return;
}
console.log('l2 gateway', l2GatewayAddr);

const zkLinkAddr = readDeployContract(logName.DEPLOY_ZKLINK_LOG_PREFIX, logName.DEPLOY_LOG_ZKLINK_PROXY);
if (zkLinkAddr === undefined) {
console.log('zkLink address not exist');
return;
}
console.log('zkLink', zkLinkAddr);

const zkLink = await hardhat.ethers.getContractAt("ZkLink", zkLinkAddr);
const existGatewayAddr = await zkLink.gateway();
if (existGatewayAddr !== hardhat.ethers.ZeroAddress) {
console.log('gateway has been set to', existGatewayAddr);
return;
}

console.log('set gateway...');
const tx = await zkLink.setGateway(l2GatewayAddr);
await tx.wait();
console.log("tx:", tx.hash);
})

0 comments on commit 6931d8d

Please sign in to comment.