Skip to content

Commit

Permalink
Merge 74e9a26 into 5390587
Browse files Browse the repository at this point in the history
  • Loading branch information
alcueca committed Jan 27, 2020
2 parents 5390587 + 74e9a26 commit 368b757
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 75 deletions.
6 changes: 3 additions & 3 deletions contracts/drafts/issuance/IssuanceAdvanced.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ contract IssuanceAdvanced is Ownable, StateMachine, ReentrancyGuard {
emit InvestmentAdded(msg.sender, _amount);
}

function withdraw() external nonReentrant {
require(currentState == "LIVE", "Cannot withdraw now.");
function claim() external nonReentrant {
require(currentState == "LIVE", "Cannot claim now.");
require(investments[msg.sender] > 0, "No investments found.");
uint256 amount = investments[msg.sender];
investments[msg.sender] = 0;
Expand Down Expand Up @@ -154,7 +154,7 @@ contract IssuanceAdvanced is Ownable, StateMachine, ReentrancyGuard {
/**
* @dev Function to transfer all collected tokens to the wallet of the owner
*/
function transferFunds(address _wallet) public onlyOwner {
function withdraw(address _wallet) public onlyOwner {
require(currentState == "LIVE", "Cannot transfer funds now.");
currencyToken.transfer(_wallet, amountRaised);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/drafts/issuance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To open the issuance to investors, the owner must call `openIssuance()`.

The `Issuance` will mint `IssuanceToken`s (which inherit from `ERC20Mintable` and `ERCDetailed`, hence they are ERC20 tokens) to all investors who participated in the ICO (having `invest()`ed more than `minInvestment` and their investment being a multiple of `issuePrice`) during `openingDate` and `closingDate`.

If the `softcap` has been reached, investors are free to `withdraw()` their alloted tokens after the owner of the `Issuance` proceeds to `startDistribution()`.
If the `softcap` has been reached, investors are free to `claim()` their alloted tokens after the owner of the `Issuance` proceeds to `startDistribution()`.

Otherwise, investors are invited to reclaim their investemnts using `cancelInvestment()` after the owner of the `Issuance` does `cancelAllInvestments()`.

Expand Down Expand Up @@ -73,9 +73,9 @@ Opens the distributing phase, setting the `Issuance` state to `LIVE`.
---

```
withdraw()
claim()
```
Request from investor to withdraw `IssuanceToken`s
Request from investor to claim `IssuanceToken`s

---

Expand Down
10 changes: 5 additions & 5 deletions contracts/issuance/Issuance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import "./../state/StateMachine.sol";
* 6. The contract owner can `cancelAllInvestments` to close the investment phase.
* In this case `invest` is not available, but `cancelInvestment` is.
* 7. Use `startDistribution` to close the investment phase.
* 8. Investors can only `withdraw` their issuance tokens now.
* 9. Owner can use `transferFunds` to send collected currency tokens to a wallet.
* 8. Investors can only `claim` their issuance tokens now.
* 9. Owner can use `withdraw` to send collected currency tokens to a wallet.
*/
contract Issuance is Ownable, StateMachine, ReentrancyGuard {
using SafeMath for uint256;
Expand Down Expand Up @@ -85,10 +85,10 @@ contract Issuance is Ownable, StateMachine, ReentrancyGuard {
emit InvestmentAdded(msg.sender, _amount);
}

function withdraw() external nonReentrant {
function claim() external nonReentrant {
require(
currentState == "LIVE",
"Cannot withdraw now."
"Cannot claim now."
);
require(
investments[msg.sender] > 0,
Expand Down Expand Up @@ -145,7 +145,7 @@ contract Issuance is Ownable, StateMachine, ReentrancyGuard {
/**
* @dev Function to transfer all collected tokens to the wallet of the owner
*/
function transferFunds(address _wallet) public onlyOwner {
function withdraw(address _wallet) public onlyOwner {
require(
currentState == "LIVE",
"Cannot transfer funds now."
Expand Down
17 changes: 10 additions & 7 deletions contracts/issuance/IssuanceEth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import "../state/StateMachine.sol";
* 6. The contract owner can `cancelAllInvestments` to close the investment phase.
* In this case `invest` is not available, but `cancelInvestment` is.
* 7. Use `startDistribution` to close the investment phase.
* 8. Investors can only `withdraw` their issued tokens now.
* 9. Owner can use `transferFunds` to send collected ether to a wallet.
* 8. Investors can only `claim` their issued tokens now.
* 9. Owner can use `withdraw` to send collected ether to a wallet.
*/
contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
using SafeMath for uint256;
Expand All @@ -38,6 +38,7 @@ contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
mapping(address => uint256) public investments;

uint256 public amountRaised;
uint256 public amountWithdrawn;
uint256 public issuePrice;
uint256 internal nextInvestor;

Expand All @@ -55,13 +56,13 @@ contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
}

/**
* @notice Use this function to withdraw your issuance tokens
* @notice Use this function to claim your issuance tokens
* @dev Each user will call this function on his behalf
*/
function withdraw() external nonReentrant {
function claim() external nonReentrant {
require(
currentState == "LIVE",
"Cannot withdraw now."
"Cannot claim now."
);
require(
investments[msg.sender] > 0,
Expand Down Expand Up @@ -139,12 +140,14 @@ contract IssuanceEth is Ownable, StateMachine, ReentrancyGuard {
/**
* @dev Function to transfer all collected tokens to the wallet of the owner
*/
function transferFunds(address payable _wallet) public onlyOwner {
function withdraw(address payable _wallet) public onlyOwner nonReentrant {
require(
currentState == "LIVE",
"Cannot transfer funds now."
);
_wallet.transfer(amountRaised);
uint256 amount = amountRaised - amountWithdrawn;
amountWithdrawn = amount;
_wallet.transfer(amount);
}

function setIssuePrice(uint256 _issuePrice) public onlyOwner {
Expand Down
6 changes: 3 additions & 3 deletions contracts/issuance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To open the issuance to investors, the owner must call `openIssuance()`.

The `Issuance` will mint `ERC20Mintable` to all investors who participated in the ICO.

Investors are free to `withdraw()` their alloted tokens after the owner of the `Issuance` proceeds to `startDistribution()`.
Investors are free to `claim()` their alloted tokens after the owner of the `Issuance` proceeds to `startDistribution()`.

Otherwise, investors are invited to reclaim their investemnts using `cancelInvestment()` after the owner of the `Issuance` does `cancelAllInvestments()`.

Expand Down Expand Up @@ -71,9 +71,9 @@ Opens the distributing phase, setting the `Issuance` state to `LIVE`.
---

```
withdraw()
claim()
```
Request from investor to withdraw `IssuanceToken`.
Request from investor to claim `IssuanceToken`.

---

Expand Down
36 changes: 18 additions & 18 deletions test/drafts/issuance/IssuanceAdvanced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ contract('IssuanceAdvanced', (accounts) => {
}, 'Not enough funds collected.');

/**
* @test {IssuanceAdvanced#withdraw}
* @test {IssuanceAdvanced#claim}
*/
it('withdraw sends tokens to investors', async () => {
it('claim sends tokens to investors', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -176,16 +176,16 @@ contract('IssuanceAdvanced', (accounts) => {
await advanceTimeAndBlock(4000);
await issuance.startDistribution();
bytes32ToString(await issuance.currentState()).should.be.equal('LIVE');
await issuance.withdraw({ from: investor1 });
await issuance.withdraw({ from: investor2 });
await issuance.claim({ from: investor1 });
await issuance.claim({ from: investor2 });
web3.utils.fromWei(await issuanceToken.balanceOf(investor1), 'ether').should.be.equal('10');
web3.utils.fromWei(await issuanceToken.balanceOf(investor2), 'ether').should.be.equal('2');
});

/**
* @test {IssuanceAdvanced#withdraw}
* @test {IssuanceAdvanced#claim}
*/
itShouldThrow('cannot withdraw when state is not "LIVE"', async () => {
itShouldThrow('cannot claim when state is not "LIVE"', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -194,13 +194,13 @@ contract('IssuanceAdvanced', (accounts) => {
await issuance.invest(new BigNumber(50e18), { from: investor1 });
await issuance.invest(new BigNumber(10e18), { from: investor2 });
await advanceTimeAndBlock(4000);
await issuance.withdraw({ from: investor1 });
}, 'Cannot withdraw now.');
await issuance.claim({ from: investor1 });
}, 'Cannot claim now.');

/**
* @test {IssuanceAdvanced#withdraw}
* @test {IssuanceAdvanced#claim}
*/
itShouldThrow('cannot withdraw when not invested', async () => {
itShouldThrow('cannot claim when not invested', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -209,7 +209,7 @@ contract('IssuanceAdvanced', (accounts) => {
await issuance.invest(new BigNumber(50e18), { from: investor1 });
await advanceTimeAndBlock(4000);
await issuance.startDistribution();
await issuance.withdraw({ from: investor2 });
await issuance.claim({ from: investor2 });
}, 'No investments found.');

/**
Expand Down Expand Up @@ -271,9 +271,9 @@ contract('IssuanceAdvanced', (accounts) => {
});

/**
* @test {IssuanceAdvanced#transferFunds}
* @test {IssuanceAdvanced#withdraw}
*/
it('transferFunds should transfer all collected tokens to the wallet of the owner', async () => {
it('withdraw should transfer all collected tokens to the wallet of the owner', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -283,18 +283,18 @@ contract('IssuanceAdvanced', (accounts) => {
await issuance.invest(new BigNumber(10e18), { from: investor2 });
await advanceTimeAndBlock(4000);
await issuance.startDistribution();
await issuance.withdraw({ from: investor1 });
await issuance.withdraw({ from: investor2 });
await issuance.transferFunds(wallet);
await issuance.claim({ from: investor1 });
await issuance.claim({ from: investor2 });
await issuance.withdraw(wallet);
web3.utils.fromWei(await currencyToken.balanceOf(wallet), 'ether').should.be.equal('60');
});

/**
* @test {IssuanceAdvanced#transferFunds}
* @test {IssuanceAdvanced#withdraw}
*/
itShouldThrow('cannot transfer funds when issuance state is not "LIVE"', async () => {
await issuance.openIssuance();
await issuance.transferFunds(wallet);
await issuance.withdraw(wallet);
}, 'Cannot transfer funds now.');


Expand Down
36 changes: 18 additions & 18 deletions test/issuance/Issuance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ contract('IssuanceToken', (accounts) => {
});

/**
* @test {Issuance#withdraw}
* @test {Issuance#claim}
*/
it('withdraw sends tokens to investors', async () => {
it('claim sends tokens to investors', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -107,38 +107,38 @@ contract('IssuanceToken', (accounts) => {
await issuance.invest(new BigNumber(10e18), { from: investor2 });
await issuance.startDistribution();
bytes32ToString(await issuance.currentState()).should.be.equal('LIVE');
await issuance.withdraw({ from: investor1 });
await issuance.withdraw({ from: investor2 });
await issuance.claim({ from: investor1 });
await issuance.claim({ from: investor2 });
web3.utils.fromWei(await issuanceToken.balanceOf(investor1), 'ether').should.be.equal('10');
web3.utils.fromWei(await issuanceToken.balanceOf(investor2), 'ether').should.be.equal('2');
});

/**
* @test {Issuance#withdraw}
* @test {Issuance#claim}
*/
itShouldThrow('cannot withdraw when state is not "LIVE"', async () => {
itShouldThrow('cannot claim when state is not "LIVE"', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
await currencyToken.approve(issuance.address, new BigNumber(10e18), { from: investor2 });
await issuance.openIssuance();
await issuance.invest(new BigNumber(50e18), { from: investor1 });
await issuance.invest(new BigNumber(10e18), { from: investor2 });
await issuance.withdraw({ from: investor1 });
}, 'Cannot withdraw now.');
await issuance.claim({ from: investor1 });
}, 'Cannot claim now.');

/**
* @test {Issuance#withdraw}
* @test {Issuance#claim}
*/
itShouldThrow('cannot withdraw when not invested', async () => {
itShouldThrow('cannot claim when not invested', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
await currencyToken.approve(issuance.address, new BigNumber(10e18), { from: investor2 });
await issuance.openIssuance();
await issuance.invest(new BigNumber(50e18), { from: investor1 });
await issuance.startDistribution();
await issuance.withdraw({ from: investor2 });
await issuance.claim({ from: investor2 });
}, 'No investments found.');

/**
Expand Down Expand Up @@ -199,9 +199,9 @@ contract('IssuanceToken', (accounts) => {
});

/**
* @test {Issuance#transferFunds}
* @test {Issuance#withdraw}
*/
it('transferFunds should transfer all collected tokens to the wallet of the owner', async () => {
it('withdraw should transfer all collected tokens to the wallet of the owner', async () => {
await currencyToken.mint(investor1, new BigNumber(100e18));
await currencyToken.mint(investor2, new BigNumber(50e18));
await currencyToken.approve(issuance.address, new BigNumber(50e18), { from: investor1 });
Expand All @@ -210,18 +210,18 @@ contract('IssuanceToken', (accounts) => {
await issuance.invest(new BigNumber(50e18), { from: investor1 });
await issuance.invest(new BigNumber(10e18), { from: investor2 });
await issuance.startDistribution();
await issuance.withdraw({ from: investor1 });
await issuance.withdraw({ from: investor2 });
await issuance.transferFunds(wallet);
await issuance.claim({ from: investor1 });
await issuance.claim({ from: investor2 });
await issuance.withdraw(wallet);
web3.utils.fromWei(await currencyToken.balanceOf(wallet), 'ether').should.be.equal('60');
});

/**
* @test {Issuance#transferFunds}
* @test {Issuance#withdraw}
*/
itShouldThrow('cannot transfer funds when issuance state is not "LIVE"', async () => {
await issuance.openIssuance();
await issuance.transferFunds(wallet);
await issuance.withdraw(wallet);
}, 'Cannot transfer funds now.');
});

Expand Down

0 comments on commit 368b757

Please sign in to comment.