-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Feature/crowdsale refactor #744
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
Changes from 1 commit
49b16cf
fc7af3c
d54f799
f48c150
3f5680b
a8a14df
469a999
90f0973
3ffe518
a5aaf94
8a3cfb9
6343246
2c22337
8c8fed1
962b5bc
bbb2dfa
3fdb6da
53ec3cc
2be5806
b814a05
dd05925
120d277
e677e33
5873f8e
2fe239c
bf5e9dd
cd0ba80
0487d25
c4a2f9c
3ef55bc
c1a41ae
b455000
a841691
3d4d41a
8b6b342
1a2a5ec
1680a18
344bec6
7d4035a
bcd0464
51c0954
cd15b41
e716a22
7134f0d
f56116e
2a6dd9f
8e8e8cc
fa055a6
56e83b9
1bf30f9
a70e3ed
5f4fc83
47ce79f
5dab495
dd338f1
8376baa
8ad6a10
107fdc4
530d85d
9fe61b8
de8e88f
6c38f46
33839c1
df03099
c6def0e
c177f01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,19 +6,24 @@ import "../../math/SafeMath.sol"; | |
|
|
||
| /** | ||
| * @title PostDeliveryCrowdsale | ||
| * @dev Crowdsale that locks funds from withdrawal until it ends | ||
| * @dev Crowdsale that locks tokens from withdrawal until it ends. | ||
| */ | ||
| contract PostDeliveryCrowdsale is TimedCrowdsale { | ||
| using SafeMath for uint256; | ||
|
|
||
| mapping(address => uint256) public promises; | ||
|
||
|
|
||
| /** | ||
| * @dev Overrides parent by storing balances instead of issuing tokens right away. | ||
| * @param _beneficiary Token purchaser | ||
| * @param _tokenAmount Amount of tokens purchased | ||
| */ | ||
| function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing doc |
||
| promises[_beneficiary] = promises[_beneficiary].add(_tokenAmount); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Withdraw tokens only after crowdsale ends | ||
| * @dev Withdraw tokens only after crowdsale ends. | ||
| */ | ||
| function withdrawTokens() public { | ||
| require(hasExpired()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,11 @@ import "../Crowdsale.sol"; | |
| import "../../token/ERC20/ERC20.sol"; | ||
| import "../../math/SafeMath.sol"; | ||
|
|
||
|
|
||
| /** | ||
| * @title AllowanceCrowdsale | ||
| * @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale. | ||
| */ | ||
| contract AllowanceCrowdsale is Crowdsale { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try if we can find a better name for this one
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I thought it was very clear, even more considering the alternatives @fiiiu and @ajsantander discussed. |
||
| using SafeMath for uint256; | ||
|
|
||
|
|
@@ -24,6 +29,11 @@ contract AllowanceCrowdsale is Crowdsale { | |
| return token.allowance(tokenWallet, this); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Overrides parent behavior by transferring tokens from wallet. | ||
| * @param _beneficiary Token purchaser | ||
| * @param _tokenAmount Amount of tokens purchased | ||
| */ | ||
| function _emitTokens(address _beneficiary, uint256 _tokenAmount) internal { | ||
|
||
| token.transferFrom(tokenWallet, _beneficiary, _tokenAmount); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,12 @@ pragma solidity ^0.4.18; | |
| import "../validation/TimedCrowdsale.sol"; | ||
| import "../../math/SafeMath.sol"; | ||
|
|
||
|
|
||
| /** | ||
| * @title IncreasingPriceCrowdsale | ||
| * @dev Extension of Crowdsale contract that increases the price of tokens linearly in time. | ||
| * Note that what should be provided to the constructor is the initial and final _rates_, that is, | ||
| * the amount of tokens per ETH contributed. Thus, the initial rate must be greater than the final rate. | ||
| */ | ||
| contract IncreasingPriceCrowdsale is TimedCrowdsale { | ||
| using SafeMath for uint256; | ||
|
|
||
|
|
@@ -22,15 +27,22 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale { | |
| } | ||
|
|
||
| /** | ||
| * @dev Returns the rate of tokens per ETH at the present time. | ||
| * Note that, as price _increases_ with time, the rate _decreases_. | ||
| * @return The number of tokens a buyer gets per wei at a given time | ||
| */ | ||
| function getCurrentRate() public view returns (uint256) { | ||
| uint256 elapsedTime = now - startTime; | ||
| uint256 timeRange = endTime - startTime; | ||
| uint256 rateRange = initialRate - finalRate; | ||
| uint256 elapsedTime = now.sub(startTime); | ||
| uint256 timeRange = endTime.sub(startTime); | ||
| uint256 rateRange = initialRate.sub(finalRate); | ||
| return initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would make
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, slope of the rate curve is negative. I was thinking about the slope of the price curve.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm with @ajsantander in here, this is confusing. We should leave a clarification to avoid silly millionaire mistakes. |
||
| } | ||
|
|
||
| /** | ||
| * @dev Overrides parent method taking into account variable rate. | ||
| * @param _weiAmount The value in wei to be converted into tokens | ||
| * @return The number of tokens _weiAmount wei will buy at present time | ||
| */ | ||
| function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) { | ||
| uint256 currentRate = getCurrentRate(); | ||
| return currentRate.mul(_weiAmount); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,10 @@ import "../../math/SafeMath.sol"; | |
| import "../Crowdsale.sol"; | ||
| import "../../ownership/Ownable.sol"; | ||
|
|
||
|
|
||
| /** | ||
| * @dev Crowdsale with per-user caps | ||
| * @title IndividuallyCappedCrowdsale | ||
| * @dev Crowdsale with per-user caps. | ||
| */ | ||
| contract IndividuallyCappedCrowdsale is Crowdsale, Ownable { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't be more appropriate to say
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, this was @ajsantander's original proposal, I changed it because this sounded to me like "capped by the user", but we can go back if you all favor this :) |
||
| using SafeMath for uint256; | ||
|
|
@@ -37,11 +39,21 @@ contract IndividuallyCappedCrowdsale is Crowdsale, Ownable { | |
| return contributions[_beneficiary]; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Extend parent behavior requiring to not exceed the individual cap. | ||
| * @param _beneficiary Token purchaser | ||
| * @param _weiAmount Amount of wei contributed | ||
| */ | ||
| function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal { | ||
| super._postValidatePurchase(_beneficiary, _weiAmount); | ||
| require(contributions[_beneficiary] <= caps[_beneficiary]); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * @dev Extend parent behavior to update user contributions | ||
| * @param _beneficiary Token purchaser | ||
| * @param _weiAmount Amount of wei contributed | ||
| */ | ||
| function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this? π
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is how the new crowdsale model flow works, we should add more documentation comments though
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed adding this with @ajsantander, please see above (link might work as intended as the comment is folded). The idea is to decouple validation from state tracking, taking into account future extensions. Usage is now described in parent |
||
| super._updatePurchasingState(_beneficiary, _weiAmount); | ||
| contributions[_beneficiary] = contributions[_beneficiary].add(_weiAmount); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,10 @@ pragma solidity ^0.4.18; | |
| import "../../math/SafeMath.sol"; | ||
| import "../Crowdsale.sol"; | ||
|
|
||
|
|
||
| /** | ||
| * @dev Crowdsale accepting contributions only within a time frame | ||
| * @title TimedCrowdsale | ||
| * @dev Crowdsale accepting contributions only within a time frame. | ||
| */ | ||
| contract TimedCrowdsale is Crowdsale { | ||
| using SafeMath for uint256; | ||
|
|
@@ -30,7 +32,12 @@ contract TimedCrowdsale is Crowdsale { | |
| function hasExpired() public view returns (bool) { | ||
|
||
| return now > endTime; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @dev Extend parent behavior requiring to be within contributing period | ||
| * @param _beneficiary Token purchaser | ||
| * @param _weiAmount Amount of wei contributed | ||
| */ | ||
| function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal { | ||
| super._preValidatePurchase(_beneficiary, _weiAmount); | ||
| require(now >= startTime && now <= endTime); | ||
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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've traditionally seen multiline
@devcomments either prefixed with@devall the way downThe docs don't specify what happens for multiline, though, so I'm not sure what the standard is. Off the top of my head, though, I think OZ primarily uses the
@devprefix per-line, but I could be wrong and I'm not particularly partialThere 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.
Hi @shrugs. Throughout the OZ codebase, a single
@devat the beginning of a multi-sentence description seems to be the norm (examples: Bounty.sol, DayLimit.sol). Also, the automatically-generated docs parse NatSpec following this convention.The NatSpec specification is not at all clear about how to handle this case, but there are two examples within the document which use a muti-line
@noticetag (link).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.
thanks for the heads up!