From 8b9da63e84c108e1842bf1837150250d78a2f5b3 Mon Sep 17 00:00:00 2001 From: oxoxDev Date: Tue, 27 Aug 2024 12:51:26 +0530 Subject: [PATCH 1/2] Merge poolVoter from origin/main to main --- contracts/voter/PoolVoter.sol | 4 +- test/fork/VotingPowerCombined/linea.test.ts | 54 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/fork/VotingPowerCombined/linea.test.ts diff --git a/contracts/voter/PoolVoter.sol b/contracts/voter/PoolVoter.sol index b82f833..2ce06e9 100644 --- a/contracts/voter/PoolVoter.sol +++ b/contracts/voter/PoolVoter.sol @@ -41,12 +41,14 @@ contract PoolVoter is * @dev This function is called only once during deployment. * @param _staking The address of the staking token (VE token). * @param _reward The address of the reward token. + * @param _votingPowerCombined The address of the VotingPowerCombined contract. */ - function init(address _staking, address _reward) external reinitializer(1) { + function init(address _staking, address _reward, address _votingPowerCombined) external reinitializer(1) { staking = IVotes(_staking); reward = IERC20(_reward); __ReentrancyGuard_init(); __Ownable_init(msg.sender); + votingPowerCombined = _votingPowerCombined; } /** diff --git a/test/fork/VotingPowerCombined/linea.test.ts b/test/fork/VotingPowerCombined/linea.test.ts new file mode 100644 index 0000000..5d29b0c --- /dev/null +++ b/test/fork/VotingPowerCombined/linea.test.ts @@ -0,0 +1,54 @@ +import { expect, should } from "chai"; +import { e18, initMainnetUser } from "../../fixtures/utils"; +import { VestedZeroNFT, VotingPowerCombined } from "../../../typechain-types"; +import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; +import { time } from "@nomicfoundation/hardhat-network-helpers"; +import { setForkBlock } from "../utils"; +import { getNetworkDetails } from "../constants"; +import { + Contract, + ContractTransactionResponse, + parseEther, + parseUnits, +} from "ethers"; +import { ethers } from "hardhat"; +import { getGovernanceContracts } from "../helper"; + +const FORK = process.env.FORK === "true"; +const FORKED_NETWORK = process.env.FORKED_NETWORK ?? ""; +const BLOCK_NUMBER = 5969983; + +const STAKING_ADDRESS = "0xf374229a18ff691406f99CCBD93e8a3f16B68888"; +const REWARD_ADDRESS = "0x78354f8DcCB269a615A7e0a24f9B0718FDC3C7A7"; +const OWNER = "0x0F6e98A756A40dD050dC78959f45559F98d3289d"; + +if (FORK) { + let votingPowerCombined: VotingPowerCombined; + let deployerForked: SignerWithAddress; + describe.only("VotingPowerCombined ForkTests", async () => { + beforeEach(async () => { + votingPowerCombined = await ethers.getContractAt( + "VotingPowerCombined", + "0x2666951A62d82860E8e1385581E2FB7669097647" + ); + [deployerForked] = await ethers.getSigners(); + await setForkBlock(BLOCK_NUMBER); + + // + + const poolVoterFactory = await ethers.getContractFactory("PoolVoter"); + const poolVoter = await poolVoterFactory.deploy(); + await poolVoter.init(STAKING_ADDRESS, REWARD_ADDRESS, votingPowerCombined.target); + + const owner = await initMainnetUser(OWNER); + await votingPowerCombined.connect(owner).setAddresses(STAKING_ADDRESS, REWARD_ADDRESS, poolVoter.target); + }); + + it("Should reset voting power", async () => { + const resetterWallet = await initMainnetUser("0x7Ff4e6A2b7B43cEAB1fC07B0CBa00f834846ADEd", parseEther('100')); + + const resetTransaction = votingPowerCombined.connect(resetterWallet).reset(resetterWallet.address); + await expect(resetTransaction).to.not.be.revertedWith('Invalid reset performed'); + }); + }); +} From cdcaa0e32907d07725a5c9480857ebe070b674b4 Mon Sep 17 00:00:00 2001 From: oxoxDev Date: Tue, 27 Aug 2024 13:05:33 +0530 Subject: [PATCH 2/2] fix failing actions on existing locks * add voting power combined to OmnichainStakingToken intialization * fix deployGovernance fixture * fix OmnichainStakingToken tests --- .../locker/staking/OmnichainStakingToken.sol | 4 ++-- test/OmnichainStaking.test.ts | 14 +++++++++++--- test/fixtures/governance.ts | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/contracts/locker/staking/OmnichainStakingToken.sol b/contracts/locker/staking/OmnichainStakingToken.sol index b6cbe64..cea0fff 100644 --- a/contracts/locker/staking/OmnichainStakingToken.sol +++ b/contracts/locker/staking/OmnichainStakingToken.sol @@ -20,7 +20,7 @@ contract OmnichainStakingToken is OmnichainStakingBase { function init( address _locker, address _zeroToken, - address _poolVoter, + address _votingPowerCombined, uint256 _rewardsDuration, address _owner, address _distributor @@ -30,7 +30,7 @@ contract OmnichainStakingToken is OmnichainStakingBase { "ZEROvp", _locker, _zeroToken, - _poolVoter, + _votingPowerCombined, _rewardsDuration, _distributor ); diff --git a/test/OmnichainStaking.test.ts b/test/OmnichainStaking.test.ts index 0a34e84..79c7c6b 100644 --- a/test/OmnichainStaking.test.ts +++ b/test/OmnichainStaking.test.ts @@ -14,6 +14,7 @@ import { AbiCoder, parseEther } from "ethers"; describe("Omnichain Staking Unit tests", () => { let ant: SignerWithAddress; + let deployer: SignerWithAddress; let vest: VestedZeroNFT; let now: number; let stakingBonus: StakingBonus; @@ -23,6 +24,7 @@ describe("Omnichain Staking Unit tests", () => { beforeEach(async () => { const deployment = await loadFixture(deployGovernance); + deployer = deployment.deployer; ant = deployment.ant; zero = deployment.zero; vest = deployment.vestedZeroNFT; @@ -38,7 +40,8 @@ describe("Omnichain Staking Unit tests", () => { // send 100 ZERO await zero.transfer(omniStaking.target, parseEther("100")); - await omniStaking.notifyRewardAmount(parseEther("1")); + await zero.connect(deployer).approve(omniStaking.target, parseEther("1")) + await omniStaking.connect(deployer).notifyRewardAmount(parseEther("1")); // deployer should be able to mint a nft for another user await vest.mint( @@ -78,7 +81,7 @@ describe("Omnichain Staking Unit tests", () => { ((oldLockDetails.end - oldLockDetails.start) * 100n) / (86400n * 365n) ).to.closeTo(100, 5); - await omniStaking.connect(ant).increaseLockDuration(0, 1, 86400 * 365 * 3); + await omniStaking.connect(ant).increaseLockDuration(1, 86400 * 365 * 3); const newLockDetails = await lockerToken.locked(1); expect( ((newLockDetails.end - newLockDetails.start) * 100n) / (86400n * 365n) @@ -90,8 +93,13 @@ describe("Omnichain Staking Unit tests", () => { const oldLockDetails = await lockerToken.locked(1); expect(oldLockDetails.amount).to.eq(e18 * 20n); await zero.connect(ant).approve(omniStaking.target, 25n * e18); - await omniStaking.connect(ant).increaseLockAmount(0, 1, e18 * 25n); + await omniStaking.connect(ant).increaseLockAmount(1, e18 * 25n); const newLockDetails = await lockerToken.locked(1); expect(newLockDetails.amount).to.eq(45n * e18); }); + + it("should be able to unstake and withdraw for an existing lock", async () => { + await zero.transfer(ant.address, e18 * 100n); + const lockDetails = await lockerToken.locked(1); + expect(lockDetails.amount).to.eq(e18 * 20n);}); }); diff --git a/test/fixtures/governance.ts b/test/fixtures/governance.ts index 8ca0d56..289855c 100644 --- a/test/fixtures/governance.ts +++ b/test/fixtures/governance.ts @@ -8,6 +8,7 @@ import { PoolVoter, StakingBonus, VestedZeroNFT, + VotingPowerCombined, } from "../../types"; import { LockerLP } from "../../typechain-types"; @@ -24,6 +25,8 @@ export async function deployGovernance() { const staking = await initProxy( "OmnichainStakingToken" ); + const votingPowerCombined: VotingPowerCombined = await initProxy("VotingPowerCombined"); + const lockerLP = await initProxy("LockerLP"); const lockerToken = await initProxy("LockerToken"); const poolVoter = await initProxy("PoolVoter"); @@ -40,16 +43,28 @@ export async function deployGovernance() { await lockerToken.init(zero.target, staking.target); await lockerLP.init(zero.target, staking.target); // TODO: add a simple LP token - await poolVoter.init(staking.target, zero.target); + await poolVoter.init(staking.target, zero.target, votingPowerCombined.target); await staking.init( lockerToken.target, zero.target, - poolVoter.target, + votingPowerCombined.target, 86400 * 14, // 14 days deployer.address, deployer.address ); + await votingPowerCombined.init( + deployer.address, + staking.target, + staking.target, + poolVoter.target + ); + + await votingPowerCombined.connect(deployer).setAddresses( + staking.target, + staking.target, + poolVoter.target, + ); // unpause zero await zero.togglePause(false);