Skip to content

Commit 3be377a

Browse files
committed
Scripts to validate and prepare upgrades for TokenStaking
1 parent 2be870b commit 3be377a

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types"
2+
import { DeployFunction } from "hardhat-deploy/types"
3+
4+
import { ethers, upgrades } from "hardhat"
5+
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7+
const { deployments } = hre
8+
const { log } = deployments
9+
10+
const T = await deployments.get("T")
11+
const KeepTokenStaking = await deployments.get("KeepTokenStaking")
12+
const NuCypherStakingEscrow = await deployments.get("NuCypherStakingEscrow")
13+
const VendingMachineKeep = await deployments.get("VendingMachineKeep")
14+
const VendingMachineNuCypher = await deployments.get("VendingMachineNuCypher")
15+
const KeepStake = await deployments.get("KeepStake")
16+
const TokenStakingDeployment = await deployments.get("TokenStaking")
17+
18+
const tokenStakingConstructorArgs = [
19+
T.address,
20+
KeepTokenStaking.address,
21+
NuCypherStakingEscrow.address,
22+
VendingMachineKeep.address,
23+
VendingMachineNuCypher.address,
24+
KeepStake.address,
25+
]
26+
27+
if (hre.network.name == "mainnet") {
28+
const TokenStaking = await ethers.getContractFactory("TokenStaking")
29+
30+
// @ts-ignore:
31+
await upgrades.validateUpgrade(
32+
TokenStakingDeployment.address,
33+
TokenStaking,
34+
{
35+
constructorArgs: tokenStakingConstructorArgs,
36+
}
37+
)
38+
39+
log(`Current TokenStaking implementation is compatible with existing deployment at ${TokenStakingDeployment.address}`)
40+
}
41+
}
42+
43+
export default func
44+
45+
func.tags = ["ValidateUpgradeTokenStaking"]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types"
2+
import { DeployFunction } from "hardhat-deploy/types"
3+
4+
import { ethers, upgrades } from "hardhat"
5+
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7+
const { deployments } = hre
8+
const { log } = deployments
9+
10+
const T = await deployments.get("T")
11+
const KeepTokenStaking = await deployments.get("KeepTokenStaking")
12+
const NuCypherStakingEscrow = await deployments.get("NuCypherStakingEscrow")
13+
const VendingMachineKeep = await deployments.get("VendingMachineKeep")
14+
const VendingMachineNuCypher = await deployments.get("VendingMachineNuCypher")
15+
const KeepStake = await deployments.get("KeepStake")
16+
const TokenStakingProxy = await deployments.get("TokenStaking")
17+
18+
const tokenStakingConstructorArgs = [
19+
T.address,
20+
KeepTokenStaking.address,
21+
NuCypherStakingEscrow.address,
22+
VendingMachineKeep.address,
23+
VendingMachineNuCypher.address,
24+
KeepStake.address,
25+
]
26+
27+
if (hre.network.name == "mainnet") {
28+
const TokenStaking = await ethers.getContractFactory("TokenStaking")
29+
const proxyAddress = TokenStakingProxy.address
30+
31+
const implAddress = await upgrades.prepareUpgrade(
32+
proxyAddress,
33+
TokenStaking,
34+
{
35+
constructorArgs: tokenStakingConstructorArgs,
36+
kind: 'transparent',
37+
}
38+
)
39+
40+
log(`Deployed new TokenStaking implementation contract at ${implAddress}`)
41+
log(`Constructor arguments: ${tokenStakingConstructorArgs}`)
42+
43+
const implementationInterface = TokenStaking.interface
44+
let jsonAbi = implementationInterface.format(ethers.utils.FormatTypes.json)
45+
46+
const tokenStakingDeployment = {
47+
address: implAddress,
48+
abi: JSON.parse(jsonAbi as string),
49+
}
50+
const fs = require("fs")
51+
fs.writeFileSync(
52+
`TokenStaking_implementation_${implAddress}.json`,
53+
JSON.stringify(tokenStakingDeployment, null, 2),
54+
"utf8",
55+
function (err) {
56+
if (err) {
57+
console.log(err)
58+
}
59+
}
60+
)
61+
62+
}
63+
}
64+
65+
export default func
66+
67+
func.tags = ["PrepareUpgradeTokenStaking"]

0 commit comments

Comments
 (0)