-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from 0xPolygonHermez/feature/updateUpgradeScript
Feature/update upgrade script
- Loading branch information
Showing
12 changed files
with
274 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## Requirements | ||
|
||
- node version: 14.x | ||
- npm version: 7.x | ||
|
||
## Upgrade | ||
|
||
``` | ||
npm i | ||
cp .env.example .env | ||
``` | ||
|
||
Fill `.env` with your `MNEMONIC` and `INFURA_PROJECT_ID` | ||
|
||
In order to upgrade the contracts we will need the information on `deployments/${network}_$(date +%s)` | ||
|
||
In project root, copy the `${network}.json` of the deployment that you want to upgrade and copy it on the `./.openzeppelin` | ||
e.g. `cp deployments/${network}_$(date +%s)/${network}.json ./.openzeppelin` | ||
|
||
Then fill the upgrade parameters: | ||
|
||
``` | ||
cd deployment | ||
cp upgrade_parameters.json.example upgrade_parameters.json | ||
``` | ||
|
||
Fill created `upgrade_parameters.json` with appropiate parameters. | ||
You should fullfill the upgrades array, with all the updates that you intend to do ( more information in `upgrade-parameters.json` section) | ||
|
||
if the deployment was deployed without a timelock you can use the `simpleUpgradeScript.js`: | ||
|
||
- Run the script | ||
|
||
Otherwise, in case of timelock use `timeLockUpgrade.js` | ||
|
||
- Run the script | ||
- Now the necessary transactions to interact with the timelock are printed in the screen `schedule` and `execute`, also will be saved in | ||
`./upgrade_output_${new Date().getTime() / 1000}.json` file | ||
- With the owner of the timelock (multisig or account), send the data printed by `schedule` to the `Timelock` contract. | ||
- Once the necessary `timelockMinDelay` has expired, with the same account you can now send the data printed by `execute` to the `Timelock` contract and the contracts will be upgraded. | ||
|
||
## upgrade-parameters.json | ||
|
||
- `timelockMinDelay`: number, timelock delay between the schedule and execution, must be bigger than current min delay | ||
- `upgrades`: Object, Indicates which address and to which implementation must upgrade | ||
- address: address of the current proxy | ||
- contractName: string, contract name that the proxy will be updated to.s | ||
|
||
### Optional Parameters | ||
|
||
- `multiplierGas`: number, Gas multiplier. If maxFeePerGas and maxPriorityFeePerGas are set, will not take effect | ||
- `deployerPvtKey`: string, deployerPvtKey of the deployer | ||
- `timelockSalt`: string, Optional salt for the timelock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-disable no-console, no-unused-vars */ | ||
const hre = require('hardhat'); | ||
const { ethers, upgrades } = require('hardhat'); | ||
const path = require('path'); | ||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') }); | ||
const upgradeParameters = require('./upgrade_parameters.json'); | ||
|
||
async function main() { | ||
// Set multiplier Gas | ||
let currentProvider = ethers.provider; | ||
if (upgradeParameters.multiplierGas) { | ||
if (process.env.HARDHAT_NETWORK !== 'hardhat') { | ||
const multiplierGas = upgradeParameters.multiplierGas; | ||
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`); | ||
async function overrideFeeData() { | ||
const feedata = await ethers.provider.getFeeData(); | ||
return { | ||
maxFeePerGas: feedata.maxFeePerGas.mul(multiplierGas), | ||
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(multiplierGas), | ||
}; | ||
} | ||
currentProvider.getFeeData = overrideFeeData; | ||
} | ||
} | ||
let deployer; | ||
if (upgradeParameters.deployerPvtKey) { | ||
deployer = new ethers.Wallet(upgradeParameters.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()); | ||
} | ||
|
||
// compìle contracts | ||
await hre.run('compile'); | ||
|
||
for (const upgrade of upgradeParameters.upgrades) { | ||
const proxyPolygonAddress = upgrade.address; | ||
const polygonZkEVMFactory = await ethers.getContractFactory(upgrade.contractName, deployer); | ||
|
||
const txZKEVM = await upgrades.upgradeProxy(proxyPolygonAddress, polygonZkEVMFactory); | ||
|
||
console.log(txZKEVM.deployTransaction); | ||
console.log(await txZKEVM.deployTransaction.wait()); | ||
console.log('upgrade succesfull', upgrade.contractName); | ||
} | ||
} | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.