Commit bce2d68e by Francisco Giordano

convert 2 spaces to 4 spaces

parent b047d284
...@@ -6,36 +6,36 @@ pragma solidity ^0.4.24; ...@@ -6,36 +6,36 @@ pragma solidity ^0.4.24;
* @dev Library for managing addresses assigned to a Role. * @dev Library for managing addresses assigned to a Role.
*/ */
library Roles { library Roles {
struct Role { struct Role {
mapping (address => bool) bearer; mapping (address => bool) bearer;
} }
/** /**
* @dev give an account access to this role * @dev give an account access to this role
*/ */
function add(Role storage role, address account) internal { function add(Role storage role, address account) internal {
require(account != address(0)); require(account != address(0));
role.bearer[account] = true; role.bearer[account] = true;
} }
/** /**
* @dev remove an account's access to this role * @dev remove an account's access to this role
*/ */
function remove(Role storage role, address account) internal { function remove(Role storage role, address account) internal {
require(account != address(0)); require(account != address(0));
role.bearer[account] = false; role.bearer[account] = false;
} }
/** /**
* @dev check if an account has this role * @dev check if an account has this role
* @return bool * @return bool
*/ */
function has(Role storage role, address account) function has(Role storage role, address account)
internal internal
view view
returns (bool) returns (bool)
{ {
require(account != address(0)); require(account != address(0));
return role.bearer[account]; return role.bearer[account];
} }
} }
...@@ -5,45 +5,45 @@ import "../Roles.sol"; ...@@ -5,45 +5,45 @@ import "../Roles.sol";
contract CapperRole is Initializable { contract CapperRole is Initializable {
using Roles for Roles.Role; using Roles for Roles.Role;
event CapperAdded(address indexed account); event CapperAdded(address indexed account);
event CapperRemoved(address indexed account); event CapperRemoved(address indexed account);
Roles.Role private cappers; Roles.Role private cappers;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
if (!isCapper(sender)) { if (!isCapper(sender)) {
_addCapper(sender); _addCapper(sender);
}
} }
}
modifier onlyCapper() { modifier onlyCapper() {
require(isCapper(msg.sender)); require(isCapper(msg.sender));
_; _;
} }
function isCapper(address account) public view returns (bool) { function isCapper(address account) public view returns (bool) {
return cappers.has(account); return cappers.has(account);
} }
function addCapper(address account) public onlyCapper { function addCapper(address account) public onlyCapper {
_addCapper(account); _addCapper(account);
} }
function renounceCapper() public { function renounceCapper() public {
_removeCapper(msg.sender); _removeCapper(msg.sender);
} }
function _addCapper(address account) internal { function _addCapper(address account) internal {
cappers.add(account); cappers.add(account);
emit CapperAdded(account); emit CapperAdded(account);
} }
function _removeCapper(address account) internal { function _removeCapper(address account) internal {
cappers.remove(account); cappers.remove(account);
emit CapperRemoved(account); emit CapperRemoved(account);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -5,45 +5,45 @@ import "../Roles.sol"; ...@@ -5,45 +5,45 @@ import "../Roles.sol";
contract MinterRole is Initializable { contract MinterRole is Initializable {
using Roles for Roles.Role; using Roles for Roles.Role;
event MinterAdded(address indexed account); event MinterAdded(address indexed account);
event MinterRemoved(address indexed account); event MinterRemoved(address indexed account);
Roles.Role private minters; Roles.Role private minters;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
if (!isMinter(sender)) { if (!isMinter(sender)) {
_addMinter(sender); _addMinter(sender);
}
} }
}
modifier onlyMinter() { modifier onlyMinter() {
require(isMinter(msg.sender)); require(isMinter(msg.sender));
_; _;
} }
function isMinter(address account) public view returns (bool) { function isMinter(address account) public view returns (bool) {
return minters.has(account); return minters.has(account);
} }
function addMinter(address account) public onlyMinter { function addMinter(address account) public onlyMinter {
_addMinter(account); _addMinter(account);
} }
function renounceMinter() public { function renounceMinter() public {
_removeMinter(msg.sender); _removeMinter(msg.sender);
} }
function _addMinter(address account) internal { function _addMinter(address account) internal {
minters.add(account); minters.add(account);
emit MinterAdded(account); emit MinterAdded(account);
} }
function _removeMinter(address account) internal { function _removeMinter(address account) internal {
minters.remove(account); minters.remove(account);
emit MinterRemoved(account); emit MinterRemoved(account);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -5,45 +5,45 @@ import "../Roles.sol"; ...@@ -5,45 +5,45 @@ import "../Roles.sol";
contract PauserRole is Initializable { contract PauserRole is Initializable {
using Roles for Roles.Role; using Roles for Roles.Role;
event PauserAdded(address indexed account); event PauserAdded(address indexed account);
event PauserRemoved(address indexed account); event PauserRemoved(address indexed account);
Roles.Role private pausers; Roles.Role private pausers;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
if (!isPauser(sender)) { if (!isPauser(sender)) {
_addPauser(sender); _addPauser(sender);
}
} }
}
modifier onlyPauser() { modifier onlyPauser() {
require(isPauser(msg.sender)); require(isPauser(msg.sender));
_; _;
} }
function isPauser(address account) public view returns (bool) { function isPauser(address account) public view returns (bool) {
return pausers.has(account); return pausers.has(account);
} }
function addPauser(address account) public onlyPauser { function addPauser(address account) public onlyPauser {
_addPauser(account); _addPauser(account);
} }
function renouncePauser() public { function renouncePauser() public {
_removePauser(msg.sender); _removePauser(msg.sender);
} }
function _addPauser(address account) internal { function _addPauser(address account) internal {
pausers.add(account); pausers.add(account);
emit PauserAdded(account); emit PauserAdded(account);
} }
function _removePauser(address account) internal { function _removePauser(address account) internal {
pausers.remove(account); pausers.remove(account);
emit PauserRemoved(account); emit PauserRemoved(account);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -5,45 +5,45 @@ import "../Roles.sol"; ...@@ -5,45 +5,45 @@ import "../Roles.sol";
contract SignerRole is Initializable { contract SignerRole is Initializable {
using Roles for Roles.Role; using Roles for Roles.Role;
event SignerAdded(address indexed account); event SignerAdded(address indexed account);
event SignerRemoved(address indexed account); event SignerRemoved(address indexed account);
Roles.Role private signers; Roles.Role private signers;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
if (!isSigner(sender)) { if (!isSigner(sender)) {
_addSigner(sender); _addSigner(sender);
}
} }
}
modifier onlySigner() { modifier onlySigner() {
require(isSigner(msg.sender)); require(isSigner(msg.sender));
_; _;
} }
function isSigner(address account) public view returns (bool) { function isSigner(address account) public view returns (bool) {
return signers.has(account); return signers.has(account);
} }
function addSigner(address account) public onlySigner { function addSigner(address account) public onlySigner {
_addSigner(account); _addSigner(account);
} }
function renounceSigner() public { function renounceSigner() public {
_removeSigner(msg.sender); _removeSigner(msg.sender);
} }
function _addSigner(address account) internal { function _addSigner(address account) internal {
signers.add(account); signers.add(account);
emit SignerAdded(account); emit SignerAdded(account);
} }
function _removeSigner(address account) internal { function _removeSigner(address account) internal {
signers.remove(account); signers.remove(account);
emit SignerRemoved(account); emit SignerRemoved(account);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -19,223 +19,223 @@ import "../token/ERC20/SafeERC20.sol"; ...@@ -19,223 +19,223 @@ import "../token/ERC20/SafeERC20.sol";
* behavior. * behavior.
*/ */
contract Crowdsale is Initializable { contract Crowdsale is Initializable {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
// The token being sold // The token being sold
IERC20 private _token; IERC20 private _token;
// Address where funds are collected // Address where funds are collected
address private _wallet; address private _wallet;
// How many token units a buyer gets per wei. // How many token units a buyer gets per wei.
// The rate is the conversion between wei and the smallest and indivisible token unit. // 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 // 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. // 1 wei will give you 1 unit, or 0.001 TOK.
uint256 private _rate; uint256 private _rate;
// Amount of wei raised // Amount of wei raised
uint256 private _weiRaised; uint256 private _weiRaised;
/** /**
* Event for token purchase logging * Event for token purchase logging
* @param purchaser who paid for the tokens * @param purchaser who paid for the tokens
* @param beneficiary who got the tokens * @param beneficiary who got the tokens
* @param value weis paid for purchase * @param value weis paid for purchase
* @param amount amount of tokens purchased * @param amount amount of tokens purchased
*/ */
event TokensPurchased( event TokensPurchased(
address indexed purchaser, address indexed purchaser,
address indexed beneficiary, address indexed beneficiary,
uint256 value, uint256 value,
uint256 amount 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
); );
_updatePurchasingState(beneficiary, weiAmount); /**
* @param rate Number of token units a buyer gets per wei
_forwardFunds(); * @dev The rate is the conversion between wei and the smallest and indivisible
_postValidatePurchase(beneficiary, weiAmount); * 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
// Internal interface (extensible) */
// ----------------------------------------- function initialize(uint256 rate, address wallet, IERC20 token) public initializer {
require(rate > 0);
function _hasBeenInitialized() internal view returns (bool) { require(wallet != address(0));
return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0))); require(token != address(0));
}
_rate = rate;
/** _wallet = wallet;
* @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. _token = token;
* Example from CappedCrowdsale.sol's _preValidatePurchase method: }
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap); // -----------------------------------------
* @param beneficiary Address performing the token purchase // Crowdsale external interface
* @param weiAmount Value in wei involved in the purchase // -----------------------------------------
*/
function _preValidatePurchase( /**
address beneficiary, * @dev fallback function ***DO NOT OVERRIDE***
uint256 weiAmount */
) function () external payable {
internal buyTokens(msg.sender);
{ }
require(beneficiary != address(0));
require(weiAmount != 0); /**
} * @return the token being sold.
*/
/** function token() public view returns(IERC20) {
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met. return _token;
* @param beneficiary Address performing the token purchase }
* @param weiAmount Value in wei involved in the purchase
*/ /**
function _postValidatePurchase( * @return the address where funds are collected.
address beneficiary, */
uint256 weiAmount function wallet() public view returns(address) {
) return _wallet;
internal }
{
// optional override /**
} * @return the number of token units a buyer gets per wei.
*/
/** function rate() public view returns(uint256) {
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens. return _rate;
* @param beneficiary Address performing the token purchase }
* @param tokenAmount Number of tokens to be emitted
*/ /**
function _deliverTokens( * @return the mount of wei raised.
address beneficiary, */
uint256 tokenAmount function weiRaised() public view returns (uint256) {
) return _weiRaised;
internal }
{
_token.safeTransfer(beneficiary, tokenAmount); /**
} * @dev low level token purchase ***DO NOT OVERRIDE***
* @param beneficiary Address performing the token purchase
/** */
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens. function buyTokens(address beneficiary) public payable {
* @param beneficiary Address receiving the tokens
* @param tokenAmount Number of tokens to be purchased uint256 weiAmount = msg.value;
*/ _preValidatePurchase(beneficiary, weiAmount);
function _processPurchase(
address beneficiary, // calculate token amount to be created
uint256 tokenAmount uint256 tokens = _getTokenAmount(weiAmount);
)
internal // update state
{ _weiRaised = _weiRaised.add(weiAmount);
_deliverTokens(beneficiary, tokenAmount);
} _processPurchase(beneficiary, tokens);
emit TokensPurchased(
/** msg.sender,
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.) beneficiary,
* @param beneficiary Address receiving the tokens weiAmount,
* @param weiAmount Value in wei involved in the purchase tokens
*/ );
function _updatePurchasingState(
address beneficiary, _updatePurchasingState(beneficiary, weiAmount);
uint256 weiAmount
) _forwardFunds();
internal _postValidatePurchase(beneficiary, weiAmount);
{ }
// optional override
} // -----------------------------------------
// Internal interface (extensible)
/** // -----------------------------------------
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens function _hasBeenInitialized() internal view returns (bool) {
* @return Number of tokens that can be purchased with the specified _weiAmount return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0)));
*/ }
function _getTokenAmount(uint256 weiAmount)
internal view returns (uint256) /**
{ * @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.
return weiAmount.mul(_rate); * Example from CappedCrowdsale.sol's _preValidatePurchase method:
} * super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
/** * @param beneficiary Address performing the token purchase
* @dev Determines how ETH is stored/forwarded on purchases. * @param weiAmount Value in wei involved in the purchase
*/ */
function _forwardFunds() internal { function _preValidatePurchase(
_wallet.transfer(msg.value); address beneficiary,
} uint256 weiAmount
)
uint256[50] private ______gap; 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;
} }
...@@ -11,41 +11,41 @@ import "../validation/TimedCrowdsale.sol"; ...@@ -11,41 +11,41 @@ import "../validation/TimedCrowdsale.sol";
* can do extra work after finishing. * can do extra work after finishing.
*/ */
contract FinalizableCrowdsale is Initializable, TimedCrowdsale { 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. * @return true if the crowdsale is finalized, false otherwise.
*/ */
function finalized() public view returns (bool) { function finalized() public view returns (bool) {
return _finalized; return _finalized;
} }
/** /**
* @dev Must be called after crowdsale ends, to do some extra finalization * @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function. * work. Calls the contract's finalization function.
*/ */
function finalize() public { function finalize() public {
require(!_finalized); require(!_finalized);
require(hasClosed()); require(hasClosed());
_finalization(); _finalization();
emit CrowdsaleFinalized(); emit CrowdsaleFinalized();
_finalized = true; _finalized = true;
} }
/** /**
* @dev Can be overridden to add finalization logic. The overriding function * @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is * should call super._finalization() to ensure the chain of finalization is
* executed entirely. * executed entirely.
*/ */
function _finalization() internal { function _finalization() internal {
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -11,43 +11,43 @@ import "../../math/SafeMath.sol"; ...@@ -11,43 +11,43 @@ import "../../math/SafeMath.sol";
* @dev Crowdsale that locks tokens from withdrawal until it ends. * @dev Crowdsale that locks tokens from withdrawal until it ends.
*/ */
contract PostDeliveryCrowdsale is Initializable, TimedCrowdsale { 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. * @dev Withdraw tokens only after crowdsale ends.
* @param beneficiary Whose tokens will be withdrawn. * @param beneficiary Whose tokens will be withdrawn.
*/ */
function withdrawTokens(address beneficiary) public { function withdrawTokens(address beneficiary) public {
require(hasClosed()); require(hasClosed());
uint256 amount = _balances[beneficiary]; uint256 amount = _balances[beneficiary];
require(amount > 0); require(amount > 0);
_balances[beneficiary] = 0; _balances[beneficiary] = 0;
_deliverTokens(beneficiary, amount); _deliverTokens(beneficiary, amount);
} }
/** /**
* @return the balance of an account. * @return the balance of an account.
*/ */
function balanceOf(address account) public view returns(uint256) { function balanceOf(address account) public view returns(uint256) {
return _balances[account]; return _balances[account];
} }
/** /**
* @dev Overrides parent by storing balances instead of issuing tokens right away. * @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param tokenAmount Amount of tokens purchased * @param tokenAmount Amount of tokens purchased
*/ */
function _processPurchase( function _processPurchase(
address beneficiary, address beneficiary,
uint256 tokenAmount uint256 tokenAmount
) )
internal internal
{ {
_balances[beneficiary] = _balances[beneficiary].add(tokenAmount); _balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -13,80 +13,80 @@ import "../../payment/RefundEscrow.sol"; ...@@ -13,80 +13,80 @@ import "../../payment/RefundEscrow.sol";
* the possibility of users getting a refund if goal is not met. * the possibility of users getting a refund if goal is not met.
*/ */
contract RefundableCrowdsale is Initializable, FinalizableCrowdsale { contract RefundableCrowdsale is Initializable, FinalizableCrowdsale {
using SafeMath for uint256; using SafeMath for uint256;
// minimum amount of funds to be raised in weis // minimum amount of funds to be raised in weis
uint256 private _goal; uint256 private _goal;
// refund escrow used to hold funds while crowdsale is running // refund escrow used to hold funds while crowdsale is running
RefundEscrow private _escrow; RefundEscrow private _escrow;
/** /**
* @dev Constructor, creates RefundEscrow. * @dev Constructor, creates RefundEscrow.
* @param goal Funding goal * @param goal Funding goal
*/ */
function initialize(uint256 goal) public initializer { function initialize(uint256 goal) public initializer {
// FinalizableCrowdsale depends on TimedCrowdsale // FinalizableCrowdsale depends on TimedCrowdsale
assert(TimedCrowdsale._hasBeenInitialized()); assert(TimedCrowdsale._hasBeenInitialized());
require(goal > 0); require(goal > 0);
// conditional added to make initializer idempotent in case of diamond inheritance // conditional added to make initializer idempotent in case of diamond inheritance
if (address(_escrow) == address(0)) { if (address(_escrow) == address(0)) {
_escrow = new RefundEscrow(); _escrow = new RefundEscrow();
_escrow.initialize(wallet(), address(this)); _escrow.initialize(wallet(), address(this));
}
_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);
} }
_goal = goal; /**
} * @dev Checks whether funding goal was reached.
* @return Whether funding goal was reached
/** */
* @return minimum amount of funds to be raised in wei. function goalReached() public view returns (bool) {
*/ return weiRaised() >= _goal;
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();
} }
super._finalization(); /**
} * @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. * @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
*/ */
function _forwardFunds() internal { function _forwardFunds() internal {
_escrow.deposit.value(msg.value)(msg.sender); _escrow.deposit.value(msg.value)(msg.sender);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -12,50 +12,50 @@ import "../../math/SafeMath.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. * @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale.
*/ */
contract AllowanceCrowdsale is Initializable, Crowdsale { contract AllowanceCrowdsale is Initializable, Crowdsale {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
address private _tokenWallet; address private _tokenWallet;
/** /**
* @dev Constructor, takes token wallet address. * @dev Constructor, takes token wallet address.
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale * @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
*/ */
function initialize(address tokenWallet) public initializer { function initialize(address tokenWallet) public initializer {
assert(Crowdsale._hasBeenInitialized()); assert(Crowdsale._hasBeenInitialized());
require(tokenWallet != address(0)); require(tokenWallet != address(0));
_tokenWallet = tokenWallet; _tokenWallet = tokenWallet;
} }
/** /**
* @return the address of the wallet that will hold the tokens. * @return the address of the wallet that will hold the tokens.
*/ */
function tokenWallet() public view returns(address) { function tokenWallet() public view returns(address) {
return _tokenWallet; return _tokenWallet;
} }
/** /**
* @dev Checks the amount of tokens left in the allowance. * @dev Checks the amount of tokens left in the allowance.
* @return Amount of tokens left in the allowance * @return Amount of tokens left in the allowance
*/ */
function remainingTokens() public view returns (uint256) { function remainingTokens() public view returns (uint256) {
return token().allowance(_tokenWallet, this); return token().allowance(_tokenWallet, this);
} }
/** /**
* @dev Overrides parent behavior by transferring tokens from wallet. * @dev Overrides parent behavior by transferring tokens from wallet.
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param tokenAmount Amount of tokens purchased * @param tokenAmount Amount of tokens purchased
*/ */
function _deliverTokens( function _deliverTokens(
address beneficiary, address beneficiary,
uint256 tokenAmount uint256 tokenAmount
) )
internal internal
{ {
token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount); token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -12,21 +12,21 @@ import "../../token/ERC20/ERC20Mintable.sol"; ...@@ -12,21 +12,21 @@ import "../../token/ERC20/ERC20Mintable.sol";
*/ */
contract MintedCrowdsale is Initializable, Crowdsale { contract MintedCrowdsale is Initializable, Crowdsale {
/** /**
* @dev Overrides delivery by minting tokens upon purchase. * @dev Overrides delivery by minting tokens upon purchase.
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param tokenAmount Number of tokens to be minted * @param tokenAmount Number of tokens to be minted
*/ */
function _deliverTokens( function _deliverTokens(
address beneficiary, address beneficiary,
uint256 tokenAmount uint256 tokenAmount
) )
internal internal
{ {
// Potentially dangerous assumption about the type of the token. // Potentially dangerous assumption about the type of the token.
require( require(
ERC20Mintable(address(token())).mint(beneficiary, tokenAmount)); ERC20Mintable(address(token())).mint(beneficiary, tokenAmount));
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -12,64 +12,64 @@ import "../../math/SafeMath.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. * the amount of tokens per wei contributed. Thus, the initial rate must be greater than the final rate.
*/ */
contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale { contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale {
using SafeMath for uint256; using SafeMath for uint256;
uint256 private _initialRate; uint256 private _initialRate;
uint256 private _finalRate; uint256 private _finalRate;
/** /**
* @dev Constructor, takes initial and final rates of tokens received per wei contributed. * @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 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 * @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
*/ */
function initialize(uint256 initialRate, uint256 finalRate) public initializer { function initialize(uint256 initialRate, uint256 finalRate) public initializer {
assert(TimedCrowdsale._hasBeenInitialized()); assert(TimedCrowdsale._hasBeenInitialized());
require(finalRate > 0); require(finalRate > 0);
require(initialRate >= finalRate); require(initialRate >= finalRate);
_initialRate = initialRate; _initialRate = initialRate;
_finalRate = finalRate; _finalRate = finalRate;
} }
/** /**
* @return the initial rate of the crowdsale. * @return the initial rate of the crowdsale.
*/ */
function initialRate() public view returns(uint256) { function initialRate() public view returns(uint256) {
return _initialRate; return _initialRate;
} }
/** /**
* @return the final rate of the crowdsale. * @return the final rate of the crowdsale.
*/ */
function finalRate() public view returns (uint256) { function finalRate() public view returns (uint256) {
return _finalRate; return _finalRate;
} }
/** /**
* @dev Returns the rate of tokens per wei at the present time. * @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_. * Note that, as price _increases_ with time, the rate _decreases_.
* @return The number of tokens a buyer gets per wei at a given time * @return The number of tokens a buyer gets per wei at a given time
*/ */
function getCurrentRate() public view returns (uint256) { function getCurrentRate() public view returns (uint256) {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
uint256 elapsedTime = block.timestamp.sub(openingTime()); uint256 elapsedTime = block.timestamp.sub(openingTime());
uint256 timeRange = closingTime().sub(openingTime()); uint256 timeRange = closingTime().sub(openingTime());
uint256 rateRange = _initialRate.sub(_finalRate); uint256 rateRange = _initialRate.sub(_finalRate);
return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
} }
/** /**
* @dev Overrides parent method taking into account variable rate. * @dev Overrides parent method taking into account variable rate.
* @param weiAmount The value in wei to be converted into tokens * @param weiAmount The value in wei to be converted into tokens
* @return The number of tokens _weiAmount wei will buy at present time * @return The number of tokens _weiAmount wei will buy at present time
*/ */
function _getTokenAmount(uint256 weiAmount) function _getTokenAmount(uint256 weiAmount)
internal view returns (uint256) internal view returns (uint256)
{ {
uint256 currentRate = getCurrentRate(); uint256 currentRate = getCurrentRate();
return currentRate.mul(weiAmount); return currentRate.mul(weiAmount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,51 +10,51 @@ import "../Crowdsale.sol"; ...@@ -10,51 +10,51 @@ import "../Crowdsale.sol";
* @dev Crowdsale with a limit for total contributions. * @dev Crowdsale with a limit for total contributions.
*/ */
contract CappedCrowdsale is Initializable, Crowdsale { 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. * @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
* @param cap Max amount of wei to be contributed * @param cap Max amount of wei to be contributed
*/ */
function initialize(uint256 cap) public initializer { function initialize(uint256 cap) public initializer {
assert(Crowdsale._hasBeenInitialized()); assert(Crowdsale._hasBeenInitialized());
require(cap > 0); require(cap > 0);
_cap = cap; _cap = cap;
} }
/** /**
* @return the cap of the crowdsale. * @return the cap of the crowdsale.
*/ */
function cap() public view returns(uint256) { function cap() public view returns(uint256) {
return _cap; return _cap;
} }
/** /**
* @dev Checks whether the cap has been reached. * @dev Checks whether the cap has been reached.
* @return Whether the cap was reached * @return Whether the cap was reached
*/ */
function capReached() public view returns (bool) { function capReached() public view returns (bool) {
return weiRaised() >= _cap; return weiRaised() >= _cap;
} }
/** /**
* @dev Extend parent behavior requiring purchase to respect the funding cap. * @dev Extend parent behavior requiring purchase to respect the funding cap.
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed * @param weiAmount Amount of wei contributed
*/ */
function _preValidatePurchase( function _preValidatePurchase(
address beneficiary, address beneficiary,
uint256 weiAmount uint256 weiAmount
) )
internal internal
{ {
super._preValidatePurchase(beneficiary, weiAmount); super._preValidatePurchase(beneficiary, weiAmount);
require(weiRaised().add(weiAmount) <= _cap); require(weiRaised().add(weiAmount) <= _cap);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -11,78 +11,78 @@ import "../../access/roles/CapperRole.sol"; ...@@ -11,78 +11,78 @@ import "../../access/roles/CapperRole.sol";
* @dev Crowdsale with per-beneficiary caps. * @dev Crowdsale with per-beneficiary caps.
*/ */
contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole { contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole {
using SafeMath for uint256; using SafeMath for uint256;
mapping(address => uint256) private _contributions; mapping(address => uint256) private _contributions;
mapping(address => uint256) private _caps; mapping(address => uint256) private _caps;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
assert(Crowdsale._hasBeenInitialized()); assert(Crowdsale._hasBeenInitialized());
CapperRole.initialize(sender); CapperRole.initialize(sender);
} }
/** /**
* @dev Sets a specific beneficiary's maximum contribution. * @dev Sets a specific beneficiary's maximum contribution.
* @param beneficiary Address to be capped * @param beneficiary Address to be capped
* @param cap Wei limit for individual contribution * @param cap Wei limit for individual contribution
*/ */
function setCap(address beneficiary, uint256 cap) external onlyCapper { function setCap(address beneficiary, uint256 cap) external onlyCapper {
_caps[beneficiary] = cap; _caps[beneficiary] = cap;
} }
/** /**
* @dev Returns the cap of a specific beneficiary. * @dev Returns the cap of a specific beneficiary.
* @param beneficiary Address whose cap is to be checked * @param beneficiary Address whose cap is to be checked
* @return Current cap for individual beneficiary * @return Current cap for individual beneficiary
*/ */
function getCap(address beneficiary) public view returns (uint256) { function getCap(address beneficiary) public view returns (uint256) {
return _caps[beneficiary]; return _caps[beneficiary];
} }
/** /**
* @dev Returns the amount contributed so far by a specific beneficiary. * @dev Returns the amount contributed so far by a specific beneficiary.
* @param beneficiary Address of contributor * @param beneficiary Address of contributor
* @return Beneficiary contribution so far * @return Beneficiary contribution so far
*/ */
function getContribution(address beneficiary) function getContribution(address beneficiary)
public view returns (uint256) public view returns (uint256)
{ {
return _contributions[beneficiary]; return _contributions[beneficiary];
} }
/** /**
* @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap. * @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap.
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed * @param weiAmount Amount of wei contributed
*/ */
function _preValidatePurchase( function _preValidatePurchase(
address beneficiary, address beneficiary,
uint256 weiAmount uint256 weiAmount
) )
internal internal
{ {
super._preValidatePurchase(beneficiary, weiAmount); super._preValidatePurchase(beneficiary, weiAmount);
require( require(
_contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]); _contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]);
} }
/** /**
* @dev Extend parent behavior to update beneficiary contributions * @dev Extend parent behavior to update beneficiary contributions
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed * @param weiAmount Amount of wei contributed
*/ */
function _updatePurchasingState( function _updatePurchasingState(
address beneficiary, address beneficiary,
uint256 weiAmount uint256 weiAmount
) )
internal internal
{ {
super._updatePurchasingState(beneficiary, weiAmount); super._updatePurchasingState(beneficiary, weiAmount);
_contributions[beneficiary] = _contributions[beneficiary].add( _contributions[beneficiary] = _contributions[beneficiary].add(
weiAmount); weiAmount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,85 +10,85 @@ import "../Crowdsale.sol"; ...@@ -10,85 +10,85 @@ import "../Crowdsale.sol";
* @dev Crowdsale accepting contributions only within a time frame. * @dev Crowdsale accepting contributions only within a time frame.
*/ */
contract TimedCrowdsale is Initializable, Crowdsale { contract TimedCrowdsale is Initializable, Crowdsale {
using SafeMath for uint256; using SafeMath for uint256;
uint256 private _openingTime; uint256 private _openingTime;
uint256 private _closingTime; uint256 private _closingTime;
/** /**
* @dev Reverts if not in crowdsale time range. * @dev Reverts if not in crowdsale time range.
*/ */
modifier onlyWhileOpen { modifier onlyWhileOpen {
require(isOpen()); require(isOpen());
_; _;
} }
/** /**
* @dev Constructor, takes crowdsale opening and closing times. * @dev Constructor, takes crowdsale opening and closing times.
* @param openingTime Crowdsale opening time * @param openingTime Crowdsale opening time
* @param closingTime Crowdsale closing time * @param closingTime Crowdsale closing time
*/ */
function initialize(uint256 openingTime, uint256 closingTime) public initializer { function initialize(uint256 openingTime, uint256 closingTime) public initializer {
assert(Crowdsale._hasBeenInitialized()); assert(Crowdsale._hasBeenInitialized());
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
require(openingTime >= block.timestamp); require(openingTime >= block.timestamp);
require(closingTime >= openingTime); require(closingTime >= openingTime);
_openingTime = openingTime; _openingTime = openingTime;
_closingTime = closingTime; _closingTime = closingTime;
} }
/** /**
* @return the crowdsale opening time. * @return the crowdsale opening time.
*/ */
function openingTime() public view returns(uint256) { function openingTime() public view returns(uint256) {
return _openingTime; return _openingTime;
} }
/** /**
* @return the crowdsale closing time. * @return the crowdsale closing time.
*/ */
function closingTime() public view returns(uint256) { function closingTime() public view returns(uint256) {
return _closingTime; return _closingTime;
} }
/** /**
* @return true if the crowdsale is open, false otherwise. * @return true if the crowdsale is open, false otherwise.
*/ */
function isOpen() public view returns (bool) { function isOpen() public view returns (bool) {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
return block.timestamp >= _openingTime && block.timestamp <= _closingTime; return block.timestamp >= _openingTime && block.timestamp <= _closingTime;
} }
/** /**
* @dev Checks whether the period in which the crowdsale is open has already elapsed. * @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed * @return Whether crowdsale period has elapsed
*/ */
function hasClosed() public view returns (bool) { function hasClosed() public view returns (bool) {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
return block.timestamp > _closingTime; return block.timestamp > _closingTime;
} }
function _hasBeenInitialized() internal view returns (bool) { function _hasBeenInitialized() internal view returns (bool) {
return ((_openingTime > 0) && (_closingTime > 0)); return ((_openingTime > 0) && (_closingTime > 0));
} }
/** /**
* @dev Extend parent behavior requiring to be within contributing period * @dev Extend parent behavior requiring to be within contributing period
* @param beneficiary Token purchaser * @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed * @param weiAmount Amount of wei contributed
*/ */
function _preValidatePurchase( function _preValidatePurchase(
address beneficiary, address beneficiary,
uint256 weiAmount uint256 weiAmount
) )
internal internal
onlyWhileOpen onlyWhileOpen
{ {
super._preValidatePurchase(beneficiary, weiAmount); super._preValidatePurchase(beneficiary, weiAmount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,63 +10,63 @@ pragma solidity ^0.4.24; ...@@ -10,63 +10,63 @@ pragma solidity ^0.4.24;
library ECDSA { library ECDSA {
/** /**
* @dev Recover signer address from a message by using their signature * @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 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() * @param signature bytes signature, the signature is generated using web3.eth.sign()
*/ */
function recover(bytes32 hash, bytes signature) function recover(bytes32 hash, bytes signature)
internal internal
pure pure
returns (address) returns (address)
{ {
bytes32 r; bytes32 r;
bytes32 s; bytes32 s;
uint8 v; uint8 v;
// Check the signature length // Check the signature length
if (signature.length != 65) { if (signature.length != 65) {
return (address(0)); return (address(0));
} }
// Divide the signature in r, s and v variables // Divide the signature in r, s and v variables
// ecrecover takes the signature parameters, and the only way to get them // ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly. // currently is to use assembly.
// solium-disable-next-line security/no-inline-assembly // solium-disable-next-line security/no-inline-assembly
assembly { assembly {
r := mload(add(signature, 32)) r := mload(add(signature, 32))
s := mload(add(signature, 64)) s := mload(add(signature, 64))
v := byte(0, mload(add(signature, 96))) v := byte(0, mload(add(signature, 96)))
} }
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions // Version of signature should be 27 or 28, but 0 and 1 are also possible versions
if (v < 27) { if (v < 27) {
v += 27; v += 27;
} }
// If the version is correct return the signer address // If the version is correct return the signer address
if (v != 27 && v != 28) { if (v != 27 && v != 28) {
return (address(0)); return (address(0));
} else { } else {
// solium-disable-next-line arg-overflow // solium-disable-next-line arg-overflow
return ecrecover(hash, v, r, s); return ecrecover(hash, v, r, s);
}
} }
}
/** /**
* toEthSignedMessageHash * toEthSignedMessageHash
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:" * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
* and hash the result * and hash the result
*/ */
function toEthSignedMessageHash(bytes32 hash) function toEthSignedMessageHash(bytes32 hash)
internal internal
pure pure
returns (bytes32) returns (bytes32)
{ {
// 32 is the length in bytes of hash, // 32 is the length in bytes of hash,
// enforced by the type signature above // enforced by the type signature above
return keccak256( return keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", hash) abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
); );
} }
} }
...@@ -7,37 +7,37 @@ pragma solidity ^0.4.24; ...@@ -7,37 +7,37 @@ pragma solidity ^0.4.24;
* https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol * https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol
*/ */
library MerkleProof { library MerkleProof {
/** /**
* @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves * @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. * 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 proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree
* @param root Merkle root * @param root Merkle root
* @param leaf Leaf of Merkle tree * @param leaf Leaf of Merkle tree
*/ */
function verify( function verify(
bytes32[] proof, bytes32[] proof,
bytes32 root, bytes32 root,
bytes32 leaf bytes32 leaf
) )
internal internal
pure pure
returns (bool) returns (bool)
{ {
bytes32 computedHash = leaf; bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) { for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i]; bytes32 proofElement = proof[i];
if (computedHash < proofElement) { if (computedHash < proofElement) {
// Hash(current computed hash + current element of the proof) // Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else { } else {
// Hash(current element of the proof + current computed hash) // Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
} }
} }
// Check if the computed hash (root) is equal to the provided root // Check if the computed hash (root) is equal to the provided root
return computedHash == root; return computedHash == root;
} }
} }
...@@ -15,15 +15,15 @@ pragma solidity ^0.4.24; ...@@ -15,15 +15,15 @@ pragma solidity ^0.4.24;
*/ */
library Counter { library Counter {
struct Counter { struct Counter {
uint256 current; // default: 0 uint256 current; // default: 0
} }
function next(Counter storage index) function next(Counter storage index)
internal internal
returns (uint256) returns (uint256)
{ {
index.current += 1; index.current += 1;
return index.current; return index.current;
} }
} }
...@@ -11,25 +11,25 @@ import "../../token/ERC20/IERC20.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 * @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 { 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 { contract ERC20WithMetadata is Initializable, ERC20TokenMetadata {
string private _tokenURI = ""; string private _tokenURI = "";
function initialize(string tokenURI) function initialize(string tokenURI)
public public
initializer initializer
{ {
_tokenURI = tokenURI; _tokenURI = tokenURI;
} }
function tokenURI() external view returns (string) { function tokenURI() external view returns (string) {
return _tokenURI; return _tokenURI;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -34,71 +34,71 @@ import "../math/Math.sol"; ...@@ -34,71 +34,71 @@ import "../math/Math.sol";
* ``` * ```
*/ */
contract ERC20Migrator is Initializable { contract ERC20Migrator is Initializable {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
/// Address of the old token contract /// Address of the old token contract
IERC20 private _legacyToken; IERC20 private _legacyToken;
/// Address of the new token contract /// Address of the new token contract
ERC20Mintable private _newToken; ERC20Mintable private _newToken;
/** /**
* @param legacyToken address of the old token contract * @param legacyToken address of the old token contract
*/ */
function initialize(IERC20 legacyToken) public initializer { function initialize(IERC20 legacyToken) public initializer {
require(legacyToken != address(0)); require(legacyToken != address(0));
_legacyToken = legacyToken; _legacyToken = legacyToken;
} }
/** /**
* @dev Returns the legacy token that is being migrated. * @dev Returns the legacy token that is being migrated.
*/ */
function legacyToken() public view returns (IERC20) { function legacyToken() public view returns (IERC20) {
return _legacyToken; return _legacyToken;
} }
/** /**
* @dev Returns the new token to which we are migrating. * @dev Returns the new token to which we are migrating.
*/ */
function newToken() public view returns (IERC20) { function newToken() public view returns (IERC20) {
return _newToken; return _newToken;
} }
/** /**
* @dev Begins the migration by setting which is the new token that will be * @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. * minted. This contract must be a minter for the new token.
* @param newToken the token that will be minted * @param newToken the token that will be minted
*/ */
function beginMigration(ERC20Mintable newToken) public { function beginMigration(ERC20Mintable newToken) public {
require(_newToken == address(0)); require(_newToken == address(0));
require(newToken != address(0)); require(newToken != address(0));
require(newToken.isMinter(this)); require(newToken.isMinter(this));
_newToken = newToken; _newToken = newToken;
} }
/** /**
* @dev Transfers part of an account's balance in the old token to this * @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. * contract, and mints the same amount of new tokens for that account.
* @param account whose tokens will be migrated * @param account whose tokens will be migrated
* @param amount amount of tokens to be migrated * @param amount amount of tokens to be migrated
*/ */
function migrate(address account, uint256 amount) public { function migrate(address account, uint256 amount) public {
_legacyToken.safeTransferFrom(account, this, amount); _legacyToken.safeTransferFrom(account, this, amount);
_newToken.mint(account, amount); _newToken.mint(account, amount);
} }
/** /**
* @dev Transfers all of an account's allowed balance in the old token to * @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. * this contract, and mints the same amount of new tokens for that account.
* @param account whose tokens will be migrated * @param account whose tokens will be migrated
*/ */
function migrateAll(address account) public { function migrateAll(address account) public {
uint256 balance = _legacyToken.balanceOf(account); uint256 balance = _legacyToken.balanceOf(account);
uint256 allowance = _legacyToken.allowance(account, this); uint256 allowance = _legacyToken.allowance(account, this);
uint256 amount = Math.min(balance, allowance); uint256 amount = Math.min(balance, allowance);
migrate(account, amount); migrate(account, amount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -30,116 +30,116 @@ import "../cryptography/ECDSA.sol"; ...@@ -30,116 +30,116 @@ import "../cryptography/ECDSA.sol";
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details. * much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
*/ */
contract SignatureBouncer is Initializable, SignerRole { contract SignatureBouncer is Initializable, SignerRole {
using ECDSA for bytes32; using ECDSA for bytes32;
// Function selectors are 4 bytes long, as documented in // Function selectors are 4 bytes long, as documented in
// https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector // https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector
uint256 private constant _METHOD_ID_SIZE = 4; uint256 private constant _METHOD_ID_SIZE = 4;
// Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes // Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint256 private constant _SIGNATURE_SIZE = 96; uint256 private constant _SIGNATURE_SIZE = 96;
/** /**
* @dev requires that a valid signature of a signer was provided * @dev requires that a valid signature of a signer was provided
*/ */
modifier onlyValidSignature(bytes signature) modifier onlyValidSignature(bytes signature)
{ {
require(_isValidSignature(msg.sender, signature)); require(_isValidSignature(msg.sender, signature));
_; _;
} }
/** /**
* @dev requires that a valid signature with a specifed method of a signer was provided * @dev requires that a valid signature with a specifed method of a signer was provided
*/ */
modifier onlyValidSignatureAndMethod(bytes signature) modifier onlyValidSignatureAndMethod(bytes signature)
{ {
require(_isValidSignatureAndMethod(msg.sender, signature)); require(_isValidSignatureAndMethod(msg.sender, signature));
_; _;
} }
/** /**
* @dev requires that a valid signature with a specifed method and params of a signer was provided * @dev requires that a valid signature with a specifed method and params of a signer was provided
*/ */
modifier onlyValidSignatureAndData(bytes signature) modifier onlyValidSignatureAndData(bytes signature)
{ {
require(_isValidSignatureAndData(msg.sender, signature)); require(_isValidSignatureAndData(msg.sender, signature));
_; _;
} }
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
SignerRole.initialize(sender); SignerRole.initialize(sender);
} }
/** /**
* @dev is the signature of `this + sender` from a signer? * @dev is the signature of `this + sender` from a signer?
* @return bool * @return bool
*/ */
function _isValidSignature(address account, bytes signature) function _isValidSignature(address account, bytes signature)
internal internal
view view
returns (bool) returns (bool)
{ {
return _isValidDataHash( return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account)), keccak256(abi.encodePacked(address(this), account)),
signature signature
); );
} }
/** /**
* @dev is the signature of `this + sender + methodId` from a signer? * @dev is the signature of `this + sender + methodId` from a signer?
* @return bool * @return bool
*/ */
function _isValidSignatureAndMethod(address account, bytes signature) function _isValidSignatureAndMethod(address account, bytes signature)
internal internal
view view
returns (bool) returns (bool)
{ {
bytes memory data = new bytes(_METHOD_ID_SIZE); bytes memory data = new bytes(_METHOD_ID_SIZE);
for (uint i = 0; i < data.length; i++) { for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i]; data[i] = msg.data[i];
}
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account, data)),
signature
);
} }
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account, data)),
signature
);
}
/** /**
* @dev is the signature of `this + sender + methodId + params(s)` from a signer? * @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 * @notice the signature parameter of the method being validated must be the "last" parameter
* @return bool * @return bool
*/ */
function _isValidSignatureAndData(address account, bytes signature) function _isValidSignatureAndData(address account, bytes signature)
internal internal
view view
returns (bool) returns (bool)
{ {
require(msg.data.length > _SIGNATURE_SIZE); require(msg.data.length > _SIGNATURE_SIZE);
bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE); bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE);
for (uint i = 0; i < data.length; i++) { for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i]; data[i] = msg.data[i];
}
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account, data)),
signature
);
} }
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account, data)),
signature
);
}
/** /**
* @dev internal function to convert a hash to an eth signed message * @dev internal function to convert a hash to an eth signed message
* and then recover the signature and check it against the signer role * and then recover the signature and check it against the signer role
* @return bool * @return bool
*/ */
function _isValidDataHash(bytes32 hash, bytes signature) function _isValidDataHash(bytes32 hash, bytes signature)
internal internal
view view
returns (bool) returns (bool)
{ {
address signer = hash address signer = hash
.toEthSignedMessageHash() .toEthSignedMessageHash()
.recover(signature); .recover(signature);
return signer != address(0) && isSigner(signer); return signer != address(0) && isSigner(signer);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -15,167 +15,167 @@ import "../math/SafeMath.sol"; ...@@ -15,167 +15,167 @@ import "../math/SafeMath.sol";
* owner. * owner.
*/ */
contract TokenVesting is Initializable, Ownable { contract TokenVesting is Initializable, Ownable {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
event Released(uint256 amount); event Released(uint256 amount);
event Revoked(); event Revoked();
// beneficiary of tokens after they are released // beneficiary of tokens after they are released
address private _beneficiary; address private _beneficiary;
uint256 private _cliff; uint256 private _cliff;
uint256 private _start; uint256 private _start;
uint256 private _duration; uint256 private _duration;
bool private _revocable; bool private _revocable;
mapping (address => uint256) private _released; mapping (address => uint256) private _released;
mapping (address => bool) private _revoked; mapping (address => bool) private _revoked;
/** /**
* @dev Creates a vesting contract that vests its balance of any ERC20 token to the * @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 * beneficiary, gradually in a linear fashion until start + duration. By then all
* of the balance will have vested. * of the balance will have vested.
* @param beneficiary address of the beneficiary to whom vested tokens are transferred * @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 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 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 duration duration in seconds of the period in which the tokens will vest
* @param revocable whether the vesting is revocable or not * @param revocable whether the vesting is revocable or not
*/ */
function initialize( function initialize(
address beneficiary, address beneficiary,
uint256 start, uint256 start,
uint256 cliffDuration, uint256 cliffDuration,
uint256 duration, uint256 duration,
bool revocable, bool revocable,
address sender address sender
) )
public public
initializer initializer
{ {
Ownable.initialize(sender); Ownable.initialize(sender);
require(beneficiary != address(0)); require(beneficiary != address(0));
require(cliffDuration <= duration); require(cliffDuration <= duration);
_beneficiary = beneficiary; _beneficiary = beneficiary;
_revocable = revocable; _revocable = revocable;
_duration = duration; _duration = duration;
_cliff = start.add(cliffDuration); _cliff = start.add(cliffDuration);
_start = start; _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);
} }
}
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;
} }
...@@ -14,19 +14,19 @@ import "../token/ERC20/ERC20Mintable.sol"; ...@@ -14,19 +14,19 @@ import "../token/ERC20/ERC20Mintable.sol";
*/ */
contract SampleCrowdsaleToken is Initializable, ERC20Mintable { contract SampleCrowdsaleToken is Initializable, ERC20Mintable {
string public name; string public name;
string public symbol; string public symbol;
uint8 public decimals; uint8 public decimals;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
ERC20Mintable.initialize(sender); ERC20Mintable.initialize(sender);
name = "Sample Crowdsale Token"; name = "Sample Crowdsale Token";
symbol = "SCT"; symbol = "SCT";
decimals = 18; decimals = 18;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -48,27 +48,27 @@ contract SampleCrowdsaleToken is Initializable, ERC20Mintable { ...@@ -48,27 +48,27 @@ contract SampleCrowdsaleToken is Initializable, ERC20Mintable {
// solium-disable-next-line max-len // solium-disable-next-line max-len
contract SampleCrowdsale is Initializable, Crowdsale, CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale { contract SampleCrowdsale is Initializable, Crowdsale, CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
function initialize( function initialize(
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
uint256 cap, uint256 cap,
ERC20Mintable token, ERC20Mintable token,
uint256 goal uint256 goal
) )
public public
initializer initializer
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
CappedCrowdsale.initialize(cap); CappedCrowdsale.initialize(cap);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
RefundableCrowdsale.initialize(goal); RefundableCrowdsale.initialize(goal);
//As goal needs to be met for a successful crowdsale //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 //the value needs to less or equal than a cap which is limit for accepted funds
require(goal <= cap); require(goal <= cap);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -13,19 +13,19 @@ import "../token/ERC20/ERC20.sol"; ...@@ -13,19 +13,19 @@ import "../token/ERC20/ERC20.sol";
*/ */
contract SimpleToken is Initializable, ERC20 { contract SimpleToken is Initializable, ERC20 {
string public constant name = "SimpleToken"; string public constant name = "SimpleToken";
string public constant symbol = "SIM"; string public constant symbol = "SIM";
uint8 public constant decimals = 18; 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. * @dev Constructor that gives sender all of existing tokens.
*/ */
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
_mint(sender, INITIAL_SUPPLY); _mint(sender, INITIAL_SUPPLY);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -11,32 +11,32 @@ import "../token/ERC20/ERC20Pausable.sol"; ...@@ -11,32 +11,32 @@ import "../token/ERC20/ERC20Pausable.sol";
* *
*/ */
contract StandardToken is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable { contract StandardToken is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable {
function initialize( function initialize(
string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder,
address[] minters, address[] pausers address[] minters, address[] pausers
) public initializer { ) public initializer {
ERC20Detailed.initialize(name, symbol, decimals); ERC20Detailed.initialize(name, symbol, decimals);
// Mint the initial supply // Mint the initial supply
if (initialSupply > 0) { // To allow passing a null address when not doing any initial supply if (initialSupply > 0) { // To allow passing a null address when not doing any initial supply
_mint(initialHolder, initialSupply); _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]);
}
}
} }
...@@ -11,48 +11,48 @@ import "./IERC165.sol"; ...@@ -11,48 +11,48 @@ import "./IERC165.sol";
*/ */
contract ERC165 is Initializable, IERC165 { contract ERC165 is Initializable, IERC165 {
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/** /**
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
/** /**
* @dev a mapping of interface id to whether or not it's supported * @dev a mapping of interface id to whether or not it's supported
*/ */
mapping(bytes4 => bool) internal _supportedInterfaces; mapping(bytes4 => bool) internal _supportedInterfaces;
/** /**
* @dev A contract implementing SupportsInterfaceWithLookup * @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself * implement ERC165 itself
*/ */
function initialize() function initialize()
public public
initializer initializer
{ {
_registerInterface(_InterfaceId_ERC165); _registerInterface(_InterfaceId_ERC165);
} }
/** /**
* @dev implement supportsInterface(bytes4) using a lookup table * @dev implement supportsInterface(bytes4) using a lookup table
*/ */
function supportsInterface(bytes4 interfaceId) function supportsInterface(bytes4 interfaceId)
public public
view view
returns (bool) returns (bool)
{ {
return _supportedInterfaces[interfaceId]; return _supportedInterfaces[interfaceId];
} }
/** /**
* @dev private method for registering an interface * @dev private method for registering an interface
*/ */
function _registerInterface(bytes4 interfaceId) function _registerInterface(bytes4 interfaceId)
internal internal
{ {
require(interfaceId != 0xffffffff); require(interfaceId != 0xffffffff);
_supportedInterfaces[interfaceId] = true; _supportedInterfaces[interfaceId] = true;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -7,142 +7,142 @@ pragma solidity ^0.4.24; ...@@ -7,142 +7,142 @@ pragma solidity ^0.4.24;
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
*/ */
library ERC165Checker { library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff // As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _InterfaceId_Invalid = 0xffffffff; bytes4 private constant _InterfaceId_Invalid = 0xffffffff;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/** /**
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
/** /**
* @notice Query if a contract supports ERC165 * @notice Query if a contract supports ERC165
* @param account The address of the contract to query for support of ERC165 * @param account The address of the contract to query for support of ERC165
* @return true if the contract at account implements ERC165 * @return true if the contract at account implements ERC165
*/ */
function supportsERC165(address account) function supportsERC165(address account)
internal internal
view view
returns (bool) returns (bool)
{ {
// Any contract that implements ERC165 must explicitly indicate support of // Any contract that implements ERC165 must explicitly indicate support of
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
return supportsERC165Interface(account, _InterfaceId_ERC165) && return supportsERC165Interface(account, _InterfaceId_ERC165) &&
!supportsERC165Interface(account, _InterfaceId_Invalid); !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;
} }
// query support of each interface in _interfaceIds /**
for (uint256 i = 0; i < interfaceIds.length; i++) { * @notice Query if a contract implements an interface, also checks support of ERC165
if (!supportsERC165Interface(account, interfaceIds[i])) { * @param account The address of the contract to query for support of an interface
return false; * @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
* @notice Query if a contract implements an interface, does not check ERC165 support * interfaceIds list, false otherwise
* @param account The address of the contract to query for support of an interface * @dev Interface identification is specified in ERC-165.
* @param interfaceId The interface identifier, as specified in ERC-165 */
* @return true if the contract at account indicates support of the interface with function supportsInterfaces(address account, bytes4[] interfaceIds)
* identifier interfaceId, false otherwise internal
* @dev Assumes that account contains a contract that supports ERC165, otherwise view
* the behavior of this method is undefined. This precondition can be checked returns (bool)
* with the `supportsERC165` method in this library. {
* Interface identification is specified in ERC-165. // query support of ERC165 itself
*/ if (!supportsERC165(account)) {
function supportsERC165Interface(address account, bytes4 interfaceId) return false;
private }
view
returns (bool) // query support of each interface in _interfaceIds
{ for (uint256 i = 0; i < interfaceIds.length; i++) {
// success determines whether the staticcall succeeded and result determines if (!supportsERC165Interface(account, interfaceIds[i])) {
// whether the contract at account indicates support of _interfaceId return false;
(bool success, bool result) = callERC165SupportsInterface( }
account, interfaceId); }
return (success && result); // all interfaces supported
} return true;
}
/**
* @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 * @notice Query if a contract implements an interface, does not check ERC165 support
* @param interfaceId The interface identifier, as specified in ERC-165 * @param account The address of the contract to query for support of an interface
* @return success true if the STATICCALL succeeded, false otherwise * @param interfaceId The interface identifier, as specified in ERC-165
* @return result true if the STATICCALL succeeded and the contract at account * @return true if the contract at account indicates support of the interface with
* indicates support of the interface with identifier interfaceId, false otherwise * identifier interfaceId, false otherwise
*/ * @dev Assumes that account contains a contract that supports ERC165, otherwise
function callERC165SupportsInterface( * the behavior of this method is undefined. This precondition can be checked
address account, * with the `supportsERC165` method in this library.
bytes4 interfaceId * Interface identification is specified in ERC-165.
) */
private function supportsERC165Interface(address account, bytes4 interfaceId)
view private
returns (bool success, bool result) view
{ returns (bool)
bytes memory encodedParams = abi.encodeWithSelector( {
_InterfaceId_ERC165, // success determines whether the staticcall succeeded and result determines
interfaceId // whether the contract at account indicates support of _interfaceId
); (bool success, bool result) = callERC165SupportsInterface(
account, interfaceId);
// solium-disable-next-line security/no-inline-assembly
assembly { return (success && result);
let encodedParams_data := add(0x20, encodedParams) }
let encodedParams_size := mload(encodedParams)
/**
let output := mload(0x40) // Find empty storage location using "free memory pointer" * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw
mstore(output, 0x0) * @param account The address of the contract to query for support of an interface
* @param interfaceId The interface identifier, as specified in ERC-165
success := staticcall( * @return success true if the STATICCALL succeeded, false otherwise
30000, // 30k gas * @return result true if the STATICCALL succeeded and the contract at account
account, // To addr * indicates support of the interface with identifier interfaceId, false otherwise
encodedParams_data, */
encodedParams_size, function callERC165SupportsInterface(
output, address account,
0x20 // Outputs are 32 bytes long bytes4 interfaceId
) )
private
result := mload(output) // Load the result 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
}
} }
}
} }
...@@ -7,14 +7,14 @@ pragma solidity ^0.4.24; ...@@ -7,14 +7,14 @@ pragma solidity ^0.4.24;
*/ */
interface IERC165 { interface IERC165 {
/** /**
* @notice Query if a contract implements an interface * @notice Query if a contract implements an interface
* @param interfaceId The interface identifier, as specified in ERC-165 * @param interfaceId The interface identifier, as specified in ERC-165
* @dev Interface identification is specified in ERC-165. This function * @dev Interface identification is specified in ERC-165. This function
* uses less than 30,000 gas. * uses less than 30,000 gas.
*/ */
function supportsInterface(bytes4 interfaceId) function supportsInterface(bytes4 interfaceId)
external external
view view
returns (bool); returns (bool);
} }
...@@ -9,53 +9,53 @@ import "../access/roles/PauserRole.sol"; ...@@ -9,53 +9,53 @@ import "../access/roles/PauserRole.sol";
* @dev Base contract which allows children to implement an emergency stop mechanism. * @dev Base contract which allows children to implement an emergency stop mechanism.
*/ */
contract Pausable is Initializable, PauserRole { contract Pausable is Initializable, PauserRole {
event Paused(); event Paused();
event Unpaused(); event Unpaused();
bool private _paused = false; bool private _paused = false;
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
PauserRole.initialize(sender); PauserRole.initialize(sender);
} }
/** /**
* @return true if the contract is paused, false otherwise. * @return true if the contract is paused, false otherwise.
*/ */
function paused() public view returns(bool) { function paused() public view returns(bool) {
return _paused; return _paused;
} }
/** /**
* @dev Modifier to make a function callable only when the contract is not paused. * @dev Modifier to make a function callable only when the contract is not paused.
*/ */
modifier whenNotPaused() { modifier whenNotPaused() {
require(!_paused); require(!_paused);
_; _;
} }
/** /**
* @dev Modifier to make a function callable only when the contract is paused. * @dev Modifier to make a function callable only when the contract is paused.
*/ */
modifier whenPaused() { modifier whenPaused() {
require(_paused); require(_paused);
_; _;
} }
/** /**
* @dev called by the owner to pause, triggers stopped state * @dev called by the owner to pause, triggers stopped state
*/ */
function pause() public onlyPauser whenNotPaused { function pause() public onlyPauser whenNotPaused {
_paused = true; _paused = true;
emit Paused(); emit Paused();
} }
/** /**
* @dev called by the owner to unpause, returns to normal state * @dev called by the owner to unpause, returns to normal state
*/ */
function unpause() public onlyPauser whenPaused { function unpause() public onlyPauser whenPaused {
_paused = false; _paused = false;
emit Unpaused(); emit Unpaused();
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -6,16 +6,16 @@ pragma solidity ^0.4.24; ...@@ -6,16 +6,16 @@ pragma solidity ^0.4.24;
* @dev Assorted math operations * @dev Assorted math operations
*/ */
library Math { library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) { function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b; return a >= b ? a : b;
} }
function min(uint256 a, uint256 b) internal pure returns (uint256) { function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b; return a < b ? a : b;
} }
function average(uint256 a, uint256 b) internal pure returns (uint256) { function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute // (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
} }
} }
...@@ -7,60 +7,60 @@ pragma solidity ^0.4.24; ...@@ -7,60 +7,60 @@ pragma solidity ^0.4.24;
*/ */
library SafeMath { library SafeMath {
/** /**
* @dev Multiplies two numbers, reverts on overflow. * @dev Multiplies two numbers, reverts on overflow.
*/ */
function mul(uint256 a, uint256 b) internal pure returns (uint256) { function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested. // benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) { if (a == 0) {
return 0; return 0;
} }
uint256 c = a * b; uint256 c = a * b;
require(c / a == b); require(c / a == b);
return c; return c;
} }
/** /**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero. * @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/ */
function div(uint256 a, uint256 b) internal pure returns (uint256) { function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0 require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b; uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold // assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c; return c;
} }
/** /**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). * @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) { function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a); require(b <= a);
uint256 c = a - b; uint256 c = a - b;
return c; return c;
} }
/** /**
* @dev Adds two numbers, reverts on overflow. * @dev Adds two numbers, reverts on overflow.
*/ */
function add(uint256 a, uint256 b) internal pure returns (uint256) { function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b; uint256 c = a + b;
require(c >= a); require(c >= a);
return c; return c;
} }
/** /**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo), * @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero. * reverts when dividing by zero.
*/ */
function mod(uint256 a, uint256 b) internal pure returns (uint256) { function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0); require(b != 0);
return a % b; return a % b;
} }
} }
...@@ -6,16 +6,16 @@ import "../crowdsale/emission/AllowanceCrowdsale.sol"; ...@@ -6,16 +6,16 @@ import "../crowdsale/emission/AllowanceCrowdsale.sol";
contract AllowanceCrowdsaleImpl is AllowanceCrowdsale { contract AllowanceCrowdsaleImpl is AllowanceCrowdsale {
constructor ( constructor (
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token, IERC20 token,
address tokenWallet address tokenWallet
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
AllowanceCrowdsale.initialize(tokenWallet); AllowanceCrowdsale.initialize(tokenWallet);
} }
} }
...@@ -6,16 +6,16 @@ import "../crowdsale/validation/CappedCrowdsale.sol"; ...@@ -6,16 +6,16 @@ import "../crowdsale/validation/CappedCrowdsale.sol";
contract CappedCrowdsaleImpl is CappedCrowdsale { contract CappedCrowdsaleImpl is CappedCrowdsale {
constructor ( constructor (
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token, IERC20 token,
uint256 cap uint256 cap
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
CappedCrowdsale.initialize(cap); CappedCrowdsale.initialize(cap);
} }
} }
...@@ -4,19 +4,19 @@ import "../access/roles/CapperRole.sol"; ...@@ -4,19 +4,19 @@ import "../access/roles/CapperRole.sol";
contract CapperRoleMock is CapperRole { contract CapperRoleMock is CapperRole {
constructor() public { constructor() public {
CapperRole.initialize(msg.sender); CapperRole.initialize(msg.sender);
} }
function removeCapper(address account) public { function removeCapper(address account) public {
_removeCapper(account); _removeCapper(account);
} }
function onlyCapperMock() public view onlyCapper { function onlyCapperMock() public view onlyCapper {
} }
// Causes a compilation error if super._removeCapper is not internal // Causes a compilation error if super._removeCapper is not internal
function _removeCapper(address account) internal { function _removeCapper(address account) internal {
super._removeCapper(account); super._removeCapper(account);
} }
} }
...@@ -5,17 +5,17 @@ import "../payment/ConditionalEscrow.sol"; ...@@ -5,17 +5,17 @@ import "../payment/ConditionalEscrow.sol";
// mock class using ConditionalEscrow // mock class using ConditionalEscrow
contract ConditionalEscrowMock is ConditionalEscrow { contract ConditionalEscrowMock is ConditionalEscrow {
mapping(address => bool) private _allowed; mapping(address => bool) private _allowed;
constructor() public { constructor() public {
ConditionalEscrow.initialize(msg.sender); ConditionalEscrow.initialize(msg.sender);
} }
function setAllowed(address payee, bool allowed) public { function setAllowed(address payee, bool allowed) public {
_allowed[payee] = allowed; _allowed[payee] = allowed;
} }
function withdrawalAllowed(address payee) public view returns (bool) { function withdrawalAllowed(address payee) public view returns (bool) {
return _allowed[payee]; return _allowed[payee];
} }
} }
...@@ -4,18 +4,18 @@ import "../drafts/Counter.sol"; ...@@ -4,18 +4,18 @@ import "../drafts/Counter.sol";
contract CounterImpl { 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 // use whatever key you want to track your counters
mapping(string => Counter.Counter) private _counters; mapping(string => Counter.Counter) private _counters;
function doThing(string key) function doThing(string key)
public public
returns (uint256) returns (uint256)
{ {
theId = _counters[key].next(); theId = _counters[key].next();
return theId; return theId;
} }
} }
...@@ -4,7 +4,7 @@ import "../crowdsale/Crowdsale.sol"; ...@@ -4,7 +4,7 @@ import "../crowdsale/Crowdsale.sol";
contract CrowdsaleMock is Crowdsale { contract CrowdsaleMock is Crowdsale {
constructor(uint256 rate, address wallet, IERC20 token) public { constructor(uint256 rate, address wallet, IERC20 token) public {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
} }
} }
...@@ -5,13 +5,13 @@ import "../token/ERC20/ERC20Detailed.sol"; ...@@ -5,13 +5,13 @@ import "../token/ERC20/ERC20Detailed.sol";
contract ERC20DetailedMock is ERC20, ERC20Detailed { contract ERC20DetailedMock is ERC20, ERC20Detailed {
constructor( constructor(
string name, string name,
string symbol, string symbol,
uint8 decimals uint8 decimals
) )
public public
{ {
ERC20Detailed.initialize(name, symbol, decimals); ERC20Detailed.initialize(name, symbol, decimals);
} }
} }
...@@ -4,21 +4,21 @@ import "../cryptography/ECDSA.sol"; ...@@ -4,21 +4,21 @@ import "../cryptography/ECDSA.sol";
contract ECDSAMock { contract ECDSAMock {
using ECDSA for bytes32; using ECDSA for bytes32;
function recover(bytes32 hash, bytes signature) function recover(bytes32 hash, bytes signature)
public public
pure pure
returns (address) returns (address)
{ {
return hash.recover(signature); return hash.recover(signature);
} }
function toEthSignedMessageHash(bytes32 hash) function toEthSignedMessageHash(bytes32 hash)
public public
pure pure
returns (bytes32) returns (bytes32)
{ {
return hash.toEthSignedMessageHash(); return hash.toEthSignedMessageHash();
} }
} }
...@@ -13,57 +13,57 @@ import "../../introspection/IERC165.sol"; ...@@ -13,57 +13,57 @@ import "../../introspection/IERC165.sol";
*/ */
contract SupportsInterfaceWithLookupMock is IERC165 { contract SupportsInterfaceWithLookupMock is IERC165 {
bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7;
/** /**
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
/** /**
* @dev a mapping of interface id to whether or not it's supported * @dev a mapping of interface id to whether or not it's supported
*/ */
mapping(bytes4 => bool) internal supportedInterfaces; mapping(bytes4 => bool) internal supportedInterfaces;
/** /**
* @dev A contract implementing SupportsInterfaceWithLookup * @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself * implement ERC165 itself
*/ */
constructor() constructor()
public public
{ {
_registerInterface(InterfaceId_ERC165); _registerInterface(InterfaceId_ERC165);
} }
/** /**
* @dev implement supportsInterface(bytes4) using a lookup table * @dev implement supportsInterface(bytes4) using a lookup table
*/ */
function supportsInterface(bytes4 interfaceId) function supportsInterface(bytes4 interfaceId)
external external
view view
returns (bool) returns (bool)
{ {
return supportedInterfaces[interfaceId]; return supportedInterfaces[interfaceId];
} }
/** /**
* @dev private method for registering an interface * @dev private method for registering an interface
*/ */
function _registerInterface(bytes4 interfaceId) function _registerInterface(bytes4 interfaceId)
internal internal
{ {
require(interfaceId != 0xffffffff); require(interfaceId != 0xffffffff);
supportedInterfaces[interfaceId] = true; supportedInterfaces[interfaceId] = true;
} }
} }
contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock { contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
constructor (bytes4[] interfaceIds) constructor (bytes4[] interfaceIds)
public public
{ {
for (uint256 i = 0; i < interfaceIds.length; i++) { for (uint256 i = 0; i < interfaceIds.length; i++) {
_registerInterface(interfaceIds[i]); _registerInterface(interfaceIds[i]);
}
} }
}
} }
...@@ -4,29 +4,29 @@ import "../introspection/ERC165Checker.sol"; ...@@ -4,29 +4,29 @@ import "../introspection/ERC165Checker.sol";
contract ERC165CheckerMock { contract ERC165CheckerMock {
using ERC165Checker for address; using ERC165Checker for address;
function supportsERC165(address account) function supportsERC165(address account)
public public
view view
returns (bool) returns (bool)
{ {
return account.supportsERC165(); return account.supportsERC165();
} }
function supportsInterface(address account, bytes4 interfaceId) function supportsInterface(address account, bytes4 interfaceId)
public public
view view
returns (bool) returns (bool)
{ {
return account.supportsInterface(interfaceId); return account.supportsInterface(interfaceId);
} }
function supportsInterfaces(address account, bytes4[] interfaceIds) function supportsInterfaces(address account, bytes4[] interfaceIds)
public public
view view
returns (bool) returns (bool)
{ {
return account.supportsInterfaces(interfaceIds); return account.supportsInterfaces(interfaceIds);
} }
} }
...@@ -4,13 +4,13 @@ import "../introspection/ERC165.sol"; ...@@ -4,13 +4,13 @@ import "../introspection/ERC165.sol";
contract ERC165Mock is ERC165 { contract ERC165Mock is ERC165 {
constructor() public { constructor() public {
ERC165.initialize(); ERC165.initialize();
} }
function registerInterface(bytes4 interfaceId) function registerInterface(bytes4 interfaceId)
public public
{ {
_registerInterface(interfaceId); _registerInterface(interfaceId);
} }
} }
...@@ -5,8 +5,8 @@ import "../token/ERC20/ERC20Burnable.sol"; ...@@ -5,8 +5,8 @@ import "../token/ERC20/ERC20Burnable.sol";
contract ERC20BurnableMock is ERC20Burnable { contract ERC20BurnableMock is ERC20Burnable {
constructor(address initialAccount, uint256 initialBalance) public { constructor(address initialAccount, uint256 initialBalance) public {
_mint(initialAccount, initialBalance); _mint(initialAccount, initialBalance);
} }
} }
...@@ -6,8 +6,8 @@ import "./MinterRoleMock.sol"; ...@@ -6,8 +6,8 @@ import "./MinterRoleMock.sol";
contract ERC20CappedMock is ERC20Capped, MinterRoleMock { contract ERC20CappedMock is ERC20Capped, MinterRoleMock {
constructor(uint256 cap) public { constructor(uint256 cap) public {
ERC20Capped.initialize(cap, msg.sender); ERC20Capped.initialize(cap, msg.sender);
} }
} }
...@@ -5,8 +5,8 @@ import "../drafts/ERC20Migrator.sol"; ...@@ -5,8 +5,8 @@ import "../drafts/ERC20Migrator.sol";
contract ERC20MigratorMock is ERC20Migrator { contract ERC20MigratorMock is ERC20Migrator {
constructor(IERC20 legacyToken) public { constructor(IERC20 legacyToken) public {
ERC20Migrator.initialize(legacyToken); ERC20Migrator.initialize(legacyToken);
} }
} }
...@@ -6,7 +6,7 @@ import "./MinterRoleMock.sol"; ...@@ -6,7 +6,7 @@ import "./MinterRoleMock.sol";
contract ERC20MintableMock is ERC20Mintable, MinterRoleMock { contract ERC20MintableMock is ERC20Mintable, MinterRoleMock {
constructor() public { constructor() public {
ERC20Mintable.initialize(msg.sender); ERC20Mintable.initialize(msg.sender);
} }
} }
...@@ -6,20 +6,20 @@ import "../token/ERC20/ERC20.sol"; ...@@ -6,20 +6,20 @@ import "../token/ERC20/ERC20.sol";
// mock class using ERC20 // mock class using ERC20
contract ERC20Mock is ERC20 { contract ERC20Mock is ERC20 {
constructor(address initialAccount, uint256 initialBalance) public { constructor(address initialAccount, uint256 initialBalance) public {
_mint(initialAccount, initialBalance); _mint(initialAccount, initialBalance);
} }
function mint(address account, uint256 amount) public { function mint(address account, uint256 amount) public {
_mint(account, amount); _mint(account, amount);
} }
function burn(address account, uint256 amount) public { function burn(address account, uint256 amount) public {
_burn(account, amount); _burn(account, amount);
} }
function burnFrom(address account, uint256 amount) public { function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount); _burnFrom(account, amount);
} }
} }
...@@ -7,10 +7,10 @@ import "./PauserRoleMock.sol"; ...@@ -7,10 +7,10 @@ import "./PauserRoleMock.sol";
// mock class using ERC20Pausable // mock class using ERC20Pausable
contract ERC20PausableMock is ERC20Pausable, PauserRoleMock { contract ERC20PausableMock is ERC20Pausable, PauserRoleMock {
constructor(address initialAccount, uint initialBalance) public { constructor(address initialAccount, uint initialBalance) public {
ERC20Pausable.initialize(msg.sender); ERC20Pausable.initialize(msg.sender);
_mint(initialAccount, initialBalance); _mint(initialAccount, initialBalance);
} }
} }
...@@ -5,7 +5,7 @@ import "../drafts/ERC1046/TokenMetadata.sol"; ...@@ -5,7 +5,7 @@ import "../drafts/ERC1046/TokenMetadata.sol";
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata { contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata {
constructor(string tokenURI) public { constructor(string tokenURI) public {
ERC20WithMetadata.initialize(tokenURI); ERC20WithMetadata.initialize(tokenURI);
} }
} }
...@@ -12,24 +12,24 @@ import "../token/ERC721/ERC721Burnable.sol"; ...@@ -12,24 +12,24 @@ import "../token/ERC721/ERC721Burnable.sol";
* and a public setter for metadata URI * and a public setter for metadata URI
*/ */
contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
constructor(string name, string symbol) public constructor(string name, string symbol) public
{ {
ERC721.initialize(); ERC721.initialize();
ERC721Metadata.initialize(name, symbol); ERC721Metadata.initialize(name, symbol);
ERC721Enumerable.initialize(); ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender); ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender); ERC721MetadataMintable.initialize(msg.sender);
} }
function exists(uint256 tokenId) public view returns (bool) { function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId); return _exists(tokenId);
} }
function setTokenURI(uint256 tokenId, string uri) public { function setTokenURI(uint256 tokenId, string uri) public {
_setTokenURI(tokenId, uri); _setTokenURI(tokenId, uri);
} }
function removeTokenFrom(address from, uint256 tokenId) public { function removeTokenFrom(address from, uint256 tokenId) public {
_removeTokenFrom(from, tokenId); _removeTokenFrom(from, tokenId);
} }
} }
...@@ -10,15 +10,15 @@ import "../token/ERC721/ERC721Burnable.sol"; ...@@ -10,15 +10,15 @@ import "../token/ERC721/ERC721Burnable.sol";
* @title ERC721MintableBurnableImpl * @title ERC721MintableBurnableImpl
*/ */
contract ERC721MintableBurnableImpl contract ERC721MintableBurnableImpl
is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
constructor() constructor()
public public
{ {
ERC721.initialize(); ERC721.initialize();
ERC721Metadata.initialize("Test", "TEST"); ERC721Metadata.initialize("Test", "TEST");
ERC721Enumerable.initialize(); ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender); ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender); ERC721MetadataMintable.initialize(msg.sender);
} }
} }
...@@ -8,15 +8,15 @@ import "../token/ERC721/ERC721.sol"; ...@@ -8,15 +8,15 @@ import "../token/ERC721/ERC721.sol";
* This mock just provides a public mint and burn functions for testing purposes * This mock just provides a public mint and burn functions for testing purposes
*/ */
contract ERC721Mock is ERC721 { contract ERC721Mock is ERC721 {
constructor() public { constructor() public {
ERC721.initialize(); ERC721.initialize();
} }
function mint(address to, uint256 tokenId) public { function mint(address to, uint256 tokenId) public {
_mint(to, tokenId); _mint(to, tokenId);
} }
function burn(uint256 tokenId) public { function burn(uint256 tokenId) public {
_burn(ownerOf(tokenId), tokenId); _burn(ownerOf(tokenId), tokenId);
} }
} }
...@@ -9,20 +9,20 @@ import "./PauserRoleMock.sol"; ...@@ -9,20 +9,20 @@ import "./PauserRoleMock.sol";
* This mock just provides a public mint, burn and exists functions for testing purposes * This mock just provides a public mint, burn and exists functions for testing purposes
*/ */
contract ERC721PausableMock is ERC721Pausable, PauserRoleMock { contract ERC721PausableMock is ERC721Pausable, PauserRoleMock {
constructor() { constructor() {
ERC721.initialize(); ERC721.initialize();
ERC721Pausable.initialize(msg.sender); ERC721Pausable.initialize(msg.sender);
} }
function mint(address to, uint256 tokenId) public { function mint(address to, uint256 tokenId) public {
super._mint(to, tokenId); super._mint(to, tokenId);
} }
function burn(uint256 tokenId) public { function burn(uint256 tokenId) public {
super._burn(ownerOf(tokenId), tokenId); super._burn(ownerOf(tokenId), tokenId);
} }
function exists(uint256 tokenId) public view returns (bool) { function exists(uint256 tokenId) public view returns (bool) {
return super._exists(tokenId); return super._exists(tokenId);
} }
} }
...@@ -4,39 +4,39 @@ import "../token/ERC721/IERC721Receiver.sol"; ...@@ -4,39 +4,39 @@ import "../token/ERC721/IERC721Receiver.sol";
contract ERC721ReceiverMock is IERC721Receiver { contract ERC721ReceiverMock is IERC721Receiver {
bytes4 private _retval; bytes4 private _retval;
bool private _reverts; bool private _reverts;
event Received( event Received(
address operator, address operator,
address from, address from,
uint256 tokenId, uint256 tokenId,
bytes data, bytes data,
uint256 gas uint256 gas
); );
constructor(bytes4 retval, bool reverts) public { constructor(bytes4 retval, bool reverts) public {
_retval = retval; _retval = retval;
_reverts = reverts; _reverts = reverts;
} }
function onERC721Received( function onERC721Received(
address operator, address operator,
address from, address from,
uint256 tokenId, uint256 tokenId,
bytes data bytes data
) )
public public
returns(bytes4) returns(bytes4)
{ {
require(!_reverts); require(!_reverts);
emit Received( emit Received(
operator, operator,
from, from,
tokenId, tokenId,
data, data,
gasleft() // msg.gas was deprecated in solidityv0.4.21 gasleft() // msg.gas was deprecated in solidityv0.4.21
); );
return _retval; return _retval;
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "../payment/Escrow.sol"; import "../payment/Escrow.sol";
contract EscrowMock is Escrow { contract EscrowMock is Escrow {
constructor() public { constructor() public {
Escrow.initialize(msg.sender); Escrow.initialize(msg.sender);
} }
} }
...@@ -6,17 +6,17 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol"; ...@@ -6,17 +6,17 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol";
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale { contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
constructor ( constructor (
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token IERC20 token
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
} }
} }
...@@ -8,9 +8,9 @@ pragma solidity ^0.4.24; ...@@ -8,9 +8,9 @@ pragma solidity ^0.4.24;
// @author Remco Bloemen <remco@neufund.org> // @author Remco Bloemen <remco@neufund.org>
contract ForceEther { contract ForceEther {
constructor() public payable { } constructor() public payable { }
function destroyAndSend(address recipient) public { function destroyAndSend(address recipient) public {
selfdestruct(recipient); selfdestruct(recipient);
} }
} }
...@@ -6,19 +6,19 @@ import "../math/SafeMath.sol"; ...@@ -6,19 +6,19 @@ import "../math/SafeMath.sol";
contract IncreasingPriceCrowdsaleImpl is IncreasingPriceCrowdsale { contract IncreasingPriceCrowdsaleImpl is IncreasingPriceCrowdsale {
constructor ( constructor (
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
address wallet, address wallet,
IERC20 token, IERC20 token,
uint256 initialRate, uint256 initialRate,
uint256 finalRate uint256 finalRate
) )
public public
{ {
Crowdsale.initialize(initialRate, wallet, token); Crowdsale.initialize(initialRate, wallet, token);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
IncreasingPriceCrowdsale.initialize(initialRate, finalRate); IncreasingPriceCrowdsale.initialize(initialRate, finalRate);
} }
} }
...@@ -6,16 +6,16 @@ import "./CapperRoleMock.sol"; ...@@ -6,16 +6,16 @@ import "./CapperRoleMock.sol";
contract IndividuallyCappedCrowdsaleImpl contract IndividuallyCappedCrowdsaleImpl
is Crowdsale, IndividuallyCappedCrowdsale, CapperRoleMock { is Crowdsale, IndividuallyCappedCrowdsale, CapperRoleMock {
constructor( constructor(
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token IERC20 token
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
IndividuallyCappedCrowdsale.initialize(msg.sender); IndividuallyCappedCrowdsale.initialize(msg.sender);
} }
} }
...@@ -5,15 +5,15 @@ import "../math/Math.sol"; ...@@ -5,15 +5,15 @@ import "../math/Math.sol";
contract MathMock { contract MathMock {
function max(uint256 a, uint256 b) public pure returns (uint256) { function max(uint256 a, uint256 b) public pure returns (uint256) {
return Math.max(a, b); return Math.max(a, b);
} }
function min(uint256 a, uint256 b) public pure returns (uint256) { function min(uint256 a, uint256 b) public pure returns (uint256) {
return Math.min(a, b); return Math.min(a, b);
} }
function average(uint256 a, uint256 b) public pure returns (uint256) { function average(uint256 a, uint256 b) public pure returns (uint256) {
return Math.average(a, b); return Math.average(a, b);
} }
} }
...@@ -5,15 +5,15 @@ import { MerkleProof } from "../cryptography/MerkleProof.sol"; ...@@ -5,15 +5,15 @@ import { MerkleProof } from "../cryptography/MerkleProof.sol";
contract MerkleProofWrapper { contract MerkleProofWrapper {
function verify( function verify(
bytes32[] proof, bytes32[] proof,
bytes32 root, bytes32 root,
bytes32 leaf bytes32 leaf
) )
public public
pure pure
returns (bool) returns (bool)
{ {
return MerkleProof.verify(proof, root, leaf); return MerkleProof.verify(proof, root, leaf);
} }
} }
...@@ -3,48 +3,48 @@ pragma solidity ^0.4.24; ...@@ -3,48 +3,48 @@ pragma solidity ^0.4.24;
contract MessageHelper { contract MessageHelper {
event Show(bytes32 b32, uint256 number, string text); event Show(bytes32 b32, uint256 number, string text);
event Buy(bytes32 b32, uint256 number, string text, uint256 value); event Buy(bytes32 b32, uint256 number, string text, uint256 value);
function showMessage( function showMessage(
bytes32 _message, bytes32 _message,
uint256 _number, uint256 _number,
string _text string _text
) )
public public
returns (bool) returns (bool)
{ {
emit Show(_message, _number, _text); emit Show(_message, _number, _text);
return true; return true;
} }
function buyMessage( function buyMessage(
bytes32 _message, bytes32 _message,
uint256 _number, uint256 _number,
string _text string _text
) )
public public
payable payable
returns (bool) returns (bool)
{ {
emit Buy( emit Buy(
_message, _message,
_number, _number,
_text, _text,
msg.value); msg.value);
return true; return true;
} }
function fail() public { function fail() public {
require(false); require(false);
} }
function call(address _to, bytes _data) public returns (bool) { function call(address _to, bytes _data) public returns (bool) {
// solium-disable-next-line security/no-low-level-calls // solium-disable-next-line security/no-low-level-calls
if (_to.call(_data)) if (_to.call(_data))
return true; return true;
else else
return false; return false;
} }
} }
...@@ -6,14 +6,14 @@ import "../crowdsale/emission/MintedCrowdsale.sol"; ...@@ -6,14 +6,14 @@ import "../crowdsale/emission/MintedCrowdsale.sol";
contract MintedCrowdsaleImpl is MintedCrowdsale { contract MintedCrowdsaleImpl is MintedCrowdsale {
constructor ( constructor (
uint256 rate, uint256 rate,
address wallet, address wallet,
ERC20Mintable token ERC20Mintable token
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
} }
} }
...@@ -4,19 +4,19 @@ import "../access/roles/MinterRole.sol"; ...@@ -4,19 +4,19 @@ import "../access/roles/MinterRole.sol";
contract MinterRoleMock is MinterRole { contract MinterRoleMock is MinterRole {
constructor() public { constructor() public {
MinterRole.initialize(msg.sender); MinterRole.initialize(msg.sender);
} }
function removeMinter(address account) public { function removeMinter(address account) public {
_removeMinter(account); _removeMinter(account);
} }
function onlyMinterMock() public view onlyMinter { function onlyMinterMock() public view onlyMinter {
} }
// Causes a compilation error if super._removeMinter is not internal // Causes a compilation error if super._removeMinter is not internal
function _removeMinter(address account) internal { function _removeMinter(address account) internal {
super._removeMinter(account); super._removeMinter(account);
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import { Ownable } from "../ownership/Ownable.sol"; import { Ownable } from "../ownership/Ownable.sol";
contract OwnableMock is Ownable { contract OwnableMock is Ownable {
constructor() { constructor() {
Ownable.initialize(msg.sender); Ownable.initialize(msg.sender);
} }
} }
...@@ -6,22 +6,22 @@ import "./PauserRoleMock.sol"; ...@@ -6,22 +6,22 @@ import "./PauserRoleMock.sol";
// mock class using Pausable // mock class using Pausable
contract PausableMock is Pausable, PauserRoleMock { contract PausableMock is Pausable, PauserRoleMock {
bool public drasticMeasureTaken; bool public drasticMeasureTaken;
uint256 public count; uint256 public count;
constructor() public { constructor() public {
Pausable.initialize(msg.sender); Pausable.initialize(msg.sender);
drasticMeasureTaken = false; drasticMeasureTaken = false;
count = 0; count = 0;
} }
function normalProcess() external whenNotPaused { function normalProcess() external whenNotPaused {
count++; count++;
} }
function drasticMeasure() external whenPaused { function drasticMeasure() external whenPaused {
drasticMeasureTaken = true; drasticMeasureTaken = true;
} }
} }
...@@ -4,19 +4,19 @@ import "../access/roles/PauserRole.sol"; ...@@ -4,19 +4,19 @@ import "../access/roles/PauserRole.sol";
contract PauserRoleMock is PauserRole { contract PauserRoleMock is PauserRole {
constructor() public { constructor() public {
PauserRole.initialize(msg.sender); PauserRole.initialize(msg.sender);
} }
function removePauser(address account) public { function removePauser(address account) public {
_removePauser(account); _removePauser(account);
} }
function onlyPauserMock() public view onlyPauser { function onlyPauserMock() public view onlyPauser {
} }
// Causes a compilation error if super._removePauser is not internal // Causes a compilation error if super._removePauser is not internal
function _removePauser(address account) internal { function _removePauser(address account) internal {
super._removePauser(account); super._removePauser(account);
} }
} }
...@@ -6,17 +6,17 @@ import "../crowdsale/distribution/PostDeliveryCrowdsale.sol"; ...@@ -6,17 +6,17 @@ import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale { contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale {
constructor ( constructor (
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token IERC20 token
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
} }
} }
...@@ -7,13 +7,13 @@ import "../payment/PullPayment.sol"; ...@@ -7,13 +7,13 @@ import "../payment/PullPayment.sol";
// mock class using PullPayment // mock class using PullPayment
contract PullPaymentMock is PullPayment { contract PullPaymentMock is PullPayment {
constructor() public payable { constructor() public payable {
PullPayment.initialize(); PullPayment.initialize();
} }
// test helper function to call asyncTransfer // test helper function to call asyncTransfer
function callTransfer(address dest, uint256 amount) public { function callTransfer(address dest, uint256 amount) public {
_asyncTransfer(dest, amount); _asyncTransfer(dest, amount);
} }
} }
...@@ -3,9 +3,9 @@ pragma solidity ^0.4.24; ...@@ -3,9 +3,9 @@ pragma solidity ^0.4.24;
contract ReentrancyAttack { contract ReentrancyAttack {
function callSender(bytes4 data) public { function callSender(bytes4 data) public {
// solium-disable-next-line security/no-low-level-calls // solium-disable-next-line security/no-low-level-calls
require(msg.sender.call(abi.encodeWithSelector(data))); require(msg.sender.call(abi.encodeWithSelector(data)));
} }
} }
...@@ -6,41 +6,41 @@ import "./ReentrancyAttack.sol"; ...@@ -6,41 +6,41 @@ import "./ReentrancyAttack.sol";
contract ReentrancyMock is ReentrancyGuard { contract ReentrancyMock is ReentrancyGuard {
uint256 public counter; uint256 public counter;
constructor() public { constructor() public {
ReentrancyGuard.initialize(); ReentrancyGuard.initialize();
counter = 0; counter = 0;
} }
function callback() external nonReentrant { function callback() external nonReentrant {
count(); count();
} }
function countLocalRecursive(uint256 n) public nonReentrant { function countLocalRecursive(uint256 n) public nonReentrant {
if (n > 0) { if (n > 0) {
count(); count();
countLocalRecursive(n - 1); countLocalRecursive(n - 1);
}
} }
}
function countThisRecursive(uint256 n) public nonReentrant {
function countThisRecursive(uint256 n) public nonReentrant { if (n > 0) {
if (n > 0) { count();
count(); // solium-disable-next-line security/no-low-level-calls
// solium-disable-next-line security/no-low-level-calls bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1)); require(result == true);
require(result == true); }
} }
}
function countAndCall(ReentrancyAttack attacker) public nonReentrant { function countAndCall(ReentrancyAttack attacker) public nonReentrant {
count(); count();
bytes4 func = bytes4(keccak256("callback()")); bytes4 func = bytes4(keccak256("callback()"));
attacker.callSender(func); attacker.callSender(func);
} }
function count() private { function count() private {
counter += 1; counter += 1;
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "../payment/RefundEscrow.sol"; import "../payment/RefundEscrow.sol";
contract RefundEscrowMock is RefundEscrow { contract RefundEscrowMock is RefundEscrow {
constructor(address beneficiary) public { constructor(address beneficiary) public {
RefundEscrow.initialize(beneficiary, msg.sender); RefundEscrow.initialize(beneficiary, msg.sender);
} }
} }
...@@ -6,19 +6,19 @@ import "../crowdsale/distribution/RefundableCrowdsale.sol"; ...@@ -6,19 +6,19 @@ import "../crowdsale/distribution/RefundableCrowdsale.sol";
contract RefundableCrowdsaleImpl is Crowdsale, TimedCrowdsale, RefundableCrowdsale { contract RefundableCrowdsaleImpl is Crowdsale, TimedCrowdsale, RefundableCrowdsale {
constructor ( constructor (
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
ERC20Mintable token, ERC20Mintable token,
uint256 goal uint256 goal
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
RefundableCrowdsale.initialize(goal); RefundableCrowdsale.initialize(goal);
} }
} }
...@@ -4,19 +4,19 @@ import "../access/Roles.sol"; ...@@ -4,19 +4,19 @@ import "../access/Roles.sol";
contract RolesMock { 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 { function add(address account) public {
dummyRole.add(account); dummyRole.add(account);
} }
function remove(address account) public { function remove(address account) public {
dummyRole.remove(account); dummyRole.remove(account);
} }
function has(address account) public view returns (bool) { function has(address account) public view returns (bool) {
return dummyRole.has(account); return dummyRole.has(account);
} }
} }
...@@ -5,91 +5,91 @@ import "../token/ERC20/SafeERC20.sol"; ...@@ -5,91 +5,91 @@ import "../token/ERC20/SafeERC20.sol";
contract ERC20FailingMock is IERC20 { contract ERC20FailingMock is IERC20 {
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return 0; return 0;
} }
function transfer(address, uint256) public returns (bool) { function transfer(address, uint256) public returns (bool) {
return false; return false;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(address, address, uint256) public returns (bool) {
return false; return false;
} }
function approve(address, uint256) public returns (bool) { function approve(address, uint256) public returns (bool) {
return false; return false;
} }
function balanceOf(address) public view returns (uint256) { function balanceOf(address) public view returns (uint256) {
return 0; return 0;
} }
function allowance(address, address) public view returns (uint256) { function allowance(address, address) public view returns (uint256) {
return 0; return 0;
} }
} }
contract ERC20SucceedingMock is IERC20 { contract ERC20SucceedingMock is IERC20 {
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return 0; return 0;
} }
function transfer(address, uint256) public returns (bool) { function transfer(address, uint256) public returns (bool) {
return true; return true;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(address, address, uint256) public returns (bool) {
return true; return true;
} }
function approve(address, uint256) public returns (bool) { function approve(address, uint256) public returns (bool) {
return true; return true;
} }
function balanceOf(address) public view returns (uint256) { function balanceOf(address) public view returns (uint256) {
return 0; return 0;
} }
function allowance(address, address) public view returns (uint256) { function allowance(address, address) public view returns (uint256) {
return 0; return 0;
} }
} }
contract SafeERC20Helper { contract SafeERC20Helper {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
IERC20 private _failing; IERC20 private _failing;
IERC20 private _succeeding; IERC20 private _succeeding;
constructor() public { constructor() public {
_failing = new ERC20FailingMock(); _failing = new ERC20FailingMock();
_succeeding = new ERC20SucceedingMock(); _succeeding = new ERC20SucceedingMock();
} }
function doFailingTransfer() public { function doFailingTransfer() public {
_failing.safeTransfer(address(0), 0); _failing.safeTransfer(address(0), 0);
} }
function doFailingTransferFrom() public { function doFailingTransferFrom() public {
_failing.safeTransferFrom(address(0), address(0), 0); _failing.safeTransferFrom(address(0), address(0), 0);
} }
function doFailingApprove() public { function doFailingApprove() public {
_failing.safeApprove(address(0), 0); _failing.safeApprove(address(0), 0);
} }
function doSucceedingTransfer() public { function doSucceedingTransfer() public {
_succeeding.safeTransfer(address(0), 0); _succeeding.safeTransfer(address(0), 0);
} }
function doSucceedingTransferFrom() public { function doSucceedingTransferFrom() public {
_succeeding.safeTransferFrom(address(0), address(0), 0); _succeeding.safeTransferFrom(address(0), address(0), 0);
} }
function doSucceedingApprove() public { function doSucceedingApprove() public {
_succeeding.safeApprove(address(0), 0); _succeeding.safeApprove(address(0), 0);
} }
} }
...@@ -6,23 +6,23 @@ import "../math/SafeMath.sol"; ...@@ -6,23 +6,23 @@ import "../math/SafeMath.sol";
contract SafeMathMock { contract SafeMathMock {
function mul(uint256 a, uint256 b) public pure returns (uint256) { function mul(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mul(a, b); return SafeMath.mul(a, b);
} }
function div(uint256 a, uint256 b) public pure returns (uint256) { function div(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.div(a, b); return SafeMath.div(a, b);
} }
function sub(uint256 a, uint256 b) public pure returns (uint256) { function sub(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.sub(a, b); return SafeMath.sub(a, b);
} }
function add(uint256 a, uint256 b) public pure returns (uint256) { function add(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.add(a, b); return SafeMath.add(a, b);
} }
function mod(uint256 a, uint256 b) public pure returns (uint256) { function mod(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mod(a, b); return SafeMath.mod(a, b);
} }
} }
...@@ -4,23 +4,23 @@ import "../examples/SampleCrowdsale.sol"; ...@@ -4,23 +4,23 @@ import "../examples/SampleCrowdsale.sol";
contract SampleCrowdsaleTokenMock is SampleCrowdsaleToken { contract SampleCrowdsaleTokenMock is SampleCrowdsaleToken {
constructor() public { constructor() public {
SampleCrowdsaleToken.initialize(msg.sender); SampleCrowdsaleToken.initialize(msg.sender);
} }
} }
contract SampleCrowdsaleMock is SampleCrowdsale { contract SampleCrowdsaleMock is SampleCrowdsale {
constructor( constructor(
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
uint256 cap, uint256 cap,
ERC20Mintable token, ERC20Mintable token,
uint256 goal uint256 goal
) )
public public
{ {
SampleCrowdsale.initialize(openingTime, closingTime, rate, wallet, cap, token, goal); SampleCrowdsale.initialize(openingTime, closingTime, rate, wallet, cap, token, goal);
} }
} }
...@@ -4,10 +4,10 @@ import "../ownership/Secondary.sol"; ...@@ -4,10 +4,10 @@ import "../ownership/Secondary.sol";
contract SecondaryMock is Secondary { contract SecondaryMock is Secondary {
constructor() public { constructor() public {
Secondary.initialize(msg.sender); Secondary.initialize(msg.sender);
} }
function onlyPrimaryMock() public view onlyPrimary { function onlyPrimaryMock() public view onlyPrimary {
} }
} }
...@@ -5,74 +5,74 @@ import "./SignerRoleMock.sol"; ...@@ -5,74 +5,74 @@ import "./SignerRoleMock.sol";
contract SignatureBouncerMock is SignatureBouncer, SignerRoleMock { contract SignatureBouncerMock is SignatureBouncer, SignerRoleMock {
constructor() public { constructor() public {
SignatureBouncer.initialize(msg.sender); SignatureBouncer.initialize(msg.sender);
} }
function checkValidSignature(address account, bytes signature) function checkValidSignature(address account, bytes signature)
public public
view view
returns (bool) returns (bool)
{ {
return _isValidSignature(account, signature); return _isValidSignature(account, signature);
} }
function onlyWithValidSignature(bytes signature) function onlyWithValidSignature(bytes signature)
public public
onlyValidSignature(signature) onlyValidSignature(signature)
view view
{ {
} }
function checkValidSignatureAndMethod(address account, bytes signature) function checkValidSignatureAndMethod(address account, bytes signature)
public public
view view
returns (bool) returns (bool)
{ {
return _isValidSignatureAndMethod(account, signature); return _isValidSignatureAndMethod(account, signature);
} }
function onlyWithValidSignatureAndMethod(bytes signature) function onlyWithValidSignatureAndMethod(bytes signature)
public public
onlyValidSignatureAndMethod(signature) onlyValidSignatureAndMethod(signature)
view view
{ {
} }
function checkValidSignatureAndData( function checkValidSignatureAndData(
address account, address account,
bytes, bytes,
uint, uint,
bytes signature bytes signature
) )
public public
view view
returns (bool) returns (bool)
{ {
return _isValidSignatureAndData(account, signature); return _isValidSignatureAndData(account, signature);
} }
function onlyWithValidSignatureAndData(uint, bytes signature) function onlyWithValidSignatureAndData(uint, bytes signature)
public public
onlyValidSignatureAndData(signature) onlyValidSignatureAndData(signature)
view view
{ {
} }
function theWrongMethod(bytes) function theWrongMethod(bytes)
public public
pure pure
{ {
} }
function tooShortMsgData() function tooShortMsgData()
public public
onlyValidSignatureAndData("") onlyValidSignatureAndData("")
view view
{ {
} }
} }
...@@ -4,19 +4,19 @@ import "../access/roles/SignerRole.sol"; ...@@ -4,19 +4,19 @@ import "../access/roles/SignerRole.sol";
contract SignerRoleMock is SignerRole { contract SignerRoleMock is SignerRole {
constructor() public { constructor() public {
SignerRole.initialize(msg.sender); SignerRole.initialize(msg.sender);
} }
function removeSigner(address account) public { function removeSigner(address account) public {
_removeSigner(account); _removeSigner(account);
} }
function onlySignerMock() public view onlySigner { function onlySignerMock() public view onlySigner {
} }
// Causes a compilation error if super._removeSigner is not internal // Causes a compilation error if super._removeSigner is not internal
function _removeSigner(address account) internal { function _removeSigner(address account) internal {
super._removeSigner(account); super._removeSigner(account);
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "../examples/SimpleToken.sol"; import "../examples/SimpleToken.sol";
contract SimpleTokenMock is SimpleToken { contract SimpleTokenMock is SimpleToken {
constructor() public { constructor() public {
SimpleToken.initialize(msg.sender); SimpleToken.initialize(msg.sender);
} }
} }
...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,7 @@ pragma solidity ^0.4.24;
import "../payment/SplitPayment.sol"; import "../payment/SplitPayment.sol";
contract SplitPaymentMock is SplitPayment { contract SplitPaymentMock is SplitPayment {
constructor(address[] payees, uint256[] shares) public { constructor(address[] payees, uint256[] shares) public {
SplitPayment.initialize(payees, shares); SplitPayment.initialize(payees, shares);
} }
} }
...@@ -6,17 +6,17 @@ import "../crowdsale/validation/TimedCrowdsale.sol"; ...@@ -6,17 +6,17 @@ import "../crowdsale/validation/TimedCrowdsale.sol";
contract TimedCrowdsaleImpl is TimedCrowdsale { contract TimedCrowdsaleImpl is TimedCrowdsale {
constructor ( constructor (
uint256 openingTime, uint256 openingTime,
uint256 closingTime, uint256 closingTime,
uint256 rate, uint256 rate,
address wallet, address wallet,
IERC20 token IERC20 token
) )
public public
{ {
Crowdsale.initialize(rate, wallet, token); Crowdsale.initialize(rate, wallet, token);
TimedCrowdsale.initialize(openingTime, closingTime); TimedCrowdsale.initialize(openingTime, closingTime);
} }
} }
...@@ -3,11 +3,11 @@ pragma solidity ^0.4.24; ...@@ -3,11 +3,11 @@ pragma solidity ^0.4.24;
import "../token/ERC20/TokenTimelock.sol"; import "../token/ERC20/TokenTimelock.sol";
contract TokenTimelockMock is TokenTimelock { contract TokenTimelockMock is TokenTimelock {
constructor( constructor(
IERC20 token, IERC20 token,
address beneficiary, address beneficiary,
uint256 releaseTime uint256 releaseTime
) public { ) public {
TokenTimelock.initialize(token, beneficiary, releaseTime); TokenTimelock.initialize(token, beneficiary, releaseTime);
} }
} }
...@@ -3,20 +3,20 @@ pragma solidity ^0.4.24; ...@@ -3,20 +3,20 @@ pragma solidity ^0.4.24;
import "../drafts/TokenVesting.sol"; import "../drafts/TokenVesting.sol";
contract TokenVestingMock is TokenVesting { contract TokenVestingMock is TokenVesting {
constructor( constructor(
address beneficiary, address beneficiary,
uint256 start, uint256 start,
uint256 cliffDuration, uint256 cliffDuration,
uint256 duration, uint256 duration,
bool revocable bool revocable
) public { ) public {
TokenVesting.initialize( TokenVesting.initialize(
beneficiary, beneficiary,
start, start,
cliffDuration, cliffDuration,
duration, duration,
revocable, revocable,
msg.sender msg.sender
); );
} }
} }
...@@ -8,74 +8,74 @@ import "zos-lib/contracts/Initializable.sol"; ...@@ -8,74 +8,74 @@ import "zos-lib/contracts/Initializable.sol";
* functions, this simplifies the implementation of "user permissions". * functions, this simplifies the implementation of "user permissions".
*/ */
contract Ownable is Initializable { contract Ownable is Initializable {
address private _owner; address private _owner;
event OwnershipRenounced(address indexed previousOwner); event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred( event OwnershipTransferred(
address indexed previousOwner, address indexed previousOwner,
address indexed newOwner address indexed newOwner
); );
/** /**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender * @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account. * account.
*/ */
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
_owner = sender; _owner = sender;
} }
/** /**
* @return the address of the owner. * @return the address of the owner.
*/ */
function owner() public view returns(address) { function owner() public view returns(address) {
return _owner; return _owner;
} }
/** /**
* @dev Throws if called by any account other than the owner. * @dev Throws if called by any account other than the owner.
*/ */
modifier onlyOwner() { modifier onlyOwner() {
require(isOwner()); require(isOwner());
_; _;
} }
/** /**
* @return true if `msg.sender` is the owner of the contract. * @return true if `msg.sender` is the owner of the contract.
*/ */
function isOwner() public view returns(bool) { function isOwner() public view returns(bool) {
return msg.sender == _owner; return msg.sender == _owner;
} }
/** /**
* @dev Allows the current owner to relinquish control of the contract. * @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner. * @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner` * It will not be possible to call the functions with the `onlyOwner`
* modifier anymore. * modifier anymore.
*/ */
function renounceOwnership() public onlyOwner { function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(_owner); emit OwnershipRenounced(_owner);
_owner = address(0); _owner = address(0);
} }
/** /**
* @dev Allows the current owner to transfer control of the contract to a newOwner. * @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to. * @param newOwner The address to transfer ownership to.
*/ */
function transferOwnership(address newOwner) public onlyOwner { function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner); _transferOwnership(newOwner);
} }
/** /**
* @dev Transfers control of the contract to a newOwner. * @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to. * @param newOwner The address to transfer ownership to.
*/ */
function _transferOwnership(address newOwner) internal { function _transferOwnership(address newOwner) internal {
require(newOwner != address(0)); require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner); emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner; _owner = newOwner;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -7,32 +7,32 @@ import "zos-lib/contracts/Initializable.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) * @dev A Secondary contract can only be used by its primary account (the one that created it)
*/ */
contract Secondary is Initializable { contract Secondary is Initializable {
address private _primary; address private _primary;
/** /**
* @dev Sets the primary account to the one that is creating the Secondary contract. * @dev Sets the primary account to the one that is creating the Secondary contract.
*/ */
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
_primary = sender; _primary = sender;
} }
/** /**
* @dev Reverts if called from any account other than the primary. * @dev Reverts if called from any account other than the primary.
*/ */
modifier onlyPrimary() { modifier onlyPrimary() {
require(msg.sender == _primary); require(msg.sender == _primary);
_; _;
} }
function primary() public view returns (address) { function primary() public view returns (address) {
return _primary; return _primary;
} }
function transferPrimary(address recipient) public onlyPrimary { function transferPrimary(address recipient) public onlyPrimary {
require(recipient != address(0)); require(recipient != address(0));
_primary = recipient; _primary = recipient;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -9,21 +9,21 @@ import "./Escrow.sol"; ...@@ -9,21 +9,21 @@ import "./Escrow.sol";
* @dev Base abstract escrow to only allow withdrawal if a condition is met. * @dev Base abstract escrow to only allow withdrawal if a condition is met.
*/ */
contract ConditionalEscrow is Initializable, Escrow { contract ConditionalEscrow is Initializable, Escrow {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
Escrow.initialize(sender); Escrow.initialize(sender);
} }
/** /**
* @dev Returns whether an address is allowed to withdraw their funds. To be * @dev Returns whether an address is allowed to withdraw their funds. To be
* implemented by derived contracts. * implemented by derived contracts.
* @param payee The destination address of the funds. * @param payee The destination address of the funds.
*/ */
function withdrawalAllowed(address payee) public view returns (bool); function withdrawalAllowed(address payee) public view returns (bool);
function withdraw(address payee) public { function withdraw(address payee) public {
require(withdrawalAllowed(payee)); require(withdrawalAllowed(payee));
super.withdraw(payee); super.withdraw(payee);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -13,45 +13,45 @@ import "../ownership/Secondary.sol"; ...@@ -13,45 +13,45 @@ import "../ownership/Secondary.sol";
* deposit and withdraw. * deposit and withdraw.
*/ */
contract Escrow is Initializable, Secondary { contract Escrow is Initializable, Secondary {
using SafeMath for uint256; using SafeMath for uint256;
event Deposited(address indexed payee, uint256 weiAmount); event Deposited(address indexed payee, uint256 weiAmount);
event Withdrawn(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 { function initialize(address sender) public initializer {
Secondary.initialize(sender); Secondary.initialize(sender);
} }
function depositsOf(address payee) public view returns (uint256) { function depositsOf(address payee) public view returns (uint256) {
return _deposits[payee]; return _deposits[payee];
} }
/** /**
* @dev Stores the sent amount as credit to be withdrawn. * @dev Stores the sent amount as credit to be withdrawn.
* @param payee The destination address of the funds. * @param payee The destination address of the funds.
*/ */
function deposit(address payee) public onlyPrimary payable { function deposit(address payee) public onlyPrimary payable {
uint256 amount = msg.value; uint256 amount = msg.value;
_deposits[payee] = _deposits[payee].add(amount); _deposits[payee] = _deposits[payee].add(amount);
emit Deposited(payee, amount); emit Deposited(payee, amount);
} }
/** /**
* @dev Withdraw accumulated balance for a payee. * @dev Withdraw accumulated balance for a payee.
* @param payee The address whose funds will be withdrawn and transferred to. * @param payee The address whose funds will be withdrawn and transferred to.
*/ */
function withdraw(address payee) public onlyPrimary { function withdraw(address payee) public onlyPrimary {
uint256 payment = _deposits[payee]; 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;
} }
...@@ -10,40 +10,40 @@ import "./Escrow.sol"; ...@@ -10,40 +10,40 @@ import "./Escrow.sol";
* contract and use _asyncTransfer instead of send or transfer. * contract and use _asyncTransfer instead of send or transfer.
*/ */
contract PullPayment is Initializable { 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));
}
}
/**
* @dev Withdraw accumulated balance.
* @param payee Whose balance will be withdrawn.
*/
function withdrawPayments(address payee) public {
_escrow.withdraw(payee);
}
function initialize() public initializer { /**
// conditional added to make initializer idempotent in case of diamond inheritance * @dev Returns the credit owed to an address.
if (address(_escrow) == address(0)) { * @param dest The creditor's address.
_escrow = new Escrow(); */
_escrow.initialize(address(this)); 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.
* @dev Withdraw accumulated balance. * @param dest The destination address of the funds.
* @param payee Whose balance will be withdrawn. * @param amount The amount to transfer.
*/ */
function withdrawPayments(address payee) public { function _asyncTransfer(address dest, uint256 amount) internal {
_escrow.withdraw(payee); _escrow.deposit.value(amount)(dest);
} }
/** uint256[50] private ______gap;
* @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);
}
uint256[50] private ______gap;
} }
...@@ -11,82 +11,82 @@ import "./ConditionalEscrow.sol"; ...@@ -11,82 +11,82 @@ import "./ConditionalEscrow.sol";
* by the beneficiary, or refunds to the depositors. * by the beneficiary, or refunds to the depositors.
*/ */
contract RefundEscrow is Initializable, ConditionalEscrow { contract RefundEscrow is Initializable, ConditionalEscrow {
enum State { Active, Refunding, Closed } enum State { Active, Refunding, Closed }
event Closed(); event Closed();
event RefundsEnabled(); event RefundsEnabled();
State private _state; State private _state;
address private _beneficiary; address private _beneficiary;
/** /**
* @dev Constructor. * @dev Constructor.
* @param beneficiary The beneficiary of the deposits. * @param beneficiary The beneficiary of the deposits.
*/ */
function initialize(address beneficiary, address sender) public initializer { function initialize(address beneficiary, address sender) public initializer {
ConditionalEscrow.initialize(sender); ConditionalEscrow.initialize(sender);
require(beneficiary != address(0)); require(beneficiary != address(0));
_beneficiary = beneficiary; _beneficiary = beneficiary;
_state = State.Active; _state = State.Active;
} }
/** /**
* @return the current state of the escrow. * @return the current state of the escrow.
*/ */
function state() public view returns (State) { function state() public view returns (State) {
return _state; return _state;
} }
/** /**
* @return the beneficiary of the escrow. * @return the beneficiary of the escrow.
*/ */
function beneficiary() public view returns (address) { function beneficiary() public view returns (address) {
return _beneficiary; return _beneficiary;
} }
/** /**
* @dev Stores funds that may later be refunded. * @dev Stores funds that may later be refunded.
* @param refundee The address funds will be sent to if a refund occurs. * @param refundee The address funds will be sent to if a refund occurs.
*/ */
function deposit(address refundee) public payable { function deposit(address refundee) public payable {
require(_state == State.Active); require(_state == State.Active);
super.deposit(refundee); super.deposit(refundee);
} }
/** /**
* @dev Allows for the beneficiary to withdraw their funds, rejecting * @dev Allows for the beneficiary to withdraw their funds, rejecting
* further deposits. * further deposits.
*/ */
function close() public onlyPrimary { function close() public onlyPrimary {
require(_state == State.Active); require(_state == State.Active);
_state = State.Closed; _state = State.Closed;
emit Closed(); emit Closed();
} }
/** /**
* @dev Allows for refunds to take place, rejecting further deposits. * @dev Allows for refunds to take place, rejecting further deposits.
*/ */
function enableRefunds() public onlyPrimary { function enableRefunds() public onlyPrimary {
require(_state == State.Active); require(_state == State.Active);
_state = State.Refunding; _state = State.Refunding;
emit RefundsEnabled(); emit RefundsEnabled();
} }
/** /**
* @dev Withdraws the beneficiary's funds. * @dev Withdraws the beneficiary's funds.
*/ */
function beneficiaryWithdraw() public { function beneficiaryWithdraw() public {
require(_state == State.Closed); require(_state == State.Closed);
_beneficiary.transfer(address(this).balance); _beneficiary.transfer(address(this).balance);
} }
/** /**
* @dev Returns whether refundees can withdraw their deposits (be refunded). * @dev Returns whether refundees can withdraw their deposits (be refunded).
*/ */
function withdrawalAllowed(address payee) public view returns (bool) { function withdrawalAllowed(address payee) public view returns (bool) {
return _state == State.Refunding; return _state == State.Refunding;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,103 +10,103 @@ import "../math/SafeMath.sol"; ...@@ -10,103 +10,103 @@ import "../math/SafeMath.sol";
* of people and split proportionately to some number of shares they own. * of people and split proportionately to some number of shares they own.
*/ */
contract SplitPayment is Initializable { contract SplitPayment is Initializable {
using SafeMath for uint256; using SafeMath for uint256;
uint256 private _totalShares; uint256 private _totalShares;
uint256 private _totalReleased; uint256 private _totalReleased;
mapping(address => uint256) private _shares; mapping(address => uint256) private _shares;
mapping(address => uint256) private _released; mapping(address => uint256) private _released;
address[] private _payees; address[] private _payees;
/** /**
* @dev Constructor * @dev Constructor
*/ */
function initialize(address[] payees, uint256[] shares) public payable initializer { function initialize(address[] payees, uint256[] shares) public payable initializer {
require(payees.length == shares.length); require(payees.length == shares.length);
require(payees.length > 0); require(payees.length > 0);
for (uint256 i = 0; i < payees.length; i++) { for (uint256 i = 0; i < payees.length; i++) {
_addPayee(payees[i], shares[i]); _addPayee(payees[i], shares[i]);
}
} }
}
/**
/** * @dev payable fallback
* @dev payable fallback */
*/ function () external payable {}
function () external payable {}
/**
/** * @return the total shares of the contract.
* @return the total shares of the contract. */
*/ function totalShares() public view returns(uint256) {
function totalShares() public view returns(uint256) { return _totalShares;
return _totalShares; }
}
/**
/** * @return the total amount already released.
* @return the total amount already released. */
*/ function totalReleased() public view returns(uint256) {
function totalReleased() public view returns(uint256) { return _totalReleased;
return _totalReleased; }
}
/**
/** * @return the shares of an account.
* @return the shares of an account. */
*/ function shares(address account) public view returns(uint256) {
function shares(address account) public view returns(uint256) { return _shares[account];
return _shares[account]; }
}
/**
/** * @return the amount already released to an account.
* @return the amount already released to an account. */
*/ function released(address account) public view returns(uint256) {
function released(address account) public view returns(uint256) { return _released[account];
return _released[account]; }
}
/**
/** * @return the address of a payee.
* @return the address of a payee. */
*/ function payee(uint256 index) public view returns(address) {
function payee(uint256 index) public view returns(address) { return _payees[index];
return _payees[index]; }
}
/**
/** * @dev Release one of the payee's proportional payment.
* @dev Release one of the payee's proportional payment. * @param account Whose payments will be released.
* @param account Whose payments will be released. */
*/ function release(address account) public {
function release(address account) public { require(_shares[account] > 0);
require(_shares[account] > 0);
uint256 totalReceived = address(this).balance.add(_totalReleased);
uint256 totalReceived = address(this).balance.add(_totalReleased); uint256 payment = totalReceived.mul(
uint256 payment = totalReceived.mul( _shares[account]).div(
_shares[account]).div( _totalShares).sub(
_totalShares).sub( _released[account]
_released[account] );
);
require(payment != 0);
require(payment != 0);
_released[account] = _released[account].add(payment);
_released[account] = _released[account].add(payment); _totalReleased = _totalReleased.add(payment);
_totalReleased = _totalReleased.add(payment);
account.transfer(payment);
account.transfer(payment); }
}
/**
/** * @dev Add a new payee to the contract.
* @dev Add a new payee to the contract. * @param account The address of the payee to add.
* @param account The address of the payee to add. * @param shares_ The number of shares owned by the payee.
* @param shares_ The number of shares owned by the payee. */
*/ function _addPayee(address account, uint256 shares_) internal {
function _addPayee(address account, uint256 shares_) internal { require(account != address(0));
require(account != address(0)); require(shares_ > 0);
require(shares_ > 0); require(_shares[account] == 0);
require(_shares[account] == 0);
_payees.push(account);
_payees.push(account); _shares[account] = shares_;
_shares[account] = shares_; _totalShares = _totalShares.add(shares_);
_totalShares = _totalShares.add(shares_); }
}
uint256[50] private ______gap;
uint256[50] private ______gap;
} }
...@@ -13,203 +13,203 @@ import "../../math/SafeMath.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 * Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ */
contract ERC20 is Initializable, IERC20 { 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 * @dev Total number of tokens in existence
*/ */
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return _totalSupply; return _totalSupply;
} }
/** /**
* @dev Gets the balance of the specified address. * @dev Gets the balance of the specified address.
* @param owner The address to query the the balance of. * @param owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address. * @return An uint256 representing the amount owned by the passed address.
*/ */
function balanceOf(address owner) public view returns (uint256) { function balanceOf(address owner) public view returns (uint256) {
return _balances[owner]; return _balances[owner];
} }
/** /**
* @dev Function to check the amount of tokens that an owner allowed to a 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 owner address The address which owns the funds.
* @param spender address The address which will spend 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. * @return A uint256 specifying the amount of tokens still available for the spender.
*/ */
function allowance( function allowance(
address owner, address owner,
address spender address spender
) )
public public
view view
returns (uint256) returns (uint256)
{ {
return _allowed[owner][spender]; return _allowed[owner][spender];
} }
/** /**
* @dev Transfer token for a specified address * @dev Transfer token for a specified address
* @param to The address to transfer to. * @param to The address to transfer to.
* @param value The amount to be transferred. * @param value The amount to be transferred.
*/ */
function transfer(address to, uint256 value) public returns (bool) { function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value); _transfer(msg.sender, to, value);
return true; return true;
} }
/** /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * @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 * 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 * 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: * 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 * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds. * @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent. * @param value The amount of tokens to be spent.
*/ */
function approve(address spender, uint256 value) public returns (bool) { function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0)); require(spender != address(0));
_allowed[msg.sender][spender] = value; _allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value); emit Approval(msg.sender, spender, value);
return true; return true;
} }
/** /**
* @dev Transfer tokens from one address to another * @dev Transfer tokens from one address to another
* @param from address The address which you want to send tokens from * @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to * @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred * @param value uint256 the amount of tokens to be transferred
*/ */
function transferFrom( function transferFrom(
address from, address from,
address to, address to,
uint256 value uint256 value
) )
public public
returns (bool) returns (bool)
{ {
require(value <= _allowed[from][msg.sender]); require(value <= _allowed[from][msg.sender]);
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
_transfer(from, to, value); _transfer(from, to, value);
return true; return true;
} }
/** /**
* @dev Increase the amount of tokens that an owner allowed to a spender. * @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To increment * 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 * allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined) * the first transaction is mined)
* From MonolithDAO Token.sol * From MonolithDAO Token.sol
* @param spender The address which will spend the funds. * @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by. * @param addedValue The amount of tokens to increase the allowance by.
*/ */
function increaseAllowance( function increaseAllowance(
address spender, address spender,
uint256 addedValue uint256 addedValue
) )
public public
returns (bool) returns (bool)
{ {
require(spender != address(0)); require(spender != address(0));
_allowed[msg.sender][spender] = ( _allowed[msg.sender][spender] = (
_allowed[msg.sender][spender].add(addedValue)); _allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true; return true;
} }
/** /**
* @dev Decrease the amount of tokens that an owner allowed to a spender. * @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To decrement * 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 * allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined) * the first transaction is mined)
* From MonolithDAO Token.sol * From MonolithDAO Token.sol
* @param spender The address which will spend the funds. * @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by. * @param subtractedValue The amount of tokens to decrease the allowance by.
*/ */
function decreaseAllowance( function decreaseAllowance(
address spender, address spender,
uint256 subtractedValue uint256 subtractedValue
) )
public public
returns (bool) returns (bool)
{ {
require(spender != address(0)); require(spender != address(0));
_allowed[msg.sender][spender] = ( _allowed[msg.sender][spender] = (
_allowed[msg.sender][spender].sub(subtractedValue)); _allowed[msg.sender][spender].sub(subtractedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true; return true;
} }
/** /**
* @dev Transfer token for a specified addresses * @dev Transfer token for a specified addresses
* @param from The address to transfer from. * @param from The address to transfer from.
* @param to The address to transfer to. * @param to The address to transfer to.
* @param value The amount to be transferred. * @param value The amount to be transferred.
*/ */
function _transfer(address from, address to, uint256 value) internal { function _transfer(address from, address to, uint256 value) internal {
require(value <= _balances[from]); require(value <= _balances[from]);
require(to != address(0)); require(to != address(0));
_balances[from] = _balances[from].sub(value); _balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value); _balances[to] = _balances[to].add(value);
emit Transfer(from, to, value); emit Transfer(from, to, value);
} }
/** /**
* @dev Internal function that mints an amount of the token and assigns it to * @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 * an account. This encapsulates the modification of balances such that the
* proper events are emitted. * proper events are emitted.
* @param account The account that will receive the created tokens. * @param account The account that will receive the created tokens.
* @param amount The amount that will be created. * @param amount The amount that will be created.
*/ */
function _mint(address account, uint256 amount) internal { function _mint(address account, uint256 amount) internal {
require(account != 0); require(account != 0);
_totalSupply = _totalSupply.add(amount); _totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount); _balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount); emit Transfer(address(0), account, amount);
} }
/** /**
* @dev Internal function that burns an amount of the token of a given * @dev Internal function that burns an amount of the token of a given
* account. * account.
* @param account The account whose tokens will be burnt. * @param account The account whose tokens will be burnt.
* @param amount The amount that will be burnt. * @param amount The amount that will be burnt.
*/ */
function _burn(address account, uint256 amount) internal { function _burn(address account, uint256 amount) internal {
require(account != 0); require(account != 0);
require(amount <= _balances[account]); require(amount <= _balances[account]);
_totalSupply = _totalSupply.sub(amount); _totalSupply = _totalSupply.sub(amount);
_balances[account] = _balances[account].sub(amount); _balances[account] = _balances[account].sub(amount);
emit Transfer(account, address(0), amount); emit Transfer(account, address(0), amount);
} }
/** /**
* @dev Internal function that burns an amount of the token of a given * @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 * account, deducting from the sender's allowance for said account. Uses the
* internal burn function. * internal burn function.
* @param account The account whose tokens will be burnt. * @param account The account whose tokens will be burnt.
* @param amount The amount that will be burnt. * @param amount The amount that will be burnt.
*/ */
function _burnFrom(address account, uint256 amount) internal { function _burnFrom(address account, uint256 amount) internal {
require(amount <= _allowed[account][msg.sender]); require(amount <= _allowed[account][msg.sender]);
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval. // this function needs to emit an event with the updated approval.
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub( _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(
amount); amount);
_burn(account, amount); _burn(account, amount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,22 +10,22 @@ import "./ERC20.sol"; ...@@ -10,22 +10,22 @@ import "./ERC20.sol";
*/ */
contract ERC20Burnable is Initializable, ERC20 { contract ERC20Burnable is Initializable, ERC20 {
/** /**
* @dev Burns a specific amount of tokens. * @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned. * @param value The amount of token to be burned.
*/ */
function burn(uint256 value) public { function burn(uint256 value) public {
_burn(msg.sender, value); _burn(msg.sender, value);
} }
/** /**
* @dev Burns a specific amount of tokens from the target address and decrements allowance * @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 from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned * @param value uint256 The amount of token to be burned
*/ */
function burnFrom(address from, uint256 value) public { function burnFrom(address from, uint256 value) public {
_burnFrom(from, value); _burnFrom(from, value);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,43 +10,43 @@ import "./ERC20Mintable.sol"; ...@@ -10,43 +10,43 @@ import "./ERC20Mintable.sol";
*/ */
contract ERC20Capped is Initializable, ERC20Mintable { contract ERC20Capped is Initializable, ERC20Mintable {
uint256 private _cap; uint256 private _cap;
function initialize(uint256 cap, address sender) function initialize(uint256 cap, address sender)
public public
initializer initializer
{ {
ERC20Mintable.initialize(sender); ERC20Mintable.initialize(sender);
require(cap > 0); require(cap > 0);
_cap = cap; _cap = cap;
} }
/** /**
* @return the cap for the token minting. * @return the cap for the token minting.
*/ */
function cap() public view returns(uint256) { function cap() public view returns(uint256) {
return _cap; return _cap;
} }
/** /**
* @dev Function to mint tokens * @dev Function to mint tokens
* @param to The address that will receive the minted tokens. * @param to The address that will receive the minted tokens.
* @param amount The amount of tokens to mint. * @param amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful. * @return A boolean that indicates if the operation was successful.
*/ */
function mint( function mint(
address to, address to,
uint256 amount uint256 amount
) )
public public
returns (bool) returns (bool)
{ {
require(totalSupply().add(amount) <= _cap); require(totalSupply().add(amount) <= _cap);
return super.mint(to, amount); return super.mint(to, amount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -11,36 +11,36 @@ import "./IERC20.sol"; ...@@ -11,36 +11,36 @@ import "./IERC20.sol";
* just as on Ethereum all the operations are done in wei. * just as on Ethereum all the operations are done in wei.
*/ */
contract ERC20Detailed is Initializable, IERC20 { contract ERC20Detailed is Initializable, IERC20 {
string private _name; string private _name;
string private _symbol; string private _symbol;
uint8 private _decimals; uint8 private _decimals;
function initialize(string name, string symbol, uint8 decimals) public initializer { function initialize(string name, string symbol, uint8 decimals) public initializer {
_name = name; _name = name;
_symbol = symbol; _symbol = symbol;
_decimals = decimals; _decimals = decimals;
} }
/** /**
* @return the name of the token. * @return the name of the token.
*/ */
function name() public view returns(string) { function name() public view returns(string) {
return _name; return _name;
} }
/** /**
* @return the symbol of the token. * @return the symbol of the token.
*/ */
function symbol() public view returns(string) { function symbol() public view returns(string) {
return _symbol; return _symbol;
} }
/** /**
* @return the number of decimals of the token. * @return the number of decimals of the token.
*/ */
function decimals() public view returns(uint8) { function decimals() public view returns(uint8) {
return _decimals; return _decimals;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,27 +10,27 @@ import "../../access/roles/MinterRole.sol"; ...@@ -10,27 +10,27 @@ import "../../access/roles/MinterRole.sol";
* @dev ERC20 minting logic * @dev ERC20 minting logic
*/ */
contract ERC20Mintable is Initializable, ERC20, MinterRole { contract ERC20Mintable is Initializable, ERC20, MinterRole {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
MinterRole.initialize(sender); MinterRole.initialize(sender);
} }
/** /**
* @dev Function to mint tokens * @dev Function to mint tokens
* @param to The address that will receive the minted tokens. * @param to The address that will receive the minted tokens.
* @param amount The amount of tokens to mint. * @param amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful. * @return A boolean that indicates if the operation was successful.
*/ */
function mint( function mint(
address to, address to,
uint256 amount uint256 amount
) )
public public
onlyMinter onlyMinter
returns (bool) returns (bool)
{ {
_mint(to, amount); _mint(to, amount);
return true; return true;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -11,65 +11,65 @@ import "../../lifecycle/Pausable.sol"; ...@@ -11,65 +11,65 @@ import "../../lifecycle/Pausable.sol";
**/ **/
contract ERC20Pausable is Initializable, ERC20, Pausable { contract ERC20Pausable is Initializable, ERC20, Pausable {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
Pausable.initialize(sender); Pausable.initialize(sender);
} }
function transfer( function transfer(
address to, address to,
uint256 value uint256 value
) )
public public
whenNotPaused whenNotPaused
returns (bool) returns (bool)
{ {
return super.transfer(to, value); return super.transfer(to, value);
} }
function transferFrom( function transferFrom(
address from, address from,
address to, address to,
uint256 value uint256 value
) )
public public
whenNotPaused whenNotPaused
returns (bool) returns (bool)
{ {
return super.transferFrom(from, to, value); return super.transferFrom(from, to, value);
} }
function approve( function approve(
address spender, address spender,
uint256 value uint256 value
) )
public public
whenNotPaused whenNotPaused
returns (bool) returns (bool)
{ {
return super.approve(spender, value); return super.approve(spender, value);
} }
function increaseAllowance( function increaseAllowance(
address spender, address spender,
uint addedValue uint addedValue
) )
public public
whenNotPaused whenNotPaused
returns (bool success) returns (bool success)
{ {
return super.increaseAllowance(spender, addedValue); return super.increaseAllowance(spender, addedValue);
} }
function decreaseAllowance( function decreaseAllowance(
address spender, address spender,
uint subtractedValue uint subtractedValue
) )
public public
whenNotPaused whenNotPaused
returns (bool success) returns (bool success)
{ {
return super.decreaseAllowance(spender, subtractedValue); return super.decreaseAllowance(spender, subtractedValue);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -6,30 +6,30 @@ pragma solidity ^0.4.24; ...@@ -6,30 +6,30 @@ pragma solidity ^0.4.24;
* @dev see https://github.com/ethereum/EIPs/issues/20 * @dev see https://github.com/ethereum/EIPs/issues/20
*/ */
interface IERC20 { 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) function allowance(address owner, address spender)
external view returns (uint256); 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) function approve(address spender, uint256 value)
external returns (bool); external returns (bool);
function transferFrom(address from, address to, uint256 value) function transferFrom(address from, address to, uint256 value)
external returns (bool); external returns (bool);
event Transfer( event Transfer(
address indexed from, address indexed from,
address indexed to, address indexed to,
uint256 value uint256 value
); );
event Approval( event Approval(
address indexed owner, address indexed owner,
address indexed spender, address indexed spender,
uint256 value uint256 value
); );
} }
...@@ -11,34 +11,34 @@ import "./IERC20.sol"; ...@@ -11,34 +11,34 @@ import "./IERC20.sol";
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc. * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/ */
library SafeERC20 { library SafeERC20 {
function safeTransfer( function safeTransfer(
IERC20 token, IERC20 token,
address to, address to,
uint256 value uint256 value
) )
internal internal
{ {
require(token.transfer(to, value)); require(token.transfer(to, value));
} }
function safeTransferFrom( function safeTransferFrom(
IERC20 token, IERC20 token,
address from, address from,
address to, address to,
uint256 value uint256 value
) )
internal internal
{ {
require(token.transferFrom(from, to, value)); require(token.transferFrom(from, to, value));
} }
function safeApprove( function safeApprove(
IERC20 token, IERC20 token,
address spender, address spender,
uint256 value uint256 value
) )
internal internal
{ {
require(token.approve(spender, value)); require(token.approve(spender, value));
} }
} }
...@@ -11,55 +11,55 @@ import "./ERC20Pausable.sol"; ...@@ -11,55 +11,55 @@ import "./ERC20Pausable.sol";
* *
*/ */
contract StandaloneERC20 is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable { contract StandaloneERC20 is Initializable, ERC20Detailed, ERC20Mintable, ERC20Pausable {
function initialize( function initialize(
string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder, string name, string symbol, uint8 decimals, uint256 initialSupply, address initialHolder,
address[] minters, address[] pausers address[] minters, address[] pausers
) public initializer { ) public initializer {
require(initialSupply > 0); require(initialSupply > 0);
ERC20Detailed.initialize(name, symbol, decimals); ERC20Detailed.initialize(name, symbol, decimals);
// Mint the initial supply // Mint the initial supply
_mint(initialHolder, initialSupply); _mint(initialHolder, initialSupply);
// Initialize the minter and pauser roles, and renounce them // Initialize the minter and pauser roles, and renounce them
ERC20Mintable.initialize(address(this)); ERC20Mintable.initialize(address(this));
renounceMinter(); renounceMinter();
ERC20Pausable.initialize(address(this)); ERC20Pausable.initialize(address(this));
renouncePauser(); renouncePauser();
// Add the requested minters and pausers (this can be done after renouncing since // Add the requested minters and pausers (this can be done after renouncing since
// these are the internal calls) // these are the internal calls)
for (uint256 i = 0; i < minters.length; ++i) { for (uint256 i = 0; i < minters.length; ++i) {
_addMinter(minters[i]); _addMinter(minters[i]);
} }
for (i = 0; i < pausers.length; ++i) { for (i = 0; i < pausers.length; ++i) {
_addPauser(pausers[i]); _addPauser(pausers[i]);
}
} }
}
function initialize( function initialize(
string name, string symbol, uint8 decimals, address[] minters, address[] pausers string name, string symbol, uint8 decimals, address[] minters, address[] pausers
) public initializer { ) public initializer {
ERC20Detailed.initialize(name, symbol, decimals); ERC20Detailed.initialize(name, symbol, decimals);
// Initialize the minter and pauser roles, and renounce them // Initialize the minter and pauser roles, and renounce them
ERC20Mintable.initialize(address(this)); ERC20Mintable.initialize(address(this));
renounceMinter(); renounceMinter();
ERC20Pausable.initialize(address(this)); ERC20Pausable.initialize(address(this));
renouncePauser(); renouncePauser();
// Add the requested minters and pausers (this can be done after renouncing since // Add the requested minters and pausers (this can be done after renouncing since
// these are the internal calls) // these are the internal calls)
for (uint256 i = 0; i < minters.length; ++i) { for (uint256 i = 0; i < minters.length; ++i) {
_addMinter(minters[i]); _addMinter(minters[i]);
} }
for (i = 0; i < pausers.length; ++i) { for (i = 0; i < pausers.length; ++i) {
_addPauser(pausers[i]); _addPauser(pausers[i]);
}
} }
}
} }
...@@ -10,65 +10,65 @@ import "./SafeERC20.sol"; ...@@ -10,65 +10,65 @@ import "./SafeERC20.sol";
* beneficiary to extract the tokens after a given release time * beneficiary to extract the tokens after a given release time
*/ */
contract TokenTimelock is Initializable { contract TokenTimelock is Initializable {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
// ERC20 basic token contract being held // ERC20 basic token contract being held
IERC20 private _token; IERC20 private _token;
// beneficiary of tokens after they are released // beneficiary of tokens after they are released
address private _beneficiary; address private _beneficiary;
// timestamp when token release is enabled // timestamp when token release is enabled
uint256 private _releaseTime; uint256 private _releaseTime;
function initialize( function initialize(
IERC20 token, IERC20 token,
address beneficiary, address beneficiary,
uint256 releaseTime uint256 releaseTime
) )
public public
initializer initializer
{ {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
require(releaseTime > block.timestamp); require(releaseTime > block.timestamp);
_token = token; _token = token;
_beneficiary = beneficiary; _beneficiary = beneficiary;
_releaseTime = releaseTime; _releaseTime = releaseTime;
} }
/** /**
* @return the token being held. * @return the token being held.
*/ */
function token() public view returns(IERC20) { function token() public view returns(IERC20) {
return _token; return _token;
} }
/** /**
* @return the beneficiary of the tokens. * @return the beneficiary of the tokens.
*/ */
function beneficiary() public view returns(address) { function beneficiary() public view returns(address) {
return _beneficiary; return _beneficiary;
} }
/** /**
* @return the time when the tokens are released. * @return the time when the tokens are released.
*/ */
function releaseTime() public view returns(uint256) { function releaseTime() public view returns(uint256) {
return _releaseTime; return _releaseTime;
} }
/** /**
* @notice Transfers tokens held by timelock to beneficiary. * @notice Transfers tokens held by timelock to beneficiary.
*/ */
function release() public { function release() public {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime); require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this)); uint256 amount = _token.balanceOf(address(this));
require(amount > 0); require(amount > 0);
_token.safeTransfer(_beneficiary, amount); _token.safeTransfer(_beneficiary, amount);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -14,323 +14,323 @@ import "../../introspection/ERC165.sol"; ...@@ -14,323 +14,323 @@ import "../../introspection/ERC165.sol";
*/ */
contract ERC721 is Initializable, ERC165, IERC721 { contract ERC721 is Initializable, ERC165, IERC721 {
using SafeMath for uint256; using SafeMath for uint256;
using Address for address; using Address for address;
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
// Mapping from token ID to owner // Mapping from token ID to owner
mapping (uint256 => address) private _tokenOwner; mapping (uint256 => address) private _tokenOwner;
// Mapping from token ID to approved address // Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals; mapping (uint256 => address) private _tokenApprovals;
// Mapping from owner to number of owned token // Mapping from owner to number of owned token
mapping (address => uint256) private _ownedTokensCount; mapping (address => uint256) private _ownedTokensCount;
// Mapping from owner to operator approvals // Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals; mapping (address => mapping (address => bool)) private _operatorApprovals;
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/* /*
* 0x80ac58cd === * 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/ */
function initialize() function initialize()
public public
initializer initializer
{ {
ERC165.initialize(); ERC165.initialize();
// register the supported interfaces to conform to ERC721 via ERC165 // register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721); _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);
} }
}
function _hasBeenInitialized() internal view returns (bool) {
/** return supportsInterface(_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 /**
*/ * @dev Gets the balance of the specified address
function _addTokenTo(address to, uint256 tokenId) internal { * @param owner address to query the balance of
require(_tokenOwner[tokenId] == address(0)); * @return uint256 representing the amount owned by the passed address
_tokenOwner[tokenId] = to; */
_ownedTokensCount[to] = _ownedTokensCount[to].add(1); function balanceOf(address owner) public view returns (uint256) {
} require(owner != address(0));
return _ownedTokensCount[owner];
/** }
* @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 * @dev Gets the owner of the specified token ID
*/ * @param tokenId uint256 ID of the token to query the owner of
function _removeTokenFrom(address from, uint256 tokenId) internal { * @return owner address currently marked as the owner of the given token ID
require(ownerOf(tokenId) == from); */
_ownedTokensCount[from] = _ownedTokensCount[from].sub(1); function ownerOf(uint256 tokenId) public view returns (address) {
_tokenOwner[tokenId] = address(0); address owner = _tokenOwner[tokenId];
} require(owner != address(0));
return owner;
/** }
* @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 * @dev Approves another address to transfer the given token ID
* @param to target address that will receive the tokens * The zero address indicates there is no approved address.
* @param tokenId uint256 ID of the token to be transferred * There can only be one approved address per token at a given time.
* @param _data bytes optional data to send along with the call * Can only be called by the token owner or an approved operator.
* @return whether the call correctly returned the expected magic value * @param to address to be approved for the given token ID
*/ * @param tokenId uint256 ID of the token to be approved
function _checkAndCallSafeTransfer( */
address from, function approve(address to, uint256 tokenId) public {
address to, address owner = ownerOf(tokenId);
uint256 tokenId, require(to != owner);
bytes _data require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
)
internal _tokenApprovals[tokenId] = to;
returns (bool) emit Approval(owner, to, tokenId);
{ }
if (!to.isContract()) {
return true; /**
* @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);
} }
bytes4 retval = IERC721Receiver(to).onERC721Received(
msg.sender, from, tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -5,12 +5,12 @@ import "./ERC721.sol"; ...@@ -5,12 +5,12 @@ import "./ERC721.sol";
contract ERC721Burnable is Initializable, ERC721 { contract ERC721Burnable is Initializable, ERC721 {
function burn(uint256 tokenId) function burn(uint256 tokenId)
public public
{ {
require(_isApprovedOrOwner(msg.sender, tokenId)); require(_isApprovedOrOwner(msg.sender, tokenId));
_burn(ownerOf(tokenId), tokenId); _burn(ownerOf(tokenId), tokenId);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -7,149 +7,149 @@ import "../../introspection/ERC165.sol"; ...@@ -7,149 +7,149 @@ import "../../introspection/ERC165.sol";
contract ERC721Enumerable is Initializable, ERC165, ERC721, IERC721Enumerable { contract ERC721Enumerable is Initializable, ERC165, ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs // Mapping from owner to list of owned token IDs
mapping(address => uint256[]) private _ownedTokens; mapping(address => uint256[]) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list // Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex; mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration // Array with all token ids, used for enumeration
uint256[] private _allTokens; uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array // Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex; mapping(uint256 => uint256) private _allTokensIndex;
bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63;
/** /**
* 0x780e9d63 === * 0x780e9d63 ===
* bytes4(keccak256('totalSupply()')) ^ * bytes4(keccak256('totalSupply()')) ^
* bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^
* bytes4(keccak256('tokenByIndex(uint256)')) * bytes4(keccak256('tokenByIndex(uint256)'))
*/ */
/** /**
* @dev Constructor function * @dev Constructor function
*/ */
function initialize() public initializer { function initialize() public initializer {
require(ERC721._hasBeenInitialized()); require(ERC721._hasBeenInitialized());
// register the supported interface to conform to ERC721 via ERC165 // register the supported interface to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721Enumerable);
} }
function _hasBeenInitialized() internal view returns (bool) { function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(_InterfaceId_ERC721Enumerable); return supportsInterface(_InterfaceId_ERC721Enumerable);
} }
/** /**
* @dev Gets the token ID at a given index of the tokens list of the requested owner * @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 owner address owning the tokens list to be accessed
* @param index uint256 representing the index to be accessed of the requested tokens list * @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 * @return uint256 token ID at the given index of the tokens list owned by the requested address
*/ */
function tokenOfOwnerByIndex( function tokenOfOwnerByIndex(
address owner, address owner,
uint256 index uint256 index
) )
public public
view view
returns (uint256) returns (uint256)
{ {
require(index < balanceOf(owner)); require(index < balanceOf(owner));
return _ownedTokens[owner][index]; return _ownedTokens[owner][index];
} }
/** /**
* @dev Gets the total amount of tokens stored by the contract * @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens * @return uint256 representing the total amount of tokens
*/ */
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return _allTokens.length; return _allTokens.length;
} }
/** /**
* @dev Gets the token ID at a given index of all the tokens in this contract * @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 * 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 * @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 * @return uint256 token ID at the given index of the tokens list
*/ */
function tokenByIndex(uint256 index) public view returns (uint256) { function tokenByIndex(uint256 index) public view returns (uint256) {
require(index < totalSupply()); require(index < totalSupply());
return _allTokens[index]; return _allTokens[index];
} }
/** /**
* @dev Internal function to add a token ID to the list of a given address * @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 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 * @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 { function _addTokenTo(address to, uint256 tokenId) internal {
super._addTokenTo(to, tokenId); super._addTokenTo(to, tokenId);
uint256 length = _ownedTokens[to].length; uint256 length = _ownedTokens[to].length;
_ownedTokens[to].push(tokenId); _ownedTokens[to].push(tokenId);
_ownedTokensIndex[tokenId] = length; _ownedTokensIndex[tokenId] = length;
} }
/** /**
* @dev Internal function to remove a token ID from the list of a given address * @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 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 * @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 { function _removeTokenFrom(address from, uint256 tokenId) internal {
super._removeTokenFrom(from, tokenId); 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 // 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. // then delete the last slot.
uint256 tokenIndex = _ownedTokensIndex[tokenId]; uint256 tokenIndex = _ownedTokensIndex[tokenId];
uint256 lastTokenIndex = _ownedTokens[from].length.sub(1); uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);
uint256 lastToken = _ownedTokens[from][lastTokenIndex]; uint256 lastToken = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastToken; _ownedTokens[from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array // This also deletes the contents at the last position of the array
_ownedTokens[from].length--; _ownedTokens[from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to // 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 // 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 // the lastToken to the first position, and then dropping the element placed in the last position of the list
_ownedTokensIndex[tokenId] = 0; _ownedTokensIndex[tokenId] = 0;
_ownedTokensIndex[lastToken] = tokenIndex; _ownedTokensIndex[lastToken] = tokenIndex;
} }
/** /**
* @dev Internal function to mint a new token * @dev Internal function to mint a new token
* Reverts if the given token ID already exists * Reverts if the given token ID already exists
* @param to address the beneficiary that will own the minted token * @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 * @param tokenId uint256 ID of the token to be minted by the msg.sender
*/ */
function _mint(address to, uint256 tokenId) internal { function _mint(address to, uint256 tokenId) internal {
super._mint(to, tokenId); super._mint(to, tokenId);
_allTokensIndex[tokenId] = _allTokens.length; _allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId); _allTokens.push(tokenId);
} }
/** /**
* @dev Internal function to burn a specific token * @dev Internal function to burn a specific token
* Reverts if the token does not exist * Reverts if the token does not exist
* @param owner owner of the token to burn * @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender * @param tokenId uint256 ID of the token being burned by the msg.sender
*/ */
function _burn(address owner, uint256 tokenId) internal { function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId); super._burn(owner, tokenId);
// Reorg all tokens array // Reorg all tokens array
uint256 tokenIndex = _allTokensIndex[tokenId]; uint256 tokenIndex = _allTokensIndex[tokenId];
uint256 lastTokenIndex = _allTokens.length.sub(1); uint256 lastTokenIndex = _allTokens.length.sub(1);
uint256 lastToken = _allTokens[lastTokenIndex]; uint256 lastToken = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastToken; _allTokens[tokenIndex] = lastToken;
_allTokens[lastTokenIndex] = 0; _allTokens[lastTokenIndex] = 0;
_allTokens.length--; _allTokens.length--;
_allTokensIndex[tokenId] = 0; _allTokensIndex[tokenId] = 0;
_allTokensIndex[lastToken] = tokenIndex; _allTokensIndex[lastToken] = tokenIndex;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -13,5 +13,5 @@ import "./ERC721Metadata.sol"; ...@@ -13,5 +13,5 @@ import "./ERC721Metadata.sol";
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ */
contract ERC721Full is Initializable, ERC721, ERC721Enumerable, ERC721Metadata { contract ERC721Full is Initializable, ERC721, ERC721Enumerable, ERC721Metadata {
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -5,17 +5,17 @@ import "./IERC721Receiver.sol"; ...@@ -5,17 +5,17 @@ import "./IERC721Receiver.sol";
contract ERC721Holder is Initializable, IERC721Receiver { contract ERC721Holder is Initializable, IERC721Receiver {
function onERC721Received( function onERC721Received(
address, address,
address, address,
uint256, uint256,
bytes bytes
) )
public public
returns(bytes4) returns(bytes4)
{ {
return this.onERC721Received.selector; return this.onERC721Received.selector;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -7,91 +7,91 @@ import "../../introspection/ERC165.sol"; ...@@ -7,91 +7,91 @@ import "../../introspection/ERC165.sol";
contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata { contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata {
// Token name // Token name
string internal _name; string internal _name;
// Token symbol // Token symbol
string internal _symbol; string internal _symbol;
// Optional mapping for token URIs // Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs; mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/** /**
* 0x5b5e139f === * 0x5b5e139f ===
* bytes4(keccak256('name()')) ^ * bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^ * bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)')) * bytes4(keccak256('tokenURI(uint256)'))
*/ */
/** /**
* @dev Constructor function * @dev Constructor function
*/ */
function initialize(string name, string symbol) public initializer { function initialize(string name, string symbol) public initializer {
require(ERC721._hasBeenInitialized()); require(ERC721._hasBeenInitialized());
_name = name; _name = name;
_symbol = symbol; _symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165 // register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata); _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];
} }
}
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;
} }
...@@ -10,32 +10,32 @@ import "../../access/roles/MinterRole.sol"; ...@@ -10,32 +10,32 @@ import "../../access/roles/MinterRole.sol";
* @dev ERC721 minting logic with metadata * @dev ERC721 minting logic with metadata
*/ */
contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole { contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
require(ERC721._hasBeenInitialized()); require(ERC721._hasBeenInitialized());
require(ERC721Metadata._hasBeenInitialized()); require(ERC721Metadata._hasBeenInitialized());
MinterRole.initialize(sender); MinterRole.initialize(sender);
} }
/** /**
* @dev Function to mint tokens * @dev Function to mint tokens
* @param to The address that will receive the minted tokens. * @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint. * @param tokenId The token id to mint.
* @param tokenURI The token URI of the minted token. * @param tokenURI The token URI of the minted token.
* @return A boolean that indicates if the operation was successful. * @return A boolean that indicates if the operation was successful.
*/ */
function mintWithTokenURI( function mintWithTokenURI(
address to, address to,
uint256 tokenId, uint256 tokenId,
string tokenURI string tokenURI
) )
public public
onlyMinter onlyMinter
returns (bool) returns (bool)
{ {
_mint(to, tokenId); _mint(to, tokenId);
_setTokenURI(tokenId, tokenURI); _setTokenURI(tokenId, tokenURI);
return true; return true;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,28 +10,28 @@ import "../../access/roles/MinterRole.sol"; ...@@ -10,28 +10,28 @@ import "../../access/roles/MinterRole.sol";
* @dev ERC721 minting logic * @dev ERC721 minting logic
*/ */
contract ERC721Mintable is Initializable, ERC721, MinterRole { contract ERC721Mintable is Initializable, ERC721, MinterRole {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
require(ERC721._hasBeenInitialized()); require(ERC721._hasBeenInitialized());
MinterRole.initialize(sender); MinterRole.initialize(sender);
} }
/** /**
* @dev Function to mint tokens * @dev Function to mint tokens
* @param to The address that will receive the minted tokens. * @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint. * @param tokenId The token id to mint.
* @return A boolean that indicates if the operation was successful. * @return A boolean that indicates if the operation was successful.
*/ */
function mint( function mint(
address to, address to,
uint256 tokenId uint256 tokenId
) )
public public
onlyMinter onlyMinter
returns (bool) returns (bool)
{ {
_mint(to, tokenId); _mint(to, tokenId);
return true; return true;
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,41 +10,41 @@ import "../../lifecycle/Pausable.sol"; ...@@ -10,41 +10,41 @@ import "../../lifecycle/Pausable.sol";
* @dev ERC721 modified with pausable transfers. * @dev ERC721 modified with pausable transfers.
**/ **/
contract ERC721Pausable is Initializable, ERC721, Pausable { contract ERC721Pausable is Initializable, ERC721, Pausable {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
require(ERC721._hasBeenInitialized()); require(ERC721._hasBeenInitialized());
Pausable.initialize(sender); Pausable.initialize(sender);
} }
function approve( function approve(
address to, address to,
uint256 tokenId uint256 tokenId
) )
public public
whenNotPaused whenNotPaused
{ {
super.approve(to, tokenId); super.approve(to, tokenId);
} }
function setApprovalForAll( function setApprovalForAll(
address to, address to,
bool approved bool approved
) )
public public
whenNotPaused whenNotPaused
{ {
super.setApprovalForAll(to, approved); super.setApprovalForAll(to, approved);
} }
function transferFrom( function transferFrom(
address from, address from,
address to, address to,
uint256 tokenId uint256 tokenId
) )
public public
whenNotPaused whenNotPaused
{ {
super.transferFrom(from, to, tokenId); super.transferFrom(from, to, tokenId);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
...@@ -10,42 +10,42 @@ import "../../introspection/IERC165.sol"; ...@@ -10,42 +10,42 @@ import "../../introspection/IERC165.sol";
*/ */
contract IERC721 is Initializable, IERC165 { contract IERC721 is Initializable, IERC165 {
event Transfer( event Transfer(
address indexed from, address indexed from,
address indexed to, address indexed to,
uint256 indexed tokenId uint256 indexed tokenId
); );
event Approval( event Approval(
address indexed owner, address indexed owner,
address indexed approved, address indexed approved,
uint256 indexed tokenId uint256 indexed tokenId
); );
event ApprovalForAll( event ApprovalForAll(
address indexed owner, address indexed owner,
address indexed operator, address indexed operator,
bool approved bool approved
); );
function balanceOf(address owner) public view returns (uint256 balance); function balanceOf(address owner) public view returns (uint256 balance);
function ownerOf(uint256 tokenId) public view returns (address owner); function ownerOf(uint256 tokenId) public view returns (address owner);
function approve(address to, uint256 tokenId) public; function approve(address to, uint256 tokenId) public;
function getApproved(uint256 tokenId) function getApproved(uint256 tokenId)
public view returns (address operator); public view returns (address operator);
function setApprovalForAll(address operator, bool _approved) public; function setApprovalForAll(address operator, bool _approved) public;
function isApprovedForAll(address owner, address operator) function isApprovedForAll(address owner, address operator)
public view returns (bool); public view returns (bool);
function transferFrom(address from, address to, uint256 tokenId) public; function transferFrom(address from, address to, uint256 tokenId) public;
function safeTransferFrom(address from, address to, uint256 tokenId) function safeTransferFrom(address from, address to, uint256 tokenId)
public; public;
function safeTransferFrom( function safeTransferFrom(
address from, address from,
address to, address to,
uint256 tokenId, uint256 tokenId,
bytes data bytes data
) )
public; public;
} }
...@@ -9,14 +9,14 @@ import "./IERC721.sol"; ...@@ -9,14 +9,14 @@ import "./IERC721.sol";
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ */
contract IERC721Enumerable is Initializable, IERC721 { contract IERC721Enumerable is Initializable, IERC721 {
function totalSupply() public view returns (uint256); function totalSupply() public view returns (uint256);
function tokenOfOwnerByIndex( function tokenOfOwnerByIndex(
address owner, address owner,
uint256 index uint256 index
) )
public public
view view
returns (uint256 tokenId); returns (uint256 tokenId);
function tokenByIndex(uint256 index) public view returns (uint256); function tokenByIndex(uint256 index) public view returns (uint256);
} }
...@@ -9,7 +9,7 @@ import "./IERC721.sol"; ...@@ -9,7 +9,7 @@ import "./IERC721.sol";
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ */
contract IERC721Metadata is Initializable, IERC721 { contract IERC721Metadata is Initializable, IERC721 {
function name() external view returns (string); function name() external view returns (string);
function symbol() external view returns (string); function symbol() external view returns (string);
function tokenURI(uint256 tokenId) public view returns (string); function tokenURI(uint256 tokenId) public view returns (string);
} }
...@@ -7,26 +7,26 @@ pragma solidity ^0.4.24; ...@@ -7,26 +7,26 @@ pragma solidity ^0.4.24;
* from ERC721 asset contracts. * from ERC721 asset contracts.
*/ */
contract IERC721Receiver { contract IERC721Receiver {
/** /**
* @notice Handle the receipt of an NFT * @notice Handle the receipt of an NFT
* @dev The ERC721 smart contract calls this function on the recipient * @dev The ERC721 smart contract calls this function on the recipient
* after a `safeTransfer`. This function MUST return the function selector, * after a `safeTransfer`. This function MUST return the function selector,
* otherwise the caller will revert the transaction. The selector to be * otherwise the caller will revert the transaction. The selector to be
* returned can be obtained as `this.onERC721Received.selector`. This * returned can be obtained as `this.onERC721Received.selector`. This
* function MAY throw to revert and reject the transfer. * function MAY throw to revert and reject the transfer.
* Note: the ERC721 contract address is always the message sender. * Note: the ERC721 contract address is always the message sender.
* @param operator The address which called `safeTransferFrom` function * @param operator The address which called `safeTransferFrom` function
* @param from The address which previously owned the token * @param from The address which previously owned the token
* @param tokenId The NFT identifier which is being transferred * @param tokenId The NFT identifier which is being transferred
* @param data Additional data with no specified format * @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
*/ */
function onERC721Received( function onERC721Received(
address operator, address operator,
address from, address from,
uint256 tokenId, uint256 tokenId,
bytes data bytes data
) )
public public
returns(bytes4); returns(bytes4);
} }
...@@ -13,28 +13,28 @@ import "./ERC721Pausable.sol"; ...@@ -13,28 +13,28 @@ import "./ERC721Pausable.sol";
* *
*/ */
contract StandaloneERC721 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 { function initialize(string name, string symbol, address[] minters, address[] pausers) public initializer {
ERC721.initialize(); ERC721.initialize();
ERC721Enumerable.initialize(); ERC721Enumerable.initialize();
ERC721Metadata.initialize(name, symbol); ERC721Metadata.initialize(name, symbol);
// Initialize the minter and pauser roles, and renounce them // Initialize the minter and pauser roles, and renounce them
ERC721MetadataMintable.initialize(address(this)); ERC721MetadataMintable.initialize(address(this));
renounceMinter(); renounceMinter();
ERC721Pausable.initialize(address(this)); ERC721Pausable.initialize(address(this));
renouncePauser(); renouncePauser();
// Add the requested minters and pausers (this can be done after renouncing since // Add the requested minters and pausers (this can be done after renouncing since
// these are the internal calls) // these are the internal calls)
for (uint256 i = 0; i < minters.length; ++i) { for (uint256 i = 0; i < minters.length; ++i) {
_addMinter(minters[i]); _addMinter(minters[i]);
} }
for (i = 0; i < pausers.length; ++i) { for (i = 0; i < pausers.length; ++i) {
_addPauser(pausers[i]); _addPauser(pausers[i]);
}
} }
}
} }
...@@ -6,23 +6,23 @@ pragma solidity ^0.4.24; ...@@ -6,23 +6,23 @@ pragma solidity ^0.4.24;
*/ */
library Address { library Address {
/** /**
* Returns whether the target address is a contract * Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of 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. * as the code is not actually created until after the constructor finishes.
* @param account address of the account to check * @param account address of the account to check
* @return whether the target address is a contract * @return whether the target address is a contract
*/ */
function isContract(address account) internal view returns (bool) { function isContract(address account) internal view returns (bool) {
uint256 size; uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address // 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. // than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603 // See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works. // for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be // TODO Check this again before the Serenity release, because all addresses will be
// contracts then. // contracts then.
// solium-disable-next-line security/no-inline-assembly // solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(account) } assembly { size := extcodesize(account) }
return size > 0; return size > 0;
} }
} }
...@@ -10,27 +10,27 @@ import "zos-lib/contracts/Initializable.sol"; ...@@ -10,27 +10,27 @@ import "zos-lib/contracts/Initializable.sol";
*/ */
contract ReentrancyGuard is Initializable { contract ReentrancyGuard is Initializable {
/// @dev counter to allow mutex lock with only one SSTORE operation /// @dev counter to allow mutex lock with only one SSTORE operation
uint256 private _guardCounter; uint256 private _guardCounter;
function initialize() public initializer { function initialize() public initializer {
_guardCounter = 1; _guardCounter = 1;
} }
/** /**
* @dev Prevents a contract from calling itself, directly or indirectly. * @dev Prevents a contract from calling itself, directly or indirectly.
* If you mark a function `nonReentrant`, you should also * If you mark a function `nonReentrant`, you should also
* mark it `external`. Calling one `nonReentrant` function from * mark it `external`. Calling one `nonReentrant` function from
* another is not supported. Instead, you can implement a * another is not supported. Instead, you can implement a
* `private` function doing the actual work, and an `external` * `private` function doing the actual work, and an `external`
* wrapper marked as `nonReentrant`. * wrapper marked as `nonReentrant`.
*/ */
modifier nonReentrant() { modifier nonReentrant() {
_guardCounter += 1; _guardCounter += 1;
uint256 localCounter = _guardCounter; uint256 localCounter = _guardCounter;
_; _;
require(localCounter == _guardCounter); require(localCounter == _guardCounter);
} }
uint256[50] private ______gap; uint256[50] private ______gap;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment