diff --git a/deployment/2_deployPolygonZKEVMDeployer.js b/deployment/2_deployPolygonZKEVMDeployer.js index 6de84d664..fdb9836c2 100644 --- a/deployment/2_deployPolygonZKEVMDeployer.js +++ b/deployment/2_deployPolygonZKEVMDeployer.js @@ -28,8 +28,8 @@ async function main() { async function overrideFeeData() { const feedata = await ethers.provider.getFeeData(); return { - maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas), // add 3 decimals - maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas), // add 3 decimals + maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000), + maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000), }; } currentProvider.getFeeData = overrideFeeData; diff --git a/deployment/3_deployContracts.js b/deployment/3_deployContracts.js index 8e25e5de7..4b04425da 100644 --- a/deployment/3_deployContracts.js +++ b/deployment/3_deployContracts.js @@ -99,8 +99,8 @@ async function main() { async function overrideFeeData() { const feedata = await ethers.provider.getFeeData(); return { - maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000), // add 3 decimals - maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000), // add 3 decimals + maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000), + maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000), }; } currentProvider.getFeeData = overrideFeeData; @@ -347,7 +347,7 @@ async function main() { console.log('genesisRoot:', genesisRootHex); console.log('trustedSequencerURL:', trustedSequencerURL); console.log('networkName:', networkName); - console.log('networkName:', forkID); + console.log('forkID:', forkID); const PolygonZkEVMFactory = await ethers.getContractFactory('PolygonZkEVM', deployer); @@ -434,7 +434,7 @@ async function main() { } console.log('\n#######################'); - console.log('##### Checks PolygonZkEVMMock #####'); + console.log('##### Checks PolygonZkEVM #####'); console.log('#######################'); console.log('PolygonZkEVMGlobalExitRootAddress:', await polygonZkEVMContract.globalExitRootManager()); console.log('maticTokenAddress:', await polygonZkEVMContract.matic()); diff --git a/deployment/README.md b/deployment/README.md index 25fdd1355..19bf1191a 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -13,6 +13,7 @@ cp .env.example .env ``` Fill `.env` with your `MNEMONIC` and `INFURA_PROJECT_ID` +If you want to verify the contracts also fill the `ETHERSCAN_API_KEY` ``` cd deployment @@ -20,16 +21,24 @@ cp deploy_parameters.json.example deploy_parameters.json ``` Fill created `deploy_parameters.json` with appropiate parameters. +See below for more information about the `deploy_parameters.json` -To deploy contracts first deploy and verify the `PolygonZkEVMDeployer` +The first step is deploying and verifying the `PolygonZkEVMDeployer`, this will be the factory for deterministic contracts, the address of the contracts will depend on the `salt` and the `initialZkEVMDeployerOwner` + +This contrat is deployed using a keyless deployment, therefore the gasPrice is hardcoded. +The value is on `100 gweis`, if it's necessary to update it go to `helpers/deployment-helpers.js` and update the `gasPriceKeylessDeployment` constant. +Note that this operation will change all the deterministic address deployed. ``` npm run deploy:deployer:ZkEVM:goerli npm run verify:deployer:ZkEVM:goerli ``` -Then deploy the contracts, if we are on testnet use `deploy:testnet:ZkEVM:${network}`, in other cases use `deploy:ZkEVM:${network}` and -set in deploy_parameters the `maticTokenAddress`: +To deploy on testnet is necessary a token MATIC contract, therefore, there's another script that previously to the actual deployment, deploys a matic contracts and adds it automatically to the `deploy_parameters.json` + +To deploy on testnet use:`deploy:testnet:ZkEVM:${network}` + +In other cases use fullfill `maticTokenAddress` in the `deploy_parameters.json` and run `deploy:ZkEVM:${network}` ``` npm run deploy:testnet:ZkEVM:goerli @@ -46,25 +55,34 @@ A new folder will be created witth the following name `deployments/${network}_$( ## deploy-parameters.json +- `realVerifier`: bool, Indicates whether deploy a real verifier or not - `trustedSequencerURL`: string, trustedSequencer URL -- `trustedSequencerAddress`: address, trusted sequencer addresss -- `realVerifier`: boolean, deploy or not a real verifier -- `chainID`: uint64, chainID - `networkName`: string, networkName +- `version`:string, will just be emitted at initialization of the contract, usefull just for synchronizer +- `trustedSequencer`: address, trusted sequencer addresss +- `chainID`: uint64, chainID of the zkEVM +- `trustedAggregator`:address, Trusted aggregator address +- `trustedAggregatorTimeout`: uint64, If a sequence is not verified in this timeout everyone can verify it +- `pendingStateTimeout`: uint64, Once a pending state exceeds this timeout it can be consolidated +- `forkID`: uint64, Fork ID of the zkEVM, indicates the prover (zkROM/executor) version +- `admin`:address, Admin address, can adjust PolygonZkEVM parameters or stop the emergency state +- `zkEVMOwner`: address, Able to put the PolygonZkEVM into emergency state (kill switch) +- `timelockAddress`: address, Timelock owner address, able to send start an upgradability process via timelock +- `minDelayTimelock`: number, Minimum timelock delay, +- `salt`: bytes32, Salt used in `PolygonZkEVMDeployer` to deploy deterministic contracts, such as the PolygonZkEVMBridge +- `initialZkEVMDeployerOwner`: address, Initial owner of the `PolygonZkEVMDeployer` +- `maticTokenAddress`: address, Matic token address, only if deploy on testnet can be left blank and will fullfilled by the scripts. +- `zkEVMDeployerAddress`: address, Address of the `PolygonZkEVMDeployer`. Can be left blank, will be fullfilled automatically with the `deploy:deployer:ZkEVM:goerli` script. ### Optional Parameters -- `deployerPvtKey`: string, deployerPvtKey of the deployer -- `maxFeePerGas`:string, maxFeePerGas of all txs -- `maxPriorityFeePerGas`:string, maxPriorityFeePerGas of all txs -- `multiplierGas`: number, Gas multiplier. If maxFeePerGas and maxPriorityFeePerGas are set, will not take effect -- `trustedSequencerPvtKey`: string, Trusted sequencer pvtKey in order to approve the matic tokens -- `PolygonZkEVMBridgeMock`:Boolean, Wheather the PolygonZkEVMBridge will be mock or not ( the mock version has a ether limitation on deposits) -- `admin`:address, Admin address -- `trustedAggregator`:address, Trusted aggregator address -- `minDelayTimelock`: number, minimum timelock delay, -- `timelockAddress`: address, Timelock owner address +- `deployerPvtKey`: string, pvtKey of the deployer, overrides the address in `MNEMONIC` of `.env` if exist +- `maxFeePerGas`:string, Set `maxFeePerGas`, must define aswell `maxPriorityFeePerGas` to use it +- `maxPriorityFeePerGas`:string, Set `maxPriorityFeePerGas`, must define aswell `maxFeePerGas` to use it +- `multiplierGas`: number, Gas multiplier with 3 decimals. If `maxFeePerGas` and `maxPriorityFeePerGas` are set, this will not take effect ## Notes -- `genesis.json` has been generated using the tool: `src/create-genesis.js` using as generator file: `genesis-gen.json` +- Since there are deterministic address you cannot deploy twice on the same network using the same `salt` and `initialZkEVMDeployerOwner`. Changing one of them is enough to make a new deployment. +- It's mandatory to delete the `.openzeppelin` upgradebility information in order to make a new deployment +- `genesis.json` has been generated using the tool: `1_createGenesis`, this script depends on the `deploy_parameters` aswell. diff --git a/deployment/deploy_parameters.json.example b/deployment/deploy_parameters.json.example index 79cc1fb10..a798213dc 100644 --- a/deployment/deploy_parameters.json.example +++ b/deployment/deploy_parameters.json.example @@ -14,11 +14,11 @@ "timelockAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "minDelayTimelock": 3600, "salt": "0x0000000000000000000000000000000000000000000000000000000000000000", - "zkEVMDeployerAddress":"", - "initialZkEVMDeployerOwner" :"0xaddress" + "initialZkEVMDeployerOwner" :"0xaddress", "maticTokenAddress":"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "zkEVMDeployerAddress":"", "deployerPvtKey": "", "maxFeePerGas":"", "maxPriorityFeePerGas":"", - "multiplierGas": "", + "multiplierGas": "" } \ No newline at end of file diff --git a/deployment/helpers/deployment-helpers.js b/deployment/helpers/deployment-helpers.js index e7fef540f..bbd7119f0 100644 --- a/deployment/helpers/deployment-helpers.js +++ b/deployment/helpers/deployment-helpers.js @@ -3,6 +3,8 @@ const { expect } = require('chai'); const { ethers } = require('hardhat'); +const gasPriceKeylessDeployment = '100'; // 100 gweis + async function deployPolygonZkEVMDeployer(deployerAddress, signer) { const PolgonZKEVMDeployerFactory = await ethers.getContractFactory('PolygonZkEVMDeployer', signer); @@ -11,7 +13,7 @@ async function deployPolygonZkEVMDeployer(deployerAddress, signer) { )).data; const gasLimit = ethers.BigNumber.from(1000000); // Put 1 Million, aprox 650k are necessary - const gasPrice = ethers.BigNumber.from(ethers.utils.parseUnits('100', 'gwei')); // just in case, seems pretty standard + const gasPrice = ethers.BigNumber.from(ethers.utils.parseUnits(gasPriceKeylessDeployment, 'gwei')); const to = '0x'; // bc deployment transaction, "to" is "0x" const tx = { to, diff --git a/hardhat.config.js b/hardhat.config.js index 3e5cc72a9..ff6d02c08 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -130,6 +130,15 @@ module.exports = { count: 20, }, }, + polygonZKEVMMainnet: { + url: "https://zkevm-rpc.com", + accounts: { + mnemonic: process.env.MNEMONIC || DEFAULT_MNEMONIC, + path: "m/44'/60'/0'/0", + initialIndex: 0, + count: 20, + }, + }, }, gasReporter: { enabled: !!process.env.REPORT_GAS, @@ -139,10 +148,19 @@ module.exports = { etherscan: { apiKey: { polygonZKEVMTestnet: `${process.env.ETHERSCAN_ZKEVM_API_KEY}`, + polygonZKEVMMainnet: `${process.env.ETHERSCAN_ZKEVM_API_KEY}`, goerli: `${process.env.ETHERSCAN_API_KEY}`, mainnet: `${process.env.ETHERSCAN_API_KEY}` }, customChains: [ + { + network: "polygonZKEVMMainnet", + chainId: 1101, + urls: { + apiURL: "https://api-zkevm.polygonscan.com/api", + browserURL: "https://zkevm.polygonscan.com/" + } + }, { network: "polygonZKEVMTestnet", chainId: 1442, diff --git a/test/contracts/polygonZkEVMTestnetV2.test.js b/test/contracts/polygonZkEVMTestnetV2.test.js index f571beaf2..508da7981 100644 --- a/test/contracts/polygonZkEVMTestnetV2.test.js +++ b/test/contracts/polygonZkEVMTestnetV2.test.js @@ -120,15 +120,17 @@ describe('Polygon ZK-EVM TestnetV2', () => { }); it('should check updateVersion', async () => { - const lastVerifiedBatch = 0; const newVersionString = '0.0.2'; - await expect(polygonZkEVMContract.updateVersion(newVersionString)) - .to.emit(polygonZkEVMContract, 'UpdateZkEVMVersion').withArgs(lastVerifiedBatch, forkID, newVersionString); + /* + * const lastVerifiedBatch = 0; + * await expect(polygonZkEVMContract.updateVersion(newVersionString)) + * .to.emit(polygonZkEVMContract, 'UpdateZkEVMVersion').withArgs(lastVerifiedBatch, forkID, newVersionString); + */ await expect(polygonZkEVMContract.updateVersion(newVersionString)) .to.be.revertedWith('VersionAlreadyUpdated'); - expect(await polygonZkEVMContract.version()).to.be.equal(1); + // expect(await polygonZkEVMContract.version()).to.be.equal(1); }); });