Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions contracts/locker/staking/OmnichainStakingToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract OmnichainStakingToken is OmnichainStakingBase {
function init(
address _locker,
address _zeroToken,
address _poolVoter,
address _votingPowerCombined,
uint256 _rewardsDuration,
address _owner,
address _distributor
Expand All @@ -30,7 +30,7 @@ contract OmnichainStakingToken is OmnichainStakingBase {
"ZEROvp",
_locker,
_zeroToken,
_poolVoter,
_votingPowerCombined,
_rewardsDuration,
_distributor
);
Expand Down
4 changes: 3 additions & 1 deletion contracts/voter/PoolVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
14 changes: 11 additions & 3 deletions test/OmnichainStaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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);});
});
19 changes: 17 additions & 2 deletions test/fixtures/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PoolVoter,
StakingBonus,
VestedZeroNFT,
VotingPowerCombined,
} from "../../types";
import { LockerLP } from "../../typechain-types";

Expand All @@ -24,6 +25,8 @@ export async function deployGovernance() {
const staking = await initProxy<OmnichainStakingToken>(
"OmnichainStakingToken"
);
const votingPowerCombined: VotingPowerCombined = await initProxy<VotingPowerCombined>("VotingPowerCombined");

const lockerLP = await initProxy<LockerLP>("LockerLP");
const lockerToken = await initProxy<LockerToken>("LockerToken");
const poolVoter = await initProxy<PoolVoter>("PoolVoter");
Expand All @@ -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);

Expand Down
54 changes: 54 additions & 0 deletions test/fork/VotingPowerCombined/linea.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
}