Compare commits
187 Commits
v2.4.0
...
v3.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
| a3c6e5f088 | |||
| a8d6f13c94 | |||
| e7b22483af | |||
| 90058040f0 | |||
| 63c89c772b | |||
| 9975a1a0c2 | |||
| eb34ae67ff | |||
| f1db30955d | |||
| c173392e15 | |||
| c9630526e2 | |||
| 8176a901a9 | |||
| baaadde3c5 | |||
| 68ad1ed18f | |||
| d14007d035 | |||
| a949d4e2bf | |||
| ed2c289c2c | |||
| 7acd60d152 | |||
| 0449062126 | |||
| 65e4ffde58 | |||
| e2813df879 | |||
| ca19cea05e | |||
| 3296ca7219 | |||
| cb458f3250 | |||
| 21d2b90d74 | |||
| ab19138f1f | |||
| 970122a9d5 | |||
| 62065cf043 | |||
| 03b61e074e | |||
| 1350f49939 | |||
| 1c22c79a32 | |||
| 08cea10aa7 | |||
| 82147dc2ee | |||
| e4d2830f1d | |||
| 19417c7cd5 | |||
| 5dfe7215a9 | |||
| 04a1b21874 | |||
| f905a14f5f | |||
| 4a531fe588 | |||
| 25dec297bf | |||
| 8e58cda8c3 | |||
| e7bded655b | |||
| 5f357d85de | |||
| 58a3368215 | |||
| 941d305044 | |||
| 1b938e39a8 | |||
| 7988c044e0 | |||
| 0ac83ce289 | |||
| 8975289c6b | |||
| 6102ddf675 | |||
| 5a67a69f80 | |||
| f2512a4f7b | |||
| 06be0ab39a | |||
| d775e315cc | |||
| e4a8a5533e | |||
| 88dc1ca6fc | |||
| 1e0f07751e | |||
| 73abd54cbe | |||
| 7d7cbcad14 | |||
| e493fb3e95 | |||
| 8c40a5b275 | |||
| d6698c3bfb | |||
| b1e811430a | |||
| 06983a2075 | |||
| d037217769 | |||
| 410e4f8ab9 | |||
| 54d2aec232 | |||
| d006a750ee | |||
| 5376e5d349 | |||
| e5805c4979 | |||
| 73cbd6a38b | |||
| 7014d94108 | |||
| 62651e8147 | |||
| f9650b4cb8 | |||
| 249b5e9a4b | |||
| 67a71519d3 | |||
| ccdeca65a1 | |||
| fbddf5ba5b | |||
| cf0e71b4ed | |||
| 73a5903789 | |||
| 5d47aa85bc | |||
| 3eaf50005f | |||
| aec642c5ab | |||
| d0d5c2835e | |||
| 2593457503 | |||
| b56e00eb61 | |||
| 0c644cc470 | |||
| 5f92adc2e7 | |||
| ca6a5dc8a2 | |||
| cc0f89e331 | |||
| 28b95ef5be | |||
| 4237eea7d8 | |||
| 95e54173e9 | |||
| 8e980480aa | |||
| 49042f2b1a | |||
| 714f13df7e | |||
| 33047ffddc | |||
| f90700f3f1 | |||
| ab43553f0f | |||
| 9cac50e428 | |||
| bc84ea450c | |||
| 3608fb4ae9 | |||
| aa73460a8d | |||
| a20408a9e0 | |||
| 81b1e48107 | |||
| 207f315231 | |||
| c3f2ed8168 | |||
| f4c5ce3009 | |||
| 5b2de262fd | |||
| 21d19dccb5 | |||
| 19a6590306 | |||
| 8e3563968f | |||
| d839c24e4b | |||
| bddbbe99a7 | |||
| 2d30415373 | |||
| 9113335cb3 | |||
| 76a1d7a3cd | |||
| d6e10ab786 | |||
| eaee98f227 | |||
| 4757f1c1c9 | |||
| c58d5cdfed | |||
| 5c8fa0f0cf | |||
| fcd77a4a37 | |||
| 5702a84429 | |||
| 91992eed0a | |||
| f6f918c64c | |||
| 8d166f3e35 | |||
| aae95db4e0 | |||
| 9e19d90cd9 | |||
| 53f1b11668 | |||
| 3e1519ac1e | |||
| 2c11ed59fa | |||
| bfca6bd379 | |||
| 85a081ff36 | |||
| 566519fd6b | |||
| 8077ae890e | |||
| 13b85c6848 | |||
| eda29e06b2 | |||
| 5d6a040fc3 | |||
| e557a54ce7 | |||
| b62c677420 | |||
| 8836fac06f | |||
| 77ae18f12f | |||
| 285ccecd66 | |||
| 59933b77ce | |||
| 2ec317ac03 | |||
| 3274d9db00 | |||
| c866522833 | |||
| 4edd0ee799 | |||
| 45befe6e95 | |||
| 40647ad04a | |||
| 38502031ae | |||
| 445d8987f3 | |||
| fa1cbc435f | |||
| 111cde942f | |||
| b8ccf8e0f1 | |||
| fba77596ce | |||
| f9a94788fb | |||
| 18473d0100 | |||
| 54182bf31c | |||
| 5ab6b99607 | |||
| b33b906b6e | |||
| 19a41980a1 | |||
| 6f8e672f3f | |||
| 52dc14c368 | |||
| 6148abb1b1 | |||
| a2ffe21aa2 | |||
| c876254457 | |||
| 681db1d330 | |||
| d9accb63fc | |||
| 72ccec4e6c | |||
| 54ee1c7ff5 | |||
| e855ca450a | |||
| 1efa9f6281 | |||
| d864228624 | |||
| 5274b3d84c | |||
| 9c733a7bf8 | |||
| 52c30edab8 | |||
| ba0fd11f52 | |||
| 635a381460 | |||
| 4e527a20a5 | |||
| 92b2e2800a | |||
| 5d183d0efe | |||
| 188a5fd700 | |||
| 2836b066c9 | |||
| d8a25d17aa | |||
| 5ec7204948 | |||
| 1e42749847 |
@ -6,15 +6,7 @@ version: 2
|
||||
aliases:
|
||||
- &defaults
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
|
||||
- &npm_install_if_necessary
|
||||
run:
|
||||
name: Install npm dependencies
|
||||
command: |
|
||||
if [ ! -d node_modules ]; then
|
||||
npm ci
|
||||
fi
|
||||
- image: circleci/node:10
|
||||
|
||||
- &cache_key_node_modules
|
||||
key: v1-node_modules-{{ checksum "package-lock.json" }}
|
||||
@ -26,7 +18,19 @@ jobs:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
<<: *cache_key_node_modules
|
||||
- *npm_install_if_necessary
|
||||
- run:
|
||||
name: Install npm dependencies and prepare
|
||||
command: |
|
||||
if [ ! -d node_modules ]; then
|
||||
npm ci
|
||||
else
|
||||
npm run prepare
|
||||
fi
|
||||
- persist_to_workspace:
|
||||
root: .
|
||||
paths:
|
||||
- node_modules
|
||||
- build
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
@ -36,9 +40,8 @@ jobs:
|
||||
<<: *defaults
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
<<: *cache_key_node_modules
|
||||
- *npm_install_if_necessary
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Linter
|
||||
command: npm run lint
|
||||
@ -46,20 +49,18 @@ jobs:
|
||||
<<: *defaults
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
<<: *cache_key_node_modules
|
||||
- *npm_install_if_necessary
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Unit tests
|
||||
command: npm run test
|
||||
|
||||
coverage:
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
<<: *defaults
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
<<: *cache_key_node_modules
|
||||
- *npm_install_if_necessary
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Unit tests with coverage report
|
||||
command: npm run coverage
|
||||
@ -80,3 +81,4 @@ workflows:
|
||||
- coverage:
|
||||
requires:
|
||||
- dependencies
|
||||
|
||||
|
||||
7
.dependabot/config.yml
Normal file
7
.dependabot/config.yml
Normal file
@ -0,0 +1,7 @@
|
||||
version: 1
|
||||
|
||||
update_configs:
|
||||
- package_manager: "javascript"
|
||||
directory: "/"
|
||||
update_schedule: "weekly"
|
||||
version_requirement_updates: "increase_versions"
|
||||
@ -25,6 +25,7 @@
|
||||
"strict": ["error", "global"],
|
||||
|
||||
// Code style
|
||||
"array-bracket-spacing": ["off"],
|
||||
"camelcase": ["error", {"properties": "always"}],
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-spacing": ["error", {"before": false, "after": true}],
|
||||
@ -54,5 +55,8 @@
|
||||
|
||||
"promise/always-return": "off",
|
||||
"promise/avoid-new": "off",
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
}
|
||||
}
|
||||
|
||||
1
.github/stale.yml
vendored
1
.github/stale.yml
vendored
@ -10,6 +10,7 @@ daysUntilClose: 15
|
||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||
exemptLabels:
|
||||
- on hold
|
||||
- meta
|
||||
|
||||
# Set to true to ignore issues in a project (defaults to false)
|
||||
exemptProjects: false
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -43,8 +43,10 @@ build/
|
||||
|
||||
# docs artifacts
|
||||
docs/modules/api
|
||||
openzeppelin-docs
|
||||
|
||||
# only used to package @openzeppelin/contracts
|
||||
contracts/build/
|
||||
contracts/README.md
|
||||
|
||||
# temporary artifact from solidity-coverage
|
||||
allFiredEvents
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
module.exports = {
|
||||
norpc: true,
|
||||
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage',
|
||||
compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network coverage',
|
||||
testCommand: 'npm test',
|
||||
compileCommand: 'npm run compile',
|
||||
skipFiles: [
|
||||
'lifecycle/Migrations.sol',
|
||||
'mocks'
|
||||
'mocks',
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
{
|
||||
"extends": "solhint:recommended",
|
||||
"rules": {
|
||||
"indent": ["error", 4],
|
||||
"func-order": "off",
|
||||
"bracket-align": "off",
|
||||
"compiler-fixed": "off",
|
||||
"no-simple-event-func-name": "off",
|
||||
"separate-by-one-line-in-contract": "off",
|
||||
"two-lines-top-level-separator": "off",
|
||||
"mark-callable-contracts": "off",
|
||||
"compiler-version": ["error", "^0.5.0"]
|
||||
"no-empty-blocks": "off",
|
||||
"compiler-version": ["error", "^0.6.0"]
|
||||
}
|
||||
}
|
||||
|
||||
98
CHANGELOG.md
98
CHANGELOG.md
@ -1,8 +1,50 @@
|
||||
# Changelog
|
||||
|
||||
## 3.0.0 (unreleased)
|
||||
|
||||
### New features
|
||||
* `AccessControl`: new contract for managing permissions in a system, replacement for `Ownable` and `Roles`. ([#2112](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2112))
|
||||
|
||||
### Breaking changes
|
||||
* `ERC721`: `burn(owner, tokenId)` was removed, use `burn(owner)` instead. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
|
||||
* `ERC721`: `_checkOnERC721Received` was removed. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
|
||||
* `PullPayment`, `Escrow`: `withdrawWithGas` was removed. The old `withdraw` function now forwards all gas. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
|
||||
* `Roles` was removed, use `AccessControl` as a replacement. ([#2112](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2112))
|
||||
* `ECDSA`: when receiving an invalid signature, `recover` now reverts instead of returning the zero address. ([#2114](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2114))
|
||||
* `Pausable`: moved to the `utils` directory. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))
|
||||
* `Strings`: moved to the `utils` directory. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))
|
||||
* `Counters`: moved to the `utils` directory. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))
|
||||
* `SignedSafeMath`: moved to the `math` directory. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))
|
||||
* `ERC20Snapshot`: moved to the `token/ERC20` directory. `snapshot` was changed into an `internal` function. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))
|
||||
* `Ownable`: moved to the `access` directory. ([#2120](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2120))
|
||||
* `Ownable`: removed `isOwner`. ([#2120](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2120))
|
||||
* `Secondary`: removed from the library, use `Ownable` instead. ([#2120](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2120))
|
||||
* `Escrow`, `ConditionalEscrow`, `RefundEscrow`: these now use `Ownable` instead of `Secondary`, their external API changed accordingly. ([#2120](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2120))
|
||||
* `ERC20`: removed `_burnFrom`. ([#2119](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2119))
|
||||
* `Address`: removed `toPayable`, use `payable(address)` instead. ([#2133](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2133))
|
||||
* `ERC777`: `_send`, `_mint` and `_burn` now use the caller as the operator. ([#2134](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2134))
|
||||
* `ERC777`: removed `_callsTokensToSend` and `_callTokensReceived`. ([#2134](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2134))
|
||||
|
||||
## 2.5.0 (2020-02-04)
|
||||
|
||||
### New features
|
||||
* `SafeCast.toUintXX`: new library for integer downcasting, which allows for safe operation on smaller types (e.g. `uint32`) when combined with `SafeMath`. ([#1926](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1926))
|
||||
* `ERC721Metadata`: added `baseURI`, which can be used for dramatic gas savings when all token URIs share a prefix (e.g. `http://api.myapp.com/tokens/<id>`). ([#1970](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1970))
|
||||
* `EnumerableSet`: new library for storing enumerable sets of values. Only `AddressSet` is supported in this release. ([#2061](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/2061))
|
||||
* `Create2`: simple library to make usage of the `CREATE2` opcode easier. ([#1744](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1744))
|
||||
|
||||
### Improvements
|
||||
* `ERC777`: `_burn` is now internal, providing more flexibility and making it easier to create tokens that deflate. ([#1908](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1908))
|
||||
* `ReentrancyGuard`: greatly improved gas efficiency by using the net gas metering mechanism introduced in the Istanbul hardfork. ([#1992](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1992), [#1996](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1996))
|
||||
* `ERC777`: improve extensibility by making `_send` and related functions `internal`. ([#2027](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2027))
|
||||
* `ERC721`: improved revert reason when transferring tokens to a non-recipient contract. ([#2018](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2018))
|
||||
|
||||
### Breaking changes
|
||||
* `ERC165Checker` now requires a minimum Solidity compiler version of 0.5.10. ([#1829](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1829))
|
||||
|
||||
## 2.4.0 (2019-10-29)
|
||||
|
||||
### New features:
|
||||
### New features
|
||||
* `Address.toPayable`: added a helper to convert between address types without having to resort to low-level casting. ([#1773](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1773))
|
||||
* Facilities to make metatransaction-enabled contracts through the Gas Station Network. ([#1844](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1844))
|
||||
* `Address.sendValue`: added a replacement to Solidity's `transfer`, removing the fixed gas stipend. ([#1962](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1962))
|
||||
@ -11,52 +53,76 @@
|
||||
* `Escrow.withdrawWithGas(address payable payee)`
|
||||
* `SafeMath`: added support for custom error messages to `sub`, `div` and `mod` functions. ([#1828](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1828))
|
||||
|
||||
### Improvements:
|
||||
### Improvements
|
||||
* `Address.isContract`: switched from `extcodesize` to `extcodehash` for less gas usage. ([#1802](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1802))
|
||||
* `ERC20` and `ERC777` updated to throw custom errors on subtraction overflows. ([#1828](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1828))
|
||||
|
||||
### Deprecations:
|
||||
### Deprecations
|
||||
* Deprecated functions that don't forward all gas: ([#1976](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1976))
|
||||
* `PullPayment.withdrawPayments(address payable payee)`
|
||||
* `Escrow.withdraw(address payable payee)`
|
||||
|
||||
### Breaking changes:
|
||||
### Breaking changes
|
||||
* `Address` now requires a minimum Solidity compiler version of 0.5.5. ([#1802](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1802))
|
||||
* `SignatureBouncer` has been removed from drafts, both to avoid confusions with the GSN and `GSNRecipientSignature` (previously called `GSNBouncerSignature`) and because the API was not very clear. ([#1879](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1879))
|
||||
|
||||
### How to upgrade from 2.4.0-beta
|
||||
|
||||
The final 2.4.0 release includes a refactor of the GSN contracts that will be a breaking change for 2.4.0-beta users.
|
||||
|
||||
* The default empty implementations of `_preRelayedCall` and `_postRelayedCall` were removed and must now be explicitly implemented always in custom recipients. If your custom recipient didn't include an implementation, you can provide an empty one.
|
||||
* `GSNRecipient`, `GSNBouncerBase`, and `GSNContext` were all merged into `GSNRecipient`.
|
||||
* `GSNBouncerSignature` and `GSNBouncerERC20Fee` were renamed to `GSNRecipientSignature` and `GSNRecipientERC20Fee`.
|
||||
* It is no longer necessary to inherit from `GSNRecipient` when using `GSNRecipientSignature` and `GSNRecipientERC20Fee`.
|
||||
|
||||
For example, a contract using `GSNBouncerSignature` would have to be changed in the following way.
|
||||
|
||||
```diff
|
||||
-contract MyDapp is GSNRecipient, GSNBouncerSignature {
|
||||
+contract MyDapp is GSNRecipientSignature {
|
||||
```
|
||||
|
||||
Refer to the table below to adjust your inheritance list.
|
||||
|
||||
| 2.4.0-beta | 2.4.0 |
|
||||
| ---------------------------------- | ---------------------------- |
|
||||
| `GSNRecipient, GSNBouncerSignature`| `GSNRecipientSignature` |
|
||||
| `GSNRecipient, GSNBouncerERC20Fee` | `GSNRecipientERC20Fee` |
|
||||
| `GSNBouncerBase` | `GSNRecipient` |
|
||||
|
||||
## 2.3.0 (2019-05-27)
|
||||
|
||||
### New features:
|
||||
### New features
|
||||
* `ERC1820`: added support for interacting with the [ERC1820](https://eips.ethereum.org/EIPS/eip-1820) registry contract (`IERC1820Registry`), as well as base contracts that can be registered as implementers there. ([#1677](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1677))
|
||||
* `ERC777`: support for the [ERC777 token](https://eips.ethereum.org/EIPS/eip-777), which has multiple improvements over `ERC20` (but is backwards compatible with it) such as built-in burning, a more straightforward permission system, and optional sender and receiver hooks on transfer (mandatory for contracts!). ([#1684](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1684))
|
||||
* All contracts now have revert reason strings, which give insight into error conditions, and help debug failing transactions. ([#1704](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1704))
|
||||
|
||||
### Improvements:
|
||||
### Improvements
|
||||
* Reverted the Solidity version bump done in v2.2.0, setting the minimum compiler version to v0.5.0, to prevent unexpected build breakage. Users are encouraged however to stay on top of new compiler releases, which usually include bugfixes. ([#1729](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1729))
|
||||
|
||||
### Bugfixes:
|
||||
### Bugfixes
|
||||
* `PostDeliveryCrowdsale`: some validations where skipped when paired with other crowdsale flavors, such as `AllowanceCrowdsale`, or `MintableCrowdsale` and `ERC20Capped`, which could cause buyers to not be able to claim their purchased tokens. ([#1721](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1721))
|
||||
* `ERC20._transfer`: the `from` argument was allowed to be the zero address, so it was possible to internally trigger a transfer of 0 tokens from the zero address. This address is not a valid destinatary of transfers, nor can it give or receive allowance, so this behavior was inconsistent. It now reverts. ([#1752](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1752))
|
||||
|
||||
## 2.2.0 (2019-03-14)
|
||||
|
||||
### New features:
|
||||
### 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/1655))
|
||||
* `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:
|
||||
### 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))
|
||||
* Fixed variable shadowing issues. ([#1606](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1606))
|
||||
|
||||
### Bugfixes:
|
||||
### 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 in drafts:
|
||||
### Breaking changes in drafts
|
||||
* `TokenMetadata` has been renamed to `ERC20Metadata`. ([#1618](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1618))
|
||||
* The library `Counter` has been renamed to `Counters` and its API has been improved. See an example in `ERC721`, lines [17](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/3cb4a00fce1da76196ac0ac3a0ae9702b99642b5/contracts/token/ERC721/ERC721.sol#L17) and [204](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/3cb4a00fce1da76196ac0ac3a0ae9702b99642b5/contracts/token/ERC721/ERC721.sol#L204). ([#1610](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1610))
|
||||
|
||||
@ -71,7 +137,7 @@
|
||||
|
||||
## 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.
|
||||
* `WhitelistCrowdsale`: a crowdsale where only whitelisted accounts (`WhitelistedRole`) can purchase tokens. Adding or removing accounts from the whitelist is done by whitelist admins (`WhitelistAdminRole`). Similar to the pre-2.0 `WhitelistedCrowdsale`. ([#1525](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1525), [#1589](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1589))
|
||||
* `RefundablePostDeliveryCrowdsale`: replacement for `RefundableCrowdsale` (deprecated, see below) where tokens are only granted once the crowdsale ends (if it meets its goal). ([#1543](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1543))
|
||||
@ -82,17 +148,17 @@
|
||||
* Crowdsales: all constructors are now `public`, meaning it is not necessary to extend these contracts in order to deploy them. The exception is `FinalizableCrowdsale`, since it is meaningless unless extended. ([#1564](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1564))
|
||||
* `SignedSafeMath`: added overflow-safe operations for signed integers (`int256`). ([#1559](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1559), [#1588](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1588))
|
||||
|
||||
### Improvements:
|
||||
### Improvements
|
||||
* The compiler version required by `Array` was behind the rest of the libray so it was updated to `v0.4.24`. ([#1553](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1553))
|
||||
* Now conforming to a 4-space indentation code style. ([1508](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1508))
|
||||
* `ERC20`: more gas efficient due to removed redundant `require`s. ([#1409](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1409))
|
||||
* `ERC721`: fixed a bug that prevented internal data structures from being properly cleaned, missing potential gas refunds. ([#1539](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1539) and [#1549](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1549))
|
||||
* `ERC721`: general gas savings on `transferFrom`, `_mint` and `_burn`, due to redudant `require`s and `SSTORE`s. ([#1549](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1549))
|
||||
|
||||
### Bugfixes:
|
||||
### Bugfixes
|
||||
|
||||
### Breaking changes:
|
||||
### Breaking changes
|
||||
|
||||
### Deprecations:
|
||||
### Deprecations
|
||||
* `ERC721._burn(address owner, uint256 tokenId)`: due to the `owner` parameter being unnecessary. ([#1550](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1550))
|
||||
* `RefundableCrowdsale`: due to trading abuse potential on crowdsales that miss their goal. ([#1543](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1543))
|
||||
|
||||
62
README.md
62
README.md
@ -4,19 +4,27 @@
|
||||
[](https://circleci.com/gh/OpenZeppelin/openzeppelin-contracts)
|
||||
[](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts)
|
||||
|
||||
**OpenZeppelin Contracts is a library for secure smart contract development.** It provides implementations of standards like ERC20 and ERC721 which you can deploy as-is or extend to suit your needs, as well as Solidity components to build custom contracts and more complex decentralized systems.
|
||||
**A library for secure smart contract development.** Build on a solid foundation of community-vetted code.
|
||||
|
||||
## Install
|
||||
* Implementations of standards like [ERC20](https://docs.openzeppelin.com/contracts/erc20) and [ERC721](https://docs.openzeppelin.com/contracts/erc721).
|
||||
* Flexible [role-based permissioning](https://docs.openzeppelin.com/contracts/access-control) scheme.
|
||||
* Reusable [Solidity components](https://docs.openzeppelin.com/contracts/utilities) to build custom contracts and complex decentralized systems.
|
||||
* First-class integration with the [Gas Station Network](https://docs.openzeppelin.com/contracts/gsn) for systems with no gas fees!
|
||||
* Audited by leading security firms.
|
||||
|
||||
```
|
||||
npm install @openzeppelin/contracts
|
||||
## Overview
|
||||
|
||||
### Installation
|
||||
|
||||
```console
|
||||
$ npm install @openzeppelin/contracts
|
||||
```
|
||||
|
||||
OpenZeppelin Contracts features a stable API, which means your contracts won't break unexpectedly when upgrading to a newer minor version. You can read ṫhe details in our [API Stability] document.
|
||||
OpenZeppelin Contracts features a [stable API](https://docs.openzeppelin.com/contracts/releases-stability#api-stability), which means your contracts won't break unexpectedly when upgrading to a newer minor version.
|
||||
|
||||
## Usage
|
||||
### Usage
|
||||
|
||||
To write your custom contracts, import ours and extend them through inheritance.
|
||||
Once installed, you can use the contracts in the library by importing them:
|
||||
|
||||
```solidity
|
||||
pragma solidity ^0.5.0;
|
||||
@ -25,18 +33,35 @@ import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721Mintable.sol";
|
||||
|
||||
contract MyNFT is ERC721Full, ERC721Mintable {
|
||||
constructor() ERC721Full("MyNFT", "MNFT") public {
|
||||
}
|
||||
constructor() ERC721Full("MyNFT", "MNFT") public {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> You need an ethereum development framework for the above import statements to work! Check out these guides for [Truffle], [Embark] or [Buidler].
|
||||
_If you're new to smart contract development, head to [Developing Smart Contracts](https://docs.openzeppelin.com/learn/developing-smart-contracts) to learn about creating a new project and compiling your contracts._
|
||||
|
||||
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 forum][forum].
|
||||
To keep your system secure, you should **always** use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.
|
||||
|
||||
## Learn More
|
||||
|
||||
The guides in the sidebar will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:
|
||||
|
||||
* [Access Control](https://docs.openzeppelin.com/contracts/access-control): decide who can perform each of the actions on your system.
|
||||
* [Tokens](https://docs.openzeppelin.com/contracts/tokens): create tradeable assets or collectives, and distribute them via [Crowdsales](https://docs.openzeppelin.com/contracts/crowdsales).
|
||||
* [Gas Station Network](https://docs.openzeppelin.com/contracts/gsn): let your users interact with your contracts without having to pay for gas themselves.
|
||||
* [Utilities](https://docs.openzeppelin.com/contracts/utilities): generic useful tools, including non-overflowing math, signature verification, and trustless paying systems.
|
||||
|
||||
The [full API](https://docs.openzeppelin.com/contracts/api/token/ERC20) is also thoroughly documented, and serves as a great reference when developing your smart contract application. You can also ask for help or follow Contracts's development in the [community forum](https://forum.openzeppelin.com).
|
||||
|
||||
Finally, you may want to take a look at the [guides on our blog](https://blog.openzeppelin.com/guides), which cover several common use cases and good practices.. The following articles provide great background reading, though please note, some of the referenced tools have changed as the tooling in the ecosystem continues to rapidly evolve.
|
||||
|
||||
* [The Hitchhiker’s Guide to Smart Contracts in Ethereum](https://blog.openzeppelin.com/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05) will help you get an overview of the various tools available for smart contract development, and help you set up your environment.
|
||||
* [A Gentle Introduction to Ethereum Programming, Part 1](https://blog.openzeppelin.com/a-gentle-introduction-to-ethereum-programming-part-1-783cc7796094) provides very useful information on an introductory level, including many basic concepts from the Ethereum platform.
|
||||
* For a more in-depth dive, you may read the guide [Designing the Architecture for Your Ethereum Application](https://blog.openzeppelin.com/designing-the-architecture-for-your-ethereum-application-9cec086f8317), which discusses how to better structure your application and its relationship to the real world.
|
||||
|
||||
## Security
|
||||
|
||||
This project is maintained by [OpenZeppelin], 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.
|
||||
This project is maintained by [OpenZeppelin](https://openzeppelin.com), 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.
|
||||
|
||||
@ -46,19 +71,8 @@ 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]!
|
||||
OpenZeppelin exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guide](CONTRIBUTING.md)!
|
||||
|
||||
## License
|
||||
|
||||
OpenZeppelin is released under the [MIT License](LICENSE).
|
||||
|
||||
|
||||
[API docs]: https://docs.openzeppelin.com/contracts/api/token/erc20
|
||||
[guides]: https://docs.openzeppelin.com/contracts
|
||||
[API Stability]: https://docs.openzeppelin.com/contracts/api-stability
|
||||
[forum]: https://forum.openzeppelin.com
|
||||
[OpenZeppelin]: https://openzeppelin.com
|
||||
[contribution guide]: CONTRIBUTING.md
|
||||
[Truffle]: https://truffleframework.com/docs/truffle/quickstart
|
||||
[Embark]: https://embark.status.im/docs/quick_start.html
|
||||
[Buidler]: https://buidler.dev/getting-started/#overview
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/*
|
||||
* @dev Provides information about the current execution context, including the
|
||||
@ -14,13 +14,12 @@ contract Context {
|
||||
// Empty internal constructor, to prevent people from mistakenly deploying
|
||||
// an instance of this contract, which should be used via inheritance.
|
||||
constructor () internal { }
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
|
||||
function _msgSender() internal view returns (address payable) {
|
||||
function _msgSender() internal view virtual returns (address payable) {
|
||||
return msg.sender;
|
||||
}
|
||||
|
||||
function _msgData() internal view returns (bytes memory) {
|
||||
function _msgData() internal view virtual returns (bytes memory) {
|
||||
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
|
||||
return msg.data;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./IRelayRecipient.sol";
|
||||
import "./IRelayHub.sol";
|
||||
@ -8,14 +8,14 @@ import "./Context.sol";
|
||||
* @dev Base GSN recipient contract: includes the {IRelayRecipient} interface
|
||||
* and enables GSN support on all contracts in the inheritance tree.
|
||||
*
|
||||
* TIP: This contract is abstract. The functions {acceptRelayedCall},
|
||||
* TIP: This contract is abstract. The functions {IRelayRecipient-acceptRelayedCall},
|
||||
* {_preRelayedCall}, and {_postRelayedCall} are not implemented and must be
|
||||
* provided by derived contracts. See the
|
||||
* xref:ROOT:gsn-strategies.adoc#gsn-strategies[GSN strategies] for more
|
||||
* information on how to use the pre-built {GSNRecipientSignature} and
|
||||
* {GSNRecipientERC20Fee}, or how to write your own.
|
||||
*/
|
||||
contract GSNRecipient is IRelayRecipient, Context {
|
||||
abstract contract GSNRecipient is IRelayRecipient, Context {
|
||||
// Default RelayHub address, deployed on mainnet and all testnets at the same address
|
||||
address private _relayHub = 0xD216153c06E857cD7f72665E0aF1d7D82172F494;
|
||||
|
||||
@ -33,7 +33,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
/**
|
||||
* @dev Returns the address of the {IRelayHub} contract for this recipient.
|
||||
*/
|
||||
function getHubAddr() public view returns (address) {
|
||||
function getHubAddr() public view override returns (address) {
|
||||
return _relayHub;
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
* IMPORTANT: After upgrading, the {GSNRecipient} will no longer be able to receive relayed calls from the old
|
||||
* {IRelayHub} instance. Additionally, all funds should be previously withdrawn via {_withdrawDeposits}.
|
||||
*/
|
||||
function _upgradeRelayHub(address newRelayHub) internal {
|
||||
function _upgradeRelayHub(address newRelayHub) internal virtual {
|
||||
address currentRelayHub = _relayHub;
|
||||
require(newRelayHub != address(0), "GSNRecipient: new RelayHub is the zero address");
|
||||
require(newRelayHub != currentRelayHub, "GSNRecipient: new RelayHub is the current one");
|
||||
@ -70,7 +70,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
*
|
||||
* Derived contracts should expose this in an external interface with proper access control.
|
||||
*/
|
||||
function _withdrawDeposits(uint256 amount, address payable payee) internal {
|
||||
function _withdrawDeposits(uint256 amount, address payable payee) internal virtual {
|
||||
IRelayHub(_relayHub).withdraw(amount, payee);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
*
|
||||
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.sender`, and use {_msgSender} instead.
|
||||
*/
|
||||
function _msgSender() internal view returns (address payable) {
|
||||
function _msgSender() internal view virtual override returns (address payable) {
|
||||
if (msg.sender != _relayHub) {
|
||||
return msg.sender;
|
||||
} else {
|
||||
@ -99,7 +99,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
*
|
||||
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.data`, and use {_msgData} instead.
|
||||
*/
|
||||
function _msgData() internal view returns (bytes memory) {
|
||||
function _msgData() internal view virtual override returns (bytes memory) {
|
||||
if (msg.sender != _relayHub) {
|
||||
return msg.data;
|
||||
} else {
|
||||
@ -119,7 +119,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
*
|
||||
* - the caller must be the `RelayHub` contract.
|
||||
*/
|
||||
function preRelayedCall(bytes calldata context) external returns (bytes32) {
|
||||
function preRelayedCall(bytes calldata context) external virtual override returns (bytes32) {
|
||||
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
|
||||
return _preRelayedCall(context);
|
||||
}
|
||||
@ -131,7 +131,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
* must implement this function with any relayed-call preprocessing they may wish to do.
|
||||
*
|
||||
*/
|
||||
function _preRelayedCall(bytes memory context) internal returns (bytes32);
|
||||
function _preRelayedCall(bytes memory context) internal virtual returns (bytes32);
|
||||
|
||||
/**
|
||||
* @dev See `IRelayRecipient.postRelayedCall`.
|
||||
@ -142,7 +142,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
*
|
||||
* - the caller must be the `RelayHub` contract.
|
||||
*/
|
||||
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external {
|
||||
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external virtual override {
|
||||
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
|
||||
_postRelayedCall(context, success, actualCharge, preRetVal);
|
||||
}
|
||||
@ -154,7 +154,7 @@ contract GSNRecipient is IRelayRecipient, Context {
|
||||
* must implement this function with any relayed-call postprocessing they may wish to do.
|
||||
*
|
||||
*/
|
||||
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal;
|
||||
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal virtual;
|
||||
|
||||
/**
|
||||
* @dev Return this in acceptRelayedCall to proceed with the execution of a relayed call. Note that this contract
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./GSNRecipient.sol";
|
||||
import "../math/SafeMath.sol";
|
||||
import "../ownership/Secondary.sol";
|
||||
import "../access/Ownable.sol";
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../token/ERC20/ERC20Detailed.sol";
|
||||
@ -17,20 +17,20 @@ import "../token/ERC20/ERC20Detailed.sol";
|
||||
* internal {_mint} function.
|
||||
*/
|
||||
contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
using SafeERC20 for __unstable__ERC20PrimaryAdmin;
|
||||
using SafeERC20 for __unstable__ERC20Owned;
|
||||
using SafeMath for uint256;
|
||||
|
||||
enum GSNRecipientERC20FeeErrorCodes {
|
||||
INSUFFICIENT_BALANCE
|
||||
}
|
||||
|
||||
__unstable__ERC20PrimaryAdmin private _token;
|
||||
__unstable__ERC20Owned private _token;
|
||||
|
||||
/**
|
||||
* @dev The arguments to the constructor are the details that the gas payment token will have: `name` and `symbol`. `decimals` is hard-coded to 18.
|
||||
*/
|
||||
constructor(string memory name, string memory symbol) public {
|
||||
_token = new __unstable__ERC20PrimaryAdmin(name, symbol, 18);
|
||||
_token = new __unstable__ERC20Owned(name, symbol, 18);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
/**
|
||||
* @dev Internal function that mints the gas payment token. Derived contracts should expose this function in their public API, with proper access control mechanisms.
|
||||
*/
|
||||
function _mint(address account, uint256 amount) internal {
|
||||
function _mint(address account, uint256 amount) internal virtual {
|
||||
_token.mint(account, amount);
|
||||
}
|
||||
|
||||
@ -63,6 +63,8 @@ contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
)
|
||||
external
|
||||
view
|
||||
virtual
|
||||
override
|
||||
returns (uint256, bytes memory)
|
||||
{
|
||||
if (_token.balanceOf(from) < maxPossibleCharge) {
|
||||
@ -78,7 +80,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
* actual charge, necessary because we cannot predict how much gas the execution will actually need. The remainder
|
||||
* is returned to the user in {_postRelayedCall}.
|
||||
*/
|
||||
function _preRelayedCall(bytes memory context) internal returns (bytes32) {
|
||||
function _preRelayedCall(bytes memory context) internal virtual override returns (bytes32) {
|
||||
(address from, uint256 maxPossibleCharge) = abi.decode(context, (address, uint256));
|
||||
|
||||
// The maximum token charge is pre-charged from the user
|
||||
@ -88,7 +90,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
/**
|
||||
* @dev Returns to the user the extra amount that was previously charged, once the actual execution cost is known.
|
||||
*/
|
||||
function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
|
||||
function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal virtual override {
|
||||
(address from, uint256 maxPossibleCharge, uint256 transactionFee, uint256 gasPrice) =
|
||||
abi.decode(context, (address, uint256, uint256, uint256));
|
||||
|
||||
@ -104,44 +106,42 @@ contract GSNRecipientERC20Fee is GSNRecipient {
|
||||
}
|
||||
|
||||
/**
|
||||
* @title __unstable__ERC20PrimaryAdmin
|
||||
* @title __unstable__ERC20Owned
|
||||
* @dev An ERC20 token owned by another contract, which has minting permissions and can use transferFrom to receive
|
||||
* anyone's tokens. This contract is an internal helper for GSNRecipientERC20Fee, and should not be used
|
||||
* outside of this context.
|
||||
*/
|
||||
// solhint-disable-next-line contract-name-camelcase
|
||||
contract __unstable__ERC20PrimaryAdmin is ERC20, ERC20Detailed, Secondary {
|
||||
contract __unstable__ERC20Owned is ERC20, ERC20Detailed, Ownable {
|
||||
uint256 private constant UINT256_MAX = 2**256 - 1;
|
||||
|
||||
constructor(string memory name, string memory symbol, uint8 decimals) public ERC20Detailed(name, symbol, decimals) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
constructor(string memory name, string memory symbol, uint8 decimals) public ERC20Detailed(name, symbol, decimals) { }
|
||||
|
||||
// The primary account (GSNRecipientERC20Fee) can mint tokens
|
||||
function mint(address account, uint256 amount) public onlyPrimary {
|
||||
// The owner (GSNRecipientERC20Fee) can mint tokens
|
||||
function mint(address account, uint256 amount) public onlyOwner {
|
||||
_mint(account, amount);
|
||||
}
|
||||
|
||||
// The primary account has 'infinite' allowance for all token holders
|
||||
function allowance(address owner, address spender) public view returns (uint256) {
|
||||
if (spender == primary()) {
|
||||
// The owner has 'infinite' allowance for all token holders
|
||||
function allowance(address tokenOwner, address spender) public view override(ERC20, IERC20) returns (uint256) {
|
||||
if (spender == owner()) {
|
||||
return UINT256_MAX;
|
||||
} else {
|
||||
return super.allowance(owner, spender);
|
||||
return super.allowance(tokenOwner, spender);
|
||||
}
|
||||
}
|
||||
|
||||
// Allowance for the primary account cannot be changed (it is always 'infinite')
|
||||
function _approve(address owner, address spender, uint256 value) internal {
|
||||
if (spender == primary()) {
|
||||
// Allowance for the owner cannot be changed (it is always 'infinite')
|
||||
function _approve(address tokenOwner, address spender, uint256 value) internal override {
|
||||
if (spender == owner()) {
|
||||
return;
|
||||
} else {
|
||||
super._approve(owner, spender, value);
|
||||
super._approve(tokenOwner, spender, value);
|
||||
}
|
||||
}
|
||||
|
||||
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
|
||||
if (recipient == primary()) {
|
||||
function transferFrom(address sender, address recipient, uint256 amount) public override(ERC20, IERC20) returns (bool) {
|
||||
if (recipient == owner()) {
|
||||
_transfer(sender, recipient, amount);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./GSNRecipient.sol";
|
||||
import "../cryptography/ECDSA.sol";
|
||||
@ -42,6 +42,8 @@ contract GSNRecipientSignature is GSNRecipient {
|
||||
)
|
||||
external
|
||||
view
|
||||
virtual
|
||||
override
|
||||
returns (uint256, bytes memory)
|
||||
{
|
||||
bytes memory blob = abi.encodePacked(
|
||||
@ -62,11 +64,7 @@ contract GSNRecipientSignature is GSNRecipient {
|
||||
}
|
||||
}
|
||||
|
||||
function _preRelayedCall(bytes memory) internal returns (bytes32) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
function _preRelayedCall(bytes memory) internal virtual override returns (bytes32) { }
|
||||
|
||||
function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal virtual override { }
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Interface for `RelayHub`, the core contract of the GSN. Users should not need to interact with this contract
|
||||
@ -7,7 +7,7 @@ pragma solidity ^0.5.0;
|
||||
* See the https://github.com/OpenZeppelin/openzeppelin-gsn-helpers[OpenZeppelin GSN helpers] for more information on
|
||||
* how to deploy an instance of `RelayHub` on your local test network.
|
||||
*/
|
||||
contract IRelayHub {
|
||||
interface IRelayHub {
|
||||
// Relay management
|
||||
|
||||
/**
|
||||
@ -36,7 +36,7 @@ contract IRelayHub {
|
||||
*
|
||||
* Emits a {RelayAdded} event.
|
||||
*/
|
||||
function registerRelay(uint256 transactionFee, string memory url) public;
|
||||
function registerRelay(uint256 transactionFee, string calldata url) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when a relay is registered or re-registerd. Looking at these events (and filtering out
|
||||
@ -52,7 +52,7 @@ contract IRelayHub {
|
||||
*
|
||||
* Emits a {RelayRemoved} event.
|
||||
*/
|
||||
function removeRelayByOwner(address relay) public;
|
||||
function removeRelayByOwner(address relay) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when a relay is removed (deregistered). `unstakeTime` is the time when unstake will be callable.
|
||||
@ -65,7 +65,7 @@ contract IRelayHub {
|
||||
*
|
||||
* Emits an {Unstaked} event.
|
||||
*/
|
||||
function unstake(address relay) public;
|
||||
function unstake(address relay) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when a relay is unstaked for, including the returned stake.
|
||||
@ -95,7 +95,7 @@ contract IRelayHub {
|
||||
*
|
||||
* Emits a {Deposited} event.
|
||||
*/
|
||||
function depositFor(address target) public payable;
|
||||
function depositFor(address target) external payable;
|
||||
|
||||
/**
|
||||
* @dev Emitted when {depositFor} is called, including the amount and account that was funded.
|
||||
@ -113,7 +113,7 @@ contract IRelayHub {
|
||||
*
|
||||
* Emits a {Withdrawn} event.
|
||||
*/
|
||||
function withdraw(uint256 amount, address payable dest) public;
|
||||
function withdraw(uint256 amount, address payable dest) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when an account withdraws funds from `RelayHub`.
|
||||
@ -136,14 +136,14 @@ contract IRelayHub {
|
||||
address relay,
|
||||
address from,
|
||||
address to,
|
||||
bytes memory encodedFunction,
|
||||
bytes calldata encodedFunction,
|
||||
uint256 transactionFee,
|
||||
uint256 gasPrice,
|
||||
uint256 gasLimit,
|
||||
uint256 nonce,
|
||||
bytes memory signature,
|
||||
bytes memory approvalData
|
||||
) public view returns (uint256 status, bytes memory recipientContext);
|
||||
bytes calldata signature,
|
||||
bytes calldata approvalData
|
||||
) external view returns (uint256 status, bytes memory recipientContext);
|
||||
|
||||
// Preconditions for relaying, checked by canRelay and returned as the corresponding numeric values.
|
||||
enum PreconditionCheck {
|
||||
@ -186,14 +186,14 @@ contract IRelayHub {
|
||||
function relayCall(
|
||||
address from,
|
||||
address to,
|
||||
bytes memory encodedFunction,
|
||||
bytes calldata encodedFunction,
|
||||
uint256 transactionFee,
|
||||
uint256 gasPrice,
|
||||
uint256 gasLimit,
|
||||
uint256 nonce,
|
||||
bytes memory signature,
|
||||
bytes memory approvalData
|
||||
) public;
|
||||
bytes calldata signature,
|
||||
bytes calldata approvalData
|
||||
) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when an attempt to relay a call failed.
|
||||
@ -207,7 +207,7 @@ contract IRelayHub {
|
||||
event CanRelayFailed(address indexed relay, address indexed from, address indexed to, bytes4 selector, uint256 reason);
|
||||
|
||||
/**
|
||||
* @dev Emitted when a transaction is relayed.
|
||||
* @dev Emitted when a transaction is relayed.
|
||||
* Useful when monitoring a relay's operation and relayed calls to a contract
|
||||
*
|
||||
* Note that the actual encoded function might be reverted: this is indicated in the `status` parameter.
|
||||
@ -229,14 +229,14 @@ contract IRelayHub {
|
||||
* @dev Returns how much gas should be forwarded to a call to {relayCall}, in order to relay a transaction that will
|
||||
* spend up to `relayedCallStipend` gas.
|
||||
*/
|
||||
function requiredGas(uint256 relayedCallStipend) public view returns (uint256);
|
||||
function requiredGas(uint256 relayedCallStipend) external view returns (uint256);
|
||||
|
||||
/**
|
||||
* @dev Returns the maximum recipient charge, given the amount of gas forwarded, gas price and relay fee.
|
||||
*/
|
||||
function maxPossibleCharge(uint256 relayedCallStipend, uint256 gasPrice, uint256 transactionFee) public view returns (uint256);
|
||||
function maxPossibleCharge(uint256 relayedCallStipend, uint256 gasPrice, uint256 transactionFee) external view returns (uint256);
|
||||
|
||||
// Relay penalization.
|
||||
// Relay penalization.
|
||||
// Any account can penalize relays, removing them from the system immediately, and rewarding the
|
||||
// reporter with half of the relay's stake. The other half is burned so that, even if the relay penalizes itself, it
|
||||
// still loses half of its stake.
|
||||
@ -247,12 +247,12 @@ contract IRelayHub {
|
||||
*
|
||||
* The (unsigned) transaction data and signature for both transactions must be provided.
|
||||
*/
|
||||
function penalizeRepeatedNonce(bytes memory unsignedTx1, bytes memory signature1, bytes memory unsignedTx2, bytes memory signature2) public;
|
||||
function penalizeRepeatedNonce(bytes calldata unsignedTx1, bytes calldata signature1, bytes calldata unsignedTx2, bytes calldata signature2) external;
|
||||
|
||||
/**
|
||||
* @dev Penalize a relay that sent a transaction that didn't target `RelayHub`'s {registerRelay} or {relayCall}.
|
||||
*/
|
||||
function penalizeIllegalTransaction(bytes memory unsignedTx, bytes memory signature) public;
|
||||
function penalizeIllegalTransaction(bytes calldata unsignedTx, bytes calldata signature) external;
|
||||
|
||||
/**
|
||||
* @dev Emitted when a relay is penalized.
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Base interface for a contract that will be called via the GSN from {IRelayHub}.
|
||||
*
|
||||
* TIP: You don't need to write an implementation yourself! Inherit from {GSNRecipient} instead.
|
||||
*/
|
||||
contract IRelayRecipient {
|
||||
interface IRelayRecipient {
|
||||
/**
|
||||
* @dev Returns the address of the {IRelayHub} instance this recipient interacts with.
|
||||
*/
|
||||
function getHubAddr() public view returns (address);
|
||||
function getHubAddr() external view returns (address);
|
||||
|
||||
/**
|
||||
* @dev Called by {IRelayHub} to validate if this recipient accepts being charged for a relayed call. Note that the
|
||||
|
||||
@ -4,7 +4,7 @@ _Available since v2.4.0._
|
||||
|
||||
This set of contracts provide all the tools required to make a contract callable via the https://gsn.openzeppelin.com[Gas Station Network].
|
||||
|
||||
TIP: If you're new to the GSN, head over to our xref:openzeppelin::gsn/what-is-the-gsn.adoc[overview of the system] and basic guide to xref:ROOT:gsn.adoc[creating a GSN-capable contract].
|
||||
TIP: If you're new to the GSN, head over to our xref:learn::sending-gasless-transactions.adoc[overview of the system] and basic guide to xref:ROOT:gsn.adoc[creating a GSN-capable contract].
|
||||
|
||||
The core contract a recipient must inherit from is {GSNRecipient}: it includes all necessary interfaces, as well as some helper methods to make interacting with the GSN easier.
|
||||
|
||||
|
||||
188
contracts/access/AccessControl.sol
Normal file
188
contracts/access/AccessControl.sol
Normal file
@ -0,0 +1,188 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../utils/EnumerableSet.sol";
|
||||
import "../GSN/Context.sol";
|
||||
|
||||
/**
|
||||
* @dev Contract module that allows children to implement role-based access
|
||||
* control mechanisms.
|
||||
*
|
||||
* Roles are referred to by their `bytes32` identifier. These should be exposed
|
||||
* in the external API and be unique. The best way to achieve this is by
|
||||
* using `public constant` hash digests:
|
||||
*
|
||||
* ```
|
||||
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
|
||||
* ```
|
||||
*
|
||||
* Roles can be used to represent a set of permissions. To restrict access to a
|
||||
* function call, use {hasRole}:
|
||||
*
|
||||
* ```
|
||||
* function foo() public {
|
||||
* require(hasRole(MY_ROLE, _msgSender()));
|
||||
* ...
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Roles can be granted and revoked programatically by calling the `internal`
|
||||
* {_grantRole} and {_revokeRole} functions.
|
||||
*
|
||||
* This can also be achieved dynamically via the `external` {grantRole} and
|
||||
* {revokeRole} functions. Each role has an associated admin role, and only
|
||||
* accounts that have a role's admin role can call {grantRole} and {revokeRoke}.
|
||||
*
|
||||
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
|
||||
* that only accounts with this role will be able to grant or revoke other
|
||||
* roles. More complex role relationships can be created by using
|
||||
* {_setRoleAdmin}.
|
||||
*/
|
||||
abstract contract AccessControl is Context {
|
||||
using EnumerableSet for EnumerableSet.AddressSet;
|
||||
|
||||
struct RoleData {
|
||||
EnumerableSet.AddressSet members;
|
||||
bytes32 adminRole;
|
||||
}
|
||||
|
||||
mapping (bytes32 => RoleData) private _roles;
|
||||
|
||||
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
|
||||
|
||||
/**
|
||||
* @dev Emitted when `account` is granted `role`.
|
||||
*
|
||||
* `sender` is the account that originated the contract call:
|
||||
* - if using `grantRole`, it is the admin role bearer
|
||||
* - if using `_grantRole`, its meaning is system-dependent
|
||||
*/
|
||||
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
|
||||
|
||||
/**
|
||||
* @dev Emitted when `account` is revoked `role`.
|
||||
*
|
||||
* `sender` is the account that originated the contract call:
|
||||
* - if using `revokeRole`, it is the admin role bearer
|
||||
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
|
||||
* - if using `_renounceRole`, its meaning is system-dependent
|
||||
*/
|
||||
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
|
||||
|
||||
/**
|
||||
* @dev Returns `true` if `account` has been granted `role`.
|
||||
*/
|
||||
function hasRole(bytes32 role, address account) public view returns (bool) {
|
||||
return _roles[role].members.contains(account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the number of accounts that have `role`. Can be used
|
||||
* together with {getRoleMember} to enumerate all bearers of a role.
|
||||
*/
|
||||
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
|
||||
return _roles[role].members.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns one of the accounts that have `role`. `index` must be a
|
||||
* value between 0 and {getRoleMemberCount}, non-inclusive.
|
||||
*
|
||||
* Role bearers are not sorted in any particular way, and their ordering may
|
||||
* change at any point.
|
||||
*
|
||||
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
|
||||
* you perform all queries on the same block. See the following
|
||||
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
|
||||
* for more information.
|
||||
*/
|
||||
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
|
||||
return _roles[role].members.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the admin role that controls `role`. See {grantRole} and
|
||||
* {revokeRole}.
|
||||
*
|
||||
* To change a role's admin, use {_setRoleAdmin}.
|
||||
*/
|
||||
function getRoleAdmin(bytes32 role) external view returns (bytes32) {
|
||||
return _roles[role].adminRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Grants `role` to `account`.
|
||||
*
|
||||
* Calls {_grantRole} internally.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must have `role`'s admin role.
|
||||
*/
|
||||
function grantRole(bytes32 role, address account) external virtual {
|
||||
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
|
||||
|
||||
_grantRole(role, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Revokes `role` from `account`.
|
||||
*
|
||||
* Calls {_revokeRole} internally.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must have `role`'s admin role.
|
||||
*/
|
||||
function revokeRole(bytes32 role, address account) external virtual {
|
||||
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
|
||||
|
||||
_revokeRole(role, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Revokes `role` from the calling account.
|
||||
*
|
||||
* Roles are often managed via {grantRole} and {revokeRole}: this function's
|
||||
* purpose is to provide a mechanism for accounts to lose their privileges
|
||||
* if they are compromised (such as when a trusted device is misplaced).
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must be `account`.
|
||||
*/
|
||||
function renounceRole(bytes32 role, address account) external virtual {
|
||||
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
|
||||
|
||||
_revokeRole(role, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Grants `role` to `account`.
|
||||
*
|
||||
* If `account` had not been already granted `role`, emits a {RoleGranted}
|
||||
* event.
|
||||
*/
|
||||
function _grantRole(bytes32 role, address account) internal virtual {
|
||||
if (_roles[role].members.add(account)) {
|
||||
emit RoleGranted(role, account, _msgSender());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Revokes `role` from `account`.
|
||||
*
|
||||
* If `account` had been granted `role`, emits a {RoleRevoked} event.
|
||||
*/
|
||||
function _revokeRole(bytes32 role, address account) internal virtual {
|
||||
if (_roles[role].members.remove(account)) {
|
||||
emit RoleRevoked(role, account, _msgSender());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets `adminRole` as `role`'s admin role.
|
||||
*/
|
||||
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
|
||||
_roles[role].adminRole = adminRole;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
/**
|
||||
@ -6,6 +6,9 @@ import "../GSN/Context.sol";
|
||||
* there is an account (an owner) that can be granted exclusive access to
|
||||
* specific functions.
|
||||
*
|
||||
* By default, the owner account will be the one that deploys the contract. This
|
||||
* can later be changed with {transferOwnership}.
|
||||
*
|
||||
* This module is used through inheritance. It will make available the modifier
|
||||
* `onlyOwner`, which can be applied to your functions to restrict their use to
|
||||
* the owner.
|
||||
@ -19,8 +22,9 @@ contract Ownable is Context {
|
||||
* @dev Initializes the contract setting the deployer as the initial owner.
|
||||
*/
|
||||
constructor () internal {
|
||||
_owner = _msgSender();
|
||||
emit OwnershipTransferred(address(0), _owner);
|
||||
address msgSender = _msgSender();
|
||||
_owner = msgSender;
|
||||
emit OwnershipTransferred(address(0), msgSender);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,17 +38,10 @@ contract Ownable is Context {
|
||||
* @dev Throws if called by any account other than the owner.
|
||||
*/
|
||||
modifier onlyOwner() {
|
||||
require(isOwner(), "Ownable: caller is not the owner");
|
||||
require(_owner == _msgSender(), "Ownable: caller is not the owner");
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the caller is the current owner.
|
||||
*/
|
||||
function isOwner() public view returns (bool) {
|
||||
return _msgSender() == _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Leaves the contract without owner. It will not be possible to call
|
||||
* `onlyOwner` functions anymore. Can only be called by the current owner.
|
||||
@ -52,7 +49,7 @@ contract Ownable is Context {
|
||||
* NOTE: Renouncing ownership will leave the contract without an owner,
|
||||
* thereby removing any functionality that is only available to the owner.
|
||||
*/
|
||||
function renounceOwnership() public onlyOwner {
|
||||
function renounceOwnership() public virtual onlyOwner {
|
||||
emit OwnershipTransferred(_owner, address(0));
|
||||
_owner = address(0);
|
||||
}
|
||||
@ -61,14 +58,14 @@ contract Ownable is Context {
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
* Can only be called by the current owner.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public onlyOwner {
|
||||
function transferOwnership(address newOwner) public virtual onlyOwner {
|
||||
_transferOwnership(newOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
*/
|
||||
function _transferOwnership(address newOwner) internal {
|
||||
function _transferOwnership(address newOwner) internal virtual {
|
||||
require(newOwner != address(0), "Ownable: new owner is the zero address");
|
||||
emit OwnershipTransferred(_owner, newOwner);
|
||||
_owner = newOwner;
|
||||
@ -1,21 +1,9 @@
|
||||
= Access
|
||||
|
||||
NOTE: This page is incomplete. We're working to improve it for the next release. Stay tuned!
|
||||
Contract modules for authorization and access control mechanisms.
|
||||
|
||||
== Library
|
||||
== Contracts
|
||||
|
||||
{{Roles}}
|
||||
{{Ownable}}
|
||||
|
||||
== Roles
|
||||
|
||||
{{CapperRole}}
|
||||
|
||||
{{MinterRole}}
|
||||
|
||||
{{PauserRole}}
|
||||
|
||||
{{SignerRole}}
|
||||
|
||||
{{WhitelistAdminRole}}
|
||||
|
||||
{{WhitelistedRole}}
|
||||
{{AccessControl}}
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
/**
|
||||
* @title Roles
|
||||
* @dev Library for managing addresses assigned to a Role.
|
||||
*/
|
||||
library Roles {
|
||||
struct Role {
|
||||
mapping (address => bool) bearer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Give an account access to this role.
|
||||
*/
|
||||
function add(Role storage role, address account) internal {
|
||||
require(!has(role, account), "Roles: account already has role");
|
||||
role.bearer[account] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Remove an account's access to this role.
|
||||
*/
|
||||
function remove(Role storage role, address account) internal {
|
||||
require(has(role, account), "Roles: account does not have role");
|
||||
role.bearer[account] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Check if an account has this role.
|
||||
* @return bool
|
||||
*/
|
||||
function has(Role storage role, address account) internal view returns (bool) {
|
||||
require(account != address(0), "Roles: account is the zero address");
|
||||
return role.bearer[account];
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
|
||||
contract CapperRole is Context {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event CapperAdded(address indexed account);
|
||||
event CapperRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _cappers;
|
||||
|
||||
constructor () internal {
|
||||
_addCapper(_msgSender());
|
||||
}
|
||||
|
||||
modifier onlyCapper() {
|
||||
require(isCapper(_msgSender()), "CapperRole: caller does not have the Capper role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isCapper(address account) public view returns (bool) {
|
||||
return _cappers.has(account);
|
||||
}
|
||||
|
||||
function addCapper(address account) public onlyCapper {
|
||||
_addCapper(account);
|
||||
}
|
||||
|
||||
function renounceCapper() public {
|
||||
_removeCapper(_msgSender());
|
||||
}
|
||||
|
||||
function _addCapper(address account) internal {
|
||||
_cappers.add(account);
|
||||
emit CapperAdded(account);
|
||||
}
|
||||
|
||||
function _removeCapper(address account) internal {
|
||||
_cappers.remove(account);
|
||||
emit CapperRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
|
||||
contract MinterRole is Context {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event MinterAdded(address indexed account);
|
||||
event MinterRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _minters;
|
||||
|
||||
constructor () internal {
|
||||
_addMinter(_msgSender());
|
||||
}
|
||||
|
||||
modifier onlyMinter() {
|
||||
require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isMinter(address account) public view returns (bool) {
|
||||
return _minters.has(account);
|
||||
}
|
||||
|
||||
function addMinter(address account) public onlyMinter {
|
||||
_addMinter(account);
|
||||
}
|
||||
|
||||
function renounceMinter() public {
|
||||
_removeMinter(_msgSender());
|
||||
}
|
||||
|
||||
function _addMinter(address account) internal {
|
||||
_minters.add(account);
|
||||
emit MinterAdded(account);
|
||||
}
|
||||
|
||||
function _removeMinter(address account) internal {
|
||||
_minters.remove(account);
|
||||
emit MinterRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
|
||||
contract PauserRole is Context {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event PauserAdded(address indexed account);
|
||||
event PauserRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _pausers;
|
||||
|
||||
constructor () internal {
|
||||
_addPauser(_msgSender());
|
||||
}
|
||||
|
||||
modifier onlyPauser() {
|
||||
require(isPauser(_msgSender()), "PauserRole: caller does not have the Pauser role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isPauser(address account) public view returns (bool) {
|
||||
return _pausers.has(account);
|
||||
}
|
||||
|
||||
function addPauser(address account) public onlyPauser {
|
||||
_addPauser(account);
|
||||
}
|
||||
|
||||
function renouncePauser() public {
|
||||
_removePauser(_msgSender());
|
||||
}
|
||||
|
||||
function _addPauser(address account) internal {
|
||||
_pausers.add(account);
|
||||
emit PauserAdded(account);
|
||||
}
|
||||
|
||||
function _removePauser(address account) internal {
|
||||
_pausers.remove(account);
|
||||
emit PauserRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
|
||||
contract SignerRole is Context {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event SignerAdded(address indexed account);
|
||||
event SignerRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _signers;
|
||||
|
||||
constructor () internal {
|
||||
_addSigner(_msgSender());
|
||||
}
|
||||
|
||||
modifier onlySigner() {
|
||||
require(isSigner(_msgSender()), "SignerRole: caller does not have the Signer role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isSigner(address account) public view returns (bool) {
|
||||
return _signers.has(account);
|
||||
}
|
||||
|
||||
function addSigner(address account) public onlySigner {
|
||||
_addSigner(account);
|
||||
}
|
||||
|
||||
function renounceSigner() public {
|
||||
_removeSigner(_msgSender());
|
||||
}
|
||||
|
||||
function _addSigner(address account) internal {
|
||||
_signers.add(account);
|
||||
emit SignerAdded(account);
|
||||
}
|
||||
|
||||
function _removeSigner(address account) internal {
|
||||
_signers.remove(account);
|
||||
emit SignerRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
|
||||
/**
|
||||
* @title WhitelistAdminRole
|
||||
* @dev WhitelistAdmins are responsible for assigning and removing Whitelisted accounts.
|
||||
*/
|
||||
contract WhitelistAdminRole is Context {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event WhitelistAdminAdded(address indexed account);
|
||||
event WhitelistAdminRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _whitelistAdmins;
|
||||
|
||||
constructor () internal {
|
||||
_addWhitelistAdmin(_msgSender());
|
||||
}
|
||||
|
||||
modifier onlyWhitelistAdmin() {
|
||||
require(isWhitelistAdmin(_msgSender()), "WhitelistAdminRole: caller does not have the WhitelistAdmin role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isWhitelistAdmin(address account) public view returns (bool) {
|
||||
return _whitelistAdmins.has(account);
|
||||
}
|
||||
|
||||
function addWhitelistAdmin(address account) public onlyWhitelistAdmin {
|
||||
_addWhitelistAdmin(account);
|
||||
}
|
||||
|
||||
function renounceWhitelistAdmin() public {
|
||||
_removeWhitelistAdmin(_msgSender());
|
||||
}
|
||||
|
||||
function _addWhitelistAdmin(address account) internal {
|
||||
_whitelistAdmins.add(account);
|
||||
emit WhitelistAdminAdded(account);
|
||||
}
|
||||
|
||||
function _removeWhitelistAdmin(address account) internal {
|
||||
_whitelistAdmins.remove(account);
|
||||
emit WhitelistAdminRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../Roles.sol";
|
||||
import "./WhitelistAdminRole.sol";
|
||||
|
||||
/**
|
||||
* @title WhitelistedRole
|
||||
* @dev Whitelisted accounts have been approved by a WhitelistAdmin to perform certain actions (e.g. participate in a
|
||||
* crowdsale). This role is special in that the only accounts that can add it are WhitelistAdmins (who can also remove
|
||||
* it), and not Whitelisteds themselves.
|
||||
*/
|
||||
contract WhitelistedRole is Context, WhitelistAdminRole {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
event WhitelistedAdded(address indexed account);
|
||||
event WhitelistedRemoved(address indexed account);
|
||||
|
||||
Roles.Role private _whitelisteds;
|
||||
|
||||
modifier onlyWhitelisted() {
|
||||
require(isWhitelisted(_msgSender()), "WhitelistedRole: caller does not have the Whitelisted role");
|
||||
_;
|
||||
}
|
||||
|
||||
function isWhitelisted(address account) public view returns (bool) {
|
||||
return _whitelisteds.has(account);
|
||||
}
|
||||
|
||||
function addWhitelisted(address account) public onlyWhitelistAdmin {
|
||||
_addWhitelisted(account);
|
||||
}
|
||||
|
||||
function removeWhitelisted(address account) public onlyWhitelistAdmin {
|
||||
_removeWhitelisted(account);
|
||||
}
|
||||
|
||||
function renounceWhitelisted() public {
|
||||
_removeWhitelisted(_msgSender());
|
||||
}
|
||||
|
||||
function _addWhitelisted(address account) internal {
|
||||
_whitelisteds.add(account);
|
||||
emit WhitelistedAdded(account);
|
||||
}
|
||||
|
||||
function _removeWhitelisted(address account) internal {
|
||||
_whitelisteds.remove(account);
|
||||
emit WhitelistedRemoved(account);
|
||||
}
|
||||
}
|
||||
@ -1,200 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
import "../token/ERC20/IERC20.sol";
|
||||
import "../math/SafeMath.sol";
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
import "../utils/ReentrancyGuard.sol";
|
||||
|
||||
/**
|
||||
* @title Crowdsale
|
||||
* @dev Crowdsale is a base contract for managing a token crowdsale,
|
||||
* allowing investors to purchase tokens with ether. This contract implements
|
||||
* such functionality in its most fundamental form and can be extended to provide additional
|
||||
* functionality and/or custom behavior.
|
||||
* The external interface represents the basic interface for purchasing tokens, and conforms
|
||||
* 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 methods to add functionality. Consider using 'super' where appropriate to concatenate
|
||||
* behavior.
|
||||
*/
|
||||
contract Crowdsale is Context, ReentrancyGuard {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// The token being sold
|
||||
IERC20 private _token;
|
||||
|
||||
// Address where funds are collected
|
||||
address payable private _wallet;
|
||||
|
||||
// How many token units a buyer gets per wei.
|
||||
// The rate is the conversion between wei and the smallest and indivisible token unit.
|
||||
// So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK
|
||||
// 1 wei will give you 1 unit, or 0.001 TOK.
|
||||
uint256 private _rate;
|
||||
|
||||
// Amount of wei raised
|
||||
uint256 private _weiRaised;
|
||||
|
||||
/**
|
||||
* Event for token purchase logging
|
||||
* @param purchaser who paid for the tokens
|
||||
* @param beneficiary who got the tokens
|
||||
* @param value weis paid for purchase
|
||||
* @param amount amount of tokens purchased
|
||||
*/
|
||||
event TokensPurchased(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
|
||||
|
||||
/**
|
||||
* @param rate Number of token units a buyer gets per wei
|
||||
* @dev The rate is the conversion between wei and the smallest and indivisible
|
||||
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
|
||||
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
|
||||
* @param wallet Address where collected funds will be forwarded to
|
||||
* @param token Address of the token being sold
|
||||
*/
|
||||
constructor (uint256 rate, address payable wallet, IERC20 token) public {
|
||||
require(rate > 0, "Crowdsale: rate is 0");
|
||||
require(wallet != address(0), "Crowdsale: wallet is the zero address");
|
||||
require(address(token) != address(0), "Crowdsale: token is the zero address");
|
||||
|
||||
_rate = rate;
|
||||
_wallet = wallet;
|
||||
_token = token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev fallback function ***DO NOT OVERRIDE***
|
||||
* Note that other contracts will transfer funds with a base gas stipend
|
||||
* of 2300, which is not enough to call buyTokens. Consider calling
|
||||
* buyTokens directly when purchasing tokens from a contract.
|
||||
*/
|
||||
function () external payable {
|
||||
buyTokens(_msgSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the token being sold.
|
||||
*/
|
||||
function token() public view returns (IERC20) {
|
||||
return _token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the address where funds are collected.
|
||||
*/
|
||||
function wallet() public view returns (address payable) {
|
||||
return _wallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of token units a buyer gets per wei.
|
||||
*/
|
||||
function rate() public view returns (uint256) {
|
||||
return _rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount of wei raised.
|
||||
*/
|
||||
function weiRaised() public view returns (uint256) {
|
||||
return _weiRaised;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev low level token purchase ***DO NOT OVERRIDE***
|
||||
* This function has a non-reentrancy guard, so it shouldn't be called by
|
||||
* another `nonReentrant` function.
|
||||
* @param beneficiary Recipient of the token purchase
|
||||
*/
|
||||
function buyTokens(address beneficiary) public nonReentrant payable {
|
||||
uint256 weiAmount = msg.value;
|
||||
_preValidatePurchase(beneficiary, weiAmount);
|
||||
|
||||
// calculate token amount to be created
|
||||
uint256 tokens = _getTokenAmount(weiAmount);
|
||||
|
||||
// update state
|
||||
_weiRaised = _weiRaised.add(weiAmount);
|
||||
|
||||
_processPurchase(beneficiary, tokens);
|
||||
emit TokensPurchased(_msgSender(), beneficiary, weiAmount, tokens);
|
||||
|
||||
_updatePurchasingState(beneficiary, weiAmount);
|
||||
|
||||
_forwardFunds();
|
||||
_postValidatePurchase(beneficiary, weiAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
|
||||
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
|
||||
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
|
||||
* super._preValidatePurchase(beneficiary, weiAmount);
|
||||
* require(weiRaised().add(weiAmount) <= cap);
|
||||
* @param beneficiary Address performing the token purchase
|
||||
* @param weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
|
||||
require(beneficiary != address(0), "Crowdsale: beneficiary is the zero address");
|
||||
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
|
||||
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid
|
||||
* conditions are not met.
|
||||
* @param beneficiary Address performing the token purchase
|
||||
* @param weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _postValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
|
||||
* its tokens.
|
||||
* @param beneficiary Address performing the token purchase
|
||||
* @param tokenAmount Number of tokens to be emitted
|
||||
*/
|
||||
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
|
||||
_token.safeTransfer(beneficiary, tokenAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send
|
||||
* tokens.
|
||||
* @param beneficiary Address receiving the tokens
|
||||
* @param tokenAmount Number of tokens to be purchased
|
||||
*/
|
||||
function _processPurchase(address beneficiary, uint256 tokenAmount) internal {
|
||||
_deliverTokens(beneficiary, tokenAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Override for extensions that require an internal state to check for validity (current user contributions,
|
||||
* etc.)
|
||||
* @param beneficiary Address receiving the tokens
|
||||
* @param weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _updatePurchasingState(address beneficiary, uint256 weiAmount) internal {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Override to extend the way in which ether is converted to tokens.
|
||||
* @param weiAmount Value in wei to be converted into tokens
|
||||
* @return Number of tokens that can be purchased with the specified _weiAmount
|
||||
*/
|
||||
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) {
|
||||
return weiAmount.mul(_rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Determines how ETH is stored/forwarded on purchases.
|
||||
*/
|
||||
function _forwardFunds() internal {
|
||||
_wallet.transfer(msg.value);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
= Crowdsales
|
||||
|
||||
NOTE: This page is incomplete. We're working to improve it for the next release. Stay tuned!
|
||||
|
||||
== Core
|
||||
|
||||
{{Crowdsale}}
|
||||
|
||||
== Emission
|
||||
|
||||
{{AllowanceCrowdsale}}
|
||||
|
||||
{{MintedCrowdsale}}
|
||||
|
||||
== Validation
|
||||
|
||||
{{CappedCrowdsale}}
|
||||
|
||||
{{IndividuallyCappedCrowdsale}}
|
||||
|
||||
{{PausableCrowdsale}}
|
||||
|
||||
{{TimedCrowdsale}}
|
||||
|
||||
{{WhitelistCrowdsale}}
|
||||
|
||||
== Distribution
|
||||
|
||||
{{FinalizableCrowdsale}}
|
||||
|
||||
{{PostDeliveryCrowdsale}}
|
||||
|
||||
{{RefundableCrowdsale}}
|
||||
|
||||
{{RefundablePostDeliveryCrowdsale}}
|
||||
@ -1,51 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../validation/TimedCrowdsale.sol";
|
||||
|
||||
/**
|
||||
* @title FinalizableCrowdsale
|
||||
* @dev Extension of TimedCrowdsale with a one-off finalization action, where one
|
||||
* can do extra work after finishing.
|
||||
*/
|
||||
contract FinalizableCrowdsale is TimedCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
bool private _finalized;
|
||||
|
||||
event CrowdsaleFinalized();
|
||||
|
||||
constructor () internal {
|
||||
_finalized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the crowdsale is finalized, false otherwise.
|
||||
*/
|
||||
function finalized() public view returns (bool) {
|
||||
return _finalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Must be called after crowdsale ends, to do some extra finalization
|
||||
* work. Calls the contract's finalization function.
|
||||
*/
|
||||
function finalize() public {
|
||||
require(!_finalized, "FinalizableCrowdsale: already finalized");
|
||||
require(hasClosed(), "FinalizableCrowdsale: not closed");
|
||||
|
||||
_finalized = true;
|
||||
|
||||
_finalization();
|
||||
emit CrowdsaleFinalized();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Can be overridden to add finalization logic. The overriding function
|
||||
* should call super._finalization() to ensure the chain of finalization is
|
||||
* executed entirely.
|
||||
*/
|
||||
function _finalization() internal {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../validation/TimedCrowdsale.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../../ownership/Secondary.sol";
|
||||
import "../../token/ERC20/IERC20.sol";
|
||||
|
||||
/**
|
||||
* @title PostDeliveryCrowdsale
|
||||
* @dev Crowdsale that locks tokens from withdrawal until it ends.
|
||||
*/
|
||||
contract PostDeliveryCrowdsale is TimedCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
mapping(address => uint256) private _balances;
|
||||
__unstable__TokenVault private _vault;
|
||||
|
||||
constructor() public {
|
||||
_vault = new __unstable__TokenVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw tokens only after crowdsale ends.
|
||||
* @param beneficiary Whose tokens will be withdrawn.
|
||||
*/
|
||||
function withdrawTokens(address beneficiary) public {
|
||||
require(hasClosed(), "PostDeliveryCrowdsale: not closed");
|
||||
uint256 amount = _balances[beneficiary];
|
||||
require(amount > 0, "PostDeliveryCrowdsale: beneficiary is not due any tokens");
|
||||
|
||||
_balances[beneficiary] = 0;
|
||||
_vault.transfer(token(), beneficiary, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the balance of an account.
|
||||
*/
|
||||
function balanceOf(address account) public view returns (uint256) {
|
||||
return _balances[account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides parent by storing due balances, and delivering tokens to the vault instead of the end user. This
|
||||
* ensures that the tokens will be available by the time they are withdrawn (which may not be the case if
|
||||
* `_deliverTokens` was called later).
|
||||
* @param beneficiary Token purchaser
|
||||
* @param tokenAmount Amount of tokens purchased
|
||||
*/
|
||||
function _processPurchase(address beneficiary, uint256 tokenAmount) internal {
|
||||
_balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
|
||||
_deliverTokens(address(_vault), tokenAmount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title __unstable__TokenVault
|
||||
* @dev Similar to an Escrow for tokens, this contract allows its primary account to spend its tokens as it sees fit.
|
||||
* This contract is an internal helper for PostDeliveryCrowdsale, and should not be used outside of this context.
|
||||
*/
|
||||
// solhint-disable-next-line contract-name-camelcase
|
||||
contract __unstable__TokenVault is Secondary {
|
||||
function transfer(IERC20 token, address to, uint256 amount) public onlyPrimary {
|
||||
token.transfer(to, amount);
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../GSN/Context.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
import "./FinalizableCrowdsale.sol";
|
||||
import "../../payment/escrow/RefundEscrow.sol";
|
||||
|
||||
/**
|
||||
* @title RefundableCrowdsale
|
||||
* @dev Extension of `FinalizableCrowdsale` contract that adds a funding goal, and the possibility of users
|
||||
* getting a refund if goal is not met.
|
||||
*
|
||||
* 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
|
||||
* the goal is unlikely to be met, they sell their tokens (possibly at a discount). The attacker will be refunded when
|
||||
* the crowdsale is finalized, and the users that purchased from them will be left with worthless tokens.
|
||||
*/
|
||||
contract RefundableCrowdsale is Context, FinalizableCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
// minimum amount of funds to be raised in weis
|
||||
uint256 private _goal;
|
||||
|
||||
// refund escrow used to hold funds while crowdsale is running
|
||||
RefundEscrow private _escrow;
|
||||
|
||||
/**
|
||||
* @dev Constructor, creates RefundEscrow.
|
||||
* @param goal Funding goal
|
||||
*/
|
||||
constructor (uint256 goal) public {
|
||||
require(goal > 0, "RefundableCrowdsale: goal is 0");
|
||||
_escrow = new RefundEscrow(wallet());
|
||||
_goal = goal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return minimum amount of funds to be raised in wei.
|
||||
*/
|
||||
function goal() public view returns (uint256) {
|
||||
return _goal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Investors can claim refunds here if crowdsale is unsuccessful.
|
||||
* @param refundee Whose refund will be claimed.
|
||||
*/
|
||||
function claimRefund(address payable refundee) public {
|
||||
require(finalized(), "RefundableCrowdsale: not finalized");
|
||||
require(!goalReached(), "RefundableCrowdsale: goal reached");
|
||||
|
||||
_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.
|
||||
*/
|
||||
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)(_msgSender());
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "./RefundableCrowdsale.sol";
|
||||
import "./PostDeliveryCrowdsale.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RefundablePostDeliveryCrowdsale
|
||||
* @dev Extension of RefundableCrowdsale contract that only delivers the tokens
|
||||
* once the crowdsale has closed and the goal met, preventing refunds to be issued
|
||||
* to token holders.
|
||||
*/
|
||||
contract RefundablePostDeliveryCrowdsale is RefundableCrowdsale, PostDeliveryCrowdsale {
|
||||
function withdrawTokens(address beneficiary) public {
|
||||
require(finalized(), "RefundablePostDeliveryCrowdsale: not finalized");
|
||||
require(goalReached(), "RefundablePostDeliveryCrowdsale: goal not reached");
|
||||
|
||||
super.withdrawTokens(beneficiary);
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../token/ERC20/IERC20.sol";
|
||||
import "../../token/ERC20/SafeERC20.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../../math/Math.sol";
|
||||
|
||||
/**
|
||||
* @title AllowanceCrowdsale
|
||||
* @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale.
|
||||
*/
|
||||
contract AllowanceCrowdsale is Crowdsale {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
address private _tokenWallet;
|
||||
|
||||
/**
|
||||
* @dev Constructor, takes token wallet address.
|
||||
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale.
|
||||
*/
|
||||
constructor (address tokenWallet) public {
|
||||
require(tokenWallet != address(0), "AllowanceCrowdsale: token wallet is the zero address");
|
||||
_tokenWallet = tokenWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the address of the wallet that will hold the tokens.
|
||||
*/
|
||||
function tokenWallet() public view returns (address) {
|
||||
return _tokenWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks the amount of tokens left in the allowance.
|
||||
* @return Amount of tokens left in the allowance
|
||||
*/
|
||||
function remainingTokens() public view returns (uint256) {
|
||||
return Math.min(token().balanceOf(_tokenWallet), token().allowance(_tokenWallet, address(this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides parent behavior by transferring tokens from wallet.
|
||||
* @param beneficiary Token purchaser
|
||||
* @param tokenAmount Amount of tokens purchased
|
||||
*/
|
||||
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
|
||||
token().safeTransferFrom(_tokenWallet, beneficiary, tokenAmount);
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../token/ERC20/ERC20Mintable.sol";
|
||||
|
||||
/**
|
||||
* @title MintedCrowdsale
|
||||
* @dev Extension of Crowdsale contract whose tokens are minted in each purchase.
|
||||
* Token ownership should be transferred to MintedCrowdsale for minting.
|
||||
*/
|
||||
contract MintedCrowdsale is Crowdsale {
|
||||
/**
|
||||
* @dev Overrides delivery by minting tokens upon purchase.
|
||||
* @param beneficiary Token purchaser
|
||||
* @param tokenAmount Number of tokens to be minted
|
||||
*/
|
||||
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
|
||||
// Potentially dangerous assumption about the type of the token.
|
||||
require(
|
||||
ERC20Mintable(address(token())).mint(beneficiary, tokenAmount),
|
||||
"MintedCrowdsale: minting failed"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../validation/TimedCrowdsale.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
|
||||
/**
|
||||
* @title IncreasingPriceCrowdsale
|
||||
* @dev Extension of Crowdsale contract that increases the price of tokens linearly in time.
|
||||
* Note that what should be provided to the constructor is the initial and final _rates_, that is,
|
||||
* the amount of tokens per wei contributed. Thus, the initial rate must be greater than the final rate.
|
||||
*/
|
||||
contract IncreasingPriceCrowdsale is TimedCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
uint256 private _initialRate;
|
||||
uint256 private _finalRate;
|
||||
|
||||
/**
|
||||
* @dev Constructor, takes initial and final rates of tokens received per wei contributed.
|
||||
* @param initialRate Number of tokens a buyer gets per wei at the start of the crowdsale
|
||||
* @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
|
||||
*/
|
||||
constructor (uint256 initialRate, uint256 finalRate) public {
|
||||
require(finalRate > 0, "IncreasingPriceCrowdsale: final rate is 0");
|
||||
// solhint-disable-next-line max-line-length
|
||||
require(initialRate > finalRate, "IncreasingPriceCrowdsale: initial rate is not greater than final rate");
|
||||
_initialRate = initialRate;
|
||||
_finalRate = finalRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base rate function is overridden to revert, since this crowdsale doesn't use it, and
|
||||
* all calls to it are a mistake.
|
||||
*/
|
||||
function rate() public view returns (uint256) {
|
||||
revert("IncreasingPriceCrowdsale: rate() called");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial rate of the crowdsale.
|
||||
*/
|
||||
function initialRate() public view returns (uint256) {
|
||||
return _initialRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the final rate of the crowdsale.
|
||||
*/
|
||||
function finalRate() public view returns (uint256) {
|
||||
return _finalRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the rate of tokens per wei at the present time.
|
||||
* Note that, as price _increases_ with time, the rate _decreases_.
|
||||
* @return The number of tokens a buyer gets per wei at a given time
|
||||
*/
|
||||
function getCurrentRate() public view returns (uint256) {
|
||||
if (!isOpen()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
uint256 elapsedTime = block.timestamp.sub(openingTime());
|
||||
uint256 timeRange = closingTime().sub(openingTime());
|
||||
uint256 rateRange = _initialRate.sub(_finalRate);
|
||||
return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides parent method taking into account variable rate.
|
||||
* @param weiAmount The value in wei to be converted into tokens
|
||||
* @return The number of tokens _weiAmount wei will buy at present time
|
||||
*/
|
||||
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) {
|
||||
uint256 currentRate = getCurrentRate();
|
||||
return currentRate.mul(weiAmount);
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../Crowdsale.sol";
|
||||
|
||||
/**
|
||||
* @title CappedCrowdsale
|
||||
* @dev Crowdsale with a limit for total contributions.
|
||||
*/
|
||||
contract CappedCrowdsale is Crowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
uint256 private _cap;
|
||||
|
||||
/**
|
||||
* @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
|
||||
* @param cap Max amount of wei to be contributed
|
||||
*/
|
||||
constructor (uint256 cap) public {
|
||||
require(cap > 0, "CappedCrowdsale: cap is 0");
|
||||
_cap = cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cap of the crowdsale.
|
||||
*/
|
||||
function cap() public view returns (uint256) {
|
||||
return _cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks whether the cap has been reached.
|
||||
* @return Whether the cap was reached
|
||||
*/
|
||||
function capReached() public view returns (bool) {
|
||||
return weiRaised() >= _cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior requiring purchase to respect the funding cap.
|
||||
* @param beneficiary Token purchaser
|
||||
* @param weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
|
||||
super._preValidatePurchase(beneficiary, weiAmount);
|
||||
require(weiRaised().add(weiAmount) <= _cap, "CappedCrowdsale: cap exceeded");
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../Crowdsale.sol";
|
||||
import "../../access/roles/CapperRole.sol";
|
||||
|
||||
/**
|
||||
* @title IndividuallyCappedCrowdsale
|
||||
* @dev Crowdsale with per-beneficiary caps.
|
||||
*/
|
||||
contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
|
||||
using SafeMath for uint256;
|
||||
|
||||
mapping(address => uint256) private _contributions;
|
||||
mapping(address => uint256) private _caps;
|
||||
|
||||
/**
|
||||
* @dev Sets a specific beneficiary's maximum contribution.
|
||||
* @param beneficiary Address to be capped
|
||||
* @param cap Wei limit for individual contribution
|
||||
*/
|
||||
function setCap(address beneficiary, uint256 cap) external onlyCapper {
|
||||
_caps[beneficiary] = cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the cap of a specific beneficiary.
|
||||
* @param beneficiary Address whose cap is to be checked
|
||||
* @return Current cap for individual beneficiary
|
||||
*/
|
||||
function getCap(address beneficiary) public view returns (uint256) {
|
||||
return _caps[beneficiary];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the amount contributed so far by a specific beneficiary.
|
||||
* @param beneficiary Address of contributor
|
||||
* @return Beneficiary contribution so far
|
||||
*/
|
||||
function getContribution(address beneficiary) public view returns (uint256) {
|
||||
return _contributions[beneficiary];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap.
|
||||
* @param beneficiary Token purchaser
|
||||
* @param weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
|
||||
super._preValidatePurchase(beneficiary, weiAmount);
|
||||
// solhint-disable-next-line max-line-length
|
||||
require(_contributions[beneficiary].add(weiAmount) <= _caps[beneficiary], "IndividuallyCappedCrowdsale: beneficiary's cap exceeded");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../lifecycle/Pausable.sol";
|
||||
|
||||
/**
|
||||
* @title PausableCrowdsale
|
||||
* @dev Extension of Crowdsale contract where purchases can be paused and unpaused by the pauser role.
|
||||
*/
|
||||
contract PausableCrowdsale is Crowdsale, Pausable {
|
||||
/**
|
||||
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
|
||||
* Use super to concatenate validations.
|
||||
* Adds the validation that the crowdsale must not be paused.
|
||||
* @param _beneficiary Address performing the token purchase
|
||||
* @param _weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal view whenNotPaused {
|
||||
return super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
}
|
||||
}
|
||||
@ -1,98 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../Crowdsale.sol";
|
||||
|
||||
/**
|
||||
* @title TimedCrowdsale
|
||||
* @dev Crowdsale accepting contributions only within a time frame.
|
||||
*/
|
||||
contract TimedCrowdsale is Crowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
uint256 private _openingTime;
|
||||
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.
|
||||
*/
|
||||
modifier onlyWhileOpen {
|
||||
require(isOpen(), "TimedCrowdsale: not open");
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Constructor, takes crowdsale opening and closing times.
|
||||
* @param openingTime Crowdsale opening time
|
||||
* @param closingTime Crowdsale closing time
|
||||
*/
|
||||
constructor (uint256 openingTime, uint256 closingTime) public {
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
require(openingTime >= block.timestamp, "TimedCrowdsale: opening time is before current time");
|
||||
// solhint-disable-next-line max-line-length
|
||||
require(closingTime > openingTime, "TimedCrowdsale: opening time is not before closing time");
|
||||
|
||||
_openingTime = openingTime;
|
||||
_closingTime = closingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the crowdsale opening time.
|
||||
*/
|
||||
function openingTime() public view returns (uint256) {
|
||||
return _openingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the crowdsale closing time.
|
||||
*/
|
||||
function closingTime() public view returns (uint256) {
|
||||
return _closingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the crowdsale is open, false otherwise.
|
||||
*/
|
||||
function isOpen() public view returns (bool) {
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
return block.timestamp >= _openingTime && block.timestamp <= _closingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
|
||||
* @return Whether crowdsale period has elapsed
|
||||
*/
|
||||
function hasClosed() public view returns (bool) {
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
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 crowdsale.
|
||||
* @param newClosingTime Crowdsale closing time
|
||||
*/
|
||||
function _extendTime(uint256 newClosingTime) internal {
|
||||
require(!hasClosed(), "TimedCrowdsale: already closed");
|
||||
// solhint-disable-next-line max-line-length
|
||||
require(newClosingTime > _closingTime, "TimedCrowdsale: new closing time is before current closing time");
|
||||
|
||||
emit TimedCrowdsaleExtended(_closingTime, newClosingTime);
|
||||
_closingTime = newClosingTime;
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
import "../Crowdsale.sol";
|
||||
import "../../access/roles/WhitelistedRole.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title WhitelistCrowdsale
|
||||
* @dev Crowdsale in which only whitelisted users can contribute.
|
||||
*/
|
||||
contract WhitelistCrowdsale is WhitelistedRole, Crowdsale {
|
||||
/**
|
||||
* @dev Extend parent behavior requiring beneficiary to be whitelisted. Note that no
|
||||
* restriction is imposed on the account sending the transaction.
|
||||
* @param _beneficiary Token beneficiary
|
||||
* @param _weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal view {
|
||||
require(isWhitelisted(_beneficiary), "WhitelistCrowdsale: beneficiary doesn't have the Whitelisted role");
|
||||
super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
|
||||
@ -15,10 +15,6 @@ library ECDSA {
|
||||
* this function rejects them by requiring the `s` value to be in the lower
|
||||
* half order, and the `v` value to be either 27 or 28.
|
||||
*
|
||||
* NOTE: This call _does not revert_ if the signature is invalid, or
|
||||
* if the signer is otherwise unable to be retrieved. In those scenarios,
|
||||
* the zero address is returned.
|
||||
*
|
||||
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
|
||||
* verification to be secure: it is possible to craft signatures that
|
||||
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
|
||||
@ -28,7 +24,7 @@ library ECDSA {
|
||||
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
|
||||
// Check the signature length
|
||||
if (signature.length != 65) {
|
||||
return (address(0));
|
||||
revert("ECDSA: invalid signature length");
|
||||
}
|
||||
|
||||
// Divide the signature in r, s and v variables
|
||||
@ -55,15 +51,18 @@ library ECDSA {
|
||||
// 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);
|
||||
revert("ECDSA: invalid signature 's' value");
|
||||
}
|
||||
|
||||
if (v != 27 && v != 28) {
|
||||
return address(0);
|
||||
revert("ECDSA: invalid signature 'v' value");
|
||||
}
|
||||
|
||||
// If the signature is valid (and not malleable), return the signer address
|
||||
return ecrecover(hash, v, r, s);
|
||||
address signer = ecrecover(hash, v, r, s);
|
||||
require(signer != address(0), "ECDSA: invalid signature");
|
||||
|
||||
return signer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev These functions deal with verification of Merkle trees (hash trees),
|
||||
@ -16,7 +16,7 @@ library MerkleProof {
|
||||
for (uint256 i = 0; i < proof.length; i++) {
|
||||
bytes32 proofElement = proof[i];
|
||||
|
||||
if (computedHash < proofElement) {
|
||||
if (computedHash <= proofElement) {
|
||||
// Hash(current computed hash + current element of the proof)
|
||||
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
|
||||
} else {
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../../token/ERC20/IERC20.sol";
|
||||
|
||||
/**
|
||||
* @title ERC-1047 Token Metadata
|
||||
* @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
|
||||
*/
|
||||
contract ERC20Metadata {
|
||||
string private _tokenURI;
|
||||
|
||||
constructor (string memory tokenURI_) public {
|
||||
_setTokenURI(tokenURI_);
|
||||
}
|
||||
|
||||
function tokenURI() external view returns (string memory) {
|
||||
return _tokenURI;
|
||||
}
|
||||
|
||||
function _setTokenURI(string memory tokenURI_) internal {
|
||||
_tokenURI = tokenURI_;
|
||||
}
|
||||
}
|
||||
@ -1,103 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/IERC20.sol";
|
||||
import "../token/ERC20/ERC20Mintable.sol";
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
import "../math/Math.sol";
|
||||
|
||||
/**
|
||||
* @title ERC20Migrator
|
||||
* @dev This contract can be used to migrate an ERC20 token from one
|
||||
* contract to another, where each token holder has to opt-in to the migration.
|
||||
* To opt-in, users must approve for this contract the number of tokens they
|
||||
* want to migrate. Once the allowance is set up, anyone can trigger the
|
||||
* migration to the new token contract. In this way, token holders "turn in"
|
||||
* their old balance and will be minted an equal amount in the new token.
|
||||
* The new token contract must be mintable. For the precise interface refer to
|
||||
* OpenZeppelin's {ERC20Mintable}, but the only functions that are needed are
|
||||
* {MinterRole-isMinter} and {ERC20Mintable-mint}. The migrator will check
|
||||
* that it is a minter for the token.
|
||||
* The balance from the legacy token will be transferred to the migrator, as it
|
||||
* is migrated, and remain there forever.
|
||||
* 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
|
||||
* version of it using ZeppelinOS. To read more about how this can be done
|
||||
* using this implementation, please follow the official documentation site of
|
||||
* ZeppelinOS: https://docs.zeppelinos.org/docs/erc20_onboarding.html
|
||||
*
|
||||
* Example of usage:
|
||||
* ```
|
||||
* const migrator = await ERC20Migrator.new(legacyToken.address);
|
||||
* await newToken.addMinter(migrator.address);
|
||||
* await migrator.beginMigration(newToken.address);
|
||||
* ```
|
||||
*/
|
||||
contract ERC20Migrator {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
/// Address of the old token contract
|
||||
IERC20 private _legacyToken;
|
||||
|
||||
/// Address of the new token contract
|
||||
ERC20Mintable private _newToken;
|
||||
|
||||
/**
|
||||
* @param legacyToken address of the old token contract
|
||||
*/
|
||||
constructor (IERC20 legacyToken) public {
|
||||
require(address(legacyToken) != address(0), "ERC20Migrator: legacy token is the zero address");
|
||||
_legacyToken = legacyToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the legacy token that is being migrated.
|
||||
*/
|
||||
function legacyToken() public view returns (IERC20) {
|
||||
return _legacyToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the new token to which we are migrating.
|
||||
*/
|
||||
function newToken() public view returns (IERC20) {
|
||||
return _newToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Begins the migration by setting which is the new token that will be
|
||||
* minted. This contract must be a minter for the new token.
|
||||
* @param newToken_ the token that will be minted
|
||||
*/
|
||||
function beginMigration(ERC20Mintable newToken_) public {
|
||||
require(address(_newToken) == address(0), "ERC20Migrator: migration already started");
|
||||
require(address(newToken_) != address(0), "ERC20Migrator: new token is the zero address");
|
||||
//solhint-disable-next-line max-line-length
|
||||
require(newToken_.isMinter(address(this)), "ERC20Migrator: not a minter for new token");
|
||||
|
||||
_newToken = newToken_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers part of an account's balance in the old token to this
|
||||
* contract, and mints the same amount of new tokens for that account.
|
||||
* @param account whose tokens will be migrated
|
||||
* @param amount amount of tokens to be migrated
|
||||
*/
|
||||
function migrate(address account, uint256 amount) public {
|
||||
require(address(_newToken) != address(0), "ERC20Migrator: migration not started");
|
||||
_legacyToken.safeTransferFrom(account, address(this), amount);
|
||||
_newToken.mint(account, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers all of an account's allowed balance in the old token to
|
||||
* this contract, and mints the same amount of new tokens for that account.
|
||||
* @param account whose tokens will be migrated
|
||||
*/
|
||||
function migrateAll(address account) public {
|
||||
uint256 balance = _legacyToken.balanceOf(account);
|
||||
uint256 allowance = _legacyToken.allowance(account, address(this));
|
||||
uint256 amount = Math.min(balance, allowance);
|
||||
migrate(account, amount);
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
= Drafts
|
||||
|
||||
NOTE: This page is incomplete. We're working to improve it for the next release. Stay tuned!
|
||||
|
||||
== ERC 20
|
||||
|
||||
{{ERC20Migrator}}
|
||||
|
||||
{{ERC20Snapshot}}
|
||||
|
||||
{{TokenVesting}}
|
||||
|
||||
== Miscellaneous
|
||||
|
||||
{{Counters}}
|
||||
|
||||
{{SignedSafeMath}}
|
||||
|
||||
== ERC 1046
|
||||
|
||||
{{ERC1046}}
|
||||
@ -1,7 +1,7 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
import "../ownership/Ownable.sol";
|
||||
import "../access/Ownable.sol";
|
||||
import "../math/SafeMath.sol";
|
||||
|
||||
/**
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../crowdsale/validation/CappedCrowdsale.sol";
|
||||
import "../crowdsale/distribution/RefundableCrowdsale.sol";
|
||||
import "../crowdsale/emission/MintedCrowdsale.sol";
|
||||
import "../token/ERC20/ERC20Mintable.sol";
|
||||
import "../token/ERC20/ERC20Detailed.sol";
|
||||
|
||||
/**
|
||||
* @title SampleCrowdsaleToken
|
||||
* @dev Very simple ERC20 Token that can be minted.
|
||||
* It is meant to be used in a crowdsale contract.
|
||||
*/
|
||||
contract SampleCrowdsaleToken is ERC20Mintable, ERC20Detailed {
|
||||
constructor () public ERC20Detailed("Sample Crowdsale Token", "SCT", 18) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title SampleCrowdsale
|
||||
* @dev This is an example of a fully fledged crowdsale.
|
||||
* The way to add new features to a base crowdsale is by multiple inheritance.
|
||||
* In this example we are providing following extensions:
|
||||
* CappedCrowdsale - sets a max boundary for raised funds
|
||||
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
|
||||
* MintedCrowdsale - assumes the token can be minted by the crowdsale, which does so
|
||||
* when receiving purchases.
|
||||
*
|
||||
* After adding multiple features it's good practice to run integration tests
|
||||
* to ensure that subcontracts works together as intended.
|
||||
*/
|
||||
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
|
||||
constructor (
|
||||
uint256 openingTime,
|
||||
uint256 closingTime,
|
||||
uint256 rate,
|
||||
address payable wallet,
|
||||
uint256 cap,
|
||||
ERC20Mintable token,
|
||||
uint256 goal
|
||||
)
|
||||
public
|
||||
Crowdsale(rate, wallet, token)
|
||||
CappedCrowdsale(cap)
|
||||
TimedCrowdsale(openingTime, closingTime)
|
||||
RefundableCrowdsale(goal)
|
||||
{
|
||||
//As goal needs to be met for a successful crowdsale
|
||||
//the value needs to less or equal than a cap which is limit for accepted funds
|
||||
require(goal <= cap, "SampleCrowdSale: goal is greater than cap");
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../token/ERC20/ERC20Detailed.sol";
|
||||
|
||||
/**
|
||||
* @title SimpleToken
|
||||
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
|
||||
* Note they can later distribute these tokens as they wish using `transfer` and other
|
||||
* `ERC20` functions.
|
||||
*/
|
||||
contract SimpleToken is Context, ERC20, ERC20Detailed {
|
||||
|
||||
/**
|
||||
* @dev Constructor that gives _msgSender() all of existing tokens.
|
||||
*/
|
||||
constructor () public ERC20Detailed("SimpleToken", "SIM", 18) {
|
||||
_mint(_msgSender(), 10000 * (10 ** uint256(decimals())));
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
@ -30,7 +30,7 @@ contract ERC165 is IERC165 {
|
||||
*
|
||||
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
|
||||
function supportsInterface(bytes4 interfaceId) external view override returns (bool) {
|
||||
return _supportedInterfaces[interfaceId];
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ contract ERC165 is IERC165 {
|
||||
*
|
||||
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
|
||||
*/
|
||||
function _registerInterface(bytes4 interfaceId) internal {
|
||||
function _registerInterface(bytes4 interfaceId) internal virtual {
|
||||
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
|
||||
_supportedInterfaces[interfaceId] = true;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Library used to query support of an interface declared via {IERC165}.
|
||||
@ -94,28 +94,11 @@ library ERC165Checker {
|
||||
function _callERC165SupportsInterface(address account, bytes4 interfaceId)
|
||||
private
|
||||
view
|
||||
returns (bool success, bool result)
|
||||
returns (bool, bool)
|
||||
{
|
||||
bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId);
|
||||
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly {
|
||||
let encodedParams_data := add(0x20, encodedParams)
|
||||
let encodedParams_size := mload(encodedParams)
|
||||
|
||||
let output := mload(0x40) // Find empty storage location using "free memory pointer"
|
||||
mstore(output, 0x0)
|
||||
|
||||
success := staticcall(
|
||||
30000, // 30k gas
|
||||
account, // To addr
|
||||
encodedParams_data,
|
||||
encodedParams_size,
|
||||
output,
|
||||
0x20 // Outputs are 32 bytes long
|
||||
)
|
||||
|
||||
result := mload(output) // Load the result
|
||||
}
|
||||
(bool success, bytes memory result) = account.staticcall.gas(30000)(encodedParams);
|
||||
if (result.length < 32) return (false, false);
|
||||
return (success, abi.decode(result, (bool)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./IERC1820Implementer.sol";
|
||||
|
||||
@ -18,7 +18,7 @@ contract ERC1820Implementer is IERC1820Implementer {
|
||||
/**
|
||||
* See {IERC1820Implementer-canImplementInterfaceForAddress}.
|
||||
*/
|
||||
function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view returns (bytes32) {
|
||||
function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view override returns (bytes32) {
|
||||
return _supportedInterfaces[interfaceHash][account] ? ERC1820_ACCEPT_MAGIC : bytes32(0x00);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ contract ERC1820Implementer is IERC1820Implementer {
|
||||
* See {IERC1820Registry-setInterfaceImplementer} and
|
||||
* {IERC1820Registry-interfaceHash}.
|
||||
*/
|
||||
function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal {
|
||||
function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
|
||||
_supportedInterfaces[interfaceHash][account] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Interface of the ERC165 standard, as defined in the
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Interface for an ERC1820 implementer, as defined in the
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Interface of the global ERC1820 Registry, as defined in the
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
= Introspection
|
||||
|
||||
This set of interfaces and contracts deal with [type introspection](https://en.wikipedia.org/wiki/Type_introspection) of contracts, that is, examining which functions can be called on them. This is usually referred to as a contract's _interface_.
|
||||
This set of interfaces and contracts deal with https://en.wikipedia.org/wiki/Type_introspection[type introspection] of contracts, that is, examining which functions can be called on them. This is usually referred to as a contract's _interface_.
|
||||
|
||||
Ethereum contracts have no native concept of an interface, so applications must usually simply trust they are not making an incorrect call. For trusted setups this is a non-issue, but often unknown and untrusted third-party addresses need to be interacted with. There may even not be any direct calls to them! (e.g. `ERC20` tokens may be sent to a contract that lacks a way to transfer them out of it, locking them forever). In these cases, a contract _declaring_ its interface can be very helpful in preventing errors.
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Standard math utilities missing in the Solidity language.
|
||||
|
||||
@ -6,4 +6,6 @@ These are math-related utilities.
|
||||
|
||||
{{SafeMath}}
|
||||
|
||||
{{SignedSafeMath}}
|
||||
|
||||
{{Math}}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Wrappers over Solidity's arithmetic operations with added overflow
|
||||
@ -51,8 +51,6 @@ library SafeMath {
|
||||
*
|
||||
* Requirements:
|
||||
* - Subtraction cannot overflow.
|
||||
*
|
||||
* _Available since v2.4.0._
|
||||
*/
|
||||
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
|
||||
require(b <= a, errorMessage);
|
||||
@ -109,8 +107,6 @@ library SafeMath {
|
||||
*
|
||||
* Requirements:
|
||||
* - The divisor cannot be zero.
|
||||
*
|
||||
* _Available since v2.4.0._
|
||||
*/
|
||||
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
|
||||
// Solidity only automatically asserts when dividing by 0
|
||||
@ -146,8 +142,6 @@ library SafeMath {
|
||||
*
|
||||
* Requirements:
|
||||
* - The divisor cannot be zero.
|
||||
*
|
||||
* _Available since v2.4.0._
|
||||
*/
|
||||
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
|
||||
require(b != 0, errorMessage);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @title SignedSafeMath
|
||||
13
contracts/mocks/AccessControlMock.sol
Normal file
13
contracts/mocks/AccessControlMock.sol
Normal file
@ -0,0 +1,13 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../access/AccessControl.sol";
|
||||
|
||||
contract AccessControlMock is AccessControl {
|
||||
constructor() public {
|
||||
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
||||
}
|
||||
|
||||
function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public {
|
||||
_setRoleAdmin(roleId, adminRoleId);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../utils/Address.sol";
|
||||
|
||||
@ -7,13 +7,10 @@ contract AddressImpl {
|
||||
return Address.isContract(account);
|
||||
}
|
||||
|
||||
function toPayable(address account) external pure returns (address payable) {
|
||||
return Address.toPayable(account);
|
||||
}
|
||||
|
||||
function sendValue(address payable receiver, uint256 amount) external {
|
||||
Address.sendValue(receiver, amount);
|
||||
}
|
||||
|
||||
function () external payable { } // sendValue's tests require the contract to hold Ether
|
||||
// sendValue's tests require the contract to hold Ether
|
||||
receive () external payable { }
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/IERC20.sol";
|
||||
import "../crowdsale/emission/AllowanceCrowdsale.sol";
|
||||
|
||||
contract AllowanceCrowdsaleImpl is AllowanceCrowdsale {
|
||||
constructor (uint256 rate, address payable wallet, IERC20 token, address tokenWallet)
|
||||
public
|
||||
Crowdsale(rate, wallet, token)
|
||||
AllowanceCrowdsale(tokenWallet)
|
||||
{
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../utils/Arrays.sol";
|
||||
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/IERC20.sol";
|
||||
import "../crowdsale/validation/CappedCrowdsale.sol";
|
||||
|
||||
contract CappedCrowdsaleImpl is CappedCrowdsale {
|
||||
constructor (uint256 rate, address payable wallet, IERC20 token, uint256 cap)
|
||||
public
|
||||
Crowdsale(rate, wallet, token)
|
||||
CappedCrowdsale(cap)
|
||||
{
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../access/roles/CapperRole.sol";
|
||||
|
||||
contract CapperRoleMock is CapperRole {
|
||||
function removeCapper(address account) public {
|
||||
_removeCapper(account);
|
||||
}
|
||||
|
||||
function onlyCapperMock() public view onlyCapper {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
|
||||
// Causes a compilation error if super._removeCapper is not internal
|
||||
function _removeCapper(address account) internal {
|
||||
super._removeCapper(account);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../payment/escrow/ConditionalEscrow.sol";
|
||||
|
||||
@ -10,7 +10,7 @@ contract ConditionalEscrowMock is ConditionalEscrow {
|
||||
_allowed[payee] = allowed;
|
||||
}
|
||||
|
||||
function withdrawalAllowed(address payee) public view returns (bool) {
|
||||
function withdrawalAllowed(address payee) public view override returns (bool) {
|
||||
return _allowed[payee];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../drafts/Counters.sol";
|
||||
import "../utils/Counters.sol";
|
||||
|
||||
contract CountersImpl {
|
||||
using Counters for Counters.Counter;
|
||||
|
||||
23
contracts/mocks/Create2Impl.sol
Normal file
23
contracts/mocks/Create2Impl.sol
Normal file
@ -0,0 +1,23 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../utils/Create2.sol";
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
|
||||
contract Create2Impl {
|
||||
function deploy(bytes32 salt, bytes memory code) public {
|
||||
Create2.deploy(salt, code);
|
||||
}
|
||||
|
||||
function deployERC20(bytes32 salt) public {
|
||||
// solhint-disable-next-line indent
|
||||
Create2.deploy(salt, type(ERC20).creationCode);
|
||||
}
|
||||
|
||||
function computeAddress(bytes32 salt, bytes32 codeHash) public view returns (address) {
|
||||
return Create2.computeAddress(salt, codeHash);
|
||||
}
|
||||
|
||||
function computeAddressWithDeployer(bytes32 salt, bytes32 codeHash, address deployer) public pure returns (address) {
|
||||
return Create2.computeAddress(salt, codeHash, deployer);
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../crowdsale/Crowdsale.sol";
|
||||
|
||||
contract CrowdsaleMock is Crowdsale {
|
||||
constructor (uint256 rate, address payable wallet, IERC20 token) public Crowdsale(rate, wallet, token) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../cryptography/ECDSA.sol";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../../introspection/IERC165.sol";
|
||||
|
||||
@ -34,7 +34,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 {
|
||||
/**
|
||||
* @dev Implement supportsInterface(bytes4) using a lookup table.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
|
||||
function supportsInterface(bytes4 interfaceId) external view override returns (bool) {
|
||||
return _supportedInterfaces[interfaceId];
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
contract ERC165NotSupported {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
contract ERC165NotSupported { }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../introspection/ERC165Checker.sol";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../introspection/ERC165.sol";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../introspection/ERC1820Implementer.sol";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/ERC20Burnable.sol";
|
||||
|
||||
|
||||
11
contracts/mocks/ERC20CappedMock.sol
Normal file
11
contracts/mocks/ERC20CappedMock.sol
Normal file
@ -0,0 +1,11 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/ERC20Capped.sol";
|
||||
|
||||
contract ERC20CappedMock is ERC20Capped {
|
||||
constructor (uint256 cap) public ERC20Capped(cap) { }
|
||||
|
||||
function mint(address to, uint256 tokenId) public {
|
||||
_mint(to, tokenId);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../token/ERC20/ERC20Detailed.sol";
|
||||
@ -8,6 +8,6 @@ contract ERC20DetailedMock is ERC20, ERC20Detailed {
|
||||
public
|
||||
ERC20Detailed(name, symbol, decimals)
|
||||
{
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../drafts/ERC1046/ERC20Metadata.sol";
|
||||
|
||||
contract ERC20MetadataMock is ERC20, ERC20Metadata {
|
||||
constructor (string memory tokenURI) public ERC20Metadata(tokenURI) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
|
||||
function setTokenURI(string memory tokenURI) public {
|
||||
_setTokenURI(tokenURI);
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/ERC20Mintable.sol";
|
||||
import "./MinterRoleMock.sol";
|
||||
|
||||
contract ERC20MintableMock is ERC20Mintable, MinterRoleMock {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
|
||||
@ -16,10 +16,6 @@ contract ERC20Mock is ERC20 {
|
||||
_burn(account, amount);
|
||||
}
|
||||
|
||||
function burnFrom(address account, uint256 amount) public {
|
||||
_burnFrom(account, amount);
|
||||
}
|
||||
|
||||
function transferInternal(address from, address to, uint256 value) public {
|
||||
_transfer(from, to, value);
|
||||
}
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC20/ERC20Pausable.sol";
|
||||
import "./PauserRoleMock.sol";
|
||||
|
||||
// mock class using ERC20Pausable
|
||||
contract ERC20PausableMock is ERC20Pausable, PauserRoleMock {
|
||||
contract ERC20PausableMock is ERC20Pausable {
|
||||
constructor (address initialAccount, uint256 initialBalance) public {
|
||||
_mint(initialAccount, initialBalance);
|
||||
}
|
||||
|
||||
function pause() external {
|
||||
_pause();
|
||||
}
|
||||
|
||||
function unpause() external {
|
||||
_unpause();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../drafts/ERC20Snapshot.sol";
|
||||
import "../token/ERC20/ERC20Snapshot.sol";
|
||||
|
||||
|
||||
contract ERC20SnapshotMock is ERC20Snapshot {
|
||||
@ -8,6 +8,10 @@ contract ERC20SnapshotMock is ERC20Snapshot {
|
||||
_mint(initialAccount, initialBalance);
|
||||
}
|
||||
|
||||
function snapshot() public {
|
||||
_snapshot();
|
||||
}
|
||||
|
||||
function mint(address account, uint256 amount) public {
|
||||
_mint(account, amount);
|
||||
}
|
||||
|
||||
9
contracts/mocks/ERC721BurnableMock.sol
Normal file
9
contracts/mocks/ERC721BurnableMock.sol
Normal file
@ -0,0 +1,9 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/ERC721Burnable.sol";
|
||||
|
||||
contract ERC721BurnableMock is ERC721Burnable {
|
||||
function mint(address to, uint256 tokenId) public {
|
||||
_mint(to, tokenId);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/ERC721Full.sol";
|
||||
import "../token/ERC721/ERC721Mintable.sol";
|
||||
import "../token/ERC721/ERC721MetadataMintable.sol";
|
||||
import "../token/ERC721/ERC721Burnable.sol";
|
||||
|
||||
/**
|
||||
@ -10,10 +8,8 @@ import "../token/ERC721/ERC721Burnable.sol";
|
||||
* This mock just provides public functions for setting metadata URI, getting all tokens of an owner,
|
||||
* checking token existence, removal of a token from an address
|
||||
*/
|
||||
contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
|
||||
constructor (string memory name, string memory symbol) public ERC721Mintable() ERC721Full(name, symbol) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
contract ERC721FullMock is ERC721Full, ERC721Burnable {
|
||||
constructor (string memory name, string memory symbol) public ERC721Full(name, symbol) { }
|
||||
|
||||
function exists(uint256 tokenId) public view returns (bool) {
|
||||
return _exists(tokenId);
|
||||
@ -26,4 +22,16 @@ contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, E
|
||||
function setTokenURI(uint256 tokenId, string memory uri) public {
|
||||
_setTokenURI(tokenId, uri);
|
||||
}
|
||||
|
||||
function setBaseURI(string memory baseURI) public {
|
||||
_setBaseURI(baseURI);
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Full) {
|
||||
super._beforeTokenTransfer(from, to, tokenId);
|
||||
}
|
||||
|
||||
function mint(address to, uint256 tokenId) public {
|
||||
_mint(to, tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/ERC721.sol";
|
||||
import "../GSN/GSNRecipient.sol";
|
||||
@ -10,9 +10,16 @@ import "../GSN/GSNRecipientSignature.sol";
|
||||
*/
|
||||
contract ERC721GSNRecipientMock is ERC721, GSNRecipient, GSNRecipientSignature {
|
||||
constructor(address trustedSigner) public GSNRecipientSignature(trustedSigner) { }
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
|
||||
function mint(uint256 tokenId) public {
|
||||
_mint(_msgSender(), tokenId);
|
||||
}
|
||||
|
||||
function _msgSender() internal view override(Context, GSNRecipient) returns (address payable) {
|
||||
return GSNRecipient._msgSender();
|
||||
}
|
||||
|
||||
function _msgData() internal view override(Context, GSNRecipient) returns (bytes memory) {
|
||||
return GSNRecipient._msgData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC721/ERC721Full.sol";
|
||||
import "../token/ERC721/ERC721Mintable.sol";
|
||||
import "../token/ERC721/ERC721MetadataMintable.sol";
|
||||
import "../token/ERC721/ERC721Burnable.sol";
|
||||
|
||||
/**
|
||||
* @title ERC721MintableBurnableImpl
|
||||
*/
|
||||
contract ERC721MintableBurnableImpl is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
|
||||
constructor () public ERC721Mintable() ERC721Full("Test", "TEST") {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/ERC721.sol";
|
||||
|
||||
@ -19,10 +19,6 @@ contract ERC721Mock is ERC721 {
|
||||
_mint(to, tokenId);
|
||||
}
|
||||
|
||||
function burn(address owner, uint256 tokenId) public {
|
||||
_burn(owner, tokenId);
|
||||
}
|
||||
|
||||
function burn(uint256 tokenId) public {
|
||||
_burn(tokenId);
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/ERC721Pausable.sol";
|
||||
import "./PauserRoleMock.sol";
|
||||
|
||||
/**
|
||||
* @title ERC721PausableMock
|
||||
* This mock just provides a public mint, burn and exists functions for testing purposes
|
||||
*/
|
||||
contract ERC721PausableMock is ERC721Pausable, PauserRoleMock {
|
||||
contract ERC721PausableMock is ERC721Pausable {
|
||||
function mint(address to, uint256 tokenId) public {
|
||||
super._mint(to, tokenId);
|
||||
}
|
||||
@ -19,4 +18,12 @@ contract ERC721PausableMock is ERC721Pausable, PauserRoleMock {
|
||||
function exists(uint256 tokenId) public view returns (bool) {
|
||||
return super._exists(tokenId);
|
||||
}
|
||||
|
||||
function pause() external {
|
||||
_pause();
|
||||
}
|
||||
|
||||
function unpause() external {
|
||||
_unpause();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../token/ERC721/IERC721Receiver.sol";
|
||||
|
||||
@ -14,7 +14,7 @@ contract ERC721ReceiverMock is IERC721Receiver {
|
||||
}
|
||||
|
||||
function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data)
|
||||
public returns (bytes4)
|
||||
public override returns (bytes4)
|
||||
{
|
||||
require(!_reverts, "ERC721ReceiverMock: reverting");
|
||||
emit Received(operator, from, tokenId, data, gasleft());
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
import "../token/ERC777/ERC777.sol";
|
||||
@ -11,16 +11,15 @@ contract ERC777Mock is Context, ERC777 {
|
||||
string memory symbol,
|
||||
address[] memory defaultOperators
|
||||
) public ERC777(name, symbol, defaultOperators) {
|
||||
_mint(_msgSender(), initialHolder, initialBalance, "", "");
|
||||
_mint(initialHolder, initialBalance, "", "");
|
||||
}
|
||||
|
||||
function mintInternal (
|
||||
address operator,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes memory userData,
|
||||
bytes memory operatorData
|
||||
) public {
|
||||
_mint(operator, to, amount, userData, operatorData);
|
||||
_mint(to, amount, userData, operatorData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/Context.sol";
|
||||
import "../token/ERC777/IERC777.sol";
|
||||
@ -47,7 +47,7 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
|
||||
uint256 amount,
|
||||
bytes calldata userData,
|
||||
bytes calldata operatorData
|
||||
) external {
|
||||
) external override {
|
||||
if (_shouldRevertSend) {
|
||||
revert();
|
||||
}
|
||||
@ -78,7 +78,7 @@ contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient,
|
||||
uint256 amount,
|
||||
bytes calldata userData,
|
||||
bytes calldata operatorData
|
||||
) external{
|
||||
) external override {
|
||||
if (_shouldRevertReceive) {
|
||||
revert();
|
||||
}
|
||||
|
||||
37
contracts/mocks/EnumerableSetMock.sol
Normal file
37
contracts/mocks/EnumerableSetMock.sol
Normal file
@ -0,0 +1,37 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../utils/EnumerableSet.sol";
|
||||
|
||||
contract EnumerableSetMock{
|
||||
using EnumerableSet for EnumerableSet.AddressSet;
|
||||
|
||||
event TransactionResult(bool result);
|
||||
|
||||
EnumerableSet.AddressSet private set;
|
||||
|
||||
function contains(address value) public view returns (bool) {
|
||||
return set.contains(value);
|
||||
}
|
||||
|
||||
function add(address value) public {
|
||||
bool result = set.add(value);
|
||||
emit TransactionResult(result);
|
||||
}
|
||||
|
||||
function remove(address value) public {
|
||||
bool result = set.remove(value);
|
||||
emit TransactionResult(result);
|
||||
}
|
||||
|
||||
function enumerate() public view returns (address[] memory) {
|
||||
return set.enumerate();
|
||||
}
|
||||
|
||||
function length() public view returns (uint256) {
|
||||
return set.length();
|
||||
}
|
||||
|
||||
function get(uint256 index) public view returns (address) {
|
||||
return set.get(index);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
contract EtherReceiverMock {
|
||||
bool private _acceptEther;
|
||||
@ -7,7 +7,7 @@ contract EtherReceiverMock {
|
||||
_acceptEther = acceptEther;
|
||||
}
|
||||
|
||||
function () external payable {
|
||||
receive () external payable {
|
||||
if (!_acceptEther) {
|
||||
revert();
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "../token/ERC20/IERC20.sol";
|
||||
import "../crowdsale/distribution/FinalizableCrowdsale.sol";
|
||||
|
||||
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
|
||||
constructor (uint256 openingTime, uint256 closingTime, uint256 rate, address payable wallet, IERC20 token)
|
||||
public
|
||||
Crowdsale(rate, wallet, token)
|
||||
TimedCrowdsale(openingTime, closingTime)
|
||||
{
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,10 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/GSNRecipient.sol";
|
||||
import "../GSN/GSNRecipientERC20Fee.sol";
|
||||
|
||||
contract GSNRecipientERC20FeeMock is GSNRecipient, GSNRecipientERC20Fee {
|
||||
constructor(string memory name, string memory symbol) public GSNRecipientERC20Fee(name, symbol) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
constructor(string memory name, string memory symbol) public GSNRecipientERC20Fee(name, symbol) { }
|
||||
|
||||
function mint(address account, uint256 amount) public {
|
||||
_mint(account, amount);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "./ContextMock.sol";
|
||||
import "../GSN/GSNRecipient.sol";
|
||||
@ -12,20 +12,25 @@ contract GSNRecipientMock is ContextMock, GSNRecipient {
|
||||
function acceptRelayedCall(address, address, bytes calldata, uint256, uint256, uint256, uint256, bytes calldata, uint256)
|
||||
external
|
||||
view
|
||||
override
|
||||
returns (uint256, bytes memory)
|
||||
{
|
||||
return (0, "");
|
||||
}
|
||||
|
||||
function _preRelayedCall(bytes memory) internal returns (bytes32) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
function _preRelayedCall(bytes memory) internal override returns (bytes32) { }
|
||||
|
||||
function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal override { }
|
||||
|
||||
function upgradeRelayHub(address newRelayHub) public {
|
||||
return _upgradeRelayHub(newRelayHub);
|
||||
}
|
||||
|
||||
function _msgSender() internal override(Context, GSNRecipient) view virtual returns (address payable) {
|
||||
return GSNRecipient._msgSender();
|
||||
}
|
||||
|
||||
function _msgData() internal override(Context, GSNRecipient) view virtual returns (bytes memory) {
|
||||
return GSNRecipient._msgData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
pragma solidity ^0.5.0;
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../GSN/GSNRecipient.sol";
|
||||
import "../GSN/GSNRecipientSignature.sol";
|
||||
|
||||
contract GSNRecipientSignatureMock is GSNRecipient, GSNRecipientSignature {
|
||||
constructor(address trustedSigner) public GSNRecipientSignature(trustedSigner) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
constructor(address trustedSigner) public GSNRecipientSignature(trustedSigner) { }
|
||||
|
||||
event MockFunctionCalled();
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user