Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hardhat/tasks/sips/args/sipArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,27 @@ const getArgsSip0084Part2 = async (hre) => {
return { args, governor: "GovernorOwner" };
};

const getArgsSIP0085 = async (hre) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getArgsSIP0085 has been used

Suggested change
const getArgsSIP0085 = async (hre) => {
const getArgsSIP0086 = async (hre) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not addressed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address in this commit

const {
ethers,
deployments: { get, log },
} = hre;

const newBorrowerOperationsImplementation = await get("BorrowerOperations_Implementation");
const borrowerOperationsProxy = await get("BorrowerOperations_Proxy");

const args = {
targets: [borrowerOperationsProxy.address],
values: [0],
signatures: ["setImplementation(address)"],
data: [abiCoder.encode(["address"], [newBorrowerOperationsImplementation.address])],
// @todo update sip description
description:
"SIP-0085: Zero Smart Contracts Upgrade (Apply Reentrancy Guard), Details: https://github.com/DistributedCollective/SIPS/blob/a86ac0e/SIP-0085.md, sha256: ",
};
return { args, governor: "GovernorOwner" };
};

module.exports = {
sampleGovernorAdminSIP,
sampleGovernorOwnerSIP,
Expand All @@ -1202,4 +1223,5 @@ module.exports = {
getArgsSip0079,
getArgsSip0084Part1,
getArgsSip0084Part2,
getArgsSIP0085,
};
171 changes: 171 additions & 0 deletions tests-onchain/sip0085.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// first run a local forked mainnet node in a separate terminal window:
// npx hardhat node --fork https://mainnet-dev.sovryn.app/rpc --no-deploy
// now run the test:
// npx hardhat test tests-onchain/sip0085.test.js --network rskForkedMainnet

const {
impersonateAccount,
mine,
time,
setBalance,
} = require("@nomicfoundation/hardhat-network-helpers");
const hre = require("hardhat");
const { getProtocolModules } = require("../deployment/helpers/helpers");

const {
ethers,
deployments: { createFixture, get },
} = hre;

const MAX_DURATION = ethers.BigNumber.from(24 * 60 * 60).mul(1092);

const ONE_RBTC = ethers.utils.parseEther("1.0");

const getImpersonatedSigner = async (addressToImpersonate) => {
await impersonateAccount(addressToImpersonate);
return await ethers.getSigner(addressToImpersonate);
};

describe("SIP-0085 test onchain", () => {
const getImpersonatedSignerFromJsonRpcProvider = async (addressToImpersonate) => {
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
await provider.send("hardhat_impersonateAccount", [addressToImpersonate]);
return provider.getSigner(addressToImpersonate);
};

const setupTest = createFixture(async ({ deployments }) => {
const deployer = (await ethers.getSigners())[0].address;
const deployerSigner = await ethers.getSigner(deployer);

const multisigAddress = (await get("MultiSigWallet")).address;
const multisigSigner = await getImpersonatedSignerFromJsonRpcProvider(multisigAddress);

await setBalance(deployer, ONE_RBTC.mul(10));
await deployments.fixture(["ProtocolModules"], {
keepExistingDeployments: true,
}); // start from a fresh deployments

const staking = await ethers.getContract("Staking", deployerSigner);
const sovrynProtocol = await ethers.getContract("SovrynProtocol", deployerSigner);

const god = await deployments.get("GovernorAdmin");
const governorAdmin = await ethers.getContractAt(
"GovernorAlpha",
god.address,
deployerSigner
);
const governorAdminSigner = await getImpersonatedSigner(god.address);

await setBalance(governorAdminSigner.address, ONE_RBTC);
const timelockOwner = await ethers.getContract("TimelockOwner", governorAdminSigner);

const timelockOwnerSigner = await getImpersonatedSignerFromJsonRpcProvider(
timelockOwner.address
);
await setBalance(timelockOwnerSigner._address, ONE_RBTC);

//
return {
deployer,
deployerSigner,
staking,
sovrynProtocol,
governorAdmin,
governorAdminSigner,
timelockOwner,
timelockOwnerSigner,
multisigAddress,
multisigSigner,
};
});

describe("SIP-0085 Test creation and execution", () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls replace all SIP-0085 mentions with SIP-0086 because SIP-0085 has been used already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address in this commit

it("SIP-0085 is executable and valid", async () => {
if (!hre.network.tags["forked"]) {
console.error("ERROR: Must run on a forked net");
return;
}
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: "https://mainnet-dev.sovryn.app/rpc",
blockNumber: 6926710,
},
},
],
});

const {
deployer,
deployerSigner,
staking,
governorAdmin,
timelockOwnerSigner,
multisigAddress,
multisigSigner,
} = await setupTest();

// CREATE PROPOSAL
const sov = await ethers.getContract("SOV", timelockOwnerSigner);
const whaleAmount = (await sov.totalSupply()).mul(ethers.BigNumber.from(5));
await sov.mint(deployer, whaleAmount);

await sov.connect(deployerSigner).approve(staking.address, whaleAmount);

if (await staking.paused()) await staking.connect(multisigSigner).pauseUnpause(false);
const kickoffTS = await staking.kickoffTS();
await staking.stake(
whaleAmount,
ethers.BigNumber.from(Date.now()).add(MAX_DURATION),
deployer,
deployer
);
await mine();

// CREATE PROPOSAL AND VERIFY
const proposalIdBeforeSIP = await governorAdmin.latestProposalIds(deployer);
await hre.run("sips:create", { argsFunc: "getArgsSip0085" });
const proposalId = await governorAdmin.latestProposalIds(deployer);
expect(
proposalId,
"Proposal was not created. Check the SIP creation is not commented out."
).is.gt(proposalIdBeforeSIP);

// VOTE FOR PROPOSAL

await mine();
await governorAdmin.connect(deployerSigner).castVote(proposalId, true);

// QUEUE PROPOSAL
let proposal = await governorAdmin.proposals(proposalId);
await mine(proposal.endBlock);
await governorAdmin.queue(proposalId);

const wrbtc = await ethers.getContract("WRBTC");
const priceFeeds = await ethers.getContract("PriceFeeds");
const previousWrbtcPriceFeeds = await priceFeeds.pricesFeeds(wrbtc.address);

console.log(`previous WRBTC priceFeeds: ${previousWrbtcPriceFeeds}`);

// EXECUTE PROPOSAL
proposal = await governorAdmin.proposals(proposalId);
await time.increaseTo(proposal.eta);
await expect(governorAdmin.execute(proposalId))
.to.emit(governorAdmin, "ProposalExecuted")
.withArgs(proposalId);

// VERIFY execution
expect((await governorAdmin.proposals(proposalId)).executed).to.be.true;

// Validate zero contracs upgrade
const borrowerOperationsProxy = await ethers.getContract("BorrowerOperations_Proxy");
const borrowerOperationsImpl = await get("BorrowerOperations_Implementation");

expect(await borrowerOperationsProxy.getImplementation()).to.equal(
borrowerOperationsImpl.address
);
});
});
});