diff --git a/hardhat.base.config.js b/hardhat.base.config.js index f3139bc..33eec9e 100644 --- a/hardhat.base.config.js +++ b/hardhat.base.config.js @@ -1,6 +1,8 @@ require("./script/deploy_zklink"); +require("./script/deploy_arbitrator"); require("./script/deploy_l1_gateway"); require("./script/deploy_l2_gateway"); +require("./script/deploy_eth_gateway"); /** * @type import('hardhat/config').HardhatUserConfig diff --git a/script/ChainConfig.json b/script/ChainConfig.json index cc8b6ba..fdf63a3 100644 --- a/script/ChainConfig.json +++ b/script/ChainConfig.json @@ -1,328 +1,46 @@ { - "POLYGON": { - "mainnet": true, - "zkLinkChainId": 1, - "layerZero": { - "chainId": 109, - "address": "0x3c2269811836af69497E5F486A85D7316753cf62" - } - }, - "AVAX": { - "mainnet": true, - "zkLinkChainId": 2, - "layerZero": { - "chainId": 106, - "address": "0x3c2269811836af69497E5F486A85D7316753cf62" - } - }, - "BSC": { - "mainnet": true, - "zkLinkChainId": 3, - "layerZero": { - "chainId": 102, - "address": "0x3c2269811836af69497E5F486A85D7316753cf62" - } - }, - "ETH": { - "mainnet": true, - "zkLinkChainId": 4, - "layerZero": { - "chainId": 101, - "address": "0x66A71Dcef29A0fFBDBE3c6a460a3B5BC225Cd675" - }, - "l1Gateway": { - "LINEA": { - "contractName": "LineaL1Gateway", - "initializeParams": [ - "0xd19d4B5d358258f05D7B411E21A1460D11B0876F", - "0x051F1D88f0aF5763fB888eC4378b4D8B29ea3319", - "0x504A330327A089d8364C4ab3811Ee26976d388ce" - ] - }, - "ZKSYNC": { - "contractName": "ZkSyncL1Gateway", - "initializeParams": [ - "0x32400084c286cf3e17e7b677ea9583e60a000324", - "0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063" - ] - } - } - }, - "ZKSYNC": { - "mainnet": true, - "zkLinkChainId": 5, - "layerZero": { - "chainId": 165, - "address": "0x9b896c0e23220469C7AE69cb4BbAE391eAa4C8da" - }, - "l2Gateway": { - "contractName": "ZkSyncL2Gateway", - "initializeParams": [ - "0x11f943b2c77b743AB90f4A0Ae7d5A4e7FCA3E102" - ] - } - }, "SCROLL": { - "mainnet": true, - "zkLinkChainId": 6, - "layerZero": { - "chainId": 214, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - } + "mainnet": true }, "LINEA": { - "mainnet": true, - "zkLinkChainId": 7, - "layerZero": { - "chainId": 183, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - }, - "l2Gateway": { - "contractName": "LineaL2Gateway", - "initializeParams": [ - "0x508Ca82Df566dCD1B0DE8296e70a96332cD644ec", - "0x353012dc4a9A6cF55c941bADC267f82004A8ceB9", - "0xA2Ee6Fce4ACB62D95448729cDb781e3BEb62504A" - ] - } + "mainnet": true }, "ZKPOLYGON": { - "mainnet": true, - "zkLinkChainId": 8, - "layerZero": { - "chainId": 158, - "address": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4" - } + "mainnet": true }, "ARBITRUM": { - "mainnet": true, - "zkLinkChainId": 9, - "layerZero": { - "chainId": 110, - "address": "0x3c2269811836af69497E5F486A85D7316753cf62" - } - }, - "OPTIMISM": { - "mainnet": true, - "zkLinkChainId": 10, - "layerZero": { - "chainId": 111, - "address": "0x3c2269811836af69497E5F486A85D7316753cf62" - } - }, - "BASE": { - "mainnet": true, - "zkLinkChainId": 11, - "layerZero": { - "chainId": 184, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - } - }, - "MANTLE": { - "mainnet": true, - "zkLinkChainId": 12, - "layerZero": { - "chainId": 181, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - } - }, - "MANTA": { - "mainnet": true, - "zkLinkChainId": 13, - "layerZero": { - "chainId": 217, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - } - }, - "TAIKO": { - "mainnet": true, - "zkLinkChainId": 14 - }, - "OPBNB": { - "mainnet": true, - "zkLinkChainId": 15, - "layerZero": { - "chainId": 202, - "address": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7" - } - }, - "STARKNET": { - "mainnet": true, - "zkLinkChainId": 16 - }, - "X1": { - "mainnet": true, - "zkLinkChainId": 17 - }, - "LIGHTLINK": { - "mainnet": true, - "zkLinkChainId": 18 - }, - "POLYGONTEST": { - "mainnet": false, - "zkLinkChainId": 1, - "layerZero": { - "chainId": 10109, - "address": "0xf69186dfBa60DdB133E91E9A4B5673624293d8F8" - } - }, - "AVAXTEST": { - "mainnet": false, - "zkLinkChainId": 2, - "layerZero": { - "chainId": 10106, - "address": "0x93f54D755A063cE7bB9e6Ac47Eccc8e33411d706" - } - }, - "BSCTEST": { - "mainnet": false, - "zkLinkChainId": 3, - "layerZero": { - "chainId": 10102, - "address": "0x6Fcb97553D41516Cb228ac03FdC8B9a0a9df04A1" - } - }, - "GOERLI": { - "mainnet": false, - "zkLinkChainId": 4, - "layerZero": { - "chainId": 10121, - "address": "0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23" - }, - "l1Gateway": { - "LINEATEST": { - "contractName": "LineaL1Gateway", - "initializeParams": [ - "0x70BaD09280FD342D02fe64119779BC1f0791BAC2", - "0x2D8b29213cCE9DeF01A01718078950C429F9A806", - "0x32d123756d32d3ed6580935f8edf416e57b940f4" - ] - }, - "ZKSYNCTEST": { - "contractName": "ZkSyncL1Gateway", - "initializeParams": [ - "0x1908e2BF4a88F91E4eF0DC72f02b8Ea36BEa2319", - "0x927DdFcc55164a59E0F33918D13a2D559bC10ce7" - ] - } - } - }, - "SEPOLIA": { - "mainnet": false, - "zkLinkChainId": 4, - "layerZero": { - "chainId": 10161, - "address": "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1" - } + "mainnet": true }, "ZKSYNCTEST": { "mainnet": false, - "zkLinkChainId": 5, - "layerZero": { - "chainId": 10165, - "address": "0x093D2CF57f764f09C3c2Ac58a42A2601B8C79281" - }, "l2Gateway": { "contractName": "ZkSyncL2Gateway", + "initializeParams": [] + }, + "l1Gateway": { + "contractName": "ZkSyncL1Gateway", "initializeParams": [ - "0x00ff932A6d70E2B8f1Eb4919e1e09C1923E7e57b" + "0x9A6DE0f62Aa270A8bCB1e2610078650D539B1Ef9" ] } }, "SCROLLTEST": { - "mainnet": false, - "zkLinkChainId": 6, - "layerZero": { - "chainId": 10214, - "address": "0x6098e96a28E02f27B1e6BD381f870F1C8Bd169d3" - } - }, - "LINEATEST": { - "mainnet": false, - "zkLinkChainId": 7, - "layerZero": { - "chainId": 10157, - "address": "0x6aB5Ae6822647046626e83ee6dB8187151E1d5ab" - }, - "l2Gateway": { - "contractName": "LineaL2Gateway", - "initializeParams": [ - "0xC499a572640B64eA1C8c194c43Bc3E19940719dC", - "0x7D9009F96dc1fF94401af63703De43b7cCf98D5D", - "0xdfa112375c9be9d124932b1d104b73f888655329" - ] - } + "mainnet": false }, "ZKPOLYGONTEST": { - "mainnet": false, - "zkLinkChainId": 8, - "layerZero": { - "chainId": 10158, - "address": "0x6aB5Ae6822647046626e83ee6dB8187151E1d5ab" - } + "mainnet": false }, "ARBITRUMTEST": { "mainnet": false, - "zkLinkChainId": 9, - "layerZero": { - "chainId": 10231, - "address": "0x6098e96a28E02f27B1e6BD381f870F1C8Bd169d3" - } - }, - "OPTIMISMTEST": { - "mainnet": false, - "zkLinkChainId": 10, - "layerZero": { - "chainId": 10232, - "address": "0x55370E0fBB5f5b8dAeD978BA1c075a499eB107B8" - } - }, - "BASETEST": { - "mainnet": false, - "zkLinkChainId": 11, - "layerZero": { - "chainId": 10160, - "address": "0x6aB5Ae6822647046626e83ee6dB8187151E1d5ab" - } - }, - "MANTLETEST": { - "mainnet": false, - "zkLinkChainId": 12, - "layerZero": { - "chainId": 10181, - "address": "0x2cA20802fd1Fd9649bA8Aa7E50F0C82b479f35fe" - } - }, - "MANTATEST": { - "mainnet": false, - "zkLinkChainId": 13, - "layerZero": { - "chainId": 10221, - "address": "0x55370E0fBB5f5b8dAeD978BA1c075a499eB107B8" - } - }, - "TAIKOTEST": { - "mainnet": false, - "zkLinkChainId": 14 - }, - "OPBNBTEST": { - "mainnet": false, - "zkLinkChainId": 15, - "layerZero": { - "chainId": 10202, - "address": "0x83c73Da98cf733B03315aFa8758834b36a195b87" + "l2Gateway": { + "contractName": "ArbitrumL2Gateway", + "initializeParams": [] + }, + "l1Gateway": { + "contractName": "ArbitrumL1Gateway", + "initializeParams": [ + "0xaAe29B0366299461418F5324a79Afc425BE5ae21" + ] } - }, - "STARKNETTEST": { - "mainnet": false, - "zkLinkChainId": 16 - }, - "X1TEST": { - "mainnet": false, - "zkLinkChainId": 17 - }, - "LIGHTLINKTEST": { - "mainnet": false, - "zkLinkChainId": 18 } } \ No newline at end of file diff --git a/script/deploy_arbitrator.js b/script/deploy_arbitrator.js new file mode 100644 index 0000000..1bd8bc1 --- /dev/null +++ b/script/deploy_arbitrator.js @@ -0,0 +1,106 @@ +const fs = require("fs"); +const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); +const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils"); +const logName = require("./deploy_log_name"); + +task("deployArbitrator", "Deploy arbitrator") + .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) + .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .setAction(async (taskArgs, hardhat) => { + let force = taskArgs.force; + let skipVerify = taskArgs.skipVerify; + console.log('force redeploy all contracts?', force); + console.log('skip verify contracts?', skipVerify); + + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); + const deployerWallet = contractDeployer.deployerWallet; + + const {deployLogPath,deployLog} = createOrGetDeployLog(logName.DEPLOY_ARBITRATOR_LOG_PREFIX); + deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + + // deploy arbitrator + let arbitratorAddr; + if (!(logName.DEPLOY_LOG_ARBITRATOR in deployLog) || force) { + console.log('deploy arbitrator...'); + const contract = await contractDeployer.deployProxy("Arbitrator"); + const transaction = await getDeployTx(contract); + arbitratorAddr = await contract.getAddress(); + deployLog[logName.DEPLOY_LOG_ARBITRATOR] = arbitratorAddr; + deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; + deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } else { + arbitratorAddr = deployLog[logName.DEPLOY_LOG_ARBITRATOR]; + } + console.log('arbitrator', arbitratorAddr); + + let arbitratorTargetAddr; + if (!(logName.DEPLOY_LOG_ARBITRATOR_TARGET in deployLog) || force) { + console.log('get arbitrator target...'); + arbitratorTargetAddr = await getImplementationAddress( + hardhat.ethers.provider, + arbitratorAddr + ); + deployLog[logName.DEPLOY_LOG_ARBITRATOR_TARGET] = arbitratorTargetAddr; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } else { + arbitratorTargetAddr = deployLog[logName.DEPLOY_LOG_ARBITRATOR_TARGET]; + } + console.log("arbitrator target", arbitratorTargetAddr); + + // verify target contract + if ((!(logName.DEPLOY_LOG_ARBITRATOR_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, arbitratorTargetAddr, []); + deployLog[logName.DEPLOY_LOG_ARBITRATOR_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + + // verify proxy contract + if ((!(logName.DEPLOY_LOG_ARBITRATOR_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, arbitratorAddr, []); + deployLog[logName.DEPLOY_LOG_ARBITRATOR_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + }); + +task("upgradeArbitrator","Upgrade arbitrator") + .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .setAction(async (taskArgs,hardhat)=>{ + let skipVerify = taskArgs.skipVerify; + console.log("skipVerify", skipVerify); + + const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ARBITRATOR_LOG_PREFIX); + const contractAddr = deployLog[logName.DEPLOY_LOG_ARBITRATOR]; + if (contractAddr === undefined) { + console.log('arbitrator address not exist'); + return; + } + console.log('arbitrator', contractAddr); + const oldContractTargetAddr = deployLog[logName.DEPLOY_LOG_ARBITRATOR_TARGET]; + if (oldContractTargetAddr === undefined) { + console.log('arbitrator target address not exist'); + return; + } + console.log('arbitrator old target', oldContractTargetAddr); + + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); + + console.log("upgrade arbitrator..."); + const contract = await contractDeployer.upgradeProxy("Arbitrator", contractAddr); + const tx = await getDeployTx(contract); + console.log('upgrade tx', tx.hash); + const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr); + deployLog[logName.DEPLOY_LOG_ARBITRATOR_TARGET] = newContractTargetAddr; + console.log("arbitrator new target", newContractTargetAddr); + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); + + // verify target contract + if (!skipVerify) { + await verifyContractCode(hardhat, newContractTargetAddr, []); + deployLog[logName.DEPLOY_LOG_ARBITRATOR_TARGET_VERIFIED] = true; + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); + } + }) \ No newline at end of file diff --git a/script/deploy_eth_gateway.js b/script/deploy_eth_gateway.js new file mode 100644 index 0000000..d300b05 --- /dev/null +++ b/script/deploy_eth_gateway.js @@ -0,0 +1,118 @@ +const fs = require("fs"); +const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); +const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, readDeployLogField} = require("./utils"); +const logName = require("./deploy_log_name"); + +task("deployETHGateway", "Deploy ETH Gateway") + .addParam("arbitrator", "The arbitrator address (default get from arbitrator deploy log)", undefined, types.string, true) + .addParam("zklink", "The zklink address (default get from zkLink deploy log)", undefined, types.string, true) + .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) + .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .setAction(async (taskArgs, hardhat) => { + let arbitrator = taskArgs.arbitrator; + if (arbitrator === undefined) { + arbitrator = readDeployLogField(logName.DEPLOY_ARBITRATOR_LOG_PREFIX, logName.DEPLOY_LOG_ARBITRATOR); + } + let zklink = taskArgs.zklink; + if (zklink === undefined) { + zklink = readDeployLogField(logName.DEPLOY_ZKLINK_LOG_PREFIX, logName.DEPLOY_LOG_ZKLINK_PROXY); + } + let force = taskArgs.force; + let skipVerify = taskArgs.skipVerify; + console.log('arbitrator', arbitrator); + console.log('zklink', zklink); + console.log('force redeploy all contracts?', force); + console.log('skip verify contracts?', skipVerify); + + + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); + const deployerWallet = contractDeployer.deployerWallet; + + const {deployLogPath,deployLog} = createOrGetDeployLog(logName.DEPLOY_ETH_GATEWAY_LOG_PREFIX); + deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + + // deploy eth gateway + let gatewayAddr; + if (!(logName.DEPLOY_GATEWAY in deployLog) || force) { + console.log('deploy eth gateway...'); + const contract = await contractDeployer.deployProxy("EthereumGateway", [arbitrator, zklink]); + const transaction = await getDeployTx(contract); + gatewayAddr = await contract.getAddress(); + deployLog[logName.DEPLOY_GATEWAY] = gatewayAddr; + deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; + deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } else { + gatewayAddr = deployLog[logName.DEPLOY_GATEWAY]; + } + console.log('eth gateway', gatewayAddr); + + let gatewayTargetAddr; + if (!(logName.DEPLOY_GATEWAY_TARGET in deployLog) || force) { + console.log('get eth gateway target...'); + gatewayTargetAddr = await getImplementationAddress( + hardhat.ethers.provider, + gatewayAddr + ); + deployLog[logName.DEPLOY_GATEWAY_TARGET] = gatewayTargetAddr; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } else { + gatewayTargetAddr = deployLog[logName.DEPLOY_GATEWAY_TARGET]; + } + console.log("eth gateway target", gatewayTargetAddr); + + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + + // verify target contract + if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayTargetAddr, []); + deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + }); + +task("upgradeETHGateway","Upgrade ETH gateway") + .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .setAction(async (taskArgs,hardhat)=>{ + let skipVerify = taskArgs.skipVerify; + console.log("skipVerify", skipVerify); + + const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ETH_GATEWAY_LOG_PREFIX); + const contractAddr = deployLog[logName.DEPLOY_GATEWAY]; + if (contractAddr === undefined) { + console.log('eth gateway address not exist'); + return; + } + console.log('eth gateway', contractAddr); + const oldContractTargetAddr = deployLog[logName.DEPLOY_GATEWAY_TARGET]; + if (oldContractTargetAddr === undefined) { + console.log('eth gateway target address not exist'); + return; + } + console.log('eth gateway old target', oldContractTargetAddr); + + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); + + console.log("upgrade eth gateway..."); + const contract = await contractDeployer.upgradeProxy("EthereumGateway", contractAddr); + const tx = await getDeployTx(contract); + console.log('upgrade tx', tx.hash); + const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr); + deployLog[logName.DEPLOY_GATEWAY_TARGET] = newContractTargetAddr; + console.log("eth gateway new target", newContractTargetAddr); + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); + + if (!skipVerify) { + await verifyContractCode(hardhat, newContractTargetAddr, []); + deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); + } + }); \ No newline at end of file diff --git a/script/deploy_l1_gateway.js b/script/deploy_l1_gateway.js index 17a3db5..59ceb9d 100644 --- a/script/deploy_l1_gateway.js +++ b/script/deploy_l1_gateway.js @@ -1,69 +1,67 @@ const fs = require("fs"); const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); -const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils"); +const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, readDeployLogField} = require("./utils"); const logName = require("./deploy_log_name"); const {zkLinkConfig} = require("./zklink_config"); task("deployL1Gateway", "Deploy L1 Gateway") - .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) - .addParam("skipVerify", "Skip verify", false, types.boolean, true) - .addParam("targetNetwork", "L2 network name", undefined, types.string, false) - .setAction(async (taskArgs, hardhat) => { - let force = taskArgs.force; - let skipVerify = taskArgs.skipVerify; - let targetNetwork = taskArgs.targetNetwork; - console.log('force redeploy all contracts?', force); - console.log('skip verify contracts?', skipVerify); - console.log('target network', targetNetwork); + .addParam("arbitrator", "The arbitrator address (default get from arbitrator deploy log)", undefined, types.string, true) + .addParam("targetNetwork", "L2 network name", undefined, types.string, false) + .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) + .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .setAction(async (taskArgs, hardhat) => { + let arbitrator = taskArgs.arbitrator; + if (arbitrator === undefined) { + arbitrator = readDeployLogField(logName.DEPLOY_ARBITRATOR_LOG_PREFIX, logName.DEPLOY_LOG_ARBITRATOR); + } + let targetNetwork = taskArgs.targetNetwork; + let force = taskArgs.force; + let skipVerify = taskArgs.skipVerify; + console.log('arbitrator', arbitrator); + console.log('target network', targetNetwork); + console.log('force redeploy all contracts?', force); + console.log('skip verify contracts?', skipVerify); - 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 l2ChainInfo = zkLinkConfig[targetNetwork]; - if (l2ChainInfo === undefined) { + const l2ChainInfo = zkLinkConfig[targetNetwork]; + if (l2ChainInfo === undefined) { console.log('l2 chain info not exist'); return; - } - const chainL1GatewayInfo = l1GatewayInfo[targetNetwork]; - if (chainL1GatewayInfo === undefined) { + } + const l1GatewayInfo = l2ChainInfo.l1Gateway; + if (l1GatewayInfo === undefined) { console.log('l1 gateway info of l2 chain not exist'); return; - } + } - const l1GatewayLogName = logName.DEPLOY_L1_GATEWAY_LOG_PREFIX + "_" + targetNetwork; - const { deployLogPath, deployLog } = createOrGetDeployLog(l1GatewayLogName); + const l1GatewayLogName = logName.DEPLOY_L1_GATEWAY_LOG_PREFIX + "_" + targetNetwork; + const { deployLogPath, deployLog } = createOrGetDeployLog(l1GatewayLogName); - const contractDeployer = new ChainContractDeployer(hardhat); - await contractDeployer.init(); - const deployerWallet = contractDeployer.deployerWallet; - deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); + const deployerWallet = contractDeployer.deployerWallet; + deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - // deploy l1 gateway - let gatewayAddr; - if (!(logName.DEPLOY_GATEWAY in deployLog) || force) { - console.log('deploy l1 gateway...'); - const contract = await contractDeployer.deployProxy(chainL1GatewayInfo.contractName, chainL1GatewayInfo.initializeParams); - const transaction = await getDeployTx(contract); - gatewayAddr = await contract.getAddress(); - deployLog[logName.DEPLOY_GATEWAY] = gatewayAddr; - deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; - deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { - gatewayAddr = deployLog[logName.DEPLOY_GATEWAY]; - } - console.log('l1 gateway', gatewayAddr); + // deploy l1 gateway + let gatewayAddr; + if (!(logName.DEPLOY_GATEWAY in deployLog) || force) { + console.log('deploy l1 gateway...'); + const { contractName, initializeParams } = l1GatewayInfo; + const allParams = [arbitrator].concat(initializeParams); + const contract = await contractDeployer.deployProxy(contractName, allParams); + const transaction = await getDeployTx(contract); + gatewayAddr = await contract.getAddress(); + deployLog[logName.DEPLOY_GATEWAY] = gatewayAddr; + deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; + deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } else { + gatewayAddr = deployLog[logName.DEPLOY_GATEWAY]; + } + console.log('l1 gateway', gatewayAddr); - let gatewayTargetAddr; - if (!(logName.DEPLOY_GATEWAY_TARGET in deployLog) || force) { + let gatewayTargetAddr; + if (!(logName.DEPLOY_GATEWAY_TARGET in deployLog) || force) { console.log('get l1 gateway target...'); gatewayTargetAddr = await getImplementationAddress( hardhat.ethers.provider, @@ -71,18 +69,25 @@ task("deployL1Gateway", "Deploy L1 Gateway") ); deployLog[logName.DEPLOY_GATEWAY_TARGET] = gatewayTargetAddr; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { + } else { gatewayTargetAddr = deployLog[logName.DEPLOY_GATEWAY_TARGET]; - } - console.log("l1 gateway target", gatewayTargetAddr); + } + console.log("l1 gateway target", gatewayTargetAddr); - // verify contract - if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !taskArgs.skipVerify) { + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + + // verify target contract + if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { await verifyContractCode(hardhat, gatewayTargetAddr, []); deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - }); + } + }); task("upgradeL1Gateway","Upgrade l1 gateway") .addParam("skipVerify", "Skip verify", false, types.boolean, true) @@ -93,18 +98,13 @@ task("upgradeL1Gateway","Upgrade l1 gateway") console.log("skipVerify", skipVerify); console.log("targetNetwork", targetNetwork); - const chainInfo = zkLinkConfig[process.env.NET]; - if (chainInfo === undefined) { - console.log('current net not support'); + const l2ChainInfo = zkLinkConfig[targetNetwork]; + if (l2ChainInfo === undefined) { + console.log('l2 chain info not exist'); return; } - const l1GatewayInfo = chainInfo.l1Gateway; + const l1GatewayInfo = l2ChainInfo.l1Gateway; if (l1GatewayInfo === undefined) { - console.log('l1 gateway config not exist'); - return; - } - const chainL1GatewayInfo = l1GatewayInfo[targetNetwork]; - if (chainL1GatewayInfo === undefined) { console.log('l1 gateway info of l2 chain not exist'); return; } @@ -128,7 +128,7 @@ task("upgradeL1Gateway","Upgrade l1 gateway") await contractDeployer.init(); console.log("upgrade l1 gateway..."); - const contract = await contractDeployer.upgradeProxy(chainL1GatewayInfo.contractName, contractAddr); + const contract = await contractDeployer.upgradeProxy(l1GatewayInfo.contractName, contractAddr); const tx = await getDeployTx(contract); console.log('upgrade tx', tx.hash); const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr); @@ -141,4 +141,4 @@ task("upgradeL1Gateway","Upgrade l1 gateway") deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); } - }) \ No newline at end of file + }); \ No newline at end of file diff --git a/script/deploy_l2_gateway.js b/script/deploy_l2_gateway.js index 98299fc..d7e31ed 100644 --- a/script/deploy_l2_gateway.js +++ b/script/deploy_l2_gateway.js @@ -31,8 +31,6 @@ task("deployL2Gateway", "Deploy L2 Gateway") return; } - const { contractName, initializeParams } = l2GatewayInfo; - const allParams = [zklink].concat(initializeParams); const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_L2_GATEWAY_LOG_PREFIX); const contractDeployer = new ChainContractDeployer(hardhat); @@ -45,6 +43,8 @@ task("deployL2Gateway", "Deploy L2 Gateway") let gatewayAddr; if (!(logName.DEPLOY_GATEWAY in deployLog) || force) { console.log('deploy l2 gateway...'); + const { contractName, initializeParams } = l2GatewayInfo; + const allParams = [zklink].concat(initializeParams); const contract = await contractDeployer.deployProxy(contractName, allParams); const transaction = await getDeployTx(contract); gatewayAddr = await contract.getAddress(); @@ -71,7 +71,14 @@ task("deployL2Gateway", "Deploy L2 Gateway") } console.log("l2 gateway target", gatewayTargetAddr); - // verify contract + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } + + // verify target contract if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !taskArgs.skipVerify) { await verifyContractCode(hardhat, gatewayTargetAddr, []); deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; diff --git a/script/deploy_log_name.js b/script/deploy_log_name.js index 9227504..257858c 100644 --- a/script/deploy_log_name.js +++ b/script/deploy_log_name.js @@ -2,52 +2,26 @@ const DEPLOY_ZKLINK_LOG_PREFIX = "deploy"; const DEPLOY_LOG_DEPLOYER = "deployer"; const DEPLOY_LOG_GOVERNOR = "governor"; -const DEPLOY_LOG_VALIDATOR = "validator"; -const DEPLOY_LOG_VERIFIER_TARGET = "verifierTarget"; -const DEPLOY_LOG_VERIFIER_TARGET_VERIFIED = "verifierTargetVerified"; -const DEPLOY_LOG_VERIFIER_PROXY = "verifierProxy"; -const DEPLOY_LOG_VERIFIER_PROXY_VERIFIED = "verifierProxyVerified"; -const DEPLOY_LOG_PERIPHERY_TARGET = "peripheryTarget"; -const DEPLOY_LOG_PERIPHERY_TARGET_VERIFIED = "peripheryTargetVerified"; const DEPLOY_LOG_ZKLINK_TARGET = "zkLinkTarget"; const DEPLOY_LOG_ZKLINK_TARGET_VERIFIED = "zkLinkTargetVerified"; const DEPLOY_LOG_ZKLINK_PROXY = "zkLinkProxy"; const DEPLOY_LOG_ZKLINK_PROXY_VERIFIED = "zkLinkProxyVerified"; -const DEPLOY_LOG_GATEKEEPER = "gatekeeper"; -const DEPLOY_LOG_GATEKEEPER_VERIFIED = "gatekeeperVerified"; const DEPLOY_LOG_DEPLOY_TX_HASH = "deployTxHash"; const DEPLOY_LOG_DEPLOY_BLOCK_NUMBER = "deployBlockNumber"; -const DEPLOY_LOG_VERIFIER_TRAMSFER_MASTERSHIP = "verifierTransferMastership"; -const DEPLOY_LOG_ZKLINK_TRAMSFER_MASTERSHIP = "zkLinkTransferMastership"; -const DEPLOY_LOG_VERIFIER_ADD_UPGRADE = "verifierAddUpgrade"; -const DEPLOY_LOG_ZKLINK_ADD_UPGRADE = "zkLinkAddUpgrade"; -const DEPLOY_LOG_ZKLINK_SET_VALIDATOR = "zkLinkSetValidator"; -// consumed in deploy_lz_bridge.js -const DEPLOY_LZ_BRIDGE_LOG_PREFIX = "deploy_lz_bridge"; -const DEPLOY_LOG_LZ_BRIDGE = "lzBridge"; -const DEPLOY_LOG_LZ_BRIDGE_VERIFIED = "lzBridgeVerified"; - -// consumed in gas_estimate.js -const DEPLOY_GAS_ESTIMATE_LOG_PREFIX = "deploy_gas_estimate"; -const DEPLOY_LOG_ADD_ETH = "addETH"; -const DEPLOY_LOG_TOKEN2 = "token2"; - -// consumed in deploy_l1_gateway.js or deploy_l2_gateway.js +// consumed in deploy_l1_gateway.js or deploy_l2_gateway.js or deploy_eth_gateway.js const DEPLOY_L1_GATEWAY_LOG_PREFIX = "deploy_l1_gateway"; const DEPLOY_L2_GATEWAY_LOG_PREFIX = "deploy_l2_gateway"; +const DEPLOY_ETH_GATEWAY_LOG_PREFIX = "deploy_eth_gateway"; const DEPLOY_GATEWAY = "gateway"; +const DEPLOY_GATEWAY_VERIFIED = "gatewayVerified"; const DEPLOY_GATEWAY_TARGET = "gatewayTarget"; const DEPLOY_GATEWAY_TARGET_VERIFIED = "gatewayTargetVerified"; -// consumed in deploy_multicall -const DEPLOY_MULTICALL_LOG_PREFIX = "deploy_multicall"; -const DEPLOY_MULTICALL = "multicall"; -const DEPLOY_MULTICALL_VERIFIED = "multicallVerified"; - // consumed in deploy_arbitrator.js const DEPLOY_ARBITRATOR_LOG_PREFIX = "deploy_arbitrator"; const DEPLOY_LOG_ARBITRATOR = "arbitrator"; +const DEPLOY_LOG_ARBITRATOR_VERIFIED = "arbitratorVerified"; const DEPLOY_LOG_ARBITRATOR_TARGET = "arbitratorTarget"; const DEPLOY_LOG_ARBITRATOR_TARGET_VERIFIED = "arbitratorTargetVerified"; @@ -55,42 +29,22 @@ module.exports = { DEPLOY_ZKLINK_LOG_PREFIX, DEPLOY_LOG_DEPLOYER, DEPLOY_LOG_GOVERNOR, - DEPLOY_LOG_VALIDATOR, - DEPLOY_LOG_VERIFIER_TARGET, - DEPLOY_LOG_VERIFIER_TARGET_VERIFIED, - DEPLOY_LOG_VERIFIER_PROXY, - DEPLOY_LOG_VERIFIER_PROXY_VERIFIED, - DEPLOY_LOG_PERIPHERY_TARGET, - DEPLOY_LOG_PERIPHERY_TARGET_VERIFIED, DEPLOY_LOG_ZKLINK_TARGET, DEPLOY_LOG_ZKLINK_TARGET_VERIFIED, DEPLOY_LOG_ZKLINK_PROXY, DEPLOY_LOG_ZKLINK_PROXY_VERIFIED, - DEPLOY_LOG_GATEKEEPER, - DEPLOY_LOG_GATEKEEPER_VERIFIED, DEPLOY_LOG_DEPLOY_TX_HASH, DEPLOY_LOG_DEPLOY_BLOCK_NUMBER, - DEPLOY_LOG_VERIFIER_TRAMSFER_MASTERSHIP, - DEPLOY_LOG_ZKLINK_TRAMSFER_MASTERSHIP, - DEPLOY_LOG_VERIFIER_ADD_UPGRADE, - DEPLOY_LOG_ZKLINK_ADD_UPGRADE, - DEPLOY_LOG_ZKLINK_SET_VALIDATOR, - DEPLOY_LZ_BRIDGE_LOG_PREFIX, - DEPLOY_LOG_LZ_BRIDGE, - DEPLOY_LOG_LZ_BRIDGE_VERIFIED, - DEPLOY_GAS_ESTIMATE_LOG_PREFIX, - DEPLOY_LOG_ADD_ETH, - DEPLOY_LOG_TOKEN2, DEPLOY_L1_GATEWAY_LOG_PREFIX, DEPLOY_L2_GATEWAY_LOG_PREFIX, + DEPLOY_ETH_GATEWAY_LOG_PREFIX, DEPLOY_GATEWAY, + DEPLOY_GATEWAY_VERIFIED, DEPLOY_GATEWAY_TARGET, DEPLOY_GATEWAY_TARGET_VERIFIED, - DEPLOY_MULTICALL_LOG_PREFIX, - DEPLOY_MULTICALL, - DEPLOY_MULTICALL_VERIFIED, DEPLOY_ARBITRATOR_LOG_PREFIX, DEPLOY_LOG_ARBITRATOR, + DEPLOY_LOG_ARBITRATOR_VERIFIED, DEPLOY_LOG_ARBITRATOR_TARGET, DEPLOY_LOG_ARBITRATOR_TARGET_VERIFIED }; diff --git a/script/deploy_zklink.js b/script/deploy_zklink.js index a267932..bafffb2 100644 --- a/script/deploy_zklink.js +++ b/script/deploy_zklink.js @@ -1,367 +1,106 @@ -const fs = require('fs'); -const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx, getDeployLog} = require('./utils'); -const logName = require('./deploy_log_name'); +const fs = require("fs"); +const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); +const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils"); +const logName = require("./deploy_log_name"); -task("deployZkLink", "Deploy zklink contracts") - .addParam("validator", "The validator address (default is same as deployer)", undefined, types.string, true) - .addParam("blockNumber", "The block number", 0, types.int, true) - .addParam("genesisRoot", "The block root hash", "0x0000000000000000000000000000000000000000000000000000000000000000", types.string, true) +task("deployZkLink", "Deploy zkLink") .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) .addParam("skipVerify", "Skip verify", false, types.boolean, true) .setAction(async (taskArgs, hardhat) => { - const abiCoder = new hardhat.ethers.AbiCoder() - const isMasterChain = hardhat.config.isMasterChain; - if (typeof isMasterChain === 'undefined') { - console.log('master chain not config'); - return; - } - console.log('is master chain?', isMasterChain); + let force = taskArgs.force; + let skipVerify = taskArgs.skipVerify; + console.log('force redeploy all contracts?', force); + console.log('skip verify contracts?', skipVerify); const contractDeployer = new ChainContractDeployer(hardhat); await contractDeployer.init(); const deployerWallet = contractDeployer.deployerWallet; - let validator = taskArgs.validator; - if (validator === undefined) { - validator = deployerWallet.address; - } - const force = taskArgs.force; - const skipVerify = taskArgs.skipVerify; - const blockNumber = taskArgs.blockNumber; - const genesisRoot = taskArgs.genesisRoot; - console.log('validator', validator); - console.log('blockNumber', blockNumber); - console.log('genesisRoot', genesisRoot); - console.log('force redeploy all contracts?', force); - console.log('skip verify contracts?', skipVerify); - const {deployLogPath,deployLog} = createOrGetDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); - - deployLog[logName.DEPLOY_LOG_DEPLOYER] = deployerWallet.address; deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address; - deployLog[logName.DEPLOY_LOG_VALIDATOR] = validator; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - const proxyContractName = contractDeployer.getProxyContractName(); - console.log('use proxy contract name: ', proxyContractName); - - // verifier - let verifierTarget; - if (!(logName.DEPLOY_LOG_VERIFIER_TARGET in deployLog) || force) { - console.log('deploy verifier target...'); - let verifier; - if (!isMasterChain) { - verifier = await contractDeployer.deployContract('EmptyVerifier', []); - } else { - verifier = await contractDeployer.deployContract('Verifier', []); - } - verifierTarget = await verifier.getAddress(); - deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET] = verifierTarget; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { - verifierTarget = deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET]; - } - console.log('verifier target', verifierTarget); - if ((!(logName.DEPLOY_LOG_VERIFIER_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, verifierTarget, []); - deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // verifier proxy - let verifierProxy; - let verifierTargetInitializationParameters = "0x"; - if (!(logName.DEPLOY_LOG_VERIFIER_PROXY in deployLog) || force) { - console.log('deploy verifier proxy...'); - let proxy = await contractDeployer.deployContract(proxyContractName, [verifierTarget, verifierTargetInitializationParameters]); - verifierProxy = await proxy.getAddress(); - deployLog[logName.DEPLOY_LOG_VERIFIER_PROXY] = verifierProxy; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { - verifierProxy = deployLog[logName.DEPLOY_LOG_VERIFIER_PROXY]; - } - console.log('verifier proxy', verifierProxy); - if ((!(logName.DEPLOY_LOG_VERIFIER_PROXY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, verifierProxy, [verifierTarget, verifierTargetInitializationParameters]); - deployLog[logName.DEPLOY_LOG_VERIFIER_PROXY_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // periphery - let peripheryTarget; - if (!(logName.DEPLOY_LOG_PERIPHERY_TARGET in deployLog) || force) { - console.log('deploy periphery target...'); - let periphery = await contractDeployer.deployContract('ZkLinkPeriphery', []); - peripheryTarget = await periphery.getAddress(); - deployLog[logName.DEPLOY_LOG_PERIPHERY_TARGET] = peripheryTarget; + // deploy zkLink + let zkLinkAddr; + if (!(logName.DEPLOY_LOG_ZKLINK_PROXY in deployLog) || force) { + console.log('deploy zkLink...'); + const contract = await contractDeployer.deployProxy("ZkLink"); + const transaction = await getDeployTx(contract); + zkLinkAddr = await contract.getAddress(); + deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY] = zkLinkAddr; + deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; + deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } else { - peripheryTarget = deployLog[logName.DEPLOY_LOG_PERIPHERY_TARGET]; - } - console.log('periphery target', peripheryTarget); - if ((!(logName.DEPLOY_LOG_PERIPHERY_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, peripheryTarget, []); - deployLog[logName.DEPLOY_LOG_PERIPHERY_TARGET_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + zkLinkAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY]; } + console.log('zkLink', zkLinkAddr); - // zkLink - let zkLinkTarget; + let zkLinkTargetAddr; if (!(logName.DEPLOY_LOG_ZKLINK_TARGET in deployLog) || force) { - console.log('deploy zkLink target...'); - let zkLink = await contractDeployer.deployContract('ZkLink', [peripheryTarget]); - zkLinkTarget = await zkLink.getAddress(); - deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET] = zkLinkTarget; + console.log('get zkLink target...'); + zkLinkTargetAddr = await getImplementationAddress( + hardhat.ethers.provider, + zkLinkAddr + ); + deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET] = zkLinkTargetAddr; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } else { - zkLinkTarget = deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET]; - } - console.log('zkLink target', zkLinkTarget); - if ((!(logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, zkLinkTarget, [peripheryTarget]); - deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + zkLinkTargetAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET]; } + console.log("zkLink target", zkLinkTargetAddr); - // zkLink proxy - let zkLinkProxy; - let zkLinkDeployTxHash; - let zkLinkDeployBlockNumber; - let zkLinkInitParams = isMasterChain ? - abiCoder.encode(['address','address', "bytes32"], [verifierProxy, deployerWallet.address, genesisRoot]) : - abiCoder.encode(['address','address', "uint32"], [verifierProxy, deployerWallet.address, blockNumber]); - console.log("zklink init params: ", zkLinkInitParams); - if (!(logName.DEPLOY_LOG_ZKLINK_PROXY in deployLog) || force) { - console.log('deploy zklink proxy...'); - let proxy = await contractDeployer.deployContract(proxyContractName, [zkLinkTarget, zkLinkInitParams]); - const transaction = await getDeployTx(proxy); - zkLinkProxy = await proxy.getAddress(); - zkLinkDeployTxHash = transaction.hash; - zkLinkDeployBlockNumber = transaction.blockNumber; - deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY] = zkLinkProxy; - deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = zkLinkDeployTxHash; - deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = zkLinkDeployBlockNumber; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { - zkLinkProxy = deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY]; - zkLinkDeployTxHash = deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH]; - zkLinkDeployBlockNumber = deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER]; - } - console.log('zklink proxy', zkLinkProxy); - console.log('deploy zklink tx hash', zkLinkDeployTxHash); - console.log('deploy zklink block number', zkLinkDeployBlockNumber); + // verify proxy contract if ((!(logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, zkLinkProxy, [zkLinkTarget, zkLinkInitParams]); + await verifyContractCode(hardhat, zkLinkAddr, []); deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } - // upgradeGatekeeper - let upgradeGatekeeper; - if (!(logName.DEPLOY_LOG_GATEKEEPER in deployLog) || force) { - console.log('deploy upgrade gatekeeper...'); - let contract = await contractDeployer.deployContract('UpgradeGatekeeper', [zkLinkProxy]); - upgradeGatekeeper = await contract.getAddress(); - deployLog[logName.DEPLOY_LOG_GATEKEEPER] = upgradeGatekeeper; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } else { - upgradeGatekeeper = deployLog[logName.DEPLOY_LOG_GATEKEEPER]; - } - console.log('upgrade gatekeeper', upgradeGatekeeper); - if ((!(logName.DEPLOY_LOG_GATEKEEPER_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, upgradeGatekeeper, [zkLinkProxy]); - deployLog[logName.DEPLOY_LOG_GATEKEEPER_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // transfer mastership to gatekeeper - if (!(logName.DEPLOY_LOG_VERIFIER_TRAMSFER_MASTERSHIP in deployLog) || force) { - console.log('verifier transfer mastership to gatekeeper...'); - const contractFactory = await hardhat.ethers.getContractFactory(proxyContractName); - const contract = contractFactory.attach(verifierProxy); - const tx = await contract.connect(deployerWallet).transferMastership(upgradeGatekeeper); - await tx.wait(); - console.log('tx hash: ', tx.hash); - deployLog[logName.DEPLOY_LOG_VERIFIER_TRAMSFER_MASTERSHIP] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - if (!(logName.DEPLOY_LOG_ZKLINK_TRAMSFER_MASTERSHIP in deployLog) || force) { - console.log('zklink transfer mastership to gatekeeper...'); - const contractFactory = await hardhat.ethers.getContractFactory(proxyContractName); - const contract = contractFactory.attach(zkLinkProxy); - const tx = await contract.connect(deployerWallet).transferMastership(upgradeGatekeeper); - await tx.wait(); - console.log('tx hash: ', tx.hash); - deployLog[logName.DEPLOY_LOG_ZKLINK_TRAMSFER_MASTERSHIP] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // addUpgradeable - if (!(logName.DEPLOY_LOG_VERIFIER_ADD_UPGRADE in deployLog) || force) { - console.log('verifier add upgrade to gatekeeper...'); - const contractFactory = await hardhat.ethers.getContractFactory('UpgradeGatekeeper'); - const contract = contractFactory.attach(upgradeGatekeeper); - const tx = await contract.connect(deployerWallet).addUpgradeable(verifierProxy); - await tx.wait(); - console.log('tx hash: ', tx.hash); - deployLog[logName.DEPLOY_LOG_VERIFIER_ADD_UPGRADE] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - if (!(logName.DEPLOY_LOG_ZKLINK_ADD_UPGRADE in deployLog) || force) { - console.log('zklink add upgrade to gatekeeper...'); - const contractFactory = await hardhat.ethers.getContractFactory('UpgradeGatekeeper'); - const contract = contractFactory.attach(upgradeGatekeeper); - const tx = await contract.connect(deployerWallet).addUpgradeable(zkLinkProxy); - await tx.wait(); - console.log('tx hash: ', tx.hash); - deployLog[logName.DEPLOY_LOG_ZKLINK_ADD_UPGRADE] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // set validator - if (!(logName.DEPLOY_LOG_ZKLINK_SET_VALIDATOR in deployLog) || force) { - console.log('zklink set validator...'); - const contractFactory = await hardhat.ethers.getContractFactory('ZkLinkPeriphery'); - const contract = contractFactory.attach(zkLinkProxy); - const tx = await contract.connect(deployerWallet).setValidator(validator, true); - await tx.wait(); - console.log('tx hash: ', tx.hash); - deployLog[logName.DEPLOY_LOG_ZKLINK_SET_VALIDATOR] = true; + // verify target contract + if ((!(logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, zkLinkTargetAddr, []); + deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } -}); + }); -task("upgradeZkLink", "Upgrade zkLink") - .addParam("upgradeVerifier", "Upgrade verifier", false, types.boolean, true) - .addParam("upgradeZkLink", "Upgrade zkLink", false, types.boolean, true) +task("upgradeZkLink","Upgrade zkLink") .addParam("skipVerify", "Skip verify", false, types.boolean, true) - .setAction(async (taskArgs, hardhat) => { - const isMasterChain = hardhat.config.isMasterChain; - if (typeof isMasterChain === 'undefined') { - console.log('master chain not config'); - return; - } - console.log('is master chain?', isMasterChain); - - const contractDeployer = new ChainContractDeployer(hardhat); - await contractDeployer.init(); - const deployerWallet = contractDeployer.deployerWallet; - - let upgradeVerifier = taskArgs.upgradeVerifier; - let upgradeZkLink = taskArgs.upgradeZkLink; + .setAction(async (taskArgs,hardhat)=>{ let skipVerify = taskArgs.skipVerify; - console.log('deployer', deployerWallet.address); - console.log('upgrade verifier?', upgradeVerifier); - console.log('upgrade zkLink?', upgradeZkLink); - console.log('skip verify contracts?', skipVerify); - if (!upgradeVerifier && !upgradeZkLink) { - console.log('no need upgrade'); - return; - } - - // deploy log must exist - const {deployLogPath,deployLog} = getDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); + console.log("skipVerify", skipVerify); - let zkLinkProxyAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY]; - if (zkLinkProxyAddr === undefined) { - console.log('ZkLink proxy address not exist'); + const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); + const contractAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY]; + if (contractAddr === undefined) { + console.log('zkLink address not exist'); return; } - - // log deployer balance - const balance = await hardhat.ethers.provider.getBalance(deployerWallet.address); - console.log('deployer balance', hardhat.ethers.formatEther(balance)); - - // attach upgrade gatekeeper - const gatekeeperAddr = deployLog[logName.DEPLOY_LOG_GATEKEEPER]; - if (gatekeeperAddr === undefined) { - console.log('Gatekeeper address not exist'); + console.log('zkLink', contractAddr); + const oldContractTargetAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET]; + if (oldContractTargetAddr === undefined) { + console.log('zkLink target address not exist'); return; } - const gatekeeperFactory = await hardhat.ethers.getContractFactory('UpgradeGatekeeper'); - const gatekeeper = await gatekeeperFactory.attach(gatekeeperAddr); - let upgradeStatus = await gatekeeper.connect(deployerWallet).upgradeStatus(); - console.log('upgrade status: ', upgradeStatus); - - // if upgrade status is Idle, then start deploy new targets - if (upgradeStatus === 0n) { - // verifier - if (upgradeVerifier) { - if (isMasterChain) { - console.log('deploy verifier target...'); - const verifier = await contractDeployer.deployContract('Verifier', []); - const verifierTargetAddr = await verifier.getAddress(); - deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET] = verifierTargetAddr; - console.log('verifier target', verifierTargetAddr); - if (!skipVerify) { - await verifyContractCode(hardhat, verifierTargetAddr, []); - deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET_VERIFIED] = true; - } - } else { - console.log('no need to upgrade verifier in slaver chain'); - } - } + console.log('zkLink old target', oldContractTargetAddr); - // zkLink - if (upgradeZkLink) { - console.log('deploy periphery target...'); - let periphery = await contractDeployer.deployContract('ZkLinkPeriphery', []); - const peripheryTargetAddr = await periphery.getAddress(); - deployLog[logName.DEPLOY_LOG_PERIPHERY_TARGET] = peripheryTargetAddr; - console.log('periphery target', peripheryTargetAddr); - if (!skipVerify) { - await verifyContractCode(hardhat, peripheryTargetAddr, []); - deployLog[logName.DEPLOY_LOG_PERIPHERY_TARGET_VERIFIED] = true; - } - - console.log('deploy zkLink target...'); - let zkLink = await contractDeployer.deployContract('ZkLink', [peripheryTargetAddr]); - const zkLinkTargetAddr = await zkLink.getAddress(); - deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET] = zkLinkTargetAddr; - console.log('zkLink target', zkLinkTargetAddr); - if (!skipVerify) { - await verifyContractCode(hardhat, zkLinkTargetAddr, [peripheryTargetAddr]); - deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true; - } - } - console.log('write new targets to log'); - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - - // check if upgrade at testnet - const zkLinkFactory = await hardhat.ethers.getContractFactory('ZkLink'); - let zkLinkProxy = await zkLinkFactory.attach(zkLinkProxyAddr); - const noticePeriod = await zkLinkProxy.connect(deployerWallet).getNoticePeriod(); - if (noticePeriod > 0n) { - console.log('Notice period is not zero, can not exec this task'); - return; - } - - const upgradeTargets = [hardhat.ethers.ZeroAddress, hardhat.ethers.ZeroAddress]; - if (upgradeVerifier) { - upgradeTargets[0] = deployLog[logName.DEPLOY_LOG_VERIFIER_TARGET]; - } - if (upgradeZkLink) { - upgradeTargets[1] = deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET]; - } - - if (upgradeStatus === 0n) { - console.log('start upgrade...'); - const startUpgradeTx = await gatekeeper.connect(deployerWallet).startUpgrade(upgradeTargets); - await startUpgradeTx.wait(); - console.info(`upgrade start tx: ${startUpgradeTx.hash}`); - upgradeStatus = await gatekeeper.connect(deployerWallet).upgradeStatus(); - console.log('upgrade status after start: ', upgradeStatus); - } + const contractDeployer = new ChainContractDeployer(hardhat); + await contractDeployer.init(); - if (upgradeStatus === 1n) { - const finishUpgradeTx = await gatekeeper.connect(deployerWallet).finishUpgrade(); - await finishUpgradeTx.wait(); - console.info(`upgrade finish tx: ${finishUpgradeTx.hash}`); - upgradeStatus = await gatekeeper.connect(deployerWallet).upgradeStatus(); - console.log('upgrade status after finish: ', upgradeStatus); + console.log("upgrade zkLink..."); + const contract = await contractDeployer.upgradeProxy("ZkLink", contractAddr); + const tx = await getDeployTx(contract); + console.log('upgrade tx', tx.hash); + const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr); + deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET] = newContractTargetAddr; + console.log("zkLink new target", newContractTargetAddr); + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); + + // verify target contract + if (!skipVerify) { + await verifyContractCode(hardhat, newContractTargetAddr, []); + deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true; + fs.writeFileSync(deployLogPath,JSON.stringify(deployLog, null, 2)); } - console.info('upgrade successful'); - }); + }) \ No newline at end of file diff --git a/script/op_utils.js b/script/op_utils.js deleted file mode 100644 index 944887e..0000000 --- a/script/op_utils.js +++ /dev/null @@ -1,215 +0,0 @@ -const { solidityPacked, keccak256, getCreate2Address, hexlify, concat, getBytes} = require("ethers"); - -const OP_NOOP = 0; -const OP_DEPOSIT = 1; -const OP_TRANSFER_TO_NEW = 2; -const OP_WITHDRAW = 3; -const OP_TRANSFER = 4; -const OP_FULL_EXIT = 5; -const OP_CHANGE_PUBKEY = 6; -const OP_FORCE_EXIT = 7; -const OP_ORDER_MATCHING = 11; -const CHUNK_BYTES = 23; -const OP_NOOP_CHUNKS = 1; -const OP_DEPOSIT_CHUNKS = 3; -const OP_TRANSFER_TO_NEW_CHUNKS = 3; -const OP_WITHDRAW_CHUNKS = 3; -const OP_TRANSFER_CHUNKS = 2; -const OP_FULL_EXIT_CHUNKS = 3; -const OP_CHANGE_PUBKEY_CHUNKS = 3; -const OP_FORCE_EXIT_CHUNKS = 3; -const OP_ORDER_MATCHING_CHUNKS = 4; -const OP_DEPOSIT_SIZE = 59; -const OP_TRANSFER_TO_NEW_SIZE = 52; -const OP_WITHDRAW_SIZE = 68; -const OP_TRANSFER_SIZE = 20; -const OP_FULL_EXIT_SIZE = 59; -const OP_CHANGE_PUBKEY_SIZE = 67; -const OP_FORCE_EXIT_SIZE = 69; -const OP_ORDER_MATCHING_SIZE = 77; -const OP_DEPOSIT_HASH_SIZE = 55; -const OP_FULLEXIT_HASH_SIZE = 43; -const ADDRESS_PREFIX_ZERO_BYTES = "0x000000000000000000000000"; - -function getDepositPubdata({ chainId, accountId, subAccountId, tokenId, targetTokenId, amount, owner }) { - const pubdata = solidityPacked(["uint8","uint8","uint8","uint16","uint16","uint128","bytes32","uint32"], - [OP_DEPOSIT,chainId,subAccountId,tokenId,targetTokenId,amount,owner,accountId]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_DEPOSIT_SIZE, "wrong deposit pubdata"); - return pubdata; -} - -function writeDepositPubdata({ chainId, subAccountId, tokenId, targetTokenId, amount, owner }) { - return solidityPacked(["uint8","uint8","uint8","uint16","uint16","uint128","bytes32","uint32"], - [OP_DEPOSIT,chainId,subAccountId,tokenId,targetTokenId,amount,owner,0]); -} - -function getWithdrawPubdata({ chainId, accountId, subAccountId, tokenId, srcTokenId, amount, fee, owner, nonce, fastWithdrawFeeRate, withdrawToL1 }) { - const pubdata = solidityPacked(["uint8","uint8","uint32","uint8","uint16","uint16","uint128","uint16","bytes32","uint32","uint16","uint8"], - [OP_WITHDRAW,chainId,accountId,subAccountId,tokenId,srcTokenId,amount,fee,owner,nonce,fastWithdrawFeeRate,withdrawToL1]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_WITHDRAW_SIZE, "wrong withdraw pubdata"); - return pubdata; -} - -function getFullExitPubdata({ chainId, accountId, subAccountId, owner, tokenId, srcTokenId, amount}) { - const pubdata = solidityPacked(["uint8","uint8","uint32","uint8","bytes32","uint16","uint16","uint128"], - [OP_FULL_EXIT,chainId,accountId,subAccountId,owner,tokenId,srcTokenId,amount]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_FULL_EXIT_SIZE, "wrong fullexit pubdata"); - return pubdata; -} - -function writeFullExitPubdata({ chainId, accountId, subAccountId, owner, tokenId, srcTokenId}) { - return solidityPacked(["uint8","uint8","uint32","uint8","bytes32","uint16","uint16","uint128"], - [OP_FULL_EXIT,chainId,accountId,subAccountId,owner,tokenId,srcTokenId,0]); -} - -function getForcedExitPubdata({ chainId, initiatorAccountId, initiatorSubAccountId, initiatorNonce, targetAccountId, targetSubAccountId, tokenId, srcTokenId, amount, withdrawToL1, target }) { - const pubdata = solidityPacked(["uint8","uint8","uint32","uint8","uint32","uint32","uint8","uint16","uint16","uint128","uint8","bytes32"], - [OP_FORCE_EXIT,chainId,initiatorAccountId,initiatorSubAccountId,initiatorNonce,targetAccountId,targetSubAccountId,tokenId,srcTokenId,amount,withdrawToL1,target]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_FORCE_EXIT_SIZE, "wrong forcedexit pubdata"); - return pubdata; -} - -function getChangePubkeyPubdata({ chainId, accountId, subAccountId, pubKeyHash, owner, nonce, tokenId, fee}) { - const pubdata = solidityPacked(["uint8","uint8","uint32","uint8","bytes20","bytes32","uint32","uint16","uint16"], - [OP_CHANGE_PUBKEY,chainId,accountId,subAccountId,pubKeyHash,owner,nonce,tokenId,fee]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_CHANGE_PUBKEY_SIZE, "wrong changepubkey pubdata"); - return pubdata; -} - -function getTransferPubdata({fromAccountId, fromSubAccountId, tokenId, amount, toAccountId, toSubAccountId, fee}) { - const pubdata = solidityPacked(["uint8","uint32","uint8","uint16","uint40","uint32","uint8","uint16"], - [OP_TRANSFER,fromAccountId,fromSubAccountId,tokenId,amount,toAccountId,toSubAccountId,fee]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_TRANSFER_SIZE, "wrong transfer pubdata"); - return pubdata; -} - -function getTransferToNewPubdata({fromAccountId, fromSubAccountId, tokenId, amount, toAccountId, toSubAccountId, to, fee}) { - const pubdata = solidityPacked(["uint8","uint32","uint8","uint16","uint40","bytes32","uint32","uint8","uint16"], - [OP_TRANSFER_TO_NEW,fromAccountId,fromSubAccountId,tokenId,amount,to,toAccountId,toSubAccountId,fee]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_TRANSFER_TO_NEW_SIZE, "wrong transfertonew pubdata"); - return pubdata; -} - -function getOrderMatchingPubdata({submitterAccountId, taker, maker, feeTokenId, fee, baseAmount, quoteAmount}) { - const pubdata = solidityPacked(["uint8", - "uint8", - "uint32","uint32","uint32", - "uint16","uint16", - "uint16","uint16","uint16", - "uint40","uint40", - "uint16", - "uint8","uint8", - "uint128","uint128", - "uint24","uint24", - "uint8" - ], - [OP_ORDER_MATCHING, - maker.subAccountId, - maker.accountId,taker.accountId,submitterAccountId, - maker.slotId,taker.slotId, - maker.tokenId,taker.tokenId,feeTokenId, - maker.amount,taker.amount, - fee, - maker.feeRatio,taker.feeRatio, - baseAmount,quoteAmount, - maker.nonce,taker.nonce, - maker.is_sell - ]); - const pubdataArray = getBytes(pubdata); - console.assert(pubdataArray.length === OP_ORDER_MATCHING_SIZE, "wrong ordermatching pubdata"); - return pubdata; -} - -function mockNoopPubdata() { - return solidityPacked(["uint8"], [OP_NOOP]); -} - -function paddingChunk(pubdata, chunks) { - const pubdataArray = getBytes(pubdata); - const zeroPaddingNum = CHUNK_BYTES * chunks - pubdataArray.length; - const zeroArray = new Uint8Array(zeroPaddingNum); - const pubdataPaddingArray = concat([pubdataArray, zeroArray]); - return hexlify(pubdataPaddingArray); -} - -function extendAddress(address) { - const addrBytes = getBytes(address); - const zeroBytes = getBytes(ADDRESS_PREFIX_ZERO_BYTES); - const extendAddrArray = concat([zeroBytes, addrBytes]); - return hexlify(extendAddrArray); -} - -function hashBytesToBytes20(pubData) { - return hexlify(getBytes(keccak256(pubData)).slice(12)); -} - -async function createEthWitnessOfECRECOVER(pubKeyHash,nonce,accountId,owner) { - const sigMsg = solidityPacked( - ["string"], - ["ChangePubKey\nPubKeyHash: " + pubKeyHash + "\nNonce: " + nonce + "\nAccountId: " + accountId]); - const signature = await owner.signMessage(getBytes(sigMsg)); - return solidityPacked(["bytes1","bytes"],['0x00', signature]); -} - -function createEthWitnessOfCREATE2(pubKeyHash,accountId,creatorAddress,saltArg,codeHash) { - const ethWitness = solidityPacked(["bytes1","address","bytes32","bytes32"],["0x01", creatorAddress, saltArg, codeHash]); - const salt = keccak256(getBytes(solidityPacked(["bytes32","bytes20"],[saltArg, pubKeyHash]))); - const owner = getCreate2Address(creatorAddress, getBytes(salt), getBytes(codeHash)); - return {ethWitness, owner}; -} - -function calWithdrawHash(receiver, token, amount, fastWithdrawFeeRate, accountIdOfNonce, subAccountIdOfNonce, nonce) { - return keccak256(solidityPacked(["uint32","uint8","uint32", "address","address","uint128","uint16"], [accountIdOfNonce, subAccountIdOfNonce, nonce, receiver, token, amount, fastWithdrawFeeRate])); -} - -function getRandomInt(max) { - return Math.floor(Math.random() * max); -} - -module.exports = { - getDepositPubdata, - writeDepositPubdata, - getWithdrawPubdata, - getFullExitPubdata, - writeFullExitPubdata, - getForcedExitPubdata, - getChangePubkeyPubdata, - getTransferPubdata, - getTransferToNewPubdata, - getOrderMatchingPubdata, - mockNoopPubdata, - paddingChunk, - extendAddress, - hashBytesToBytes20, - createEthWitnessOfECRECOVER, - createEthWitnessOfCREATE2, - calWithdrawHash, - getRandomInt, - OP_DEPOSIT, - OP_WITHDRAW, - OP_FULL_EXIT, - OP_FORCE_EXIT, - OP_CHANGE_PUBKEY, - OP_TRANSFER, - OP_TRANSFER_TO_NEW, - OP_ORDER_MATCHING, - CHUNK_BYTES, - OP_NOOP_CHUNKS, - OP_DEPOSIT_CHUNKS, - OP_TRANSFER_TO_NEW_CHUNKS, - OP_WITHDRAW_CHUNKS, - OP_TRANSFER_CHUNKS, - OP_FULL_EXIT_CHUNKS, - OP_CHANGE_PUBKEY_CHUNKS, - OP_FORCE_EXIT_CHUNKS, - OP_ORDER_MATCHING_CHUNKS, - OP_DEPOSIT_HASH_SIZE, - OP_FULLEXIT_HASH_SIZE -};