Skip to content

Commit b7478bd

Browse files
authored
Merge branch 'master' into price-rates
2 parents 28d91e0 + 94692ac commit b7478bd

21 files changed

+204
-69
lines changed

contracts/crowdsale/Crowdsale.sol

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ contract Crowdsale {
5757
* @param wallet Address where collected funds will be forwarded to
5858
* @param token Address of the token being sold
5959
*/
60-
constructor(uint256 rate, address wallet, IERC20 token) public {
60+
constructor(uint256 rate, address wallet, IERC20 token) internal {
6161
require(rate > 0);
6262
require(wallet != address(0));
6363
require(token != address(0));
@@ -73,6 +73,9 @@ contract Crowdsale {
7373

7474
/**
7575
* @dev fallback function ***DO NOT OVERRIDE***
76+
* Note that other contracts will transfer fund with a base gas stipend
77+
* of 2300, which is not enough to call buyTokens. Consider calling
78+
* buyTokens directly when purchasing tokens from a contract.
7679
*/
7780
function () external payable {
7881
buyTokens(msg.sender);
@@ -100,15 +103,15 @@ contract Crowdsale {
100103
}
101104

102105
/**
103-
* @return the mount of wei raised.
106+
* @return the amount of wei raised.
104107
*/
105108
function weiRaised() public view returns (uint256) {
106109
return _weiRaised;
107110
}
108111

109112
/**
110113
* @dev low level token purchase ***DO NOT OVERRIDE***
111-
* @param beneficiary Address performing the token purchase
114+
* @param beneficiary Recipient of the token purchase
112115
*/
113116
function buyTokens(address beneficiary) public payable {
114117

@@ -152,6 +155,7 @@ contract Crowdsale {
152155
uint256 weiAmount
153156
)
154157
internal
158+
view
155159
{
156160
require(beneficiary != address(0));
157161
require(weiAmount != 0);
@@ -167,6 +171,7 @@ contract Crowdsale {
167171
uint256 weiAmount
168172
)
169173
internal
174+
view
170175
{
171176
// optional override
172177
}
@@ -186,7 +191,7 @@ contract Crowdsale {
186191
}
187192

188193
/**
189-
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
194+
* @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send tokens.
190195
* @param beneficiary Address receiving the tokens
191196
* @param tokenAmount Number of tokens to be purchased
192197
*/

contracts/crowdsale/distribution/FinalizableCrowdsale.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contract FinalizableCrowdsale is TimedCrowdsale {
1515

1616
event CrowdsaleFinalized();
1717

18-
constructor() public {
18+
constructor() internal {
1919
_finalized = false;
2020
}
2121

contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
1313

1414
mapping(address => uint256) private _balances;
1515

16+
constructor() internal {}
17+
1618
/**
1719
* @dev Withdraw tokens only after crowdsale ends.
1820
* @param beneficiary Whose tokens will be withdrawn.

contracts/crowdsale/distribution/RefundableCrowdsale.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
2222
* @dev Constructor, creates RefundEscrow.
2323
* @param goal Funding goal
2424
*/
25-
constructor(uint256 goal) public {
25+
constructor(uint256 goal) internal {
2626
require(goal > 0);
2727
_escrow = new RefundEscrow(wallet());
2828
_goal = goal;

contracts/crowdsale/emission/AllowanceCrowdsale.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ contract AllowanceCrowdsale is Crowdsale {
1919
* @dev Constructor, takes token wallet address.
2020
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
2121
*/
22-
constructor(address tokenWallet) public {
22+
constructor(address tokenWallet) internal {
2323
require(tokenWallet != address(0));
2424
_tokenWallet = tokenWallet;
2525
}

contracts/crowdsale/emission/MintedCrowdsale.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "../../token/ERC20/ERC20Mintable.sol";
99
* Token ownership should be transferred to MintedCrowdsale for minting.
1010
*/
1111
contract MintedCrowdsale is Crowdsale {
12+
constructor() internal {}
1213

1314
/**
1415
* @dev Overrides delivery by minting tokens upon purchase.

contracts/crowdsale/price/IncreasingPriceCrowdsale.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
2020
* @param initialRate Number of tokens a buyer gets per wei at the start of the crowdsale
2121
* @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
2222
*/
23-
constructor(uint256 initialRate, uint256 finalRate) public {
23+
constructor(uint256 initialRate, uint256 finalRate) internal {
2424
require(finalRate > 0);
2525
require(initialRate > finalRate);
2626
_initialRate = initialRate;
@@ -55,6 +55,10 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
5555
* @return The number of tokens a buyer gets per wei at a given time
5656
*/
5757
function getCurrentRate() public view returns (uint256) {
58+
if (!isOpen()) {
59+
return 0;
60+
}
61+
5862
// solium-disable-next-line security/no-block-members
5963
uint256 elapsedTime = block.timestamp.sub(openingTime());
6064
uint256 timeRange = closingTime().sub(openingTime());

contracts/crowdsale/validation/CappedCrowdsale.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ contract CappedCrowdsale is Crowdsale {
1616
* @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
1717
* @param cap Max amount of wei to be contributed
1818
*/
19-
constructor(uint256 cap) public {
19+
constructor(uint256 cap) internal {
2020
require(cap > 0);
2121
_cap = cap;
2222
}
@@ -46,6 +46,7 @@ contract CappedCrowdsale is Crowdsale {
4646
uint256 weiAmount
4747
)
4848
internal
49+
view
4950
{
5051
super._preValidatePurchase(beneficiary, weiAmount);
5152
require(weiRaised().add(weiAmount) <= _cap);

contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
1414
mapping(address => uint256) private _contributions;
1515
mapping(address => uint256) private _caps;
1616

17+
constructor() internal {}
18+
1719
/**
1820
* @dev Sets a specific beneficiary's maximum contribution.
1921
* @param beneficiary Address to be capped
@@ -53,6 +55,7 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
5355
uint256 weiAmount
5456
)
5557
internal
58+
view
5659
{
5760
super._preValidatePurchase(beneficiary, weiAmount);
5861
require(

contracts/crowdsale/validation/TimedCrowdsale.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ contract TimedCrowdsale is Crowdsale {
2626
* @param openingTime Crowdsale opening time
2727
* @param closingTime Crowdsale closing time
2828
*/
29-
constructor(uint256 openingTime, uint256 closingTime) public {
29+
constructor(uint256 openingTime, uint256 closingTime) internal {
3030
// solium-disable-next-line security/no-block-members
3131
require(openingTime >= block.timestamp);
32-
require(closingTime >= openingTime);
32+
require(closingTime > openingTime);
3333

3434
_openingTime = openingTime;
3535
_closingTime = closingTime;
@@ -77,6 +77,7 @@ contract TimedCrowdsale is Crowdsale {
7777
)
7878
internal
7979
onlyWhileOpen
80+
view
8081
{
8182
super._preValidatePurchase(beneficiary, weiAmount);
8283
}

contracts/mocks/CrowdsaleMock.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "../crowdsale/Crowdsale.sol";
4+
5+
contract CrowdsaleMock is Crowdsale {
6+
constructor(uint256 rate, address wallet, IERC20 token) public
7+
Crowdsale(rate, wallet, token) {
8+
}
9+
}

contracts/mocks/SafeERC20Helper.sol

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ pragma solidity ^0.4.24;
33
import "../token/ERC20/IERC20.sol";
44
import "../token/ERC20/SafeERC20.sol";
55

6-
contract ERC20FailingMock is IERC20 {
7-
function totalSupply() public view returns (uint256) {
8-
return 0;
9-
}
6+
contract ERC20FailingMock {
7+
uint256 private _allowance;
108

119
function transfer(address, uint256) public returns (bool) {
1210
return false;
@@ -20,19 +18,13 @@ contract ERC20FailingMock is IERC20 {
2018
return false;
2119
}
2220

23-
function balanceOf(address) public view returns (uint256) {
24-
return 0;
25-
}
26-
2721
function allowance(address, address) public view returns (uint256) {
2822
return 0;
2923
}
3024
}
3125

32-
contract ERC20SucceedingMock is IERC20 {
33-
function totalSupply() public view returns (uint256) {
34-
return 0;
35-
}
26+
contract ERC20SucceedingMock {
27+
uint256 private _allowance;
3628

3729
function transfer(address, uint256) public returns (bool) {
3830
return true;
@@ -46,12 +38,12 @@ contract ERC20SucceedingMock is IERC20 {
4638
return true;
4739
}
4840

49-
function balanceOf(address) public view returns (uint256) {
50-
return 0;
41+
function setAllowance(uint256 allowance_) public {
42+
_allowance = allowance_;
5143
}
5244

5345
function allowance(address, address) public view returns (uint256) {
54-
return 0;
46+
return _allowance;
5547
}
5648
}
5749

@@ -62,10 +54,12 @@ contract SafeERC20Helper {
6254
IERC20 private _succeeding;
6355

6456
constructor() public {
65-
_failing = new ERC20FailingMock();
66-
_succeeding = new ERC20SucceedingMock();
57+
_failing = IERC20(new ERC20FailingMock());
58+
_succeeding = IERC20(new ERC20SucceedingMock());
6759
}
6860

61+
// Using _failing
62+
6963
function doFailingTransfer() public {
7064
_failing.safeTransfer(address(0), 0);
7165
}
@@ -78,6 +72,16 @@ contract SafeERC20Helper {
7872
_failing.safeApprove(address(0), 0);
7973
}
8074

75+
function doFailingIncreaseAllowance() public {
76+
_failing.safeIncreaseAllowance(address(0), 0);
77+
}
78+
79+
function doFailingDecreaseAllowance() public {
80+
_failing.safeDecreaseAllowance(address(0), 0);
81+
}
82+
83+
// Using _succeeding
84+
8185
function doSucceedingTransfer() public {
8286
_succeeding.safeTransfer(address(0), 0);
8387
}
@@ -86,7 +90,23 @@ contract SafeERC20Helper {
8690
_succeeding.safeTransferFrom(address(0), address(0), 0);
8791
}
8892

89-
function doSucceedingApprove() public {
90-
_succeeding.safeApprove(address(0), 0);
93+
function doSucceedingApprove(uint256 amount) public {
94+
_succeeding.safeApprove(address(0), amount);
95+
}
96+
97+
function doSucceedingIncreaseAllowance(uint256 amount) public {
98+
_succeeding.safeIncreaseAllowance(address(0), amount);
99+
}
100+
101+
function doSucceedingDecreaseAllowance(uint256 amount) public {
102+
_succeeding.safeDecreaseAllowance(address(0), amount);
103+
}
104+
105+
function setAllowance(uint256 allowance_) public {
106+
ERC20SucceedingMock(_succeeding).setAllowance(allowance_);
107+
}
108+
109+
function allowance() public view returns (uint256) {
110+
return _succeeding.allowance(address(0), address(0));
91111
}
92112
}

contracts/token/ERC20/ERC20Capped.sol

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,8 @@ contract ERC20Capped is ERC20Mintable {
2424
return _cap;
2525
}
2626

27-
/**
28-
* @dev Function to mint tokens
29-
* @param to The address that will receive the minted tokens.
30-
* @param value The amount of tokens to mint.
31-
* @return A boolean that indicates if the operation was successful.
32-
*/
33-
function mint(
34-
address to,
35-
uint256 value
36-
)
37-
public
38-
returns (bool)
39-
{
27+
function _mint(address account, uint256 value) internal {
4028
require(totalSupply().add(value) <= _cap);
41-
42-
return super.mint(to, value);
29+
super._mint(account, value);
4330
}
44-
4531
}

contracts/token/ERC20/SafeERC20.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import "./IERC20.sol";
1010
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
1111
*/
1212
library SafeERC20 {
13+
14+
using SafeMath for uint256;
15+
1316
function safeTransfer(
1417
IERC20 token,
1518
address to,
@@ -38,6 +41,32 @@ library SafeERC20 {
3841
)
3942
internal
4043
{
44+
// safeApprove should only be called when setting an initial allowance,
45+
// or when resetting it to zero. To increase and decrease it, use
46+
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
47+
require((value == 0) || (token.allowance(msg.sender, spender) == 0));
4148
require(token.approve(spender, value));
4249
}
50+
51+
function safeIncreaseAllowance(
52+
IERC20 token,
53+
address spender,
54+
uint256 value
55+
)
56+
internal
57+
{
58+
uint256 newAllowance = token.allowance(address(this), spender).add(value);
59+
require(token.approve(spender, newAllowance));
60+
}
61+
62+
function safeDecreaseAllowance(
63+
IERC20 token,
64+
address spender,
65+
uint256 value
66+
)
67+
internal
68+
{
69+
uint256 newAllowance = token.allowance(address(this), spender).sub(value);
70+
require(token.approve(spender, newAllowance));
71+
}
4372
}

contracts/token/ERC721/ERC721.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ contract ERC721 is ERC165, IERC721 {
200200
{
201201
transferFrom(from, to, tokenId);
202202
// solium-disable-next-line arg-overflow
203-
require(_checkAndCallSafeTransfer(from, to, tokenId, _data));
203+
require(_checkOnERC721Received(from, to, tokenId, _data));
204204
}
205205

206206
/**
@@ -306,7 +306,7 @@ contract ERC721 is ERC165, IERC721 {
306306
* @param _data bytes optional data to send along with the call
307307
* @return whether the call correctly returned the expected magic value
308308
*/
309-
function _checkAndCallSafeTransfer(
309+
function _checkOnERC721Received(
310310
address from,
311311
address to,
312312
uint256 tokenId,

contracts/token/ERC721/ERC721Metadata.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ contract ERC721Metadata is ERC165, ERC721, IERC721Metadata {
5454
* Throws if the token ID does not exist. May return an empty string.
5555
* @param tokenId uint256 ID of the token to query
5656
*/
57-
function tokenURI(uint256 tokenId) public view returns (string) {
57+
function tokenURI(uint256 tokenId) external view returns (string) {
5858
require(_exists(tokenId));
5959
return _tokenURIs[tokenId];
6060
}

0 commit comments

Comments
 (0)