Skip to content

Commit

Permalink
Merge branch 'master' into price-rates
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro authored Oct 18, 2018
2 parents 28d91e0 + 94692ac commit b7478bd
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 69 deletions.
13 changes: 9 additions & 4 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract Crowdsale {
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(uint256 rate, address wallet, IERC20 token) public {
constructor(uint256 rate, address wallet, IERC20 token) internal {
require(rate > 0);
require(wallet != address(0));
require(token != address(0));
Expand All @@ -73,6 +73,9 @@ contract Crowdsale {

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

/**
* @return the mount of wei raised.
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}

/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param beneficiary Address performing the token purchase
* @param beneficiary Recipient of the token purchase
*/
function buyTokens(address beneficiary) public payable {

Expand Down Expand Up @@ -152,6 +155,7 @@ contract Crowdsale {
uint256 weiAmount
)
internal
view
{
require(beneficiary != address(0));
require(weiAmount != 0);
Expand All @@ -167,6 +171,7 @@ contract Crowdsale {
uint256 weiAmount
)
internal
view
{
// optional override
}
Expand All @@ -186,7 +191,7 @@ contract Crowdsale {
}

/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send tokens.
* @param beneficiary Address receiving the tokens
* @param tokenAmount Number of tokens to be purchased
*/
Expand Down
2 changes: 1 addition & 1 deletion contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract FinalizableCrowdsale is TimedCrowdsale {

event CrowdsaleFinalized();

constructor() public {
constructor() internal {
_finalized = false;
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {

mapping(address => uint256) private _balances;

constructor() internal {}

/**
* @dev Withdraw tokens only after crowdsale ends.
* @param beneficiary Whose tokens will be withdrawn.
Expand Down
2 changes: 1 addition & 1 deletion contracts/crowdsale/distribution/RefundableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
* @dev Constructor, creates RefundEscrow.
* @param goal Funding goal
*/
constructor(uint256 goal) public {
constructor(uint256 goal) internal {
require(goal > 0);
_escrow = new RefundEscrow(wallet());
_goal = goal;
Expand Down
2 changes: 1 addition & 1 deletion contracts/crowdsale/emission/AllowanceCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract AllowanceCrowdsale is Crowdsale {
* @dev Constructor, takes token wallet address.
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
*/
constructor(address tokenWallet) public {
constructor(address tokenWallet) internal {
require(tokenWallet != address(0));
_tokenWallet = tokenWallet;
}
Expand Down
1 change: 1 addition & 0 deletions contracts/crowdsale/emission/MintedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../../token/ERC20/ERC20Mintable.sol";
* Token ownership should be transferred to MintedCrowdsale for minting.
*/
contract MintedCrowdsale is Crowdsale {
constructor() internal {}

/**
* @dev Overrides delivery by minting tokens upon purchase.
Expand Down
6 changes: 5 additions & 1 deletion contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
* @param initialRate Number of tokens a buyer gets per wei at the start of the crowdsale
* @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
*/
constructor(uint256 initialRate, uint256 finalRate) public {
constructor(uint256 initialRate, uint256 finalRate) internal {
require(finalRate > 0);
require(initialRate > finalRate);
_initialRate = initialRate;
Expand Down Expand Up @@ -55,6 +55,10 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
* @return The number of tokens a buyer gets per wei at a given time
*/
function getCurrentRate() public view returns (uint256) {
if (!isOpen()) {
return 0;
}

// solium-disable-next-line security/no-block-members
uint256 elapsedTime = block.timestamp.sub(openingTime());
uint256 timeRange = closingTime().sub(openingTime());
Expand Down
3 changes: 2 additions & 1 deletion contracts/crowdsale/validation/CappedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract CappedCrowdsale is Crowdsale {
* @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
* @param cap Max amount of wei to be contributed
*/
constructor(uint256 cap) public {
constructor(uint256 cap) internal {
require(cap > 0);
_cap = cap;
}
Expand Down Expand Up @@ -46,6 +46,7 @@ contract CappedCrowdsale is Crowdsale {
uint256 weiAmount
)
internal
view
{
super._preValidatePurchase(beneficiary, weiAmount);
require(weiRaised().add(weiAmount) <= _cap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
mapping(address => uint256) private _contributions;
mapping(address => uint256) private _caps;

constructor() internal {}

/**
* @dev Sets a specific beneficiary's maximum contribution.
* @param beneficiary Address to be capped
Expand Down Expand Up @@ -53,6 +55,7 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
uint256 weiAmount
)
internal
view
{
super._preValidatePurchase(beneficiary, weiAmount);
require(
Expand Down
5 changes: 3 additions & 2 deletions contracts/crowdsale/validation/TimedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ contract TimedCrowdsale is Crowdsale {
* @param openingTime Crowdsale opening time
* @param closingTime Crowdsale closing time
*/
constructor(uint256 openingTime, uint256 closingTime) public {
constructor(uint256 openingTime, uint256 closingTime) internal {
// solium-disable-next-line security/no-block-members
require(openingTime >= block.timestamp);
require(closingTime >= openingTime);
require(closingTime > openingTime);

_openingTime = openingTime;
_closingTime = closingTime;
Expand Down Expand Up @@ -77,6 +77,7 @@ contract TimedCrowdsale is Crowdsale {
)
internal
onlyWhileOpen
view
{
super._preValidatePurchase(beneficiary, weiAmount);
}
Expand Down
9 changes: 9 additions & 0 deletions contracts/mocks/CrowdsaleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity ^0.4.24;

import "../crowdsale/Crowdsale.sol";

contract CrowdsaleMock is Crowdsale {
constructor(uint256 rate, address wallet, IERC20 token) public
Crowdsale(rate, wallet, token) {
}
}
58 changes: 39 additions & 19 deletions contracts/mocks/SafeERC20Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ pragma solidity ^0.4.24;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/SafeERC20.sol";

contract ERC20FailingMock is IERC20 {
function totalSupply() public view returns (uint256) {
return 0;
}
contract ERC20FailingMock {
uint256 private _allowance;

function transfer(address, uint256) public returns (bool) {
return false;
Expand All @@ -20,19 +18,13 @@ contract ERC20FailingMock is IERC20 {
return false;
}

function balanceOf(address) public view returns (uint256) {
return 0;
}

function allowance(address, address) public view returns (uint256) {
return 0;
}
}

contract ERC20SucceedingMock is IERC20 {
function totalSupply() public view returns (uint256) {
return 0;
}
contract ERC20SucceedingMock {
uint256 private _allowance;

function transfer(address, uint256) public returns (bool) {
return true;
Expand All @@ -46,12 +38,12 @@ contract ERC20SucceedingMock is IERC20 {
return true;
}

function balanceOf(address) public view returns (uint256) {
return 0;
function setAllowance(uint256 allowance_) public {
_allowance = allowance_;
}

function allowance(address, address) public view returns (uint256) {
return 0;
return _allowance;
}
}

Expand All @@ -62,10 +54,12 @@ contract SafeERC20Helper {
IERC20 private _succeeding;

constructor() public {
_failing = new ERC20FailingMock();
_succeeding = new ERC20SucceedingMock();
_failing = IERC20(new ERC20FailingMock());
_succeeding = IERC20(new ERC20SucceedingMock());
}

// Using _failing

function doFailingTransfer() public {
_failing.safeTransfer(address(0), 0);
}
Expand All @@ -78,6 +72,16 @@ contract SafeERC20Helper {
_failing.safeApprove(address(0), 0);
}

function doFailingIncreaseAllowance() public {
_failing.safeIncreaseAllowance(address(0), 0);
}

function doFailingDecreaseAllowance() public {
_failing.safeDecreaseAllowance(address(0), 0);
}

// Using _succeeding

function doSucceedingTransfer() public {
_succeeding.safeTransfer(address(0), 0);
}
Expand All @@ -86,7 +90,23 @@ contract SafeERC20Helper {
_succeeding.safeTransferFrom(address(0), address(0), 0);
}

function doSucceedingApprove() public {
_succeeding.safeApprove(address(0), 0);
function doSucceedingApprove(uint256 amount) public {
_succeeding.safeApprove(address(0), amount);
}

function doSucceedingIncreaseAllowance(uint256 amount) public {
_succeeding.safeIncreaseAllowance(address(0), amount);
}

function doSucceedingDecreaseAllowance(uint256 amount) public {
_succeeding.safeDecreaseAllowance(address(0), amount);
}

function setAllowance(uint256 allowance_) public {
ERC20SucceedingMock(_succeeding).setAllowance(allowance_);
}

function allowance() public view returns (uint256) {
return _succeeding.allowance(address(0), address(0));
}
}
18 changes: 2 additions & 16 deletions contracts/token/ERC20/ERC20Capped.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,8 @@ contract ERC20Capped is ERC20Mintable {
return _cap;
}

/**
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(
address to,
uint256 value
)
public
returns (bool)
{
function _mint(address account, uint256 value) internal {
require(totalSupply().add(value) <= _cap);

return super.mint(to, value);
super._mint(account, value);
}

}
29 changes: 29 additions & 0 deletions contracts/token/ERC20/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import "./IERC20.sol";
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {

using SafeMath for uint256;

function safeTransfer(
IERC20 token,
address to,
Expand Down Expand Up @@ -38,6 +41,32 @@ library SafeERC20 {
)
internal
{
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require((value == 0) || (token.allowance(msg.sender, spender) == 0));
require(token.approve(spender, value));
}

function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
)
internal
{
uint256 newAllowance = token.allowance(address(this), spender).add(value);
require(token.approve(spender, newAllowance));
}

function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
)
internal
{
uint256 newAllowance = token.allowance(address(this), spender).sub(value);
require(token.approve(spender, newAllowance));
}
}
4 changes: 2 additions & 2 deletions contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contract ERC721 is ERC165, IERC721 {
{
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkAndCallSafeTransfer(from, to, tokenId, _data));
require(_checkOnERC721Received(from, to, tokenId, _data));
}

/**
Expand Down Expand Up @@ -306,7 +306,7 @@ contract ERC721 is ERC165, IERC721 {
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkAndCallSafeTransfer(
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/ERC721Metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract ERC721Metadata is ERC165, ERC721, IERC721Metadata {
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
Expand Down
Loading

0 comments on commit b7478bd

Please sign in to comment.