Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment script for the contract #57

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MNEMONIC="test test test test test test test test test test test junk"
INFURA_PROJECT_ID=""
ETHERSCAN_API_KEY=""
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zkproverjs/
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
plugins: [
'mocha',
],
env: {
node: true,
mocha: true,
},
extends: 'airbnb-base',
rules: {
indent: ['error', 4],
'mocha/no-exclusive-tests': 'error',
'max-len': ['error', {
code: 140, comments: 200, ignoreStrings: true, ignoreTemplateLiterals: true,
}],
'no-unused-vars': [2, { varsIgnorePattern: 'export^' }],
'no-return-assign': [0],
'no-underscore-dangle': [0],
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'func-names': [0],
'class-methods-use-this': [0],
'no-bitwise': [0],
'no-param-reassign': 'off',
'no-console': [2, { allow: ['warn', 'error'] }],
'import/prefer-default-export': [0],
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'multiline-comment-style': 'error',
'import/no-extraneous-dependencies': 'off',
'no-promise-executor-return': 'off',
},
};
16 changes: 5 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
- run: yarn --frozen-lockfile
- run: yarn lint
node-version: 16
cache: 'npm'
cache-dependency-path: ./package-lock.json
- run: npm install
- run: npm run lint
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ stats.json
.stylelintcache
cache/
out/
.env
deployment/deploy_parameters.json
artifacts/*
cache_hardhat/
.openzeppelin/
deployment/genesis.json
deployment/deploy_output.json

15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "always"
}
}
]
}
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": ["prettier"],
"rules": {
"compiler-version": "off",
"max-states-count": "off"
"max-states-count": "off",
"no-empty-blocks": "off"
}
}
2 changes: 2 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ development/contracts/interfaces/IArbitratorForeignProxy.sol
development/contracts/ERC20Mint.sol
development/contracts/TokenBridge.sol
development/contracts/ERC20.sol
development/contracts/dependencies/*
lib/zkevm-contracts/contracts/mocks/VerifierRollupHelperMock.sol
152 changes: 152 additions & 0 deletions deployment/1_deployforkableToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/* eslint-disable no-await-in-loop, no-use-before-define, no-lonely-if, import/no-dynamic-require, global-require */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */
const path = require('path');
const fs = require('fs');
const { ethers, upgrades } = require('hardhat');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const { expect } = require('chai');
const { deployPolygonZkEVMDeployer } = require('./helpers/deployment-helpers');

const { create2Deployment } = require('./helpers/deployment-helpers');
const deployParameters = require('./deploy_parameters.json');

const pathDeployParameters = path.join(__dirname, './deploy_parameters.json');

