update test script for stake

This commit is contained in:
CounterFire2023 2024-09-13 16:35:31 +08:00
parent 619c3264c0
commit a3b985b927
12 changed files with 186 additions and 178 deletions

View File

@ -29,9 +29,11 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
mapping(address account => uint256 amount) public override cumulativeClaimAmounts; mapping(address account => uint256 amount) public override cumulativeClaimAmounts;
mapping(address account => uint256 amount) public override claimedAmounts; mapping(address account => uint256 amount) public override claimedAmounts;
mapping(address account => uint256 time) public lastVestingTimes; mapping(address account => uint256 time) public lastVestingTimes;
mapping(address account => uint256 time) public lastDepositTimes;
mapping(address account => uint256 amount) public override cumulativeRewardDeductions; mapping(address account => uint256 amount) public override cumulativeRewardDeductions;
mapping(address account => uint256 amount) public override bonusRewards; mapping(address account => uint256 amount) public override bonusRewards;
mapping(address account => uint256 amount) public vestingTotal;
mapping(address handler => bool status) public isHandler; mapping(address handler => bool status) public isHandler;
@ -103,6 +105,7 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
delete cumulativeClaimAmounts[account]; delete cumulativeClaimAmounts[account];
delete claimedAmounts[account]; delete claimedAmounts[account];
delete lastVestingTimes[account]; delete lastVestingTimes[account];
delete vestingTotal[account];
emit Withdraw(account, claimedAmount, balance); emit Withdraw(account, claimedAmount, balance);
} }
@ -135,7 +138,7 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
if (hasRewardTrackerCEC()) { if (hasRewardTrackerCEC()) {
uint256 cumulativeRewardCEC = IRewardTracker(rewardTrackerCEC).cumulativeRewards(_account); uint256 cumulativeRewardCEC = IRewardTracker(rewardTrackerCEC).cumulativeRewards(_account);
maxVestableAmount = maxVestableAmount + cumulativeRewardCEC ; maxVestableAmount = maxVestableAmount + cumulativeRewardCEC;
} }
if (hasRewardTrackerEsCEC()) { if (hasRewardTrackerEsCEC()) {
@ -193,9 +196,10 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
} }
function getVestedAmount(address _account) public view override returns (uint256) { function getVestedAmount(address _account) public view override returns (uint256) {
uint256 balance = balances[_account]; // uint256 balance = balances[_account];
uint256 cumulativeClaimAmount = cumulativeClaimAmounts[_account]; // uint256 cumulativeClaimAmount = cumulativeClaimAmounts[_account];
return balance + cumulativeClaimAmount; // return balance + cumulativeClaimAmount;
return vestingTotal[_account];
} }
function _mint(address _account, uint256 _amount) private { function _mint(address _account, uint256 _amount) private {
@ -222,10 +226,10 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
function _deposit(address _account, uint256 _amount) private { function _deposit(address _account, uint256 _amount) private {
require(_amount > 0, "Vester: invalid _amount"); require(_amount > 0, "Vester: invalid _amount");
_updateVesting(_account); _updateVesting(_account);
IERC20(esToken).safeTransferFrom(_account, address(this), _amount); IERC20(esToken).safeTransferFrom(_account, address(this), _amount);
_mint(_account, _amount); _mint(_account, _amount);
vestingTotal[_account] = balanceOf(_account);
if (needCheckStake && hasRewardTrackerCEC()) { if (needCheckStake && hasRewardTrackerCEC()) {
// if u want to transfer 100 esCec to cec, u need to have 100 cec in stake // if u want to transfer 100 esCec to cec, u need to have 100 cec in stake
@ -234,6 +238,7 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
} }
uint256 maxAmount = getMaxVestableAmount(_account); uint256 maxAmount = getMaxVestableAmount(_account);
require(getTotalVested(_account) <= maxAmount, "Vester: max vestable amount exceeded"); require(getTotalVested(_account) <= maxAmount, "Vester: max vestable amount exceeded");
lastDepositTimes[_account] = block.timestamp;
emit Deposit(_account, _amount); emit Deposit(_account, _amount);
} }
@ -277,6 +282,16 @@ contract Vester is IVester, IERC20, ReentrancyGuard, Governable {
return amount + nextClaimable; return amount + nextClaimable;
} }
function remainingEsToken(address _account) public view returns (uint256) {
uint256 balance = balances[_account];
uint256 claimedAmount = claimedAmounts[_account];
uint256 claimableAmount = claimable(_account);
if (balance > claimableAmount + claimedAmount) {
return balance - claimableAmount - claimedAmount;
}
return 0;
}
function _claim(address _account, address _receiver) private returns (uint256) { function _claim(address _account, address _receiver) private returns (uint256) {
_updateVesting(_account); _updateVesting(_account);
uint256 amount = claimable(_account); uint256 amount = claimable(_account);

View File

@ -3,6 +3,7 @@ import {DeployFunction} from "hardhat-deploy/types";
import {deplayOne, loadData} from "../scripts/utils"; import {deplayOne, loadData} from "../scripts/utils";
import {ZeroAddress} from "ethers"; import {ZeroAddress} from "ethers";
import { assert } from "chai"; import { assert } from "chai";
import { expandDecimals } from "../test/shared/utilities";
const deployNFTClaim: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const deployNFTClaim: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
@ -61,6 +62,12 @@ const deployNFTClaim: DeployFunction = async function (hre: HardhatRuntimeEnviro
tx = await esCECContract.setHandler(vester.address, true); tx = await esCECContract.setHandler(vester.address, true);
await tx.wait(); await tx.wait();
console.log("==esCECContract setHandler"); console.log("==esCECContract setHandler");
// mint esCEC to stakedCecTracker
tx = await esCECContract.mint(stakedCecTracker.address, expandDecimals(5000000000, 18));
await tx.wait();
console.log("==esCECContract mint");
}; };
deployNFTClaim.tags = ["StakingCEC"]; deployNFTClaim.tags = ["StakingCEC"];

View File

@ -3,6 +3,7 @@ import {DeployFunction} from "hardhat-deploy/types";
import {deplayOne, loadData} from "../scripts/utils"; import {deplayOne, loadData} from "../scripts/utils";
import {ZeroAddress} from "ethers"; import {ZeroAddress} from "ethers";
import { assert } from "chai"; import { assert } from "chai";
import { expandDecimals } from "../test/shared/utilities";
@ -50,6 +51,9 @@ const deployNFTClaim: DeployFunction = async function (hre: HardhatRuntimeEnviro
tx = await vesterContract.setRewardTrackerEsCEC(stakedCecTracker.address); tx = await vesterContract.setRewardTrackerEsCEC(stakedCecTracker.address);
await tx.wait(); await tx.wait();
console.log("==vesterContract setRewardTrackerEsCEC"); console.log("==vesterContract setRewardTrackerEsCEC");
tx = await esCECContract.mint(stakedCecTracker.address, expandDecimals(5000000000, 18));
await tx.wait();
console.log("==esCECContract mint");
}; };
deployNFTClaim.tags = ["StakingEsCEC"]; deployNFTClaim.tags = ["StakingEsCEC"];

View File

@ -1,5 +1,5 @@
{ {
"address": "0x495Ba7734C9727117275807817bbd4C176a118c3", "address": "0x3455e5D4962de708050278FA2761A613028bdf08",
"abi": [ "abi": [
{ {
"inputs": [ "inputs": [
@ -212,25 +212,25 @@
"type": "function" "type": "function"
} }
], ],
"transactionHash": "0x1042e2e96f6a63168e7c69628d07ebe5d647be614486a5ac137032133cc9750c", "transactionHash": "0xa2592f659da58bd269d5dbe140d619e339ff053a89877b7381f9632d516e26d1",
"receipt": { "receipt": {
"to": null, "to": null,
"from": "0x50A8e60041A206AcaA5F844a1104896224be6F39", "from": "0x50A8e60041A206AcaA5F844a1104896224be6F39",
"contractAddress": "0x495Ba7734C9727117275807817bbd4C176a118c3", "contractAddress": "0x3455e5D4962de708050278FA2761A613028bdf08",
"transactionIndex": 0, "transactionIndex": 0,
"gasUsed": "806753", "gasUsed": "806753",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"blockHash": "0x501b550a9ac7597b9396eae9306b8fcbcbf0411676028bdecb678765520d3bb8", "blockHash": "0x5c7e0af896928ea534d6e9863f61939744912a2d69ca7849aa2e96a915cc772b",
"transactionHash": "0x1042e2e96f6a63168e7c69628d07ebe5d647be614486a5ac137032133cc9750c", "transactionHash": "0xa2592f659da58bd269d5dbe140d619e339ff053a89877b7381f9632d516e26d1",
"logs": [], "logs": [],
"blockNumber": 43798859, "blockNumber": 43808466,
"cumulativeGasUsed": "806753", "cumulativeGasUsed": "806753",
"status": 1, "status": 1,
"byzantium": true "byzantium": true
}, },
"args": [ "args": [
"0x1FbA3F84e62163069050f1156b73C008722136A3", "0x1FbA3F84e62163069050f1156b73C008722136A3",
"0x47eFeaCdF6bE0CD4c1f654633D1DaaEDaD82DAB5", "0x1ebeE9a0B5E8deF2c75aBbc6209d7f2b4d5c7bd0",
"0x0000000000000000000000000000000000000000" "0x0000000000000000000000000000000000000000"
], ],
"numDeployments": 1, "numDeployments": 1,

File diff suppressed because one or more lines are too long

View File

@ -45,30 +45,30 @@
"name": "stakedCecTracker", "name": "stakedCecTracker",
"type": "logic", "type": "logic",
"json": "assets/contracts/RewardTracker.json", "json": "assets/contracts/RewardTracker.json",
"address": "0x4d0d113e7E271B07a031B638562fd7778e7fF0F9" "address": "0xF45547C1bF15dbB69b16Bf548C9fC5AF4696DD84"
}, },
{ {
"name": "vester", "name": "vester",
"type": "logic", "type": "logic",
"json": "assets/contracts/Vester.json", "json": "assets/contracts/Vester.json",
"address": "0x012ad686a48A887A6b6a70E2618828c3ef372eb2" "address": "0x30C91ED20FdfFD7C423014BaFcd5D6a4132d4Fdb"
}, },
{ {
"name": "stakedCecRouter", "name": "stakedCecRouter",
"type": "logic", "type": "logic",
"json": "assets/contracts/RewardRouter.json", "json": "assets/contracts/RewardRouter.json",
"address": "0xeD11fA906275e5e0B15B1a1c575F60Af551687FC" "address": "0x568D74A7D3E7647e507b5FbD5AB96Af6F0c36D83"
}, },
{ {
"name": "stakedEsCecTracker", "name": "stakedEsCecTracker",
"type": "logic", "type": "logic",
"json": "assets/contracts/RewardTracker.json", "json": "assets/contracts/RewardTracker.json",
"address": "0x47eFeaCdF6bE0CD4c1f654633D1DaaEDaD82DAB5" "address": "0x1ebeE9a0B5E8deF2c75aBbc6209d7f2b4d5c7bd0"
}, },
{ {
"name": "stakedEsCecRouter", "name": "stakedEsCecRouter",
"type": "logic", "type": "logic",
"json": "assets/contracts/RewardRouter.json", "json": "assets/contracts/RewardRouter.json",
"address": "0x495Ba7734C9727117275807817bbd4C176a118c3" "address": "0x3455e5D4962de708050278FA2761A613028bdf08"
} }
] ]

View File

@ -1 +1 @@
["constructor(string,string)","event Approval(address indexed,address indexed,uint256)","event Claim(address,uint256)","event Transfer(address indexed,address indexed,uint256)","function BASIS_POINTS_DIVISOR() view returns (uint256)","function PRECISION() view returns (uint256)","function allowance(address,address) view returns (uint256)","function approve(address,uint256) returns (bool)","function averageStakedAmounts(address) view returns (uint256)","function balanceOf(address) view returns (uint256)","function balances(address) view returns (uint256)","function claim(address) returns (uint256)","function claimForAccount(address,address) returns (uint256)","function claimable(address) view returns (uint256)","function claimableReward(address) view returns (uint256)","function cumulativeRewardPerToken() view returns (uint256)","function cumulativeRewards(address) view returns (uint256)","function decimals() view returns (uint8)","function depositBalances(address,address) view returns (uint256)","function distributor() view returns (address)","function gov() view returns (address)","function inPrivateClaimingMode() view returns (bool)","function inPrivateStakingMode() view returns (bool)","function inPrivateTransferMode() view returns (bool)","function initialize(address[],address)","function isDepositToken(address) view returns (bool)","function isHandler(address) view returns (bool)","function isInitialized() view returns (bool)","function name() view returns (string)","function previousCumulatedRewardPerToken(address) view returns (uint256)","function rewardToken() view returns (address)","function setDepositToken(address,bool)","function setGov(address)","function setHandler(address,bool)","function setInPrivateClaimingMode(bool)","function setInPrivateStakingMode(bool)","function setInPrivateTransferMode(bool)","function stake(address,uint256)","function stakeForAccount(address,address,address,uint256)","function stakedAmounts(address) view returns (uint256)","function symbol() view returns (string)","function tokensPerInterval() view returns (uint256)","function totalDepositSupply(address) view returns (uint256)","function totalSupply() view returns (uint256)","function transfer(address,uint256) returns (bool)","function transferFrom(address,address,uint256) returns (bool)","function unstake(address,uint256)","function unstakeForAccount(address,address,uint256,address)","function updateRewards()","function withdrawToken(address,address,uint256)"] ["constructor(address,address,uint256,uint8)","event Claim(address,uint256)","event TokensPerIntervalChange(uint256)","function claim(address) returns (uint256)","function claimForAccount(address,address) returns (uint256)","function claimable(address) view returns (uint256)","function claimableReward(address) view returns (uint256)","function cumulativeRewards(address) view returns (uint256)","function decimals() view returns (uint8)","function gov() view returns (address)","function inPrivateClaimingMode() view returns (bool)","function inPrivateStakingMode() view returns (bool)","function isDepositToken(address) view returns (bool)","function isHandler(address) view returns (bool)","function lastUpdateTimes(address) view returns (uint256)","function rewardToken() view returns (address)","function setDepositToken(address,bool)","function setGov(address)","function setHandler(address,bool)","function setInPrivateClaimingMode(bool)","function setInPrivateStakingMode(bool)","function setTokensPerInterval(uint256)","function stake(address,uint256)","function stakeForAccount(address,address,address,uint256)","function stakedAmounts(address) view returns (uint256)","function tokensPerInterval() view returns (uint256)","function totalDepositSupply(address) view returns (uint256)","function unstake(address,uint256)","function unstakeForAccount(address,address,uint256,address)","function updateRewards(address)","function withdrawToken(address,address,uint256)"]

View File

@ -1 +1 @@
["constructor(string,string,uint256,address,address,address,address,bool)","event Approval(address indexed,address indexed,uint256)","event Claim(address,uint256)","event Deposit(address,uint256)","event PairTransfer(address indexed,address indexed,uint256)","event Transfer(address indexed,address indexed,uint256)","event Withdraw(address,uint256,uint256)","function allowance(address,address) view returns (uint256)","function approve(address,uint256) returns (bool)","function balanceOf(address) view returns (uint256)","function balances(address) view returns (uint256)","function bonusRewards(address) view returns (uint256)","function claim() returns (uint256)","function claimForAccount(address,address) returns (uint256)","function claimable(address) view returns (uint256)","function claimableToken() view returns (address)","function claimedAmounts(address) view returns (uint256)","function cumulativeClaimAmounts(address) view returns (uint256)","function cumulativeRewardDeductions(address) view returns (uint256)","function decimals() view returns (uint8)","function deposit(uint256)","function depositForAccount(address,uint256)","function esToken() view returns (address)","function getCombinedAverageStakedAmount(address) view returns (uint256)","function getMaxVestableAmount(address) view returns (uint256)","function getPairAmount(address,uint256) view returns (uint256)","function getTotalVested(address) view returns (uint256)","function getVestedAmount(address) view returns (uint256)","function gov() view returns (address)","function hasPairToken() view returns (bool)","function hasRewardTracker() view returns (bool)","function isHandler(address) view returns (bool)","function lastVestingTimes(address) view returns (uint256)","function name() view returns (string)","function needCheckStake() view returns (bool)","function pairAmounts(address) view returns (uint256)","function pairSupply() view returns (uint256)","function pairToken() view returns (address)","function rewardTracker() view returns (address)","function setBonusRewards(address,uint256)","function setCumulativeRewardDeductions(address,uint256)","function setGov(address)","function setHandler(address,bool)","function setRewardTracker(address)","function symbol() view returns (string)","function totalSupply() view returns (uint256)","function transfer(address,uint256) returns (bool)","function transferFrom(address,address,uint256) returns (bool)","function vestingDuration() view returns (uint256)","function withdraw()","function withdrawToken(address,address,uint256)"] ["constructor(string,string,uint256,address,address,address,address,bool)","event Approval(address indexed,address indexed,uint256)","event Claim(address indexed,uint256)","event Deposit(address indexed,uint256)","event DurationUpdated(uint256)","event Transfer(address indexed,address indexed,uint256)","event Withdraw(address indexed,uint256,uint256)","function _updateVesting(address)","function allowance(address,address) view returns (uint256)","function approve(address,uint256) returns (bool)","function balanceOf(address) view returns (uint256)","function balances(address) view returns (uint256)","function bonusRewards(address) view returns (uint256)","function claim() returns (uint256)","function claimForAccount(address,address) returns (uint256)","function claimable(address) view returns (uint256)","function claimableToken() view returns (address)","function claimedAmounts(address) view returns (uint256)","function cumulativeClaimAmounts(address) view returns (uint256)","function cumulativeRewardDeductions(address) view returns (uint256)","function decimals() view returns (uint8)","function deposit(uint256)","function depositForAccount(address,uint256)","function esToken() view returns (address)","function getMaxVestableAmount(address) view returns (uint256)","function getTotalVested(address) view returns (uint256)","function getVestedAmount(address) view returns (uint256)","function gov() view returns (address)","function hasRewardTrackerCEC() view returns (bool)","function hasRewardTrackerEsCEC() view returns (bool)","function isHandler(address) view returns (bool)","function lastDepositTimes(address) view returns (uint256)","function lastVestingTimes(address) view returns (uint256)","function name() view returns (string)","function needCheckStake() view returns (bool)","function remainingEsToken(address) view returns (uint256)","function rewardTrackerCEC() view returns (address)","function rewardTrackerEsCEC() view returns (address)","function setBonusRewards(address,uint256)","function setCumulativeRewardDeductions(address,uint256)","function setGov(address)","function setHandler(address,bool)","function setRewardTrackerCEC(address)","function setRewardTrackerEsCEC(address)","function symbol() view returns (string)","function totalSupply() view returns (uint256)","function transfer(address,uint256) returns (bool)","function transferFrom(address,address,uint256) returns (bool)","function updateDuration(uint256)","function updateVesting(address)","function vestingDuration() view returns (uint256)","function vestingTotal(address) view returns (uint256)","function withdraw()","function withdrawToken(address,address,uint256)"]

View File

@ -45,7 +45,7 @@ export async function reportGasUsed(provider: any, tx: any, label: any) {
export async function getBlockTime(provider: any) { export async function getBlockTime(provider: any) {
const blockNumber = await provider.getBlockNumber() const blockNumber = await provider.getBlockNumber()
const block = await provider.getBlock(blockNumber) const block = await provider.getBlock(blockNumber)
return block.timestamp return BigInt(block.timestamp)
} }
export async function getTxnBalances(provider: any, user: any, txn: any, callback: any) { export async function getTxnBalances(provider: any, user: any, txn: any, callback: any) {

View File

@ -42,11 +42,7 @@ describe('RewardRouter', function() {
const esCec = await EsToken.deploy("test esCec", "esCec"); const esCec = await EsToken.deploy("test esCec", "esCec");
const RewardTracker = await hre.ethers.getContractFactory("RewardTracker"); const RewardTracker = await hre.ethers.getContractFactory("RewardTracker");
const RewardDistributor = await hre.ethers.getContractFactory("RewardDistributor"); const stakedCecTracker = await RewardTracker.deploy(esCec.target, cec.target, rewardPerSecond, 18);
const stakedCecTracker = await RewardTracker.deploy("Staked CEC", "sCEC");
const stakedCecDistributor = await RewardDistributor.deploy(esCec.target, stakedCecTracker.target);
await stakedCecTracker.initialize([cec.target, esCec.target], stakedCecDistributor.target);
await stakedCecDistributor.updateLastDistributionTime();
const Vester = await hre.ethers.getContractFactory("Vester"); const Vester = await hre.ethers.getContractFactory("Vester");
const vester = await Vester.deploy( const vester = await Vester.deploy(
@ -54,13 +50,12 @@ describe('RewardRouter', function() {
"veCEC", "veCEC",
secondsPerYear, secondsPerYear,
esCec.target, esCec.target,
ZeroAddress,
cec.target, cec.target,
stakedCecTracker.target,
ZeroAddress, ZeroAddress,
false false
); );
await stakedCecTracker.setInPrivateTransferMode(true)
await stakedCecTracker.setInPrivateStakingMode(true) await stakedCecTracker.setInPrivateStakingMode(true)
await esCec.setInPrivateTransferMode(true) await esCec.setInPrivateTransferMode(true)
@ -74,15 +69,13 @@ describe('RewardRouter', function() {
await esCec.setMinter(owner.address, true) await esCec.setMinter(owner.address, true)
await esCec.setHandler(owner.address, true) await esCec.setHandler(owner.address, true)
await esCec.mint(stakedCecDistributor.target, expandDecimals(50000, 18)) await esCec.mint(stakedCecTracker.target, expandDecimals(50000, 18))
await stakedCecDistributor.setTokensPerInterval(rewardPerSecond)
await stakedCecTracker.setHandler(rewardRouter.target, true) await stakedCecTracker.setHandler(rewardRouter.target, true)
await esCec.setMinter(vester.target, true) await esCec.setMinter(vester.target, true)
await esCec.setHandler(stakedCecTracker.target, true) await esCec.setHandler(stakedCecTracker.target, true)
await esCec.setHandler(stakedCecDistributor.target, true)
return { owner, user0, user1, user2, chainId, cec, esCec, stakedCecTracker, stakedCecDistributor, vester, rewardRouter }; return { owner, user0, user1, user2, chainId, cec, esCec, stakedCecTracker, vester, rewardRouter };
} }
describe("Deployment", function () { describe("Deployment", function () {
it('should deploy RewardRouter', async function() { it('should deploy RewardRouter', async function() {
@ -92,7 +85,7 @@ describe('RewardRouter', function() {
}) })
describe("Staking CEC", function () { describe("Staking CEC", function () {
it("stakeCecForAccount, stakeCec, stakeEsCec, unstakeCec, unstakeEsCec, claimEsCec", async () => { it("stakeCecForAccount, stakeCec, stakeEsCec, unstakeCec, unstakeEsCec, claimEsCec", async () => {
const {owner, user0, user1, user2, chainId, cec, esCec, stakedCecTracker, stakedCecDistributor, vester, rewardRouter} = await loadFixture(deployOneContract); const {owner, user0, user1, user2, chainId, cec, esCec, stakedCecTracker, vester, rewardRouter} = await loadFixture(deployOneContract);
const wallet = owner const wallet = owner
const provider = wallet.provider; const provider = wallet.provider;
await cec.setMinter(wallet.address, true) await cec.setMinter(wallet.address, true)
@ -101,55 +94,51 @@ describe('RewardRouter', function() {
// @ts-ignore // @ts-ignore
await cec.connect(user0).approve(stakedCecTracker.target, expandDecimals(1000, 18)) await cec.connect(user0).approve(stakedCecTracker.target, expandDecimals(1000, 18))
let startTime1 = await blockTime(provider)
console.log('startTime1: ', startTime1)
const lastDistributioTime1 = await stakedCecDistributor.lastDistributionTime()
console.log('lastDistributioTime1: ', lastDistributioTime1)
// @ts-ignore // @ts-ignore
await expect(rewardRouter.connect(user0).batchStakeCecForAccount([user1.address], [expandDecimals(1000, 18)])) await expect(rewardRouter.connect(user0).batchStakeCecForAccount([user1.address], [expandDecimals(1000, 18)]))
.to.be.revertedWith("Governable: forbidden") .to.be.revertedWith("Governable: forbidden")
let startTime = await blockTime(provider)
console.log('startTime: ', startTime)
await rewardRouter.setGov(user0.address) await rewardRouter.setGov(user0.address)
const lastDistributioTime = await stakedCecDistributor.lastDistributionTime()
console.log('lastDistributioTime: ', lastDistributioTime)
// @ts-ignore // @ts-ignore
await rewardRouter.connect(user0).batchStakeCecForAccount([user1.address], [expandDecimals(800, 18)]) await rewardRouter.connect(user0).batchStakeCecForAccount([user1.address], [expandDecimals(800, 18)])
const lastDistributioTime2 = await stakedCecDistributor.lastDistributionTime() let startTime = await blockTime(provider)
console.log('lastDistributioTime2: ', lastDistributioTime2) console.log('startTime: ', startTime)
let nextTime = await blockTime(provider)
console.log('nextTime: ', nextTime)
let reward = BigInt(1000) * BigInt(nextTime - startTime) * rewardPerSecond
//@ts-ignore
expect(await stakedCecTracker.claimable(user1.address)).eq(reward)
expect(await cec.balanceOf(user0.address)).eq(expandDecimals(700, 18)) expect(await cec.balanceOf(user0.address)).eq(expandDecimals(700, 18))
await cec.mint(user1.address, expandDecimals(200, 18)) await cec.mint(user1.address, expandDecimals(200, 18))
expect(await cec.balanceOf(user1.address)).eq(expandDecimals(200, 18)) expect(await cec.balanceOf(user1.address)).eq(expandDecimals(200, 18))
let nowTime = await blockTime(provider)
console.log('nowTime: ', nowTime)
let reward = BigInt(800) * BigInt(nowTime - startTime) * rewardPerSecond
//@ts-ignore
expect(await stakedCecTracker.claimable(user1.address)).eq(reward)
// @ts-ignore // @ts-ignore
await cec.connect(user1).approve(stakedCecTracker.target, expandDecimals(200, 18)) await cec.connect(user1).approve(stakedCecTracker.target, expandDecimals(200, 18))
// @ts-ignore // @ts-ignore
await rewardRouter.connect(user1).stakeCec(expandDecimals(200, 18)) await rewardRouter.connect(user1).stakeCec(expandDecimals(200, 18))
let preTime = nowTime
nowTime = await blockTime(provider)
console.log('nowTime: ', nowTime)
let _reward = BigInt(800) * BigInt(nowTime - preTime) * rewardPerSecond
reward += _reward
expect(await stakedCecTracker.claimable(user1.address)).eq(reward)
expect(await cec.balanceOf(user1.address)).eq(0) expect(await cec.balanceOf(user1.address)).eq(0)
expect(await stakedCecTracker.stakedAmounts(user0.address)).eq(0) expect(await stakedCecTracker.stakedAmounts(user0.address)).eq(0)
expect(await stakedCecTracker.depositBalances(user0.address, cec.target)).eq(0)
expect(await stakedCecTracker.stakedAmounts(user1.address)).eq(expandDecimals(1000, 18)) expect(await stakedCecTracker.stakedAmounts(user1.address)).eq(expandDecimals(1000, 18))
expect(await stakedCecTracker.depositBalances(user1.address, cec.target)).eq(expandDecimals(1000, 18))
const totalSupply = await stakedCecTracker.totalSupply()
console.log('totalSupply: ', formatEther(totalSupply))
await showLog('init', stakedCecTracker, esCec, user1.address) await showLog('init', stakedCecTracker, esCec, user1.address)
await increaseTime(provider, Number(secondsOneDay)) await increaseTime(provider, Number(secondsOneDay))
await mineBlock(provider) await mineBlock(provider)
await showLog('1day', stakedCecTracker, esCec, user1.address) await showLog('1day', stakedCecTracker, esCec, user1.address)
expect(await stakedCecTracker.claimable(user0.address)).eq(0) expect(await stakedCecTracker.claimable(user0.address)).eq(0)
console.log('blockTime: ', await blockTime(provider)) console.log('blockTime: ', await blockTime(provider))
preTime = nowTime
expect(await stakedCecTracker.claimable(user1.address)).gt(expandDecimals(4, 18)) nowTime = await blockTime(provider)
expect(await stakedCecTracker.claimable(user1.address)).lt(expandDecimals(5, 18)) console.log('nowTime: ', nowTime)
_reward = BigInt(1000) * BigInt(nowTime - preTime) * rewardPerSecond
reward += _reward
expect(await stakedCecTracker.claimable(user1.address)).eq(reward)
await increaseTime(provider, 20) await increaseTime(provider, 20)
await mineBlock(provider) await mineBlock(provider)
@ -161,13 +150,11 @@ describe('RewardRouter', function() {
await cec.connect(user2).approve(stakedCecTracker.target, expandDecimals(500, 18)) await cec.connect(user2).approve(stakedCecTracker.target, expandDecimals(500, 18))
// @ts-ignore // @ts-ignore
await rewardRouter.connect(user2).stakeCec(expandDecimals(500, 18)) await rewardRouter.connect(user2).stakeCec(expandDecimals(500, 18))
let startTime2 = await blockTime(provider)
expect(await stakedCecTracker.stakedAmounts(user0.address)).eq(0) expect(await stakedCecTracker.stakedAmounts(user0.address)).eq(0)
expect(await stakedCecTracker.depositBalances(user0.address, cec.target)).eq(0)
expect(await stakedCecTracker.stakedAmounts(user1.address)).eq(expandDecimals(1000, 18)) expect(await stakedCecTracker.stakedAmounts(user1.address)).eq(expandDecimals(1000, 18))
expect(await stakedCecTracker.depositBalances(user1.address, cec.target)).eq(expandDecimals(1000, 18))
expect(await stakedCecTracker.stakedAmounts(user2.address)).eq(expandDecimals(500, 18)) expect(await stakedCecTracker.stakedAmounts(user2.address)).eq(expandDecimals(500, 18))
expect(await stakedCecTracker.depositBalances(user2.address, cec.target)).eq(expandDecimals(500, 18))
@ -175,26 +162,43 @@ describe('RewardRouter', function() {
await mineBlock(provider) await mineBlock(provider)
expect(await stakedCecTracker.claimable(user0.address)).eq(0) expect(await stakedCecTracker.claimable(user0.address)).eq(0)
expect(await stakedCecTracker.claimable(user1.address)).gt(expandDecimals(8, 18))
expect(await stakedCecTracker.claimable(user1.address)).lt(expandDecimals(9, 18)) preTime = nowTime
expect(await stakedCecTracker.claimable(user2.address)).gt(expandDecimals(2, 18)) nowTime = await blockTime(provider)
expect(await stakedCecTracker.claimable(user2.address)).lt(expandDecimals(5, 18)) console.log('nowTime: ', nowTime)
_reward = BigInt(1000) * BigInt(nowTime - preTime) * rewardPerSecond
reward += _reward
expect(await stakedCecTracker.claimable(user1.address)).eq(reward)
let preTime2 = startTime2
let nowTime2 = await blockTime(provider)
let reward2 = BigInt(500) * BigInt(nowTime2 - preTime2) * rewardPerSecond
expect(await stakedCecTracker.claimable(user2.address)).eq(reward2)
await showLog('2day', stakedCecTracker, esCec, user1.address) await showLog('2day', stakedCecTracker, esCec, user1.address)
expect(await esCec.balanceOf(user1.address)).eq(0) expect(await esCec.balanceOf(user1.address)).eq(0)
// @ts-ignore // @ts-ignore
await rewardRouter.connect(user1).claim() await rewardRouter.connect(user1).claim()
expect(await esCec.balanceOf(user1.address)).gt(expandDecimals(8, 18)) preTime = nowTime
expect(await esCec.balanceOf(user1.address)).lt(expandDecimals(9, 18)) nowTime = await blockTime(provider)
console.log('nowTime: ', nowTime)
_reward = BigInt(1000) * BigInt(nowTime - preTime) * rewardPerSecond
reward += _reward
expect(await esCec.balanceOf(user1.address)).eq(reward)
expect(await stakedCecTracker.claimable(user1.address)).eq(0)
expect(await esCec.balanceOf(user2.address)).eq(0) expect(await esCec.balanceOf(user2.address)).eq(0)
// @ts-ignore // @ts-ignore
await rewardRouter.connect(user2).claim() await rewardRouter.connect(user2).claim()
expect(await esCec.balanceOf(user2.address)).gt(expandDecimals(2, 18)) preTime = nowTime2
expect(await esCec.balanceOf(user2.address)).lt(expandDecimals(5, 18)) nowTime2 = await blockTime(provider)
console.log('nowTime: ', nowTime)
reward2 = BigInt(500) * BigInt(nowTime2 - preTime2) * rewardPerSecond
expect(await esCec.balanceOf(user2.address)).eq(reward2)
@ -206,44 +210,10 @@ describe('RewardRouter', function() {
await increaseTime(provider, Number(secondsOneDay)) await increaseTime(provider, Number(secondsOneDay))
await mineBlock(provider) await mineBlock(provider)
await showLog('claim cec 2day', stakedCecTracker, esCec, user1.address) await showLog('claim cec 2day', stakedCecTracker, esCec, user1.address)
// // @ts-ignore
// await rewardRouter.connect(user1).stakeCec(await esCec.balanceOf(user1.address))
// await showLog('compound', stakedCecTracker, esCec, user1.address) //@ts-ignore
// expect(await stakedCecTracker.stakedAmounts(user1.address)).gt(expandDecimals(1008, 18)) await rewardRouter.connect(user1).claim()
// expect(await stakedCecTracker.stakedAmounts(user1.address)).lt(expandDecimals(1009, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, cec.target)).eq(expandDecimals(1000, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, esCec.target)).gt(expandDecimals(8, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, esCec.target)).lt(expandDecimals(9, 18))
// expect(await cec.balanceOf(user1.address)).eq(0)
// // @ts-ignore
// await rewardRouter.connect(user1).unstakeCec(expandDecimals(300, 18))
// expect(await cec.balanceOf(user1.address)).eq(expandDecimals(300, 18))
// expect(await stakedCecTracker.stakedAmounts(user1.address)).gt(expandDecimals(708, 18))
// expect(await stakedCecTracker.stakedAmounts(user1.address)).lt(expandDecimals(709, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, cec.target)).eq(expandDecimals(700, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, esCec.target)).gt(expandDecimals(8, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, esCec.target)).lt(expandDecimals(9, 18))
// const esCecBalance1 = await esCec.balanceOf(user1.address)
// const esCecUnstakeBalance1 = await stakedCecTracker.depositBalances(user1.address, esCec.target)
// // @ts-ignore
// await rewardRouter.connect(user1).unstakeCec(esCecUnstakeBalance1)
// expect(await esCec.balanceOf(user1.address)).eq(esCecBalance1 + esCecUnstakeBalance1)
// expect(await stakedCecTracker.stakedAmounts(user1.address)).eq(expandDecimals(700, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, cec.target)).eq(expandDecimals(700, 18))
// expect(await stakedCecTracker.depositBalances(user1.address, esCec.target)).eq(0)
// // @ts-ignore
// await expect(rewardRouter.connect(user1).unstakeCec(expandDecimals(1, 18)))
// .to.be.revertedWith("RewardTracker: _amount exceeds depositBalance")
}) })
}) })
}) })

View File

@ -4,7 +4,9 @@ import {getBytes, solidityPackedKeccak256, ZeroAddress} from "ethers";
import {loadFixture} from "@nomicfoundation/hardhat-toolbox/network-helpers"; import {loadFixture} from "@nomicfoundation/hardhat-toolbox/network-helpers";
import {expandDecimals, getBlockTime, increaseTime, mineBlock} from "./shared/utilities"; import {expandDecimals, getBlockTime, increaseTime, mineBlock} from "./shared/utilities";
const secondsPerYear = 365 * 24 * 60 * 60; const secondsPerYear = BigInt(365 * 24 * 60 * 60);
const rewardPerSecond = BigInt(1.5 * 10 ** 18) / secondsPerYear ;
describe("Vester", function () { describe("Vester", function () {
async function deployOneContract() { async function deployOneContract() {
@ -19,13 +21,10 @@ describe("Vester", function () {
await cec.setMinter(owner.address, true); await cec.setMinter(owner.address, true);
await esCec.setMinter(owner.address, true); await esCec.setMinter(owner.address, true);
const RewardDistributor = await hre.ethers.getContractFactory("RewardDistributor");
const RewardTracker = await hre.ethers.getContractFactory("RewardTracker"); const RewardTracker = await hre.ethers.getContractFactory("RewardTracker");
const stakedCecTracker = await RewardTracker.deploy("Staked CEC", "sCEC");
const stakedCecDistributor = await RewardDistributor.deploy(esCec.target, stakedCecTracker.target); const stakedCecTracker = await RewardTracker.deploy(esCec.target, cec.target, rewardPerSecond, 18);
await stakedCecTracker.initialize([cec.target, esCec.target], stakedCecDistributor.target);
await stakedCecDistributor.updateLastDistributionTime();
const Vester = await hre.ethers.getContractFactory("Vester"); const Vester = await hre.ethers.getContractFactory("Vester");
const vester = await Vester.deploy( const vester = await Vester.deploy(
@ -33,9 +32,9 @@ describe("Vester", function () {
"veCEC", "veCEC",
secondsPerYear, secondsPerYear,
esCec.target, esCec.target,
ZeroAddress,
cec.target, cec.target,
stakedCecTracker.target, stakedCecTracker.target,
ZeroAddress,
true true
); );
await cec.mint(owner.address, expandDecimals(100000, 18)); await cec.mint(owner.address, expandDecimals(100000, 18));
@ -50,11 +49,9 @@ describe("Vester", function () {
expect(await vester.symbol()).eq("veCEC"); expect(await vester.symbol()).eq("veCEC");
expect(await vester.vestingDuration()).eq(secondsPerYear); expect(await vester.vestingDuration()).eq(secondsPerYear);
expect(await vester.esToken()).eq(esCec.target); expect(await vester.esToken()).eq(esCec.target);
expect(await vester.pairToken()).eq(ZeroAddress);
expect(await vester.claimableToken()).eq(cec.target); expect(await vester.claimableToken()).eq(cec.target);
expect(await vester.rewardTracker()).eq(stakedCecTracker.target); expect(await vester.rewardTrackerCEC()).eq(stakedCecTracker.target);
expect(await vester.hasPairToken()).eq(false); expect(await vester.hasRewardTrackerCEC()).eq(true);
expect(await vester.hasRewardTracker()).eq(true);
}); });
it("setCumulativeRewardDeductions", async () => { it("setCumulativeRewardDeductions", async () => {
@ -105,7 +102,6 @@ describe("Vester", function () {
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0);
expect(await vester.claimedAmounts(user0.address)).eq(0); expect(await vester.claimedAmounts(user0.address)).eq(0);
expect(await vester.claimable(user0.address)).eq(0); expect(await vester.claimable(user0.address)).eq(0);
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(0); expect(await vester.lastVestingTimes(user0.address)).eq(0);
await esCec.mint(user0.address, expandDecimals(1000, 18)); await esCec.mint(user0.address, expandDecimals(1000, 18));
@ -134,7 +130,6 @@ describe("Vester", function () {
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0);
expect(await vester.claimedAmounts(user0.address)).eq(0); expect(await vester.claimedAmounts(user0.address)).eq(0);
expect(await vester.claimable(user0.address)).eq(0); expect(await vester.claimable(user0.address)).eq(0);
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(blockTime); expect(await vester.lastVestingTimes(user0.address)).eq(blockTime);
await increaseTime(provider, 24 * 60 * 60); await increaseTime(provider, 24 * 60 * 60);
@ -146,9 +141,12 @@ describe("Vester", function () {
expect(await vester.getTotalVested(user0.address)).eq(expandDecimals(1000, 18)); expect(await vester.getTotalVested(user0.address)).eq(expandDecimals(1000, 18));
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0);
expect(await vester.claimedAmounts(user0.address)).eq(0); expect(await vester.claimedAmounts(user0.address)).eq(0);
expect(await vester.claimable(user0.address)).gt("2730000000000000000"); // 1000 / 365 => ~2.739 let lastDepositTime = await vester.lastDepositTimes(user0.address);
expect(await vester.claimable(user0.address)).lt("2750000000000000000"); let lastVestingTime = BigInt(await vester.lastVestingTimes(user0.address));
expect(await vester.pairAmounts(user0.address)).eq(0); expect(lastDepositTime).eq(lastVestingTime);
let now = await getBlockTime(provider);
let total = BigInt(1000) * BigInt(10 ** 18) * (BigInt(now) - lastDepositTime) / BigInt(secondsPerYear);
expect(await vester.claimable(user0.address)).eq(total);
expect(await vester.lastVestingTimes(user0.address)).eq(blockTime); expect(await vester.lastVestingTimes(user0.address)).eq(blockTime);
// @ts-ignore // @ts-ignore
await expect(vester.connect(user0).claim()).to.be.revertedWith("ERC20: transfer amount exceeds balance"); await expect(vester.connect(user0).claim()).to.be.revertedWith("ERC20: transfer amount exceeds balance");
@ -157,43 +155,57 @@ describe("Vester", function () {
// @ts-ignore // @ts-ignore
await vester.connect(user0).claim(); await vester.connect(user0).claim();
blockTime = await getBlockTime(provider); blockTime = await getBlockTime(provider);
lastDepositTime = await vester.lastDepositTimes(user0.address);
now = await getBlockTime(provider);
total = BigInt(1000) * (now - lastDepositTime) * BigInt(10 ** 18) / BigInt(secondsPerYear);
expect(await esCec.balanceOf(user0.address)).eq(0); expect(await esCec.balanceOf(user0.address)).eq(0);
expect(await cec.balanceOf(user0.address)).gt("2730000000000000000"); expect(await cec.balanceOf(user0.address)).eq(total);
expect(await cec.balanceOf(user0.address)).lt("2750000000000000000");
let cecAmount = await cec.balanceOf(user0.address); let cecAmount = await cec.balanceOf(user0.address);
let claimed = cecAmount;
expect(await vester.balanceOf(user0.address)).eq(expandDecimals(1000, 18) - cecAmount); expect(await vester.balanceOf(user0.address)).eq(expandDecimals(1000, 18) - cecAmount);
expect(cecAmount).eq(total);
expect(await vester.getTotalVested(user0.address)).eq(expandDecimals(1000, 18)); expect(await vester.getTotalVested(user0.address)).eq(expandDecimals(1000, 18));
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimedAmounts(user0.address)).eq(cecAmount); expect(await vester.claimedAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimable(user0.address)).eq(0); expect(await vester.claimable(user0.address)).eq(0);
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(blockTime); expect(await vester.lastVestingTimes(user0.address)).eq(blockTime);
await increaseTime(provider, 48 * 60 * 60); await increaseTime(provider, 48 * 60 * 60);
await mineBlock(provider); await mineBlock(provider);
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount); lastDepositTime = await vester.lastDepositTimes(user0.address);
let pre = now
now = await getBlockTime(provider);
let _claimable = BigInt(1000) * (now - pre) * BigInt(10 ** 18) / BigInt(secondsPerYear);
lastVestingTime = BigInt(await vester.lastVestingTimes(user0.address));
expect(pre).eq(lastVestingTime);
expect(await vester.claimedAmounts(user0.address)).eq(cecAmount); expect(await vester.claimedAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimable(user0.address)).gt("5478000000000000000"); // 1000 / 365 * 2 => ~5.479 expect(await vester.claimable(user0.address)).eq(total - claimed + _claimable);
expect(await vester.claimable(user0.address)).lt("5480000000000000000");
await increaseTime(provider, parseInt(365 / 2 - 1 + "") * 24 * 60 * 60); await increaseTime(provider, parseInt(365 / 2 - 1 + "") * 24 * 60 * 60);
await mineBlock(provider); await mineBlock(provider);
let tmpNow = await getBlockTime(provider);
_claimable = BigInt(1000) * (tmpNow - pre) * BigInt(10 ** 18) / BigInt(secondsPerYear);
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimedAmounts(user0.address)).eq(cecAmount); expect(await vester.claimedAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimable(user0.address)).gt(expandDecimals(500, 18)); // 1000 / 2 => 500 expect(await vester.claimable(user0.address)).eq(total - cecAmount + _claimable);
expect(await vester.claimable(user0.address)).lt(expandDecimals(502, 18));
// @ts-ignore // @ts-ignore
await vester.connect(user0).claim(); await vester.connect(user0).claim();
blockTime = await getBlockTime(provider); blockTime = await getBlockTime(provider);
now = await getBlockTime(provider);
_claimable = BigInt(1000) * (now - pre) * BigInt(10 ** 18) / BigInt(secondsPerYear);
total += _claimable;
pre = now;
cecAmount += (total - cecAmount)
expect(await esCec.balanceOf(user0.address)).eq(0); expect(await esCec.balanceOf(user0.address)).eq(0);
expect(await cec.balanceOf(user0.address)).gt(expandDecimals(503, 18)); expect(await cec.balanceOf(user0.address)).eq(cecAmount);
expect(await cec.balanceOf(user0.address)).lt(expandDecimals(505, 18));
cecAmount = await cec.balanceOf(user0.address); cecAmount = await cec.balanceOf(user0.address);
expect(await vester.balanceOf(user0.address)).eq(expandDecimals(1000, 18) - cecAmount); expect(await vester.balanceOf(user0.address)).eq(expandDecimals(1000, 18) - cecAmount);
@ -202,45 +214,58 @@ describe("Vester", function () {
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimedAmounts(user0.address)).eq(cecAmount); expect(await vester.claimedAmounts(user0.address)).eq(cecAmount);
expect(await vester.claimable(user0.address)).eq(0); expect(await vester.claimable(user0.address)).eq(0);
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(blockTime); expect(await vester.lastVestingTimes(user0.address)).eq(blockTime);
await increaseTime(provider, 24 * 60 * 60); await increaseTime(provider, 24 * 60 * 60);
await mineBlock(provider); await mineBlock(provider);
// vesting rate should be the same even after claiming // vesting rate should be the same even after claiming
expect(await vester.claimable(user0.address)).gt("2730000000000000000"); // 1000 / 365 => ~2.739 tmpNow = await getBlockTime(provider);
expect(await vester.claimable(user0.address)).lt("2750000000000000000"); _claimable = BigInt(1000) * (tmpNow - pre) * BigInt(10 ** 18) / BigInt(secondsPerYear);
expect(await vester.claimable(user0.address)).eq(total - cecAmount + _claimable); // 1000 / 365 => ~2.739
await esCec.mint(user0.address, expandDecimals(500, 18)); await esCec.mint(user0.address, expandDecimals(500, 18));
// @ts-ignore // @ts-ignore
await esCec.connect(user0).approve(vester.target, expandDecimals(500, 18)); await esCec.connect(user0).approve(vester.target, expandDecimals(500, 18));
// @ts-ignore // @ts-ignore
await vester.connect(user0).deposit(expandDecimals(500, 18)); await vester.connect(user0).deposit(expandDecimals(500, 18));
tmpNow = await getBlockTime(provider);
_claimable = BigInt(1000) * (tmpNow - pre) * BigInt(10 ** 18) / BigInt(secondsPerYear);
let _balance1 = await vester.balanceOf(user0.address);
let _balance2 = (BigInt(1000) * BigInt(10 ** 18) - cecAmount) + BigInt(500) * BigInt(10 ** 18) - _claimable
expect(_balance1).eq(_balance2);
let vestTotal = await vester.vestingTotal(user0.address);
expect(vestTotal).eq(_balance2);
total += _claimable;
pre = tmpNow;
lastVestingTime = BigInt(await vester.lastVestingTimes(user0.address));
expect(pre).eq(lastVestingTime);
await increaseTime(provider, 24 * 60 * 60); await increaseTime(provider, 24 * 60 * 60);
await mineBlock(provider); await mineBlock(provider);
expect(await vester.claimable(user0.address)).gt("6840000000000000000"); // 1000 / 365 + 1500 / 365 => 6.849 tmpNow = await getBlockTime(provider);
expect(await vester.claimable(user0.address)).lt("6860000000000000000"); _claimable = BigInt(_balance2) * (tmpNow - pre) / BigInt(secondsPerYear);
expect(await esCec.balanceOf(user0.address)).eq(0); expect(await esCec.balanceOf(user0.address)).eq(0);
expect(await cec.balanceOf(user0.address)).eq(cecAmount); expect(await cec.balanceOf(user0.address)).eq(cecAmount);
expect(await vester.claimable(user0.address)).eq(total - cecAmount + _claimable);
// @ts-ignore // @ts-ignore
await vester.connect(user0).withdraw(); await vester.connect(user0).withdraw();
tmpNow = await getBlockTime(provider);
_claimable = BigInt(_balance2) * (tmpNow - pre) / BigInt(secondsPerYear);
cecAmount += (total - cecAmount + _claimable);
expect(await esCec.balanceOf(user0.address)).gt(expandDecimals(989, 18)); expect(await cec.balanceOf(user0.address)).eq(cecAmount);
expect(await esCec.balanceOf(user0.address)).lt(expandDecimals(990, 18));
expect(await cec.balanceOf(user0.address)).gt(expandDecimals(510, 18));
expect(await cec.balanceOf(user0.address)).lt(expandDecimals(512, 18));
expect(await vester.balanceOf(user0.address)).eq(0); expect(await vester.balanceOf(user0.address)).eq(0);
expect(await vester.getTotalVested(user0.address)).eq(0); expect(await vester.getTotalVested(user0.address)).eq(0);
expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0); expect(await vester.cumulativeClaimAmounts(user0.address)).eq(0);
expect(await vester.claimedAmounts(user0.address)).eq(0); expect(await vester.claimedAmounts(user0.address)).eq(0);
expect(await vester.claimable(user0.address)).eq(0); expect(await vester.claimable(user0.address)).eq(0);
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(0); expect(await vester.lastVestingTimes(user0.address)).eq(0);
// @ts-ignore // @ts-ignore
@ -259,7 +284,6 @@ describe("Vester", function () {
expect(await vester.claimedAmounts(user0.address)).eq(0); expect(await vester.claimedAmounts(user0.address)).eq(0);
expect(await vester.claimable(user0.address)).gt("2730000000000000000"); // 1000 / 365 => ~2.739 expect(await vester.claimable(user0.address)).gt("2730000000000000000"); // 1000 / 365 => ~2.739
expect(await vester.claimable(user0.address)).lt("2750000000000000000"); expect(await vester.claimable(user0.address)).lt("2750000000000000000");
expect(await vester.pairAmounts(user0.address)).eq(0);
expect(await vester.lastVestingTimes(user0.address)).eq(blockTime); expect(await vester.lastVestingTimes(user0.address)).eq(blockTime);
// @ts-ignore // @ts-ignore
await vester.connect(user0).claim(); await vester.connect(user0).claim();