Unverified Commit 5471fc80 by Nicolás Venturo Committed by GitHub

Updated code style to 4 space indentation and 120 characters per line. (#1508)

* Updated code style to 4 spaces and 120 max characters per line.

* Update contracts/token/ERC721/ERC721Pausable.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Update contracts/token/ERC721/IERC721.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>
parent 28133840
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
"extends": "solium:all", "extends": "solium:all",
"plugins": ["security"], "plugins": ["security"],
"rules": { "rules": {
"arg-overflow": "off",
"blank-lines": "off", "blank-lines": "off",
"error-reason": "off", "error-reason": "off",
"indentation": ["error", 2], "indentation": ["error", 4],
"lbrace": "off", "lbrace": "off",
"linebreak-style": ["error", "unix"], "linebreak-style": ["error", "unix"],
"max-len": ["error", 79], "max-len": ["error", 120],
"no-constant": ["error"], "no-constant": ["error"],
"no-empty-blocks": "off", "no-empty-blocks": "off",
"quotes": ["error", "double"], "quotes": ["error", "double"],
......
...@@ -5,40 +5,36 @@ pragma solidity ^0.4.24; ...@@ -5,40 +5,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));
require(!has(role, account)); require(!has(role, account));
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));
require(has(role, account)); require(has(role, account));
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 view returns (bool) {
internal require(account != address(0));
view return role.bearer[account];
returns (bool) }
{
require(account != address(0));
return role.bearer[account];
}
} }
...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24; ...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24;
import "../Roles.sol"; import "../Roles.sol";
contract CapperRole { contract CapperRole {
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;
constructor() internal { constructor () internal {
_addCapper(msg.sender); _addCapper(msg.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);
} }
} }
...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24; ...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24;
import "../Roles.sol"; import "../Roles.sol";
contract MinterRole { contract MinterRole {
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;
constructor() internal { constructor () internal {
_addMinter(msg.sender); _addMinter(msg.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);
} }
} }
...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24; ...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24;
import "../Roles.sol"; import "../Roles.sol";
contract PauserRole { contract PauserRole {
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;
constructor() internal { constructor () internal {
_addPauser(msg.sender); _addPauser(msg.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);
} }
} }
...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24; ...@@ -3,41 +3,41 @@ pragma solidity ^0.4.24;
import "../Roles.sol"; import "../Roles.sol";
contract SignerRole { contract SignerRole {
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;
constructor() internal { constructor () internal {
_addSigner(msg.sender); _addSigner(msg.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);
} }
} }
...@@ -9,42 +9,41 @@ import "../validation/TimedCrowdsale.sol"; ...@@ -9,42 +9,41 @@ import "../validation/TimedCrowdsale.sol";
* can do extra work after finishing. * can do extra work after finishing.
*/ */
contract FinalizableCrowdsale is TimedCrowdsale { contract FinalizableCrowdsale is TimedCrowdsale {
using SafeMath for uint256; using SafeMath for uint256;
bool private _finalized; bool private _finalized;
event CrowdsaleFinalized(); event CrowdsaleFinalized();
constructor() internal { constructor () internal {
_finalized = false; _finalized = false;
} }
/** /**
* @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());
_finalized = true; _finalized = true;
_finalization(); _finalization();
emit CrowdsaleFinalized(); emit CrowdsaleFinalized();
} }
/** /**
* @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 {}
}
} }
...@@ -8,43 +8,38 @@ import "../../math/SafeMath.sol"; ...@@ -8,43 +8,38 @@ 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 TimedCrowdsale { contract PostDeliveryCrowdsale is TimedCrowdsale {
using SafeMath for uint256; using SafeMath for uint256;
mapping(address => uint256) private _balances; mapping(address => uint256) private _balances;
constructor() internal {} constructor () internal {}
/** /**
* @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, uint256 tokenAmount) internal {
address beneficiary, _balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
uint256 tokenAmount }
)
internal
{
_balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
}
} }
...@@ -8,84 +8,83 @@ import "../../payment/escrow/RefundEscrow.sol"; ...@@ -8,84 +8,83 @@ import "../../payment/escrow/RefundEscrow.sol";
* @title RefundableCrowdsale * @title RefundableCrowdsale
* @dev Extension of Crowdsale contract that adds a funding goal, and * @dev Extension of Crowdsale contract that adds a funding goal, and
* the possibility of users getting a refund if goal is not met. * the possibility of users getting a refund if goal is not met.
* WARNING: note that if you allow tokens to be traded before the goal * WARNING: note that if you allow tokens to be traded before the goal
* is met, then an attack is possible in which the attacker purchases * is met, then an attack is possible in which the attacker purchases
* tokens from the crowdsale and when they sees that the goal is * tokens from the crowdsale and when they sees that the goal is
* unlikely to be met, they sell their tokens (possibly at a discount). * unlikely to be met, they sell their tokens (possibly at a discount).
* The attacker will be refunded when the crowdsale is finalized, and * The attacker will be refunded when the crowdsale is finalized, and
* the users that purchased from them will be left with worthless * the users that purchased from them will be left with worthless
* tokens. There are many possible ways to avoid this, like making the * tokens. There are many possible ways to avoid this, like making the
* the crowdsale inherit from PostDeliveryCrowdsale, or imposing * the crowdsale inherit from PostDeliveryCrowdsale, or imposing
* restrictions on token trading until the crowdsale is finalized. * restrictions on token trading until the crowdsale is finalized.
* This is being discussed in * This is being discussed in
* https://github.com/OpenZeppelin/openzeppelin-solidity/issues/877 * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/877
* This contract will be updated when we agree on a general solution * This contract will be updated when we agree on a general solution
* for this problem. * for this problem.
*/ */
contract RefundableCrowdsale is FinalizableCrowdsale { contract RefundableCrowdsale is 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
*/ */
constructor(uint256 goal) internal { constructor (uint256 goal) internal {
require(goal > 0); require(goal > 0);
_escrow = new RefundEscrow(wallet()); _escrow = new RefundEscrow(wallet());
_goal = goal; _goal = goal;
} }
/**
* @return minimum amount of funds to be raised in wei.
*/
function goal() public view returns(uint256) {
return _goal;
}
/** /**
* @dev Investors can claim refunds here if crowdsale is unsuccessful * @return minimum amount of funds to be raised in wei.
* @param refundee Whose refund will be claimed. */
*/ function goal() public view returns (uint256) {
function claimRefund(address refundee) public { return _goal;
require(finalized()); }
require(!goalReached());
_escrow.withdraw(refundee); /**
} * @dev Investors can claim refunds here if crowdsale is unsuccessful
* @param refundee Whose refund will be claimed.
*/
function claimRefund(address refundee) public {
require(finalized());
require(!goalReached());
/** _escrow.withdraw(refundee);
* @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 * @dev Checks whether funding goal was reached.
*/ * @return Whether funding goal was reached
function _finalization() internal { */
if (goalReached()) { function goalReached() public view returns (bool) {
_escrow.close(); return weiRaised() >= _goal;
_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. }
*/
function _forwardFunds() internal {
_escrow.deposit.value(msg.value)(msg.sender);
}
/**
* @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
*/
function _forwardFunds() internal {
_escrow.deposit.value(msg.value)(msg.sender);
}
} }
...@@ -11,49 +11,41 @@ import "../../math/Math.sol"; ...@@ -11,49 +11,41 @@ import "../../math/Math.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 Crowdsale { contract AllowanceCrowdsale is 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
*/ */
constructor(address tokenWallet) internal { constructor (address tokenWallet) internal {
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 Math.min( return Math.min(token().balanceOf(_tokenWallet), token().allowance(_tokenWallet, this));
token().balanceOf(_tokenWallet), }
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, uint256 tokenAmount) internal {
address beneficiary, token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount);
uint256 tokenAmount }
)
internal
{
token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount);
}
} }
...@@ -9,21 +9,15 @@ import "../../token/ERC20/ERC20Mintable.sol"; ...@@ -9,21 +9,15 @@ import "../../token/ERC20/ERC20Mintable.sol";
* Token ownership should be transferred to MintedCrowdsale for minting. * Token ownership should be transferred to MintedCrowdsale for minting.
*/ */
contract MintedCrowdsale is Crowdsale { contract MintedCrowdsale is Crowdsale {
constructor() internal {} constructor () internal {}
/** /**
* @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, uint256 tokenAmount) internal {
address beneficiary, // Potentially dangerous assumption about the type of the token.
uint256 tokenAmount require(ERC20Mintable(address(token())).mint(beneficiary, tokenAmount));
) }
internal
{
// Potentially dangerous assumption about the type of the token.
require(
ERC20Mintable(address(token())).mint(beneficiary, tokenAmount));
}
} }
...@@ -10,72 +10,69 @@ import "../../math/SafeMath.sol"; ...@@ -10,72 +10,69 @@ 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 TimedCrowdsale { contract IncreasingPriceCrowdsale is 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
*/ */
constructor(uint256 initialRate, uint256 finalRate) internal { constructor (uint256 initialRate, uint256 finalRate) internal {
require(finalRate > 0); require(finalRate > 0);
require(initialRate > finalRate); require(initialRate > finalRate);
_initialRate = initialRate; _initialRate = initialRate;
_finalRate = finalRate; _finalRate = finalRate;
} }
/**
* The base rate function is overridden to revert, since this crowdsale doens't use it, and
* all calls to it are a mistake.
*/
function rate() public view returns(uint256) {
revert();
}
/** /**
* @return the initial rate of the crowdsale. * The base rate function is overridden to revert, since this crowdsale doens't use it, and
*/ * all calls to it are a mistake.
function initialRate() public view returns(uint256) { */
return _initialRate; function rate() public view returns (uint256) {
} revert();
}
/** /**
* @return the final rate of the crowdsale. * @return the initial rate of the crowdsale.
*/ */
function finalRate() public view returns (uint256) { function initialRate() public view returns (uint256) {
return _finalRate; return _initialRate;
} }
/** /**
* @dev Returns the rate of tokens per wei at the present time. * @return the final rate of the crowdsale.
* Note that, as price _increases_ with time, the rate _decreases_. */
* @return The number of tokens a buyer gets per wei at a given time function finalRate() public view returns (uint256) {
*/ return _finalRate;
function getCurrentRate() public view returns (uint256) {
if (!isOpen()) {
return 0;
} }
// solium-disable-next-line security/no-block-members /**
uint256 elapsedTime = block.timestamp.sub(openingTime()); * @dev Returns the rate of tokens per wei at the present time.
uint256 timeRange = closingTime().sub(openingTime()); * Note that, as price _increases_ with time, the rate _decreases_.
uint256 rateRange = _initialRate.sub(_finalRate); * @return The number of tokens a buyer gets per wei at a given time
return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); */
} function getCurrentRate() public view returns (uint256) {
if (!isOpen()) {
return 0;
}
/** // solium-disable-next-line security/no-block-members
* @dev Overrides parent method taking into account variable rate. uint256 elapsedTime = block.timestamp.sub(openingTime());
* @param weiAmount The value in wei to be converted into tokens uint256 timeRange = closingTime().sub(openingTime());
* @return The number of tokens _weiAmount wei will buy at present time uint256 rateRange = _initialRate.sub(_finalRate);
*/ return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
function _getTokenAmount(uint256 weiAmount) }
internal view returns (uint256)
{
uint256 currentRate = getCurrentRate();
return currentRate.mul(weiAmount);
}
/**
* @dev Overrides parent method taking into account variable rate.
* @param weiAmount The value in wei to be converted into tokens
* @return The number of tokens _weiAmount wei will buy at present time
*/
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) {
uint256 currentRate = getCurrentRate();
return currentRate.mul(weiAmount);
}
} }
...@@ -8,48 +8,41 @@ import "../Crowdsale.sol"; ...@@ -8,48 +8,41 @@ import "../Crowdsale.sol";
* @dev Crowdsale with a limit for total contributions. * @dev Crowdsale with a limit for total contributions.
*/ */
contract CappedCrowdsale is Crowdsale { contract CappedCrowdsale is 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
*/ */
constructor(uint256 cap) internal { constructor (uint256 cap) internal {
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, uint256 weiAmount) internal view {
address beneficiary, super._preValidatePurchase(beneficiary, weiAmount);
uint256 weiAmount require(weiRaised().add(weiAmount) <= _cap);
) }
internal
view
{
super._preValidatePurchase(beneficiary, weiAmount);
require(weiRaised().add(weiAmount) <= _cap);
}
} }
...@@ -9,73 +9,57 @@ import "../../access/roles/CapperRole.sol"; ...@@ -9,73 +9,57 @@ import "../../access/roles/CapperRole.sol";
* @dev Crowdsale with per-beneficiary caps. * @dev Crowdsale with per-beneficiary caps.
*/ */
contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole { contract IndividuallyCappedCrowdsale is 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;
constructor() internal {} constructor () internal {}
/** /**
* @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, uint256 weiAmount) internal view {
address beneficiary, super._preValidatePurchase(beneficiary, weiAmount);
uint256 weiAmount require(_contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]);
) }
internal
view
{
super._preValidatePurchase(beneficiary, weiAmount);
require(
_contributions[beneficiary].add(weiAmount) <= _caps[beneficiary]);
}
/**
* @dev Extend parent behavior to update beneficiary contributions
* @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed
*/
function _updatePurchasingState(
address beneficiary,
uint256 weiAmount
)
internal
{
super._updatePurchasingState(beneficiary, weiAmount);
_contributions[beneficiary] = _contributions[beneficiary].add(
weiAmount);
}
/**
* @dev Extend parent behavior to update beneficiary contributions
* @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed
*/
function _updatePurchasingState(address beneficiary, uint256 weiAmount) internal {
super._updatePurchasingState(beneficiary, weiAmount);
_contributions[beneficiary] = _contributions[beneficiary].add(weiAmount);
}
} }
...@@ -8,78 +8,70 @@ import "../Crowdsale.sol"; ...@@ -8,78 +8,70 @@ import "../Crowdsale.sol";
* @dev Crowdsale accepting contributions only within a time frame. * @dev Crowdsale accepting contributions only within a time frame.
*/ */
contract TimedCrowdsale is Crowdsale { contract TimedCrowdsale is 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
*/ */
constructor(uint256 openingTime, uint256 closingTime) internal { constructor (uint256 openingTime, uint256 closingTime) internal {
// 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;
} }
/**
* @dev Extend parent behavior requiring to be within contributing period
* @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed
*/
function _preValidatePurchase(
address beneficiary,
uint256 weiAmount
)
internal
onlyWhileOpen
view
{
super._preValidatePurchase(beneficiary, weiAmount);
}
/**
* @dev Extend parent behavior requiring to be within contributing period
* @param beneficiary Token purchaser
* @param weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal onlyWhileOpen view {
super._preValidatePurchase(beneficiary, weiAmount);
}
} }
...@@ -8,64 +8,53 @@ pragma solidity ^0.4.24; ...@@ -8,64 +8,53 @@ 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) internal pure returns (address) {
function recover(bytes32 hash, bytes signature) bytes32 r;
internal bytes32 s;
pure uint8 v;
returns (address)
{ // Check the signature length
bytes32 r; if (signature.length != 65) {
bytes32 s; return (address(0));
uint8 v; }
// Check the signature length // Divide the signature in r, s and v variables
if (signature.length != 65) { // ecrecover takes the signature parameters, and the only way to get them
return (address(0)); // currently is to use assembly.
} // solium-disable-next-line security/no-inline-assembly
assembly {
// Divide the signature in r, s and v variables r := mload(add(signature, 0x20))
// ecrecover takes the signature parameters, and the only way to get them s := mload(add(signature, 0x40))
// currently is to use assembly. v := byte(0, mload(add(signature, 0x60)))
// solium-disable-next-line security/no-inline-assembly }
assembly {
r := mload(add(signature, 0x20)) // Version of signature should be 27 or 28, but 0 and 1 are also possible versions
s := mload(add(signature, 0x40)) if (v < 27) {
v := byte(0, mload(add(signature, 0x60))) v += 27;
}
// If the version is correct return the signer address
if (v != 27 && v != 28) {
return (address(0));
} else {
// solium-disable-next-line arg-overflow
return ecrecover(hash, v, r, s);
}
} }
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions /**
if (v < 27) { * toEthSignedMessageHash
v += 27; * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
* and hash the result
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
} }
// If the version is correct return the signer address
if (v != 27 && v != 28) {
return (address(0));
} else {
// solium-disable-next-line arg-overflow
return ecrecover(hash, v, r, s);
}
}
/**
* toEthSignedMessageHash
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
* and hash the result
*/
function toEthSignedMessageHash(bytes32 hash)
internal
pure
returns (bytes32)
{
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
);
}
} }
...@@ -6,37 +6,29 @@ pragma solidity ^0.4.24; ...@@ -6,37 +6,29 @@ 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 root, bytes32 leaf) internal pure returns (bool) {
bytes32[] proof, bytes32 computedHash = leaf;
bytes32 root,
bytes32 leaf
)
internal
pure
returns (bool)
{
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;
} }
} }
...@@ -13,16 +13,12 @@ pragma solidity ^0.4.24; ...@@ -13,16 +13,12 @@ pragma solidity ^0.4.24;
* so it's not something you have to worry about.) * so it's not something you have to worry about.)
*/ */
library Counter { library Counter {
struct Counter {
uint256 current; // default: 0
}
struct Counter { function next(Counter storage index) internal returns (uint256) {
uint256 current; // default: 0 index.current += 1;
} return index.current;
}
function next(Counter storage index)
internal
returns (uint256)
{
index.current += 1;
return index.current;
}
} }
...@@ -9,19 +9,17 @@ import "../../token/ERC20/IERC20.sol"; ...@@ -9,19 +9,17 @@ 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 IERC20 { contract ERC20TokenMetadata is IERC20 {
function tokenURI() external view returns (string); function tokenURI() external view returns (string);
} }
contract ERC20WithMetadata is ERC20TokenMetadata { contract ERC20WithMetadata is ERC20TokenMetadata {
string private _tokenURI; string private _tokenURI;
constructor(string tokenURI) constructor (string tokenURI) public {
public _tokenURI = tokenURI;
{ }
_tokenURI = tokenURI;
}
function tokenURI() external view returns (string) { function tokenURI() external view returns (string) {
return _tokenURI; return _tokenURI;
} }
} }
...@@ -32,69 +32,69 @@ import "../math/Math.sol"; ...@@ -32,69 +32,69 @@ import "../math/Math.sol";
* ``` * ```
*/ */
contract ERC20Migrator { contract ERC20Migrator {
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
*/ */
constructor(IERC20 legacyToken) public { constructor (IERC20 legacyToken) public {
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);
} }
} }
...@@ -35,112 +35,84 @@ import "../cryptography/ECDSA.sol"; ...@@ -35,112 +35,84 @@ import "../cryptography/ECDSA.sol";
* See https://ethereum.stackexchange.com/a/50616 for more details. * See https://ethereum.stackexchange.com/a/50616 for more details.
*/ */
contract SignatureBouncer is SignerRole { contract SignatureBouncer is 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;
constructor() internal {} constructor () internal {}
/** /**
* @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)); _;
_; }
}
/** /**
* @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 view returns (bool) {
internal return _isValidDataHash(keccak256(abi.encodePacked(address(this), account)), signature);
view }
returns (bool)
{
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account)),
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 view returns (bool) {
internal bytes memory data = new bytes(_METHOD_ID_SIZE);
view for (uint i = 0; i < data.length; i++) {
returns (bool) data[i] = msg.data[i];
{ }
bytes memory data = new bytes(_METHOD_ID_SIZE); return _isValidDataHash(keccak256(abi.encodePacked(address(this), account, data)), signature);
for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i];
} }
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), account, data)),
signature
);
}
/** /**
* @dev is the signature of `this + sender + methodId + params(s)` from a signer? * @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 view returns (bool) {
internal require(msg.data.length > _SIGNATURE_SIZE);
view
returns (bool) bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE);
{ for (uint i = 0; i < data.length; i++) {
require(msg.data.length > _SIGNATURE_SIZE); data[i] = msg.data[i];
bytes memory data = new bytes(msg.data.length - _SIGNATURE_SIZE); }
for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i]; return _isValidDataHash(keccak256(abi.encodePacked(address(this), account, data)), signature);
} }
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 view returns (bool) {
internal address signer = hash.toEthSignedMessageHash().recover(signature);
view
returns (bool)
{
address signer = hash
.toEthSignedMessageHash()
.recover(signature);
return signer != address(0) && isSigner(signer); return signer != address(0) && isSigner(signer);
} }
} }
...@@ -13,163 +13,155 @@ import "../math/SafeMath.sol"; ...@@ -13,163 +13,155 @@ import "../math/SafeMath.sol";
* owner. * owner.
*/ */
contract TokenVesting is Ownable { contract TokenVesting is Ownable {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
event TokensReleased(address token, uint256 amount); event TokensReleased(address token, uint256 amount);
event TokenVestingRevoked(address token); event TokenVestingRevoked(address token);
// 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
*/ */
constructor( constructor (address beneficiary, uint256 start, uint256 cliffDuration, uint256 duration, bool revocable) public {
address beneficiary, require(beneficiary != address(0));
uint256 start, require(cliffDuration <= duration);
uint256 cliffDuration, require(duration > 0);
uint256 duration, require(start.add(duration) > block.timestamp);
bool revocable
) _beneficiary = beneficiary;
public _revocable = revocable;
{ _duration = duration;
require(beneficiary != address(0)); _cliff = start.add(cliffDuration);
require(cliffDuration <= duration); _start = start;
require(duration > 0); }
require(start.add(duration) > block.timestamp);
/**
_beneficiary = beneficiary; * @return the beneficiary of the tokens.
_revocable = revocable; */
_duration = duration; function beneficiary() public view returns (address) {
_cliff = start.add(cliffDuration); return _beneficiary;
_start = start; }
}
/**
/** * @return the cliff time of the token vesting.
* @return the beneficiary of the tokens. */
*/ function cliff() public view returns (uint256) {
function beneficiary() public view returns(address) { return _cliff;
return _beneficiary; }
}
/**
/** * @return the start time of the token vesting.
* @return the cliff time of the token vesting. */
*/ function start() public view returns (uint256) {
function cliff() public view returns(uint256) { return _start;
return _cliff; }
}
/**
/** * @return the duration of the token vesting.
* @return the start time of the token vesting. */
*/ function duration() public view returns (uint256) {
function start() public view returns(uint256) { return _duration;
return _start; }
}
/**
/** * @return true if the vesting is revocable.
* @return the duration of the token vesting. */
*/ function revocable() public view returns (bool) {
function duration() public view returns(uint256) { return _revocable;
return _duration; }
}
/**
/** * @return the amount of the token released.
* @return true if the vesting is revocable. */
*/ function released(address token) public view returns (uint256) {
function revocable() public view returns(bool) { return _released[token];
return _revocable; }
}
/**
/** * @return true if the token is revoked.
* @return the amount of the token released. */
*/ function revoked(address token) public view returns (bool) {
function released(address token) public view returns(uint256) { return _revoked[token];
return _released[token]; }
}
/**
/** * @notice Transfers vested tokens to beneficiary.
* @return true if the token is revoked. * @param token ERC20 token which is being vested
*/ */
function revoked(address token) public view returns(bool) { function release(IERC20 token) public {
return _revoked[token]; uint256 unreleased = _releasableAmount(token);
}
require(unreleased > 0);
/**
* @notice Transfers vested tokens to beneficiary. _released[token] = _released[token].add(unreleased);
* @param token ERC20 token which is being vested
*/ token.safeTransfer(_beneficiary, unreleased);
function release(IERC20 token) public {
uint256 unreleased = _releasableAmount(token); emit TokensReleased(token, unreleased);
}
require(unreleased > 0);
/**
_released[token] = _released[token].add(unreleased); * @notice Allows the owner to revoke the vesting. Tokens already vested
* remain in the contract, the rest are returned to the owner.
token.safeTransfer(_beneficiary, unreleased); * @param token ERC20 token which is being vested
*/
emit TokensReleased(token, unreleased); function revoke(IERC20 token) public onlyOwner {
} require(_revocable);
require(!_revoked[token]);
/**
* @notice Allows the owner to revoke the vesting. Tokens already vested uint256 balance = token.balanceOf(address(this));
* remain in the contract, the rest are returned to the owner.
* @param token ERC20 token which is being vested uint256 unreleased = _releasableAmount(token);
*/ uint256 refund = balance.sub(unreleased);
function revoke(IERC20 token) public onlyOwner {
require(_revocable); _revoked[token] = true;
require(!_revoked[token]);
token.safeTransfer(owner(), refund);
uint256 balance = token.balanceOf(address(this));
emit TokenVestingRevoked(token);
uint256 unreleased = _releasableAmount(token); }
uint256 refund = balance.sub(unreleased);
/**
_revoked[token] = true; * @dev Calculates the amount that has already vested but hasn't been released yet.
* @param token ERC20 token which is being vested
token.safeTransfer(owner(), refund); */
function _releasableAmount(IERC20 token) private view returns (uint256) {
emit TokenVestingRevoked(token); return _vestedAmount(token).sub(_released[token]);
} }
/** /**
* @dev Calculates the amount that has already vested but hasn't been released yet. * @dev Calculates the amount that has already vested.
* @param token ERC20 token which is being vested * @param token ERC20 token which is being vested
*/ */
function _releasableAmount(IERC20 token) private view returns (uint256) { function _vestedAmount(IERC20 token) private view returns (uint256) {
return _vestedAmount(token).sub(_released[token]); uint256 currentBalance = token.balanceOf(address(this));
} uint256 totalBalance = currentBalance.add(_released[token]);
/** if (block.timestamp < _cliff) {
* @dev Calculates the amount that has already vested. return 0;
* @param token ERC20 token which is being vested } else if (block.timestamp >= _start.add(_duration) || _revoked[token]) {
*/ return totalBalance;
function _vestedAmount(IERC20 token) private view returns (uint256) { } else {
uint256 currentBalance = token.balanceOf(address(this)); return totalBalance.mul(block.timestamp.sub(_start)).div(_duration);
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);
} }
}
} }
...@@ -12,7 +12,7 @@ import "../token/ERC20/ERC20Detailed.sol"; ...@@ -12,7 +12,7 @@ import "../token/ERC20/ERC20Detailed.sol";
* It is meant to be used in a crowdsale contract. * It is meant to be used in a crowdsale contract.
*/ */
contract SampleCrowdsaleToken is ERC20Mintable, ERC20Detailed { contract SampleCrowdsaleToken is ERC20Mintable, ERC20Detailed {
constructor() public ERC20Detailed("Sample Crowdsale Token", "SCT", 18) {} constructor () public ERC20Detailed("Sample Crowdsale Token", "SCT", 18) {}
} }
/** /**
...@@ -34,24 +34,23 @@ contract SampleCrowdsaleToken is ERC20Mintable, ERC20Detailed { ...@@ -34,24 +34,23 @@ contract SampleCrowdsaleToken is ERC20Mintable, ERC20Detailed {
// --elopio - 2018-05-10 // --elopio - 2018-05-10
// solium-disable-next-line max-len // solium-disable-next-line max-len
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale { contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
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 Crowdsale(rate, wallet, token)
Crowdsale(rate, wallet, token) CappedCrowdsale(cap)
CappedCrowdsale(cap) TimedCrowdsale(openingTime, closingTime)
TimedCrowdsale(openingTime, closingTime) RefundableCrowdsale(goal)
RefundableCrowdsale(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); }
}
} }
...@@ -10,14 +10,12 @@ import "../token/ERC20/ERC20Detailed.sol"; ...@@ -10,14 +10,12 @@ import "../token/ERC20/ERC20Detailed.sol";
* `ERC20` functions. * `ERC20` functions.
*/ */
contract SimpleToken is ERC20, ERC20Detailed { contract SimpleToken is ERC20, ERC20Detailed {
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals()));
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals())); /**
* @dev Constructor that gives msg.sender all of existing tokens.
/** */
* @dev Constructor that gives msg.sender all of existing tokens. constructor () public ERC20Detailed("SimpleToken", "SIM", 18) {
*/ _mint(msg.sender, INITIAL_SUPPLY);
constructor() public ERC20Detailed("SimpleToken", "SIM", 18) { }
_mint(msg.sender, INITIAL_SUPPLY);
}
} }
...@@ -8,46 +8,37 @@ import "./IERC165.sol"; ...@@ -8,46 +8,37 @@ import "./IERC165.sol";
* @dev Implements ERC165 using a lookup table. * @dev Implements ERC165 using a lookup table.
*/ */
contract ERC165 is IERC165 { contract ERC165 is IERC165 {
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; /**
/** * @dev a mapping of interface id to whether or not it's supported
* 0x01ffc9a7 === */
* bytes4(keccak256('supportsInterface(bytes4)')) mapping(bytes4 => bool) private _supportedInterfaces;
*/
/** /**
* @dev a mapping of interface id to whether or not it's supported * @dev A contract implementing SupportsInterfaceWithLookup
*/ * implement ERC165 itself
mapping(bytes4 => bool) private _supportedInterfaces; */
constructor () internal {
_registerInterface(_InterfaceId_ERC165);
}
/** /**
* @dev A contract implementing SupportsInterfaceWithLookup * @dev implement supportsInterface(bytes4) using a lookup table
* implement ERC165 itself */
*/ function supportsInterface(bytes4 interfaceId) external view returns (bool) {
constructor() return _supportedInterfaces[interfaceId];
internal }
{
_registerInterface(_InterfaceId_ERC165);
}
/** /**
* @dev implement supportsInterface(bytes4) using a lookup table * @dev internal method for registering an interface
*/ */
function supportsInterface(bytes4 interfaceId) function _registerInterface(bytes4 interfaceId) internal {
external require(interfaceId != 0xffffffff);
view _supportedInterfaces[interfaceId] = true;
returns (bool) }
{
return _supportedInterfaces[interfaceId];
}
/**
* @dev internal method for registering an interface
*/
function _registerInterface(bytes4 interfaceId)
internal
{
require(interfaceId != 0xffffffff);
_supportedInterfaces[interfaceId] = true;
}
} }
...@@ -5,15 +5,11 @@ pragma solidity ^0.4.24; ...@@ -5,15 +5,11 @@ pragma solidity ^0.4.24;
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
*/ */
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) external view returns (bool);
function supportsInterface(bytes4 interfaceId)
external
view
returns (bool);
} }
...@@ -7,51 +7,51 @@ import "../access/roles/PauserRole.sol"; ...@@ -7,51 +7,51 @@ 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 PauserRole { contract Pausable is PauserRole {
event Paused(address account); event Paused(address account);
event Unpaused(address account); event Unpaused(address account);
bool private _paused; bool private _paused;
constructor() internal { constructor () internal {
_paused = false; _paused = false;
} }
/** /**
* @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(msg.sender); emit Paused(msg.sender);
} }
/** /**
* @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(msg.sender); emit Unpaused(msg.sender);
} }
} }
...@@ -5,27 +5,27 @@ pragma solidity ^0.4.24; ...@@ -5,27 +5,27 @@ pragma solidity ^0.4.24;
* @dev Assorted math operations * @dev Assorted math operations
*/ */
library Math { library Math {
/** /**
* @dev Returns the largest of two numbers. * @dev Returns the largest of two numbers.
*/ */
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;
} }
/** /**
* @dev Returns the smallest of two numbers. * @dev Returns the smallest of two numbers.
*/ */
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;
} }
/** /**
* @dev Calculates the average of two numbers. Since these are integers, * @dev Calculates the average of two numbers. Since these are integers,
* averages of an even and odd number cannot be represented, and will be * averages of an even and odd number cannot be represented, and will be
* rounded down. * rounded down.
*/ */
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);
} }
} }
...@@ -5,61 +5,61 @@ pragma solidity ^0.4.24; ...@@ -5,61 +5,61 @@ pragma solidity ^0.4.24;
* @dev Math operations with safety checks that revert on error * @dev Math operations with safety checks that revert on error
*/ */
library SafeMath { library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
/** uint256 c = a * b;
* @dev Multiplies two numbers, reverts on overflow. require(c / a == b);
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c; 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 // Solidity only automatically asserts when dividing by 0
uint256 c = a / b; require(b > 0);
// assert(a == b * c + a % b); // There is no case in which this doesn't hold uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c; return c;
} }
/** /**
* @dev 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;
} }
} }
...@@ -3,12 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,12 +3,7 @@ pragma solidity ^0.4.24;
import "../utils/Address.sol"; import "../utils/Address.sol";
contract AddressImpl { contract AddressImpl {
function isContract(address account) function isContract(address account) external view returns (bool) {
external return Address.isContract(account);
view }
returns (bool)
{
return Address.isContract(account);
}
} }
...@@ -4,17 +4,9 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,17 +4,9 @@ import "../token/ERC20/IERC20.sol";
import "../crowdsale/emission/AllowanceCrowdsale.sol"; import "../crowdsale/emission/AllowanceCrowdsale.sol";
contract AllowanceCrowdsaleImpl is AllowanceCrowdsale { contract AllowanceCrowdsaleImpl is AllowanceCrowdsale {
constructor (uint256 rate, address wallet, IERC20 token, address tokenWallet)
constructor ( public
uint256 rate, Crowdsale(rate, wallet, token)
address wallet, AllowanceCrowdsale(tokenWallet)
IERC20 token, {}
address tokenWallet
)
public
Crowdsale(rate, wallet, token)
AllowanceCrowdsale(tokenWallet)
{
}
} }
...@@ -3,16 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,16 +3,15 @@ pragma solidity ^0.4.24;
import "../utils/Arrays.sol"; import "../utils/Arrays.sol";
contract ArraysImpl { contract ArraysImpl {
using Arrays for uint256[];
using Arrays for uint256[]; uint256[] private array;
uint256[] private array; constructor (uint256[] _array) public {
array = _array;
}
constructor(uint256[] _array) public { function findUpperBound(uint256 _element) external view returns (uint256) {
array = _array; return array.findUpperBound(_element);
} }
function findUpperBound(uint256 _element) external view returns (uint256) {
return array.findUpperBound(_element);
}
} }
...@@ -4,17 +4,9 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,17 +4,9 @@ import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/CappedCrowdsale.sol"; import "../crowdsale/validation/CappedCrowdsale.sol";
contract CappedCrowdsaleImpl is CappedCrowdsale { contract CappedCrowdsaleImpl is CappedCrowdsale {
constructor (uint256 rate, address wallet, IERC20 token, uint256 cap)
constructor ( public
uint256 rate, Crowdsale(rate, wallet, token)
address wallet, CappedCrowdsale(cap)
IERC20 token, {}
uint256 cap
)
public
Crowdsale(rate, wallet, token)
CappedCrowdsale(cap)
{
}
} }
...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24;
import "../access/roles/CapperRole.sol"; import "../access/roles/CapperRole.sol";
contract CapperRoleMock is CapperRole { contract CapperRoleMock is CapperRole {
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);
} }
} }
...@@ -4,13 +4,13 @@ import "../payment/escrow/ConditionalEscrow.sol"; ...@@ -4,13 +4,13 @@ import "../payment/escrow/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;
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];
} }
} }
...@@ -3,18 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,18 +3,15 @@ pragma solidity ^0.4.24;
import "../drafts/Counter.sol"; 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 returns (uint256) {
public theId = _counters[key].next();
returns (uint256) return theId;
{ }
theId = _counters[key].next();
return theId;
}
} }
...@@ -3,7 +3,5 @@ pragma solidity ^0.4.24; ...@@ -3,7 +3,5 @@ pragma solidity ^0.4.24;
import "../crowdsale/Crowdsale.sol"; 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(rate, wallet, token) {}
Crowdsale(rate, wallet, token) {
}
} }
...@@ -4,12 +4,5 @@ import "../token/ERC20/ERC20.sol"; ...@@ -4,12 +4,5 @@ import "../token/ERC20/ERC20.sol";
import "../token/ERC20/ERC20Detailed.sol"; import "../token/ERC20/ERC20Detailed.sol";
contract ERC20DetailedMock is ERC20, ERC20Detailed { contract ERC20DetailedMock is ERC20, ERC20Detailed {
constructor( constructor (string name, string symbol, uint8 decimals) ERC20Detailed(name, symbol, decimals) public {}
string name,
string symbol,
uint8 decimals
)
ERC20Detailed(name, symbol, decimals)
public
{}
} }
...@@ -3,21 +3,13 @@ pragma solidity ^0.4.24; ...@@ -3,21 +3,13 @@ pragma solidity ^0.4.24;
import "../cryptography/ECDSA.sol"; 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 pure returns (address) {
public return hash.recover(signature);
pure }
returns (address)
{
return hash.recover(signature);
}
function toEthSignedMessageHash(bytes32 hash) function toEthSignedMessageHash(bytes32 hash) public pure returns (bytes32) {
public return hash.toEthSignedMessageHash();
pure }
returns (bytes32)
{
return hash.toEthSignedMessageHash();
}
} }
...@@ -11,56 +11,45 @@ import "../../introspection/IERC165.sol"; ...@@ -11,56 +11,45 @@ import "../../introspection/IERC165.sol";
* solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
*/ */
contract SupportsInterfaceWithLookupMock is IERC165 { contract SupportsInterfaceWithLookupMock is IERC165 {
bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
/**
* @dev a mapping of interface id to whether or not it's supported
*/
mapping(bytes4 => bool) private _supportedInterfaces;
/**
* @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself
*/
constructor () public {
_registerInterface(InterfaceId_ERC165);
}
bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; /**
/** * @dev implement supportsInterface(bytes4) using a lookup table
* 0x01ffc9a7 === */
* bytes4(keccak256('supportsInterface(bytes4)')) function supportsInterface(bytes4 interfaceId) external view returns (bool) {
*/ return _supportedInterfaces[interfaceId];
}
/**
* @dev a mapping of interface id to whether or not it's supported
*/
mapping(bytes4 => bool) private _supportedInterfaces;
/**
* @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself
*/
constructor()
public
{
_registerInterface(InterfaceId_ERC165);
}
/**
* @dev implement supportsInterface(bytes4) using a lookup table
*/
function supportsInterface(bytes4 interfaceId)
external
view
returns (bool)
{
return _supportedInterfaces[interfaceId];
}
/** /**
* @dev 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);
{ _supportedInterfaces[interfaceId] = true;
require(interfaceId != 0xffffffff); }
_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++) {
{ _registerInterface(interfaceIds[i]);
for (uint256 i = 0; i < interfaceIds.length; i++) { }
_registerInterface(interfaceIds[i]);
} }
}
} }
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
contract ERC165NotSupported { contract ERC165NotSupported {}
}
...@@ -3,29 +3,17 @@ pragma solidity ^0.4.24; ...@@ -3,29 +3,17 @@ pragma solidity ^0.4.24;
import "../introspection/ERC165Checker.sol"; 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 view returns (bool) {
public return account._supportsERC165();
view }
returns (bool)
{
return account._supportsERC165();
}
function supportsInterface(address account, bytes4 interfaceId) function supportsInterface(address account, bytes4 interfaceId) public view returns (bool) {
public return account._supportsInterface(interfaceId);
view }
returns (bool)
{
return account._supportsInterface(interfaceId);
}
function supportsAllInterfaces(address account, bytes4[] interfaceIds) function supportsAllInterfaces(address account, bytes4[] interfaceIds) public view returns (bool) {
public return account._supportsAllInterfaces(interfaceIds);
view }
returns (bool)
{
return account._supportsAllInterfaces(interfaceIds);
}
} }
...@@ -3,9 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,9 +3,7 @@ pragma solidity ^0.4.24;
import "../introspection/ERC165.sol"; import "../introspection/ERC165.sol";
contract ERC165Mock is ERC165 { contract ERC165Mock is ERC165 {
function registerInterface(bytes4 interfaceId) function registerInterface(bytes4 interfaceId) public {
public _registerInterface(interfaceId);
{ }
_registerInterface(interfaceId);
}
} }
...@@ -3,9 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,9 +3,7 @@ pragma solidity ^0.4.24;
import "../token/ERC20/ERC20Burnable.sol"; 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); }
}
} }
...@@ -4,21 +4,19 @@ import "../token/ERC20/ERC20.sol"; ...@@ -4,21 +4,19 @@ 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 {
_mint(initialAccount, initialBalance);
}
constructor(address initialAccount, uint256 initialBalance) public { function mint(address account, uint256 amount) public {
_mint(initialAccount, initialBalance); _mint(account, amount);
} }
function mint(address account, uint256 amount) public { function burn(address account, uint256 amount) public {
_mint(account, amount); _burn(account, amount);
} }
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
} }
...@@ -5,9 +5,7 @@ import "./PauserRoleMock.sol"; ...@@ -5,9 +5,7 @@ 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 { _mint(initialAccount, initialBalance);
_mint(initialAccount, initialBalance); }
}
} }
...@@ -4,8 +4,5 @@ import "../token/ERC20/ERC20.sol"; ...@@ -4,8 +4,5 @@ import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/TokenMetadata.sol"; import "../drafts/ERC1046/TokenMetadata.sol";
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata { contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata {
constructor(string tokenURI) public constructor (string tokenURI) public ERC20WithMetadata(tokenURI) {}
ERC20WithMetadata(tokenURI)
{
}
} }
...@@ -10,23 +10,18 @@ import "../token/ERC721/ERC721Burnable.sol"; ...@@ -10,23 +10,18 @@ import "../token/ERC721/ERC721Burnable.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,
* and a public setter for metadata URI * and a public setter for metadata URI
*/ */
contract ERC721FullMock contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { constructor (string name, string symbol) public ERC721Mintable() ERC721Full(name, symbol) {}
constructor(string name, string symbol) public function exists(uint256 tokenId) public view returns (bool) {
ERC721Mintable() return _exists(tokenId);
ERC721Full(name, symbol) }
{}
function exists(uint256 tokenId) public view returns (bool) { function setTokenURI(uint256 tokenId, string uri) public {
return _exists(tokenId); _setTokenURI(tokenId, uri);
} }
function setTokenURI(uint256 tokenId, string uri) public { function removeTokenFrom(address from, uint256 tokenId) public {
_setTokenURI(tokenId, uri); _removeTokenFrom(from, tokenId);
} }
function removeTokenFrom(address from, uint256 tokenId) public {
_removeTokenFrom(from, tokenId);
}
} }
...@@ -8,13 +8,6 @@ import "../token/ERC721/ERC721Burnable.sol"; ...@@ -8,13 +8,6 @@ import "../token/ERC721/ERC721Burnable.sol";
/** /**
* @title ERC721MintableBurnableImpl * @title ERC721MintableBurnableImpl
*/ */
contract ERC721MintableBurnableImpl contract ERC721MintableBurnableImpl is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { constructor () ERC721Mintable() ERC721Full("Test", "TEST") public {}
constructor()
ERC721Mintable()
ERC721Full("Test", "TEST")
public
{
}
} }
...@@ -7,11 +7,11 @@ import "../token/ERC721/ERC721.sol"; ...@@ -7,11 +7,11 @@ 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 {
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);
} }
} }
...@@ -8,15 +8,15 @@ import "./PauserRoleMock.sol"; ...@@ -8,15 +8,15 @@ 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 {
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);
} }
} }
...@@ -3,39 +3,19 @@ pragma solidity ^0.4.24; ...@@ -3,39 +3,19 @@ pragma solidity ^0.4.24;
import "../token/ERC721/IERC721Receiver.sol"; 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 from, uint256 tokenId, bytes data, uint256 gas);
address operator,
address from,
uint256 tokenId,
bytes data,
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 from, uint256 tokenId, bytes data) public returns (bytes4) {
address operator, require(!_reverts);
address from, emit Received(operator, from, tokenId, data, gasleft());
uint256 tokenId, return _retval;
bytes data }
)
public
returns(bytes4)
{
require(!_reverts);
emit Received(
operator,
from,
tokenId,
data,
gasleft() // msg.gas was deprecated in solidityv0.4.21
);
return _retval;
}
} }
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
contract EventEmitter { contract EventEmitter {
event Argumentless(); event Argumentless();
event ShortUint(uint8 value); event ShortUint(uint8 value);
event ShortInt(int8 value); event ShortInt(int8 value);
event LongUint(uint256 value); event LongUint(uint256 value);
event LongInt(int256 value); event LongInt(int256 value);
event Address(address value); event Address(address value);
event Boolean(bool value); event Boolean(bool value);
event String(string value); event String(string value);
event LongUintBooleanString( event LongUintBooleanString(uint256 uintValue, bool booleanValue, string stringValue);
uint256 uintValue,
bool booleanValue, function emitArgumentless() public {
string stringValue emit Argumentless();
); }
function emitArgumentless() public { function emitShortUint(uint8 value) public {
emit Argumentless(); emit ShortUint(value);
} }
function emitShortUint(uint8 value) public { function emitShortInt(int8 value) public {
emit ShortUint(value); emit ShortInt(value);
} }
function emitShortInt(int8 value) public { function emitLongUint(uint256 value) public {
emit ShortInt(value); emit LongUint(value);
} }
function emitLongUint(uint256 value) public { function emitLongInt(int256 value) public {
emit LongUint(value); emit LongInt(value);
} }
function emitLongInt(int256 value) public { function emitAddress(address value) public {
emit LongInt(value); emit Address(value);
} }
function emitAddress(address value) public { function emitBoolean(bool value) public {
emit Address(value); emit Boolean(value);
} }
function emitBoolean(bool value) public { function emitString(string value) public {
emit Boolean(value); emit String(value);
} }
function emitString(string value) public { function emitLongUintBooleanString(uint256 uintValue, bool booleanValue, string stringValue) public {
emit String(value); emit LongUintBooleanString(uintValue, booleanValue, stringValue);
} }
function emitLongUintBooleanString( function emitLongUintAndBoolean(uint256 uintValue, bool boolValue) public {
uint256 uintValue, emit LongUint(uintValue);
bool booleanValue, emit Boolean(boolValue);
string stringValue) }
public {
emit LongUintBooleanString(uintValue, booleanValue, stringValue);
}
function emitLongUintAndBoolean(uint256 uintValue, bool boolValue) public {
emit LongUint(uintValue);
emit Boolean(boolValue);
}
} }
...@@ -5,17 +5,9 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol"; ...@@ -5,17 +5,9 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol";
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale { contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
constructor ( constructor (uint256 openingTime, uint256 closingTime, uint256 rate, address wallet, IERC20 token)
uint256 openingTime, public
uint256 closingTime, Crowdsale(rate, wallet, token)
uint256 rate, TimedCrowdsale(openingTime, closingTime)
address wallet, {}
IERC20 token
)
public
Crowdsale(rate, wallet, token)
TimedCrowdsale(openingTime, closingTime)
{
}
} }
...@@ -4,20 +4,17 @@ import "../crowdsale/price/IncreasingPriceCrowdsale.sol"; ...@@ -4,20 +4,17 @@ import "../crowdsale/price/IncreasingPriceCrowdsale.sol";
import "../math/SafeMath.sol"; 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(initialRate, wallet, token)
Crowdsale(initialRate, wallet, token) TimedCrowdsale(openingTime, closingTime)
TimedCrowdsale(openingTime, closingTime) IncreasingPriceCrowdsale(initialRate, finalRate)
IncreasingPriceCrowdsale(initialRate, finalRate) {}
{
}
} }
...@@ -4,16 +4,7 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,16 +4,7 @@ import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol"; import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
import "./CapperRoleMock.sol"; import "./CapperRoleMock.sol";
contract IndividuallyCappedCrowdsaleImpl contract IndividuallyCappedCrowdsaleImpl is IndividuallyCappedCrowdsale, CapperRoleMock {
is IndividuallyCappedCrowdsale, CapperRoleMock { constructor (uint256 rate, address wallet, IERC20 token) public Crowdsale(rate, wallet, token)
{}
constructor(
uint256 rate,
address wallet,
IERC20 token
)
public
Crowdsale(rate, wallet, token)
{
}
} }
...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24;
import "../math/Math.sol"; 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);
} }
} }
...@@ -3,16 +3,7 @@ pragma solidity ^0.4.24; ...@@ -3,16 +3,7 @@ pragma solidity ^0.4.24;
import { MerkleProof } from "../cryptography/MerkleProof.sol"; import { MerkleProof } from "../cryptography/MerkleProof.sol";
contract MerkleProofWrapper { contract MerkleProofWrapper {
function verify(bytes32[] proof, bytes32 root, bytes32 leaf) public pure returns (bool) {
function verify( return MerkleProof.verify(proof, root, leaf);
bytes32[] proof, }
bytes32 root,
bytes32 leaf
)
public
pure
returns (bool)
{
return MerkleProof.verify(proof, root, leaf);
}
} }
...@@ -4,15 +4,5 @@ import "../token/ERC20/ERC20Mintable.sol"; ...@@ -4,15 +4,5 @@ import "../token/ERC20/ERC20Mintable.sol";
import "../crowdsale/emission/MintedCrowdsale.sol"; import "../crowdsale/emission/MintedCrowdsale.sol";
contract MintedCrowdsaleImpl is MintedCrowdsale { contract MintedCrowdsaleImpl is MintedCrowdsale {
constructor (uint256 rate, address wallet, ERC20Mintable token) public Crowdsale(rate, wallet, token) {}
constructor (
uint256 rate,
address wallet,
ERC20Mintable token
)
public
Crowdsale(rate, wallet, token)
{
}
} }
...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24;
import "../access/roles/MinterRole.sol"; import "../access/roles/MinterRole.sol";
contract MinterRoleMock is MinterRole { contract MinterRoleMock is MinterRole {
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);
} }
} }
...@@ -2,5 +2,4 @@ pragma solidity ^0.4.24; ...@@ -2,5 +2,4 @@ pragma solidity ^0.4.24;
import "../ownership/Ownable.sol"; import "../ownership/Ownable.sol";
contract OwnableMock is Ownable { contract OwnableMock is Ownable {}
}
...@@ -5,20 +5,19 @@ import "./PauserRoleMock.sol"; ...@@ -5,20 +5,19 @@ 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 {
drasticMeasureTaken = false; drasticMeasureTaken = false;
count = 0; count = 0;
} }
function normalProcess() external whenNotPaused { function normalProcess() external whenNotPaused {
count++; count++;
} }
function drasticMeasure() external whenPaused {
drasticMeasureTaken = true;
}
function drasticMeasure() external whenPaused {
drasticMeasureTaken = true;
}
} }
...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24;
import "../access/roles/PauserRole.sol"; import "../access/roles/PauserRole.sol";
contract PauserRoleMock is PauserRole { contract PauserRoleMock is PauserRole {
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);
} }
} }
...@@ -4,18 +4,9 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,18 +4,9 @@ import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/PostDeliveryCrowdsale.sol"; import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale { contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale {
constructor (uint256 openingTime, uint256 closingTime, uint256 rate, address wallet, IERC20 token)
constructor ( public
uint256 openingTime, TimedCrowdsale(openingTime, closingTime)
uint256 closingTime, Crowdsale(rate, wallet, token)
uint256 rate, {}
address wallet,
IERC20 token
)
public
TimedCrowdsale(openingTime, closingTime)
Crowdsale(rate, wallet, token)
{
}
} }
...@@ -4,12 +4,10 @@ import "../payment/PullPayment.sol"; ...@@ -4,12 +4,10 @@ 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 { } // test helper function to call asyncTransfer
function callTransfer(address dest, uint256 amount) public {
// test helper function to call asyncTransfer _asyncTransfer(dest, amount);
function callTransfer(address dest, uint256 amount) public { }
_asyncTransfer(dest, amount);
}
} }
...@@ -2,9 +2,9 @@ pragma solidity ^0.4.24; ...@@ -2,9 +2,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)));
} }
} }
...@@ -4,41 +4,39 @@ import "../utils/ReentrancyGuard.sol"; ...@@ -4,41 +4,39 @@ import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol"; import "./ReentrancyAttack.sol";
contract ReentrancyMock is ReentrancyGuard { contract ReentrancyMock is ReentrancyGuard {
uint256 public counter;
uint256 public counter; constructor () public {
counter = 0;
constructor() public { }
counter = 0;
}
function callback() external nonReentrant {
count();
}
function countLocalRecursive(uint256 n) public nonReentrant { function callback() external nonReentrant {
if (n > 0) { count();
count();
countLocalRecursive(n - 1);
} }
}
function countLocalRecursive(uint256 n) public nonReentrant {
function countThisRecursive(uint256 n) public nonReentrant { if (n > 0) {
if (n > 0) { count();
count(); countLocalRecursive(n - 1);
// solium-disable-next-line security/no-low-level-calls }
bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
require(result == true);
} }
}
function countAndCall(ReentrancyAttack attacker) public nonReentrant { function countThisRecursive(uint256 n) public nonReentrant {
count(); if (n > 0) {
bytes4 func = bytes4(keccak256("callback()")); count();
attacker.callSender(func); // solium-disable-next-line security/no-low-level-calls
} bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
require(result == true);
}
}
function count() private { function countAndCall(ReentrancyAttack attacker) public nonReentrant {
counter += 1; count();
} bytes4 func = bytes4(keccak256("callback()"));
attacker.callSender(func);
}
function count() private {
counter += 1;
}
} }
...@@ -4,20 +4,17 @@ import "../token/ERC20/ERC20Mintable.sol"; ...@@ -4,20 +4,17 @@ import "../token/ERC20/ERC20Mintable.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol"; import "../crowdsale/distribution/RefundableCrowdsale.sol";
contract RefundableCrowdsaleImpl is RefundableCrowdsale { contract RefundableCrowdsaleImpl is 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(rate, wallet, token)
Crowdsale(rate, wallet, token) TimedCrowdsale(openingTime, closingTime)
TimedCrowdsale(openingTime, closingTime) RefundableCrowdsale(goal)
RefundableCrowdsale(goal) {}
{
}
} }
...@@ -3,19 +3,19 @@ pragma solidity ^0.4.24; ...@@ -3,19 +3,19 @@ pragma solidity ^0.4.24;
import "../access/Roles.sol"; 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);
} }
} }
...@@ -4,109 +4,109 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,109 +4,109 @@ import "../token/ERC20/IERC20.sol";
import "../token/ERC20/SafeERC20.sol"; import "../token/ERC20/SafeERC20.sol";
contract ERC20FailingMock { contract ERC20FailingMock {
uint256 private _allowance; uint256 private _allowance;
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 allowance(address, address) public view returns (uint256) { function allowance(address, address) public view returns (uint256) {
return 0; return 0;
} }
} }
contract ERC20SucceedingMock { contract ERC20SucceedingMock {
uint256 private _allowance; uint256 private _allowance;
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 setAllowance(uint256 allowance_) public { function setAllowance(uint256 allowance_) public {
_allowance = allowance_; _allowance = allowance_;
} }
function allowance(address, address) public view returns (uint256) { function allowance(address, address) public view returns (uint256) {
return _allowance; return _allowance;
} }
} }
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 = IERC20(new ERC20FailingMock()); _failing = IERC20(new ERC20FailingMock());
_succeeding = IERC20(new ERC20SucceedingMock()); _succeeding = IERC20(new ERC20SucceedingMock());
} }
// Using _failing // Using _failing
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 doFailingIncreaseAllowance() public { function doFailingIncreaseAllowance() public {
_failing.safeIncreaseAllowance(address(0), 0); _failing.safeIncreaseAllowance(address(0), 0);
} }
function doFailingDecreaseAllowance() public { function doFailingDecreaseAllowance() public {
_failing.safeDecreaseAllowance(address(0), 0); _failing.safeDecreaseAllowance(address(0), 0);
} }
// Using _succeeding // Using _succeeding
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(uint256 amount) public { function doSucceedingApprove(uint256 amount) public {
_succeeding.safeApprove(address(0), amount); _succeeding.safeApprove(address(0), amount);
} }
function doSucceedingIncreaseAllowance(uint256 amount) public { function doSucceedingIncreaseAllowance(uint256 amount) public {
_succeeding.safeIncreaseAllowance(address(0), amount); _succeeding.safeIncreaseAllowance(address(0), amount);
} }
function doSucceedingDecreaseAllowance(uint256 amount) public { function doSucceedingDecreaseAllowance(uint256 amount) public {
_succeeding.safeDecreaseAllowance(address(0), amount); _succeeding.safeDecreaseAllowance(address(0), amount);
} }
function setAllowance(uint256 allowance_) public { function setAllowance(uint256 allowance_) public {
ERC20SucceedingMock(_succeeding).setAllowance(allowance_); ERC20SucceedingMock(_succeeding).setAllowance(allowance_);
} }
function allowance() public view returns (uint256) { function allowance() public view returns (uint256) {
return _succeeding.allowance(address(0), address(0)); return _succeeding.allowance(address(0), address(0));
} }
} }
...@@ -3,24 +3,23 @@ pragma solidity ^0.4.24; ...@@ -3,24 +3,23 @@ pragma solidity ^0.4.24;
import "../math/SafeMath.sol"; import "../math/SafeMath.sol";
contract SafeMathMock { contract SafeMathMock {
function mul(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mul(a, b);
}
function mul(uint256 a, uint256 b) public pure returns (uint256) { function div(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mul(a, b); return SafeMath.div(a, b);
} }
function div(uint256 a, uint256 b) public pure returns (uint256) { function sub(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.div(a, b); return SafeMath.sub(a, b);
} }
function sub(uint256 a, uint256 b) public pure returns (uint256) { function add(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.sub(a, b); return SafeMath.add(a, b);
} }
function add(uint256 a, uint256 b) public pure returns (uint256) { function mod(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.add(a, b); return SafeMath.mod(a, b);
} }
function mod(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mod(a, b);
}
} }
...@@ -3,6 +3,5 @@ pragma solidity ^0.4.24; ...@@ -3,6 +3,5 @@ pragma solidity ^0.4.24;
import "../ownership/Secondary.sol"; import "../ownership/Secondary.sol";
contract SecondaryMock is Secondary { contract SecondaryMock is Secondary {
function onlyPrimaryMock() public view onlyPrimary { function onlyPrimaryMock() public view onlyPrimary {}
}
} }
...@@ -4,70 +4,25 @@ import "../drafts/SignatureBouncer.sol"; ...@@ -4,70 +4,25 @@ import "../drafts/SignatureBouncer.sol";
import "./SignerRoleMock.sol"; import "./SignerRoleMock.sol";
contract SignatureBouncerMock is SignatureBouncer, SignerRoleMock { contract SignatureBouncerMock is SignatureBouncer, SignerRoleMock {
function checkValidSignature(address account, bytes signature) function checkValidSignature(address account, bytes signature) public view returns (bool) {
public return _isValidSignature(account, signature);
view }
returns (bool)
{
return _isValidSignature(account, signature);
}
function onlyWithValidSignature(bytes signature) function onlyWithValidSignature(bytes signature) public onlyValidSignature(signature) view {}
public
onlyValidSignature(signature)
view
{
} function checkValidSignatureAndMethod(address account, bytes signature) public view returns (bool) {
return _isValidSignatureAndMethod(account, signature);
}
function checkValidSignatureAndMethod(address account, bytes signature) function onlyWithValidSignatureAndMethod(bytes signature) public onlyValidSignatureAndMethod(signature) view {}
public
view
returns (bool)
{
return _isValidSignatureAndMethod(account, signature);
}
function onlyWithValidSignatureAndMethod(bytes signature) function checkValidSignatureAndData(address account, bytes, uint, bytes signature) public view returns (bool) {
public return _isValidSignatureAndData(account, signature);
onlyValidSignatureAndMethod(signature) }
view
{
} function onlyWithValidSignatureAndData(uint, bytes signature) public onlyValidSignatureAndData(signature) view {}
function checkValidSignatureAndData( function theWrongMethod(bytes) public pure {}
address account,
bytes,
uint,
bytes signature
)
public
view
returns (bool)
{
return _isValidSignatureAndData(account, signature);
}
function onlyWithValidSignatureAndData(uint, bytes signature) function tooShortMsgData() public onlyValidSignatureAndData("") view {}
public
onlyValidSignatureAndData(signature)
view
{
}
function theWrongMethod(bytes)
public
pure
{
}
function tooShortMsgData()
public
onlyValidSignatureAndData("")
view
{
}
} }
...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24; ...@@ -3,15 +3,15 @@ pragma solidity ^0.4.24;
import "../access/roles/SignerRole.sol"; import "../access/roles/SignerRole.sol";
contract SignerRoleMock is SignerRole { contract SignerRoleMock is SignerRole {
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);
} }
} }
...@@ -4,18 +4,9 @@ import "../token/ERC20/IERC20.sol"; ...@@ -4,18 +4,9 @@ import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/TimedCrowdsale.sol"; import "../crowdsale/validation/TimedCrowdsale.sol";
contract TimedCrowdsaleImpl is TimedCrowdsale { contract TimedCrowdsaleImpl is TimedCrowdsale {
constructor (uint256 openingTime, uint256 closingTime, uint256 rate, address wallet, IERC20 token)
constructor ( public
uint256 openingTime, Crowdsale(rate, wallet, token)
uint256 closingTime, TimedCrowdsale(openingTime, closingTime)
uint256 rate, {}
address wallet,
IERC20 token
)
public
Crowdsale(rate, wallet, token)
TimedCrowdsale(openingTime, closingTime)
{
}
} }
...@@ -6,70 +6,67 @@ pragma solidity ^0.4.24; ...@@ -6,70 +6,67 @@ pragma solidity ^0.4.24;
* functions, this simplifies the implementation of "user permissions". * functions, this simplifies the implementation of "user permissions".
*/ */
contract Ownable { contract Ownable {
address private _owner; address private _owner;
event OwnershipTransferred( event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
address indexed previousOwner,
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.
*/ */
constructor() internal { constructor () internal {
_owner = msg.sender; _owner = msg.sender;
emit OwnershipTransferred(address(0), _owner); emit OwnershipTransferred(address(0), _owner);
} }
/** /**
* @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 OwnershipTransferred(_owner, address(0)); emit OwnershipTransferred(_owner, address(0));
_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;
} }
} }
...@@ -5,42 +5,42 @@ pragma solidity ^0.4.24; ...@@ -5,42 +5,42 @@ pragma solidity ^0.4.24;
* @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 { contract Secondary {
address private _primary; address private _primary;
event PrimaryTransferred( event PrimaryTransferred(
address recipient address recipient
); );
/** /**
* @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.
*/ */
constructor() internal { constructor () internal {
_primary = msg.sender; _primary = msg.sender;
emit PrimaryTransferred(_primary); emit PrimaryTransferred(_primary);
} }
/** /**
* @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);
_; _;
} }
/** /**
* @return the address of the primary. * @return the address of the primary.
*/ */
function primary() public view returns (address) { function primary() public view returns (address) {
return _primary; return _primary;
} }
/** /**
* @dev Transfers contract to a new primary. * @dev Transfers contract to a new primary.
* @param recipient The address of new primary. * @param recipient The address of new 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;
emit PrimaryTransferred(_primary); emit PrimaryTransferred(_primary);
} }
} }
...@@ -8,109 +8,105 @@ import "../math/SafeMath.sol"; ...@@ -8,109 +8,105 @@ 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 PaymentSplitter { contract PaymentSplitter {
using SafeMath for uint256; using SafeMath for uint256;
event PayeeAdded(address account, uint256 shares); event PayeeAdded(address account, uint256 shares);
event PaymentReleased(address to, uint256 amount); event PaymentReleased(address to, uint256 amount);
event PaymentReceived(address from, uint256 amount); event PaymentReceived(address from, uint256 amount);
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
*/ */
constructor(address[] payees, uint256[] shares) public payable { constructor (address[] payees, uint256[] shares) public payable {
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
*/
function () external payable {
emit PaymentReceived(msg.sender, msg.value);
}
/**
* @return the total shares of the contract.
*/
function totalShares() public view returns (uint256) {
return _totalShares;
}
/**
* @return the total amount already released.
*/
function totalReleased() public view returns (uint256) {
return _totalReleased;
}
/**
* @return the shares of an account.
*/
function shares(address account) public view returns (uint256) {
return _shares[account];
}
/**
* @return the amount already released to an account.
*/
function released(address account) public view returns (uint256) {
return _released[account];
}
/**
* @return the address of a payee.
*/
function payee(uint256 index) public view returns (address) {
return _payees[index];
}
/**
* @dev Release one of the payee's proportional payment.
* @param account Whose payments will be released.
*/
function release(address account) public {
require(_shares[account] > 0);
uint256 totalReceived = address(this).balance.add(_totalReleased);
uint256 payment = totalReceived.mul(_shares[account]).div(_totalShares).sub(_released[account]);
require(payment != 0);
_released[account] = _released[account].add(payment);
_totalReleased = _totalReleased.add(payment);
account.transfer(payment);
emit PaymentReleased(account, payment);
}
/**
* @dev Add a new payee to the contract.
* @param account The address of the payee to add.
* @param shares_ The number of shares owned by the payee.
*/
function _addPayee(address account, uint256 shares_) private {
require(account != address(0));
require(shares_ > 0);
require(_shares[account] == 0);
_payees.push(account);
_shares[account] = shares_;
_totalShares = _totalShares.add(shares_);
emit PayeeAdded(account, shares_);
} }
}
/**
* @dev payable fallback
*/
function () external payable {
emit PaymentReceived(msg.sender, msg.value);
}
/**
* @return the total shares of the contract.
*/
function totalShares() public view returns(uint256) {
return _totalShares;
}
/**
* @return the total amount already released.
*/
function totalReleased() public view returns(uint256) {
return _totalReleased;
}
/**
* @return the shares of an account.
*/
function shares(address account) public view returns(uint256) {
return _shares[account];
}
/**
* @return the amount already released to an account.
*/
function released(address account) public view returns(uint256) {
return _released[account];
}
/**
* @return the address of a payee.
*/
function payee(uint256 index) public view returns(address) {
return _payees[index];
}
/**
* @dev Release one of the payee's proportional payment.
* @param account Whose payments will be released.
*/
function release(address account) public {
require(_shares[account] > 0);
uint256 totalReceived = address(this).balance.add(_totalReleased);
uint256 payment = totalReceived.mul(
_shares[account]).div(
_totalShares).sub(
_released[account]
);
require(payment != 0);
_released[account] = _released[account].add(payment);
_totalReleased = _totalReleased.add(payment);
account.transfer(payment);
emit PaymentReleased(account, payment);
}
/**
* @dev Add a new payee to the contract.
* @param account The address of the payee to add.
* @param shares_ The number of shares owned by the payee.
*/
function _addPayee(address account, uint256 shares_) private {
require(account != address(0));
require(shares_ > 0);
require(_shares[account] == 0);
_payees.push(account);
_shares[account] = shares_;
_totalShares = _totalShares.add(shares_);
emit PayeeAdded(account, shares_);
}
} }
...@@ -8,34 +8,34 @@ import "./escrow/Escrow.sol"; ...@@ -8,34 +8,34 @@ import "./escrow/Escrow.sol";
* contract and use _asyncTransfer instead of send or transfer. * contract and use _asyncTransfer instead of send or transfer.
*/ */
contract PullPayment { contract PullPayment {
Escrow private _escrow; Escrow private _escrow;
constructor() internal { constructor () internal {
_escrow = new Escrow(); _escrow = new Escrow();
} }
/** /**
* @dev Withdraw accumulated balance. * @dev Withdraw accumulated balance.
* @param payee Whose balance will be withdrawn. * @param payee Whose balance will be withdrawn.
*/ */
function withdrawPayments(address payee) public { function withdrawPayments(address payee) public {
_escrow.withdraw(payee); _escrow.withdraw(payee);
} }
/** /**
* @dev Returns the credit owed to an address. * @dev Returns the credit owed to an address.
* @param dest The creditor's address. * @param dest The creditor's address.
*/ */
function payments(address dest) public view returns (uint256) { function payments(address dest) public view returns (uint256) {
return _escrow.depositsOf(dest); return _escrow.depositsOf(dest);
} }
/** /**
* @dev Called by the payer to store the sent amount as credit to be pulled. * @dev Called by the payer to store the sent amount as credit to be pulled.
* @param dest The destination address of the funds. * @param dest The destination address of the funds.
* @param amount The amount to transfer. * @param amount The amount to transfer.
*/ */
function _asyncTransfer(address dest, uint256 amount) internal { function _asyncTransfer(address dest, uint256 amount) internal {
_escrow.deposit.value(amount)(dest); _escrow.deposit.value(amount)(dest);
} }
} }
...@@ -8,15 +8,15 @@ import "./Escrow.sol"; ...@@ -8,15 +8,15 @@ import "./Escrow.sol";
* @dev Intended usage: See Escrow.sol. Same usage guidelines apply here. * @dev Intended usage: See Escrow.sol. Same usage guidelines apply here.
*/ */
contract ConditionalEscrow is Escrow { contract ConditionalEscrow is Escrow {
/** /**
* @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);
} }
} }
...@@ -16,39 +16,39 @@ import "../../ownership/Secondary.sol"; ...@@ -16,39 +16,39 @@ import "../../ownership/Secondary.sol";
* to the escrow's deposit and withdraw. * to the escrow's deposit and withdraw.
*/ */
contract Escrow is Secondary { contract Escrow is 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 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);
} }
} }
...@@ -14,78 +14,78 @@ import "./ConditionalEscrow.sol"; ...@@ -14,78 +14,78 @@ import "./ConditionalEscrow.sol";
* RefundableCrowdsale contract for an example of RefundEscrow’s use. * RefundableCrowdsale contract for an example of RefundEscrow’s use.
*/ */
contract RefundEscrow is ConditionalEscrow { contract RefundEscrow is ConditionalEscrow {
enum State { Active, Refunding, Closed } enum State { Active, Refunding, Closed }
event RefundsClosed(); event RefundsClosed();
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.
*/ */
constructor(address beneficiary) public { constructor (address beneficiary) public {
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 RefundsClosed(); emit RefundsClosed();
} }
/** /**
* @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;
} }
} }
...@@ -7,21 +7,20 @@ import "./ERC20.sol"; ...@@ -7,21 +7,20 @@ import "./ERC20.sol";
* @dev Token that can be irreversibly burned (destroyed). * @dev Token that can be irreversibly burned (destroyed).
*/ */
contract ERC20Burnable is ERC20 { contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/** /**
* @dev Burns a specific amount of tokens. * @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param value The amount of token to be burned. * @param from address The address which you want to send tokens from
*/ * @param value uint256 The amount of token to be burned
function burn(uint256 value) public { */
_burn(msg.sender, value); function burnFrom(address from, uint256 value) public {
} _burnFrom(from, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
} }
...@@ -7,25 +7,22 @@ import "./ERC20Mintable.sol"; ...@@ -7,25 +7,22 @@ import "./ERC20Mintable.sol";
* @dev Mintable token with a token cap. * @dev Mintable token with a token cap.
*/ */
contract ERC20Capped is ERC20Mintable { contract ERC20Capped is ERC20Mintable {
uint256 private _cap;
uint256 private _cap; constructor (uint256 cap) public {
require(cap > 0);
_cap = cap;
}
constructor(uint256 cap) /**
public * @return the cap for the token minting.
{ */
require(cap > 0); function cap() public view returns (uint256) {
_cap = cap; return _cap;
} }
/** function _mint(address account, uint256 value) internal {
* @return the cap for the token minting. require(totalSupply().add(value) <= _cap);
*/ super._mint(account, value);
function cap() public view returns(uint256) { }
return _cap;
}
function _mint(address account, uint256 value) internal {
require(totalSupply().add(value) <= _cap);
super._mint(account, value);
}
} }
...@@ -9,34 +9,34 @@ import "./IERC20.sol"; ...@@ -9,34 +9,34 @@ 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 IERC20 { contract ERC20Detailed is IERC20 {
string private _name; string private _name;
string private _symbol; string private _symbol;
uint8 private _decimals; uint8 private _decimals;
constructor(string name, string symbol, uint8 decimals) public { constructor (string name, string symbol, uint8 decimals) public {
_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;
} }
} }
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