diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43f1fc20..0bed1d47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,3 +55,4 @@ jobs: - run: npm install - run: npm run lint - run: npm run fmt:check + - run: npm run lintjs diff --git a/package.json b/package.json index cdd39ca2..23354058 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "verify:ZkEVM:mainnet": "npx hardhat run deployment/verifyContracts.js --network mainnet", "deployApplications:backstopTestnet0": "npx hardhat run src/deployment/4_deployL1Applications.js --network sepolia && npx hardhat run src/deployment/5_deployL2Applications.js --network backstopTestnet0 && npx hardhat run src/deployment/6_chainInfoUpdate.js --network sepolia && npx hardhat run src/deployment/7_claimChainInfo.js --network backstopTestnet0", "compile": "npx hardhat compile", - "lintjs": "npx eslint ./src", - "lintjs:fix": "npx eslint ./src --fix", + "lintjs": "npx eslint ./src && npx eslint ./test", + "lintjs:fix": "npx eslint ./src --fix && npx eslint ./test --fix", "test": "npx hardhat test" }, "dependencies": { diff --git a/src/deployment/4_deployL1Applications.js b/src/deployment/4_deployL1Applications.js index 173775a3..1e8a9449 100644 --- a/src/deployment/4_deployL1Applications.js +++ b/src/deployment/4_deployL1Applications.js @@ -2,8 +2,7 @@ /* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */ const path = require('path'); const fs = require('fs'); -const { expect } = require('chai'); -const { ethers, upgrades } = require('hardhat'); +const { ethers } = require('hardhat'); require('dotenv').config({ path: path.resolve(__dirname, '../.env') }); const pathOutputJson = path.join(__dirname, './deploy_output_l1_applications.json'); @@ -12,10 +11,7 @@ const pathOngoingDeploymentJson = path.join(__dirname, './deploy_ongoing_l1_appl // const deployParameters = require('./deploy_parameters.json'); const deployParameters = {}; -const delay = ms => new Promise(res => setTimeout(res, ms)); - async function main() { - // Check if there's an ongoing deployment let ongoingDeployment = {}; if (fs.existsSync(pathOngoingDeploymentJson)) { @@ -27,18 +23,18 @@ async function main() { * Check that every necessary parameter is fullfilled */ /* - const mandatoryDeploymentParameters = [ - ]; - - for (const parameterName of mandatoryDeploymentParameters) { - if (deployParameters[parameterName] === undefined || deployParameters[parameterName] === '') { - throw new Error(`Missing parameter: ${parameterName}`); - } - } - - const { - } = deployParameters; - */ + *const mandatoryDeploymentParameters = [ + *]; + * + *for (const parameterName of mandatoryDeploymentParameters) { + * if (deployParameters[parameterName] === undefined || deployParameters[parameterName] === '') { + * throw new Error(`Missing parameter: ${parameterName}`); + * } + *} + * + *const { + *} = deployParameters; + */ // Load provider let currentProvider = ethers.provider; @@ -77,10 +73,10 @@ async function main() { } else { [deployer] = (await ethers.getSigners()); } - let deployerBalance = await currentProvider.getBalance(deployer.address); + const deployerBalance = await currentProvider.getBalance(deployer.address); console.log('using deployer: ', deployer.address, 'balance is ', deployerBalance.toString()); -// ../../contracts/L1GlobalChainInfoPublisher.sol ../../contracts/L1GlobalForkRequester.sol + // ../../contracts/L1GlobalChainInfoPublisher.sol ../../contracts/L1GlobalForkRequester.sol const L1GlobalChainInfoPublisherFactory = await ethers.getContractFactory('L1GlobalChainInfoPublisher', { signer: deployer, @@ -94,7 +90,6 @@ async function main() { // save an ongoing deployment ongoingDeployment.l1GlobalChainInfoPublisherContract = l1GlobalChainInfoPublisherContract.address; fs.writeFileSync(pathOngoingDeploymentJson, JSON.stringify(ongoingDeployment, null, 1)); - } else { l1GlobalChainInfoPublisherContract = ChainIdManagerFactory.attach(ongoingDeployment.l1GlobalChainInfoPublisher); console.log('#######################\n'); @@ -106,18 +101,18 @@ async function main() { }); /* - let newDeployerBalance; - while (!newDeployerBalance || newDeployerBalance.eq(deployerBalance)) { - newDeployerBalance = await currentProvider.getBalance(deployer.address); - if (newDeployerBalance.lt(deployerBalance)) { - break; - } else { - console.log('Waiting for RPC node to notice account balance change before trying next deployment'); - await delay(5000); - } - } - console.log('continue using deployer: ', deployer.address, 'balance is now', deployerBalance.toString()); - */ + *let newDeployerBalance; + *while (!newDeployerBalance || newDeployerBalance.eq(deployerBalance)) { + * newDeployerBalance = await currentProvider.getBalance(deployer.address); + * if (newDeployerBalance.lt(deployerBalance)) { + * break; + * } else { + * console.log('Waiting for RPC node to notice account balance change before trying next deployment'); + * await delay(5000); + * } + *} + *console.log('continue using deployer: ', deployer.address, 'balance is now', deployerBalance.toString()); + */ if (!ongoingDeployment.l1GlobalForkRequester) { l1GlobalForkRequesterContract = await L1GlobalForkRequesterFactory.deploy(); @@ -135,7 +130,7 @@ async function main() { const outputJson = { l1GlobalChainInfoPublisher: l1GlobalChainInfoPublisherContract.address, - l1GlobalForkRequester: l1GlobalForkRequesterContract.address + l1GlobalForkRequester: l1GlobalForkRequesterContract.address, }; fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1)); diff --git a/src/deployment/5_deployL2Applications.js b/src/deployment/5_deployL2Applications.js index 743b6aee..76936060 100644 --- a/src/deployment/5_deployL2Applications.js +++ b/src/deployment/5_deployL2Applications.js @@ -2,8 +2,7 @@ /* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */ const path = require('path'); const fs = require('fs'); -const { expect } = require('chai'); -const { ethers, upgrades } = require('hardhat'); +const { ethers } = require('hardhat'); require('dotenv').config({ path: path.resolve(__dirname, '../.env') }); const pathGenesisJson = path.join(__dirname, './genesis.json'); @@ -15,10 +14,7 @@ const pathOngoingDeploymentJson = path.join(__dirname, './deploy_ongoing_l2_appl const deployParameters = require('./deploy_application_parameters.json'); -const delay = ms => new Promise(res => setTimeout(res, ms)); - async function main() { - // Check that we already have the L1 settings we need if (!fs.existsSync(pathOutputJsonL1Applications)) { throw new Error('No l1 application addresses found. Deploy l1 applications first.'); @@ -28,15 +24,13 @@ async function main() { } const l1ApplicationAddresses = require(pathOutputJsonL1Applications); - const l1SystemAddresses = require(pathOutputJsonL1System); const genesisJSON = require(pathGenesisJson); const genesisEntries = genesisJSON.genesis; let l2BridgeAddress; - for(const genesisIdx in genesisEntries) { - const genesisEntry = genesisEntries[genesisIdx]; - if (genesisEntry.contractName == "PolygonZkEVMBridge proxy") { - l2BridgeAddress = genesisEntry.address; + for (const [, genesisEntry] of Object.entries(genesisEntries)) { + if (genesisEntry.contractName === 'PolygonZkEVMBridge proxy') { + l2BridgeAddress = genesisEntry.address; break; } } @@ -46,18 +40,16 @@ async function main() { const { l1GlobalChainInfoPublisher, - l1GlobalForkRequester + l1GlobalForkRequester, } = l1ApplicationAddresses; if (!l1GlobalForkRequester) { - throw new Error("Missing l1GlobalForkRequester address"); + throw new Error('Missing l1GlobalForkRequester address'); } if (!l1GlobalChainInfoPublisher) { - throw new Error("Missing l1GlobalChainInfoPublisher address"); + throw new Error('Missing l1GlobalChainInfoPublisher address'); } - const forkonomicTokenAddress = l1SystemAddresses.maticTokenAddress; - // Check if there's an ongoing deployment let ongoingDeployment = {}; if (fs.existsSync(pathOngoingDeploymentJson)) { @@ -71,7 +63,7 @@ async function main() { const mandatoryDeploymentParameters = [ 'adjudicationFrameworkDisputeFee', 'arbitratorDisputeFee', - 'forkArbitratorDisputeFee' + 'forkArbitratorDisputeFee', ]; for (const parameterName of mandatoryDeploymentParameters) { @@ -81,21 +73,19 @@ async function main() { } let { - adjudicationFrameworkDisputeFee, - forkArbitratorDisputeFee, - arbitratorDisputeFee, - arbitratorOwner, realityETHAddress, // This is optional, it will be deployed if not supplied - initialArbitratorAddresses // This can be an empty array + initialArbitratorAddresses, // This can be an empty array } = deployParameters; // Load provider - let currentProvider = ethers.provider; + const currentProvider = ethers.provider; - //const feeData = await currentProvider.getFeeData(); - //console.log('feeData', feeData); - //const block = await currentProvider.getBlock('latest'); - //console.log('latest block', block); + /* + * const feeData = await currentProvider.getFeeData(); + * console.log('feeData', feeData); + * const block = await currentProvider.getBlock('latest'); + * console.log('latest block', block); + */ // Load deployer let deployer; @@ -108,7 +98,7 @@ async function main() { } else { [deployer] = (await ethers.getSigners()); } - let deployerBalance = await currentProvider.getBalance(deployer.address); + const deployerBalance = await currentProvider.getBalance(deployer.address); console.log('using deployer: ', deployer.address, 'balance is ', deployerBalance.toString()); if (!realityETHAddress && ongoingDeployment.realityETH) { @@ -116,7 +106,7 @@ async function main() { } // NB If we deploy then we only do 1 initial arbitrator. But there may be multiple in the config. - if (initialArbitratorAddresses.length == 0 && ongoingDeployment.initialArbitrator) { + if (initialArbitratorAddresses.length === 0 && ongoingDeployment.initialArbitrator) { initialArbitratorAddresses = [ongoingDeployment.initialArbitrator]; } @@ -143,8 +133,7 @@ async function main() { signer: deployer, }); - if (initialArbitratorAddresses.length == 0) { - + if (initialArbitratorAddresses.length === 0) { if (!ongoingDeployment.initialArbitrator) { const arbitratorContract = await arbitratorFactory.deploy(); console.log('#######################\n'); @@ -158,7 +147,6 @@ async function main() { fs.writeFileSync(pathOngoingDeploymentJson, JSON.stringify(ongoingDeployment, null, 1)); initialArbitratorAddresses = [arbitratorContract.address]; - } else { arbitratorContract = arbitratorFactory.attach(initialArbitratorAddresses[0]); console.log('#######################\n'); @@ -167,7 +155,6 @@ async function main() { } } - const l2ChainInfoFactory = await ethers.getContractFactory('L2ChainInfo', { signer: deployer, }); @@ -176,7 +163,7 @@ async function main() { if (!ongoingDeployment.l2ChainInfo) { l2ChainInfoContract = await l2ChainInfoFactory.deploy( l2BridgeAddress, - l1GlobalChainInfoPublisher + l1GlobalChainInfoPublisher, ); console.log('#######################\n'); console.log('L2ChainInfo deployed to:', l2ChainInfoContract.address); @@ -202,7 +189,7 @@ async function main() { realityETHContract.address, l2ChainInfoContract.address, l1GlobalForkRequester, - forkArbitratorDisputeFee + forkArbitratorDisputeFee, ); console.log('#######################\n'); console.log('L2ForkArbitrator deployed to:', l2ForkArbitratorContract.address); @@ -216,7 +203,6 @@ async function main() { console.log('L2ForkArbitrator already deployed on: ', l2ForkArbitratorContract.address); } - const adjudicationFrameworkFactory = await ethers.getContractFactory('AdjudicationFramework', { signer: deployer, }); @@ -229,7 +215,7 @@ async function main() { realityETHContract.address, adjudicationFrameworkDisputeFee, l2ForkArbitratorContract.address, - initialArbitratorAddresses + initialArbitratorAddresses, ); console.log('#######################\n'); console.log('AdjudicationFramework deployed to:', adjudicationFrameworkContract.address); @@ -248,7 +234,7 @@ async function main() { arbitrators: initialArbitratorAddresses, l2ChainInfo: l2ChainInfoContract.address, l2ForkArbitrator: l2ForkArbitratorContract.address, - adjudicationFramework: adjudicationFrameworkContract.address + adjudicationFramework: adjudicationFrameworkContract.address, }; fs.writeFileSync(pathOutputJsonL2Applications, JSON.stringify(outputJson, null, 1)); diff --git a/src/deployment/6_chainInfoUpdate.js b/src/deployment/6_chainInfoUpdate.js index 0831620a..bcd8d250 100644 --- a/src/deployment/6_chainInfoUpdate.js +++ b/src/deployment/6_chainInfoUpdate.js @@ -1,4 +1,4 @@ -/* eslint-disable no-await-in-loop */ +/* eslint-disable no-await-in-loop, import/no-dynamic-require */ /* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved */ const path = require('path'); @@ -14,7 +14,6 @@ const l2Applications = require(pathOutputJsonL2Applications); const l1SystemAddresses = require(pathOutputJsonL1System); async function main() { - const currentProvider = ethers.provider; let deployer; if (process.env.PVTKEY) { @@ -35,9 +34,13 @@ async function main() { const l1GlobalChainInfoPublisher = l1GlobalChainInfoPublisherFactory.attach(l1Applications.l1GlobalChainInfoPublisher); console.log('sending chain info update with addresses', l1BridgeAddress, l2Applications.l2ChainInfo); - const result = await l1GlobalChainInfoPublisher.updateL2ChainInfo(l1BridgeAddress, l2Applications.l2ChainInfo, ethers.constants.AddressZero, ethers.constants.AddressZero); + const result = await l1GlobalChainInfoPublisher.updateL2ChainInfo( + l1BridgeAddress, + l2Applications.l2ChainInfo, + ethers.constants.AddressZero, + ethers.constants.AddressZero, + ); console.log('sent tx, hash is', result.hash); - } main().catch((e) => { diff --git a/src/deployment/7_claimChainInfo.js b/src/deployment/7_claimChainInfo.js index d2d31af9..ac896798 100644 --- a/src/deployment/7_claimChainInfo.js +++ b/src/deployment/7_claimChainInfo.js @@ -1,29 +1,32 @@ -/* eslint-disable no-await-in-loo/ -/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved */ +/* eslint-disable no-await-in-loop, no-restricted-syntax, no-continue, import/no-dynamic-require, no-console, no-inner-declarations, no-undef, import/no-unresolved */ -// Script to run claim for the chain info update -// Based on https://github.com/0xPolygonHermez/code-examples/blob/main/zkevm-nft-bridge-example/scripts/claimMockNFT.js#L34 -// Same thing should work for any other claim on L2 except you have to substitute the address of the claimer contract +/* + * Script to run claim for the chain info update + * Based on https://github.com/0xPolygonHermez/code-examples/blob/main/zkevm-nft-bridge-example/scripts/claimMockNFT.js#L34 + * Same thing should work for any other claim on L2 except you have to substitute the address of the claimer contract + */ const path = require('path'); require('dotenv').config({ path: path.resolve(__dirname, '../../.env') }); const { ethers } = require('hardhat'); const hre = require('hardhat'); -const network_name = hre.network.name; -const bridgeAPIEndpoint = hre.config.zkEVMServices[network_name].bridgeAPIEndpoint; +const networkName = hre.network.name; +const { bridgeAPIEndpoint } = hre.config.zkEVMServices[networkName]; const pathGenesisJson = path.join(__dirname, './genesis.json'); const pathOutputJsonL2Applications = path.join(__dirname, './deploy_output_l2_applications.json'); +const axiosPackage = require('axios'); + const genesisJSON = require(pathGenesisJson); const genesisEntries = genesisJSON.genesis; const l2Applications = require(pathOutputJsonL2Applications); let l2BridgeAddress; -for(const genesisIdx in genesisEntries) { - const genesisEntry = genesisEntries[genesisIdx]; - if (genesisEntry.contractName == "PolygonZkEVMBridge proxy") { + +for (const [, genesisEntry] of Object.entries(genesisEntries)) { + if (genesisEntry.contractName === 'PolygonZkEVMBridge proxy') { l2BridgeAddress = genesisEntry.address; break; } @@ -36,7 +39,6 @@ const merkleProofString = '/merkle-proof'; const getClaimsFromAcc = '/bridges/'; async function main() { - const currentProvider = ethers.provider; let deployer; if (process.env.PVTKEY) { @@ -51,21 +53,20 @@ async function main() { const baseURL = bridgeAPIEndpoint; if (!baseURL) { - throw new Error("Missing baseURL"); + throw new Error('Missing baseURL'); } - - const axios = require('axios').create({ + + const axios = axiosPackage.create({ baseURL, }); const l2BridgeFactory = await ethers.getContractFactory('PolygonZkEVMBridge', deployer); const l2BridgeContract = l2BridgeFactory.attach(l2BridgeAddress); - const sleep = ms => new Promise(r => setTimeout(r, ms)); + const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); function filterClaimable(_depositsArray, _verbose) { - - let claimable = []; + const claimable = []; for (let i = 0; i < _depositsArray.length; i++) { const currentDeposit = _depositsArray[i]; if (!currentDeposit.ready_for_claim) { @@ -74,8 +75,8 @@ async function main() { } continue; } - - if (currentDeposit.claim_tx_hash != "") { + + if (currentDeposit.claim_tx_hash !== '') { if (_verbose) { console.log('already claimed: ', currentDeposit.claim_tx_hash); } @@ -85,21 +86,19 @@ async function main() { } return claimable; - } let depositsArray; let found = false; console.log('Trying claim for contract', l2Applications.l2ChainInfo, 'against bridge', l2BridgeAddress, '...'); while (!found) { - const depositAxions = await axios.get(getClaimsFromAcc + l2Applications.l2ChainInfo, { params: { limit: 100, offset: 0 } }); depositsArray = filterClaimable(depositAxions.data.deposits, true); if (depositsArray.length === 0) { const secs = 5; - console.log('No deposits ready to claim yet, retrying in '+secs+' seconds...'); - await sleep(secs*1000); + console.log(`No deposits ready to claim yet, retrying in ${secs} seconds...`); + await sleep(secs * 1000); } else { found = true; } @@ -108,7 +107,6 @@ async function main() { for (let i = 0; i < depositsArray.length; i++) { const currentDeposit = depositsArray[i]; if (currentDeposit.ready_for_claim) { - const proofAxios = await axios.get(merkleProofString, { params: { deposit_cnt: currentDeposit.deposit_cnt, net_id: currentDeposit.orig_net }, }); @@ -126,9 +124,9 @@ async function main() { currentDeposit.amount, currentDeposit.metadata, ); - console.log('Claim message succesfully sent: ', claimTx.hash); + console.log('Claim message successfully sent: ', claimTx.hash); await claimTx.wait(); - console.log('Claim message succesfully mined ', claimTx.hash); + console.log('Claim message successfully mined ', claimTx.hash); } else { console.log('Not ready yet!'); } diff --git a/src/deployment/verifyApplicationL1Contracts.js b/src/deployment/verifyApplicationL1Contracts.js index 736353f1..09c137cc 100644 --- a/src/deployment/verifyApplicationL1Contracts.js +++ b/src/deployment/verifyApplicationL1Contracts.js @@ -1,4 +1,4 @@ -/* eslint-disable import/no-dynamic-require, no-await-in-loop, no-restricted-syntax, guard-for-in */ +/* eslint-disable no-console, import/no-dynamic-require, no-await-in-loop, no-restricted-syntax, guard-for-in */ // Broken and/or not fully tested @@ -7,10 +7,8 @@ const path = require('path'); const hre = require('hardhat'); const { expect } = require('chai'); -const pathDeployParameters = path.join(__dirname, './deploy_application_parameters.json'); const pathDeployL1OutputParameters = path.join(__dirname, './deploy_output_l1_applications.json'); -const deployParameters = require(pathDeployParameters); const deployL1OutputParameters = require(pathDeployL1OutputParameters); async function main() { @@ -23,7 +21,7 @@ async function main() { await hre.run( 'verify:verify', { - address: deployL1OutputParameters.l1GlobalChainInfoPublisher + address: deployL1OutputParameters.l1GlobalChainInfoPublisher, }, ); } catch (error) { @@ -34,14 +32,13 @@ async function main() { await hre.run( 'verify:verify', { - address: deployL1OutputParameters.l1GlobalForkRequester + address: deployL1OutputParameters.l1GlobalForkRequester, }, ); } catch (error) { console.log(error); expect(error.message.toLowerCase().includes('already verified')).to.be.equal(true); } - } main() @@ -50,4 +47,3 @@ main() console.error(error); process.exit(1); }); - diff --git a/src/deployment/verifyApplicationL2Contracts.js b/src/deployment/verifyApplicationL2Contracts.js index 7334facc..cff57c93 100644 --- a/src/deployment/verifyApplicationL2Contracts.js +++ b/src/deployment/verifyApplicationL2Contracts.js @@ -1,4 +1,4 @@ -/* eslint-disable import/no-dynamic-require, no-await-in-loop, no-restricted-syntax, guard-for-in */ +/* eslint-disable no-console, import/no-dynamic-require, no-await-in-loop, no-restricted-syntax, guard-for-in */ // Broken and/or not fully tested @@ -27,7 +27,7 @@ async function main() { await hre.run( 'verify:verify', { - address: deployL2OutputParameters.realityETH + address: deployL2OutputParameters.realityETH, }, ); } catch (error) { @@ -39,7 +39,7 @@ async function main() { await hre.run( 'verify:verify', { - address: deployL2OutputParameters.arbitrators[0] + address: deployL2OutputParameters.arbitrators[0], }, ); } catch (error) { @@ -48,16 +48,15 @@ async function main() { } try { - console.log('verify', deployL2OutputParameters.l2ChainInfo, 'using params', deployParameters.l2BridgeAddress, deployL1OutputParameters.l1GlobalChainInfoPublisher); await hre.run( 'verify:verify', { - address: deployL2OutputParameters.l2ChainInfo - ,constructorArguments: [ + address: deployL2OutputParameters.l2ChainInfo, + constructorArguments: [ deployParameters.l2BridgeAddress, - deployL1OutputParameters.l1GlobalChainInfoPublisher - ] + deployL1OutputParameters.l1GlobalChainInfoPublisher, + ], }, ); } catch (error) { @@ -66,17 +65,16 @@ async function main() { } try { - await hre.run( 'verify:verify', { - address: deployL2OutputParameters.l2ForkArbitrator - ,constructorArguments: [ + address: deployL2OutputParameters.l2ForkArbitrator, + constructorArguments: [ deployL2OutputParameters.realityETH, deployL2OutputParameters.l2ChainInfo, deployL1OutputParameters.l1GlobalForkRequester, - deployParameters.forkArbitratorDisputeFee - ] + deployParameters.forkArbitratorDisputeFee, + ], }, ); } catch (error) { @@ -84,28 +82,23 @@ async function main() { expect(error.message.toLowerCase().includes('already verified')).to.be.equal(true); } - try { - await hre.run( 'verify:verify', { - address: deployL2OutputParameters.adjudicationFramework - ,constructorArguments: [ + address: deployL2OutputParameters.adjudicationFramework, + constructorArguments: [ deployL2OutputParameters.realityETH, deployParameters.adjudicationFrameworkDisputeFee, deployL2OutputParameters.l2ForkArbitrator, - deployL2OutputParameters.arbitrators - ] + deployL2OutputParameters.arbitrators, + ], }, ); } catch (error) { console.log(error); expect(error.message.toLowerCase().includes('already verified')).to.be.equal(true); } - - return; - } main() @@ -114,4 +107,3 @@ main() console.error(error); process.exit(1); }); -