Skip to content

Commit

Permalink
Merge branch 'POZ-Combined' into CS-Subtract-Total-Committed-Emergenc…
Browse files Browse the repository at this point in the history
…y-Exit
  • Loading branch information
Joeysantoro committed Jan 30, 2021
2 parents 604890d + 0d66119 commit 735cc58
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path to directory or file e.g. test/genesis, test/token/Fei.test.js>`

### Coverage
`npm run coverage`

## License
Fei Protocol is under [the AGPL v3 license](LICENSE.md)
6 changes: 3 additions & 3 deletions contracts/genesis/GenesisGroup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
_;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion contracts/pcv/EthUniswapPCVController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion contracts/pool/Pool.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions contracts/token/UniswapIncentive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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);
Expand Down
26 changes: 22 additions & 4 deletions test/genesis/GenesisGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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');
Expand All @@ -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() {
Expand Down

0 comments on commit 735cc58

Please sign in to comment.