-
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 |
|---|---|---|
|
|
@@ -4,20 +4,35 @@ import "../../math/SafeMath.sol"; | |
| import "../Crowdsale.sol"; | ||
| import "../../ownership/Ownable.sol"; | ||
|
|
||
| /** | ||
| * @dev Crowdsale with per-user caps | ||
| */ | ||
| contract IndividuallyCappedCrowdsale is Crowdsale, Ownable { | ||
| using SafeMath for uint256; | ||
|
|
||
| mapping(address => uint256) public contributions; | ||
| mapping(address => uint256) public caps; | ||
|
|
||
| /** | ||
| * @param _beneficiary Address to be capped | ||
| * @param _cap Wei limit for individual contribution | ||
| */ | ||
| function setUserCap(address _beneficiary, uint256 _cap) external onlyOwner { | ||
|
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. Should we consider adding another function accepting an array of addresses? This is an implicit whitelist, it can be expensive to whitelist each crowdsale address in a different function call. |
||
| caps[_beneficiary] = _cap; | ||
| } | ||
|
|
||
| /** | ||
| * @param _beneficiary Address whose cap is to be checked | ||
| * @return Current cap for individual user | ||
| */ | ||
| function getUserCap(address _beneficiary) public view returns (uint256) { | ||
| return caps[_beneficiary]; | ||
| } | ||
|
|
||
| /** | ||
| * @param _beneficiary Address of contributor | ||
| * @return User contribution so far | ||
| */ | ||
| function getUserContribution(address _beneficiary) public view returns (uint256) { | ||
| return contributions[_beneficiary]; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,19 @@ pragma solidity ^0.4.18; | |
| import "../../math/SafeMath.sol"; | ||
| import "../Crowdsale.sol"; | ||
|
|
||
| /** | ||
| * @dev Crowdsale accepting contributions only within a time frame | ||
| */ | ||
| contract TimedCrowdsale is Crowdsale { | ||
| using SafeMath for uint256; | ||
|
|
||
| uint256 public startTime; | ||
| uint256 public endTime; | ||
|
|
||
| /** | ||
| * @param _startTime Crowdsale opening time | ||
| * @param _endTime Crowdsale closing time | ||
| */ | ||
| function TimedCrowdsale(uint256 _startTime, uint256 _endTime) public { | ||
| require(_startTime >= now); | ||
| require(_endTime >= _startTime); | ||
|
||
|
|
@@ -17,6 +24,9 @@ contract TimedCrowdsale is Crowdsale { | |
| endTime = _endTime; | ||
| } | ||
|
|
||
| /** | ||
| * @return Whether crowdsale period has elapsed | ||
| */ | ||
| function hasExpired() public view returns (bool) { | ||
|
||
| return now > endTime; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,18 +3,31 @@ pragma solidity ^ 0.4.18; | |
| import "../Crowdsale.sol"; | ||
| import "../../ownership/Ownable.sol"; | ||
|
|
||
| /** | ||
| * @dev Crowdsale in which only whitelisted users can contribute | ||
| */ | ||
| contract WhitelistedCrowdsale is Crowdsale, Ownable { | ||
|
|
||
| mapping(address => bool) public whitelist; | ||
|
|
||
| /** | ||
| * @param _beneficiary Address to be added to the whitelist | ||
| */ | ||
| function addToWhitelist(address _beneficiary) external onlyOwner { | ||
|
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. Considering this is a crowd sale, we should provide an
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. or a constructor |
||
| whitelist[_beneficiary] = true; | ||
| } | ||
|
|
||
| /** | ||
| * @param _beneficiary Address to be removed to the whitelist | ||
| */ | ||
| function removeFromWhitelist(address _beneficiary) external onlyOwner { | ||
| whitelist[_beneficiary] = false; | ||
| } | ||
|
|
||
| /** | ||
| * @param _beneficiary Address to check whether already in the whitelist | ||
| * @return Whether the address is whitelisted | ||
| */ | ||
| function isWhitelisted(address _beneficiary) public view returns (bool) { | ||
|
||
| return whitelist[_beneficiary]; | ||
| } | ||
|
|
||
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 be more appropriate to say
UserCappedCrowdsale? see the names of the functions belowThere 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.
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 :)