diff --git a/contracts/access/Roles.sol b/contracts/access/Roles.sol index b0212c2be..b71aa8e29 100644 --- a/contracts/access/Roles.sol +++ b/contracts/access/Roles.sol @@ -6,36 +6,36 @@ pragma solidity ^0.4.24; * @dev Library for managing addresses assigned to a Role. */ library Roles { - struct Role { - mapping (address => bool) bearer; - } + struct Role { + mapping (address => bool) bearer; + } - /** - * @dev give an account access to this role - */ - function add(Role storage role, address account) internal { - require(account != address(0)); - role.bearer[account] = true; - } + /** + * @dev give an account access to this role + */ + function add(Role storage role, address account) internal { + require(account != address(0)); + role.bearer[account] = true; + } - /** - * @dev remove an account's access to this role - */ - function remove(Role storage role, address account) internal { - require(account != address(0)); - role.bearer[account] = false; - } + /** + * @dev remove an account's access to this role + */ + function remove(Role storage role, address account) internal { + require(account != address(0)); + role.bearer[account] = false; + } - /** - * @dev check if an account has this role - * @return bool - */ - function has(Role storage role, address account) - internal - view - returns (bool) - { - require(account != address(0)); - return role.bearer[account]; - } + /** + * @dev check if an account has this role + * @return bool + */ + function has(Role storage role, address account) + internal + view + returns (bool) + { + require(account != address(0)); + return role.bearer[account]; + } } diff --git a/contracts/access/roles/CapperRole.sol b/contracts/access/roles/CapperRole.sol index d76d195f9..7347e0a6a 100644 --- a/contracts/access/roles/CapperRole.sol +++ b/contracts/access/roles/CapperRole.sol @@ -5,45 +5,45 @@ import "../Roles.sol"; contract CapperRole is Initializable { - using Roles for Roles.Role; + using Roles for Roles.Role; - event CapperAdded(address indexed account); - event CapperRemoved(address indexed account); + event CapperAdded(address indexed account); + event CapperRemoved(address indexed account); - Roles.Role private cappers; + Roles.Role private cappers; - function initialize(address sender) public initializer { - if (!isCapper(sender)) { - _addCapper(sender); + function initialize(address sender) public initializer { + if (!isCapper(sender)) { + _addCapper(sender); + } } - } - modifier onlyCapper() { - require(isCapper(msg.sender)); - _; - } + modifier onlyCapper() { + require(isCapper(msg.sender)); + _; + } - function isCapper(address account) public view returns (bool) { - return cappers.has(account); - } + function isCapper(address account) public view returns (bool) { + return cappers.has(account); + } - function addCapper(address account) public onlyCapper { - _addCapper(account); - } + function addCapper(address account) public onlyCapper { + _addCapper(account); + } - function renounceCapper() public { - _removeCapper(msg.sender); - } + function renounceCapper() public { + _removeCapper(msg.sender); + } - function _addCapper(address account) internal { - cappers.add(account); - emit CapperAdded(account); - } + function _addCapper(address account) internal { + cappers.add(account); + emit CapperAdded(account); + } - function _removeCapper(address account) internal { - cappers.remove(account); - emit CapperRemoved(account); - } + function _removeCapper(address account) internal { + cappers.remove(account); + emit CapperRemoved(account); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/access/roles/MinterRole.sol b/contracts/access/roles/MinterRole.sol index 7e573fab4..4d451b971 100644 --- a/contracts/access/roles/MinterRole.sol +++ b/contracts/access/roles/MinterRole.sol @@ -5,45 +5,45 @@ import "../Roles.sol"; contract MinterRole is Initializable { - using Roles for Roles.Role; + using Roles for Roles.Role; - event MinterAdded(address indexed account); - event MinterRemoved(address indexed account); + event MinterAdded(address indexed account); + event MinterRemoved(address indexed account); - Roles.Role private minters; + Roles.Role private minters; - function initialize(address sender) public initializer { - if (!isMinter(sender)) { - _addMinter(sender); + function initialize(address sender) public initializer { + if (!isMinter(sender)) { + _addMinter(sender); + } } - } - modifier onlyMinter() { - require(isMinter(msg.sender)); - _; - } + modifier onlyMinter() { + require(isMinter(msg.sender)); + _; + } - function isMinter(address account) public view returns (bool) { - return minters.has(account); - } + function isMinter(address account) public view returns (bool) { + return minters.has(account); + } - function addMinter(address account) public onlyMinter { - _addMinter(account); - } + function addMinter(address account) public onlyMinter { + _addMinter(account); + } - function renounceMinter() public { - _removeMinter(msg.sender); - } + function renounceMinter() public { + _removeMinter(msg.sender); + } - function _addMinter(address account) internal { - minters.add(account); - emit MinterAdded(account); - } + function _addMinter(address account) internal { + minters.add(account); + emit MinterAdded(account); + } - function _removeMinter(address account) internal { - minters.remove(account); - emit MinterRemoved(account); - } + function _removeMinter(address account) internal { + minters.remove(account); + emit MinterRemoved(account); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/access/roles/PauserRole.sol b/contracts/access/roles/PauserRole.sol index ea5fd0df9..4acf3737e 100644 --- a/contracts/access/roles/PauserRole.sol +++ b/contracts/access/roles/PauserRole.sol @@ -5,45 +5,45 @@ import "../Roles.sol"; contract PauserRole is Initializable { - using Roles for Roles.Role; + using Roles for Roles.Role; - event PauserAdded(address indexed account); - event PauserRemoved(address indexed account); + event PauserAdded(address indexed account); + event PauserRemoved(address indexed account); - Roles.Role private pausers; + Roles.Role private pausers; - function initialize(address sender) public initializer { - if (!isPauser(sender)) { - _addPauser(sender); + function initialize(address sender) public initializer { + if (!isPauser(sender)) { + _addPauser(sender); + } } - } - modifier onlyPauser() { - require(isPauser(msg.sender)); - _; - } + modifier onlyPauser() { + require(isPauser(msg.sender)); + _; + } - function isPauser(address account) public view returns (bool) { - return pausers.has(account); - } + function isPauser(address account) public view returns (bool) { + return pausers.has(account); + } - function addPauser(address account) public onlyPauser { - _addPauser(account); - } + function addPauser(address account) public onlyPauser { + _addPauser(account); + } - function renouncePauser() public { - _removePauser(msg.sender); - } + function renouncePauser() public { + _removePauser(msg.sender); + } - function _addPauser(address account) internal { - pausers.add(account); - emit PauserAdded(account); - } + function _addPauser(address account) internal { + pausers.add(account); + emit PauserAdded(account); + } - function _removePauser(address account) internal { - pausers.remove(account); - emit PauserRemoved(account); - } + function _removePauser(address account) internal { + pausers.remove(account); + emit PauserRemoved(account); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/access/roles/SignerRole.sol b/contracts/access/roles/SignerRole.sol index 77553a907..66ebcbedd 100644 --- a/contracts/access/roles/SignerRole.sol +++ b/contracts/access/roles/SignerRole.sol @@ -5,45 +5,45 @@ import "../Roles.sol"; contract SignerRole is Initializable { - using Roles for Roles.Role; + using Roles for Roles.Role; - event SignerAdded(address indexed account); - event SignerRemoved(address indexed account); + event SignerAdded(address indexed account); + event SignerRemoved(address indexed account); - Roles.Role private signers; + Roles.Role private signers; - function initialize(address sender) public initializer { - if (!isSigner(sender)) { - _addSigner(sender); + function initialize(address sender) public initializer { + if (!isSigner(sender)) { + _addSigner(sender); + } } - } - modifier onlySigner() { - require(isSigner(msg.sender)); - _; - } + modifier onlySigner() { + require(isSigner(msg.sender)); + _; + } - function isSigner(address account) public view returns (bool) { - return signers.has(account); - } + function isSigner(address account) public view returns (bool) { + return signers.has(account); + } - function addSigner(address account) public onlySigner { - _addSigner(account); - } + function addSigner(address account) public onlySigner { + _addSigner(account); + } - function renounceSigner() public { - _removeSigner(msg.sender); - } + function renounceSigner() public { + _removeSigner(msg.sender); + } - function _addSigner(address account) internal { - signers.add(account); - emit SignerAdded(account); - } + function _addSigner(address account) internal { + signers.add(account); + emit SignerAdded(account); + } - function _removeSigner(address account) internal { - signers.remove(account); - emit SignerRemoved(account); - } + function _removeSigner(address account) internal { + signers.remove(account); + emit SignerRemoved(account); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/Crowdsale.sol b/contracts/crowdsale/Crowdsale.sol index d896b0bb1..d4fb398f6 100644 --- a/contracts/crowdsale/Crowdsale.sol +++ b/contracts/crowdsale/Crowdsale.sol @@ -19,223 +19,223 @@ import "../token/ERC20/SafeERC20.sol"; * behavior. */ contract Crowdsale is Initializable { - using SafeMath for uint256; - using SafeERC20 for IERC20; + using SafeMath for uint256; + using SafeERC20 for IERC20; - // The token being sold - IERC20 private _token; + // The token being sold + IERC20 private _token; - // Address where funds are collected - address private _wallet; + // Address where funds are collected + address private _wallet; - // How many token units a buyer gets per wei. - // The rate is the conversion between wei and the smallest and indivisible token unit. - // So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK - // 1 wei will give you 1 unit, or 0.001 TOK. - uint256 private _rate; + // How many token units a buyer gets per wei. + // The rate is the conversion between wei and the smallest and indivisible token unit. + // So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK + // 1 wei will give you 1 unit, or 0.001 TOK. + uint256 private _rate; - // Amount of wei raised - uint256 private _weiRaised; + // Amount of wei raised + uint256 private _weiRaised; - /** - * Event for token purchase logging - * @param purchaser who paid for the tokens - * @param beneficiary who got the tokens - * @param value weis paid for purchase - * @param amount amount of tokens purchased - */ - event TokensPurchased( - address indexed purchaser, - address indexed beneficiary, - uint256 value, - uint256 amount - ); - - /** - * @param rate Number of token units a buyer gets per wei - * @dev The rate is the conversion between wei and the smallest and indivisible - * token unit. So, if you are using a rate of 1 with a ERC20Detailed token - * with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK. - * @param wallet Address where collected funds will be forwarded to - * @param token Address of the token being sold - */ - function initialize(uint256 rate, address wallet, IERC20 token) public initializer { - require(rate > 0); - require(wallet != address(0)); - require(token != address(0)); - - _rate = rate; - _wallet = wallet; - _token = token; - } - - // ----------------------------------------- - // Crowdsale external interface - // ----------------------------------------- - - /** - * @dev fallback function ***DO NOT OVERRIDE*** - */ - function () external payable { - buyTokens(msg.sender); - } - - /** - * @return the token being sold. - */ - function token() public view returns(IERC20) { - return _token; - } - - /** - * @return the address where funds are collected. - */ - function wallet() public view returns(address) { - return _wallet; - } - - /** - * @return the number of token units a buyer gets per wei. - */ - function rate() public view returns(uint256) { - return _rate; - } - - /** - * @return the mount 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 - */ - function buyTokens(address beneficiary) public payable { - - uint256 weiAmount = msg.value; - _preValidatePurchase(beneficiary, weiAmount); - - // calculate token amount to be created - uint256 tokens = _getTokenAmount(weiAmount); - - // update state - _weiRaised = _weiRaised.add(weiAmount); - - _processPurchase(beneficiary, tokens); - emit TokensPurchased( - msg.sender, - beneficiary, - weiAmount, - tokens + /** + * Event for token purchase logging + * @param purchaser who paid for the tokens + * @param beneficiary who got the tokens + * @param value weis paid for purchase + * @param amount amount of tokens purchased + */ + event TokensPurchased( + address indexed purchaser, + address indexed beneficiary, + uint256 value, + uint256 amount ); - _updatePurchasingState(beneficiary, weiAmount); + /** + * @param rate Number of token units a buyer gets per wei + * @dev The rate is the conversion between wei and the smallest and indivisible + * token unit. So, if you are using a rate of 1 with a ERC20Detailed token + * with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK. + * @param wallet Address where collected funds will be forwarded to + * @param token Address of the token being sold + */ + function initialize(uint256 rate, address wallet, IERC20 token) public initializer { + require(rate > 0); + require(wallet != address(0)); + require(token != address(0)); - _forwardFunds(); - _postValidatePurchase(beneficiary, weiAmount); - } + _rate = rate; + _wallet = wallet; + _token = token; + } - // ----------------------------------------- - // Internal interface (extensible) - // ----------------------------------------- + // ----------------------------------------- + // Crowdsale external interface + // ----------------------------------------- - function _hasBeenInitialized() internal view returns (bool) { - return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0))); - } + /** + * @dev fallback function ***DO NOT OVERRIDE*** + */ + function () external payable { + buyTokens(msg.sender); + } - /** - * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations. - * Example from CappedCrowdsale.sol's _preValidatePurchase method: - * super._preValidatePurchase(beneficiary, weiAmount); - * require(weiRaised().add(weiAmount) <= cap); - * @param beneficiary Address performing the token purchase - * @param weiAmount Value in wei involved in the purchase - */ - function _preValidatePurchase( - address beneficiary, - uint256 weiAmount - ) - internal - { - require(beneficiary != address(0)); - require(weiAmount != 0); - } + /** + * @return the token being sold. + */ + function token() public view returns(IERC20) { + return _token; + } - /** - * @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met. - * @param beneficiary Address performing the token purchase - * @param weiAmount Value in wei involved in the purchase - */ - function _postValidatePurchase( - address beneficiary, - uint256 weiAmount - ) - internal - { - // optional override - } + /** + * @return the address where funds are collected. + */ + function wallet() public view returns(address) { + return _wallet; + } - /** - * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens. - * @param beneficiary Address performing the token purchase - * @param tokenAmount Number of tokens to be emitted - */ - function _deliverTokens( - address beneficiary, - uint256 tokenAmount - ) - internal - { - _token.safeTransfer(beneficiary, tokenAmount); - } + /** + * @return the number of token units a buyer gets per wei. + */ + function rate() public view returns(uint256) { + return _rate; + } - /** - * @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens. - * @param beneficiary Address receiving the tokens - * @param tokenAmount Number of tokens to be purchased - */ - function _processPurchase( - address beneficiary, - uint256 tokenAmount - ) - internal - { - _deliverTokens(beneficiary, tokenAmount); - } + /** + * @return the mount of wei raised. + */ + function weiRaised() public view returns (uint256) { + return _weiRaised; + } - /** - * @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.) - * @param beneficiary Address receiving the tokens - * @param weiAmount Value in wei involved in the purchase - */ - function _updatePurchasingState( - address beneficiary, - uint256 weiAmount - ) - internal - { - // optional override - } + /** + * @dev low level token purchase ***DO NOT OVERRIDE*** + * @param beneficiary Address performing the token purchase + */ + function buyTokens(address beneficiary) public payable { - /** - * @dev Override to extend the way in which ether is converted to tokens. - * @param weiAmount Value in wei to be converted into tokens - * @return Number of tokens that can be purchased with the specified _weiAmount - */ - function _getTokenAmount(uint256 weiAmount) - internal view returns (uint256) - { - return weiAmount.mul(_rate); - } + uint256 weiAmount = msg.value; + _preValidatePurchase(beneficiary, weiAmount); - /** - * @dev Determines how ETH is stored/forwarded on purchases. - */ - function _forwardFunds() internal { - _wallet.transfer(msg.value); - } + // calculate token amount to be created + uint256 tokens = _getTokenAmount(weiAmount); - uint256[50] private ______gap; + // update state + _weiRaised = _weiRaised.add(weiAmount); + + _processPurchase(beneficiary, tokens); + emit TokensPurchased( + msg.sender, + beneficiary, + weiAmount, + tokens + ); + + _updatePurchasingState(beneficiary, weiAmount); + + _forwardFunds(); + _postValidatePurchase(beneficiary, weiAmount); + } + + // ----------------------------------------- + // Internal interface (extensible) + // ----------------------------------------- + + function _hasBeenInitialized() internal view returns (bool) { + return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0))); + } + + /** + * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations. + * Example from CappedCrowdsale.sol's _preValidatePurchase method: + * super._preValidatePurchase(beneficiary, weiAmount); + * require(weiRaised().add(weiAmount) <= cap); + * @param beneficiary Address performing the token purchase + * @param weiAmount Value in wei involved in the purchase + */ + function _preValidatePurchase( + address beneficiary, + uint256 weiAmount + ) + internal + { + require(beneficiary != address(0)); + require(weiAmount != 0); + } + + /** + * @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met. + * @param beneficiary Address performing the token purchase + * @param weiAmount Value in wei involved in the purchase + */ + function _postValidatePurchase( + address beneficiary, + uint256 weiAmount + ) + internal + { + // optional override + } + + /** + * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens. + * @param beneficiary Address performing the token purchase + * @param tokenAmount Number of tokens to be emitted + */ + function _deliverTokens( + address beneficiary, + uint256 tokenAmount + ) + internal + { + _token.safeTransfer(beneficiary, tokenAmount); + } + + /** + * @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens. + * @param beneficiary Address receiving the tokens + * @param tokenAmount Number of tokens to be purchased + */ + function _processPurchase( + address beneficiary, + uint256 tokenAmount + ) + internal + { + _deliverTokens(beneficiary, tokenAmount); + } + + /** + * @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.) + * @param beneficiary Address receiving the tokens + * @param weiAmount Value in wei involved in the purchase + */ + function _updatePurchasingState( + address beneficiary, + uint256 weiAmount + ) + internal + { + // optional override + } + + /** + * @dev Override to extend the way in which ether is converted to tokens. + * @param weiAmount Value in wei to be converted into tokens + * @return Number of tokens that can be purchased with the specified _weiAmount + */ + function _getTokenAmount(uint256 weiAmount) + internal view returns (uint256) + { + return weiAmount.mul(_rate); + } + + /** + * @dev Determines how ETH is stored/forwarded on purchases. + */ + function _forwardFunds() internal { + _wallet.transfer(msg.value); + } + + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/distribution/FinalizableCrowdsale.sol b/contracts/crowdsale/distribution/FinalizableCrowdsale.sol index 6edf68cc1..549afe6fe 100644 --- a/contracts/crowdsale/distribution/FinalizableCrowdsale.sol +++ b/contracts/crowdsale/distribution/FinalizableCrowdsale.sol @@ -11,41 +11,41 @@ import "../validation/TimedCrowdsale.sol"; * can do extra work after finishing. */ contract FinalizableCrowdsale is Initializable, TimedCrowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - bool private _finalized = false; + bool private _finalized = false; - event CrowdsaleFinalized(); + event CrowdsaleFinalized(); - /** - * @return true if the crowdsale is finalized, false otherwise. - */ - function finalized() public view returns (bool) { - return _finalized; - } + /** + * @return true if the crowdsale is finalized, false otherwise. + */ + function finalized() public view returns (bool) { + return _finalized; + } - /** - * @dev Must be called after crowdsale ends, to do some extra finalization - * work. Calls the contract's finalization function. - */ - function finalize() public { - require(!_finalized); - require(hasClosed()); + /** + * @dev Must be called after crowdsale ends, to do some extra finalization + * work. Calls the contract's finalization function. + */ + function finalize() public { + require(!_finalized); + require(hasClosed()); - _finalization(); - emit CrowdsaleFinalized(); + _finalization(); + emit CrowdsaleFinalized(); - _finalized = true; - } + _finalized = true; + } - /** - * @dev Can be overridden to add finalization logic. The overriding function - * should call super._finalization() to ensure the chain of finalization is - * executed entirely. - */ - function _finalization() internal { - } + /** + * @dev Can be overridden to add finalization logic. The overriding function + * should call super._finalization() to ensure the chain of finalization is + * executed entirely. + */ + function _finalization() internal { + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol b/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol index 869d74378..1a8ceb270 100644 --- a/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol +++ b/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol @@ -11,43 +11,43 @@ import "../../math/SafeMath.sol"; * @dev Crowdsale that locks tokens from withdrawal until it ends. */ contract PostDeliveryCrowdsale is Initializable, TimedCrowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - mapping(address => uint256) private _balances; + mapping(address => uint256) private _balances; - /** - * @dev Withdraw tokens only after crowdsale ends. - * @param beneficiary Whose tokens will be withdrawn. - */ - function withdrawTokens(address beneficiary) public { - require(hasClosed()); - uint256 amount = _balances[beneficiary]; - require(amount > 0); - _balances[beneficiary] = 0; - _deliverTokens(beneficiary, amount); - } + /** + * @dev Withdraw tokens only after crowdsale ends. + * @param beneficiary Whose tokens will be withdrawn. + */ + function withdrawTokens(address beneficiary) public { + require(hasClosed()); + uint256 amount = _balances[beneficiary]; + require(amount > 0); + _balances[beneficiary] = 0; + _deliverTokens(beneficiary, amount); + } - /** - * @return the balance of an account. - */ - function balanceOf(address account) public view returns(uint256) { - return _balances[account]; - } + /** + * @return the balance of an account. + */ + function balanceOf(address account) public view returns(uint256) { + return _balances[account]; + } - /** - * @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 - { - _balances[beneficiary] = _balances[beneficiary].add(tokenAmount); - } + /** + * @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 + { + _balances[beneficiary] = _balances[beneficiary].add(tokenAmount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/distribution/RefundableCrowdsale.sol b/contracts/crowdsale/distribution/RefundableCrowdsale.sol index 5ab88aab7..680edd79e 100644 --- a/contracts/crowdsale/distribution/RefundableCrowdsale.sol +++ b/contracts/crowdsale/distribution/RefundableCrowdsale.sol @@ -13,80 +13,80 @@ import "../../payment/RefundEscrow.sol"; * the possibility of users getting a refund if goal is not met. */ contract RefundableCrowdsale is Initializable, FinalizableCrowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - // minimum amount of funds to be raised in weis - uint256 private _goal; + // minimum amount of funds to be raised in weis + uint256 private _goal; - // refund escrow used to hold funds while crowdsale is running - RefundEscrow private _escrow; + // refund escrow used to hold funds while crowdsale is running + RefundEscrow private _escrow; - /** - * @dev Constructor, creates RefundEscrow. - * @param goal Funding goal - */ - function initialize(uint256 goal) public initializer { - // FinalizableCrowdsale depends on TimedCrowdsale - assert(TimedCrowdsale._hasBeenInitialized()); + /** + * @dev Constructor, creates RefundEscrow. + * @param goal Funding goal + */ + function initialize(uint256 goal) public initializer { + // FinalizableCrowdsale depends on TimedCrowdsale + assert(TimedCrowdsale._hasBeenInitialized()); - require(goal > 0); + require(goal > 0); - // conditional added to make initializer idempotent in case of diamond inheritance - if (address(_escrow) == address(0)) { - _escrow = new RefundEscrow(); - _escrow.initialize(wallet(), address(this)); + // conditional added to make initializer idempotent in case of diamond inheritance + if (address(_escrow) == address(0)) { + _escrow = new RefundEscrow(); + _escrow.initialize(wallet(), address(this)); + } + + _goal = goal; } - _goal = goal; - } - - /** - * @return minimum amount of funds to be raised in wei. - */ - function goal() public view returns(uint256) { - return _goal; - } - - /** - * @dev Investors can claim refunds here if crowdsale is unsuccessful - * @param beneficiary Whose refund will be claimed. - */ - function claimRefund(address beneficiary) public { - require(finalized()); - require(!goalReached()); - - _escrow.withdraw(beneficiary); - } - - /** - * @dev Checks whether funding goal was reached. - * @return Whether funding goal was reached - */ - function goalReached() public view returns (bool) { - return weiRaised() >= _goal; - } - - /** - * @dev escrow finalization task, called when finalize() is called - */ - function _finalization() internal { - if (goalReached()) { - _escrow.close(); - _escrow.beneficiaryWithdraw(); - } else { - _escrow.enableRefunds(); + /** + * @return minimum amount of funds to be raised in wei. + */ + function goal() public view returns(uint256) { + return _goal; } - super._finalization(); - } + /** + * @dev Investors can claim refunds here if crowdsale is unsuccessful + * @param beneficiary Whose refund will be claimed. + */ + function claimRefund(address beneficiary) public { + require(finalized()); + require(!goalReached()); - /** - * @dev Overrides Crowdsale fund forwarding, sending funds to escrow. - */ - function _forwardFunds() internal { - _escrow.deposit.value(msg.value)(msg.sender); - } + _escrow.withdraw(beneficiary); + } + + /** + * @dev Checks whether funding goal was reached. + * @return Whether funding goal was reached + */ + function goalReached() public view returns (bool) { + return weiRaised() >= _goal; + } + + /** + * @dev escrow finalization task, called when finalize() is called + */ + function _finalization() internal { + if (goalReached()) { + _escrow.close(); + _escrow.beneficiaryWithdraw(); + } else { + _escrow.enableRefunds(); + } + + super._finalization(); + } + + /** + * @dev Overrides Crowdsale fund forwarding, sending funds to escrow. + */ + function _forwardFunds() internal { + _escrow.deposit.value(msg.value)(msg.sender); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/emission/AllowanceCrowdsale.sol b/contracts/crowdsale/emission/AllowanceCrowdsale.sol index b0f8d26e1..0e062e49e 100644 --- a/contracts/crowdsale/emission/AllowanceCrowdsale.sol +++ b/contracts/crowdsale/emission/AllowanceCrowdsale.sol @@ -12,50 +12,50 @@ import "../../math/SafeMath.sol"; * @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale. */ contract AllowanceCrowdsale is Initializable, Crowdsale { - using SafeMath for uint256; - using SafeERC20 for IERC20; + using SafeMath for uint256; + using SafeERC20 for IERC20; - address private _tokenWallet; + address private _tokenWallet; - /** - * @dev Constructor, takes token wallet address. - * @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale - */ - function initialize(address tokenWallet) public initializer { - assert(Crowdsale._hasBeenInitialized()); + /** + * @dev Constructor, takes token wallet address. + * @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale + */ + function initialize(address tokenWallet) public initializer { + assert(Crowdsale._hasBeenInitialized()); - require(tokenWallet != address(0)); - _tokenWallet = tokenWallet; - } + require(tokenWallet != address(0)); + _tokenWallet = tokenWallet; + } - /** - * @return the address of the wallet that will hold the tokens. - */ - function tokenWallet() public view returns(address) { - return _tokenWallet; - } + /** + * @return the address of the wallet that will hold the tokens. + */ + function tokenWallet() public view returns(address) { + return _tokenWallet; + } - /** - * @dev Checks the amount of tokens left in the allowance. - * @return Amount of tokens left in the allowance - */ - function remainingTokens() public view returns (uint256) { - return token().allowance(_tokenWallet, this); - } + /** + * @dev Checks the amount of tokens left in the allowance. + * @return Amount of tokens left in the allowance + */ + function remainingTokens() public view returns (uint256) { + 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 _deliverTokens( - address beneficiary, - uint256 tokenAmount - ) - internal - { - token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount); - } + /** + * @dev Overrides parent behavior by transferring tokens from wallet. + * @param beneficiary Token purchaser + * @param tokenAmount Amount of tokens purchased + */ + function _deliverTokens( + address beneficiary, + uint256 tokenAmount + ) + internal + { + token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/emission/MintedCrowdsale.sol b/contracts/crowdsale/emission/MintedCrowdsale.sol index 52b41ae85..58b01d2f8 100644 --- a/contracts/crowdsale/emission/MintedCrowdsale.sol +++ b/contracts/crowdsale/emission/MintedCrowdsale.sol @@ -12,21 +12,21 @@ import "../../token/ERC20/ERC20Mintable.sol"; */ contract MintedCrowdsale is Initializable, Crowdsale { - /** - * @dev Overrides delivery by minting tokens upon purchase. - * @param beneficiary Token purchaser - * @param tokenAmount Number of tokens to be minted - */ - function _deliverTokens( - address beneficiary, - uint256 tokenAmount - ) - internal - { - // Potentially dangerous assumption about the type of the token. - require( - ERC20Mintable(address(token())).mint(beneficiary, tokenAmount)); - } + /** + * @dev Overrides delivery by minting tokens upon purchase. + * @param beneficiary Token purchaser + * @param tokenAmount Number of tokens to be minted + */ + function _deliverTokens( + address beneficiary, + uint256 tokenAmount + ) + internal + { + // Potentially dangerous assumption about the type of the token. + require( + ERC20Mintable(address(token())).mint(beneficiary, tokenAmount)); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol index b00aae8d2..3a9dddcbc 100644 --- a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol +++ b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol @@ -12,64 +12,64 @@ import "../../math/SafeMath.sol"; * the amount of tokens per wei contributed. Thus, the initial rate must be greater than the final rate. */ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - uint256 private _initialRate; - uint256 private _finalRate; + uint256 private _initialRate; + uint256 private _finalRate; - /** - * @dev Constructor, takes initial and final rates of tokens received per wei contributed. - * @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 - */ - function initialize(uint256 initialRate, uint256 finalRate) public initializer { - assert(TimedCrowdsale._hasBeenInitialized()); + /** + * @dev Constructor, takes initial and final rates of tokens received per wei contributed. + * @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 + */ + function initialize(uint256 initialRate, uint256 finalRate) public initializer { + assert(TimedCrowdsale._hasBeenInitialized()); - require(finalRate > 0); - require(initialRate >= finalRate); - _initialRate = initialRate; - _finalRate = finalRate; - } + require(finalRate > 0); + require(initialRate >= finalRate); + _initialRate = initialRate; + _finalRate = finalRate; + } - /** - * @return the initial rate of the crowdsale. - */ - function initialRate() public view returns(uint256) { - return _initialRate; - } + /** + * @return the initial rate of the crowdsale. + */ + function initialRate() public view returns(uint256) { + return _initialRate; + } - /** - * @return the final rate of the crowdsale. - */ - function finalRate() public view returns (uint256) { - return _finalRate; - } + /** + * @return the final rate of the crowdsale. + */ + function finalRate() public view returns (uint256) { + return _finalRate; + } - /** - * @dev Returns the rate of tokens per wei 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) { - // solium-disable-next-line security/no-block-members - uint256 elapsedTime = block.timestamp.sub(openingTime()); - uint256 timeRange = closingTime().sub(openingTime()); - uint256 rateRange = _initialRate.sub(_finalRate); - return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); - } + /** + * @dev Returns the rate of tokens per wei 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) { + // solium-disable-next-line security/no-block-members + uint256 elapsedTime = block.timestamp.sub(openingTime()); + uint256 timeRange = closingTime().sub(openingTime()); + uint256 rateRange = _initialRate.sub(_finalRate); + return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); + } - /** - * @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); - } + /** + * @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); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/validation/CappedCrowdsale.sol b/contracts/crowdsale/validation/CappedCrowdsale.sol index 8ef742b32..09dcaf595 100644 --- a/contracts/crowdsale/validation/CappedCrowdsale.sol +++ b/contracts/crowdsale/validation/CappedCrowdsale.sol @@ -10,51 +10,51 @@ import "../Crowdsale.sol"; * @dev Crowdsale with a limit for total contributions. */ contract CappedCrowdsale is Initializable, Crowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - uint256 private _cap; + uint256 private _cap; - /** - * @dev Constructor, takes maximum amount of wei accepted in the crowdsale. - * @param cap Max amount of wei to be contributed - */ - function initialize(uint256 cap) public initializer { - assert(Crowdsale._hasBeenInitialized()); + /** + * @dev Constructor, takes maximum amount of wei accepted in the crowdsale. + * @param cap Max amount of wei to be contributed + */ + function initialize(uint256 cap) public initializer { + assert(Crowdsale._hasBeenInitialized()); - require(cap > 0); - _cap = cap; - } + require(cap > 0); + _cap = cap; + } - /** - * @return the cap of the crowdsale. - */ - function cap() public view returns(uint256) { - return _cap; - } + /** + * @return the cap of the crowdsale. + */ + function cap() public view returns(uint256) { + return _cap; + } - /** - * @dev Checks whether the cap has been reached. - * @return Whether the cap was reached - */ - function capReached() public view returns (bool) { - return weiRaised() >= _cap; - } + /** + * @dev Checks whether the cap has been reached. + * @return Whether the cap was reached + */ + function capReached() public view returns (bool) { + return weiRaised() >= _cap; + } - /** - * @dev Extend parent behavior requiring purchase to respect the funding cap. - * @param beneficiary Token purchaser - * @param weiAmount Amount of wei contributed - */ - function _preValidatePurchase( - address beneficiary, - uint256 weiAmount - ) - internal - { - super._preValidatePurchase(beneficiary, weiAmount); - require(weiRaised().add(weiAmount) <= _cap); - } + /** + * @dev Extend parent behavior requiring purchase to respect the funding cap. + * @param beneficiary Token purchaser + * @param weiAmount Amount of wei contributed + */ + function _preValidatePurchase( + address beneficiary, + uint256 weiAmount + ) + internal + { + super._preValidatePurchase(beneficiary, weiAmount); + require(weiRaised().add(weiAmount) <= _cap); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol b/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol index 337a36da9..255375eb3 100644 --- a/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol +++ b/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol @@ -11,78 +11,78 @@ import "../../access/roles/CapperRole.sol"; * @dev Crowdsale with per-beneficiary caps. */ contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole { - using SafeMath for uint256; + using SafeMath for uint256; - mapping(address => uint256) private _contributions; - mapping(address => uint256) private _caps; + mapping(address => uint256) private _contributions; + mapping(address => uint256) private _caps; - function initialize(address sender) public initializer { - assert(Crowdsale._hasBeenInitialized()); + function initialize(address sender) public initializer { + assert(Crowdsale._hasBeenInitialized()); - CapperRole.initialize(sender); - } + CapperRole.initialize(sender); + } - /** - * @dev Sets a specific beneficiary's maximum contribution. - * @param beneficiary Address to be capped - * @param cap Wei limit for individual contribution - */ - function setCap(address beneficiary, uint256 cap) external onlyCapper { - _caps[beneficiary] = cap; - } + /** + * @dev Sets a specific beneficiary's maximum contribution. + * @param beneficiary Address to be capped + * @param cap Wei limit for individual contribution + */ + function setCap(address beneficiary, uint256 cap) external onlyCapper { + _caps[beneficiary] = cap; + } - /** - * @dev Returns the cap of a specific beneficiary. - * @param beneficiary Address whose cap is to be checked - * @return Current cap for individual beneficiary - */ - function getCap(address beneficiary) public view returns (uint256) { - return _caps[beneficiary]; - } + /** + * @dev Returns the cap of a specific beneficiary. + * @param beneficiary Address whose cap is to be checked + * @return Current cap for individual beneficiary + */ + function getCap(address beneficiary) public view returns (uint256) { + return _caps[beneficiary]; + } - /** - * @dev Returns the amount contributed so far by a specific beneficiary. - * @param beneficiary Address of contributor - * @return Beneficiary contribution so far - */ - function getContribution(address beneficiary) - public view returns (uint256) - { - return _contributions[beneficiary]; - } + /** + * @dev Returns the amount contributed so far by a specific beneficiary. + * @param beneficiary Address of contributor + * @return Beneficiary contribution so far + */ + function getContribution(address beneficiary) + public view returns (uint256) + { + return _contributions[beneficiary]; + } - /** - * @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap. - * @param beneficiary Token purchaser - * @param weiAmount Amount of wei contributed - */ - function _preValidatePurchase( - address beneficiary, - uint256 weiAmount - ) - internal - { - super._preValidatePurchase(beneficiary, weiAmount); - require( - _contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]); - } + /** + * @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap. + * @param beneficiary Token purchaser + * @param weiAmount Amount of wei contributed + */ + function _preValidatePurchase( + address beneficiary, + uint256 weiAmount + ) + internal + { + super._preValidatePurchase(beneficiary, weiAmount); + require( + _contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]); + } - /** - * @dev Extend parent behavior to update beneficiary contributions - * @param beneficiary Token purchaser - * @param weiAmount Amount of wei contributed - */ - function _updatePurchasingState( - address beneficiary, - uint256 weiAmount - ) - internal - { - super._updatePurchasingState(beneficiary, weiAmount); - _contributions[beneficiary] = _contributions[beneficiary].add( - weiAmount); - } + /** + * @dev Extend parent behavior to update beneficiary contributions + * @param beneficiary Token purchaser + * @param weiAmount Amount of wei contributed + */ + function _updatePurchasingState( + address beneficiary, + uint256 weiAmount + ) + internal + { + super._updatePurchasingState(beneficiary, weiAmount); + _contributions[beneficiary] = _contributions[beneficiary].add( + weiAmount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/crowdsale/validation/TimedCrowdsale.sol b/contracts/crowdsale/validation/TimedCrowdsale.sol index 4bbbb8689..9356b054c 100644 --- a/contracts/crowdsale/validation/TimedCrowdsale.sol +++ b/contracts/crowdsale/validation/TimedCrowdsale.sol @@ -10,85 +10,85 @@ import "../Crowdsale.sol"; * @dev Crowdsale accepting contributions only within a time frame. */ contract TimedCrowdsale is Initializable, Crowdsale { - using SafeMath for uint256; + using SafeMath for uint256; - uint256 private _openingTime; - uint256 private _closingTime; + uint256 private _openingTime; + uint256 private _closingTime; - /** - * @dev Reverts if not in crowdsale time range. - */ - modifier onlyWhileOpen { - require(isOpen()); - _; - } + /** + * @dev Reverts if not in crowdsale time range. + */ + modifier onlyWhileOpen { + require(isOpen()); + _; + } - /** - * @dev Constructor, takes crowdsale opening and closing times. - * @param openingTime Crowdsale opening time - * @param closingTime Crowdsale closing time - */ - function initialize(uint256 openingTime, uint256 closingTime) public initializer { - assert(Crowdsale._hasBeenInitialized()); + /** + * @dev Constructor, takes crowdsale opening and closing times. + * @param openingTime Crowdsale opening time + * @param closingTime Crowdsale closing time + */ + function initialize(uint256 openingTime, uint256 closingTime) public initializer { + assert(Crowdsale._hasBeenInitialized()); - // solium-disable-next-line security/no-block-members - require(openingTime >= block.timestamp); - require(closingTime >= openingTime); + // solium-disable-next-line security/no-block-members + require(openingTime >= block.timestamp); + require(closingTime >= openingTime); - _openingTime = openingTime; - _closingTime = closingTime; - } + _openingTime = openingTime; + _closingTime = closingTime; + } - /** - * @return the crowdsale opening time. - */ - function openingTime() public view returns(uint256) { - return _openingTime; - } + /** + * @return the crowdsale opening time. + */ + function openingTime() public view returns(uint256) { + return _openingTime; + } - /** - * @return the crowdsale closing time. - */ - function closingTime() public view returns(uint256) { - return _closingTime; - } + /** + * @return the crowdsale closing time. + */ + function closingTime() public view returns(uint256) { + return _closingTime; + } - /** - * @return true if the crowdsale is open, false otherwise. - */ - function isOpen() public view returns (bool) { - // solium-disable-next-line security/no-block-members - return block.timestamp >= _openingTime && block.timestamp <= _closingTime; - } + /** + * @return true if the crowdsale is open, false otherwise. + */ + function isOpen() public view returns (bool) { + // solium-disable-next-line security/no-block-members + return block.timestamp >= _openingTime && block.timestamp <= _closingTime; + } - /** - * @dev Checks whether the period in which the crowdsale is open has already elapsed. - * @return Whether crowdsale period has elapsed - */ - function hasClosed() public view returns (bool) { - // solium-disable-next-line security/no-block-members - return block.timestamp > _closingTime; - } + /** + * @dev Checks whether the period in which the crowdsale is open has already elapsed. + * @return Whether crowdsale period has elapsed + */ + function hasClosed() public view returns (bool) { + // solium-disable-next-line security/no-block-members + return block.timestamp > _closingTime; + } - function _hasBeenInitialized() internal view returns (bool) { - return ((_openingTime > 0) && (_closingTime > 0)); - } + function _hasBeenInitialized() internal view returns (bool) { + return ((_openingTime > 0) && (_closingTime > 0)); + } - /** - * @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 - onlyWhileOpen - { - super._preValidatePurchase(beneficiary, weiAmount); - } + /** + * @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 + onlyWhileOpen + { + super._preValidatePurchase(beneficiary, weiAmount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/cryptography/ECDSA.sol b/contracts/cryptography/ECDSA.sol index 61d19f20c..b3f6d8de0 100644 --- a/contracts/cryptography/ECDSA.sol +++ b/contracts/cryptography/ECDSA.sol @@ -10,63 +10,63 @@ pragma solidity ^0.4.24; library ECDSA { - /** - * @dev Recover signer address from a message by using their signature - * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. - * @param signature bytes signature, the signature is generated using web3.eth.sign() - */ - function recover(bytes32 hash, bytes signature) - internal - pure - returns (address) - { - bytes32 r; - bytes32 s; - uint8 v; + /** + * @dev Recover signer address from a message by using their signature + * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. + * @param signature bytes signature, the signature is generated using web3.eth.sign() + */ + function recover(bytes32 hash, bytes signature) + internal + pure + returns (address) + { + bytes32 r; + bytes32 s; + uint8 v; - // Check the signature length - if (signature.length != 65) { - return (address(0)); + // Check the signature length + if (signature.length != 65) { + return (address(0)); + } + + // Divide the signature in r, s and v variables + // ecrecover takes the signature parameters, and the only way to get them + // currently is to use assembly. + // solium-disable-next-line security/no-inline-assembly + assembly { + r := mload(add(signature, 32)) + s := mload(add(signature, 64)) + v := byte(0, mload(add(signature, 96))) + } + + // Version of signature should be 27 or 28, but 0 and 1 are also possible versions + if (v < 27) { + v += 27; + } + + // If the version is correct return the signer address + if (v != 27 && v != 28) { + return (address(0)); + } else { + // solium-disable-next-line arg-overflow + return ecrecover(hash, v, r, s); + } } - // Divide the signature in r, s and v variables - // ecrecover takes the signature parameters, and the only way to get them - // currently is to use assembly. - // solium-disable-next-line security/no-inline-assembly - assembly { - r := mload(add(signature, 32)) - s := mload(add(signature, 64)) - v := byte(0, mload(add(signature, 96))) + /** + * toEthSignedMessageHash + * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:" + * and hash the result + */ + function toEthSignedMessageHash(bytes32 hash) + internal + pure + returns (bytes32) + { + // 32 is the length in bytes of hash, + // enforced by the type signature above + return keccak256( + abi.encodePacked("\x19Ethereum Signed Message:\n32", hash) + ); } - - // Version of signature should be 27 or 28, but 0 and 1 are also possible versions - if (v < 27) { - v += 27; - } - - // If the version is correct return the signer address - if (v != 27 && v != 28) { - return (address(0)); - } else { - // solium-disable-next-line arg-overflow - return ecrecover(hash, v, r, s); - } - } - - /** - * toEthSignedMessageHash - * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:" - * and hash the result - */ - function toEthSignedMessageHash(bytes32 hash) - internal - pure - returns (bytes32) - { - // 32 is the length in bytes of hash, - // enforced by the type signature above - return keccak256( - abi.encodePacked("\x19Ethereum Signed Message:\n32", hash) - ); - } } diff --git a/contracts/cryptography/MerkleProof.sol b/contracts/cryptography/MerkleProof.sol index d490e7ff5..210b78a82 100644 --- a/contracts/cryptography/MerkleProof.sol +++ b/contracts/cryptography/MerkleProof.sol @@ -7,37 +7,37 @@ pragma solidity ^0.4.24; * https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol */ library MerkleProof { - /** - * @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves - * and each pair of pre-images are sorted. - * @param proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree - * @param root Merkle root - * @param leaf Leaf of Merkle tree - */ - function verify( - bytes32[] proof, - bytes32 root, - bytes32 leaf - ) - internal - pure - returns (bool) - { - bytes32 computedHash = leaf; + /** + * @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves + * and each pair of pre-images are sorted. + * @param proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree + * @param root Merkle root + * @param leaf Leaf of Merkle tree + */ + function verify( + bytes32[] proof, + bytes32 root, + bytes32 leaf + ) + internal + pure + returns (bool) + { + bytes32 computedHash = leaf; - for (uint256 i = 0; i < proof.length; i++) { - bytes32 proofElement = proof[i]; + for (uint256 i = 0; i < proof.length; i++) { + bytes32 proofElement = proof[i]; - if (computedHash < proofElement) { - // Hash(current computed hash + current element of the proof) - computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); - } else { - // Hash(current element of the proof + current computed hash) - computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); - } + if (computedHash < proofElement) { + // Hash(current computed hash + current element of the proof) + computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); + } else { + // Hash(current element of the proof + current computed hash) + computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); + } + } + + // Check if the computed hash (root) is equal to the provided root + return computedHash == root; } - - // Check if the computed hash (root) is equal to the provided root - return computedHash == root; - } } diff --git a/contracts/drafts/Counter.sol b/contracts/drafts/Counter.sol index b47d9b824..e5bfc7e09 100644 --- a/contracts/drafts/Counter.sol +++ b/contracts/drafts/Counter.sol @@ -15,15 +15,15 @@ pragma solidity ^0.4.24; */ library Counter { - struct Counter { - uint256 current; // default: 0 - } + struct Counter { + uint256 current; // default: 0 + } - function next(Counter storage index) - internal - returns (uint256) - { - index.current += 1; - return index.current; - } + function next(Counter storage index) + internal + returns (uint256) + { + index.current += 1; + return index.current; + } } diff --git a/contracts/drafts/ERC1046/TokenMetadata.sol b/contracts/drafts/ERC1046/TokenMetadata.sol index 5807bfef6..ec0ae3a46 100644 --- a/contracts/drafts/ERC1046/TokenMetadata.sol +++ b/contracts/drafts/ERC1046/TokenMetadata.sol @@ -11,25 +11,25 @@ import "../../token/ERC20/IERC20.sol"; * @dev TODO - update https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/IERC721.sol#L17 when 1046 is finalized */ contract ERC20TokenMetadata is Initializable, IERC20 { - function tokenURI() external view returns (string); + function tokenURI() external view returns (string); - uint256[50] private ______gap; + uint256[50] private ______gap; } contract ERC20WithMetadata is Initializable, ERC20TokenMetadata { - string private _tokenURI = ""; + string private _tokenURI = ""; - function initialize(string tokenURI) - public - initializer - { - _tokenURI = tokenURI; - } + function initialize(string tokenURI) + public + initializer + { + _tokenURI = tokenURI; + } - function tokenURI() external view returns (string) { - return _tokenURI; - } + function tokenURI() external view returns (string) { + return _tokenURI; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/drafts/ERC20Migrator.sol b/contracts/drafts/ERC20Migrator.sol index a89f7db0d..03cfcdacd 100644 --- a/contracts/drafts/ERC20Migrator.sol +++ b/contracts/drafts/ERC20Migrator.sol @@ -34,71 +34,71 @@ import "../math/Math.sol"; * ``` */ contract ERC20Migrator is Initializable { - using SafeERC20 for IERC20; + using SafeERC20 for IERC20; - /// Address of the old token contract - IERC20 private _legacyToken; + /// Address of the old token contract + IERC20 private _legacyToken; - /// Address of the new token contract - ERC20Mintable private _newToken; + /// Address of the new token contract + ERC20Mintable private _newToken; - /** - * @param legacyToken address of the old token contract - */ - function initialize(IERC20 legacyToken) public initializer { - require(legacyToken != address(0)); - _legacyToken = legacyToken; - } + /** + * @param legacyToken address of the old token contract + */ + function initialize(IERC20 legacyToken) public initializer { + require(legacyToken != address(0)); + _legacyToken = legacyToken; + } - /** - * @dev Returns the legacy token that is being migrated. - */ - function legacyToken() public view returns (IERC20) { - return _legacyToken; - } + /** + * @dev Returns the legacy token that is being migrated. + */ + function legacyToken() public view returns (IERC20) { + return _legacyToken; + } - /** - * @dev Returns the new token to which we are migrating. - */ - function newToken() public view returns (IERC20) { - return _newToken; - } + /** + * @dev Returns the new token to which we are migrating. + */ + function newToken() public view returns (IERC20) { + return _newToken; + } - /** - * @dev Begins the migration by setting which is the new token that will be - * minted. This contract must be a minter for the new token. - * @param newToken the token that will be minted - */ - function beginMigration(ERC20Mintable newToken) public { - require(_newToken == address(0)); - require(newToken != address(0)); - require(newToken.isMinter(this)); + /** + * @dev Begins the migration by setting which is the new token that will be + * minted. This contract must be a minter for the new token. + * @param newToken the token that will be minted + */ + function beginMigration(ERC20Mintable newToken) public { + require(_newToken == address(0)); + require(newToken != address(0)); + require(newToken.isMinter(this)); - _newToken = newToken; - } + _newToken = newToken; + } - /** - * @dev Transfers part of an account's balance in the old token to this - * contract, and mints the same amount of new tokens for that account. - * @param account whose tokens will be migrated - * @param amount amount of tokens to be migrated - */ - function migrate(address account, uint256 amount) public { - _legacyToken.safeTransferFrom(account, this, amount); - _newToken.mint(account, amount); - } + /** + * @dev Transfers part of an account's balance in the old token to this + * contract, and mints the same amount of new tokens for that account. + * @param account whose tokens will be migrated + * @param amount amount of tokens to be migrated + */ + function migrate(address account, uint256 amount) public { + _legacyToken.safeTransferFrom(account, this, amount); + _newToken.mint(account, amount); + } - /** - * @dev Transfers all of an account's allowed balance in the old token to - * this contract, and mints the same amount of new tokens for that account. - * @param account whose tokens will be migrated - */ - function migrateAll(address account) public { - uint256 balance = _legacyToken.balanceOf(account); - uint256 allowance = _legacyToken.allowance(account, this); - uint256 amount = Math.min(balance, allowance); - migrate(account, amount); - } + /** + * @dev Transfers all of an account's allowed balance in the old token to + * this contract, and mints the same amount of new tokens for that account. + * @param account whose tokens will be migrated + */ + function migrateAll(address account) public { + uint256 balance = _legacyToken.balanceOf(account); + uint256 allowance = _legacyToken.allowance(account, this); + uint256 amount = Math.min(balance, allowance); + migrate(account, amount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/drafts/SignatureBouncer.sol b/contracts/drafts/SignatureBouncer.sol index c280917da..0e5937bbd 100644 --- a/contracts/drafts/SignatureBouncer.sol +++ b/contracts/drafts/SignatureBouncer.sol @@ -30,116 +30,116 @@ import "../cryptography/ECDSA.sol"; * much more complex. See https://ethereum.stackexchange.com/a/50616 for more details. */ contract SignatureBouncer is Initializable, SignerRole { - using ECDSA for bytes32; + using ECDSA for bytes32; - // Function selectors are 4 bytes long, as documented in - // https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector - uint256 private constant _METHOD_ID_SIZE = 4; - // Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes - uint256 private constant _SIGNATURE_SIZE = 96; + // Function selectors are 4 bytes long, as documented in + // https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector + uint256 private constant _METHOD_ID_SIZE = 4; + // Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes + uint256 private constant _SIGNATURE_SIZE = 96; - /** - * @dev requires that a valid signature of a signer was provided - */ - modifier onlyValidSignature(bytes signature) - { - require(_isValidSignature(msg.sender, signature)); - _; - } - - /** - * @dev requires that a valid signature with a specifed method of a signer was provided - */ - modifier onlyValidSignatureAndMethod(bytes signature) - { - require(_isValidSignatureAndMethod(msg.sender, signature)); - _; - } - - /** - * @dev requires that a valid signature with a specifed method and params of a signer was provided - */ - modifier onlyValidSignatureAndData(bytes signature) - { - require(_isValidSignatureAndData(msg.sender, signature)); - _; - } - - function initialize(address sender) public initializer { - SignerRole.initialize(sender); - } - - /** - * @dev is the signature of `this + sender` from a signer? - * @return bool - */ - function _isValidSignature(address account, bytes signature) - internal - view - returns (bool) - { - return _isValidDataHash( - keccak256(abi.encodePacked(address(this), account)), - signature - ); - } - - /** - * @dev is the signature of `this + sender + methodId` from a signer? - * @return bool - */ - function _isValidSignatureAndMethod(address account, bytes signature) - internal - view - returns (bool) - { - bytes memory data = new bytes(_METHOD_ID_SIZE); - for (uint i = 0; i < data.length; i++) { - data[i] = msg.data[i]; + /** + * @dev requires that a valid signature of a signer was provided + */ + modifier onlyValidSignature(bytes signature) + { + require(_isValidSignature(msg.sender, signature)); + _; } - return _isValidDataHash( - keccak256(abi.encodePacked(address(this), account, data)), - signature - ); - } - /** - * @dev is the signature of `this + sender + methodId + params(s)` from a signer? - * @notice the signature parameter of the method being validated must be the "last" parameter - * @return bool - */ - function _isValidSignatureAndData(address account, bytes signature) - internal - view - returns (bool) - { - require(msg.data.length > _SIGNATURE_SIZE); - bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE); - for (uint i = 0; i < data.length; i++) { - data[i] = msg.data[i]; + /** + * @dev requires that a valid signature with a specifed method of a signer was provided + */ + modifier onlyValidSignatureAndMethod(bytes signature) + { + require(_isValidSignatureAndMethod(msg.sender, signature)); + _; } - return _isValidDataHash( - keccak256(abi.encodePacked(address(this), account, data)), - signature - ); - } - /** - * @dev internal function to convert a hash to an eth signed message - * and then recover the signature and check it against the signer role - * @return bool - */ - function _isValidDataHash(bytes32 hash, bytes signature) - internal - view - returns (bool) - { - address signer = hash - .toEthSignedMessageHash() - .recover(signature); + /** + * @dev requires that a valid signature with a specifed method and params of a signer was provided + */ + modifier onlyValidSignatureAndData(bytes signature) + { + require(_isValidSignatureAndData(msg.sender, signature)); + _; + } - return signer != address(0) && isSigner(signer); - } + function initialize(address sender) public initializer { + SignerRole.initialize(sender); + } - uint256[50] private ______gap; + /** + * @dev is the signature of `this + sender` from a signer? + * @return bool + */ + function _isValidSignature(address account, bytes signature) + internal + view + returns (bool) + { + return _isValidDataHash( + keccak256(abi.encodePacked(address(this), account)), + signature + ); + } + + /** + * @dev is the signature of `this + sender + methodId` from a signer? + * @return bool + */ + function _isValidSignatureAndMethod(address account, bytes signature) + internal + view + returns (bool) + { + bytes memory data = new bytes(_METHOD_ID_SIZE); + for (uint i = 0; i < data.length; i++) { + data[i] = msg.data[i]; + } + return _isValidDataHash( + keccak256(abi.encodePacked(address(this), account, data)), + signature + ); + } + + /** + * @dev is the signature of `this + sender + methodId + params(s)` from a signer? + * @notice the signature parameter of the method being validated must be the "last" parameter + * @return bool + */ + function _isValidSignatureAndData(address account, bytes signature) + internal + view + returns (bool) + { + require(msg.data.length > _SIGNATURE_SIZE); + bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE); + for (uint i = 0; i < data.length; i++) { + data[i] = msg.data[i]; + } + return _isValidDataHash( + keccak256(abi.encodePacked(address(this), account, data)), + signature + ); + } + + /** + * @dev internal function to convert a hash to an eth signed message + * and then recover the signature and check it against the signer role + * @return bool + */ + function _isValidDataHash(bytes32 hash, bytes signature) + internal + view + returns (bool) + { + address signer = hash + .toEthSignedMessageHash() + .recover(signature); + + return signer != address(0) && isSigner(signer); + } + + uint256[50] private ______gap; } diff --git a/contracts/drafts/TokenVesting.sol b/contracts/drafts/TokenVesting.sol index fa3acedc2..bb86d5917 100644 --- a/contracts/drafts/TokenVesting.sol +++ b/contracts/drafts/TokenVesting.sol @@ -15,167 +15,167 @@ import "../math/SafeMath.sol"; * owner. */ contract TokenVesting is Initializable, Ownable { - using SafeMath for uint256; - using SafeERC20 for IERC20; + using SafeMath for uint256; + using SafeERC20 for IERC20; - event Released(uint256 amount); - event Revoked(); + event Released(uint256 amount); + event Revoked(); - // beneficiary of tokens after they are released - address private _beneficiary; + // beneficiary of tokens after they are released + address private _beneficiary; - uint256 private _cliff; - uint256 private _start; - uint256 private _duration; + uint256 private _cliff; + uint256 private _start; + uint256 private _duration; - bool private _revocable; + bool private _revocable; - mapping (address => uint256) private _released; - mapping (address => bool) private _revoked; + mapping (address => uint256) private _released; + mapping (address => bool) private _revoked; - /** - * @dev Creates a vesting contract that vests its balance of any ERC20 token to the - * beneficiary, gradually in a linear fashion until start + duration. By then all - * of the balance will have vested. - * @param beneficiary address of the beneficiary to whom vested tokens are transferred - * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest - * @param start the time (as Unix time) at which point vesting starts - * @param duration duration in seconds of the period in which the tokens will vest - * @param revocable whether the vesting is revocable or not - */ - function initialize( - address beneficiary, - uint256 start, - uint256 cliffDuration, - uint256 duration, - bool revocable, - address sender - ) - public - initializer - { - Ownable.initialize(sender); + /** + * @dev Creates a vesting contract that vests its balance of any ERC20 token to the + * beneficiary, gradually in a linear fashion until start + duration. By then all + * of the balance will have vested. + * @param beneficiary address of the beneficiary to whom vested tokens are transferred + * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest + * @param start the time (as Unix time) at which point vesting starts + * @param duration duration in seconds of the period in which the tokens will vest + * @param revocable whether the vesting is revocable or not + */ + function initialize( + address beneficiary, + uint256 start, + uint256 cliffDuration, + uint256 duration, + bool revocable, + address sender + ) + public + initializer + { + Ownable.initialize(sender); - require(beneficiary != address(0)); - require(cliffDuration <= duration); + require(beneficiary != address(0)); + require(cliffDuration <= duration); - _beneficiary = beneficiary; - _revocable = revocable; - _duration = duration; - _cliff = start.add(cliffDuration); - _start = start; - } - - /** - * @return the beneficiary of the tokens. - */ - function beneficiary() public view returns(address) { - return _beneficiary; - } - - /** - * @return the cliff time of the token vesting. - */ - function cliff() public view returns(uint256) { - return _cliff; - } - - /** - * @return the start time of the token vesting. - */ - function start() public view returns(uint256) { - return _start; - } - - /** - * @return the duration of the token vesting. - */ - function duration() public view returns(uint256) { - return _duration; - } - - /** - * @return true if the vesting is revocable. - */ - function revocable() public view returns(bool) { - return _revocable; - } - - /** - * @return the amount of the token released. - */ - function released(address token) public view returns(uint256) { - return _released[token]; - } - - /** - * @return true if the token is revoked. - */ - function revoked(address token) public view returns(bool) { - return _revoked[token]; - } - - /** - * @notice Transfers vested tokens to beneficiary. - * @param token ERC20 token which is being vested - */ - function release(IERC20 token) public { - uint256 unreleased = releasableAmount(token); - - require(unreleased > 0); - - _released[token] = _released[token].add(unreleased); - - token.safeTransfer(_beneficiary, unreleased); - - emit Released(unreleased); - } - - /** - * @notice Allows the owner to revoke the vesting. Tokens already vested - * remain in the contract, the rest are returned to the owner. - * @param token ERC20 token which is being vested - */ - function revoke(IERC20 token) public onlyOwner { - require(_revocable); - require(!_revoked[token]); - - uint256 balance = token.balanceOf(address(this)); - - uint256 unreleased = releasableAmount(token); - uint256 refund = balance.sub(unreleased); - - _revoked[token] = true; - - token.safeTransfer(owner(), refund); - - emit Revoked(); - } - - /** - * @dev Calculates the amount that has already vested but hasn't been released yet. - * @param token ERC20 token which is being vested - */ - function releasableAmount(IERC20 token) public view returns (uint256) { - return vestedAmount(token).sub(_released[token]); - } - - /** - * @dev Calculates the amount that has already vested. - * @param token ERC20 token which is being vested - */ - function vestedAmount(IERC20 token) public view returns (uint256) { - uint256 currentBalance = token.balanceOf(this); - uint256 totalBalance = currentBalance.add(_released[token]); - - if (block.timestamp < _cliff) { - return 0; - } else if (block.timestamp >= _start.add(_duration) || _revoked[token]) { - return totalBalance; - } else { - return totalBalance.mul(block.timestamp.sub(_start)).div(_duration); + _beneficiary = beneficiary; + _revocable = revocable; + _duration = duration; + _cliff = start.add(cliffDuration); + _start = start; } - } - uint256[50] private ______gap; + /** + * @return the beneficiary of the tokens. + */ + function beneficiary() public view returns(address) { + return _beneficiary; + } + + /** + * @return the cliff time of the token vesting. + */ + function cliff() public view returns(uint256) { + return _cliff; + } + + /** + * @return the start time of the token vesting. + */ + function start() public view returns(uint256) { + return _start; + } + + /** + * @return the duration of the token vesting. + */ + function duration() public view returns(uint256) { + return _duration; + } + + /** + * @return true if the vesting is revocable. + */ + function revocable() public view returns(bool) { + return _revocable; + } + + /** + * @return the amount of the token released. + */ + function released(address token) public view returns(uint256) { + return _released[token]; + } + + /** + * @return true if the token is revoked. + */ + function revoked(address token) public view returns(bool) { + return _revoked[token]; + } + + /** + * @notice Transfers vested tokens to beneficiary. + * @param token ERC20 token which is being vested + */ + function release(IERC20 token) public { + uint256 unreleased = releasableAmount(token); + + require(unreleased > 0); + + _released[token] = _released[token].add(unreleased); + + token.safeTransfer(_beneficiary, unreleased); + + emit Released(unreleased); + } + + /** + * @notice Allows the owner to revoke the vesting. Tokens already vested + * remain in the contract, the rest are returned to the owner. + * @param token ERC20 token which is being vested + */ + function revoke(IERC20 token) public onlyOwner { + require(_revocable); + require(!_revoked[token]); + + uint256 balance = token.balanceOf(address(this)); + + uint256 unreleased = releasableAmount(token); + uint256 refund = balance.sub(unreleased); + + _revoked[token] = true; + + token.safeTransfer(owner(), refund); + + emit Revoked(); + } + + /** + * @dev Calculates the amount that has already vested but hasn't been released yet. + * @param token ERC20 token which is being vested + */ + function releasableAmount(IERC20 token) public view returns (uint256) { + return vestedAmount(token).sub(_released[token]); + } + + /** + * @dev Calculates the amount that has already vested. + * @param token ERC20 token which is being vested + */ + function vestedAmount(IERC20 token) public view returns (uint256) { + uint256 currentBalance = token.balanceOf(this); + uint256 totalBalance = currentBalance.add(_released[token]); + + if (block.timestamp < _cliff) { + return 0; + } else if (block.timestamp >= _start.add(_duration) || _revoked[token]) { + return totalBalance; + } else { + return totalBalance.mul(block.timestamp.sub(_start)).div(_duration); + } + } + + uint256[50] private ______gap; } diff --git a/contracts/examples/SampleCrowdsale.sol b/contracts/examples/SampleCrowdsale.sol index f865de9c5..cb51fcbab 100644 --- a/contracts/examples/SampleCrowdsale.sol +++ b/contracts/examples/SampleCrowdsale.sol @@ -14,19 +14,19 @@ import "../token/ERC20/ERC20Mintable.sol"; */ contract SampleCrowdsaleToken is Initializable, ERC20Mintable { - string public name; - string public symbol; - uint8 public decimals; + string public name; + string public symbol; + uint8 public decimals; - function initialize(address sender) public initializer { - ERC20Mintable.initialize(sender); + function initialize(address sender) public initializer { + ERC20Mintable.initialize(sender); - name = "Sample Crowdsale Token"; - symbol = "SCT"; - decimals = 18; - } + name = "Sample Crowdsale Token"; + symbol = "SCT"; + decimals = 18; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } @@ -48,27 +48,27 @@ contract SampleCrowdsaleToken is Initializable, ERC20Mintable { // solium-disable-next-line max-len contract SampleCrowdsale is Initializable, Crowdsale, CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale { - function initialize( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - uint256 cap, - ERC20Mintable token, - uint256 goal - ) - public - initializer - { - Crowdsale.initialize(rate, wallet, token); - CappedCrowdsale.initialize(cap); - TimedCrowdsale.initialize(openingTime, closingTime); - RefundableCrowdsale.initialize(goal); + function initialize( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + uint256 cap, + ERC20Mintable token, + uint256 goal + ) + public + initializer + { + Crowdsale.initialize(rate, wallet, token); + CappedCrowdsale.initialize(cap); + TimedCrowdsale.initialize(openingTime, closingTime); + RefundableCrowdsale.initialize(goal); - //As goal needs to be met for a successful crowdsale - //the value needs to less or equal than a cap which is limit for accepted funds - require(goal <= cap); - } + //As goal needs to be met for a successful crowdsale + //the value needs to less or equal than a cap which is limit for accepted funds + require(goal <= cap); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/examples/SimpleToken.sol b/contracts/examples/SimpleToken.sol index 8ca96ee82..c67472a4d 100644 --- a/contracts/examples/SimpleToken.sol +++ b/contracts/examples/SimpleToken.sol @@ -13,19 +13,19 @@ import "../token/ERC20/ERC20.sol"; */ contract SimpleToken is Initializable, ERC20 { - string public constant name = "SimpleToken"; - string public constant symbol = "SIM"; - uint8 public constant decimals = 18; + string public constant name = "SimpleToken"; + string public constant symbol = "SIM"; + uint8 public constant decimals = 18; - uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals)); + uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals)); - /** - * @dev Constructor that gives sender all of existing tokens. - */ - function initialize(address sender) public initializer { - _mint(sender, INITIAL_SUPPLY); - } + /** + * @dev Constructor that gives sender all of existing tokens. + */ + function initialize(address sender) public initializer { + _mint(sender, INITIAL_SUPPLY); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/examples/StandardToken.sol b/contracts/examples/StandardToken.sol index ff07ad145..e004a2562 100644 --- a/contracts/examples/StandardToken.sol +++ b/contracts/examples/StandardToken.sol @@ -11,32 +11,32 @@ import "../token/ERC20/ERC20Pausable.sol"; * */ contract StandardToken is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable { - function initialize( - string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, - address[] minters, address[] pausers - ) public initializer { - ERC20Detailed.initialize(name, symbol, decimals); + function initialize( + string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, + address[] minters, address[] pausers + ) public initializer { + ERC20Detailed.initialize(name, symbol, decimals); - // Mint the initial supply - if (initialSupply > 0) { // To allow passing a null address when not doing any initial supply - _mint(initialHolder, initialSupply); + // Mint the initial supply + if (initialSupply > 0) { // To allow passing a null address when not doing any initial supply + _mint(initialHolder, initialSupply); + } + + // Initialize the minter and pauser roles, and renounce them + ERC20Mintable.initialize(address(this)); + renounceMinter(); + + ERC20Pausable.initialize(address(this)); + renouncePauser(); + + // Add the requested minters and pausers (this can be done after renouncing since + // these are the internal calls) + for (uint256 i = 0; i < minters.length; ++i) { + _addMinter(minters[i]); + } + + for (i = 0; i < pausers.length; ++i) { + _addPauser(pausers[i]); + } } - - // Initialize the minter and pauser roles, and renounce them - ERC20Mintable.initialize(address(this)); - renounceMinter(); - - ERC20Pausable.initialize(address(this)); - renouncePauser(); - - // Add the requested minters and pausers (this can be done after renouncing since - // these are the internal calls) - for (uint256 i = 0; i < minters.length; ++i) { - _addMinter(minters[i]); - } - - for (i = 0; i < pausers.length; ++i) { - _addPauser(pausers[i]); - } - } } diff --git a/contracts/introspection/ERC165.sol b/contracts/introspection/ERC165.sol index 7ba1f1bcc..427383d80 100644 --- a/contracts/introspection/ERC165.sol +++ b/contracts/introspection/ERC165.sol @@ -11,48 +11,48 @@ import "./IERC165.sol"; */ contract ERC165 is Initializable, IERC165 { - bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ + bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; + /** + * 0x01ffc9a7 === + * bytes4(keccak256('supportsInterface(bytes4)')) + */ - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal _supportedInterfaces; + /** + * @dev a mapping of interface id to whether or not it's supported + */ + mapping(bytes4 => bool) internal _supportedInterfaces; - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - function initialize() - public - initializer - { - _registerInterface(_InterfaceId_ERC165); - } + /** + * @dev A contract implementing SupportsInterfaceWithLookup + * implement ERC165 itself + */ + function initialize() + public + initializer + { + _registerInterface(_InterfaceId_ERC165); + } - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 interfaceId) - public - view - returns (bool) - { - return _supportedInterfaces[interfaceId]; - } + /** + * @dev implement supportsInterface(bytes4) using a lookup table + */ + function supportsInterface(bytes4 interfaceId) + public + view + returns (bool) + { + return _supportedInterfaces[interfaceId]; + } - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 interfaceId) - internal - { - require(interfaceId != 0xffffffff); - _supportedInterfaces[interfaceId] = true; - } + /** + * @dev private method for registering an interface + */ + function _registerInterface(bytes4 interfaceId) + internal + { + require(interfaceId != 0xffffffff); + _supportedInterfaces[interfaceId] = true; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/introspection/ERC165Checker.sol b/contracts/introspection/ERC165Checker.sol index 36bc20959..68d3532a8 100644 --- a/contracts/introspection/ERC165Checker.sol +++ b/contracts/introspection/ERC165Checker.sol @@ -7,142 +7,142 @@ pragma solidity ^0.4.24; * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */ library ERC165Checker { - // As per the EIP-165 spec, no interface should ever match 0xffffffff - bytes4 private constant _InterfaceId_Invalid = 0xffffffff; + // As per the EIP-165 spec, no interface should ever match 0xffffffff + bytes4 private constant _InterfaceId_Invalid = 0xffffffff; - bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ + bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; + /** + * 0x01ffc9a7 === + * bytes4(keccak256('supportsInterface(bytes4)')) + */ - /** - * @notice Query if a contract supports ERC165 - * @param account The address of the contract to query for support of ERC165 - * @return true if the contract at account implements ERC165 - */ - function supportsERC165(address account) - internal - view - returns (bool) - { - // Any contract that implements ERC165 must explicitly indicate support of - // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid - return supportsERC165Interface(account, _InterfaceId_ERC165) && - !supportsERC165Interface(account, _InterfaceId_Invalid); - } - - /** - * @notice Query if a contract implements an interface, also checks support of ERC165 - * @param account The address of the contract to query for support of an interface - * @param interfaceId The interface identifier, as specified in ERC-165 - * @return true if the contract at account indicates support of the interface with - * identifier interfaceId, false otherwise - * @dev Interface identification is specified in ERC-165. - */ - function supportsInterface(address account, bytes4 interfaceId) - internal - view - returns (bool) - { - // query support of both ERC165 as per the spec and support of _interfaceId - return supportsERC165(account) && - supportsERC165Interface(account, interfaceId); - } - - /** - * @notice Query if a contract implements interfaces, also checks support of ERC165 - * @param account The address of the contract to query for support of an interface - * @param interfaceIds A list of interface identifiers, as specified in ERC-165 - * @return true if the contract at account indicates support all interfaces in the - * interfaceIds list, false otherwise - * @dev Interface identification is specified in ERC-165. - */ - function supportsInterfaces(address account, bytes4[] interfaceIds) - internal - view - returns (bool) - { - // query support of ERC165 itself - if (!supportsERC165(account)) { - return false; + /** + * @notice Query if a contract supports ERC165 + * @param account The address of the contract to query for support of ERC165 + * @return true if the contract at account implements ERC165 + */ + function supportsERC165(address account) + internal + view + returns (bool) + { + // Any contract that implements ERC165 must explicitly indicate support of + // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid + return supportsERC165Interface(account, _InterfaceId_ERC165) && + !supportsERC165Interface(account, _InterfaceId_Invalid); } - // query support of each interface in _interfaceIds - for (uint256 i = 0; i < interfaceIds.length; i++) { - if (!supportsERC165Interface(account, interfaceIds[i])) { - return false; - } + /** + * @notice Query if a contract implements an interface, also checks support of ERC165 + * @param account The address of the contract to query for support of an interface + * @param interfaceId The interface identifier, as specified in ERC-165 + * @return true if the contract at account indicates support of the interface with + * identifier interfaceId, false otherwise + * @dev Interface identification is specified in ERC-165. + */ + function supportsInterface(address account, bytes4 interfaceId) + internal + view + returns (bool) + { + // query support of both ERC165 as per the spec and support of _interfaceId + return supportsERC165(account) && + supportsERC165Interface(account, interfaceId); } - // all interfaces supported - return true; - } + /** + * @notice Query if a contract implements interfaces, also checks support of ERC165 + * @param account The address of the contract to query for support of an interface + * @param interfaceIds A list of interface identifiers, as specified in ERC-165 + * @return true if the contract at account indicates support all interfaces in the + * interfaceIds list, false otherwise + * @dev Interface identification is specified in ERC-165. + */ + function supportsInterfaces(address account, bytes4[] interfaceIds) + internal + view + returns (bool) + { + // query support of ERC165 itself + if (!supportsERC165(account)) { + return false; + } - /** - * @notice Query if a contract implements an interface, does not check ERC165 support - * @param account The address of the contract to query for support of an interface - * @param interfaceId The interface identifier, as specified in ERC-165 - * @return true if the contract at account indicates support of the interface with - * identifier interfaceId, false otherwise - * @dev Assumes that account contains a contract that supports ERC165, otherwise - * the behavior of this method is undefined. This precondition can be checked - * with the `supportsERC165` method in this library. - * Interface identification is specified in ERC-165. - */ - function supportsERC165Interface(address account, bytes4 interfaceId) - private - view - returns (bool) - { - // success determines whether the staticcall succeeded and result determines - // whether the contract at account indicates support of _interfaceId - (bool success, bool result) = callERC165SupportsInterface( - account, interfaceId); + // query support of each interface in _interfaceIds + for (uint256 i = 0; i < interfaceIds.length; i++) { + if (!supportsERC165Interface(account, interfaceIds[i])) { + return false; + } + } - return (success && result); - } - - /** - * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw - * @param account The address of the contract to query for support of an interface - * @param interfaceId The interface identifier, as specified in ERC-165 - * @return success true if the STATICCALL succeeded, false otherwise - * @return result true if the STATICCALL succeeded and the contract at account - * indicates support of the interface with identifier interfaceId, false otherwise - */ - function callERC165SupportsInterface( - address account, - bytes4 interfaceId - ) - private - view - returns (bool success, bool result) - { - bytes memory encodedParams = abi.encodeWithSelector( - _InterfaceId_ERC165, - interfaceId - ); - - // solium-disable-next-line security/no-inline-assembly - assembly { - let encodedParams_data := add(0x20, encodedParams) - let encodedParams_size := mload(encodedParams) - - let output := mload(0x40) // Find empty storage location using "free memory pointer" - mstore(output, 0x0) - - success := staticcall( - 30000, // 30k gas - account, // To addr - encodedParams_data, - encodedParams_size, - output, - 0x20 // Outputs are 32 bytes long - ) - - result := mload(output) // Load the result + // all interfaces supported + return true; + } + + /** + * @notice Query if a contract implements an interface, does not check ERC165 support + * @param account The address of the contract to query for support of an interface + * @param interfaceId The interface identifier, as specified in ERC-165 + * @return true if the contract at account indicates support of the interface with + * identifier interfaceId, false otherwise + * @dev Assumes that account contains a contract that supports ERC165, otherwise + * the behavior of this method is undefined. This precondition can be checked + * with the `supportsERC165` method in this library. + * Interface identification is specified in ERC-165. + */ + function supportsERC165Interface(address account, bytes4 interfaceId) + private + view + returns (bool) + { + // success determines whether the staticcall succeeded and result determines + // whether the contract at account indicates support of _interfaceId + (bool success, bool result) = callERC165SupportsInterface( + account, interfaceId); + + return (success && result); + } + + /** + * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw + * @param account The address of the contract to query for support of an interface + * @param interfaceId The interface identifier, as specified in ERC-165 + * @return success true if the STATICCALL succeeded, false otherwise + * @return result true if the STATICCALL succeeded and the contract at account + * indicates support of the interface with identifier interfaceId, false otherwise + */ + function callERC165SupportsInterface( + address account, + bytes4 interfaceId + ) + private + view + returns (bool success, bool result) + { + bytes memory encodedParams = abi.encodeWithSelector( + _InterfaceId_ERC165, + interfaceId + ); + + // solium-disable-next-line security/no-inline-assembly + assembly { + let encodedParams_data := add(0x20, encodedParams) + let encodedParams_size := mload(encodedParams) + + let output := mload(0x40) // Find empty storage location using "free memory pointer" + mstore(output, 0x0) + + success := staticcall( + 30000, // 30k gas + account, // To addr + encodedParams_data, + encodedParams_size, + output, + 0x20 // Outputs are 32 bytes long + ) + + result := mload(output) // Load the result + } } - } } diff --git a/contracts/introspection/IERC165.sol b/contracts/introspection/IERC165.sol index 4d8b5b69f..41567f241 100644 --- a/contracts/introspection/IERC165.sol +++ b/contracts/introspection/IERC165.sol @@ -7,14 +7,14 @@ pragma solidity ^0.4.24; */ interface IERC165 { - /** - * @notice Query if a contract implements an interface - * @param interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 interfaceId) - external - view - returns (bool); + /** + * @notice Query if a contract implements an interface + * @param interfaceId The interface identifier, as specified in ERC-165 + * @dev Interface identification is specified in ERC-165. This function + * uses less than 30,000 gas. + */ + function supportsInterface(bytes4 interfaceId) + external + view + returns (bool); } diff --git a/contracts/lifecycle/Pausable.sol b/contracts/lifecycle/Pausable.sol index c2aec1deb..be25872b5 100644 --- a/contracts/lifecycle/Pausable.sol +++ b/contracts/lifecycle/Pausable.sol @@ -9,53 +9,53 @@ import "../access/roles/PauserRole.sol"; * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Initializable, PauserRole { - event Paused(); - event Unpaused(); + event Paused(); + event Unpaused(); - bool private _paused = false; + bool private _paused = false; - function initialize(address sender) public initializer { - PauserRole.initialize(sender); - } + function initialize(address sender) public initializer { + PauserRole.initialize(sender); + } - /** - * @return true if the contract is paused, false otherwise. - */ - function paused() public view returns(bool) { - return _paused; - } + /** + * @return true if the contract is paused, false otherwise. + */ + function paused() public view returns(bool) { + return _paused; + } - /** - * @dev Modifier to make a function callable only when the contract is not paused. - */ - modifier whenNotPaused() { - require(!_paused); - _; - } + /** + * @dev Modifier to make a function callable only when the contract is not paused. + */ + modifier whenNotPaused() { + require(!_paused); + _; + } - /** - * @dev Modifier to make a function callable only when the contract is paused. - */ - modifier whenPaused() { - require(_paused); - _; - } + /** + * @dev Modifier to make a function callable only when the contract is paused. + */ + modifier whenPaused() { + require(_paused); + _; + } - /** - * @dev called by the owner to pause, triggers stopped state - */ - function pause() public onlyPauser whenNotPaused { - _paused = true; - emit Paused(); - } + /** + * @dev called by the owner to pause, triggers stopped state + */ + function pause() public onlyPauser whenNotPaused { + _paused = true; + emit Paused(); + } - /** - * @dev called by the owner to unpause, returns to normal state - */ - function unpause() public onlyPauser whenPaused { - _paused = false; - emit Unpaused(); - } + /** + * @dev called by the owner to unpause, returns to normal state + */ + function unpause() public onlyPauser whenPaused { + _paused = false; + emit Unpaused(); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/math/Math.sol b/contracts/math/Math.sol index 78ef1ae2b..690e0b530 100644 --- a/contracts/math/Math.sol +++ b/contracts/math/Math.sol @@ -6,16 +6,16 @@ pragma solidity ^0.4.24; * @dev Assorted math operations */ library Math { - function max(uint256 a, uint256 b) internal pure returns (uint256) { - return a >= b ? a : b; - } + function max(uint256 a, uint256 b) internal pure returns (uint256) { + return a >= b ? a : b; + } - function min(uint256 a, uint256 b) internal pure returns (uint256) { - return a < b ? a : b; - } + function min(uint256 a, uint256 b) internal pure returns (uint256) { + return a < b ? a : b; + } - function average(uint256 a, uint256 b) internal pure returns (uint256) { - // (a + b) / 2 can overflow, so we distribute - return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); - } + function average(uint256 a, uint256 b) internal pure returns (uint256) { + // (a + b) / 2 can overflow, so we distribute + return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); + } } diff --git a/contracts/math/SafeMath.sol b/contracts/math/SafeMath.sol index d183fa361..06828ea10 100644 --- a/contracts/math/SafeMath.sol +++ b/contracts/math/SafeMath.sol @@ -7,60 +7,60 @@ pragma solidity ^0.4.24; */ library SafeMath { - /** - * @dev Multiplies two numbers, reverts on overflow. - */ - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - // Gas optimization: this is cheaper than requiring 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (a == 0) { - return 0; + /** + * @dev Multiplies two numbers, reverts on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b); + + return c; } - uint256 c = a * b; - require(c / a == b); + /** + * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + require(b > 0); // Solidity only automatically asserts when dividing by 0 + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold - return c; - } + return c; + } - /** - * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. - */ - function div(uint256 a, uint256 b) internal pure returns (uint256) { - require(b > 0); // Solidity only automatically asserts when dividing by 0 - uint256 c = a / b; - // assert(a == b * c + a % b); // There is no case in which this doesn't hold + /** + * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + require(b <= a); + uint256 c = a - b; - return c; - } + return c; + } - /** - * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - require(b <= a); - uint256 c = a - b; + /** + * @dev Adds two numbers, reverts on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a); - return c; - } + return c; + } - /** - * @dev Adds two numbers, reverts on overflow. - */ - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a); - - return c; - } - - /** - * @dev Divides two numbers and returns the remainder (unsigned integer modulo), - * reverts when dividing by zero. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - require(b != 0); - return a % b; - } + /** + * @dev Divides two numbers and returns the remainder (unsigned integer modulo), + * reverts when dividing by zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } } diff --git a/contracts/mocks/AllowanceCrowdsaleImpl.sol b/contracts/mocks/AllowanceCrowdsaleImpl.sol index 8d9fc2300..42de59375 100644 --- a/contracts/mocks/AllowanceCrowdsaleImpl.sol +++ b/contracts/mocks/AllowanceCrowdsaleImpl.sol @@ -6,16 +6,16 @@ import "../crowdsale/emission/AllowanceCrowdsale.sol"; contract AllowanceCrowdsaleImpl is AllowanceCrowdsale { - constructor ( - uint256 rate, - address wallet, - IERC20 token, - address tokenWallet - ) - public - { - Crowdsale.initialize(rate, wallet, token); - AllowanceCrowdsale.initialize(tokenWallet); - } + constructor ( + uint256 rate, + address wallet, + IERC20 token, + address tokenWallet + ) + public + { + Crowdsale.initialize(rate, wallet, token); + AllowanceCrowdsale.initialize(tokenWallet); + } } diff --git a/contracts/mocks/CappedCrowdsaleImpl.sol b/contracts/mocks/CappedCrowdsaleImpl.sol index f66ab88e3..ff80ffe08 100644 --- a/contracts/mocks/CappedCrowdsaleImpl.sol +++ b/contracts/mocks/CappedCrowdsaleImpl.sol @@ -6,16 +6,16 @@ import "../crowdsale/validation/CappedCrowdsale.sol"; contract CappedCrowdsaleImpl is CappedCrowdsale { - constructor ( - uint256 rate, - address wallet, - IERC20 token, - uint256 cap - ) - public - { - Crowdsale.initialize(rate, wallet, token); - CappedCrowdsale.initialize(cap); - } + constructor ( + uint256 rate, + address wallet, + IERC20 token, + uint256 cap + ) + public + { + Crowdsale.initialize(rate, wallet, token); + CappedCrowdsale.initialize(cap); + } } diff --git a/contracts/mocks/CapperRoleMock.sol b/contracts/mocks/CapperRoleMock.sol index 5150d1727..e38f23618 100644 --- a/contracts/mocks/CapperRoleMock.sol +++ b/contracts/mocks/CapperRoleMock.sol @@ -4,19 +4,19 @@ import "../access/roles/CapperRole.sol"; contract CapperRoleMock is CapperRole { - constructor() public { - CapperRole.initialize(msg.sender); - } + constructor() public { + CapperRole.initialize(msg.sender); + } - function removeCapper(address account) public { - _removeCapper(account); - } + function removeCapper(address account) public { + _removeCapper(account); + } - function onlyCapperMock() public view onlyCapper { - } + function onlyCapperMock() public view onlyCapper { + } - // Causes a compilation error if super._removeCapper is not internal - function _removeCapper(address account) internal { - super._removeCapper(account); - } + // Causes a compilation error if super._removeCapper is not internal + function _removeCapper(address account) internal { + super._removeCapper(account); + } } diff --git a/contracts/mocks/ConditionalEscrowMock.sol b/contracts/mocks/ConditionalEscrowMock.sol index 7767195f6..b1a2055e8 100644 --- a/contracts/mocks/ConditionalEscrowMock.sol +++ b/contracts/mocks/ConditionalEscrowMock.sol @@ -5,17 +5,17 @@ import "../payment/ConditionalEscrow.sol"; // mock class using ConditionalEscrow contract ConditionalEscrowMock is ConditionalEscrow { - mapping(address => bool) private _allowed; + mapping(address => bool) private _allowed; - constructor() public { - ConditionalEscrow.initialize(msg.sender); - } + constructor() public { + ConditionalEscrow.initialize(msg.sender); + } - function setAllowed(address payee, bool allowed) public { - _allowed[payee] = allowed; - } + function setAllowed(address payee, bool allowed) public { + _allowed[payee] = allowed; + } - function withdrawalAllowed(address payee) public view returns (bool) { - return _allowed[payee]; - } + function withdrawalAllowed(address payee) public view returns (bool) { + return _allowed[payee]; + } } diff --git a/contracts/mocks/CounterImpl.sol b/contracts/mocks/CounterImpl.sol index d42fcbda2..3432506e1 100644 --- a/contracts/mocks/CounterImpl.sol +++ b/contracts/mocks/CounterImpl.sol @@ -4,18 +4,18 @@ import "../drafts/Counter.sol"; contract CounterImpl { - using Counter for Counter.Counter; + using Counter for Counter.Counter; - uint256 public theId; + uint256 public theId; - // use whatever key you want to track your counters - mapping(string => Counter.Counter) private _counters; + // use whatever key you want to track your counters + mapping(string => Counter.Counter) private _counters; - function doThing(string key) - public - returns (uint256) - { - theId = _counters[key].next(); - return theId; - } + function doThing(string key) + public + returns (uint256) + { + theId = _counters[key].next(); + return theId; + } } diff --git a/contracts/mocks/CrowdsaleMock.sol b/contracts/mocks/CrowdsaleMock.sol index f33cc3806..86fbdd219 100644 --- a/contracts/mocks/CrowdsaleMock.sol +++ b/contracts/mocks/CrowdsaleMock.sol @@ -4,7 +4,7 @@ import "../crowdsale/Crowdsale.sol"; contract CrowdsaleMock is Crowdsale { - constructor(uint256 rate, address wallet, IERC20 token) public { - Crowdsale.initialize(rate, wallet, token); - } + constructor(uint256 rate, address wallet, IERC20 token) public { + Crowdsale.initialize(rate, wallet, token); + } } diff --git a/contracts/mocks/DetailedERC20Mock.sol b/contracts/mocks/DetailedERC20Mock.sol index 94a59e499..63fc237dd 100644 --- a/contracts/mocks/DetailedERC20Mock.sol +++ b/contracts/mocks/DetailedERC20Mock.sol @@ -5,13 +5,13 @@ import "../token/ERC20/ERC20Detailed.sol"; contract ERC20DetailedMock is ERC20, ERC20Detailed { - constructor( - string name, - string symbol, - uint8 decimals - ) - public - { - ERC20Detailed.initialize(name, symbol, decimals); - } + constructor( + string name, + string symbol, + uint8 decimals + ) + public + { + ERC20Detailed.initialize(name, symbol, decimals); + } } diff --git a/contracts/mocks/ECDSAMock.sol b/contracts/mocks/ECDSAMock.sol index b3fbf1854..4d8e70c82 100644 --- a/contracts/mocks/ECDSAMock.sol +++ b/contracts/mocks/ECDSAMock.sol @@ -4,21 +4,21 @@ import "../cryptography/ECDSA.sol"; contract ECDSAMock { - using ECDSA for bytes32; + using ECDSA for bytes32; - function recover(bytes32 hash, bytes signature) - public - pure - returns (address) - { - return hash.recover(signature); - } + function recover(bytes32 hash, bytes signature) + public + pure + returns (address) + { + return hash.recover(signature); + } - function toEthSignedMessageHash(bytes32 hash) - public - pure - returns (bytes32) - { - return hash.toEthSignedMessageHash(); - } + function toEthSignedMessageHash(bytes32 hash) + public + pure + returns (bytes32) + { + return hash.toEthSignedMessageHash(); + } } diff --git a/contracts/mocks/ERC165/ERC165InterfacesSupported.sol b/contracts/mocks/ERC165/ERC165InterfacesSupported.sol index 6573d972c..235cfe2f0 100644 --- a/contracts/mocks/ERC165/ERC165InterfacesSupported.sol +++ b/contracts/mocks/ERC165/ERC165InterfacesSupported.sol @@ -13,57 +13,57 @@ import "../../introspection/IERC165.sol"; */ contract SupportsInterfaceWithLookupMock is IERC165 { - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ + bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; + /** + * 0x01ffc9a7 === + * bytes4(keccak256('supportsInterface(bytes4)')) + */ - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; + /** + * @dev a mapping of interface id to whether or not it's supported + */ + mapping(bytes4 => bool) internal supportedInterfaces; - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } + /** + * @dev A contract implementing SupportsInterfaceWithLookup + * implement ERC165 itself + */ + constructor() + public + { + _registerInterface(InterfaceId_ERC165); + } - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[interfaceId]; - } + /** + * @dev implement supportsInterface(bytes4) using a lookup table + */ + function supportsInterface(bytes4 interfaceId) + external + view + returns (bool) + { + return supportedInterfaces[interfaceId]; + } - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 interfaceId) - internal - { - require(interfaceId != 0xffffffff); - supportedInterfaces[interfaceId] = true; - } + /** + * @dev private method for registering an interface + */ + function _registerInterface(bytes4 interfaceId) + internal + { + require(interfaceId != 0xffffffff); + supportedInterfaces[interfaceId] = true; + } } contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock { - constructor (bytes4[] interfaceIds) - public - { - for (uint256 i = 0; i < interfaceIds.length; i++) { - _registerInterface(interfaceIds[i]); + constructor (bytes4[] interfaceIds) + public + { + for (uint256 i = 0; i < interfaceIds.length; i++) { + _registerInterface(interfaceIds[i]); + } } - } } diff --git a/contracts/mocks/ERC165CheckerMock.sol b/contracts/mocks/ERC165CheckerMock.sol index f4d6219f9..35d2255f0 100644 --- a/contracts/mocks/ERC165CheckerMock.sol +++ b/contracts/mocks/ERC165CheckerMock.sol @@ -4,29 +4,29 @@ import "../introspection/ERC165Checker.sol"; contract ERC165CheckerMock { - using ERC165Checker for address; + using ERC165Checker for address; - function supportsERC165(address account) - public - view - returns (bool) - { - return account.supportsERC165(); - } + function supportsERC165(address account) + public + view + returns (bool) + { + return account.supportsERC165(); + } - function supportsInterface(address account, bytes4 interfaceId) - public - view - returns (bool) - { - return account.supportsInterface(interfaceId); - } + function supportsInterface(address account, bytes4 interfaceId) + public + view + returns (bool) + { + return account.supportsInterface(interfaceId); + } - function supportsInterfaces(address account, bytes4[] interfaceIds) - public - view - returns (bool) - { - return account.supportsInterfaces(interfaceIds); - } + function supportsInterfaces(address account, bytes4[] interfaceIds) + public + view + returns (bool) + { + return account.supportsInterfaces(interfaceIds); + } } diff --git a/contracts/mocks/ERC165Mock.sol b/contracts/mocks/ERC165Mock.sol index 54abe3c9d..3853f8001 100644 --- a/contracts/mocks/ERC165Mock.sol +++ b/contracts/mocks/ERC165Mock.sol @@ -4,13 +4,13 @@ import "../introspection/ERC165.sol"; contract ERC165Mock is ERC165 { - constructor() public { - ERC165.initialize(); - } + constructor() public { + ERC165.initialize(); + } - function registerInterface(bytes4 interfaceId) - public - { - _registerInterface(interfaceId); - } + function registerInterface(bytes4 interfaceId) + public + { + _registerInterface(interfaceId); + } } diff --git a/contracts/mocks/ERC20BurnableMock.sol b/contracts/mocks/ERC20BurnableMock.sol index bbc7c4d1a..5db472294 100644 --- a/contracts/mocks/ERC20BurnableMock.sol +++ b/contracts/mocks/ERC20BurnableMock.sol @@ -5,8 +5,8 @@ import "../token/ERC20/ERC20Burnable.sol"; contract ERC20BurnableMock is ERC20Burnable { - constructor(address initialAccount, uint256 initialBalance) public { - _mint(initialAccount, initialBalance); - } + constructor(address initialAccount, uint256 initialBalance) public { + _mint(initialAccount, initialBalance); + } } diff --git a/contracts/mocks/ERC20CappedMock.sol b/contracts/mocks/ERC20CappedMock.sol index 2f3cd7d8b..ee0b75425 100644 --- a/contracts/mocks/ERC20CappedMock.sol +++ b/contracts/mocks/ERC20CappedMock.sol @@ -6,8 +6,8 @@ import "./MinterRoleMock.sol"; contract ERC20CappedMock is ERC20Capped, MinterRoleMock { - constructor(uint256 cap) public { - ERC20Capped.initialize(cap, msg.sender); - } + constructor(uint256 cap) public { + ERC20Capped.initialize(cap, msg.sender); + } } diff --git a/contracts/mocks/ERC20MigratorMock.sol b/contracts/mocks/ERC20MigratorMock.sol index ae03623bc..ec7fd691a 100644 --- a/contracts/mocks/ERC20MigratorMock.sol +++ b/contracts/mocks/ERC20MigratorMock.sol @@ -5,8 +5,8 @@ import "../drafts/ERC20Migrator.sol"; contract ERC20MigratorMock is ERC20Migrator { - constructor(IERC20 legacyToken) public { - ERC20Migrator.initialize(legacyToken); - } + constructor(IERC20 legacyToken) public { + ERC20Migrator.initialize(legacyToken); + } } diff --git a/contracts/mocks/ERC20MintableMock.sol b/contracts/mocks/ERC20MintableMock.sol index 95da72069..a0e8d2c60 100644 --- a/contracts/mocks/ERC20MintableMock.sol +++ b/contracts/mocks/ERC20MintableMock.sol @@ -6,7 +6,7 @@ import "./MinterRoleMock.sol"; contract ERC20MintableMock is ERC20Mintable, MinterRoleMock { - constructor() public { - ERC20Mintable.initialize(msg.sender); - } + constructor() public { + ERC20Mintable.initialize(msg.sender); + } } diff --git a/contracts/mocks/ERC20Mock.sol b/contracts/mocks/ERC20Mock.sol index 046730750..3180f616d 100644 --- a/contracts/mocks/ERC20Mock.sol +++ b/contracts/mocks/ERC20Mock.sol @@ -6,20 +6,20 @@ import "../token/ERC20/ERC20.sol"; // mock class using ERC20 contract ERC20Mock is ERC20 { - constructor(address initialAccount, uint256 initialBalance) public { - _mint(initialAccount, initialBalance); - } + constructor(address initialAccount, uint256 initialBalance) public { + _mint(initialAccount, initialBalance); + } - function mint(address account, uint256 amount) public { - _mint(account, amount); - } + function mint(address account, uint256 amount) public { + _mint(account, amount); + } - function burn(address account, uint256 amount) public { - _burn(account, amount); - } + function burn(address account, uint256 amount) public { + _burn(account, amount); + } - function burnFrom(address account, uint256 amount) public { - _burnFrom(account, amount); - } + function burnFrom(address account, uint256 amount) public { + _burnFrom(account, amount); + } } diff --git a/contracts/mocks/ERC20PausableMock.sol b/contracts/mocks/ERC20PausableMock.sol index 51003145d..c3c323030 100644 --- a/contracts/mocks/ERC20PausableMock.sol +++ b/contracts/mocks/ERC20PausableMock.sol @@ -7,10 +7,10 @@ import "./PauserRoleMock.sol"; // mock class using ERC20Pausable contract ERC20PausableMock is ERC20Pausable, PauserRoleMock { - constructor(address initialAccount, uint initialBalance) public { - ERC20Pausable.initialize(msg.sender); + constructor(address initialAccount, uint initialBalance) public { + ERC20Pausable.initialize(msg.sender); - _mint(initialAccount, initialBalance); - } + _mint(initialAccount, initialBalance); + } } diff --git a/contracts/mocks/ERC20WithMetadataMock.sol b/contracts/mocks/ERC20WithMetadataMock.sol index 6981fc53a..b7fdf1ad1 100644 --- a/contracts/mocks/ERC20WithMetadataMock.sol +++ b/contracts/mocks/ERC20WithMetadataMock.sol @@ -5,7 +5,7 @@ import "../drafts/ERC1046/TokenMetadata.sol"; contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata { - constructor(string tokenURI) public { - ERC20WithMetadata.initialize(tokenURI); - } + constructor(string tokenURI) public { + ERC20WithMetadata.initialize(tokenURI); + } } diff --git a/contracts/mocks/ERC721FullMock.sol b/contracts/mocks/ERC721FullMock.sol index ce59952da..3e2c1eead 100644 --- a/contracts/mocks/ERC721FullMock.sol +++ b/contracts/mocks/ERC721FullMock.sol @@ -12,24 +12,24 @@ import "../token/ERC721/ERC721Burnable.sol"; * and a public setter for metadata URI */ contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { - constructor(string name, string symbol) public - { - ERC721.initialize(); - ERC721Metadata.initialize(name, symbol); - ERC721Enumerable.initialize(); - ERC721Mintable.initialize(msg.sender); - ERC721MetadataMintable.initialize(msg.sender); - } + constructor(string name, string symbol) public + { + ERC721.initialize(); + ERC721Metadata.initialize(name, symbol); + ERC721Enumerable.initialize(); + ERC721Mintable.initialize(msg.sender); + ERC721MetadataMintable.initialize(msg.sender); + } - function exists(uint256 tokenId) public view returns (bool) { - return _exists(tokenId); - } + function exists(uint256 tokenId) public view returns (bool) { + return _exists(tokenId); + } - function setTokenURI(uint256 tokenId, string uri) public { - _setTokenURI(tokenId, uri); - } + function setTokenURI(uint256 tokenId, string uri) public { + _setTokenURI(tokenId, uri); + } - function removeTokenFrom(address from, uint256 tokenId) public { - _removeTokenFrom(from, tokenId); - } + function removeTokenFrom(address from, uint256 tokenId) public { + _removeTokenFrom(from, tokenId); + } } diff --git a/contracts/mocks/ERC721MintableBurnableImpl.sol b/contracts/mocks/ERC721MintableBurnableImpl.sol index 3c1e10204..e3aade0f1 100644 --- a/contracts/mocks/ERC721MintableBurnableImpl.sol +++ b/contracts/mocks/ERC721MintableBurnableImpl.sol @@ -10,15 +10,15 @@ import "../token/ERC721/ERC721Burnable.sol"; * @title ERC721MintableBurnableImpl */ contract ERC721MintableBurnableImpl - is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { + is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { - constructor() - public - { - ERC721.initialize(); - ERC721Metadata.initialize("Test", "TEST"); - ERC721Enumerable.initialize(); - ERC721Mintable.initialize(msg.sender); - ERC721MetadataMintable.initialize(msg.sender); - } + constructor() + public + { + ERC721.initialize(); + ERC721Metadata.initialize("Test", "TEST"); + ERC721Enumerable.initialize(); + ERC721Mintable.initialize(msg.sender); + ERC721MetadataMintable.initialize(msg.sender); + } } diff --git a/contracts/mocks/ERC721Mock.sol b/contracts/mocks/ERC721Mock.sol index db4fbfc1b..2a7c049f0 100644 --- a/contracts/mocks/ERC721Mock.sol +++ b/contracts/mocks/ERC721Mock.sol @@ -8,15 +8,15 @@ import "../token/ERC721/ERC721.sol"; * This mock just provides a public mint and burn functions for testing purposes */ contract ERC721Mock is ERC721 { - constructor() public { - ERC721.initialize(); - } + constructor() public { + ERC721.initialize(); + } - function mint(address to, uint256 tokenId) public { - _mint(to, tokenId); - } + function mint(address to, uint256 tokenId) public { + _mint(to, tokenId); + } - function burn(uint256 tokenId) public { - _burn(ownerOf(tokenId), tokenId); - } + function burn(uint256 tokenId) public { + _burn(ownerOf(tokenId), tokenId); + } } diff --git a/contracts/mocks/ERC721PausableMock.sol b/contracts/mocks/ERC721PausableMock.sol index aa53d9f19..db3870f92 100644 --- a/contracts/mocks/ERC721PausableMock.sol +++ b/contracts/mocks/ERC721PausableMock.sol @@ -9,20 +9,20 @@ import "./PauserRoleMock.sol"; * This mock just provides a public mint, burn and exists functions for testing purposes */ contract ERC721PausableMock is ERC721Pausable, PauserRoleMock { - constructor() { - ERC721.initialize(); - ERC721Pausable.initialize(msg.sender); - } + constructor() { + ERC721.initialize(); + ERC721Pausable.initialize(msg.sender); + } - function mint(address to, uint256 tokenId) public { - super._mint(to, tokenId); - } + function mint(address to, uint256 tokenId) public { + super._mint(to, tokenId); + } - function burn(uint256 tokenId) public { - super._burn(ownerOf(tokenId), tokenId); - } + function burn(uint256 tokenId) public { + super._burn(ownerOf(tokenId), tokenId); + } - function exists(uint256 tokenId) public view returns (bool) { - return super._exists(tokenId); - } + function exists(uint256 tokenId) public view returns (bool) { + return super._exists(tokenId); + } } diff --git a/contracts/mocks/ERC721ReceiverMock.sol b/contracts/mocks/ERC721ReceiverMock.sol index 4e21ff6ac..00a30b439 100644 --- a/contracts/mocks/ERC721ReceiverMock.sol +++ b/contracts/mocks/ERC721ReceiverMock.sol @@ -4,39 +4,39 @@ import "../token/ERC721/IERC721Receiver.sol"; contract ERC721ReceiverMock is IERC721Receiver { - bytes4 private _retval; - bool private _reverts; + bytes4 private _retval; + bool private _reverts; - event Received( - address operator, - address from, - uint256 tokenId, - bytes data, - uint256 gas - ); - - constructor(bytes4 retval, bool reverts) public { - _retval = retval; - _reverts = reverts; - } - - function onERC721Received( - address operator, - address from, - uint256 tokenId, - bytes data - ) - public - returns(bytes4) - { - require(!_reverts); - emit Received( - operator, - from, - tokenId, - data, - gasleft() // msg.gas was deprecated in solidityv0.4.21 + event Received( + address operator, + address from, + uint256 tokenId, + bytes data, + uint256 gas ); - return _retval; - } + + constructor(bytes4 retval, bool reverts) public { + _retval = retval; + _reverts = reverts; + } + + function onERC721Received( + address operator, + address from, + uint256 tokenId, + bytes data + ) + public + returns(bytes4) + { + require(!_reverts); + emit Received( + operator, + from, + tokenId, + data, + gasleft() // msg.gas was deprecated in solidityv0.4.21 + ); + return _retval; + } } diff --git a/contracts/mocks/EscrowMock.sol b/contracts/mocks/EscrowMock.sol index 0b6886071..f156307fc 100644 --- a/contracts/mocks/EscrowMock.sol +++ b/contracts/mocks/EscrowMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.24; import "../payment/Escrow.sol"; contract EscrowMock is Escrow { - constructor() public { - Escrow.initialize(msg.sender); - } + constructor() public { + Escrow.initialize(msg.sender); + } } diff --git a/contracts/mocks/FinalizableCrowdsaleImpl.sol b/contracts/mocks/FinalizableCrowdsaleImpl.sol index a512e12aa..013791504 100644 --- a/contracts/mocks/FinalizableCrowdsaleImpl.sol +++ b/contracts/mocks/FinalizableCrowdsaleImpl.sol @@ -6,17 +6,17 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol"; contract FinalizableCrowdsaleImpl is FinalizableCrowdsale { - constructor ( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - IERC20 token - ) - public - { - Crowdsale.initialize(rate, wallet, token); - TimedCrowdsale.initialize(openingTime, closingTime); - } + constructor ( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + IERC20 token + ) + public + { + Crowdsale.initialize(rate, wallet, token); + TimedCrowdsale.initialize(openingTime, closingTime); + } } diff --git a/contracts/mocks/ForceEther.sol b/contracts/mocks/ForceEther.sol index 41cde563c..dd4e7bf7c 100644 --- a/contracts/mocks/ForceEther.sol +++ b/contracts/mocks/ForceEther.sol @@ -8,9 +8,9 @@ pragma solidity ^0.4.24; // @author Remco Bloemen contract ForceEther { - constructor() public payable { } + constructor() public payable { } - function destroyAndSend(address recipient) public { - selfdestruct(recipient); - } + function destroyAndSend(address recipient) public { + selfdestruct(recipient); + } } diff --git a/contracts/mocks/IncreasingPriceCrowdsaleImpl.sol b/contracts/mocks/IncreasingPriceCrowdsaleImpl.sol index 986a5e45a..6b69384ac 100644 --- a/contracts/mocks/IncreasingPriceCrowdsaleImpl.sol +++ b/contracts/mocks/IncreasingPriceCrowdsaleImpl.sol @@ -6,19 +6,19 @@ import "../math/SafeMath.sol"; contract IncreasingPriceCrowdsaleImpl is IncreasingPriceCrowdsale { - constructor ( - uint256 openingTime, - uint256 closingTime, - address wallet, - IERC20 token, - uint256 initialRate, - uint256 finalRate - ) - public - { - Crowdsale.initialize(initialRate, wallet, token); - TimedCrowdsale.initialize(openingTime, closingTime); - IncreasingPriceCrowdsale.initialize(initialRate, finalRate); - } + constructor ( + uint256 openingTime, + uint256 closingTime, + address wallet, + IERC20 token, + uint256 initialRate, + uint256 finalRate + ) + public + { + Crowdsale.initialize(initialRate, wallet, token); + TimedCrowdsale.initialize(openingTime, closingTime); + IncreasingPriceCrowdsale.initialize(initialRate, finalRate); + } } diff --git a/contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol b/contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol index f0a12cddd..6a2587bbf 100644 --- a/contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol +++ b/contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol @@ -6,16 +6,16 @@ import "./CapperRoleMock.sol"; contract IndividuallyCappedCrowdsaleImpl - is Crowdsale, IndividuallyCappedCrowdsale, CapperRoleMock { + is Crowdsale, IndividuallyCappedCrowdsale, CapperRoleMock { - constructor( - uint256 rate, - address wallet, - IERC20 token - ) - public - { - Crowdsale.initialize(rate, wallet, token); - IndividuallyCappedCrowdsale.initialize(msg.sender); - } + constructor( + uint256 rate, + address wallet, + IERC20 token + ) + public + { + Crowdsale.initialize(rate, wallet, token); + IndividuallyCappedCrowdsale.initialize(msg.sender); + } } diff --git a/contracts/mocks/MathMock.sol b/contracts/mocks/MathMock.sol index 696653858..fb169e6a2 100644 --- a/contracts/mocks/MathMock.sol +++ b/contracts/mocks/MathMock.sol @@ -5,15 +5,15 @@ import "../math/Math.sol"; contract MathMock { - function max(uint256 a, uint256 b) public pure returns (uint256) { - return Math.max(a, b); - } + function max(uint256 a, uint256 b) public pure returns (uint256) { + return Math.max(a, b); + } - function min(uint256 a, uint256 b) public pure returns (uint256) { - return Math.min(a, b); - } + function min(uint256 a, uint256 b) public pure returns (uint256) { + return Math.min(a, b); + } - function average(uint256 a, uint256 b) public pure returns (uint256) { - return Math.average(a, b); - } + function average(uint256 a, uint256 b) public pure returns (uint256) { + return Math.average(a, b); + } } diff --git a/contracts/mocks/MerkleProofWrapper.sol b/contracts/mocks/MerkleProofWrapper.sol index 7909098f6..0d8e68fc7 100644 --- a/contracts/mocks/MerkleProofWrapper.sol +++ b/contracts/mocks/MerkleProofWrapper.sol @@ -5,15 +5,15 @@ import { MerkleProof } from "../cryptography/MerkleProof.sol"; contract MerkleProofWrapper { - function verify( - bytes32[] proof, - bytes32 root, - bytes32 leaf - ) - public - pure - returns (bool) - { - return MerkleProof.verify(proof, root, leaf); - } + function verify( + bytes32[] proof, + bytes32 root, + bytes32 leaf + ) + public + pure + returns (bool) + { + return MerkleProof.verify(proof, root, leaf); + } } diff --git a/contracts/mocks/MessageHelper.sol b/contracts/mocks/MessageHelper.sol index 63571714f..a73ce3bec 100644 --- a/contracts/mocks/MessageHelper.sol +++ b/contracts/mocks/MessageHelper.sol @@ -3,48 +3,48 @@ pragma solidity ^0.4.24; contract MessageHelper { - event Show(bytes32 b32, uint256 number, string text); - event Buy(bytes32 b32, uint256 number, string text, uint256 value); + event Show(bytes32 b32, uint256 number, string text); + event Buy(bytes32 b32, uint256 number, string text, uint256 value); - function showMessage( - bytes32 _message, - uint256 _number, - string _text - ) - public - returns (bool) - { - emit Show(_message, _number, _text); - return true; - } + function showMessage( + bytes32 _message, + uint256 _number, + string _text + ) + public + returns (bool) + { + emit Show(_message, _number, _text); + return true; + } - function buyMessage( - bytes32 _message, - uint256 _number, - string _text - ) - public - payable - returns (bool) - { - emit Buy( - _message, - _number, - _text, - msg.value); - return true; - } + function buyMessage( + bytes32 _message, + uint256 _number, + string _text + ) + public + payable + returns (bool) + { + emit Buy( + _message, + _number, + _text, + msg.value); + return true; + } - function fail() public { - require(false); - } + function fail() public { + require(false); + } - function call(address _to, bytes _data) public returns (bool) { - // solium-disable-next-line security/no-low-level-calls - if (_to.call(_data)) - return true; - else - return false; - } + function call(address _to, bytes _data) public returns (bool) { + // solium-disable-next-line security/no-low-level-calls + if (_to.call(_data)) + return true; + else + return false; + } } diff --git a/contracts/mocks/MintedCrowdsaleImpl.sol b/contracts/mocks/MintedCrowdsaleImpl.sol index 5d184426d..5b55b5e37 100644 --- a/contracts/mocks/MintedCrowdsaleImpl.sol +++ b/contracts/mocks/MintedCrowdsaleImpl.sol @@ -6,14 +6,14 @@ import "../crowdsale/emission/MintedCrowdsale.sol"; contract MintedCrowdsaleImpl is MintedCrowdsale { - constructor ( - uint256 rate, - address wallet, - ERC20Mintable token - ) - public - { - Crowdsale.initialize(rate, wallet, token); - } + constructor ( + uint256 rate, + address wallet, + ERC20Mintable token + ) + public + { + Crowdsale.initialize(rate, wallet, token); + } } diff --git a/contracts/mocks/MinterRoleMock.sol b/contracts/mocks/MinterRoleMock.sol index 0c69c84c6..85f779195 100644 --- a/contracts/mocks/MinterRoleMock.sol +++ b/contracts/mocks/MinterRoleMock.sol @@ -4,19 +4,19 @@ import "../access/roles/MinterRole.sol"; contract MinterRoleMock is MinterRole { - constructor() public { - MinterRole.initialize(msg.sender); - } + constructor() public { + MinterRole.initialize(msg.sender); + } - function removeMinter(address account) public { - _removeMinter(account); - } + function removeMinter(address account) public { + _removeMinter(account); + } - function onlyMinterMock() public view onlyMinter { - } + function onlyMinterMock() public view onlyMinter { + } - // Causes a compilation error if super._removeMinter is not internal - function _removeMinter(address account) internal { - super._removeMinter(account); - } + // Causes a compilation error if super._removeMinter is not internal + function _removeMinter(address account) internal { + super._removeMinter(account); + } } diff --git a/contracts/mocks/OwnableMock.sol b/contracts/mocks/OwnableMock.sol index 4e8bdb622..0523d48e7 100644 --- a/contracts/mocks/OwnableMock.sol +++ b/contracts/mocks/OwnableMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.24; import { Ownable } from "../ownership/Ownable.sol"; contract OwnableMock is Ownable { - constructor() { - Ownable.initialize(msg.sender); - } + constructor() { + Ownable.initialize(msg.sender); + } } diff --git a/contracts/mocks/PausableMock.sol b/contracts/mocks/PausableMock.sol index 04fef5482..10b03f8bd 100644 --- a/contracts/mocks/PausableMock.sol +++ b/contracts/mocks/PausableMock.sol @@ -6,22 +6,22 @@ import "./PauserRoleMock.sol"; // mock class using Pausable contract PausableMock is Pausable, PauserRoleMock { - bool public drasticMeasureTaken; - uint256 public count; + bool public drasticMeasureTaken; + uint256 public count; - constructor() public { - Pausable.initialize(msg.sender); + constructor() public { + Pausable.initialize(msg.sender); - drasticMeasureTaken = false; - count = 0; - } + drasticMeasureTaken = false; + count = 0; + } - function normalProcess() external whenNotPaused { - count++; - } + function normalProcess() external whenNotPaused { + count++; + } - function drasticMeasure() external whenPaused { - drasticMeasureTaken = true; - } + function drasticMeasure() external whenPaused { + drasticMeasureTaken = true; + } } diff --git a/contracts/mocks/PauserRoleMock.sol b/contracts/mocks/PauserRoleMock.sol index 4ebf04e5d..4c53ba289 100644 --- a/contracts/mocks/PauserRoleMock.sol +++ b/contracts/mocks/PauserRoleMock.sol @@ -4,19 +4,19 @@ import "../access/roles/PauserRole.sol"; contract PauserRoleMock is PauserRole { - constructor() public { - PauserRole.initialize(msg.sender); - } + constructor() public { + PauserRole.initialize(msg.sender); + } - function removePauser(address account) public { - _removePauser(account); - } + function removePauser(address account) public { + _removePauser(account); + } - function onlyPauserMock() public view onlyPauser { - } + function onlyPauserMock() public view onlyPauser { + } - // Causes a compilation error if super._removePauser is not internal - function _removePauser(address account) internal { - super._removePauser(account); - } + // Causes a compilation error if super._removePauser is not internal + function _removePauser(address account) internal { + super._removePauser(account); + } } diff --git a/contracts/mocks/PostDeliveryCrowdsaleImpl.sol b/contracts/mocks/PostDeliveryCrowdsaleImpl.sol index f22932260..9352ca3a0 100644 --- a/contracts/mocks/PostDeliveryCrowdsaleImpl.sol +++ b/contracts/mocks/PostDeliveryCrowdsaleImpl.sol @@ -6,17 +6,17 @@ import "../crowdsale/distribution/PostDeliveryCrowdsale.sol"; contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale { - constructor ( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - IERC20 token - ) - public - { - Crowdsale.initialize(rate, wallet, token); - TimedCrowdsale.initialize(openingTime, closingTime); - } + constructor ( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + IERC20 token + ) + public + { + Crowdsale.initialize(rate, wallet, token); + TimedCrowdsale.initialize(openingTime, closingTime); + } } diff --git a/contracts/mocks/PullPaymentMock.sol b/contracts/mocks/PullPaymentMock.sol index acfdaacb0..8c4f8d2cf 100644 --- a/contracts/mocks/PullPaymentMock.sol +++ b/contracts/mocks/PullPaymentMock.sol @@ -7,13 +7,13 @@ import "../payment/PullPayment.sol"; // mock class using PullPayment contract PullPaymentMock is PullPayment { - constructor() public payable { - PullPayment.initialize(); - } + constructor() public payable { + PullPayment.initialize(); + } - // test helper function to call asyncTransfer - function callTransfer(address dest, uint256 amount) public { - _asyncTransfer(dest, amount); - } + // test helper function to call asyncTransfer + function callTransfer(address dest, uint256 amount) public { + _asyncTransfer(dest, amount); + } } diff --git a/contracts/mocks/ReentrancyAttack.sol b/contracts/mocks/ReentrancyAttack.sol index 05ef748e7..d84c5fb2a 100644 --- a/contracts/mocks/ReentrancyAttack.sol +++ b/contracts/mocks/ReentrancyAttack.sol @@ -3,9 +3,9 @@ pragma solidity ^0.4.24; contract ReentrancyAttack { - function callSender(bytes4 data) public { - // solium-disable-next-line security/no-low-level-calls - require(msg.sender.call(abi.encodeWithSelector(data))); - } + function callSender(bytes4 data) public { + // solium-disable-next-line security/no-low-level-calls + require(msg.sender.call(abi.encodeWithSelector(data))); + } } diff --git a/contracts/mocks/ReentrancyMock.sol b/contracts/mocks/ReentrancyMock.sol index 0bfae1213..8f9f086ab 100644 --- a/contracts/mocks/ReentrancyMock.sol +++ b/contracts/mocks/ReentrancyMock.sol @@ -6,41 +6,41 @@ import "./ReentrancyAttack.sol"; contract ReentrancyMock is ReentrancyGuard { - uint256 public counter; + uint256 public counter; - constructor() public { - ReentrancyGuard.initialize(); - counter = 0; - } - - function callback() external nonReentrant { - count(); - } - - function countLocalRecursive(uint256 n) public nonReentrant { - if (n > 0) { - count(); - countLocalRecursive(n - 1); + constructor() public { + ReentrancyGuard.initialize(); + counter = 0; } - } - function countThisRecursive(uint256 n) public nonReentrant { - if (n > 0) { - count(); - // solium-disable-next-line security/no-low-level-calls - bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1)); - require(result == true); + function callback() external nonReentrant { + count(); } - } - function countAndCall(ReentrancyAttack attacker) public nonReentrant { - count(); - bytes4 func = bytes4(keccak256("callback()")); - attacker.callSender(func); - } + function countLocalRecursive(uint256 n) public nonReentrant { + if (n > 0) { + count(); + countLocalRecursive(n - 1); + } + } - function count() private { - counter += 1; - } + function countThisRecursive(uint256 n) public nonReentrant { + if (n > 0) { + count(); + // solium-disable-next-line security/no-low-level-calls + bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1)); + require(result == true); + } + } + + function countAndCall(ReentrancyAttack attacker) public nonReentrant { + count(); + bytes4 func = bytes4(keccak256("callback()")); + attacker.callSender(func); + } + + function count() private { + counter += 1; + } } diff --git a/contracts/mocks/RefundEscrowMock.sol b/contracts/mocks/RefundEscrowMock.sol index 7c41a9cc0..35e56f809 100644 --- a/contracts/mocks/RefundEscrowMock.sol +++ b/contracts/mocks/RefundEscrowMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.24; import "../payment/RefundEscrow.sol"; contract RefundEscrowMock is RefundEscrow { - constructor(address beneficiary) public { - RefundEscrow.initialize(beneficiary, msg.sender); - } + constructor(address beneficiary) public { + RefundEscrow.initialize(beneficiary, msg.sender); + } } diff --git a/contracts/mocks/RefundableCrowdsaleImpl.sol b/contracts/mocks/RefundableCrowdsaleImpl.sol index 633db9bb6..5ce3550ea 100644 --- a/contracts/mocks/RefundableCrowdsaleImpl.sol +++ b/contracts/mocks/RefundableCrowdsaleImpl.sol @@ -6,19 +6,19 @@ import "../crowdsale/distribution/RefundableCrowdsale.sol"; contract RefundableCrowdsaleImpl is Crowdsale, TimedCrowdsale, RefundableCrowdsale { - constructor ( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - ERC20Mintable token, - uint256 goal - ) - public - { - Crowdsale.initialize(rate, wallet, token); - TimedCrowdsale.initialize(openingTime, closingTime); - RefundableCrowdsale.initialize(goal); - } + constructor ( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + ERC20Mintable token, + uint256 goal + ) + public + { + Crowdsale.initialize(rate, wallet, token); + TimedCrowdsale.initialize(openingTime, closingTime); + RefundableCrowdsale.initialize(goal); + } } diff --git a/contracts/mocks/RolesMock.sol b/contracts/mocks/RolesMock.sol index cd2922289..0aca6196e 100644 --- a/contracts/mocks/RolesMock.sol +++ b/contracts/mocks/RolesMock.sol @@ -4,19 +4,19 @@ import "../access/Roles.sol"; contract RolesMock { - using Roles for Roles.Role; + using Roles for Roles.Role; - Roles.Role private dummyRole; + Roles.Role private dummyRole; - function add(address account) public { - dummyRole.add(account); - } + function add(address account) public { + dummyRole.add(account); + } - function remove(address account) public { - dummyRole.remove(account); - } + function remove(address account) public { + dummyRole.remove(account); + } - function has(address account) public view returns (bool) { - return dummyRole.has(account); - } + function has(address account) public view returns (bool) { + return dummyRole.has(account); + } } diff --git a/contracts/mocks/SafeERC20Helper.sol b/contracts/mocks/SafeERC20Helper.sol index 0009fd01c..8354751e4 100644 --- a/contracts/mocks/SafeERC20Helper.sol +++ b/contracts/mocks/SafeERC20Helper.sol @@ -5,91 +5,91 @@ import "../token/ERC20/SafeERC20.sol"; contract ERC20FailingMock is IERC20 { - function totalSupply() public view returns (uint256) { - return 0; - } + function totalSupply() public view returns (uint256) { + return 0; + } - function transfer(address, uint256) public returns (bool) { - return false; - } + function transfer(address, uint256) public returns (bool) { + return false; + } - function transferFrom(address, address, uint256) public returns (bool) { - return false; - } + function transferFrom(address, address, uint256) public returns (bool) { + return false; + } - function approve(address, uint256) public returns (bool) { - return false; - } + function approve(address, uint256) public returns (bool) { + return false; + } - function balanceOf(address) public view returns (uint256) { - return 0; - } + function balanceOf(address) public view returns (uint256) { + return 0; + } - function allowance(address, 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; - } + function totalSupply() public view returns (uint256) { + return 0; + } - function transfer(address, uint256) public returns (bool) { - return true; - } + function transfer(address, uint256) public returns (bool) { + return true; + } - function transferFrom(address, address, uint256) public returns (bool) { - return true; - } + function transferFrom(address, address, uint256) public returns (bool) { + return true; + } - function approve(address, uint256) public returns (bool) { - return true; - } + function approve(address, uint256) public returns (bool) { + return true; + } - function balanceOf(address) public view returns (uint256) { - return 0; - } + function balanceOf(address) public view returns (uint256) { + return 0; + } - function allowance(address, address) public view returns (uint256) { - return 0; - } + function allowance(address, address) public view returns (uint256) { + return 0; + } } contract SafeERC20Helper { - using SafeERC20 for IERC20; + using SafeERC20 for IERC20; - IERC20 private _failing; - IERC20 private _succeeding; + IERC20 private _failing; + IERC20 private _succeeding; - constructor() public { - _failing = new ERC20FailingMock(); - _succeeding = new ERC20SucceedingMock(); - } + constructor() public { + _failing = new ERC20FailingMock(); + _succeeding = new ERC20SucceedingMock(); + } - function doFailingTransfer() public { - _failing.safeTransfer(address(0), 0); - } + function doFailingTransfer() public { + _failing.safeTransfer(address(0), 0); + } - function doFailingTransferFrom() public { - _failing.safeTransferFrom(address(0), address(0), 0); - } + function doFailingTransferFrom() public { + _failing.safeTransferFrom(address(0), address(0), 0); + } - function doFailingApprove() public { - _failing.safeApprove(address(0), 0); - } + function doFailingApprove() public { + _failing.safeApprove(address(0), 0); + } - function doSucceedingTransfer() public { - _succeeding.safeTransfer(address(0), 0); - } + function doSucceedingTransfer() public { + _succeeding.safeTransfer(address(0), 0); + } - function doSucceedingTransferFrom() public { - _succeeding.safeTransferFrom(address(0), address(0), 0); - } + function doSucceedingTransferFrom() public { + _succeeding.safeTransferFrom(address(0), address(0), 0); + } - function doSucceedingApprove() public { - _succeeding.safeApprove(address(0), 0); - } + function doSucceedingApprove() public { + _succeeding.safeApprove(address(0), 0); + } } diff --git a/contracts/mocks/SafeMathMock.sol b/contracts/mocks/SafeMathMock.sol index c5464ec16..909864023 100644 --- a/contracts/mocks/SafeMathMock.sol +++ b/contracts/mocks/SafeMathMock.sol @@ -6,23 +6,23 @@ import "../math/SafeMath.sol"; contract SafeMathMock { - function mul(uint256 a, uint256 b) public pure returns (uint256) { - return SafeMath.mul(a, b); - } + function mul(uint256 a, uint256 b) public pure returns (uint256) { + return SafeMath.mul(a, b); + } - function div(uint256 a, uint256 b) public pure returns (uint256) { - return SafeMath.div(a, b); - } + function div(uint256 a, uint256 b) public pure returns (uint256) { + return SafeMath.div(a, b); + } - function sub(uint256 a, uint256 b) public pure returns (uint256) { - return SafeMath.sub(a, b); - } + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return SafeMath.sub(a, b); + } - function add(uint256 a, uint256 b) public pure returns (uint256) { - return SafeMath.add(a, b); - } + function add(uint256 a, uint256 b) public pure returns (uint256) { + return SafeMath.add(a, b); + } - function mod(uint256 a, uint256 b) public pure returns (uint256) { - return SafeMath.mod(a, b); - } + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return SafeMath.mod(a, b); + } } diff --git a/contracts/mocks/SampleCrowdsaleMock.sol b/contracts/mocks/SampleCrowdsaleMock.sol index ff29cb49f..70a4da8e1 100644 --- a/contracts/mocks/SampleCrowdsaleMock.sol +++ b/contracts/mocks/SampleCrowdsaleMock.sol @@ -4,23 +4,23 @@ import "../examples/SampleCrowdsale.sol"; contract SampleCrowdsaleTokenMock is SampleCrowdsaleToken { - constructor() public { - SampleCrowdsaleToken.initialize(msg.sender); - } + constructor() public { + SampleCrowdsaleToken.initialize(msg.sender); + } } contract SampleCrowdsaleMock is SampleCrowdsale { - constructor( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - uint256 cap, - ERC20Mintable token, - uint256 goal - ) - public - { - SampleCrowdsale.initialize(openingTime, closingTime, rate, wallet, cap, token, goal); - } + constructor( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + uint256 cap, + ERC20Mintable token, + uint256 goal + ) + public + { + SampleCrowdsale.initialize(openingTime, closingTime, rate, wallet, cap, token, goal); + } } diff --git a/contracts/mocks/SecondaryMock.sol b/contracts/mocks/SecondaryMock.sol index ba8a298e7..a3edbe17c 100644 --- a/contracts/mocks/SecondaryMock.sol +++ b/contracts/mocks/SecondaryMock.sol @@ -4,10 +4,10 @@ import "../ownership/Secondary.sol"; contract SecondaryMock is Secondary { - constructor() public { - Secondary.initialize(msg.sender); - } + constructor() public { + Secondary.initialize(msg.sender); + } - function onlyPrimaryMock() public view onlyPrimary { - } + function onlyPrimaryMock() public view onlyPrimary { + } } diff --git a/contracts/mocks/SignatureBouncerMock.sol b/contracts/mocks/SignatureBouncerMock.sol index 7c9568c6f..c7dc30313 100644 --- a/contracts/mocks/SignatureBouncerMock.sol +++ b/contracts/mocks/SignatureBouncerMock.sol @@ -5,74 +5,74 @@ import "./SignerRoleMock.sol"; contract SignatureBouncerMock is SignatureBouncer, SignerRoleMock { - constructor() public { - SignatureBouncer.initialize(msg.sender); - } + constructor() public { + SignatureBouncer.initialize(msg.sender); + } - function checkValidSignature(address account, bytes signature) - public - view - returns (bool) - { - return _isValidSignature(account, signature); - } + function checkValidSignature(address account, bytes signature) + public + view + returns (bool) + { + return _isValidSignature(account, signature); + } - function onlyWithValidSignature(bytes signature) - public - onlyValidSignature(signature) - view - { + function onlyWithValidSignature(bytes signature) + public + onlyValidSignature(signature) + view + { - } + } - function checkValidSignatureAndMethod(address account, bytes signature) - public - view - returns (bool) - { - return _isValidSignatureAndMethod(account, signature); - } + function checkValidSignatureAndMethod(address account, bytes signature) + public + view + returns (bool) + { + return _isValidSignatureAndMethod(account, signature); + } - function onlyWithValidSignatureAndMethod(bytes signature) - public - onlyValidSignatureAndMethod(signature) - view - { + function onlyWithValidSignatureAndMethod(bytes signature) + public + onlyValidSignatureAndMethod(signature) + view + { - } + } - function checkValidSignatureAndData( - address account, - bytes, - uint, - bytes signature - ) - public - view - returns (bool) - { - return _isValidSignatureAndData(account, signature); - } + function checkValidSignatureAndData( + address account, + bytes, + uint, + bytes signature + ) + public + view + returns (bool) + { + return _isValidSignatureAndData(account, signature); + } - function onlyWithValidSignatureAndData(uint, bytes signature) - public - onlyValidSignatureAndData(signature) - view - { + function onlyWithValidSignatureAndData(uint, bytes signature) + public + onlyValidSignatureAndData(signature) + view + { - } + } - function theWrongMethod(bytes) - public - pure - { + function theWrongMethod(bytes) + public + pure + { - } + } - function tooShortMsgData() - public - onlyValidSignatureAndData("") - view - { - } + function tooShortMsgData() + public + onlyValidSignatureAndData("") + view + { + } } diff --git a/contracts/mocks/SignerRoleMock.sol b/contracts/mocks/SignerRoleMock.sol index f7a08f8d1..0f51f83b7 100644 --- a/contracts/mocks/SignerRoleMock.sol +++ b/contracts/mocks/SignerRoleMock.sol @@ -4,19 +4,19 @@ import "../access/roles/SignerRole.sol"; contract SignerRoleMock is SignerRole { - constructor() public { - SignerRole.initialize(msg.sender); - } + constructor() public { + SignerRole.initialize(msg.sender); + } - function removeSigner(address account) public { - _removeSigner(account); - } + function removeSigner(address account) public { + _removeSigner(account); + } - function onlySignerMock() public view onlySigner { - } + function onlySignerMock() public view onlySigner { + } - // Causes a compilation error if super._removeSigner is not internal - function _removeSigner(address account) internal { - super._removeSigner(account); - } + // Causes a compilation error if super._removeSigner is not internal + function _removeSigner(address account) internal { + super._removeSigner(account); + } } diff --git a/contracts/mocks/SimpleTokenMock.sol b/contracts/mocks/SimpleTokenMock.sol index b614c2f53..df8f8b581 100644 --- a/contracts/mocks/SimpleTokenMock.sol +++ b/contracts/mocks/SimpleTokenMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.24; import "../examples/SimpleToken.sol"; contract SimpleTokenMock is SimpleToken { - constructor() public { - SimpleToken.initialize(msg.sender); - } + constructor() public { + SimpleToken.initialize(msg.sender); + } } diff --git a/contracts/mocks/SplitPaymentMock.sol b/contracts/mocks/SplitPaymentMock.sol index fd673bbcd..60b933f5a 100644 --- a/contracts/mocks/SplitPaymentMock.sol +++ b/contracts/mocks/SplitPaymentMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.24; import "../payment/SplitPayment.sol"; contract SplitPaymentMock is SplitPayment { - constructor(address[] payees, uint256[] shares) public { - SplitPayment.initialize(payees, shares); - } + constructor(address[] payees, uint256[] shares) public { + SplitPayment.initialize(payees, shares); + } } diff --git a/contracts/mocks/TimedCrowdsaleImpl.sol b/contracts/mocks/TimedCrowdsaleImpl.sol index c12541e5b..e6bcf8768 100644 --- a/contracts/mocks/TimedCrowdsaleImpl.sol +++ b/contracts/mocks/TimedCrowdsaleImpl.sol @@ -6,17 +6,17 @@ import "../crowdsale/validation/TimedCrowdsale.sol"; contract TimedCrowdsaleImpl is TimedCrowdsale { - constructor ( - uint256 openingTime, - uint256 closingTime, - uint256 rate, - address wallet, - IERC20 token - ) - public - { - Crowdsale.initialize(rate, wallet, token); - TimedCrowdsale.initialize(openingTime, closingTime); - } + constructor ( + uint256 openingTime, + uint256 closingTime, + uint256 rate, + address wallet, + IERC20 token + ) + public + { + Crowdsale.initialize(rate, wallet, token); + TimedCrowdsale.initialize(openingTime, closingTime); + } } diff --git a/contracts/mocks/TokenTimelockMock.sol b/contracts/mocks/TokenTimelockMock.sol index 618630adc..c50892d40 100644 --- a/contracts/mocks/TokenTimelockMock.sol +++ b/contracts/mocks/TokenTimelockMock.sol @@ -3,11 +3,11 @@ pragma solidity ^0.4.24; import "../token/ERC20/TokenTimelock.sol"; contract TokenTimelockMock is TokenTimelock { - constructor( - IERC20 token, - address beneficiary, - uint256 releaseTime - ) public { - TokenTimelock.initialize(token, beneficiary, releaseTime); - } + constructor( + IERC20 token, + address beneficiary, + uint256 releaseTime + ) public { + TokenTimelock.initialize(token, beneficiary, releaseTime); + } } diff --git a/contracts/mocks/TokenVestingMock.sol b/contracts/mocks/TokenVestingMock.sol index bb617997f..44bcb6ed4 100644 --- a/contracts/mocks/TokenVestingMock.sol +++ b/contracts/mocks/TokenVestingMock.sol @@ -3,20 +3,20 @@ pragma solidity ^0.4.24; import "../drafts/TokenVesting.sol"; contract TokenVestingMock is TokenVesting { - constructor( - address beneficiary, - uint256 start, - uint256 cliffDuration, - uint256 duration, - bool revocable - ) public { - TokenVesting.initialize( - beneficiary, - start, - cliffDuration, - duration, - revocable, - msg.sender - ); - } + constructor( + address beneficiary, + uint256 start, + uint256 cliffDuration, + uint256 duration, + bool revocable + ) public { + TokenVesting.initialize( + beneficiary, + start, + cliffDuration, + duration, + revocable, + msg.sender + ); + } } diff --git a/contracts/ownership/Ownable.sol b/contracts/ownership/Ownable.sol index b7db4252d..2f74c0e09 100644 --- a/contracts/ownership/Ownable.sol +++ b/contracts/ownership/Ownable.sol @@ -8,74 +8,74 @@ import "zos-lib/contracts/Initializable.sol"; * functions, this simplifies the implementation of "user permissions". */ contract Ownable is Initializable { - address private _owner; + address private _owner; - event OwnershipRenounced(address indexed previousOwner); - event OwnershipTransferred( - address indexed previousOwner, - address indexed newOwner - ); + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); - /** - * @dev The Ownable constructor sets the original `owner` of the contract to the sender - * account. - */ - function initialize(address sender) public initializer { - _owner = sender; - } + /** + * @dev The Ownable constructor sets the original `owner` of the contract to the sender + * account. + */ + function initialize(address sender) public initializer { + _owner = sender; + } - /** - * @return the address of the owner. - */ - function owner() public view returns(address) { - return _owner; - } + /** + * @return the address of the owner. + */ + function owner() public view returns(address) { + return _owner; + } - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(isOwner()); - _; - } + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(isOwner()); + _; + } - /** - * @return true if `msg.sender` is the owner of the contract. - */ - function isOwner() public view returns(bool) { - return msg.sender == _owner; - } + /** + * @return true if `msg.sender` is the owner of the contract. + */ + function isOwner() public view returns(bool) { + return msg.sender == _owner; + } - /** - * @dev Allows the current owner to relinquish control of the contract. - * @notice Renouncing to ownership will leave the contract without an owner. - * It will not be possible to call the functions with the `onlyOwner` - * modifier anymore. - */ - function renounceOwnership() public onlyOwner { - emit OwnershipRenounced(_owner); - _owner = address(0); - } + /** + * @dev Allows the current owner to relinquish control of the contract. + * @notice Renouncing to ownership will leave the contract without an owner. + * It will not be possible to call the functions with the `onlyOwner` + * modifier anymore. + */ + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(_owner); + _owner = address(0); + } - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function transferOwnership(address newOwner) public onlyOwner { - _transferOwnership(newOwner); - } + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + _transferOwnership(newOwner); + } - /** - * @dev Transfers control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function _transferOwnership(address newOwner) internal { - require(newOwner != address(0)); - emit OwnershipTransferred(_owner, newOwner); - _owner = newOwner; - } + /** + * @dev Transfers control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function _transferOwnership(address newOwner) internal { + require(newOwner != address(0)); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/ownership/Secondary.sol b/contracts/ownership/Secondary.sol index 7b108fe61..0a620121e 100644 --- a/contracts/ownership/Secondary.sol +++ b/contracts/ownership/Secondary.sol @@ -7,32 +7,32 @@ import "zos-lib/contracts/Initializable.sol"; * @dev A Secondary contract can only be used by its primary account (the one that created it) */ contract Secondary is Initializable { - address private _primary; + address private _primary; - /** - * @dev Sets the primary account to the one that is creating the Secondary contract. - */ - function initialize(address sender) public initializer { - _primary = sender; - } + /** + * @dev Sets the primary account to the one that is creating the Secondary contract. + */ + function initialize(address sender) public initializer { + _primary = sender; + } - /** - * @dev Reverts if called from any account other than the primary. - */ - modifier onlyPrimary() { - require(msg.sender == _primary); - _; - } + /** + * @dev Reverts if called from any account other than the primary. + */ + modifier onlyPrimary() { + require(msg.sender == _primary); + _; + } - function primary() public view returns (address) { - return _primary; - } + function primary() public view returns (address) { + return _primary; + } - function transferPrimary(address recipient) public onlyPrimary { - require(recipient != address(0)); + function transferPrimary(address recipient) public onlyPrimary { + require(recipient != address(0)); - _primary = recipient; - } + _primary = recipient; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/payment/ConditionalEscrow.sol b/contracts/payment/ConditionalEscrow.sol index f1b87832a..5ccf686a1 100644 --- a/contracts/payment/ConditionalEscrow.sol +++ b/contracts/payment/ConditionalEscrow.sol @@ -9,21 +9,21 @@ import "./Escrow.sol"; * @dev Base abstract escrow to only allow withdrawal if a condition is met. */ contract ConditionalEscrow is Initializable, Escrow { - function initialize(address sender) public initializer { - Escrow.initialize(sender); - } + function initialize(address sender) public initializer { + Escrow.initialize(sender); + } - /** - * @dev Returns whether an address is allowed to withdraw their funds. To be - * implemented by derived contracts. - * @param payee The destination address of the funds. - */ - function withdrawalAllowed(address payee) public view returns (bool); + /** + * @dev Returns whether an address is allowed to withdraw their funds. To be + * implemented by derived contracts. + * @param payee The destination address of the funds. + */ + function withdrawalAllowed(address payee) public view returns (bool); - function withdraw(address payee) public { - require(withdrawalAllowed(payee)); - super.withdraw(payee); - } + function withdraw(address payee) public { + require(withdrawalAllowed(payee)); + super.withdraw(payee); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/payment/Escrow.sol b/contracts/payment/Escrow.sol index 86dd1c241..1931bf984 100644 --- a/contracts/payment/Escrow.sol +++ b/contracts/payment/Escrow.sol @@ -13,45 +13,45 @@ import "../ownership/Secondary.sol"; * deposit and withdraw. */ contract Escrow is Initializable, Secondary { - using SafeMath for uint256; + using SafeMath for uint256; - event Deposited(address indexed payee, uint256 weiAmount); - event Withdrawn(address indexed payee, uint256 weiAmount); + event Deposited(address indexed payee, uint256 weiAmount); + event Withdrawn(address indexed payee, uint256 weiAmount); - mapping(address => uint256) private _deposits; + mapping(address => uint256) private _deposits; - function initialize(address sender) public initializer { - Secondary.initialize(sender); - } + function initialize(address sender) public initializer { + Secondary.initialize(sender); + } - function depositsOf(address payee) public view returns (uint256) { - return _deposits[payee]; - } + function depositsOf(address payee) public view returns (uint256) { + return _deposits[payee]; + } - /** - * @dev Stores the sent amount as credit to be withdrawn. - * @param payee The destination address of the funds. - */ - function deposit(address payee) public onlyPrimary payable { - uint256 amount = msg.value; - _deposits[payee] = _deposits[payee].add(amount); + /** + * @dev Stores the sent amount as credit to be withdrawn. + * @param payee The destination address of the funds. + */ + function deposit(address payee) public onlyPrimary payable { + uint256 amount = msg.value; + _deposits[payee] = _deposits[payee].add(amount); - emit Deposited(payee, amount); - } + emit Deposited(payee, amount); + } - /** - * @dev Withdraw accumulated balance for a payee. - * @param payee The address whose funds will be withdrawn and transferred to. - */ - function withdraw(address payee) public onlyPrimary { - uint256 payment = _deposits[payee]; + /** + * @dev Withdraw accumulated balance for a payee. + * @param payee The address whose funds will be withdrawn and transferred to. + */ + function withdraw(address payee) public onlyPrimary { + uint256 payment = _deposits[payee]; - _deposits[payee] = 0; + _deposits[payee] = 0; - payee.transfer(payment); + payee.transfer(payment); - emit Withdrawn(payee, payment); - } + emit Withdrawn(payee, payment); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/payment/PullPayment.sol b/contracts/payment/PullPayment.sol index 1cc5e0461..a8b57ea24 100644 --- a/contracts/payment/PullPayment.sol +++ b/contracts/payment/PullPayment.sol @@ -10,40 +10,40 @@ import "./Escrow.sol"; * contract and use _asyncTransfer instead of send or transfer. */ contract PullPayment is Initializable { - Escrow private _escrow; + Escrow private _escrow; - function initialize() public initializer { - // conditional added to make initializer idempotent in case of diamond inheritance - if (address(_escrow) == address(0)) { - _escrow = new Escrow(); - _escrow.initialize(address(this)); + function initialize() public initializer { + // conditional added to make initializer idempotent in case of diamond inheritance + if (address(_escrow) == address(0)) { + _escrow = new Escrow(); + _escrow.initialize(address(this)); + } } - } - /** - * @dev Withdraw accumulated balance. - * @param payee Whose balance will be withdrawn. - */ - function withdrawPayments(address payee) public { - _escrow.withdraw(payee); - } + /** + * @dev Withdraw accumulated balance. + * @param payee Whose balance will be withdrawn. + */ + function withdrawPayments(address payee) public { + _escrow.withdraw(payee); + } - /** - * @dev Returns the credit owed to an address. - * @param dest The creditor's address. - */ - function payments(address dest) public view returns (uint256) { - return _escrow.depositsOf(dest); - } + /** + * @dev Returns the credit owed to an address. + * @param dest The creditor's address. + */ + function payments(address dest) public view returns (uint256) { + return _escrow.depositsOf(dest); + } - /** - * @dev Called by the payer to store the sent amount as credit to be pulled. - * @param dest The destination address of the funds. - * @param amount The amount to transfer. - */ - function _asyncTransfer(address dest, uint256 amount) internal { - _escrow.deposit.value(amount)(dest); - } + /** + * @dev Called by the payer to store the sent amount as credit to be pulled. + * @param dest The destination address of the funds. + * @param amount The amount to transfer. + */ + function _asyncTransfer(address dest, uint256 amount) internal { + _escrow.deposit.value(amount)(dest); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/payment/RefundEscrow.sol b/contracts/payment/RefundEscrow.sol index 2fb97f991..353a873c0 100644 --- a/contracts/payment/RefundEscrow.sol +++ b/contracts/payment/RefundEscrow.sol @@ -11,82 +11,82 @@ import "./ConditionalEscrow.sol"; * by the beneficiary, or refunds to the depositors. */ contract RefundEscrow is Initializable, ConditionalEscrow { - enum State { Active, Refunding, Closed } + enum State { Active, Refunding, Closed } - event Closed(); - event RefundsEnabled(); + event Closed(); + event RefundsEnabled(); - State private _state; - address private _beneficiary; + State private _state; + address private _beneficiary; - /** - * @dev Constructor. - * @param beneficiary The beneficiary of the deposits. - */ - function initialize(address beneficiary, address sender) public initializer { - ConditionalEscrow.initialize(sender); + /** + * @dev Constructor. + * @param beneficiary The beneficiary of the deposits. + */ + function initialize(address beneficiary, address sender) public initializer { + ConditionalEscrow.initialize(sender); - require(beneficiary != address(0)); - _beneficiary = beneficiary; - _state = State.Active; - } + require(beneficiary != address(0)); + _beneficiary = beneficiary; + _state = State.Active; + } - /** - * @return the current state of the escrow. - */ - function state() public view returns (State) { - return _state; - } + /** + * @return the current state of the escrow. + */ + function state() public view returns (State) { + return _state; + } - /** - * @return the beneficiary of the escrow. - */ - function beneficiary() public view returns (address) { - return _beneficiary; - } + /** + * @return the beneficiary of the escrow. + */ + function beneficiary() public view returns (address) { + return _beneficiary; + } - /** - * @dev Stores funds that may later be refunded. - * @param refundee The address funds will be sent to if a refund occurs. - */ - function deposit(address refundee) public payable { - require(_state == State.Active); - super.deposit(refundee); - } + /** + * @dev Stores funds that may later be refunded. + * @param refundee The address funds will be sent to if a refund occurs. + */ + function deposit(address refundee) public payable { + require(_state == State.Active); + super.deposit(refundee); + } - /** - * @dev Allows for the beneficiary to withdraw their funds, rejecting - * further deposits. - */ - function close() public onlyPrimary { - require(_state == State.Active); - _state = State.Closed; - emit Closed(); - } + /** + * @dev Allows for the beneficiary to withdraw their funds, rejecting + * further deposits. + */ + function close() public onlyPrimary { + require(_state == State.Active); + _state = State.Closed; + emit Closed(); + } - /** - * @dev Allows for refunds to take place, rejecting further deposits. - */ - function enableRefunds() public onlyPrimary { - require(_state == State.Active); - _state = State.Refunding; - emit RefundsEnabled(); - } + /** + * @dev Allows for refunds to take place, rejecting further deposits. + */ + function enableRefunds() public onlyPrimary { + require(_state == State.Active); + _state = State.Refunding; + emit RefundsEnabled(); + } - /** - * @dev Withdraws the beneficiary's funds. - */ - function beneficiaryWithdraw() public { - require(_state == State.Closed); - _beneficiary.transfer(address(this).balance); - } + /** + * @dev Withdraws the beneficiary's funds. + */ + function beneficiaryWithdraw() public { + require(_state == State.Closed); + _beneficiary.transfer(address(this).balance); + } - /** - * @dev Returns whether refundees can withdraw their deposits (be refunded). - */ - function withdrawalAllowed(address payee) public view returns (bool) { - return _state == State.Refunding; - } + /** + * @dev Returns whether refundees can withdraw their deposits (be refunded). + */ + function withdrawalAllowed(address payee) public view returns (bool) { + return _state == State.Refunding; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/payment/SplitPayment.sol b/contracts/payment/SplitPayment.sol index b63df9fe5..2410ee968 100644 --- a/contracts/payment/SplitPayment.sol +++ b/contracts/payment/SplitPayment.sol @@ -10,103 +10,103 @@ import "../math/SafeMath.sol"; * of people and split proportionately to some number of shares they own. */ contract SplitPayment is Initializable { - using SafeMath for uint256; + using SafeMath for uint256; - uint256 private _totalShares; - uint256 private _totalReleased; + uint256 private _totalShares; + uint256 private _totalReleased; - mapping(address => uint256) private _shares; - mapping(address => uint256) private _released; - address[] private _payees; + mapping(address => uint256) private _shares; + mapping(address => uint256) private _released; + address[] private _payees; - /** - * @dev Constructor - */ - function initialize(address[] payees, uint256[] shares) public payable initializer { - require(payees.length == shares.length); - require(payees.length > 0); + /** + * @dev Constructor + */ + function initialize(address[] payees, uint256[] shares) public payable initializer { + require(payees.length == shares.length); + require(payees.length > 0); - for (uint256 i = 0; i < payees.length; i++) { - _addPayee(payees[i], shares[i]); + for (uint256 i = 0; i < payees.length; i++) { + _addPayee(payees[i], shares[i]); + } } - } - /** - * @dev payable fallback - */ - function () external payable {} + /** + * @dev payable fallback + */ + function () external payable {} - /** - * @return the total shares of the contract. - */ - function totalShares() public view returns(uint256) { - return _totalShares; - } + /** + * @return the total shares of the contract. + */ + function totalShares() public view returns(uint256) { + return _totalShares; + } - /** - * @return the total amount already released. - */ - function totalReleased() public view returns(uint256) { - return _totalReleased; - } + /** + * @return the total amount already released. + */ + function totalReleased() public view returns(uint256) { + return _totalReleased; + } - /** - * @return the shares of an account. - */ - function shares(address account) public view returns(uint256) { - return _shares[account]; - } + /** + * @return the shares of an account. + */ + function shares(address account) public view returns(uint256) { + return _shares[account]; + } - /** - * @return the amount already released to an account. - */ - function released(address account) public view returns(uint256) { - return _released[account]; - } + /** + * @return the amount already released to an account. + */ + function released(address account) public view returns(uint256) { + return _released[account]; + } - /** - * @return the address of a payee. - */ - function payee(uint256 index) public view returns(address) { - return _payees[index]; - } + /** + * @return the address of a payee. + */ + function payee(uint256 index) public view returns(address) { + return _payees[index]; + } - /** - * @dev Release one of the payee's proportional payment. - * @param account Whose payments will be released. - */ - function release(address account) public { - require(_shares[account] > 0); + /** + * @dev Release one of the payee's proportional payment. + * @param account Whose payments will be released. + */ + function release(address account) public { + require(_shares[account] > 0); - uint256 totalReceived = address(this).balance.add(_totalReleased); - uint256 payment = totalReceived.mul( - _shares[account]).div( - _totalShares).sub( - _released[account] - ); + uint256 totalReceived = address(this).balance.add(_totalReleased); + uint256 payment = totalReceived.mul( + _shares[account]).div( + _totalShares).sub( + _released[account] + ); - require(payment != 0); + require(payment != 0); - _released[account] = _released[account].add(payment); - _totalReleased = _totalReleased.add(payment); + _released[account] = _released[account].add(payment); + _totalReleased = _totalReleased.add(payment); - account.transfer(payment); - } + account.transfer(payment); + } - /** - * @dev Add a new payee to the contract. - * @param account The address of the payee to add. - * @param shares_ The number of shares owned by the payee. - */ - function _addPayee(address account, uint256 shares_) internal { - require(account != address(0)); - require(shares_ > 0); - require(_shares[account] == 0); + /** + * @dev Add a new payee to the contract. + * @param account The address of the payee to add. + * @param shares_ The number of shares owned by the payee. + */ + function _addPayee(address account, uint256 shares_) internal { + require(account != address(0)); + require(shares_ > 0); + require(_shares[account] == 0); - _payees.push(account); - _shares[account] = shares_; - _totalShares = _totalShares.add(shares_); - } + _payees.push(account); + _shares[account] = shares_; + _totalShares = _totalShares.add(shares_); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index 8d5fc0eca..d1744c3d0 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -13,203 +13,203 @@ import "../../math/SafeMath.sol"; * Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract ERC20 is Initializable, IERC20 { - using SafeMath for uint256; + using SafeMath for uint256; - mapping (address => uint256) private _balances; + mapping (address => uint256) private _balances; - mapping (address => mapping (address => uint256)) private _allowed; + mapping (address => mapping (address => uint256)) private _allowed; - uint256 private _totalSupply; + uint256 private _totalSupply; - /** - * @dev Total number of tokens in existence - */ - function totalSupply() public view returns (uint256) { - return _totalSupply; - } + /** + * @dev Total number of tokens in existence + */ + function totalSupply() public view returns (uint256) { + return _totalSupply; + } - /** - * @dev Gets the balance of the specified address. - * @param owner The address to query the the balance of. - * @return An uint256 representing the amount owned by the passed address. - */ - function balanceOf(address owner) public view returns (uint256) { - return _balances[owner]; - } + /** + * @dev Gets the balance of the specified address. + * @param owner The address to query the the balance of. + * @return An uint256 representing the amount owned by the passed address. + */ + function balanceOf(address owner) public view returns (uint256) { + return _balances[owner]; + } - /** - * @dev Function to check the amount of tokens that an owner allowed to a spender. - * @param owner address The address which owns the funds. - * @param spender address The address which will spend the funds. - * @return A uint256 specifying the amount of tokens still available for the spender. - */ - function allowance( - address owner, - address spender - ) - public - view - returns (uint256) - { - return _allowed[owner][spender]; - } + /** + * @dev Function to check the amount of tokens that an owner allowed to a spender. + * @param owner address The address which owns the funds. + * @param spender address The address which will spend the funds. + * @return A uint256 specifying the amount of tokens still available for the spender. + */ + function allowance( + address owner, + address spender + ) + public + view + returns (uint256) + { + return _allowed[owner][spender]; + } - /** - * @dev Transfer token for a specified address - * @param to The address to transfer to. - * @param value The amount to be transferred. - */ - function transfer(address to, uint256 value) public returns (bool) { - _transfer(msg.sender, to, value); - return true; - } + /** + * @dev Transfer token for a specified address + * @param to The address to transfer to. + * @param value The amount to be transferred. + */ + function transfer(address to, uint256 value) public returns (bool) { + _transfer(msg.sender, to, value); + return true; + } - /** - * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. - * Beware that changing an allowance with this method brings the risk that someone may use both the old - * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this - * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: - * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 - * @param spender The address which will spend the funds. - * @param value The amount of tokens to be spent. - */ - function approve(address spender, uint256 value) public returns (bool) { - require(spender != address(0)); + /** + * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. + * Beware that changing an allowance with this method brings the risk that someone may use both the old + * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this + * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * @param spender The address which will spend the funds. + * @param value The amount of tokens to be spent. + */ + function approve(address spender, uint256 value) public returns (bool) { + require(spender != address(0)); - _allowed[msg.sender][spender] = value; - emit Approval(msg.sender, spender, value); - return true; - } + _allowed[msg.sender][spender] = value; + emit Approval(msg.sender, spender, value); + return true; + } - /** - * @dev Transfer tokens from one address to another - * @param from address The address which you want to send tokens from - * @param to address The address which you want to transfer to - * @param value uint256 the amount of tokens to be transferred - */ - function transferFrom( - address from, - address to, - uint256 value - ) - public - returns (bool) - { - require(value <= _allowed[from][msg.sender]); + /** + * @dev Transfer tokens from one address to another + * @param from address The address which you want to send tokens from + * @param to address The address which you want to transfer to + * @param value uint256 the amount of tokens to be transferred + */ + function transferFrom( + address from, + address to, + uint256 value + ) + public + returns (bool) + { + require(value <= _allowed[from][msg.sender]); - _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); - _transfer(from, to, value); - return true; - } + _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); + _transfer(from, to, value); + return true; + } - /** - * @dev Increase the amount of tokens that an owner allowed to a spender. - * approve should be called when allowed_[_spender] == 0. To increment - * allowed value is better to use this function to avoid 2 calls (and wait until - * the first transaction is mined) - * From MonolithDAO Token.sol - * @param spender The address which will spend the funds. - * @param addedValue The amount of tokens to increase the allowance by. - */ - function increaseAllowance( - address spender, - uint256 addedValue - ) - public - returns (bool) - { - require(spender != address(0)); + /** + * @dev Increase the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed_[_spender] == 0. To increment + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param spender The address which will spend the funds. + * @param addedValue The amount of tokens to increase the allowance by. + */ + function increaseAllowance( + address spender, + uint256 addedValue + ) + public + returns (bool) + { + require(spender != address(0)); - _allowed[msg.sender][spender] = ( - _allowed[msg.sender][spender].add(addedValue)); - emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); - return true; - } + _allowed[msg.sender][spender] = ( + _allowed[msg.sender][spender].add(addedValue)); + emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); + return true; + } - /** - * @dev Decrease the amount of tokens that an owner allowed to a spender. - * approve should be called when allowed_[_spender] == 0. To decrement - * allowed value is better to use this function to avoid 2 calls (and wait until - * the first transaction is mined) - * From MonolithDAO Token.sol - * @param spender The address which will spend the funds. - * @param subtractedValue The amount of tokens to decrease the allowance by. - */ - function decreaseAllowance( - address spender, - uint256 subtractedValue - ) - public - returns (bool) - { - require(spender != address(0)); + /** + * @dev Decrease the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed_[_spender] == 0. To decrement + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param spender The address which will spend the funds. + * @param subtractedValue The amount of tokens to decrease the allowance by. + */ + function decreaseAllowance( + address spender, + uint256 subtractedValue + ) + public + returns (bool) + { + require(spender != address(0)); - _allowed[msg.sender][spender] = ( - _allowed[msg.sender][spender].sub(subtractedValue)); - emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); - return true; - } + _allowed[msg.sender][spender] = ( + _allowed[msg.sender][spender].sub(subtractedValue)); + emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); + return true; + } - /** - * @dev Transfer token for a specified addresses - * @param from The address to transfer from. - * @param to The address to transfer to. - * @param value The amount to be transferred. - */ - function _transfer(address from, address to, uint256 value) internal { - require(value <= _balances[from]); - require(to != address(0)); + /** + * @dev Transfer token for a specified addresses + * @param from The address to transfer from. + * @param to The address to transfer to. + * @param value The amount to be transferred. + */ + function _transfer(address from, address to, uint256 value) internal { + require(value <= _balances[from]); + require(to != address(0)); - _balances[from] = _balances[from].sub(value); - _balances[to] = _balances[to].add(value); - emit Transfer(from, to, value); - } + _balances[from] = _balances[from].sub(value); + _balances[to] = _balances[to].add(value); + emit Transfer(from, to, value); + } - /** - * @dev Internal function that mints an amount of the token and assigns it to - * an account. This encapsulates the modification of balances such that the - * proper events are emitted. - * @param account The account that will receive the created tokens. - * @param amount The amount that will be created. - */ - function _mint(address account, uint256 amount) internal { - require(account != 0); - _totalSupply = _totalSupply.add(amount); - _balances[account] = _balances[account].add(amount); - emit Transfer(address(0), account, amount); - } + /** + * @dev Internal function that mints an amount of the token and assigns it to + * an account. This encapsulates the modification of balances such that the + * proper events are emitted. + * @param account The account that will receive the created tokens. + * @param amount The amount that will be created. + */ + function _mint(address account, uint256 amount) internal { + require(account != 0); + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } - /** - * @dev Internal function that burns an amount of the token of a given - * account. - * @param account The account whose tokens will be burnt. - * @param amount The amount that will be burnt. - */ - function _burn(address account, uint256 amount) internal { - require(account != 0); - require(amount <= _balances[account]); + /** + * @dev Internal function that burns an amount of the token of a given + * account. + * @param account The account whose tokens will be burnt. + * @param amount The amount that will be burnt. + */ + function _burn(address account, uint256 amount) internal { + require(account != 0); + require(amount <= _balances[account]); - _totalSupply = _totalSupply.sub(amount); - _balances[account] = _balances[account].sub(amount); - emit Transfer(account, address(0), amount); - } + _totalSupply = _totalSupply.sub(amount); + _balances[account] = _balances[account].sub(amount); + emit Transfer(account, address(0), amount); + } - /** - * @dev Internal function that burns an amount of the token of a given - * account, deducting from the sender's allowance for said account. Uses the - * internal burn function. - * @param account The account whose tokens will be burnt. - * @param amount The amount that will be burnt. - */ - function _burnFrom(address account, uint256 amount) internal { - require(amount <= _allowed[account][msg.sender]); + /** + * @dev Internal function that burns an amount of the token of a given + * account, deducting from the sender's allowance for said account. Uses the + * internal burn function. + * @param account The account whose tokens will be burnt. + * @param amount The amount that will be burnt. + */ + function _burnFrom(address account, uint256 amount) internal { + require(amount <= _allowed[account][msg.sender]); - // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, - // this function needs to emit an event with the updated approval. - _allowed[account][msg.sender] = _allowed[account][msg.sender].sub( - amount); - _burn(account, amount); - } + // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, + // this function needs to emit an event with the updated approval. + _allowed[account][msg.sender] = _allowed[account][msg.sender].sub( + amount); + _burn(account, amount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20Burnable.sol b/contracts/token/ERC20/ERC20Burnable.sol index ace51414f..84b870c1d 100644 --- a/contracts/token/ERC20/ERC20Burnable.sol +++ b/contracts/token/ERC20/ERC20Burnable.sol @@ -10,22 +10,22 @@ import "./ERC20.sol"; */ contract ERC20Burnable is Initializable, ERC20 { - /** - * @dev Burns a specific amount of tokens. - * @param value The amount of token to be burned. - */ - function burn(uint256 value) public { - _burn(msg.sender, value); - } + /** + * @dev Burns a specific amount of tokens. + * @param value The amount of token to be burned. + */ + function burn(uint256 value) public { + _burn(msg.sender, value); + } - /** - * @dev Burns a specific amount of tokens from the target address and decrements allowance - * @param from address The address which you want to send tokens from - * @param value uint256 The amount of token to be burned - */ - function burnFrom(address from, uint256 value) public { - _burnFrom(from, value); - } + /** + * @dev Burns a specific amount of tokens from the target address and decrements allowance + * @param from address The address which you want to send tokens from + * @param value uint256 The amount of token to be burned + */ + function burnFrom(address from, uint256 value) public { + _burnFrom(from, value); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20Capped.sol b/contracts/token/ERC20/ERC20Capped.sol index 2f1a24ea8..264d29667 100644 --- a/contracts/token/ERC20/ERC20Capped.sol +++ b/contracts/token/ERC20/ERC20Capped.sol @@ -10,43 +10,43 @@ import "./ERC20Mintable.sol"; */ contract ERC20Capped is Initializable, ERC20Mintable { - uint256 private _cap; + uint256 private _cap; - function initialize(uint256 cap, address sender) - public - initializer - { - ERC20Mintable.initialize(sender); + function initialize(uint256 cap, address sender) + public + initializer + { + ERC20Mintable.initialize(sender); - require(cap > 0); - _cap = cap; - } + require(cap > 0); + _cap = cap; + } - /** - * @return the cap for the token minting. - */ - function cap() public view returns(uint256) { - return _cap; - } + /** + * @return the cap for the token minting. + */ + function cap() public view returns(uint256) { + return _cap; + } - /** - * @dev Function to mint tokens - * @param to The address that will receive the minted tokens. - * @param amount The amount of tokens to mint. - * @return A boolean that indicates if the operation was successful. - */ - function mint( - address to, - uint256 amount - ) - public - returns (bool) - { - require(totalSupply().add(amount) <= _cap); + /** + * @dev Function to mint tokens + * @param to The address that will receive the minted tokens. + * @param amount The amount of tokens to mint. + * @return A boolean that indicates if the operation was successful. + */ + function mint( + address to, + uint256 amount + ) + public + returns (bool) + { + require(totalSupply().add(amount) <= _cap); - return super.mint(to, amount); - } + return super.mint(to, amount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20Detailed.sol b/contracts/token/ERC20/ERC20Detailed.sol index 178e23421..4a1d8d681 100644 --- a/contracts/token/ERC20/ERC20Detailed.sol +++ b/contracts/token/ERC20/ERC20Detailed.sol @@ -11,36 +11,36 @@ import "./IERC20.sol"; * just as on Ethereum all the operations are done in wei. */ contract ERC20Detailed is Initializable, IERC20 { - string private _name; - string private _symbol; - uint8 private _decimals; + string private _name; + string private _symbol; + uint8 private _decimals; - function initialize(string name, string symbol, uint8 decimals) public initializer { - _name = name; - _symbol = symbol; - _decimals = decimals; - } + function initialize(string name, string symbol, uint8 decimals) public initializer { + _name = name; + _symbol = symbol; + _decimals = decimals; + } - /** - * @return the name of the token. - */ - function name() public view returns(string) { - return _name; - } + /** + * @return the name of the token. + */ + function name() public view returns(string) { + return _name; + } - /** - * @return the symbol of the token. - */ - function symbol() public view returns(string) { - return _symbol; - } + /** + * @return the symbol of the token. + */ + function symbol() public view returns(string) { + return _symbol; + } - /** - * @return the number of decimals of the token. - */ - function decimals() public view returns(uint8) { - return _decimals; - } + /** + * @return the number of decimals of the token. + */ + function decimals() public view returns(uint8) { + return _decimals; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20Mintable.sol b/contracts/token/ERC20/ERC20Mintable.sol index 83cc3f8c7..7b6864099 100644 --- a/contracts/token/ERC20/ERC20Mintable.sol +++ b/contracts/token/ERC20/ERC20Mintable.sol @@ -10,27 +10,27 @@ import "../../access/roles/MinterRole.sol"; * @dev ERC20 minting logic */ contract ERC20Mintable is Initializable, ERC20, MinterRole { - function initialize(address sender) public initializer { - MinterRole.initialize(sender); - } + function initialize(address sender) public initializer { + MinterRole.initialize(sender); + } - /** - * @dev Function to mint tokens - * @param to The address that will receive the minted tokens. - * @param amount The amount of tokens to mint. - * @return A boolean that indicates if the operation was successful. - */ - function mint( - address to, - uint256 amount - ) - public - onlyMinter - returns (bool) - { - _mint(to, amount); - return true; - } + /** + * @dev Function to mint tokens + * @param to The address that will receive the minted tokens. + * @param amount The amount of tokens to mint. + * @return A boolean that indicates if the operation was successful. + */ + function mint( + address to, + uint256 amount + ) + public + onlyMinter + returns (bool) + { + _mint(to, amount); + return true; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/ERC20Pausable.sol b/contracts/token/ERC20/ERC20Pausable.sol index fd4ea8723..9f38dec39 100644 --- a/contracts/token/ERC20/ERC20Pausable.sol +++ b/contracts/token/ERC20/ERC20Pausable.sol @@ -11,65 +11,65 @@ import "../../lifecycle/Pausable.sol"; **/ contract ERC20Pausable is Initializable, ERC20, Pausable { - function initialize(address sender) public initializer { - Pausable.initialize(sender); - } + function initialize(address sender) public initializer { + Pausable.initialize(sender); + } - function transfer( - address to, - uint256 value - ) - public - whenNotPaused - returns (bool) - { - return super.transfer(to, value); - } + function transfer( + address to, + uint256 value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(to, value); + } - function transferFrom( - address from, - address to, - uint256 value - ) - public - whenNotPaused - returns (bool) - { - return super.transferFrom(from, to, value); - } + function transferFrom( + address from, + address to, + uint256 value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(from, to, value); + } - function approve( - address spender, - uint256 value - ) - public - whenNotPaused - returns (bool) - { - return super.approve(spender, value); - } + function approve( + address spender, + uint256 value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(spender, value); + } - function increaseAllowance( - address spender, - uint addedValue - ) - public - whenNotPaused - returns (bool success) - { - return super.increaseAllowance(spender, addedValue); - } + function increaseAllowance( + address spender, + uint addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseAllowance(spender, addedValue); + } - function decreaseAllowance( - address spender, - uint subtractedValue - ) - public - whenNotPaused - returns (bool success) - { - return super.decreaseAllowance(spender, subtractedValue); - } + function decreaseAllowance( + address spender, + uint subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseAllowance(spender, subtractedValue); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC20/IERC20.sol b/contracts/token/ERC20/IERC20.sol index 34d68fd62..3c111b412 100644 --- a/contracts/token/ERC20/IERC20.sol +++ b/contracts/token/ERC20/IERC20.sol @@ -6,30 +6,30 @@ pragma solidity ^0.4.24; * @dev see https://github.com/ethereum/EIPs/issues/20 */ interface IERC20 { - function totalSupply() external view returns (uint256); + function totalSupply() external view returns (uint256); - function balanceOf(address who) external view returns (uint256); + function balanceOf(address who) external view returns (uint256); - function allowance(address owner, address spender) - external view returns (uint256); + function allowance(address owner, address spender) + external view returns (uint256); - function transfer(address to, uint256 value) external returns (bool); + function transfer(address to, uint256 value) external returns (bool); - function approve(address spender, uint256 value) - external returns (bool); + function approve(address spender, uint256 value) + external returns (bool); - function transferFrom(address from, address to, uint256 value) - external returns (bool); + function transferFrom(address from, address to, uint256 value) + external returns (bool); - event Transfer( - address indexed from, - address indexed to, - uint256 value - ); + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); - event Approval( - address indexed owner, - address indexed spender, - uint256 value - ); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); } diff --git a/contracts/token/ERC20/SafeERC20.sol b/contracts/token/ERC20/SafeERC20.sol index 48b15fba9..bbc8914a2 100644 --- a/contracts/token/ERC20/SafeERC20.sol +++ b/contracts/token/ERC20/SafeERC20.sol @@ -11,34 +11,34 @@ import "./IERC20.sol"; * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { - function safeTransfer( - IERC20 token, - address to, - uint256 value - ) - internal - { - require(token.transfer(to, value)); - } + function safeTransfer( + IERC20 token, + address to, + uint256 value + ) + internal + { + require(token.transfer(to, value)); + } - function safeTransferFrom( - IERC20 token, - address from, - address to, - uint256 value - ) - internal - { - require(token.transferFrom(from, to, value)); - } + function safeTransferFrom( + IERC20 token, + address from, + address to, + uint256 value + ) + internal + { + require(token.transferFrom(from, to, value)); + } - function safeApprove( - IERC20 token, - address spender, - uint256 value - ) - internal - { - require(token.approve(spender, value)); - } + function safeApprove( + IERC20 token, + address spender, + uint256 value + ) + internal + { + require(token.approve(spender, value)); + } } diff --git a/contracts/token/ERC20/StandaloneERC20.sol b/contracts/token/ERC20/StandaloneERC20.sol index aa15c77c5..49e831c1d 100644 --- a/contracts/token/ERC20/StandaloneERC20.sol +++ b/contracts/token/ERC20/StandaloneERC20.sol @@ -11,55 +11,55 @@ import "./ERC20Pausable.sol"; * */ contract StandaloneERC20 is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable { - function initialize( - string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, - address[] minters, address[] pausers - ) public initializer { - require(initialSupply > 0); + function initialize( + string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, + address[] minters, address[] pausers + ) public initializer { + require(initialSupply > 0); - ERC20Detailed.initialize(name, symbol, decimals); + ERC20Detailed.initialize(name, symbol, decimals); - // Mint the initial supply - _mint(initialHolder, initialSupply); + // Mint the initial supply + _mint(initialHolder, initialSupply); - // Initialize the minter and pauser roles, and renounce them - ERC20Mintable.initialize(address(this)); - renounceMinter(); + // Initialize the minter and pauser roles, and renounce them + ERC20Mintable.initialize(address(this)); + renounceMinter(); - ERC20Pausable.initialize(address(this)); - renouncePauser(); + ERC20Pausable.initialize(address(this)); + renouncePauser(); - // Add the requested minters and pausers (this can be done after renouncing since - // these are the internal calls) - for (uint256 i = 0; i < minters.length; ++i) { - _addMinter(minters[i]); + // Add the requested minters and pausers (this can be done after renouncing since + // these are the internal calls) + for (uint256 i = 0; i < minters.length; ++i) { + _addMinter(minters[i]); + } + + for (i = 0; i < pausers.length; ++i) { + _addPauser(pausers[i]); + } } - for (i = 0; i < pausers.length; ++i) { - _addPauser(pausers[i]); + function initialize( + string name, string symbol, uint8 decimals, address[] minters, address[] pausers + ) public initializer { + ERC20Detailed.initialize(name, symbol, decimals); + + // Initialize the minter and pauser roles, and renounce them + ERC20Mintable.initialize(address(this)); + renounceMinter(); + + ERC20Pausable.initialize(address(this)); + renouncePauser(); + + // Add the requested minters and pausers (this can be done after renouncing since + // these are the internal calls) + for (uint256 i = 0; i < minters.length; ++i) { + _addMinter(minters[i]); + } + + for (i = 0; i < pausers.length; ++i) { + _addPauser(pausers[i]); + } } - } - - function initialize( - string name, string symbol, uint8 decimals, address[] minters, address[] pausers - ) public initializer { - ERC20Detailed.initialize(name, symbol, decimals); - - // Initialize the minter and pauser roles, and renounce them - ERC20Mintable.initialize(address(this)); - renounceMinter(); - - ERC20Pausable.initialize(address(this)); - renouncePauser(); - - // Add the requested minters and pausers (this can be done after renouncing since - // these are the internal calls) - for (uint256 i = 0; i < minters.length; ++i) { - _addMinter(minters[i]); - } - - for (i = 0; i < pausers.length; ++i) { - _addPauser(pausers[i]); - } - } } diff --git a/contracts/token/ERC20/TokenTimelock.sol b/contracts/token/ERC20/TokenTimelock.sol index 3f9347798..a0c9f2ff5 100644 --- a/contracts/token/ERC20/TokenTimelock.sol +++ b/contracts/token/ERC20/TokenTimelock.sol @@ -10,65 +10,65 @@ import "./SafeERC20.sol"; * beneficiary to extract the tokens after a given release time */ contract TokenTimelock is Initializable { - using SafeERC20 for IERC20; + using SafeERC20 for IERC20; - // ERC20 basic token contract being held - IERC20 private _token; + // ERC20 basic token contract being held + IERC20 private _token; - // beneficiary of tokens after they are released - address private _beneficiary; + // beneficiary of tokens after they are released + address private _beneficiary; - // timestamp when token release is enabled - uint256 private _releaseTime; + // timestamp when token release is enabled + uint256 private _releaseTime; - function initialize( - IERC20 token, - address beneficiary, - uint256 releaseTime - ) - public - initializer - { - // solium-disable-next-line security/no-block-members - require(releaseTime > block.timestamp); - _token = token; - _beneficiary = beneficiary; - _releaseTime = releaseTime; - } + function initialize( + IERC20 token, + address beneficiary, + uint256 releaseTime + ) + public + initializer + { + // solium-disable-next-line security/no-block-members + require(releaseTime > block.timestamp); + _token = token; + _beneficiary = beneficiary; + _releaseTime = releaseTime; + } - /** - * @return the token being held. - */ - function token() public view returns(IERC20) { - return _token; - } + /** + * @return the token being held. + */ + function token() public view returns(IERC20) { + return _token; + } - /** - * @return the beneficiary of the tokens. - */ - function beneficiary() public view returns(address) { - return _beneficiary; - } + /** + * @return the beneficiary of the tokens. + */ + function beneficiary() public view returns(address) { + return _beneficiary; + } - /** - * @return the time when the tokens are released. - */ - function releaseTime() public view returns(uint256) { - return _releaseTime; - } + /** + * @return the time when the tokens are released. + */ + function releaseTime() public view returns(uint256) { + return _releaseTime; + } - /** - * @notice Transfers tokens held by timelock to beneficiary. - */ - function release() public { - // solium-disable-next-line security/no-block-members - require(block.timestamp >= _releaseTime); + /** + * @notice Transfers tokens held by timelock to beneficiary. + */ + function release() public { + // solium-disable-next-line security/no-block-members + require(block.timestamp >= _releaseTime); - uint256 amount = _token.balanceOf(address(this)); - require(amount > 0); + uint256 amount = _token.balanceOf(address(this)); + require(amount > 0); - _token.safeTransfer(_beneficiary, amount); - } + _token.safeTransfer(_beneficiary, amount); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index 9f81b81a1..05a495d53 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -14,323 +14,323 @@ import "../../introspection/ERC165.sol"; */ contract ERC721 is Initializable, ERC165, IERC721 { - using SafeMath for uint256; - using Address for address; + using SafeMath for uint256; + using Address for address; - // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` - // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` - bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; + // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` + // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` + bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; - // Mapping from token ID to owner - mapping (uint256 => address) private _tokenOwner; + // Mapping from token ID to owner + mapping (uint256 => address) private _tokenOwner; - // Mapping from token ID to approved address - mapping (uint256 => address) private _tokenApprovals; + // Mapping from token ID to approved address + mapping (uint256 => address) private _tokenApprovals; - // Mapping from owner to number of owned token - mapping (address => uint256) private _ownedTokensCount; + // Mapping from owner to number of owned token + mapping (address => uint256) private _ownedTokensCount; - // Mapping from owner to operator approvals - mapping (address => mapping (address => bool)) private _operatorApprovals; + // Mapping from owner to operator approvals + mapping (address => mapping (address => bool)) private _operatorApprovals; - bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ + bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; + /* + * 0x80ac58cd === + * bytes4(keccak256('balanceOf(address)')) ^ + * bytes4(keccak256('ownerOf(uint256)')) ^ + * bytes4(keccak256('approve(address,uint256)')) ^ + * bytes4(keccak256('getApproved(uint256)')) ^ + * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ + * bytes4(keccak256('isApprovedForAll(address,address)')) ^ + * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ + * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ + * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) + */ - function initialize() - public - initializer - { - ERC165.initialize(); + function initialize() + public + initializer + { + ERC165.initialize(); - // register the supported interfaces to conform to ERC721 via ERC165 - _registerInterface(_InterfaceId_ERC721); - } - - function _hasBeenInitialized() internal view returns (bool) { - return supportsInterface(_InterfaceId_ERC721); - } - - /** - * @dev Gets the balance of the specified address - * @param owner address to query the balance of - * @return uint256 representing the amount owned by the passed address - */ - function balanceOf(address owner) public view returns (uint256) { - require(owner != address(0)); - return _ownedTokensCount[owner]; - } - - /** - * @dev Gets the owner of the specified token ID - * @param tokenId uint256 ID of the token to query the owner of - * @return owner address currently marked as the owner of the given token ID - */ - function ownerOf(uint256 tokenId) public view returns (address) { - address owner = _tokenOwner[tokenId]; - require(owner != address(0)); - return owner; - } - - /** - * @dev Approves another address to transfer the given token ID - * The zero address indicates there is no approved address. - * There can only be one approved address per token at a given time. - * Can only be called by the token owner or an approved operator. - * @param to address to be approved for the given token ID - * @param tokenId uint256 ID of the token to be approved - */ - function approve(address to, uint256 tokenId) public { - address owner = ownerOf(tokenId); - require(to != owner); - require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); - - _tokenApprovals[tokenId] = to; - emit Approval(owner, to, tokenId); - } - - /** - * @dev Gets the approved address for a token ID, or zero if no address set - * Reverts if the token ID does not exist. - * @param tokenId uint256 ID of the token to query the approval of - * @return address currently approved for the given token ID - */ - function getApproved(uint256 tokenId) public view returns (address) { - require(_exists(tokenId)); - return _tokenApprovals[tokenId]; - } - - /** - * @dev Sets or unsets the approval of a given operator - * An operator is allowed to transfer all tokens of the sender on their behalf - * @param to operator address to set the approval - * @param approved representing the status of the approval to be set - */ - function setApprovalForAll(address to, bool approved) public { - require(to != msg.sender); - _operatorApprovals[msg.sender][to] = approved; - emit ApprovalForAll(msg.sender, to, approved); - } - - /** - * @dev Tells whether an operator is approved by a given owner - * @param owner owner address which you want to query the approval of - * @param operator operator address which you want to query the approval of - * @return bool whether the given operator is approved by the given owner - */ - function isApprovedForAll( - address owner, - address operator - ) - public - view - returns (bool) - { - return _operatorApprovals[owner][operator]; - } - - /** - * @dev Transfers the ownership of a given token ID to another address - * Usage of this method is discouraged, use `safeTransferFrom` whenever possible - * Requires the msg sender to be the owner, approved, or operator - * @param from current owner of the token - * @param to address to receive the ownership of the given token ID - * @param tokenId uint256 ID of the token to be transferred - */ - function transferFrom( - address from, - address to, - uint256 tokenId - ) - public - { - require(_isApprovedOrOwner(msg.sender, tokenId)); - require(to != address(0)); - - _clearApproval(from, tokenId); - _removeTokenFrom(from, tokenId); - _addTokenTo(to, tokenId); - - emit Transfer(from, to, tokenId); - } - - /** - * @dev Safely transfers the ownership of a given token ID to another address - * If the target address is a contract, it must implement `onERC721Received`, - * which is called upon a safe transfer, and return the magic value - * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, - * the transfer is reverted. - * - * Requires the msg sender to be the owner, approved, or operator - * @param from current owner of the token - * @param to address to receive the ownership of the given token ID - * @param tokenId uint256 ID of the token to be transferred - */ - function safeTransferFrom( - address from, - address to, - uint256 tokenId - ) - public - { - // solium-disable-next-line arg-overflow - safeTransferFrom(from, to, tokenId, ""); - } - - /** - * @dev Safely transfers the ownership of a given token ID to another address - * If the target address is a contract, it must implement `onERC721Received`, - * which is called upon a safe transfer, and return the magic value - * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, - * the transfer is reverted. - * Requires the msg sender to be the owner, approved, or operator - * @param from current owner of the token - * @param to address to receive the ownership of the given token ID - * @param tokenId uint256 ID of the token to be transferred - * @param _data bytes data to send along with a safe transfer check - */ - function safeTransferFrom( - address from, - address to, - uint256 tokenId, - bytes _data - ) - public - { - transferFrom(from, to, tokenId); - // solium-disable-next-line arg-overflow - require(_checkAndCallSafeTransfer(from, to, tokenId, _data)); - } - - /** - * @dev Returns whether the specified token exists - * @param tokenId uint256 ID of the token to query the existence of - * @return whether the token exists - */ - function _exists(uint256 tokenId) internal view returns (bool) { - address owner = _tokenOwner[tokenId]; - return owner != address(0); - } - - /** - * @dev Returns whether the given spender can transfer a given token ID - * @param spender address of the spender to query - * @param tokenId uint256 ID of the token to be transferred - * @return bool whether the msg.sender is approved for the given token ID, - * is an operator of the owner, or is the owner of the token - */ - function _isApprovedOrOwner( - address spender, - uint256 tokenId - ) - internal - view - returns (bool) - { - address owner = ownerOf(tokenId); - // Disable solium check because of - // https://github.com/duaraghav8/Solium/issues/175 - // solium-disable-next-line operator-whitespace - return ( - spender == owner || - getApproved(tokenId) == spender || - isApprovedForAll(owner, spender) - ); - } - - /** - * @dev Internal function to mint a new token - * Reverts if the given token ID already exists - * @param to The address that will own the minted token - * @param tokenId uint256 ID of the token to be minted by the msg.sender - */ - function _mint(address to, uint256 tokenId) internal { - require(to != address(0)); - _addTokenTo(to, tokenId); - emit Transfer(address(0), to, tokenId); - } - - /** - * @dev Internal function to burn a specific token - * Reverts if the token does not exist - * @param tokenId uint256 ID of the token being burned by the msg.sender - */ - function _burn(address owner, uint256 tokenId) internal { - _clearApproval(owner, tokenId); - _removeTokenFrom(owner, tokenId); - emit Transfer(owner, address(0), tokenId); - } - - /** - * @dev Internal function to clear current approval of a given token ID - * Reverts if the given address is not indeed the owner of the token - * @param owner owner of the token - * @param tokenId uint256 ID of the token to be transferred - */ - function _clearApproval(address owner, uint256 tokenId) internal { - require(ownerOf(tokenId) == owner); - if (_tokenApprovals[tokenId] != address(0)) { - _tokenApprovals[tokenId] = address(0); + // register the supported interfaces to conform to ERC721 via ERC165 + _registerInterface(_InterfaceId_ERC721); } - } - /** - * @dev Internal function to add a token ID to the list of a given address - * @param to address representing the new owner of the given token ID - * @param tokenId uint256 ID of the token to be added to the tokens list of the given address - */ - function _addTokenTo(address to, uint256 tokenId) internal { - require(_tokenOwner[tokenId] == address(0)); - _tokenOwner[tokenId] = to; - _ownedTokensCount[to] = _ownedTokensCount[to].add(1); - } - - /** - * @dev Internal function to remove a token ID from the list of a given address - * @param from address representing the previous owner of the given token ID - * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address - */ - function _removeTokenFrom(address from, uint256 tokenId) internal { - require(ownerOf(tokenId) == from); - _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); - _tokenOwner[tokenId] = address(0); - } - - /** - * @dev Internal function to invoke `onERC721Received` on a target address - * The call is not executed if the target address is not a contract - * @param from address representing the previous owner of the given token ID - * @param to target address that will receive the tokens - * @param tokenId uint256 ID of the token to be transferred - * @param _data bytes optional data to send along with the call - * @return whether the call correctly returned the expected magic value - */ - function _checkAndCallSafeTransfer( - address from, - address to, - uint256 tokenId, - bytes _data - ) - internal - returns (bool) - { - if (!to.isContract()) { - return true; + function _hasBeenInitialized() internal view returns (bool) { + return supportsInterface(_InterfaceId_ERC721); } - bytes4 retval = IERC721Receiver(to).onERC721Received( - msg.sender, from, tokenId, _data); - return (retval == _ERC721_RECEIVED); - } - uint256[50] private ______gap; + /** + * @dev Gets the balance of the specified address + * @param owner address to query the balance of + * @return uint256 representing the amount owned by the passed address + */ + function balanceOf(address owner) public view returns (uint256) { + require(owner != address(0)); + return _ownedTokensCount[owner]; + } + + /** + * @dev Gets the owner of the specified token ID + * @param tokenId uint256 ID of the token to query the owner of + * @return owner address currently marked as the owner of the given token ID + */ + function ownerOf(uint256 tokenId) public view returns (address) { + address owner = _tokenOwner[tokenId]; + require(owner != address(0)); + return owner; + } + + /** + * @dev Approves another address to transfer the given token ID + * The zero address indicates there is no approved address. + * There can only be one approved address per token at a given time. + * Can only be called by the token owner or an approved operator. + * @param to address to be approved for the given token ID + * @param tokenId uint256 ID of the token to be approved + */ + function approve(address to, uint256 tokenId) public { + address owner = ownerOf(tokenId); + require(to != owner); + require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); + + _tokenApprovals[tokenId] = to; + emit Approval(owner, to, tokenId); + } + + /** + * @dev Gets the approved address for a token ID, or zero if no address set + * Reverts if the token ID does not exist. + * @param tokenId uint256 ID of the token to query the approval of + * @return address currently approved for the given token ID + */ + function getApproved(uint256 tokenId) public view returns (address) { + require(_exists(tokenId)); + return _tokenApprovals[tokenId]; + } + + /** + * @dev Sets or unsets the approval of a given operator + * An operator is allowed to transfer all tokens of the sender on their behalf + * @param to operator address to set the approval + * @param approved representing the status of the approval to be set + */ + function setApprovalForAll(address to, bool approved) public { + require(to != msg.sender); + _operatorApprovals[msg.sender][to] = approved; + emit ApprovalForAll(msg.sender, to, approved); + } + + /** + * @dev Tells whether an operator is approved by a given owner + * @param owner owner address which you want to query the approval of + * @param operator operator address which you want to query the approval of + * @return bool whether the given operator is approved by the given owner + */ + function isApprovedForAll( + address owner, + address operator + ) + public + view + returns (bool) + { + return _operatorApprovals[owner][operator]; + } + + /** + * @dev Transfers the ownership of a given token ID to another address + * Usage of this method is discouraged, use `safeTransferFrom` whenever possible + * Requires the msg sender to be the owner, approved, or operator + * @param from current owner of the token + * @param to address to receive the ownership of the given token ID + * @param tokenId uint256 ID of the token to be transferred + */ + function transferFrom( + address from, + address to, + uint256 tokenId + ) + public + { + require(_isApprovedOrOwner(msg.sender, tokenId)); + require(to != address(0)); + + _clearApproval(from, tokenId); + _removeTokenFrom(from, tokenId); + _addTokenTo(to, tokenId); + + emit Transfer(from, to, tokenId); + } + + /** + * @dev Safely transfers the ownership of a given token ID to another address + * If the target address is a contract, it must implement `onERC721Received`, + * which is called upon a safe transfer, and return the magic value + * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, + * the transfer is reverted. + * + * Requires the msg sender to be the owner, approved, or operator + * @param from current owner of the token + * @param to address to receive the ownership of the given token ID + * @param tokenId uint256 ID of the token to be transferred + */ + function safeTransferFrom( + address from, + address to, + uint256 tokenId + ) + public + { + // solium-disable-next-line arg-overflow + safeTransferFrom(from, to, tokenId, ""); + } + + /** + * @dev Safely transfers the ownership of a given token ID to another address + * If the target address is a contract, it must implement `onERC721Received`, + * which is called upon a safe transfer, and return the magic value + * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, + * the transfer is reverted. + * Requires the msg sender to be the owner, approved, or operator + * @param from current owner of the token + * @param to address to receive the ownership of the given token ID + * @param tokenId uint256 ID of the token to be transferred + * @param _data bytes data to send along with a safe transfer check + */ + function safeTransferFrom( + address from, + address to, + uint256 tokenId, + bytes _data + ) + public + { + transferFrom(from, to, tokenId); + // solium-disable-next-line arg-overflow + require(_checkAndCallSafeTransfer(from, to, tokenId, _data)); + } + + /** + * @dev Returns whether the specified token exists + * @param tokenId uint256 ID of the token to query the existence of + * @return whether the token exists + */ + function _exists(uint256 tokenId) internal view returns (bool) { + address owner = _tokenOwner[tokenId]; + return owner != address(0); + } + + /** + * @dev Returns whether the given spender can transfer a given token ID + * @param spender address of the spender to query + * @param tokenId uint256 ID of the token to be transferred + * @return bool whether the msg.sender is approved for the given token ID, + * is an operator of the owner, or is the owner of the token + */ + function _isApprovedOrOwner( + address spender, + uint256 tokenId + ) + internal + view + returns (bool) + { + address owner = ownerOf(tokenId); + // Disable solium check because of + // https://github.com/duaraghav8/Solium/issues/175 + // solium-disable-next-line operator-whitespace + return ( + spender == owner || + getApproved(tokenId) == spender || + isApprovedForAll(owner, spender) + ); + } + + /** + * @dev Internal function to mint a new token + * Reverts if the given token ID already exists + * @param to The address that will own the minted token + * @param tokenId uint256 ID of the token to be minted by the msg.sender + */ + function _mint(address to, uint256 tokenId) internal { + require(to != address(0)); + _addTokenTo(to, tokenId); + emit Transfer(address(0), to, tokenId); + } + + /** + * @dev Internal function to burn a specific token + * Reverts if the token does not exist + * @param tokenId uint256 ID of the token being burned by the msg.sender + */ + function _burn(address owner, uint256 tokenId) internal { + _clearApproval(owner, tokenId); + _removeTokenFrom(owner, tokenId); + emit Transfer(owner, address(0), tokenId); + } + + /** + * @dev Internal function to clear current approval of a given token ID + * Reverts if the given address is not indeed the owner of the token + * @param owner owner of the token + * @param tokenId uint256 ID of the token to be transferred + */ + function _clearApproval(address owner, uint256 tokenId) internal { + require(ownerOf(tokenId) == owner); + if (_tokenApprovals[tokenId] != address(0)) { + _tokenApprovals[tokenId] = address(0); + } + } + + /** + * @dev Internal function to add a token ID to the list of a given address + * @param to address representing the new owner of the given token ID + * @param tokenId uint256 ID of the token to be added to the tokens list of the given address + */ + function _addTokenTo(address to, uint256 tokenId) internal { + require(_tokenOwner[tokenId] == address(0)); + _tokenOwner[tokenId] = to; + _ownedTokensCount[to] = _ownedTokensCount[to].add(1); + } + + /** + * @dev Internal function to remove a token ID from the list of a given address + * @param from address representing the previous owner of the given token ID + * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address + */ + function _removeTokenFrom(address from, uint256 tokenId) internal { + require(ownerOf(tokenId) == from); + _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); + _tokenOwner[tokenId] = address(0); + } + + /** + * @dev Internal function to invoke `onERC721Received` on a target address + * The call is not executed if the target address is not a contract + * @param from address representing the previous owner of the given token ID + * @param to target address that will receive the tokens + * @param tokenId uint256 ID of the token to be transferred + * @param _data bytes optional data to send along with the call + * @return whether the call correctly returned the expected magic value + */ + function _checkAndCallSafeTransfer( + address from, + address to, + uint256 tokenId, + bytes _data + ) + internal + returns (bool) + { + if (!to.isContract()) { + return true; + } + bytes4 retval = IERC721Receiver(to).onERC721Received( + msg.sender, from, tokenId, _data); + return (retval == _ERC721_RECEIVED); + } + + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Burnable.sol b/contracts/token/ERC721/ERC721Burnable.sol index 668579ff6..32749b6a3 100644 --- a/contracts/token/ERC721/ERC721Burnable.sol +++ b/contracts/token/ERC721/ERC721Burnable.sol @@ -5,12 +5,12 @@ import "./ERC721.sol"; contract ERC721Burnable is Initializable, ERC721 { - function burn(uint256 tokenId) - public - { - require(_isApprovedOrOwner(msg.sender, tokenId)); - _burn(ownerOf(tokenId), tokenId); - } + function burn(uint256 tokenId) + public + { + require(_isApprovedOrOwner(msg.sender, tokenId)); + _burn(ownerOf(tokenId), tokenId); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Enumerable.sol b/contracts/token/ERC721/ERC721Enumerable.sol index cd04f128f..39584ae04 100644 --- a/contracts/token/ERC721/ERC721Enumerable.sol +++ b/contracts/token/ERC721/ERC721Enumerable.sol @@ -7,149 +7,149 @@ import "../../introspection/ERC165.sol"; contract ERC721Enumerable is Initializable, ERC165, ERC721, IERC721Enumerable { - // Mapping from owner to list of owned token IDs - mapping(address => uint256[]) private _ownedTokens; + // Mapping from owner to list of owned token IDs + mapping(address => uint256[]) private _ownedTokens; - // Mapping from token ID to index of the owner tokens list - mapping(uint256 => uint256) private _ownedTokensIndex; + // Mapping from token ID to index of the owner tokens list + mapping(uint256 => uint256) private _ownedTokensIndex; - // Array with all token ids, used for enumeration - uint256[] private _allTokens; + // Array with all token ids, used for enumeration + uint256[] private _allTokens; - // Mapping from token id to position in the allTokens array - mapping(uint256 => uint256) private _allTokensIndex; + // Mapping from token id to position in the allTokens array + mapping(uint256 => uint256) private _allTokensIndex; - bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ + bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; + /** + * 0x780e9d63 === + * bytes4(keccak256('totalSupply()')) ^ + * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ + * bytes4(keccak256('tokenByIndex(uint256)')) + */ - /** - * @dev Constructor function - */ - function initialize() public initializer { - require(ERC721._hasBeenInitialized()); + /** + * @dev Constructor function + */ + function initialize() public initializer { + require(ERC721._hasBeenInitialized()); - // register the supported interface to conform to ERC721 via ERC165 - _registerInterface(_InterfaceId_ERC721Enumerable); - } + // register the supported interface to conform to ERC721 via ERC165 + _registerInterface(_InterfaceId_ERC721Enumerable); + } - function _hasBeenInitialized() internal view returns (bool) { - return supportsInterface(_InterfaceId_ERC721Enumerable); - } + function _hasBeenInitialized() internal view returns (bool) { + return supportsInterface(_InterfaceId_ERC721Enumerable); + } - /** - * @dev Gets the token ID at a given index of the tokens list of the requested owner - * @param owner address owning the tokens list to be accessed - * @param index uint256 representing the index to be accessed of the requested tokens list - * @return uint256 token ID at the given index of the tokens list owned by the requested address - */ - function tokenOfOwnerByIndex( - address owner, - uint256 index - ) - public - view - returns (uint256) - { - require(index < balanceOf(owner)); - return _ownedTokens[owner][index]; - } + /** + * @dev Gets the token ID at a given index of the tokens list of the requested owner + * @param owner address owning the tokens list to be accessed + * @param index uint256 representing the index to be accessed of the requested tokens list + * @return uint256 token ID at the given index of the tokens list owned by the requested address + */ + function tokenOfOwnerByIndex( + address owner, + uint256 index + ) + public + view + returns (uint256) + { + require(index < balanceOf(owner)); + return _ownedTokens[owner][index]; + } - /** - * @dev Gets the total amount of tokens stored by the contract - * @return uint256 representing the total amount of tokens - */ - function totalSupply() public view returns (uint256) { - return _allTokens.length; - } + /** + * @dev Gets the total amount of tokens stored by the contract + * @return uint256 representing the total amount of tokens + */ + function totalSupply() public view returns (uint256) { + return _allTokens.length; + } - /** - * @dev Gets the token ID at a given index of all the tokens in this contract - * Reverts if the index is greater or equal to the total number of tokens - * @param index uint256 representing the index to be accessed of the tokens list - * @return uint256 token ID at the given index of the tokens list - */ - function tokenByIndex(uint256 index) public view returns (uint256) { - require(index < totalSupply()); - return _allTokens[index]; - } + /** + * @dev Gets the token ID at a given index of all the tokens in this contract + * Reverts if the index is greater or equal to the total number of tokens + * @param index uint256 representing the index to be accessed of the tokens list + * @return uint256 token ID at the given index of the tokens list + */ + function tokenByIndex(uint256 index) public view returns (uint256) { + require(index < totalSupply()); + return _allTokens[index]; + } - /** - * @dev Internal function to add a token ID to the list of a given address - * @param to address representing the new owner of the given token ID - * @param tokenId uint256 ID of the token to be added to the tokens list of the given address - */ - function _addTokenTo(address to, uint256 tokenId) internal { - super._addTokenTo(to, tokenId); - uint256 length = _ownedTokens[to].length; - _ownedTokens[to].push(tokenId); - _ownedTokensIndex[tokenId] = length; - } + /** + * @dev Internal function to add a token ID to the list of a given address + * @param to address representing the new owner of the given token ID + * @param tokenId uint256 ID of the token to be added to the tokens list of the given address + */ + function _addTokenTo(address to, uint256 tokenId) internal { + super._addTokenTo(to, tokenId); + uint256 length = _ownedTokens[to].length; + _ownedTokens[to].push(tokenId); + _ownedTokensIndex[tokenId] = length; + } - /** - * @dev Internal function to remove a token ID from the list of a given address - * @param from address representing the previous owner of the given token ID - * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address - */ - function _removeTokenFrom(address from, uint256 tokenId) internal { - super._removeTokenFrom(from, tokenId); + /** + * @dev Internal function to remove a token ID from the list of a given address + * @param from address representing the previous owner of the given token ID + * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address + */ + function _removeTokenFrom(address from, uint256 tokenId) internal { + super._removeTokenFrom(from, tokenId); - // To prevent a gap in the array, we store the last token in the index of the token to delete, and - // then delete the last slot. - uint256 tokenIndex = _ownedTokensIndex[tokenId]; - uint256 lastTokenIndex = _ownedTokens[from].length.sub(1); - uint256 lastToken = _ownedTokens[from][lastTokenIndex]; + // To prevent a gap in the array, we store the last token in the index of the token to delete, and + // then delete the last slot. + uint256 tokenIndex = _ownedTokensIndex[tokenId]; + uint256 lastTokenIndex = _ownedTokens[from].length.sub(1); + uint256 lastToken = _ownedTokens[from][lastTokenIndex]; - _ownedTokens[from][tokenIndex] = lastToken; - // This also deletes the contents at the last position of the array - _ownedTokens[from].length--; + _ownedTokens[from][tokenIndex] = lastToken; + // This also deletes the contents at the last position of the array + _ownedTokens[from].length--; - // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to - // be zero. Then we can make sure that we will remove tokenId from the ownedTokens list since we are first swapping - // the lastToken to the first position, and then dropping the element placed in the last position of the list + // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to + // be zero. Then we can make sure that we will remove tokenId from the ownedTokens list since we are first swapping + // the lastToken to the first position, and then dropping the element placed in the last position of the list - _ownedTokensIndex[tokenId] = 0; - _ownedTokensIndex[lastToken] = tokenIndex; - } + _ownedTokensIndex[tokenId] = 0; + _ownedTokensIndex[lastToken] = tokenIndex; + } - /** - * @dev Internal function to mint a new token - * Reverts if the given token ID already exists - * @param to address the beneficiary that will own the minted token - * @param tokenId uint256 ID of the token to be minted by the msg.sender - */ - function _mint(address to, uint256 tokenId) internal { - super._mint(to, tokenId); + /** + * @dev Internal function to mint a new token + * Reverts if the given token ID already exists + * @param to address the beneficiary that will own the minted token + * @param tokenId uint256 ID of the token to be minted by the msg.sender + */ + function _mint(address to, uint256 tokenId) internal { + super._mint(to, tokenId); - _allTokensIndex[tokenId] = _allTokens.length; - _allTokens.push(tokenId); - } + _allTokensIndex[tokenId] = _allTokens.length; + _allTokens.push(tokenId); + } - /** - * @dev Internal function to burn a specific token - * Reverts if the token does not exist - * @param owner owner of the token to burn - * @param tokenId uint256 ID of the token being burned by the msg.sender - */ - function _burn(address owner, uint256 tokenId) internal { - super._burn(owner, tokenId); + /** + * @dev Internal function to burn a specific token + * Reverts if the token does not exist + * @param owner owner of the token to burn + * @param tokenId uint256 ID of the token being burned by the msg.sender + */ + function _burn(address owner, uint256 tokenId) internal { + super._burn(owner, tokenId); - // Reorg all tokens array - uint256 tokenIndex = _allTokensIndex[tokenId]; - uint256 lastTokenIndex = _allTokens.length.sub(1); - uint256 lastToken = _allTokens[lastTokenIndex]; + // Reorg all tokens array + uint256 tokenIndex = _allTokensIndex[tokenId]; + uint256 lastTokenIndex = _allTokens.length.sub(1); + uint256 lastToken = _allTokens[lastTokenIndex]; - _allTokens[tokenIndex] = lastToken; - _allTokens[lastTokenIndex] = 0; + _allTokens[tokenIndex] = lastToken; + _allTokens[lastTokenIndex] = 0; - _allTokens.length--; - _allTokensIndex[tokenId] = 0; - _allTokensIndex[lastToken] = tokenIndex; - } + _allTokens.length--; + _allTokensIndex[tokenId] = 0; + _allTokensIndex[lastToken] = tokenIndex; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Full.sol b/contracts/token/ERC721/ERC721Full.sol index 70f5a83ab..a44c5abfe 100644 --- a/contracts/token/ERC721/ERC721Full.sol +++ b/contracts/token/ERC721/ERC721Full.sol @@ -13,5 +13,5 @@ import "./ERC721Metadata.sol"; * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */ contract ERC721Full is Initializable, ERC721, ERC721Enumerable, ERC721Metadata { - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Holder.sol b/contracts/token/ERC721/ERC721Holder.sol index 793af68f5..aa1413b6a 100644 --- a/contracts/token/ERC721/ERC721Holder.sol +++ b/contracts/token/ERC721/ERC721Holder.sol @@ -5,17 +5,17 @@ import "./IERC721Receiver.sol"; contract ERC721Holder is Initializable, IERC721Receiver { - function onERC721Received( - address, - address, - uint256, - bytes - ) - public - returns(bytes4) - { - return this.onERC721Received.selector; - } + function onERC721Received( + address, + address, + uint256, + bytes + ) + public + returns(bytes4) + { + return this.onERC721Received.selector; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Metadata.sol b/contracts/token/ERC721/ERC721Metadata.sol index c5e009819..038d78656 100644 --- a/contracts/token/ERC721/ERC721Metadata.sol +++ b/contracts/token/ERC721/ERC721Metadata.sol @@ -7,91 +7,91 @@ import "../../introspection/ERC165.sol"; contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata { - // Token name - string internal _name; + // Token name + string internal _name; - // Token symbol - string internal _symbol; + // Token symbol + string internal _symbol; - // Optional mapping for token URIs - mapping(uint256 => string) private _tokenURIs; + // Optional mapping for token URIs + mapping(uint256 => string) private _tokenURIs; - bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ + bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; + /** + * 0x5b5e139f === + * bytes4(keccak256('name()')) ^ + * bytes4(keccak256('symbol()')) ^ + * bytes4(keccak256('tokenURI(uint256)')) + */ - /** - * @dev Constructor function - */ - function initialize(string name, string symbol) public initializer { - require(ERC721._hasBeenInitialized()); + /** + * @dev Constructor function + */ + function initialize(string name, string symbol) public initializer { + require(ERC721._hasBeenInitialized()); - _name = name; - _symbol = symbol; + _name = name; + _symbol = symbol; - // register the supported interfaces to conform to ERC721 via ERC165 - _registerInterface(InterfaceId_ERC721Metadata); - } - - function _hasBeenInitialized() internal view returns (bool) { - return supportsInterface(InterfaceId_ERC721Metadata); - } - - /** - * @dev Gets the token name - * @return string representing the token name - */ - function name() external view returns (string) { - return _name; - } - - /** - * @dev Gets the token symbol - * @return string representing the token symbol - */ - function symbol() external view returns (string) { - return _symbol; - } - - /** - * @dev Returns an URI for a given token ID - * 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) { - require(_exists(tokenId)); - return _tokenURIs[tokenId]; - } - - /** - * @dev Internal function to set the token URI for a given token - * Reverts if the token ID does not exist - * @param tokenId uint256 ID of the token to set its URI - * @param uri string URI to assign - */ - function _setTokenURI(uint256 tokenId, string uri) internal { - require(_exists(tokenId)); - _tokenURIs[tokenId] = uri; - } - - /** - * @dev Internal function to burn a specific token - * Reverts if the token does not exist - * @param owner owner of the token to burn - * @param tokenId uint256 ID of the token being burned by the msg.sender - */ - function _burn(address owner, uint256 tokenId) internal { - super._burn(owner, tokenId); - - // Clear metadata (if any) - if (bytes(_tokenURIs[tokenId]).length != 0) { - delete _tokenURIs[tokenId]; + // register the supported interfaces to conform to ERC721 via ERC165 + _registerInterface(InterfaceId_ERC721Metadata); } - } - uint256[50] private ______gap; + function _hasBeenInitialized() internal view returns (bool) { + return supportsInterface(InterfaceId_ERC721Metadata); + } + + /** + * @dev Gets the token name + * @return string representing the token name + */ + function name() external view returns (string) { + return _name; + } + + /** + * @dev Gets the token symbol + * @return string representing the token symbol + */ + function symbol() external view returns (string) { + return _symbol; + } + + /** + * @dev Returns an URI for a given token ID + * 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) { + require(_exists(tokenId)); + return _tokenURIs[tokenId]; + } + + /** + * @dev Internal function to set the token URI for a given token + * Reverts if the token ID does not exist + * @param tokenId uint256 ID of the token to set its URI + * @param uri string URI to assign + */ + function _setTokenURI(uint256 tokenId, string uri) internal { + require(_exists(tokenId)); + _tokenURIs[tokenId] = uri; + } + + /** + * @dev Internal function to burn a specific token + * Reverts if the token does not exist + * @param owner owner of the token to burn + * @param tokenId uint256 ID of the token being burned by the msg.sender + */ + function _burn(address owner, uint256 tokenId) internal { + super._burn(owner, tokenId); + + // Clear metadata (if any) + if (bytes(_tokenURIs[tokenId]).length != 0) { + delete _tokenURIs[tokenId]; + } + } + + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721MetadataMintable.sol b/contracts/token/ERC721/ERC721MetadataMintable.sol index 9a18074d2..a7b55c9f1 100644 --- a/contracts/token/ERC721/ERC721MetadataMintable.sol +++ b/contracts/token/ERC721/ERC721MetadataMintable.sol @@ -10,32 +10,32 @@ import "../../access/roles/MinterRole.sol"; * @dev ERC721 minting logic with metadata */ contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole { - function initialize(address sender) public initializer { - require(ERC721._hasBeenInitialized()); - require(ERC721Metadata._hasBeenInitialized()); - MinterRole.initialize(sender); - } + function initialize(address sender) public initializer { + require(ERC721._hasBeenInitialized()); + require(ERC721Metadata._hasBeenInitialized()); + MinterRole.initialize(sender); + } - /** - * @dev Function to mint tokens - * @param to The address that will receive the minted tokens. - * @param tokenId The token id to mint. - * @param tokenURI The token URI of the minted token. - * @return A boolean that indicates if the operation was successful. - */ - function mintWithTokenURI( - address to, - uint256 tokenId, - string tokenURI - ) - public - onlyMinter - returns (bool) - { - _mint(to, tokenId); - _setTokenURI(tokenId, tokenURI); - return true; - } + /** + * @dev Function to mint tokens + * @param to The address that will receive the minted tokens. + * @param tokenId The token id to mint. + * @param tokenURI The token URI of the minted token. + * @return A boolean that indicates if the operation was successful. + */ + function mintWithTokenURI( + address to, + uint256 tokenId, + string tokenURI + ) + public + onlyMinter + returns (bool) + { + _mint(to, tokenId); + _setTokenURI(tokenId, tokenURI); + return true; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Mintable.sol b/contracts/token/ERC721/ERC721Mintable.sol index 71b068ef4..bf452b0f1 100644 --- a/contracts/token/ERC721/ERC721Mintable.sol +++ b/contracts/token/ERC721/ERC721Mintable.sol @@ -10,28 +10,28 @@ import "../../access/roles/MinterRole.sol"; * @dev ERC721 minting logic */ contract ERC721Mintable is Initializable, ERC721, MinterRole { - function initialize(address sender) public initializer { - require(ERC721._hasBeenInitialized()); - MinterRole.initialize(sender); - } + function initialize(address sender) public initializer { + require(ERC721._hasBeenInitialized()); + MinterRole.initialize(sender); + } - /** - * @dev Function to mint tokens - * @param to The address that will receive the minted tokens. - * @param tokenId The token id to mint. - * @return A boolean that indicates if the operation was successful. - */ - function mint( - address to, - uint256 tokenId - ) - public - onlyMinter - returns (bool) - { - _mint(to, tokenId); - return true; - } + /** + * @dev Function to mint tokens + * @param to The address that will receive the minted tokens. + * @param tokenId The token id to mint. + * @return A boolean that indicates if the operation was successful. + */ + function mint( + address to, + uint256 tokenId + ) + public + onlyMinter + returns (bool) + { + _mint(to, tokenId); + return true; + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/ERC721Pausable.sol b/contracts/token/ERC721/ERC721Pausable.sol index 46fa92e57..e7dbd0054 100644 --- a/contracts/token/ERC721/ERC721Pausable.sol +++ b/contracts/token/ERC721/ERC721Pausable.sol @@ -10,41 +10,41 @@ import "../../lifecycle/Pausable.sol"; * @dev ERC721 modified with pausable transfers. **/ contract ERC721Pausable is Initializable, ERC721, Pausable { - function initialize(address sender) public initializer { - require(ERC721._hasBeenInitialized()); - Pausable.initialize(sender); - } + function initialize(address sender) public initializer { + require(ERC721._hasBeenInitialized()); + Pausable.initialize(sender); + } - function approve( - address to, - uint256 tokenId - ) - public - whenNotPaused - { - super.approve(to, tokenId); - } + function approve( + address to, + uint256 tokenId + ) + public + whenNotPaused + { + super.approve(to, tokenId); + } - function setApprovalForAll( - address to, - bool approved - ) - public - whenNotPaused - { - super.setApprovalForAll(to, approved); - } + function setApprovalForAll( + address to, + bool approved + ) + public + whenNotPaused + { + super.setApprovalForAll(to, approved); + } - function transferFrom( - address from, - address to, - uint256 tokenId - ) - public - whenNotPaused - { - super.transferFrom(from, to, tokenId); - } + function transferFrom( + address from, + address to, + uint256 tokenId + ) + public + whenNotPaused + { + super.transferFrom(from, to, tokenId); + } - uint256[50] private ______gap; + uint256[50] private ______gap; } diff --git a/contracts/token/ERC721/IERC721.sol b/contracts/token/ERC721/IERC721.sol index 521406773..200e43fa8 100644 --- a/contracts/token/ERC721/IERC721.sol +++ b/contracts/token/ERC721/IERC721.sol @@ -10,42 +10,42 @@ import "../../introspection/IERC165.sol"; */ contract IERC721 is Initializable, IERC165 { - event Transfer( - address indexed from, - address indexed to, - uint256 indexed tokenId - ); - event Approval( - address indexed owner, - address indexed approved, - uint256 indexed tokenId - ); - event ApprovalForAll( - address indexed owner, - address indexed operator, - bool approved - ); + event Transfer( + address indexed from, + address indexed to, + uint256 indexed tokenId + ); + event Approval( + address indexed owner, + address indexed approved, + uint256 indexed tokenId + ); + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); - function balanceOf(address owner) public view returns (uint256 balance); - function ownerOf(uint256 tokenId) public view returns (address owner); + function balanceOf(address owner) public view returns (uint256 balance); + function ownerOf(uint256 tokenId) public view returns (address owner); - function approve(address to, uint256 tokenId) public; - function getApproved(uint256 tokenId) - public view returns (address operator); + function approve(address to, uint256 tokenId) public; + function getApproved(uint256 tokenId) + public view returns (address operator); - function setApprovalForAll(address operator, bool _approved) public; - function isApprovedForAll(address owner, address operator) - public view returns (bool); + function setApprovalForAll(address operator, bool _approved) public; + function isApprovedForAll(address owner, address operator) + public view returns (bool); - function transferFrom(address from, address to, uint256 tokenId) public; - function safeTransferFrom(address from, address to, uint256 tokenId) - public; + function transferFrom(address from, address to, uint256 tokenId) public; + function safeTransferFrom(address from, address to, uint256 tokenId) + public; - function safeTransferFrom( - address from, - address to, - uint256 tokenId, - bytes data - ) - public; + function safeTransferFrom( + address from, + address to, + uint256 tokenId, + bytes data + ) + public; } diff --git a/contracts/token/ERC721/IERC721Enumerable.sol b/contracts/token/ERC721/IERC721Enumerable.sol index 9290e21af..d09479781 100644 --- a/contracts/token/ERC721/IERC721Enumerable.sol +++ b/contracts/token/ERC721/IERC721Enumerable.sol @@ -9,14 +9,14 @@ import "./IERC721.sol"; * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */ contract IERC721Enumerable is Initializable, IERC721 { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address owner, - uint256 index - ) - public - view - returns (uint256 tokenId); + function totalSupply() public view returns (uint256); + function tokenOfOwnerByIndex( + address owner, + uint256 index + ) + public + view + returns (uint256 tokenId); - function tokenByIndex(uint256 index) public view returns (uint256); + function tokenByIndex(uint256 index) public view returns (uint256); } diff --git a/contracts/token/ERC721/IERC721Metadata.sol b/contracts/token/ERC721/IERC721Metadata.sol index 37938f0a8..495780efe 100644 --- a/contracts/token/ERC721/IERC721Metadata.sol +++ b/contracts/token/ERC721/IERC721Metadata.sol @@ -9,7 +9,7 @@ import "./IERC721.sol"; * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */ contract IERC721Metadata is Initializable, IERC721 { - function name() external view returns (string); - function symbol() external view returns (string); - function tokenURI(uint256 tokenId) public view returns (string); + function name() external view returns (string); + function symbol() external view returns (string); + function tokenURI(uint256 tokenId) public view returns (string); } diff --git a/contracts/token/ERC721/IERC721Receiver.sol b/contracts/token/ERC721/IERC721Receiver.sol index 946582f7e..42ca6f91d 100644 --- a/contracts/token/ERC721/IERC721Receiver.sol +++ b/contracts/token/ERC721/IERC721Receiver.sol @@ -7,26 +7,26 @@ pragma solidity ^0.4.24; * from ERC721 asset contracts. */ contract IERC721Receiver { - /** - * @notice Handle the receipt of an NFT - * @dev The ERC721 smart contract calls this function on the recipient - * after a `safeTransfer`. This function MUST return the function selector, - * otherwise the caller will revert the transaction. The selector to be - * returned can be obtained as `this.onERC721Received.selector`. This - * function MAY throw to revert and reject the transfer. - * Note: the ERC721 contract address is always the message sender. - * @param operator The address which called `safeTransferFrom` function - * @param from The address which previously owned the token - * @param tokenId The NFT identifier which is being transferred - * @param data Additional data with no specified format - * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` - */ - function onERC721Received( - address operator, - address from, - uint256 tokenId, - bytes data - ) - public - returns(bytes4); + /** + * @notice Handle the receipt of an NFT + * @dev The ERC721 smart contract calls this function on the recipient + * after a `safeTransfer`. This function MUST return the function selector, + * otherwise the caller will revert the transaction. The selector to be + * returned can be obtained as `this.onERC721Received.selector`. This + * function MAY throw to revert and reject the transfer. + * Note: the ERC721 contract address is always the message sender. + * @param operator The address which called `safeTransferFrom` function + * @param from The address which previously owned the token + * @param tokenId The NFT identifier which is being transferred + * @param data Additional data with no specified format + * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` + */ + function onERC721Received( + address operator, + address from, + uint256 tokenId, + bytes data + ) + public + returns(bytes4); } diff --git a/contracts/token/ERC721/StandaloneERC721.sol b/contracts/token/ERC721/StandaloneERC721.sol index ff499f4f2..49059d8ff 100644 --- a/contracts/token/ERC721/StandaloneERC721.sol +++ b/contracts/token/ERC721/StandaloneERC721.sol @@ -13,28 +13,28 @@ import "./ERC721Pausable.sol"; * */ contract StandaloneERC721 - is Initializable, ERC721, ERC721Enumerable, ERC721Metadata, ERC721MetadataMintable, ERC721Pausable + is Initializable, ERC721, ERC721Enumerable, ERC721Metadata, ERC721MetadataMintable, ERC721Pausable { - function initialize(string name, string symbol, address[] minters, address[] pausers) public initializer { - ERC721.initialize(); - ERC721Enumerable.initialize(); - ERC721Metadata.initialize(name, symbol); + function initialize(string name, string symbol, address[] minters, address[] pausers) public initializer { + ERC721.initialize(); + ERC721Enumerable.initialize(); + ERC721Metadata.initialize(name, symbol); - // Initialize the minter and pauser roles, and renounce them - ERC721MetadataMintable.initialize(address(this)); - renounceMinter(); + // Initialize the minter and pauser roles, and renounce them + ERC721MetadataMintable.initialize(address(this)); + renounceMinter(); - ERC721Pausable.initialize(address(this)); - renouncePauser(); + ERC721Pausable.initialize(address(this)); + renouncePauser(); - // Add the requested minters and pausers (this can be done after renouncing since - // these are the internal calls) - for (uint256 i = 0; i < minters.length; ++i) { - _addMinter(minters[i]); + // Add the requested minters and pausers (this can be done after renouncing since + // these are the internal calls) + for (uint256 i = 0; i < minters.length; ++i) { + _addMinter(minters[i]); + } + + for (i = 0; i < pausers.length; ++i) { + _addPauser(pausers[i]); + } } - - for (i = 0; i < pausers.length; ++i) { - _addPauser(pausers[i]); - } - } } diff --git a/contracts/utils/Address.sol b/contracts/utils/Address.sol index 3e7fad8f6..feb31eeba 100644 --- a/contracts/utils/Address.sol +++ b/contracts/utils/Address.sol @@ -6,23 +6,23 @@ pragma solidity ^0.4.24; */ library Address { - /** - * Returns whether the target address is a contract - * @dev This function will return false if invoked during the constructor of a contract, - * as the code is not actually created until after the constructor finishes. - * @param account address of the account to check - * @return whether the target address is a contract - */ - function isContract(address account) internal view returns (bool) { - uint256 size; - // XXX Currently there is no better way to check if there is a contract in an address - // than to check the size of the code at that address. - // See https://ethereum.stackexchange.com/a/14016/36603 - // for more details about how this works. - // TODO Check this again before the Serenity release, because all addresses will be - // contracts then. - // solium-disable-next-line security/no-inline-assembly - assembly { size := extcodesize(account) } - return size > 0; - } + /** + * Returns whether the target address is a contract + * @dev This function will return false if invoked during the constructor of a contract, + * as the code is not actually created until after the constructor finishes. + * @param account address of the account to check + * @return whether the target address is a contract + */ + function isContract(address account) internal view returns (bool) { + uint256 size; + // XXX Currently there is no better way to check if there is a contract in an address + // than to check the size of the code at that address. + // See https://ethereum.stackexchange.com/a/14016/36603 + // for more details about how this works. + // TODO Check this again before the Serenity release, because all addresses will be + // contracts then. + // solium-disable-next-line security/no-inline-assembly + assembly { size := extcodesize(account) } + return size > 0; + } } diff --git a/contracts/utils/ReentrancyGuard.sol b/contracts/utils/ReentrancyGuard.sol index be103e7d7..1e8196b26 100644 --- a/contracts/utils/ReentrancyGuard.sol +++ b/contracts/utils/ReentrancyGuard.sol @@ -10,27 +10,27 @@ import "zos-lib/contracts/Initializable.sol"; */ contract ReentrancyGuard is Initializable { - /// @dev counter to allow mutex lock with only one SSTORE operation - uint256 private _guardCounter; + /// @dev counter to allow mutex lock with only one SSTORE operation + uint256 private _guardCounter; - function initialize() public initializer { - _guardCounter = 1; - } + function initialize() public initializer { + _guardCounter = 1; + } - /** - * @dev Prevents a contract from calling itself, directly or indirectly. - * If you mark a function `nonReentrant`, you should also - * mark it `external`. Calling one `nonReentrant` function from - * another is not supported. Instead, you can implement a - * `private` function doing the actual work, and an `external` - * wrapper marked as `nonReentrant`. - */ - modifier nonReentrant() { - _guardCounter += 1; - uint256 localCounter = _guardCounter; - _; - require(localCounter == _guardCounter); - } + /** + * @dev Prevents a contract from calling itself, directly or indirectly. + * If you mark a function `nonReentrant`, you should also + * mark it `external`. Calling one `nonReentrant` function from + * another is not supported. Instead, you can implement a + * `private` function doing the actual work, and an `external` + * wrapper marked as `nonReentrant`. + */ + modifier nonReentrant() { + _guardCounter += 1; + uint256 localCounter = _guardCounter; + _; + require(localCounter == _guardCounter); + } - uint256[50] private ______gap; + uint256[50] private ______gap; }