async function main() {
const attemptsDeployProxy = 5;
// Load provider
let currentProvider = ethers.provider;
if (deployParameters.multiplierGas || deployParameters.maxFeePerGas) {
if (process.env.HARDHAT_NETWORK !== 'hardhat') {
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`);
if (deployParameters.maxPriorityFeePerGas && deployParameters.maxFeePerGas) {
console.log(`Hardcoded gas used: MaxPriority${deployParameters.maxPriorityFeePerGas} gwei, MaxFee${deployParameters.maxFeePerGas} gwei`);
const FEE_DATA = {
maxFeePerGas: ethers.utils.parseUnits(deployParameters.maxFeePerGas, 'gwei'),
maxPriorityFeePerGas: ethers.utils.parseUnits(deployParameters.maxPriorityFeePerGas, 'gwei'),
};
currentProvider.getFeeData = async () => FEE_DATA;
} else {
console.log('Multiplier gas used: ', deployParameters.multiplierGas);
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return {
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000),
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000),
};
}
currentProvider.getFeeData = overrideFeeData;
}
}
}
// Load deployer
let deployer;
if (deployParameters.deployerPvtKey) {
deployer = new ethers.Wallet(deployParameters.deployerPvtKey, currentProvider);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0').connect(currentProvider);
} else {
[deployer] = (await ethers.getSigners());
}
console.log('Deployer: ', deployer.address);

// Load initialZkEVMDeployerOwner
const {
initialZkEVMDeployerOwner,
salt,
} = deployParameters;

if (initialZkEVMDeployerOwner === undefined || initialZkEVMDeployerOwner === '') {
throw new Error('Missing parameter: initialZkEVMDeployerOwner');
}

// Deploy PolygonZkEVMDeployer if is not deployed already using keyless deployment
const [zkEVMDeployerContract, keylessDeployer] = await deployPolygonZkEVMDeployer(initialZkEVMDeployerOwner, deployer);
if (keylessDeployer === ethers.constants.AddressZero) {
console.log('#######################\n');
console.log('polygonZkEVMDeployer already deployed on: ', zkEVMDeployerContract.address);
} else {
console.log('#######################\n');
console.log('polygonZkEVMDeployer deployed on: ', zkEVMDeployerContract.address);
}

expect(deployer.address).to.be.equal(await zkEVMDeployerContract.owner());

const proxyAdminFactory = await ethers.getContractFactory('ProxyAdmin', deployer);
const deployTransactionAdmin = (proxyAdminFactory.getDeployTransaction()).data;
const dataCallAdmin = proxyAdminFactory.interface.encodeFunctionData('transferOwnership', [deployer.address]);
const [proxyAdminAddress, isProxyAdminDeployed] = await create2Deployment(
zkEVMDeployerContract,
salt,
deployTransactionAdmin,
dataCallAdmin,
deployer,
);

if (isProxyAdminDeployed) {
console.log('#######################\n');
console.log('proxyAdmin deployed on: ', proxyAdminAddress);
} else {
console.log('#######################\n');
console.log('proxyAdmin already deployed on: ', proxyAdminAddress);
}

// Deploy implementation PolygonZkEVMBridge
const createChildrenLib = await ethers.getContractFactory('CreateChildren', deployer);
const createChildrenLibDeployTransaction = (createChildrenLib.getDeployTransaction()).data;
const overrideGasLimit = ethers.BigNumber.from(6500000);
const [createChildrenImplementationAddress] = await create2Deployment(
zkEVMDeployerContract,
salt,
createChildrenLibDeployTransaction,
null,
deployer,
overrideGasLimit,
);

console.log('#######################\n');
console.log('createChildrenImplementation deployed on: ', createChildrenImplementationAddress);

const forkonomicTokenFactory = await ethers.getContractFactory('ForkonomicToken', {
signer: deployer,
libraries: { CreateChildren: createChildrenImplementationAddress },
});
for (let i = 0; i < attemptsDeployProxy; i++) {
try {
forkonomicTokenProxy = await upgrades.deployProxy(forkonomicTokenFactory, [], {
initializer: false,
libraries: {
CreateChildren: createChildrenImplementationAddress,
},
constructorArgs: [],
unsafeAllowLinkedLibraries: true,
});
break;
} catch (error) {
console.log(`attempt ${i}`);
console.log('upgrades.deployProxy of forkonomicToken ', error.message);
}

// reach limits of attempts
if (i + 1 === attemptsDeployProxy) {
throw new Error('forkonomicToken contract has not been deployed');
}
}
console.log('#######################\n');
console.log('forkonomicToken deployed on: ', forkonomicTokenProxy.address);
console.log(
' Use this forkonomic token instead of the matic token in the next steps.',
);

// append the new address to the deploy_parameters.json file as the maticTokenAddress, even though we use it as native token
deployParameters.proxyAdminAddress = proxyAdminAddress;
deployParameters.maticTokenAddress = forkonomicTokenProxy.address;
deployParameters.createChildrenImplementationAddress = createChildrenImplementationAddress;
deployParameters.zkEVMDeployerAddress = zkEVMDeployerContract.address;
fs.writeFileSync(pathDeployParameters, JSON.stringify(deployParameters, null, 1));
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
Loading