-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
160 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { verify } from '../helpers'; | ||
|
||
export class CustomRuntimeEnvironment { | ||
constructor(private readonly hre: HardhatRuntimeEnvironment) {} | ||
|
||
async getTimelock(address: string) { | ||
const timelock = await this.hre.ethers.getContractAt( | ||
'ITimelockController', | ||
address | ||
); | ||
|
||
console.log(`Timelock found at ${await timelock.getAddress()}`); | ||
|
||
return timelock; | ||
} | ||
|
||
async getProxyAdmin(proxy: string) { | ||
const proxyAdmin = await this.hre.ethers.getContractAt( | ||
'IProxyAdmin', | ||
await this.hre.upgrades.erc1967.getAdminAddress(proxy) | ||
); | ||
|
||
console.log( | ||
`ProxyAdmin of ${proxy} found at ${await proxyAdmin.getAddress()}` | ||
); | ||
|
||
return proxyAdmin; | ||
} | ||
|
||
async deployImplementation(contract: string): Promise<string> { | ||
// TODO: verify storage | ||
|
||
console.log(`Deploying ${contract} implementation`); | ||
|
||
const impl = await this.hre.ethers.deployContract(contract); | ||
await impl.waitForDeployment(); | ||
|
||
const addr = await impl.getAddress(); | ||
|
||
console.log( | ||
`New implementation of ${contract} deployed at ${addr}, verifying...` | ||
); | ||
|
||
await verify(run, addr); | ||
|
||
return addr; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,85 @@ | ||
import { task } from 'hardhat/config'; | ||
import { upgradeProxy } from '../helpers/upgrade'; | ||
import { CustomRuntimeEnvironment } from '../cre'; | ||
import { populateSchedule, schedule } from '../helpers'; | ||
|
||
task('upgrade-proxy', 'Upgrades proxy contract') | ||
.addParam('proxy', 'The address of the proxy contract') | ||
.addParam('contract', 'The name of the contract') | ||
.addPositionalParam('contractName', 'The name of the contract') | ||
.addOptionalParam('timelock', 'The address of timelock contract') | ||
.addOptionalParam('timelockDelay', 'The timelock delay in seconds') | ||
.addParam('calldata', 'The calldata to execute during upgrade', '0x') | ||
.addFlag('populate', 'Show tx data to execute later') | ||
.setAction(async (taskArgs, hre) => { | ||
let { proxy, contract } = taskArgs; | ||
const { | ||
proxy, | ||
contractName, | ||
calldata, | ||
populate, | ||
timelock: timelockArg, | ||
timelockDelay: timelockDelayArg, | ||
} = taskArgs; | ||
|
||
const res = await upgradeProxy(contract, proxy, hre); | ||
const cre = new CustomRuntimeEnvironment(hre); | ||
|
||
console.log(`Implementation address is ${res.implementation}`); | ||
const proxyAdmin = await cre.getProxyAdmin(proxy); | ||
|
||
const impl = await cre.deployImplementation(contractName); | ||
|
||
if (!populate && !timelockArg) { | ||
const upgradeTx = await proxyAdmin.upgradeAndCall( | ||
proxy, | ||
impl, | ||
calldata | ||
); | ||
await upgradeTx.wait(1); | ||
|
||
console.log( | ||
`Contract ${contractName} at ${proxy} successfully upgraded in ${upgradeTx.hash}` | ||
); | ||
|
||
return; | ||
} | ||
|
||
const upgradeTx = await proxyAdmin.upgradeAndCall.populateTransaction( | ||
proxy, | ||
impl, | ||
calldata | ||
); | ||
|
||
if (populate && !timelockArg) { | ||
console.log( | ||
`Upgrade tx data:\n${JSON.stringify(upgradeTx, null, 2)}` | ||
); | ||
|
||
return; | ||
} | ||
|
||
const timelock = await cre.getTimelock(timelockArg); | ||
|
||
if (populate) { | ||
const timelockTx = await populateSchedule( | ||
hre, | ||
timelock, | ||
upgradeTx, | ||
timelockDelayArg | ||
); | ||
console.log( | ||
`Upgrade via timelock tx data:\n${JSON.stringify(timelockTx, null, 2)}` | ||
); | ||
|
||
return; | ||
} | ||
|
||
const timelockTx = await schedule( | ||
hre, | ||
timelock, | ||
upgradeTx, | ||
timelockDelayArg | ||
); | ||
|
||
await timelockTx.wait(1); | ||
|
||
console.log( | ||
`Scheduled upgrade for ${contractName} contract at ${proxy} in ${timelockTx.hash}` | ||
); | ||
}); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.