Skip to content

Commit 2c12617

Browse files
Merge pull request #576 from xai-foundation/feat/sc-6398
Add tests for transfer staked keys
2 parents 7f086fc + 1178f94 commit 2c12617

File tree

11 files changed

+5954
-33
lines changed

11 files changed

+5954
-33
lines changed

infrastructure/smart-contracts/.openzeppelin/unknown-421614.json

+1,641
Large diffs are not rendered by default.

infrastructure/smart-contracts/contracts/upgrades/StakingPool/StakingPool3.sol

+604
Large diffs are not rendered by default.

infrastructure/smart-contracts/contracts/upgrades/node-license/NodeLicense10.sol

+920
Large diffs are not rendered by default.

infrastructure/smart-contracts/contracts/upgrades/pool-factory/PoolFactory3.sol

+1,010
Large diffs are not rendered by default.

infrastructure/smart-contracts/contracts/upgrades/referee/Referee11.sol

+1,144
Large diffs are not rendered by default.

infrastructure/smart-contracts/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
"deploy-sepolia": "hardhat run scripts/sepolia-deploy/deployAndPopulateSepolia.mjs",
4141
"deploy-tiny-keys": "hardhat run scripts/tiny-keys/deployTinyKeys.mjs",
4242
"start-tiny-keys-drop": "hardhat run scripts/tiny-keys/startAirdrop.mjs",
43-
"process-tiny-keys-drop": "hardhat run scripts/tiny-keys/processAirdrop.mjs"
43+
"process-tiny-keys-drop": "hardhat run scripts/tiny-keys/processAirdrop.mjs",
44+
"upgrade-transfer-staked-keys": "hardhat run scripts/transfer-staked-keys/upgrade-contracts.mjs",
45+
"check-flagged-accounts": "hardhat run scripts/flagged/flaggedNodeLicenses.mjs"
4446
},
4547
"dependencies": {
4648
"@sentry/core": "workspace:*",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { config } from "@sentry/core";
2+
import { safeVerify } from "../../utils/safeVerify.mjs";
3+
4+
import { PoolBeaconAbi } from "@sentry/core";
5+
6+
// Find this in the deployed PoolProxyDeployer's public fields. This should reflect which set of proxies you want to change; staking pools, key buckets, or esXai buckets
7+
// https://arbiscan.io/address/0x68D78D1E81379EfD9C61f8E9131D52CE571AF4fD#readProxyContract
8+
const beaconAddress = "0x5f9D168d3435747335b1B3dC7e4d42e3510087C7";
9+
const currentContractImplementationName = "StakingPool2";
10+
const newContractImplementationName = "StakingPool3";
11+
12+
const REFEREE_ADDRESS = config.refereeAddress;
13+
const POOL_FACTORY_ADDRESS = config.poolFactoryAddress;
14+
const NODE_LICENSE_ADDRESS = config.nodeLicenseAddress;
15+
16+
async function main() {
17+
18+
// get the deployer
19+
const [deployer] = (await ethers.getSigners());
20+
21+
console.log("Upgrading Referee...");
22+
const Referee11 = await ethers.getContractFactory("Referee11", deployer);
23+
console.log("Got Referee factory");
24+
const referee11 = await upgrades.upgradeProxy(REFEREE_ADDRESS, Referee11);
25+
console.log("Referee upgraded to version 11");
26+
27+
console.log("Upgrading PoolFactory...");
28+
const PoolFactory3 = await ethers.getContractFactory("PoolFactory3");
29+
console.log("Got PoolFactory factory");
30+
const poolFactory3 = await upgrades.upgradeProxy(POOL_FACTORY_ADDRESS, PoolFactory3);
31+
console.log("PoolFactory upgraded to version 3");
32+
33+
console.log("Upgrading NodeLicense...");
34+
const NodeLicense10 = await ethers.getContractFactory("NodeLicense10");
35+
console.log("Got NodeLicense factory");
36+
const nodeLicense10 = await upgrades.upgradeProxy(NODE_LICENSE_ADDRESS, NodeLicense10);
37+
console.log("NodeLicense upgraded to version 10");
38+
39+
// UPGRADE PoolBeacon
40+
// Create instance of the beacon
41+
const beacon = new ethers.Contract(beaconAddress, PoolBeaconAbi, deployer);
42+
console.log("Found beacon:", await beacon.getAddress());
43+
44+
// Validate the new implementation is upgrade safe
45+
console.log("Validating upgrade viability...");
46+
const CurrentImplementationFactory = await ethers.getContractFactory(currentContractImplementationName);
47+
const NewImplementationFactory = await ethers.getContractFactory(newContractImplementationName);
48+
await upgrades.validateUpgrade(CurrentImplementationFactory, NewImplementationFactory, { kind: "beacon" });
49+
console.log("New implementation validated as upgrade safe");
50+
51+
// Deploy the new implementation
52+
console.log("Deploying the new implementation");
53+
const NewImplementation = await ethers.deployContract(newContractImplementationName);
54+
await NewImplementation.waitForDeployment();
55+
const newImplementationAddress = await NewImplementation.getAddress();
56+
57+
// Update the beacon with the new implementation address
58+
console.log("Updating the beacon with the new implementation address");
59+
await beacon.update(newImplementationAddress);
60+
61+
console.log("Verifying the new PoolBeacon implementation");
62+
63+
console.log("Starting verification... ");
64+
await safeVerify({ skipWaitForDeployTx: true, contractAddress: newImplementationAddress });
65+
await safeVerify({ skipWaitForDeployTx: true, contract: referee11 });
66+
await safeVerify({ skipWaitForDeployTx: true, contract: nodeLicense10 });
67+
await safeVerify({ skipWaitForDeployTx: true, contract: poolFactory3 });
68+
console.log("Verification complete ");
69+
}
70+
71+
// We recommend this pattern to be able to use async/await everywhere
72+
// and properly handle errors.
73+
main().catch((error) => {
74+
console.error(error);
75+
process.exitCode = 1;
76+
});

infrastructure/smart-contracts/test/Fixture.mjs

+23-5
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,14 @@ describe("Fixture Tests", function () {
369369
const esXai3 = await upgrades.upgradeProxy((await esXai.getAddress()), EsXai3, { call: { fn: "initialize", args: [await referee.getAddress(), await nodeLicense.getAddress(), poolFactoryAddress, maxKeysNonKyc] } });
370370
await esXai3.waitForDeployment();
371371

372-
372+
373373
// Referee9
374374
// This upgrade needs to happen after all the setters are called, Referee 9 will remove the setters that are not needed in prod anymore to save contract size
375375
const Referee9 = await ethers.getContractFactory("Referee9");
376376
// Upgrade the Referee
377377
const referee9 = await upgrades.upgradeProxy((await referee.getAddress()), Referee9, { call: { fn: "initialize", args: [await refereeCalculations.getAddress()] } });
378378
await referee9.waitForDeployment();
379-
379+
380380
// // Referee10 upgrade - Required For Tiny Keys
381381
// // This upgrade needs to happen after all the setters are called, Referee 9 will remove the setters that are not needed in prod anymore to save contract size
382382
const Referee10 = await ethers.getContractFactory("Referee10");
@@ -411,6 +411,24 @@ describe("Fixture Tests", function () {
411411
);
412412
await nodeLicense9.waitForDeployment();
413413

414+
// Upgrade for allow transfer staked keys
415+
const NodeLicense10 = await ethers.getContractFactory("NodeLicense10");
416+
const nodeLicense10 = await upgrades.upgradeProxy((await nodeLicense.getAddress()), NodeLicense10);
417+
await nodeLicense10.waitForDeployment();
418+
419+
const PoolFactory3 = await ethers.getContractFactory("PoolFactory3");
420+
const poolFactory3 = await upgrades.upgradeProxy((await poolFactory2.getAddress()), PoolFactory3);
421+
await poolFactory3.waitForDeployment();
422+
423+
const Referee11 = await ethers.getContractFactory("Referee11");
424+
const referee11 = await upgrades.upgradeProxy((await referee.getAddress()), Referee11);
425+
await referee11.waitForDeployment();
426+
427+
const StakingPool3 = await ethers.deployContract("StakingPool3");
428+
await StakingPool3.waitForDeployment();
429+
const stakingPool3ImplAddress = await StakingPool3.getAddress();
430+
await StakingPoolPoolBeacon.update(stakingPool3ImplAddress);
431+
414432
config.esXaiAddress = await esXai.getAddress();
415433
config.esXaiDeployedBlockNumber = (await esXai.deploymentTransaction()).blockNumber;
416434
config.gasSubsidyAddress = await gasSubsidy.getAddress();
@@ -445,9 +463,9 @@ describe("Fixture Tests", function () {
445463
tiers,
446464
secretKeyHex,
447465
publicKeyHex: "0x" + publicKeyHex,
448-
referee: referee10,
449-
nodeLicense: nodeLicense9,
450-
poolFactory: poolFactory2,
466+
referee: referee11,
467+
nodeLicense: nodeLicense10,
468+
poolFactory: poolFactory3,
451469
gasSubsidy,
452470
esXai: esXai3,
453471
xai,

infrastructure/smart-contracts/test/FixtureAuditTest.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ describe("Stake V1 & Transfer keys on Bulksubmissions", function () {
398398
);
399399
await nodeLicense9.waitForDeployment();
400400

401+
// Upgrade for allow transfer staked keys
402+
const NodeLicense10 = await ethers.getContractFactory("NodeLicense10");
403+
const nodeLicense10 = await upgrades.upgradeProxy((await nodeLicense.getAddress()), NodeLicense10);
404+
await nodeLicense10.waitForDeployment();
405+
401406
// Upgrade the StakingPool
402407
const NewImplementation = await ethers.deployContract("StakingPool2");
403408
await NewImplementation.waitForDeployment();
@@ -440,7 +445,7 @@ describe("Stake V1 & Transfer keys on Bulksubmissions", function () {
440445
secretKeyHex,
441446
publicKeyHex: "0x" + publicKeyHex,
442447
referee: referee10,
443-
nodeLicense: nodeLicense9,
448+
nodeLicense: nodeLicense10,
444449
poolFactory: poolFactory2,
445450
gasSubsidy,
446451
esXai: esXai3,

0 commit comments

Comments
 (0)