Skip to content

Commit b4b3199

Browse files
zmalatraxjaybuidl
authored andcommitted
feat(proxy): add selective upgrade scripts
1 parent 80cd463 commit b4b3199

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { BigNumber } from "ethers";
4+
import getContractAddress from "../deploy-helpers/getContractAddress";
5+
import { get } from "http";
6+
7+
enum HomeChains {
8+
ARBITRUM_ONE = 42161,
9+
ARBITRUM_GOERLI = 421613,
10+
HARDHAT = 31337,
11+
}
12+
13+
const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
14+
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
15+
const { deploy, execute } = deployments;
16+
const { AddressZero } = hre.ethers.constants;
17+
const RNG_LOOKAHEAD = 20;
18+
19+
// fallback to hardhat node signers on local network
20+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
21+
const chainId = Number(await getChainId());
22+
console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer);
23+
24+
try {
25+
const pnk = await deployments.get("PNK");
26+
27+
const dai = await deployments.get("DAI");
28+
29+
const weth = await deployments.get("WETH");
30+
31+
const rng = await deployments.get("RandomizerRNG");
32+
33+
const disputeKit = await deployments.get("DisputeKitClassic");
34+
35+
const minStake = BigNumber.from(10).pow(20).mul(2);
36+
const alpha = 10000;
37+
const feeForJuror = BigNumber.from(10).pow(17);
38+
39+
// console.log("Upgrading the SortitionModule...");
40+
// const sortitionModuleDeployment = await deployments.get("SortitionModule")
41+
const sortitionModuleDeployment = await deployments.get("SortitionModule");
42+
43+
console.log("Upgrading the KlerosCore...");
44+
const klerosCoreDeploymenent = await deploy("KlerosCore", {
45+
from: deployer,
46+
proxy: {
47+
proxyContract: "UUPSProxy",
48+
proxyArgs: ["{implementation}", "{data}"],
49+
checkProxyAdmin: false,
50+
checkABIConflict: false,
51+
execute: {
52+
init: {
53+
methodName: "initialize",
54+
args: [
55+
deployer,
56+
pnk,
57+
AddressZero,
58+
disputeKit.address,
59+
false,
60+
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
61+
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
62+
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K
63+
sortitionModuleDeployment.address,
64+
],
65+
},
66+
// Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined
67+
// To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier)
68+
onUpgrade: {
69+
methodName: "governor",
70+
args: [],
71+
},
72+
},
73+
},
74+
args: [],
75+
log: true,
76+
});
77+
} catch (err) {
78+
console.error(err);
79+
throw err;
80+
}
81+
};
82+
83+
deployUpgradeKlerosCore.tags = ["Upgrade", "KlerosCore"];
84+
deployUpgradeKlerosCore.skip = async ({ getChainId }) => {
85+
const chainId = Number(await getChainId());
86+
return !HomeChains[chainId];
87+
};
88+
89+
export default deployUpgradeKlerosCore;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { BigNumber } from "ethers";
4+
import getContractAddress from "../deploy-helpers/getContractAddress";
5+
import { get } from "http";
6+
7+
enum HomeChains {
8+
ARBITRUM_ONE = 42161,
9+
ARBITRUM_GOERLI = 421613,
10+
HARDHAT = 31337,
11+
}
12+
13+
const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
14+
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
15+
const { deploy, execute } = deployments;
16+
const { AddressZero } = hre.ethers.constants;
17+
const RNG_LOOKAHEAD = 20;
18+
19+
// fallback to hardhat node signers on local network
20+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
21+
const chainId = Number(await getChainId());
22+
console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer);
23+
24+
try {
25+
const pnk = await deployments.get("PNK");
26+
27+
const dai = await deployments.get("DAI");
28+
29+
const weth = await deployments.get("WETH");
30+
31+
const rng = await deployments.get("RandomizerRNG");
32+
33+
const klerosCore = await deployments.get("KlerosCore");
34+
const KlerosCoreAddress = klerosCore.address;
35+
36+
console.log("Upgrading the SortitionModule...");
37+
const sortitionModuleDeployment = await deploy("SortitionModule", {
38+
from: deployer,
39+
proxy: {
40+
proxyContract: "UUPSProxy",
41+
proxyArgs: ["{implementation}", "{data}"],
42+
checkProxyAdmin: false,
43+
checkABIConflict: false,
44+
execute: {
45+
init: {
46+
methodName: "initialize",
47+
args: [deployer, KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime
48+
},
49+
// Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined
50+
// To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier)
51+
onUpgrade: {
52+
methodName: "governor",
53+
args: [],
54+
},
55+
},
56+
},
57+
log: true,
58+
args: [],
59+
});
60+
} catch (err) {
61+
console.error(err);
62+
throw err;
63+
}
64+
};
65+
66+
deployUpgradeSortitionModule.tags = ["Upgrade", "SortitionModule"];
67+
deployUpgradeSortitionModule.skip = async ({ getChainId }) => {
68+
const chainId = Number(await getChainId());
69+
return !HomeChains[chainId];
70+
};
71+
72+
export default deployUpgradeSortitionModule;

0 commit comments

Comments
 (0)