Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding Periodic Crowdsale
  • Loading branch information
Georgi Spasov authored and Perseverance committed Dec 29, 2017
commit 6a53b0529c1a7534f80c15ccbb9e83ac3be6d0e2
8 changes: 7 additions & 1 deletion contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ contract Crowdsale {
buyTokens(msg.sender);
}

// determines the rate of the crowdsale. Override this for periodization logic
function getRate() internal constant returns(uint256) {
return rate;
}

// low level token purchase function
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
Expand All @@ -73,7 +78,8 @@ contract Crowdsale {
uint256 weiAmount = msg.value;

// calculate token amount to be created
uint256 tokens = weiAmount.mul(rate);
uint256 _rate = getRate();
uint256 tokens = weiAmount.mul(_rate);
Copy link

@grimsa grimsa Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't extracting getTokenAmount(weiAmount) with default implementation of weiAmount.mul(rate) be more flexible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure which one is more flexible :) I wanted to keep the code as similar to the original one

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had two scenarios in my mind:

  1. Applying multiple price levels to a transaction, for example:
    • You have a crowdsale with a bonus period where you are minting tokens at 25% increased rate until GOAL wei are raised.
    • Let's say you have raised (GOAL - 10 wei) already and a big transaction comes sending 10k ETH. You only want to mint (10 wei * 25%) worth of bonus tokens (not 10K ETH * 25 %).
  2. Rounding problems when original rate = 1. Example:
    • If you want to implement 1 ETH = 1 Token crowdsale, you'll use a rate of 1 and a token with 18 decimal places.
    • Now if you want to issue tokens at 125% rate at first, you have a problem, as getRate result will be 1 (original rate) * 5/4, which rounds down to 1, hence, no bonus.

It is impossible to implement any of these two by just overriding getRate().

As you can always override getTokenAmount(weiAmount) and implement it as weiAmount.mul(getRate()) with a custom getRate() function, to me it seems like a superior approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, will rewrite it ASAP ;)


// update state
weiRaised = weiRaised.add(weiAmount);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zeppelin-solidity",
"version": "1.4.0",
"version": "1.4.1",
"description": "Secure Smart Contract library for Solidity",
"scripts": {
"test": "scripts/test.sh",
Expand Down Expand Up @@ -52,4 +52,4 @@
"dependencies": {
"dotenv": "^4.0.0"
}
}
}