diff --git a/README.md b/README.md index 749186e7c..396fcb640 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,21 @@ Smart contract code for Fei Protocol and the FEI stablecoin ## Documentation See the [Wiki](https://github.com/fei-protocol/fei-protocol-core/wiki) +## Setup +Currently using Truffle/Ganache with mainnet chain forking for compiling and running contracts locally + +### Install +`git clone https://github.com/fei-protocol/fei-protocol-core.git` + +`npm install` + +### Testing +Entire suite: `npm run testAll` + +Single module/file: `npm run test ` + +### Coverage +`npm run coverage` + ## License Fei Protocol is under [the AGPL v3 license](LICENSE.md) diff --git a/contracts/genesis/GenesisGroup.sol b/contracts/genesis/GenesisGroup.sol index 10fd20efb..e55d88d84 100644 --- a/contracts/genesis/GenesisGroup.sol +++ b/contracts/genesis/GenesisGroup.sol @@ -71,7 +71,7 @@ contract GenesisGroup is IGenesisGroup, CoreRef, ERC20, ERC20Burnable, Timed { } modifier onlyGenesisPeriod() { - require(!isTimeEnded(), "GenesisGroup: Not in Genesis Period"); + require(!isTimeEnded() && !core().hasGenesisGroupCompleted(), "GenesisGroup: Not in Genesis Period"); _; } @@ -87,7 +87,7 @@ contract GenesisGroup is IGenesisGroup, CoreRef, ERC20, ERC20Burnable, Timed { function commit(address from, address to, uint amount) external override onlyGenesisPeriod { burnFrom(from, amount); - committedFGEN[to] = amount; + committedFGEN[to] += amount; totalCommittedFGEN += amount; emit Commit(from, to, amount); @@ -128,7 +128,7 @@ contract GenesisGroup is IGenesisGroup, CoreRef, ERC20, ERC20Burnable, Timed { uint totalFGEN = circulatingFGEN + totalCommittedFGEN; // subtract purchased TRIBE amount - uint totalGenesisTribe = tribeBalance() - totalCommittedTribe; + uint totalGenesisTribe = tribeBalance().sub(totalCommittedTribe); if (circulatingFGEN != 0) { feiAmount = feiBalance() * userFGEN / circulatingFGEN; diff --git a/contracts/pcv/EthUniswapPCVController.sol b/contracts/pcv/EthUniswapPCVController.sol index c45d39026..9f717b677 100644 --- a/contracts/pcv/EthUniswapPCVController.sol +++ b/contracts/pcv/EthUniswapPCVController.sol @@ -119,7 +119,7 @@ contract EthUniswapPCVController is IUniswapPCVController, UniRef { IWETH weth = IWETH(router.WETH()); weth.deposit{value: amount}(); - weth.transfer(address(pair), amount); + assert(weth.transfer(address(pair), amount)); (uint amount0Out, uint amount1Out) = pair.token0() == address(weth) ? (uint(0), amountOut) : (amountOut, uint(0)); pair.swap(amount0Out, amount1Out, address(this), new bytes(0)); diff --git a/contracts/pool/Pool.sol b/contracts/pool/Pool.sol index 3ee4e9230..b9b103545 100644 --- a/contracts/pool/Pool.sol +++ b/contracts/pool/Pool.sol @@ -1,6 +1,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; +import "@uniswap/lib/contracts/libraries/TransferHelper.sol"; import "@openzeppelin/contracts/utils/SafeCast.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; @@ -118,7 +119,12 @@ abstract contract Pool is IPool, ERC20, ERC20Burnable, Timed { require(initialized, "Pool: Uninitialized"); require(amount <= stakedToken.balanceOf(from), "Pool: Balance too low to stake"); - stakedToken.transferFrom(from, address(this), amount); + TransferHelper.safeTransferFrom( + address(stakedToken), + from, + address(this), + amount + ); stakedBalance[to] += amount; _incrementStaked(amount); diff --git a/contracts/token/UniswapIncentive.sol b/contracts/token/UniswapIncentive.sol index d718487d7..519028960 100644 --- a/contracts/token/UniswapIncentive.sol +++ b/contracts/token/UniswapIncentive.sol @@ -131,7 +131,8 @@ contract UniswapIncentive is IUniswapIncentive, UniRef { Decimal.D256 memory initialDeviation, Decimal.D256 memory finalDeviation ) { - (initialDeviation, finalDeviation) = getPriceDeviations(-1 * int256(amount)); + int256 signedAmount = amount.toInt256(); + (initialDeviation, finalDeviation) = getPriceDeviations(-1 * signedAmount); weight = getTimeWeight(); if (initialDeviation.equals(Decimal.zero())) { @@ -153,7 +154,8 @@ contract UniswapIncentive is IUniswapIncentive, UniRef { Decimal.D256 memory initialDeviation, Decimal.D256 memory finalDeviation ) { - (initialDeviation, finalDeviation) = getPriceDeviations(int256(amount)); + int256 signedAmount = amount.toInt256(); + (initialDeviation, finalDeviation) = getPriceDeviations(signedAmount); if (finalDeviation.equals(Decimal.zero())) { return (0, initialDeviation, finalDeviation); diff --git a/test/genesis/GenesisGroup.test.js b/test/genesis/GenesisGroup.test.js index 63bdd20d0..60578b1c7 100644 --- a/test/genesis/GenesisGroup.test.js +++ b/test/genesis/GenesisGroup.test.js @@ -158,8 +158,15 @@ describe('GenesisGroup', function () { it('inits Bonding Curve Oracle', async function() { expect(await this.bo.initPrice()).to.be.bignumber.equal(new BN('950000000000000000')); }); - }); + it('reverts purchase', async function() { + await expectRevert(this.genesisGroup.purchase(userAddress, 100, {from: userAddress, value: 100}), "GenesisGroup: Not in Genesis Period"); + }); + + it('reverts pre-commit', async function() { + await expectRevert(this.genesisGroup.commit(userAddress, userAddress, '500', {from: userAddress}), "GenesisGroup: Not in Genesis Period"); + }); + }); }); describe('Redeem', function() { @@ -174,12 +181,12 @@ describe('GenesisGroup', function () { await this.genesisGroup.purchase(userAddress, 750, {from: userAddress, value: 750}); await this.genesisGroup.purchase(secondUserAddress, 250, {from: secondUserAddress, value: 250}); }); - describe('Single Commit', async function() { - describe('Self commit', async function() { + describe('Single Commit', function() { + describe('Self commit', function() { beforeEach(async function() { await this.genesisGroup.commit(userAddress, userAddress, '500', {from: userAddress}); - await time.increase('2000'); }); + it('succeeds', async function() { expect(await this.genesisGroup.balanceOf(userAddress)).to.be.bignumber.equal('250'); expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal('500'); @@ -200,6 +207,17 @@ describe('GenesisGroup', function () { expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal(new BN('0')); }); }); + describe('Second commit', function() { + beforeEach(async function() { + await this.genesisGroup.commit(userAddress, userAddress, '250', {from: userAddress}); + }); + + it('updates', async function() { + expect(await this.genesisGroup.balanceOf(userAddress)).to.be.bignumber.equal('0'); + expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal('750'); + expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal('750'); + }); + }); }); describe('Commit other', async function() {