Skip to content

Commit

Permalink
subtract total committed emergency exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey Santoro committed Jan 28, 2021
1 parent c710ec6 commit 604890d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contracts/genesis/GenesisGroup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,17 @@ contract GenesisGroup is IGenesisGroup, CoreRef, ERC20, ERC20Burnable, Timed {
function emergencyExit(address from, address to) external {
require(now > (startTime + duration + 3 days), "GenesisGroup: Not in exit window");

uint amountFGEN = balanceOf(from);
uint total = amountFGEN + committedFGEN[from];
uint heldFGEN = balanceOf(from);
uint committed = committedFGEN[from];
uint total = heldFGEN + committed;

require(total != 0, "GenesisGroup: No FGEN or committed balance");
require(address(this).balance >= total, "GenesisGroup: Not enough ETH to redeem");
require(msg.sender == from || allowance(from, msg.sender) >= total, "GenesisGroup: Not approved for emergency withdrawal");

burnFrom(from, amountFGEN);
burnFrom(from, heldFGEN);
committedFGEN[from] = 0;
totalCommittedFGEN -= committed;

payable(to).transfer(total);
}
Expand Down
15 changes: 15 additions & 0 deletions test/genesis/GenesisGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ describe('GenesisGroup', function () {
expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal('500');
expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal('500');
});

describe('Exit', function() {
beforeEach(async function() {
await time.increase('300000');
await this.genesisGroup.emergencyExit(userAddress, userAddress, {from: userAddress});
});

it('decrements user committed', async function() {
expect(await this.genesisGroup.committedFGEN(userAddress)).to.be.bignumber.equal(new BN('0'));
});

it('decrements total committed', async function() {
expect(await this.genesisGroup.totalCommittedFGEN()).to.be.bignumber.equal(new BN('0'));
});
});
});

describe('Commit other', async function() {
Expand Down

0 comments on commit 604890d

Please sign in to comment.