Skip to content
Merged
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
6 changes: 6 additions & 0 deletions contracts/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ abstract contract Pool is IPool, ERC20, ERC20Burnable, Timed {
function _withdraw(address from, address to) internal returns(uint amountStaked) {
amountStaked = stakedBalance[from];
stakedBalance[from] = 0;
_decrementStaked(amountStaked);

stakedToken.transfer(to, amountStaked);

uint amountPool = balanceOf(from);
Expand Down Expand Up @@ -166,6 +168,10 @@ abstract contract Pool is IPool, ERC20, ERC20Burnable, Timed {
totalStaked = totalStaked.add(amount.toUint128());
}

function _decrementStaked(uint amount) internal {
totalStaked = totalStaked.sub(amount.toUint128());
}

function _twfb(uint amount) internal view returns(uint) {
return amount * uint(remainingTime());
}
Expand Down
66 changes: 48 additions & 18 deletions test/pool/FeiPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,22 @@ describe('Pool', function () {
it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));

expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(66666));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(33334));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
});
});
});
describe('Withdraw', function() {
Expand All @@ -189,14 +194,19 @@ describe('Pool', function () {

it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(this.expectedPoolFeiSecond);
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(100));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(75001));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(this.expectedPoolFeiSecond);
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(100));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(75001));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(75001));
});

describe('Complete', function() {
beforeEach(async function() {
await time.increase(this.window.div(new BN(2)));
Expand All @@ -211,13 +221,17 @@ describe('Pool', function () {
});
it('updates balances', async function() {
expect(await this.pool.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(24999));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(24999));
});
});
});
Expand All @@ -242,17 +256,21 @@ describe('Pool', function () {

it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(this.expectedPoolFeiSecond);
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(100));

expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(100));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(75001));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(75001));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(this.expectedPoolFeiSecond);
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(100));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(75001));
});
});
describe('Claim', function() {
beforeEach(async function() {
Expand Down Expand Up @@ -297,17 +315,21 @@ describe('Pool', function () {
it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(87500));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(12500));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
});
});
});
});
Expand Down Expand Up @@ -439,17 +461,21 @@ describe('Pool', function () {
it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(50));
expect(await this.fei.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(150));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(secondUserAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(50000));
expect(await this.tribe.balanceOf(secondUserAddress)).to.be.bignumber.equal(new BN(50000));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
});
});
});
});
Expand Down Expand Up @@ -492,13 +518,17 @@ describe('Pool', function () {
});
it('updates balances', async function() {
expect(await this.pool.balanceOf(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.fei.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100));
expect(await this.fei.balanceOf(this.pool.address)).to.be.bignumber.equal(new BN(0));
expect(await this.pool.stakedBalance(userAddress)).to.be.bignumber.equal(new BN(0));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100000));
});

it('updates totals', async function() {
expect(await this.pool.totalSupply()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.totalStaked()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.releasedReward()).to.be.bignumber.equal(new BN(0));
expect(await this.pool.claimedRewards()).to.be.bignumber.equal(new BN(100000));
expect(await this.tribe.balanceOf(userAddress)).to.be.bignumber.equal(new BN(100000));
});
});
describe('Deposit', function() {
Expand Down