-
Notifications
You must be signed in to change notification settings - Fork 12.4k
BuyTokens getting rate from a function instead of field. Useful for making Crowdsales with bonus periods #632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Minor version increase
|
Sorry for the messiness with the commits, we should squash them upon merge |
|
LGTM, but since this is a breaking change we should settle on a semver strategy before merging (and it should be rebased on to master; 1.5.0 now). cc @frangio for the semver strategy. |
|
Correct me if I am wrong, but I rebased already and saw the version is 1.4.0 before upgrading. Am I rebasing to the wrong branch? |
|
You're totally right; we forgot to update package.json when we released 1.5.0 a few days ago. https://github.com/OpenZeppelin/zeppelin-solidity/releases |
contracts/crowdsale/Crowdsale.sol
Outdated
| // calculate token amount to be created | ||
| uint256 tokens = weiAmount.mul(rate); | ||
| uint256 _rate = getRate(); | ||
| uint256 tokens = weiAmount.mul(_rate); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- 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 %).
- 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
getRateresult will be1 (original rate) * 5/4, which rounds down to1, 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.
There was a problem hiding this comment.
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 ;)
fix: TokenDestructible typo fron->from
fix typo: that -> than
…ate how many tokens are minted to the backer
I've changed the buyTokens method to get the rate from
getRatefunction. This function can later be overridden to make crowdsales with different rate periods based on some business logic.