-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proxy): add selective upgrade scripts
- Loading branch information
Showing
2 changed files
with
161 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { BigNumber } from "ethers"; | ||
import getContractAddress from "../deploy-helpers/getContractAddress"; | ||
import { get } from "http"; | ||
|
||
enum HomeChains { | ||
ARBITRUM_ONE = 42161, | ||
ARBITRUM_GOERLI = 421613, | ||
HARDHAT = 31337, | ||
} | ||
|
||
const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { ethers, deployments, getNamedAccounts, getChainId } = hre; | ||
const { deploy, execute } = deployments; | ||
const { AddressZero } = hre.ethers.constants; | ||
const RNG_LOOKAHEAD = 20; | ||
|
||
// fallback to hardhat node signers on local network | ||
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; | ||
const chainId = Number(await getChainId()); | ||
console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer); | ||
|
||
try { | ||
const pnk = await deployments.get("PNK"); | ||
|
||
const dai = await deployments.get("DAI"); | ||
|
||
const weth = await deployments.get("WETH"); | ||
|
||
const rng = await deployments.get("RandomizerRNG"); | ||
|
||
const disputeKit = await deployments.get("DisputeKitClassic"); | ||
|
||
const minStake = BigNumber.from(10).pow(20).mul(2); | ||
const alpha = 10000; | ||
const feeForJuror = BigNumber.from(10).pow(17); | ||
|
||
// console.log("Upgrading the SortitionModule..."); | ||
// const sortitionModuleDeployment = await deployments.get("SortitionModule") | ||
const sortitionModuleDeployment = await deployments.get("SortitionModule"); | ||
|
||
console.log("Upgrading the KlerosCore..."); | ||
const klerosCoreDeploymenent = await deploy("KlerosCore", { | ||
from: deployer, | ||
proxy: { | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, | ||
checkABIConflict: false, | ||
execute: { | ||
init: { | ||
methodName: "initialize", | ||
args: [ | ||
deployer, | ||
pnk, | ||
AddressZero, | ||
disputeKit.address, | ||
false, | ||
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump | ||
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod | ||
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K | ||
sortitionModuleDeployment.address, | ||
], | ||
}, | ||
// Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined | ||
// To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier) | ||
onUpgrade: { | ||
methodName: "governor", | ||
args: [], | ||
}, | ||
}, | ||
}, | ||
args: [], | ||
log: true, | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
}; | ||
|
||
deployUpgradeKlerosCore.tags = ["Upgrade", "KlerosCore"]; | ||
deployUpgradeKlerosCore.skip = async ({ getChainId }) => { | ||
const chainId = Number(await getChainId()); | ||
return !HomeChains[chainId]; | ||
}; | ||
|
||
export default deployUpgradeKlerosCore; |
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,72 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { BigNumber } from "ethers"; | ||
import getContractAddress from "../deploy-helpers/getContractAddress"; | ||
import { get } from "http"; | ||
|
||
enum HomeChains { | ||
ARBITRUM_ONE = 42161, | ||
ARBITRUM_GOERLI = 421613, | ||
HARDHAT = 31337, | ||
} | ||
|
||
const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { ethers, deployments, getNamedAccounts, getChainId } = hre; | ||
const { deploy, execute } = deployments; | ||
const { AddressZero } = hre.ethers.constants; | ||
const RNG_LOOKAHEAD = 20; | ||
|
||
// fallback to hardhat node signers on local network | ||
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; | ||
const chainId = Number(await getChainId()); | ||
console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer); | ||
|
||
try { | ||
const pnk = await deployments.get("PNK"); | ||
|
||
const dai = await deployments.get("DAI"); | ||
|
||
const weth = await deployments.get("WETH"); | ||
|
||
const rng = await deployments.get("RandomizerRNG"); | ||
|
||
const klerosCore = await deployments.get("KlerosCore"); | ||
const KlerosCoreAddress = klerosCore.address; | ||
|
||
console.log("Upgrading the SortitionModule..."); | ||
const sortitionModuleDeployment = await deploy("SortitionModule", { | ||
from: deployer, | ||
proxy: { | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, | ||
checkABIConflict: false, | ||
execute: { | ||
init: { | ||
methodName: "initialize", | ||
args: [deployer, KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime | ||
}, | ||
// Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined | ||
// To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier) | ||
onUpgrade: { | ||
methodName: "governor", | ||
args: [], | ||
}, | ||
}, | ||
}, | ||
log: true, | ||
args: [], | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
}; | ||
|
||
deployUpgradeSortitionModule.tags = ["Upgrade", "SortitionModule"]; | ||
deployUpgradeSortitionModule.skip = async ({ getChainId }) => { | ||
const chainId = Number(await getChainId()); | ||
return !HomeChains[chainId]; | ||
}; | ||
|
||
export default deployUpgradeSortitionModule; |