Commit 2b9dc9ae by Francisco Giordano

Merge tag 'v2.2.0' of github.com:OpenZeppelin/openzeppelin-solidity

v2.2.0
parents f18fd173 9ed1b448
...@@ -16,6 +16,7 @@ Fixes # ...@@ -16,6 +16,7 @@ Fixes #
(https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md), (https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md),
- added tests where applicable to test new functionality, - added tests where applicable to test new functionality,
- made sure that your contracts are well-documented, - made sure that your contracts are well-documented,
- run the JS/Solidity linters and fixed any issues (`npm run lint:fix`), and - run the Solidity linter (`npm run lint:sol`) and fixed any issues,
- run the JS linter and fixed any issues (`npm run lint:fix`), and
- updated the changelog, if applicable. - updated the changelog, if applicable.
--> -->
...@@ -32,10 +32,13 @@ npm-debug.log ...@@ -32,10 +32,13 @@ npm-debug.log
# truffle build directory # truffle build directory
build/ build/
# lol macs # macOS
.DS_Store/ .DS_Store
# truffle # truffle
.node-xmlhttprequest-* .node-xmlhttprequest-*
.zos.session .zos.session
# IntelliJ IDE
.idea
...@@ -25,11 +25,10 @@ jobs: ...@@ -25,11 +25,10 @@ jobs:
name: "Unit tests" name: "Unit tests"
script: npm run test script: npm run test
# solidity-coverage fails at parsing 0.5.x code - stage: tests
# - stage: tests name: "Unit tests with coverage report"
# name: "Unit tests with coverage report" script: npm run test
# script: npm run test env: SOLIDITY_COVERAGE=true
# env: SOLIDITY_COVERAGE=true
- stage: tests - stage: tests
name: "Unit tests using solc nightly" name: "Unit tests using solc nightly"
......
# Changelog # Changelog
## 2.2.0 (unreleased) ## 2.2.0 (2019-03-14)
## 2.1.2 (2019-17-01) ### New features:
* `ERC20Snapshot`: create snapshots on demand of the token balances and total supply, to later retrieve and e.g. calculate dividends at a past time. ([#1617](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1617))
* `SafeERC20`: `ERC20` contracts with no return value (i.e. that revert on failure) are now supported. ([#1655](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/))
* `ERC20`: added internal `_approve(address owner, address spender, uint256 value)`, allowing derived contracts to set the allowance of arbitrary accounts. ([#1609](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1609))
* `ERC20Metadata`: added internal `_setTokenURI(string memory tokenURI)`. ([#1618](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1618))
* `TimedCrowdsale`: added internal `_extendTime(uint256 newClosingTime)` as well as `TimedCrowdsaleExtended(uint256 prevClosingTime, uint256 newClosingTime)` event allowing to extend the crowdsale, as long as it hasn't already closed.
### Improvements:
* Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives. ([#1606](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1606))
* `ECDSA`: `recover` no longer accepts malleable signatures (those using upper-range values for `s`, or 0/1 for `v`). ([#1622](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1622))
* `ERC721`'s transfers are now more gas efficient due to removal of unnecessary `SafeMath` calls. ([#1610](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1610))
* `Counter`'s API has been improved, and is now used by `ERC721` (though it is still in `drafts`). ([#1610](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1610))
* Fixed variable shadowing issues. ([#1606](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1606))
### Bugfixes:
* (minor) `SafeERC20`: `safeApprove` wasn't properly checking for a zero allowance when attempting to set a non-zero allowance. ([#1647](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1647))
### Breaking changes:
* `TokenMetadata` (in drafts) has been renamed to `ERC20Metadata`. ([#1618](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1618))
## 2.1.3 (2019-02-26)
* Backported `SafeERC20.safeApprove` bugfix. ([#1647](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1647))
## 2.1.2 (2019-01-17)
* Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`. * Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`.
## 2.1.1 (2019-04-01) ## 2.1.1 (2019-01-04)
* Version bump to avoid conflict in the npm registry. * Version bump to avoid conflict in the npm registry.
## 2.1.0 (2019-04-01) ## 2.1.0 (2019-01-04)
### New features: ### New features:
* Now targeting the 0.5.x line of Solidity compilers. For 0.4.24 support, use version 2.0 of OpenZeppelin. * Now targeting the 0.5.x line of Solidity compilers. For 0.4.24 support, use version 2.0 of OpenZeppelin.
......
...@@ -94,6 +94,24 @@ contract MyNFT is Initializable, ERC721Full, ERC721Mintable { ...@@ -94,6 +94,24 @@ contract MyNFT is Initializable, ERC721Full, ERC721Mintable {
} }
``` ```
> You need an ethereum development framework for the above import statements to work! Check out these guides for [Truffle] or [Embark].
On our site you will find a few [guides] to learn about the different parts of OpenZeppelin, as well as [documentation for the API][API docs]. Keep in mind that the API docs are work in progress, and don’t hesitate to ask questions in [our Slack][Slack].
## Security
OpenZeppelin the project is maintained by [Zeppelin] the company, and developed following our high standards for code quality and security. OpenZeppelin is meant to provide tested and community-audited code, but please use common sense when doing anything that deals with real money! We take no responsibility for your implementation decisions and any security problems you might experience.
The core development principles and strategies that OpenZeppelin is based on include: security in depth, simple and modular code, clarity-driven naming conventions, comprehensive unit testing, pre-and-post-condition sanity checks, code consistency, and regular audits.
The latest audit was done on October 2018 on version 2.0.0.
Please report any security issues you find to security@openzeppelin.org.
## Contribute
OpenZeppelin exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guide]!
## License ## License
OpenZeppelin is released under the [MIT License](LICENSE). OpenZeppelin is released under the [MIT License](LICENSE).
\ No newline at end of file
...@@ -51,12 +51,15 @@ git checkout release-vX.Y.Z ...@@ -51,12 +51,15 @@ git checkout release-vX.Y.Z
git pull upstream git pull upstream
``` ```
Before starting the release process, make one final commit to CHANGELOG.md, including the date of the release.
Change the version string in `package.json`, `package-lock.json` and `ethpm.json` removing the "-rc.R" suffix. Commit these changes and tag the commit as `vX.Y.Z`. Change the version string in `package.json`, `package-lock.json` and `ethpm.json` removing the "-rc.R" suffix. Commit these changes and tag the commit as `vX.Y.Z`.
``` ```
git add package.json package-lock.json ethpm.json git add package.json package-lock.json ethpm.json
git commit -m "Release vX.Y.Z" git commit -m "Release vX.Y.Z"
git tag -a vX.Y.Z git tag -a vX.Y.Z
git push upstream release-vX.Y.Z
git push upstream vX.Y.Z git push upstream vX.Y.Z
``` ```
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title Roles * @title Roles
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol"; import "../Roles.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol"; import "../Roles.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol"; import "../Roles.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol"; import "../Roles.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
...@@ -12,8 +12,8 @@ import "../utils/ReentrancyGuard.sol"; ...@@ -12,8 +12,8 @@ import "../utils/ReentrancyGuard.sol";
* allowing investors to purchase tokens with ether. This contract implements * allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional * such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior. * functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform * The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. They are *not* intended to be modified / overridden. * the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override * The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate * the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior. * behavior.
...@@ -66,7 +66,7 @@ contract Crowdsale is Initializable, ReentrancyGuard { ...@@ -66,7 +66,7 @@ contract Crowdsale is Initializable, ReentrancyGuard {
/** /**
* @dev fallback function ***DO NOT OVERRIDE*** * @dev fallback function ***DO NOT OVERRIDE***
* Note that other contracts will transfer fund with a base gas stipend * Note that other contracts will transfer funds with a base gas stipend
* of 2300, which is not enough to call buyTokens. Consider calling * of 2300, which is not enough to call buyTokens. Consider calling
* buyTokens directly when purchasing tokens from a contract. * buyTokens directly when purchasing tokens from a contract.
*/ */
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
...@@ -6,7 +6,7 @@ import "../validation/TimedCrowdsale.sol"; ...@@ -6,7 +6,7 @@ import "../validation/TimedCrowdsale.sol";
/** /**
* @title FinalizableCrowdsale * @title FinalizableCrowdsale
* @dev Extension of Crowdsale with a one-off finalization action, where one * @dev Extension of TimedCrowdsale with a one-off finalization action, where one
* can do extra work after finishing. * can do extra work after finishing.
*/ */
contract FinalizableCrowdsale is Initializable, TimedCrowdsale { contract FinalizableCrowdsale is Initializable, TimedCrowdsale {
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../validation/TimedCrowdsale.sol"; import "../validation/TimedCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
...@@ -7,8 +7,8 @@ import "../../payment/escrow/RefundEscrow.sol"; ...@@ -7,8 +7,8 @@ import "../../payment/escrow/RefundEscrow.sol";
/** /**
* @title RefundableCrowdsale * @title RefundableCrowdsale
* @dev Extension of Crowdsale contract that adds a funding goal, and the possibility of users getting a refund if goal * @dev Extension of FinalizableCrowdsale contract that adds a funding goal, and the possibility of users
* is not met. * getting a refund if goal is not met.
* *
* Deprecated, use RefundablePostDeliveryCrowdsale instead. Note that if you allow tokens to be traded before the goal * Deprecated, use RefundablePostDeliveryCrowdsale instead. Note that if you allow tokens to be traded before the goal
* is met, then an attack is possible in which the attacker purchases tokens from the crowdsale and when they sees that * is met, then an attack is possible in which the attacker purchases tokens from the crowdsale and when they sees that
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Crowdsale.sol"; import "../Crowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../Crowdsale.sol"; import "../Crowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../validation/TimedCrowdsale.sol"; import "../validation/TimedCrowdsale.sol";
...@@ -31,7 +31,7 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale { ...@@ -31,7 +31,7 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale {
} }
/** /**
* The base rate function is overridden to revert, since this crowdsale doens't use it, and * The base rate function is overridden to revert, since this crowdsale doesn't use it, and
* all calls to it are a mistake. * all calls to it are a mistake.
*/ */
function rate() public view returns (uint256) { function rate() public view returns (uint256) {
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
...@@ -15,6 +15,13 @@ contract TimedCrowdsale is Initializable, Crowdsale { ...@@ -15,6 +15,13 @@ contract TimedCrowdsale is Initializable, Crowdsale {
uint256 private _closingTime; uint256 private _closingTime;
/** /**
* Event for crowdsale extending
* @param newClosingTime new closing time
* @param prevClosingTime old closing time
*/
event TimedCrowdsaleExtended(uint256 prevClosingTime, uint256 newClosingTime);
/**
* @dev Reverts if not in crowdsale time range. * @dev Reverts if not in crowdsale time range.
*/ */
modifier onlyWhileOpen { modifier onlyWhileOpen {
...@@ -82,5 +89,17 @@ contract TimedCrowdsale is Initializable, Crowdsale { ...@@ -82,5 +89,17 @@ contract TimedCrowdsale is Initializable, Crowdsale {
super._preValidatePurchase(beneficiary, weiAmount); super._preValidatePurchase(beneficiary, weiAmount);
} }
/**
* @dev Extend crowdsale
* @param newClosingTime Crowdsale closing time
*/
function _extendTime(uint256 newClosingTime) internal {
require(!hasClosed());
require(newClosingTime > _closingTime);
emit TimedCrowdsaleExtended(_closingTime, newClosingTime);
_closingTime = newClosingTime;
}
uint256[50] private ______gap; uint256[50] private ______gap;
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../Crowdsale.sol"; import "../Crowdsale.sol";
import "../../access/roles/WhitelistedRole.sol"; import "../../access/roles/WhitelistedRole.sol";
...@@ -15,11 +15,11 @@ contract WhitelistCrowdsale is Initializable, WhitelistedRole, Crowdsale { ...@@ -15,11 +15,11 @@ contract WhitelistCrowdsale is Initializable, WhitelistedRole, Crowdsale {
} }
/** /**
* @dev Extend parent behavior requiring beneficiary to be whitelisted. Note that no * @dev Extend parent behavior requiring beneficiary to be whitelisted. Note that no
* restriction is imposed on the account sending the transaction. * restriction is imposed on the account sending the transaction.
* @param _beneficiary Token beneficiary * @param _beneficiary Token beneficiary
* @param _weiAmount Amount of wei contributed * @param _weiAmount Amount of wei contributed
*/ */
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal view { function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal view {
require(isWhitelisted(_beneficiary)); require(isWhitelisted(_beneficiary));
super._preValidatePurchase(_beneficiary, _weiAmount); super._preValidatePurchase(_beneficiary, _weiAmount);
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title Elliptic curve signature operations * @title Elliptic curve signature operations
...@@ -14,16 +14,16 @@ library ECDSA { ...@@ -14,16 +14,16 @@ library ECDSA {
* @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 memory signature) internal pure returns (address) { function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
bytes32 r;
bytes32 s;
uint8 v;
// Check the signature length // Check the signature length
if (signature.length != 65) { if (signature.length != 65) {
return (address(0)); return (address(0));
} }
// Divide the signature in r, s and v variables // Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them // ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly. // currently is to use assembly.
// solhint-disable-next-line no-inline-assembly // solhint-disable-next-line no-inline-assembly
...@@ -33,17 +33,25 @@ library ECDSA { ...@@ -33,17 +33,25 @@ library ECDSA {
v := byte(0, mload(add(signature, 0x60))) v := byte(0, mload(add(signature, 0x60)))
} }
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
if (v < 27) { // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
v += 27; // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return address(0);
} }
// If the version is correct return the signer address
if (v != 27 && v != 28) { if (v != 27 && v != 28) {
return (address(0)); return address(0);
} else {
return ecrecover(hash, v, r, s);
} }
// If the signature is valid (and not malleable), return the signer address
return ecrecover(hash, v, r, s);
} }
/** /**
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title MerkleProof * @title MerkleProof
......
pragma solidity ^0.5.0;
/**
* @title Counter
* @author Matt Condon (@shrugs)
* @dev Provides an incrementing uint256 id acquired by the `Counter#next` getter.
* Use this for issuing ERC721 ids or keeping track of request ids, anything you want, really.
*
* Include with `using Counter for Counter.Counter;`
* @notice Does not allow an Id of 0, which is popularly used to signify a null state in solidity.
* Does not protect from overflows, but if you have 2^256 ids, you have other problems.
* (But actually, it's generally impossible to increment a counter this many times, energy wise
* so it's not something you have to worry about.)
*/
library Counter {
struct Counter {
uint256 current; // default: 0
}
function next(Counter storage index) internal returns (uint256) {
index.current += 1;
return index.current;
}
}
pragma solidity ^0.5.2;
import "../math/SafeMath.sol";
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids
*
* Include with `using Counters for Counters.Counter;`
* Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the SafeMath
* overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
* directly accessed.
*/
library Counters {
using SafeMath for uint256;
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
counter._value += 1;
}
function decrement(Counter storage counter) internal {
counter._value = counter._value.sub(1);
}
}
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../../token/ERC20/IERC20.sol"; import "../../token/ERC20/IERC20.sol";
...@@ -8,22 +8,20 @@ import "../../token/ERC20/IERC20.sol"; ...@@ -8,22 +8,20 @@ import "../../token/ERC20/IERC20.sol";
* @dev See https://eips.ethereum.org/EIPS/eip-1046 * @dev See https://eips.ethereum.org/EIPS/eip-1046
* @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047 * @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047
*/ */
contract ERC20TokenMetadata is Initializable, IERC20 { contract ERC20Metadata is Initializable {
function tokenURI() external view returns (string memory);
uint256[50] private ______gap;
}
contract ERC20WithMetadata is Initializable, ERC20TokenMetadata {
string private _tokenURI; string private _tokenURI;
function initialize(string memory tokenURI) public { function initialize(string memory tokenURI_) public {
_tokenURI = tokenURI; _setTokenURI(tokenURI_);
} }
function tokenURI() external view returns (string memory) { function tokenURI() external view returns (string memory) {
return _tokenURI; return _tokenURI;
} }
function _setTokenURI(string memory tokenURI_) internal {
_tokenURI = tokenURI_;
}
uint256[50] private ______gap; uint256[50] private ______gap;
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
...@@ -18,7 +18,7 @@ import "../math/Math.sol"; ...@@ -18,7 +18,7 @@ import "../math/Math.sol";
* OpenZeppelin's ERC20Mintable, but the only functions that are needed are * OpenZeppelin's ERC20Mintable, but the only functions that are needed are
* `isMinter(address)` and `mint(address, amount)`. The migrator will check * `isMinter(address)` and `mint(address, amount)`. The migrator will check
* that it is a minter for the token. * that it is a minter for the token.
* The balance from the legacy token will be transfered to the migrator, as it * The balance from the legacy token will be transferred to the migrator, as it
* is migrated, and remain there forever. * is migrated, and remain there forever.
* Although this contract can be used in many different scenarios, the main * Although this contract can be used in many different scenarios, the main
* motivation was to provide a way to migrate ERC20 tokens into an upgradeable * motivation was to provide a way to migrate ERC20 tokens into an upgradeable
...@@ -66,14 +66,14 @@ contract ERC20Migrator is Initializable { ...@@ -66,14 +66,14 @@ contract ERC20Migrator is Initializable {
/** /**
* @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(address(_newToken) == address(0)); require(address(_newToken) == address(0));
require(address(newToken) != address(0)); require(address(newToken_) != address(0));
require(newToken.isMinter(address(this))); require(newToken_.isMinter(address(this)));
_newToken = newToken; _newToken = newToken_;
} }
/** /**
...@@ -83,6 +83,7 @@ contract ERC20Migrator is Initializable { ...@@ -83,6 +83,7 @@ contract ERC20Migrator is Initializable {
* @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 {
require(address(_newToken) != address(0));
_legacyToken.safeTransferFrom(account, address(this), amount); _legacyToken.safeTransferFrom(account, address(this), amount);
_newToken.mint(account, amount); _newToken.mint(account, amount);
} }
......
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../math/SafeMath.sol";
import "../utils/Arrays.sol";
import "../drafts/Counters.sol";
import "../token/ERC20/ERC20.sol";
/**
* @title ERC20 token with snapshots.
* @dev Inspired by Jordi Baylina's MiniMeToken to record historical balances:
* https://github.com/Giveth/minime/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol
* When a snapshot is made, the balances and totalSupply at the time of the snapshot are recorded for later
* access.
*
* To make a snapshot, call the `snapshot` function, which will emit the `Snapshot` event and return a snapshot id.
* To get the total supply from a snapshot, call the function `totalSupplyAt` with the snapshot id.
* To get the balance of an account from a snapshot, call the `balanceOfAt` function with the snapshot id and the
* account address.
* @author Validity Labs AG <info@validitylabs.org>
*/
contract ERC20Snapshot is Initializable, ERC20 {
using SafeMath for uint256;
using Arrays for uint256[];
using Counters for Counters.Counter;
// Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
// Snapshot struct, but that would impede usage of functions that work on an array.
struct Snapshots {
uint256[] ids;
uint256[] values;
}
mapping (address => Snapshots) private _accountBalanceSnapshots;
Snapshots private _totalSupplySnaphots;
// Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
Counters.Counter private _currentSnapshotId;
event Snapshot(uint256 id);
// Creates a new snapshot id. Balances are only stored in snapshots on demand: unless a snapshot was taken, a
// balance change will not be recorded. This means the extra added cost of storing snapshotted balances is only paid
// when required, but is also flexible enough that it allows for e.g. daily snapshots.
function snapshot() public returns (uint256) {
_currentSnapshotId.increment();
uint256 currentId = _currentSnapshotId.current();
emit Snapshot(currentId);
return currentId;
}
function balanceOfAt(address account, uint256 snapshotId) public view returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);
return snapshotted ? value : balanceOf(account);
}
function totalSupplyAt(uint256 snapshotId) public view returns(uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnaphots);
return snapshotted ? value : totalSupply();
}
// _transfer, _mint and _burn are the only functions where the balances are modified, so it is there that the
// snapshots are updated. Note that the update happens _before_ the balance change, with the pre-modified value.
// The same is true for the total supply and _mint and _burn.
function _transfer(address from, address to, uint256 value) internal {
_updateAccountSnapshot(from);
_updateAccountSnapshot(to);
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
_updateAccountSnapshot(account);
_updateTotalSupplySnapshot();
super._mint(account, value);
}
function _burn(address account, uint256 value) internal {
_updateAccountSnapshot(account);
_updateTotalSupplySnapshot();
super._burn(account, value);
}
// When a valid snapshot is queried, there are three possibilities:
// a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
// created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
// to this id is the current one.
// b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
// requested id, and its value is the one to return.
// c) More snapshots were created after the requested one, and the queried value was later modified. There will be
// no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
// larger than the requested one.
//
// In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
// it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
// exactly this.
function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
private view returns (bool, uint256)
{
require(snapshotId > 0);
require(snapshotId <= _currentSnapshotId.current());
uint256 index = snapshots.ids.findUpperBound(snapshotId);
if (index == snapshots.ids.length) {
return (false, 0);
} else {
return (true, snapshots.values[index]);
}
}
function _updateAccountSnapshot(address account) private {
_updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
}
function _updateTotalSupplySnapshot() private {
_updateSnapshot(_totalSupplySnaphots, totalSupply());
}
function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
uint256 currentId = _currentSnapshotId.current();
if (_lastSnapshotId(snapshots.ids) < currentId) {
snapshots.ids.push(currentId);
snapshots.values.push(currentValue);
}
}
function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
if (ids.length == 0) {
return 0;
} else {
return ids[ids.length - 1];
}
}
}
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../access/roles/SignerRole.sol"; import "../access/roles/SignerRole.sol";
...@@ -30,7 +30,7 @@ import "../cryptography/ECDSA.sol"; ...@@ -30,7 +30,7 @@ import "../cryptography/ECDSA.sol";
* @notice A method that uses the `onlyValidSignatureAndData` modifier must make * @notice A method that uses the `onlyValidSignatureAndData` modifier must make
* the _signature parameter the "last" parameter. You cannot sign a message that * the _signature parameter the "last" parameter. You cannot sign a message that
* has its own signature in it so the last 128 bytes of msg.data (which * has its own signature in it so the last 128 bytes of msg.data (which
* represents the length of the _signature data and the _signaature data itself) * represents the length of the _signature data and the _signature data itself)
* is ignored when validating. Also non fixed sized parameters make constructing * is ignored when validating. Also non fixed sized parameters make constructing
* the data in the signature much more complex. * the data in the signature much more complex.
* See https://ethereum.stackexchange.com/a/50616 for more details. * See https://ethereum.stackexchange.com/a/50616 for more details.
...@@ -57,7 +57,7 @@ contract SignatureBouncer is Initializable, SignerRole { ...@@ -57,7 +57,7 @@ contract SignatureBouncer is Initializable, SignerRole {
} }
/** /**
* @dev requires that a valid signature with a specifed method of a signer was provided * @dev requires that a valid signature with a specified method of a signer was provided
*/ */
modifier onlyValidSignatureAndMethod(bytes memory signature) { modifier onlyValidSignatureAndMethod(bytes memory signature) {
require(_isValidSignatureAndMethod(msg.sender, signature)); require(_isValidSignatureAndMethod(msg.sender, signature));
...@@ -65,7 +65,7 @@ contract SignatureBouncer is Initializable, SignerRole { ...@@ -65,7 +65,7 @@ contract SignatureBouncer is Initializable, SignerRole {
} }
/** /**
* @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 specified method and params of a signer was provided
*/ */
modifier onlyValidSignatureAndData(bytes memory signature) { modifier onlyValidSignatureAndData(bytes memory signature) {
require(_isValidSignatureAndData(msg.sender, signature)); require(_isValidSignatureAndData(msg.sender, signature));
...@@ -73,7 +73,7 @@ contract SignatureBouncer is Initializable, SignerRole { ...@@ -73,7 +73,7 @@ contract SignatureBouncer is Initializable, SignerRole {
} }
/** /**
* @dev is the signature of `this + sender` from a signer? * @dev is the signature of `this + account` from a signer?
* @return bool * @return bool
*/ */
function _isValidSignature(address account, bytes memory signature) internal view returns (bool) { function _isValidSignature(address account, bytes memory signature) internal view returns (bool) {
...@@ -81,7 +81,7 @@ contract SignatureBouncer is Initializable, SignerRole { ...@@ -81,7 +81,7 @@ contract SignatureBouncer is Initializable, SignerRole {
} }
/** /**
* @dev is the signature of `this + sender + methodId` from a signer? * @dev is the signature of `this + account + methodId` from a signer?
* @return bool * @return bool
*/ */
function _isValidSignatureAndMethod(address account, bytes memory signature) internal view returns (bool) { function _isValidSignatureAndMethod(address account, bytes memory signature) internal view returns (bool) {
...@@ -93,10 +93,10 @@ contract SignatureBouncer is Initializable, SignerRole { ...@@ -93,10 +93,10 @@ contract SignatureBouncer is Initializable, SignerRole {
} }
/** /**
* @dev is the signature of `this + sender + methodId + params(s)` from a signer? * @dev is the signature of `this + account + 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 memory signature) internal view returns (bool) { function _isValidSignatureAndData(address account, bytes memory signature) internal view returns (bool) {
require(msg.data.length > _SIGNATURE_SIZE); require(msg.data.length > _SIGNATURE_SIZE);
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title SignedSafeMath * @title SignedSafeMath
...@@ -8,8 +8,8 @@ library SignedSafeMath { ...@@ -8,8 +8,8 @@ library SignedSafeMath {
int256 constant private INT256_MIN = -2**255; int256 constant private INT256_MIN = -2**255;
/** /**
* @dev Multiplies two signed integers, reverts on overflow. * @dev Multiplies two signed integers, reverts on overflow.
*/ */
function mul(int256 a, int256 b) internal pure returns (int256) { function mul(int256 a, int256 b) internal pure returns (int256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested. // benefit is lost if 'b' is also tested.
...@@ -27,8 +27,8 @@ library SignedSafeMath { ...@@ -27,8 +27,8 @@ library SignedSafeMath {
} }
/** /**
* @dev Integer division of two signed integers truncating the quotient, reverts on division by zero. * @dev Integer division of two signed integers truncating the quotient, reverts on division by zero.
*/ */
function div(int256 a, int256 b) internal pure returns (int256) { function div(int256 a, int256 b) internal pure returns (int256) {
require(b != 0); // Solidity only automatically asserts when dividing by 0 require(b != 0); // Solidity only automatically asserts when dividing by 0
require(!(b == -1 && a == INT256_MIN)); // This is the only case of overflow require(!(b == -1 && a == INT256_MIN)); // This is the only case of overflow
...@@ -39,8 +39,8 @@ library SignedSafeMath { ...@@ -39,8 +39,8 @@ library SignedSafeMath {
} }
/** /**
* @dev Subtracts two signed integers, reverts on overflow. * @dev Subtracts two signed integers, reverts on overflow.
*/ */
function sub(int256 a, int256 b) internal pure returns (int256) { function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b; int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a)); require((b >= 0 && c <= a) || (b < 0 && c > a));
...@@ -49,8 +49,8 @@ library SignedSafeMath { ...@@ -49,8 +49,8 @@ library SignedSafeMath {
} }
/** /**
* @dev Adds two signed integers, reverts on overflow. * @dev Adds two signed integers, reverts on overflow.
*/ */
function add(int256 a, int256 b) internal pure returns (int256) { function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b; int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a)); require((b >= 0 && c >= a) || (b < 0 && c < a));
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/SafeERC20.sol"; import "../token/ERC20/SafeERC20.sol";
...@@ -14,8 +14,8 @@ import "../math/SafeMath.sol"; ...@@ -14,8 +14,8 @@ import "../math/SafeMath.sol";
contract TokenVesting is Initializable, Ownable { contract TokenVesting is Initializable, Ownable {
// The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is
// therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore,
// it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a cliff // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a
// period of a year and a duration of four years, are safe to use. // cliff period of a year and a duration of four years, are safe to use.
// solhint-disable not-rely-on-time // solhint-disable not-rely-on-time
using SafeMath for uint256; using SafeMath for uint256;
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../crowdsale/validation/CappedCrowdsale.sol"; import "../crowdsale/validation/CappedCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "./IERC165.sol"; import "./IERC165.sol";
...@@ -10,7 +10,7 @@ import "./IERC165.sol"; ...@@ -10,7 +10,7 @@ import "./IERC165.sol";
*/ */
contract ERC165 is Initializable, IERC165 { contract ERC165 is Initializable, IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/** /*
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title ERC165Checker * @title ERC165Checker
* @dev Use `using ERC165Checker for address`; to include this library * @dev Use `using ERC165Checker for address`; to include this library
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md * https://eips.ethereum.org/EIPS/eip-165
*/ */
library ERC165Checker { library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff // As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/** /*
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
...@@ -109,15 +109,15 @@ library ERC165Checker { ...@@ -109,15 +109,15 @@ library ERC165Checker {
mstore(output, 0x0) mstore(output, 0x0)
success := staticcall( success := staticcall(
30000, // 30k gas 30000, // 30k gas
account, // To addr account, // To addr
encodedParams_data, encodedParams_data,
encodedParams_size, encodedParams_size,
output, output,
0x20 // Outputs are 32 bytes long 0x20 // Outputs are 32 bytes long
) )
result := mload(output) // Load the result result := mload(output) // Load the result
} }
} }
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title IERC165 * @title IERC165
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md * @dev https://eips.ethereum.org/EIPS/eip-165
*/ */
interface IERC165 { interface IERC165 {
/** /**
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol"; import "zos-lib/contracts/Initializable.sol";
import "../access/roles/PauserRole.sol"; import "../access/roles/PauserRole.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title Math * @title Math
...@@ -6,24 +6,24 @@ pragma solidity ^0.5.0; ...@@ -6,24 +6,24 @@ pragma solidity ^0.5.0;
*/ */
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);
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
/** /**
* @title SafeMath * @title SafeMath
...@@ -6,8 +6,8 @@ pragma solidity ^0.5.0; ...@@ -6,8 +6,8 @@ pragma solidity ^0.5.0;
*/ */
library SafeMath { library SafeMath {
/** /**
* @dev Multiplies two unsigned integers, reverts on overflow. * @dev Multiplies two unsigned integers, reverts on overflow.
*/ */
function mul(uint256 a, uint256 b) internal pure returns (uint256) { function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested. // benefit is lost if 'b' is also tested.
...@@ -23,8 +23,8 @@ library SafeMath { ...@@ -23,8 +23,8 @@ library SafeMath {
} }
/** /**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. * @dev Integer division of two unsigned integers 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) {
// Solidity only automatically asserts when dividing by 0 // Solidity only automatically asserts when dividing by 0
require(b > 0); require(b > 0);
...@@ -35,8 +35,8 @@ library SafeMath { ...@@ -35,8 +35,8 @@ library SafeMath {
} }
/** /**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). * @dev Subtracts two unsigned integers, 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;
...@@ -45,8 +45,8 @@ library SafeMath { ...@@ -45,8 +45,8 @@ library SafeMath {
} }
/** /**
* @dev Adds two unsigned integers, reverts on overflow. * @dev Adds two unsigned integers, 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);
...@@ -55,9 +55,9 @@ library SafeMath { ...@@ -55,9 +55,9 @@ library SafeMath {
} }
/** /**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), * @dev Divides two unsigned integers 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;
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
contract Acknowledger { contract Acknowledger {
event AcknowledgeFoo(uint256 a); event AcknowledgeFoo(uint256 a);
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../utils/Address.sol"; import "../utils/Address.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/emission/AllowanceCrowdsale.sol"; import "../crowdsale/emission/AllowanceCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../utils/Arrays.sol"; import "../utils/Arrays.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/CappedCrowdsale.sol"; import "../crowdsale/validation/CappedCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../access/roles/CapperRole.sol"; import "../access/roles/CapperRole.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../payment/escrow/ConditionalEscrow.sol"; import "../payment/escrow/ConditionalEscrow.sol";
......
pragma solidity ^0.5.0;
import "../drafts/Counter.sol";
contract CounterImpl {
using Counter for Counter.Counter;
uint256 public theId;
// use whatever key you want to track your counters
mapping(string => Counter.Counter) private _counters;
function doThing(string memory key) public returns (uint256) {
theId = _counters[key].next();
return theId;
}
}
pragma solidity ^0.5.2;
import "../drafts/Counters.sol";
contract CountersImpl {
using Counters for Counters.Counter;
Counters.Counter private _counter;
function current() public view returns (uint256) {
return _counter.current();
}
function increment() public {
_counter.increment();
}
function decrement() public {
_counter.decrement();
}
}
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../crowdsale/Crowdsale.sol"; import "../crowdsale/Crowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../cryptography/ECDSA.sol"; import "../cryptography/ECDSA.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../../introspection/IERC165.sol"; import "../../introspection/IERC165.sol";
/** /**
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-214.md#specification * https://eips.ethereum.org/EIPS/eip-214#specification
* From the specification:
* > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead
* throw an exception. * throw an exception.
* > These operations include [...], LOG0, LOG1, LOG2, [...] * > These operations include [...], LOG0, LOG1, LOG2, [...]
...@@ -13,7 +14,7 @@ import "../../introspection/IERC165.sol"; ...@@ -13,7 +14,7 @@ import "../../introspection/IERC165.sol";
*/ */
contract SupportsInterfaceWithLookupMock is IERC165 { contract SupportsInterfaceWithLookupMock is IERC165 {
bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7; bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
/** /*
* 0x01ffc9a7 === * 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)')) * bytes4(keccak256('supportsInterface(bytes4)'))
*/ */
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
contract ERC165NotSupported { contract ERC165NotSupported {
// solhint-disable-previous-line no-empty-blocks // solhint-disable-previous-line no-empty-blocks
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../introspection/ERC165Checker.sol"; import "../introspection/ERC165Checker.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../introspection/ERC165.sol"; import "../introspection/ERC165.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Burnable.sol"; import "../token/ERC20/ERC20Burnable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
import "../token/ERC20/ERC20Detailed.sol"; import "../token/ERC20/ERC20Detailed.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.0;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/TokenMetadata.sol"; import "../drafts/ERC1046/ERC20Metadata.sol";
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata { contract ERC20MetadataMock is ERC20, ERC20Metadata {
constructor (string memory tokenURI) public { constructor (string memory tokenURI) public {
ERC20WithMetadata.initialize(tokenURI); ERC20Metadata.initialize(tokenURI);
}
function setTokenURI(string memory tokenURI) public {
_setTokenURI(tokenURI);
} }
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Mintable.sol"; import "../token/ERC20/ERC20Mintable.sol";
import "./MinterRoleMock.sol"; import "./MinterRoleMock.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
...@@ -19,4 +19,8 @@ contract ERC20Mock is ERC20 { ...@@ -19,4 +19,8 @@ contract ERC20Mock is ERC20 {
function burnFrom(address account, uint256 amount) public { function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount); _burnFrom(account, amount);
} }
function approveInternal(address owner, address spender, uint256 value) public {
_approve(owner, spender, value);
}
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Pausable.sol"; import "../token/ERC20/ERC20Pausable.sol";
import "./PauserRoleMock.sol"; import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.2;
import "../drafts/ERC20Snapshot.sol";
contract ERC20SnapshotMock is ERC20Snapshot {
constructor(address initialAccount, uint256 initialBalance) public {
_mint(initialAccount, initialBalance);
}
function mint(address account, uint256 amount) public {
_mint(account, amount);
}
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
}
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Full.sol"; import "../token/ERC721/ERC721Full.sol";
import "../token/ERC721/ERC721Mintable.sol"; import "../token/ERC721/ERC721Mintable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Full.sol"; import "../token/ERC721/ERC721Full.sol";
import "../token/ERC721/ERC721Mintable.sol"; import "../token/ERC721/ERC721Mintable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC721/ERC721.sol"; import "../token/ERC721/ERC721.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Pausable.sol"; import "../token/ERC721/ERC721Pausable.sol";
import "./PauserRoleMock.sol"; import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC721/IERC721Receiver.sol"; import "../token/ERC721/IERC721Receiver.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
contract EventEmitter { contract EventEmitter {
event Argumentless(); event Argumentless();
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
contract Failer { contract Failer {
uint256[] private array; uint256[] private array;
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/FinalizableCrowdsale.sol"; import "../crowdsale/distribution/FinalizableCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../crowdsale/price/IncreasingPriceCrowdsale.sol"; import "../crowdsale/price/IncreasingPriceCrowdsale.sol";
import "../math/SafeMath.sol"; import "../math/SafeMath.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol"; import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../math/Math.sol"; import "../math/Math.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import { MerkleProof } from "../cryptography/MerkleProof.sol"; import { MerkleProof } from "../cryptography/MerkleProof.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Mintable.sol"; import "../token/ERC20/ERC20Mintable.sol";
import "../crowdsale/emission/MintedCrowdsale.sol"; import "../crowdsale/emission/MintedCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../access/roles/MinterRole.sol"; import "../access/roles/MinterRole.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../ownership/Ownable.sol"; import "../ownership/Ownable.sol";
/** /**
* @title Ownable interface id calculator. * @title Ownable interface id calculator.
* @dev See the EIP165 specification for more information: * @dev See the EIP165 specification for more information:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md#specification * https://eips.ethereum.org/EIPS/eip-165#specification
*/ */
contract OwnableInterfaceId { contract OwnableInterfaceId {
function getInterfaceId() public pure returns (bytes4) { function getInterfaceId() public pure returns (bytes4) {
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../ownership/Ownable.sol"; import "../ownership/Ownable.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/PausableCrowdsale.sol"; import "../crowdsale/validation/PausableCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../lifecycle/Pausable.sol"; import "../lifecycle/Pausable.sol";
import "./PauserRoleMock.sol"; import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../access/roles/PauserRole.sol"; import "../access/roles/PauserRole.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/PostDeliveryCrowdsale.sol"; import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../payment/PullPayment.sol"; import "../payment/PullPayment.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
contract ReentrancyAttack { contract ReentrancyAttack {
function callSender(bytes4 data) public { function callSender(bytes4 data) public {
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../utils/ReentrancyGuard.sol"; import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol"; import "./ReentrancyAttack.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol"; import "../crowdsale/distribution/RefundableCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/RefundablePostDeliveryCrowdsale.sol"; import "../crowdsale/distribution/RefundablePostDeliveryCrowdsale.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../access/Roles.sol"; import "../access/Roles.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol"; import "../token/ERC20/IERC20.sol";
import "../token/ERC20/SafeERC20.sol"; import "../token/ERC20/SafeERC20.sol";
contract ERC20FailingMock { contract ERC20ReturnFalseMock {
uint256 private _allowance; uint256 private _allowance;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable.
uint256 private _dummy;
function transfer(address, uint256) public returns (bool) { function transfer(address, uint256) public returns (bool) {
_dummy = 0;
return false; return false;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(address, address, uint256) public returns (bool) {
_dummy = 0;
return false; return false;
} }
function approve(address, uint256) public returns (bool) { function approve(address, uint256) public returns (bool) {
_dummy = 0;
return false; return false;
} }
function allowance(address, address) public view returns (uint256) { function allowance(address, address) public view returns (uint256) {
require(_dummy == 0);
return 0; return 0;
} }
} }
contract ERC20SucceedingMock { contract ERC20ReturnTrueMock {
uint256 private _allowance; mapping (address => uint256) private _allowances;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable.
uint256 private _dummy;
function transfer(address, uint256) public returns (bool) { function transfer(address, uint256) public returns (bool) {
_dummy = 0;
return true; return true;
} }
function transferFrom(address, address, uint256) public returns (bool) { function transferFrom(address, address, uint256) public returns (bool) {
_dummy = 0;
return true; return true;
} }
function approve(address, uint256) public returns (bool) { function approve(address, uint256) public returns (bool) {
_dummy = 0;
return true; return true;
} }
function setAllowance(uint256 allowance_) public { function setAllowance(uint256 allowance_) public {
_allowance = allowance_; _allowances[msg.sender] = allowance_;
} }
function allowance(address, address) public view returns (uint256) { function allowance(address owner, address) public view returns (uint256) {
return _allowance; return _allowances[owner];
} }
} }
contract SafeERC20Helper { contract ERC20NoReturnMock {
using SafeERC20 for IERC20; mapping (address => uint256) private _allowances;
IERC20 private _failing; // IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
IERC20 private _succeeding; // we write to a dummy state variable.
uint256 private _dummy;
constructor () public { function transfer(address, uint256) public {
_failing = IERC20(address(new ERC20FailingMock())); _dummy = 0;
_succeeding = IERC20(address(new ERC20SucceedingMock()));
} }
function doFailingTransfer() public { function transferFrom(address, address, uint256) public {
_failing.safeTransfer(address(0), 0); _dummy = 0;
} }
function doFailingTransferFrom() public { function approve(address, uint256) public {
_failing.safeTransferFrom(address(0), address(0), 0); _dummy = 0;
} }
function doFailingApprove() public { function setAllowance(uint256 allowance_) public {
_failing.safeApprove(address(0), 0); _allowances[msg.sender] = allowance_;
} }
function doFailingIncreaseAllowance() public { function allowance(address owner, address) public view returns (uint256) {
_failing.safeIncreaseAllowance(address(0), 0); return _allowances[owner];
} }
}
contract SafeERC20Wrapper {
using SafeERC20 for IERC20;
IERC20 private _token;
function doFailingDecreaseAllowance() public { constructor (IERC20 token) public {
_failing.safeDecreaseAllowance(address(0), 0); _token = token;
} }
function doSucceedingTransfer() public { function transfer() public {
_succeeding.safeTransfer(address(0), 0); _token.safeTransfer(address(0), 0);
} }
function doSucceedingTransferFrom() public { function transferFrom() public {
_succeeding.safeTransferFrom(address(0), address(0), 0); _token.safeTransferFrom(address(0), address(0), 0);
} }
function doSucceedingApprove(uint256 amount) public { function approve(uint256 amount) public {
_succeeding.safeApprove(address(0), amount); _token.safeApprove(address(0), amount);
} }
function doSucceedingIncreaseAllowance(uint256 amount) public { function increaseAllowance(uint256 amount) public {
_succeeding.safeIncreaseAllowance(address(0), amount); _token.safeIncreaseAllowance(address(0), amount);
} }
function doSucceedingDecreaseAllowance(uint256 amount) public { function decreaseAllowance(uint256 amount) public {
_succeeding.safeDecreaseAllowance(address(0), amount); _token.safeDecreaseAllowance(address(0), amount);
} }
function setAllowance(uint256 allowance_) public { function setAllowance(uint256 allowance_) public {
ERC20SucceedingMock(address(_succeeding)).setAllowance(allowance_); ERC20ReturnTrueMock(address(_token)).setAllowance(allowance_);
} }
function allowance() public view returns (uint256) { function allowance() public view returns (uint256) {
return _succeeding.allowance(address(0), address(0)); return _token.allowance(address(0), address(0));
} }
} }
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../math/SafeMath.sol"; import "../math/SafeMath.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../ownership/Secondary.sol"; import "../ownership/Secondary.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../drafts/SignatureBouncer.sol"; import "../drafts/SignatureBouncer.sol";
import "./SignerRoleMock.sol"; import "./SignerRoleMock.sol";
......
pragma solidity ^0.5.0; pragma solidity ^0.5.2;
import "../drafts/SignedSafeMath.sol"; import "../drafts/SignedSafeMath.sol";
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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