Compare commits
90 Commits
v1.9.1
...
v1.12.0-rc
| Author | SHA1 | Date | |
|---|---|---|---|
| 3806d6128e | |||
| 4d799f3cbe | |||
| 07a27f0e5e | |||
| ca9e317259 | |||
| 9638ecd87a | |||
| 56735a706c | |||
| 2765350248 | |||
| 1200969eb6 | |||
| 90b98a7bef | |||
| 16429b1522 | |||
| ae2980b072 | |||
| f5b0bb3246 | |||
| 4c6575bf2f | |||
| 2f6c8b05f6 | |||
| 567b773242 | |||
| 6e19ed47be | |||
| e6c15b34da | |||
| afe9113b18 | |||
| 73be06412f | |||
| 23074676c4 | |||
| 3c69cf658c | |||
| 6bd8842ab5 | |||
| d20d03c149 | |||
| ebd4b5e73d | |||
| 1ecda54449 | |||
| 67b67b791e | |||
| ce0c3274ee | |||
| 90b3050ad7 | |||
| c95ea5125d | |||
| 11266b0d56 | |||
| 45d6943913 | |||
| 5f6d511af9 | |||
| 7dbb7a8b8e | |||
| 3318b91697 | |||
| cea2a85a42 | |||
| 99e4b081dc | |||
| b120b9aff7 | |||
| cc9fa57777 | |||
| 40b5594f52 | |||
| 4575a240f7 | |||
| eb4dfea6e9 | |||
| 8fd072cf8e | |||
| c2ad8c3f57 | |||
| fd253d6b8d | |||
| 7d8e3ca8b2 | |||
| 6b37ba36a1 | |||
| dc1e352cc4 | |||
| f18c3bc438 | |||
| 0047e79681 | |||
| 74a62a1314 | |||
| 92b695f2fb | |||
| ee78f67985 | |||
| 07020e9544 | |||
| b4406d385f | |||
| 78e39aa2ad | |||
| e4ed8f0705 | |||
| 5daaf60d11 | |||
| e1dc1411fc | |||
| 9f1d294ba4 | |||
| 9951acf6d8 | |||
| 72792a724d | |||
| b0292cf628 | |||
| 39385f9f4e | |||
| 7a61371b19 | |||
| 259b9da3e6 | |||
| 5326e7c36e | |||
| feb665136c | |||
| 7fb84b42d5 | |||
| 5db0d7d1a0 | |||
| 512e8218ca | |||
| 9d6ffae8cb | |||
| 2a997a8e92 | |||
| 5651538045 | |||
| 10e84aecaf | |||
| 2637bd89be | |||
| 32ec8b5398 | |||
| a0c03ee61c | |||
| e3f866c982 | |||
| 5ab9024b6a | |||
| d5f06ab32f | |||
| 746673a94f | |||
| ba4cf03da7 | |||
| 39370ff690 | |||
| ad12381549 | |||
| 20b85be6aa | |||
| 4223c9d50e | |||
| f0eea31bdf | |||
| ce0a928a6c | |||
| 85f079ee89 | |||
| 7e44204d9b |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@ -0,0 +1,12 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
47
.eslintrc
47
.eslintrc
@ -21,31 +21,34 @@
|
||||
"rules": {
|
||||
|
||||
// Strict mode
|
||||
"strict": [2, "global"],
|
||||
"strict": ["error", "global"],
|
||||
|
||||
// Code style
|
||||
"indent": [2, 2],
|
||||
"quotes": [2, "single"],
|
||||
"camelcase": ["error", {"properties": "always"}],
|
||||
"comma-dangle": ["warn", "always-multiline"],
|
||||
"comma-spacing": ["error", {"before": false, "after": true}],
|
||||
"dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}],
|
||||
"eol-last": ["error", "always"],
|
||||
"eqeqeq": ["error", "smart"],
|
||||
"generator-star-spacing": ["error", "before"],
|
||||
"indent": ["error", 2],
|
||||
"max-len": ["error", 120, 2],
|
||||
"no-debugger": "off",
|
||||
"no-dupe-args": "error",
|
||||
"no-dupe-keys": "error",
|
||||
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
|
||||
"no-redeclare": ["error", {"builtinGlobals": true}],
|
||||
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
|
||||
"no-undef": "error",
|
||||
"no-use-before-define": "off",
|
||||
"no-var": "error",
|
||||
"object-curly-spacing": ["error", "always"],
|
||||
"prefer-const": "error",
|
||||
"quotes": ["error", "single"],
|
||||
"semi": ["error", "always"],
|
||||
"space-before-function-paren": ["error", "always"],
|
||||
"no-use-before-define": 0,
|
||||
"eqeqeq": [2, "smart"],
|
||||
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
|
||||
"no-redeclare": [2, {"builtinGlobals": true}],
|
||||
"no-trailing-spaces": [2, { "skipBlankLines": true }],
|
||||
"eol-last": 1,
|
||||
"comma-spacing": [2, {"before": false, "after": true}],
|
||||
"camelcase": [2, {"properties": "always"}],
|
||||
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
||||
"comma-dangle": [1, "always-multiline"],
|
||||
"no-dupe-args": 2,
|
||||
"no-dupe-keys": 2,
|
||||
"no-debugger": 0,
|
||||
"no-undef": 2,
|
||||
"object-curly-spacing": [2, "always"],
|
||||
"max-len": [2, 120, 2],
|
||||
"generator-star-spacing": ["error", "before"],
|
||||
"promise/avoid-new": 0,
|
||||
"promise/always-return": 0
|
||||
|
||||
"promise/always-return": "off",
|
||||
"promise/avoid-new": "off",
|
||||
}
|
||||
}
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -34,3 +34,6 @@ build/
|
||||
|
||||
# lol macs
|
||||
.DS_Store/
|
||||
|
||||
# truffle
|
||||
.node-xmlhttprequest-*
|
||||
|
||||
48
.jshintrc
48
.jshintrc
@ -1,48 +0,0 @@
|
||||
{
|
||||
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
|
||||
"browser": true, // Standard browser globals e.g. `window`, `document`.
|
||||
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
|
||||
"curly": true, // Require {} for every new block or scope.
|
||||
"devel": false, // Allow development statements e.g. `console.log();`.
|
||||
"eqeqeq": true, // Require triple equals i.e. `===`.
|
||||
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
|
||||
"freeze": true, // Forbid overwriting prototypes of native objects such as Array, Date and so on.
|
||||
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
||||
"indent": 2, // Specify indentation spacing
|
||||
"latedef": true, // Prohibit variable use before definition.
|
||||
"newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
|
||||
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
||||
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
|
||||
"noempty": true, // Prohibit use of empty blocks.
|
||||
"nonew": true, // Prohibits the use of constructor functions for side-effects
|
||||
"quotmark": "single", // Define quotes to string values.
|
||||
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
|
||||
"smarttabs": false, // Supress warnings about mixed tabs and spaces
|
||||
"strict": true, // Require `use strict` pragma in every file.
|
||||
"trailing": true, // Prohibit trailing whitespaces.
|
||||
"undef": true, // Require all non-global variables be declared before they are used.
|
||||
"unused": true, // Warn unused variables.
|
||||
|
||||
"maxparams": 4, // Maximum number of parameters for a function
|
||||
"maxstatements": 15, // Maximum number of statements in a function
|
||||
"maxcomplexity": 10, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
|
||||
"maxdepth": 4, // Maximum depth of nested control structures
|
||||
"maxlen": 120, // Maximum number of cols in a line
|
||||
"multistr": true, // Allow use of multiline EOL escaping
|
||||
"experimental": ["asyncawait", "asyncreqawait"],
|
||||
|
||||
"predef": [ // Extra globals.
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach",
|
||||
"define",
|
||||
"describe",
|
||||
"exports",
|
||||
"it",
|
||||
"web3",
|
||||
"artifacts",
|
||||
"contract",
|
||||
"assert"
|
||||
]
|
||||
}
|
||||
@ -2,10 +2,14 @@
|
||||
"extends": "solium:all",
|
||||
"plugins": ["security"],
|
||||
"rules": {
|
||||
"quotes": ["error", "double"],
|
||||
"no-empty-blocks": "off",
|
||||
"error-reason": "off",
|
||||
"indentation": ["error", 2],
|
||||
"arg-overflow": ["warning", 3],
|
||||
"max-len": ["warning", 79],
|
||||
"no-constant": ["error"],
|
||||
"no-empty-blocks": "off",
|
||||
"quotes": ["error", "double"],
|
||||
"uppercase": "off",
|
||||
|
||||
"security/enforce-explicit-visibility": ["error"],
|
||||
"security/no-block-members": ["warning"],
|
||||
"security/no-inline-assembly": ["warning"]
|
||||
|
||||
73
CODE_OF_CONDUCT.md
Normal file
73
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,73 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at maintainers@openzeppelin.org. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
@ -20,13 +20,13 @@ As a contributor, you are expected to fork this repository, work on your own for
|
||||
|
||||
```
|
||||
cd openzeppelin-solidity
|
||||
git remote add upstream https://github.com/OpenZeppelin/openzeppelin-solidity.git
|
||||
git fetch upstream
|
||||
git checkout development
|
||||
git pull --rebase upstream development
|
||||
git pull --rebase upstream master
|
||||
```
|
||||
NOTE: The directory `openzeppelin-solidity` represents your fork's local copy.
|
||||
|
||||
2) Branch out from `development` into `fix/some-bug-#123`:
|
||||
2) Branch out from `master` into `fix/some-bug-#123`:
|
||||
(Postfixing #123 will associate your PR with the issue #123 and make everyone's life easier =D)
|
||||
```
|
||||
git checkout -b fix/some-bug-#123
|
||||
|
||||
73
README.md
73
README.md
@ -13,7 +13,11 @@ With OpenZeppelin, you can build distributed applications, protocols and organiz
|
||||
|
||||
## Getting Started
|
||||
|
||||
OpenZeppelin integrates with [Truffle](https://github.com/ConsenSys/truffle), an Ethereum development environment. Please install Truffle and initialize your project with `truffle init`.
|
||||
OpenZeppelin integrates with [Truffle](https://github.com/ConsenSys/truffle) and [Embark](https://github.com/embark-framework/embark/).
|
||||
|
||||
## truffle
|
||||
|
||||
To use with Truffle, first install it and initialize your project with `truffle init`.
|
||||
|
||||
```sh
|
||||
npm install -g truffle
|
||||
@ -21,7 +25,20 @@ mkdir myproject && cd myproject
|
||||
truffle init
|
||||
```
|
||||
|
||||
To install the OpenZeppelin library, run the following in your Solidity project root directory:
|
||||
## Embark
|
||||
|
||||
To use with Embark, first install it and initialize your project with `embark new MyApp`.
|
||||
|
||||
```sh
|
||||
npm install -g embark
|
||||
embark new MyApp
|
||||
cd MyApp
|
||||
```
|
||||
|
||||
## Installing OpenZeppelin
|
||||
|
||||
After installing either Framework, to install the OpenZeppelin library, run the following in your Solidity project root directory:
|
||||
|
||||
```sh
|
||||
npm init -y
|
||||
npm install -E openzeppelin-solidity
|
||||
@ -39,10 +56,60 @@ contract MyContract is Ownable {
|
||||
}
|
||||
```
|
||||
|
||||
If you are using Embark, you can also import directly from github:
|
||||
|
||||
```solidity
|
||||
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol#v1.9.0";
|
||||
|
||||
contract MyContract is Ownable {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Architecture
|
||||
The following provides visibility into how OpenZeppelin's contracts are organized:
|
||||
|
||||
- **access** - Smart contracts that enable functionality that can be used for selective restrictions and basic authorization control functions. Includes address whitelisting and signature-based permissions management.
|
||||
- **rbac** - A library used to manage addresses assigned to different user roles and an example Role-Based Access Control (RBAC) interface that demonstrates how to handle setters and getters for roles and addresses.
|
||||
- **crowdsale** - A collection of smart contracts used to manage token crowdsales that allow investors to purchase tokens with ETH. Includes a base contract which implements fundamental crowdsale functionality in its simplest form. The base contract can be extended in order to satisfy your crowdsale’s specific requirements.
|
||||
- **distribution** - Includes extensions of the base crowdsale contract which can be used to customize the completion of a crowdsale.
|
||||
- **emission** - Includes extensions of the base crowdsale contract which can be used to mint and manage how tokens are issued to purchasers.
|
||||
- **price** - Includes extensions of the crowdsale contract that can be used to manage changes in token prices.
|
||||
- **validation** - Includes extensions of the crowdsale contract that can be used to enforce restraints and limit access to token purchases.
|
||||
- **examples** - A collection of simple smart contracts that demonstrate how to add new features to base contracts through multiple inheritance.
|
||||
- **introspection** - An interface that can be used to make a contract comply with the ERC-165 standard as well as a contract that implements ERC-165 using a lookup table.
|
||||
- **lifecycle** - A collection of base contracts used to manage the existence and behavior of your contracts and their funds.
|
||||
- **math** - Libraries with safety checks on operations that throw on errors.
|
||||
- **mocks** - A collection of abstract contracts that are primarily used for unit testing. They also serve as good usage examples and demonstrate how to combine contracts with inheritence when developing your own custom applciations.
|
||||
- **ownership** - A collection of smart contracts that can be used to manage contract and token ownership
|
||||
- **payment** - A collection of smart contracts that can be used to manage payments through escrow arrangements, withdrawals, and claims. Includes support for both single payees and multiple payees.
|
||||
- **proposals** - A collection of smart contracts that reflect community Ethereum Improvement Proposals (EIPs). These contracts are under development and standardization. They are not recommended for production, but they are useful for experimentation with pending EIP standards. Go [here](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/ERC-Process) for more information.
|
||||
|
||||
- **token** - A collection of approved ERC standard tokens -- their interfaces and implementations.
|
||||
- **ERC20** - A standard interface for fungible tokens:
|
||||
- *Interfaces* - Includes the ERC-20 token standard basic interface. I.e., what the contract’s ABI can represent.
|
||||
- *Implementations* - Includes ERC-20 token implementations that include all required and some optional ERC-20 functionality.
|
||||
- **ERC721** - A standard interface for non-fungible tokens
|
||||
- *Interfaces* - Includes the ERC-721 token standard basic interface. I.e., what the contract’s ABI can represent.
|
||||
- *Implementations* - Includes ERC-721 token implementations that include all required and some optional ERC-721 functionality.
|
||||
|
||||
## Tests
|
||||
Unit test are critical to the OpenZeppelin framework. They help ensure code quality and mitigate against security vulnerabilities. The directory structure within the `/tests` directory corresponds to the `/contracts` directory. OpenZeppelin uses Mocha’s JavaScript testing framework and Chai’s assertion library. To learn more about how to tests are structured, please reference OpenZeppelin’s Testing Guide.
|
||||
|
||||
## How To Use And Modify OpenZeppelin Contracts
|
||||
When using OpenZeppelin to build your own distributed applications, for security reasons we encourage you NOT to modify the framework’s base contracts, libraries, and interfaces. In order to leverage and extend their functionality, we encourage you to inherit from them or compose them together with your own contracts.
|
||||
|
||||
The Solidity programming language supports multiple inheritance. This is very powerful yet it can also be confusing: the more complexity you introduce to your distributed applications through multiple inheritance, the greater your application’s attack surface is.
|
||||
|
||||
You’ll notice in the `/mocks` directory there are a collection of abstract contracts used primarily for unit testing purposes that can also be used as the foundation for your own custom implementations. These mock contracts demonstrate how OpenZeppelin’s secure base contracts can be used with multiple inheritance.
|
||||
|
||||
To learn more about combining OpenZeppelin contracts with your own custom contracts using multiple inheritance we encourage you to read the following: [On crowdsales and multiple inheritance](https://blog.zeppelin.solutions/on-crowdsales-and-multiple-inheritance-af90c694e35f)
|
||||
|
||||
## Security
|
||||
OpenZeppelin is meant to provide secure, 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 problem 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.
|
||||
|
||||
If you find a security issue, please email [security@openzeppelin.org](mailto:security@openzeppelin.org).
|
||||
|
||||
## Developer Resources
|
||||
@ -61,4 +128,4 @@ Interested in contributing to OpenZeppelin?
|
||||
- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki
|
||||
|
||||
## License
|
||||
Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE).
|
||||
Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE).
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
@ -9,11 +9,11 @@ library AddressUtils {
|
||||
/**
|
||||
* Returns whether the target address is a contract
|
||||
* @dev This function will return false if invoked during the constructor of a contract,
|
||||
* as the code is not actually created until after the constructor finishes.
|
||||
* @param addr address to check
|
||||
* as the code is not actually created until after the constructor finishes.
|
||||
* @param _addr address to check
|
||||
* @return whether the target address is a contract
|
||||
*/
|
||||
function isContract(address addr) internal view returns (bool) {
|
||||
function isContract(address _addr) internal view returns (bool) {
|
||||
uint256 size;
|
||||
// XXX Currently there is no better way to check if there is a contract in an address
|
||||
// than to check the size of the code at that address.
|
||||
@ -21,7 +21,8 @@ library AddressUtils {
|
||||
// for more details about how this works.
|
||||
// TODO Check this again before the Serenity release, because all addresses will be
|
||||
// contracts then.
|
||||
assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly { size := extcodesize(_addr) }
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
|
||||
29
contracts/AutoIncrementing.sol
Normal file
29
contracts/AutoIncrementing.sol
Normal file
@ -0,0 +1,29 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title AutoIncrementing
|
||||
* @author Matt Condon (@shrugs)
|
||||
* @dev Provides an auto-incrementing uint256 id acquired by the `Counter#nextId` getter.
|
||||
* Use this for issuing ERC721Token ids or keeping track of request ids, anything you want, really.
|
||||
*
|
||||
* Include with `using AutoIncrementing for AutoIncrementing.Counter;`
|
||||
* @notice Does not allow an Id of 0, which is popularly used to signify a null state in solidity.
|
||||
* Does not protect from overflows, but if you have 2^256 ids, you have other problems.
|
||||
* (But actually, it's generally impossible to increment a counter this many times, energy wise
|
||||
* so it's not something you have to worry about.)
|
||||
*/
|
||||
library AutoIncrementing {
|
||||
|
||||
struct Counter {
|
||||
uint256 prevId; // default: 0
|
||||
}
|
||||
|
||||
function nextId(Counter storage _counter)
|
||||
internal
|
||||
returns (uint256)
|
||||
{
|
||||
_counter.prevId = _counter.prevId + 1;
|
||||
return _counter.prevId;
|
||||
}
|
||||
}
|
||||
72
contracts/Bounty.sol
Normal file
72
contracts/Bounty.sol
Normal file
@ -0,0 +1,72 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "./payment/PullPayment.sol";
|
||||
import "./lifecycle/Destructible.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Bounty
|
||||
* @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
|
||||
*/
|
||||
contract Bounty is PullPayment, Destructible {
|
||||
bool public claimed;
|
||||
mapping(address => address) public researchers;
|
||||
|
||||
event TargetCreated(address createdAddress);
|
||||
|
||||
/**
|
||||
* @dev Fallback function allowing the contract to receive funds, if they haven't already been claimed.
|
||||
*/
|
||||
function() external payable {
|
||||
require(!claimed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Create and deploy the target contract (extension of Target contract), and sets the
|
||||
* msg.sender as a researcher
|
||||
* @return A target contract
|
||||
*/
|
||||
function createTarget() public returns(Target) {
|
||||
Target target = Target(deployContract());
|
||||
researchers[target] = msg.sender;
|
||||
emit TargetCreated(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers the contract funds to the researcher that proved the contract is broken.
|
||||
* @param _target contract
|
||||
*/
|
||||
function claim(Target _target) public {
|
||||
address researcher = researchers[_target];
|
||||
require(researcher != address(0));
|
||||
// Check Target contract invariants
|
||||
require(!_target.checkInvariant());
|
||||
asyncTransfer(researcher, address(this).balance);
|
||||
claimed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal function to deploy the target contract.
|
||||
* @return A target contract address
|
||||
*/
|
||||
function deployContract() internal returns(address);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title Target
|
||||
* @dev Your main contract should inherit from this class and implement the checkInvariant method.
|
||||
*/
|
||||
contract Target {
|
||||
|
||||
/**
|
||||
* @dev Checks all values a contract assumes to be true all the time. If this function returns
|
||||
* false, the contract is broken in some way and is in an inconsistent state.
|
||||
* In order to win the bounty, security researchers will try to cause this broken state.
|
||||
* @return True if all invariant values are correct, false otherwise.
|
||||
*/
|
||||
function checkInvariant() public returns(bool);
|
||||
}
|
||||
@ -1,24 +1,21 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title Eliptic curve signature operations
|
||||
*
|
||||
* @title Elliptic curve signature operations
|
||||
* @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d
|
||||
*
|
||||
* TODO Remove this library once solidity supports passing a signature to ecrecover.
|
||||
* See https://github.com/ethereum/solidity/issues/864
|
||||
*
|
||||
*/
|
||||
|
||||
library ECRecovery {
|
||||
|
||||
/**
|
||||
* @dev Recover signer address from a message by using their signature
|
||||
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
|
||||
* @param sig bytes signature, the signature is generated using web3.eth.sign()
|
||||
* @param _hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
|
||||
* @param _sig bytes signature, the signature is generated using web3.eth.sign()
|
||||
*/
|
||||
function recover(bytes32 hash, bytes sig)
|
||||
function recover(bytes32 _hash, bytes _sig)
|
||||
internal
|
||||
pure
|
||||
returns (address)
|
||||
@ -28,7 +25,7 @@ library ECRecovery {
|
||||
uint8 v;
|
||||
|
||||
// Check the signature length
|
||||
if (sig.length != 65) {
|
||||
if (_sig.length != 65) {
|
||||
return (address(0));
|
||||
}
|
||||
|
||||
@ -37,9 +34,9 @@ library ECRecovery {
|
||||
// currently is to use assembly.
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
r := mload(add(sig, 32))
|
||||
s := mload(add(sig, 64))
|
||||
v := byte(0, mload(add(sig, 96)))
|
||||
r := mload(add(_sig, 32))
|
||||
s := mload(add(_sig, 64))
|
||||
v := byte(0, mload(add(_sig, 96)))
|
||||
}
|
||||
|
||||
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions
|
||||
@ -52,16 +49,16 @@ library ECRecovery {
|
||||
return (address(0));
|
||||
} else {
|
||||
// solium-disable-next-line arg-overflow
|
||||
return ecrecover(hash, v, r, s);
|
||||
return ecrecover(_hash, v, r, s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toEthSignedMessageHash
|
||||
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
|
||||
* @dev and hash the result
|
||||
* and hash the result
|
||||
*/
|
||||
function toEthSignedMessageHash(bytes32 hash)
|
||||
function toEthSignedMessageHash(bytes32 _hash)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32)
|
||||
@ -69,8 +66,7 @@ library ECRecovery {
|
||||
// 32 is the length in bytes of hash,
|
||||
// enforced by the type signature above
|
||||
return keccak256(
|
||||
"\x19Ethereum Signed Message:\n32",
|
||||
hash
|
||||
abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
31
contracts/LimitBalance.sol
Normal file
31
contracts/LimitBalance.sol
Normal file
@ -0,0 +1,31 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title LimitBalance
|
||||
* @dev Simple contract to limit the balance of child contract.
|
||||
* Note this doesn't prevent other contracts to send funds by using selfdestruct(address);
|
||||
* See: https://github.com/ConsenSys/smart-contract-best-practices#remember-that-ether-can-be-forcibly-sent-to-an-account
|
||||
*/
|
||||
contract LimitBalance {
|
||||
|
||||
uint256 public limit;
|
||||
|
||||
/**
|
||||
* @dev Constructor that sets the passed value as a limit.
|
||||
* @param _limit uint256 to represent the limit.
|
||||
*/
|
||||
constructor(uint256 _limit) public {
|
||||
limit = _limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks if limit was reached. Case true, it throws.
|
||||
*/
|
||||
modifier limitedPayable() {
|
||||
require(address(this).balance <= limit);
|
||||
_;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +1,28 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* @title MerkleProof
|
||||
* @dev Merkle proof verification
|
||||
* @note Based on https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol
|
||||
* @dev Merkle proof verification based on
|
||||
* https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol
|
||||
*/
|
||||
library MerkleProof {
|
||||
/*
|
||||
/**
|
||||
* @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves
|
||||
* and each pair of pre-images is sorted.
|
||||
* and each pair of pre-images are sorted.
|
||||
* @param _proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree
|
||||
* @param _root Merkle root
|
||||
* @param _leaf Leaf of Merkle tree
|
||||
*/
|
||||
function verifyProof(bytes32[] _proof, bytes32 _root, bytes32 _leaf) internal pure returns (bool) {
|
||||
function verifyProof(
|
||||
bytes32[] _proof,
|
||||
bytes32 _root,
|
||||
bytes32 _leaf
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bool)
|
||||
{
|
||||
bytes32 computedHash = _leaf;
|
||||
|
||||
for (uint256 i = 0; i < _proof.length; i++) {
|
||||
@ -22,10 +30,10 @@ library MerkleProof {
|
||||
|
||||
if (computedHash < proofElement) {
|
||||
// Hash(current computed hash + current element of the proof)
|
||||
computedHash = keccak256(computedHash, proofElement);
|
||||
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
|
||||
} else {
|
||||
// Hash(current element of the proof + current computed hash)
|
||||
computedHash = keccak256(proofElement, computedHash);
|
||||
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
39
contracts/ReentrancyGuard.sol
Normal file
39
contracts/ReentrancyGuard.sol
Normal file
@ -0,0 +1,39 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title Helps contracts guard against reentrancy attacks.
|
||||
* @author Remco Bloemen <remco@2π.com>, Eenae <alexey@mixbytes.io>
|
||||
* @dev If you mark a function `nonReentrant`, you should also
|
||||
* mark it `external`.
|
||||
*/
|
||||
contract ReentrancyGuard {
|
||||
|
||||
/// @dev Constant for unlocked guard state - non-zero to prevent extra gas costs.
|
||||
/// See: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1056
|
||||
uint private constant REENTRANCY_GUARD_FREE = 1;
|
||||
|
||||
/// @dev Constant for locked guard state
|
||||
uint private constant REENTRANCY_GUARD_LOCKED = 2;
|
||||
|
||||
/**
|
||||
* @dev We use a single lock for the whole contract.
|
||||
*/
|
||||
uint private reentrancyLock = REENTRANCY_GUARD_FREE;
|
||||
|
||||
/**
|
||||
* @dev Prevents a contract from calling itself, directly or indirectly.
|
||||
* If you mark a function `nonReentrant`, you should also
|
||||
* mark it `external`. Calling one `nonReentrant` function from
|
||||
* another is not supported. Instead, you can implement a
|
||||
* `private` function doing the actual work, and an `external`
|
||||
* wrapper marked as `nonReentrant`.
|
||||
*/
|
||||
modifier nonReentrant() {
|
||||
require(reentrancyLock == REENTRANCY_GUARD_FREE);
|
||||
reentrancyLock = REENTRANCY_GUARD_LOCKED;
|
||||
_;
|
||||
reentrancyLock = REENTRANCY_GUARD_FREE;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +1,41 @@
|
||||
pragma solidity ^0.4.18;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../ownership/Ownable.sol";
|
||||
import "../ownership/rbac/RBAC.sol";
|
||||
import "../access/rbac/RBAC.sol";
|
||||
import "../ECRecovery.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title SignatureBouncer
|
||||
* @author PhABC and Shrugs
|
||||
* @author PhABC, Shrugs and aflesher
|
||||
* @dev Bouncer allows users to submit a signature as a permission to do an action.
|
||||
* @dev If the signature is from one of the authorized bouncer addresses, the signature
|
||||
* @dev is valid. The owner of the contract adds/removes bouncers.
|
||||
* @dev Bouncer addresses can be individual servers signing grants or different
|
||||
* @dev users within a decentralized club that have permission to invite other members.
|
||||
* @dev
|
||||
* @dev This technique is useful for whitelists and airdrops; instead of putting all
|
||||
* @dev valid addresses on-chain, simply sign a grant of the form
|
||||
* @dev keccak256(`:contractAddress` + `:granteeAddress`) using a valid bouncer address.
|
||||
* @dev Then restrict access to your crowdsale/whitelist/airdrop using the
|
||||
* @dev `onlyValidSignature` modifier (or implement your own using isValidSignature).
|
||||
* @dev
|
||||
* @dev See the tests Bouncer.test.js for specific usage examples.
|
||||
* If the signature is from one of the authorized bouncer addresses, the signature
|
||||
* is valid. The owner of the contract adds/removes bouncers.
|
||||
* Bouncer addresses can be individual servers signing grants or different
|
||||
* users within a decentralized club that have permission to invite other members.
|
||||
* This technique is useful for whitelists and airdrops; instead of putting all
|
||||
* valid addresses on-chain, simply sign a grant of the form
|
||||
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
|
||||
* Then restrict access to your crowdsale/whitelist/airdrop using the
|
||||
* `onlyValidSignature` modifier (or implement your own using isValidSignature).
|
||||
* In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and
|
||||
* `onlyValidSignatureAndData` can be used to restrict access to only a given method
|
||||
* or a given method with given parameters respectively.
|
||||
* See the tests Bouncer.test.js for specific usage examples.
|
||||
* @notice A method that uses the `onlyValidSignatureAndData` modifier must make the _sig
|
||||
* parameter the "last" parameter. You cannot sign a message that has its own
|
||||
* signature in it so the last 128 bytes of msg.data (which represents the
|
||||
* length of the _sig data and the _sig data itself) is ignored when validating.
|
||||
* Also non fixed sized parameters make constructing the data in the signature
|
||||
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
|
||||
*/
|
||||
contract SignatureBouncer is Migratable, Ownable, RBAC {
|
||||
contract SignatureBouncer is Ownable, RBAC {
|
||||
using ECRecovery for bytes32;
|
||||
|
||||
string public constant ROLE_BOUNCER = "bouncer";
|
||||
|
||||
function initialize(address _sender)
|
||||
isInitializer("SignatureBouncer", "1.9.0")
|
||||
public
|
||||
{
|
||||
Ownable.initialize(_sender);
|
||||
}
|
||||
uint constant METHOD_ID_SIZE = 4;
|
||||
// signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
|
||||
uint constant SIGNATURE_SIZE = 96;
|
||||
|
||||
/**
|
||||
* @dev requires that a valid signature of a bouncer was provided
|
||||
@ -43,12 +46,30 @@ contract SignatureBouncer is Migratable, Ownable, RBAC {
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev requires that a valid signature with a specifed method of a bouncer was provided
|
||||
*/
|
||||
modifier onlyValidSignatureAndMethod(bytes _sig)
|
||||
{
|
||||
require(isValidSignatureAndMethod(msg.sender, _sig));
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev requires that a valid signature with a specifed method and params of a bouncer was provided
|
||||
*/
|
||||
modifier onlyValidSignatureAndData(bytes _sig)
|
||||
{
|
||||
require(isValidSignatureAndData(msg.sender, _sig));
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev allows the owner to add additional bouncer addresses
|
||||
*/
|
||||
function addBouncer(address _bouncer)
|
||||
onlyOwner
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
require(_bouncer != address(0));
|
||||
addRole(_bouncer, ROLE_BOUNCER);
|
||||
@ -58,8 +79,8 @@ contract SignatureBouncer is Migratable, Ownable, RBAC {
|
||||
* @dev allows the owner to remove bouncer addresses
|
||||
*/
|
||||
function removeBouncer(address _bouncer)
|
||||
onlyOwner
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
require(_bouncer != address(0));
|
||||
removeRole(_bouncer, ROLE_BOUNCER);
|
||||
@ -75,22 +96,62 @@ contract SignatureBouncer is Migratable, Ownable, RBAC {
|
||||
returns (bool)
|
||||
{
|
||||
return isValidDataHash(
|
||||
keccak256(address(this), _address),
|
||||
keccak256(abi.encodePacked(address(this), _address)),
|
||||
_sig
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev is the signature of `this + sender + methodId` from a bouncer?
|
||||
* @return bool
|
||||
*/
|
||||
function isValidSignatureAndMethod(address _address, bytes _sig)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
bytes memory data = new bytes(METHOD_ID_SIZE);
|
||||
for (uint i = 0; i < data.length; i++) {
|
||||
data[i] = msg.data[i];
|
||||
}
|
||||
return isValidDataHash(
|
||||
keccak256(abi.encodePacked(address(this), _address, data)),
|
||||
_sig
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev is the signature of `this + sender + methodId + params(s)` from a bouncer?
|
||||
* @notice the _sig parameter of the method being validated must be the "last" parameter
|
||||
* @return bool
|
||||
*/
|
||||
function isValidSignatureAndData(address _address, bytes _sig)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
require(msg.data.length > SIGNATURE_SIZE);
|
||||
bytes memory data = new bytes(msg.data.length - SIGNATURE_SIZE);
|
||||
for (uint i = 0; i < data.length; i++) {
|
||||
data[i] = msg.data[i];
|
||||
}
|
||||
return isValidDataHash(
|
||||
keccak256(abi.encodePacked(address(this), _address, data)),
|
||||
_sig
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev internal function to convert a hash to an eth signed message
|
||||
* @dev and then recover the signature and check it against the bouncer role
|
||||
* and then recover the signature and check it against the bouncer role
|
||||
* @return bool
|
||||
*/
|
||||
function isValidDataHash(bytes32 hash, bytes _sig)
|
||||
function isValidDataHash(bytes32 _hash, bytes _sig)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
address signer = hash
|
||||
address signer = _hash
|
||||
.toEthSignedMessageHash()
|
||||
.recover(_sig);
|
||||
return hasRole(signer, ROLE_BOUNCER);
|
||||
|
||||
91
contracts/access/Whitelist.sol
Normal file
91
contracts/access/Whitelist.sol
Normal file
@ -0,0 +1,91 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../ownership/Ownable.sol";
|
||||
import "../access/rbac/RBAC.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Whitelist
|
||||
* @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
|
||||
* This simplifies the implementation of "user permissions".
|
||||
*/
|
||||
contract Whitelist is Ownable, RBAC {
|
||||
string public constant ROLE_WHITELISTED = "whitelist";
|
||||
|
||||
/**
|
||||
* @dev Throws if operator is not whitelisted.
|
||||
* @param _operator address
|
||||
*/
|
||||
modifier onlyIfWhitelisted(address _operator) {
|
||||
checkRole(_operator, ROLE_WHITELISTED);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add an address to the whitelist
|
||||
* @param _operator address
|
||||
* @return true if the address was added to the whitelist, false if the address was already in the whitelist
|
||||
*/
|
||||
function addAddressToWhitelist(address _operator)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
addRole(_operator, ROLE_WHITELISTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev getter to determine if address is in whitelist
|
||||
*/
|
||||
function whitelist(address _operator)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return hasRole(_operator, ROLE_WHITELISTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add addresses to the whitelist
|
||||
* @param _operators addresses
|
||||
* @return true if at least one address was added to the whitelist,
|
||||
* false if all addresses were already in the whitelist
|
||||
*/
|
||||
function addAddressesToWhitelist(address[] _operators)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
for (uint256 i = 0; i < _operators.length; i++) {
|
||||
addAddressToWhitelist(_operators[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove an address from the whitelist
|
||||
* @param _operator address
|
||||
* @return true if the address was removed from the whitelist,
|
||||
* false if the address wasn't in the whitelist in the first place
|
||||
*/
|
||||
function removeAddressFromWhitelist(address _operator)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
removeRole(_operator, ROLE_WHITELISTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove addresses from the whitelist
|
||||
* @param _operators addresses
|
||||
* @return true if at least one address was removed from the whitelist,
|
||||
* false if all addresses weren't in the whitelist in the first place
|
||||
*/
|
||||
function removeAddressesFromWhitelist(address[] _operators)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
for (uint256 i = 0; i < _operators.length; i++) {
|
||||
removeAddressFromWhitelist(_operators[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
106
contracts/access/rbac/RBAC.sol
Normal file
106
contracts/access/rbac/RBAC.sol
Normal file
@ -0,0 +1,106 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Roles.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RBAC (Role-Based Access Control)
|
||||
* @author Matt Condon (@Shrugs)
|
||||
* @dev Stores and provides setters and getters for roles and addresses.
|
||||
* Supports unlimited numbers of roles and addresses.
|
||||
* See //contracts/mocks/RBACMock.sol for an example of usage.
|
||||
* This RBAC method uses strings to key roles. It may be beneficial
|
||||
* for you to write your own implementation of this interface using Enums or similar.
|
||||
*/
|
||||
contract RBAC {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
mapping (string => Roles.Role) private roles;
|
||||
|
||||
event RoleAdded(address indexed operator, string role);
|
||||
event RoleRemoved(address indexed operator, string role);
|
||||
|
||||
/**
|
||||
* @dev reverts if addr does not have role
|
||||
* @param _operator address
|
||||
* @param _role the name of the role
|
||||
* // reverts
|
||||
*/
|
||||
function checkRole(address _operator, string _role)
|
||||
public
|
||||
view
|
||||
{
|
||||
roles[_role].check(_operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev determine if addr has role
|
||||
* @param _operator address
|
||||
* @param _role the name of the role
|
||||
* @return bool
|
||||
*/
|
||||
function hasRole(address _operator, string _role)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return roles[_role].has(_operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add a role to an address
|
||||
* @param _operator address
|
||||
* @param _role the name of the role
|
||||
*/
|
||||
function addRole(address _operator, string _role)
|
||||
internal
|
||||
{
|
||||
roles[_role].add(_operator);
|
||||
emit RoleAdded(_operator, _role);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove a role from an address
|
||||
* @param _operator address
|
||||
* @param _role the name of the role
|
||||
*/
|
||||
function removeRole(address _operator, string _role)
|
||||
internal
|
||||
{
|
||||
roles[_role].remove(_operator);
|
||||
emit RoleRemoved(_operator, _role);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to a single role (uses msg.sender as addr)
|
||||
* @param _role the name of the role
|
||||
* // reverts
|
||||
*/
|
||||
modifier onlyRole(string _role)
|
||||
{
|
||||
checkRole(msg.sender, _role);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to a set of roles (uses msg.sender as addr)
|
||||
* @param _roles the names of the roles to scope access to
|
||||
* // reverts
|
||||
*
|
||||
* @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this
|
||||
* see: https://github.com/ethereum/solidity/issues/2467
|
||||
*/
|
||||
// modifier onlyRoles(string[] _roles) {
|
||||
// bool hasAnyRole = false;
|
||||
// for (uint8 i = 0; i < _roles.length; i++) {
|
||||
// if (hasRole(msg.sender, _roles[i])) {
|
||||
// hasAnyRole = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// require(hasAnyRole);
|
||||
|
||||
// _;
|
||||
// }
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title Roles
|
||||
* @author Francisco Giordano (@frangio)
|
||||
* @dev Library for managing addresses assigned to a Role.
|
||||
* See RBAC.sol for example usage.
|
||||
* See RBAC.sol for example usage.
|
||||
*/
|
||||
library Roles {
|
||||
struct Role {
|
||||
@ -15,41 +15,41 @@ library Roles {
|
||||
/**
|
||||
* @dev give an address access to this role
|
||||
*/
|
||||
function add(Role storage role, address addr)
|
||||
function add(Role storage _role, address _addr)
|
||||
internal
|
||||
{
|
||||
role.bearer[addr] = true;
|
||||
_role.bearer[_addr] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove an address' access to this role
|
||||
*/
|
||||
function remove(Role storage role, address addr)
|
||||
function remove(Role storage _role, address _addr)
|
||||
internal
|
||||
{
|
||||
role.bearer[addr] = false;
|
||||
_role.bearer[_addr] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev check if an address has this role
|
||||
* // reverts
|
||||
*/
|
||||
function check(Role storage role, address addr)
|
||||
view
|
||||
function check(Role storage _role, address _addr)
|
||||
internal
|
||||
view
|
||||
{
|
||||
require(has(role, addr));
|
||||
require(has(_role, _addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev check if an address has this role
|
||||
* @return bool
|
||||
*/
|
||||
function has(Role storage role, address addr)
|
||||
view
|
||||
function has(Role storage _role, address _addr)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return role.bearer[addr];
|
||||
return _role.bearer[_addr];
|
||||
}
|
||||
}
|
||||
203
contracts/crowdsale/Crowdsale.sol
Normal file
203
contracts/crowdsale/Crowdsale.sol
Normal file
@ -0,0 +1,203 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../math/SafeMath.sol";
|
||||
import "../token/ERC20/SafeERC20.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 conform
|
||||
* the base architecture for crowdsales. They are *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 {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for ERC20;
|
||||
|
||||
// The token being sold
|
||||
ERC20 public token;
|
||||
|
||||
// Address where funds are collected
|
||||
address public 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 DetailedERC20 token with 3 decimals called TOK
|
||||
// 1 wei will give you 1 unit, or 0.001 TOK.
|
||||
uint256 public rate;
|
||||
|
||||
// Amount of wei raised
|
||||
uint256 public 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 TokenPurchase(
|
||||
address indexed purchaser,
|
||||
address indexed beneficiary,
|
||||
uint256 value,
|
||||
uint256 amount
|
||||
);
|
||||
|
||||
/**
|
||||
* @param _rate Number of token units a buyer gets per wei
|
||||
* @param _wallet Address where collected funds will be forwarded to
|
||||
* @param _token Address of the token being sold
|
||||
*/
|
||||
constructor(uint256 _rate, address _wallet, ERC20 _token) public {
|
||||
require(_rate > 0);
|
||||
require(_wallet != address(0));
|
||||
require(_token != address(0));
|
||||
|
||||
rate = _rate;
|
||||
wallet = _wallet;
|
||||
token = _token;
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Crowdsale external interface
|
||||
// -----------------------------------------
|
||||
|
||||
/**
|
||||
* @dev fallback function ***DO NOT OVERRIDE***
|
||||
*/
|
||||
function () external payable {
|
||||
buyTokens(msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev low level token purchase ***DO NOT OVERRIDE***
|
||||
* @param _beneficiary Address performing the token purchase
|
||||
*/
|
||||
function buyTokens(address _beneficiary) public payable {
|
||||
|
||||
uint256 weiAmount = msg.value;
|
||||
_preValidatePurchase(_beneficiary, weiAmount);
|
||||
|
||||
// calculate token amount to be created
|
||||
uint256 tokens = _getTokenAmount(weiAmount);
|
||||
|
||||
// update state
|
||||
weiRaised = weiRaised.add(weiAmount);
|
||||
|
||||
_processPurchase(_beneficiary, tokens);
|
||||
emit TokenPurchase(
|
||||
msg.sender,
|
||||
_beneficiary,
|
||||
weiAmount,
|
||||
tokens
|
||||
);
|
||||
|
||||
_updatePurchasingState(_beneficiary, weiAmount);
|
||||
|
||||
_forwardFunds();
|
||||
_postValidatePurchase(_beneficiary, weiAmount);
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Internal interface (extensible)
|
||||
// -----------------------------------------
|
||||
|
||||
/**
|
||||
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
|
||||
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
|
||||
* super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
* require(weiRaised.add(_weiAmount) <= cap);
|
||||
* @param _beneficiary Address performing the token purchase
|
||||
* @param _weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _preValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
require(_beneficiary != address(0));
|
||||
require(_weiAmount != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
|
||||
* @param _beneficiary Address performing the token purchase
|
||||
* @param _weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _postValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
// optional override
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
|
||||
* @param _beneficiary Address performing the token purchase
|
||||
* @param _tokenAmount Number of tokens to be emitted
|
||||
*/
|
||||
function _deliverTokens(
|
||||
address _beneficiary,
|
||||
uint256 _tokenAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
token.safeTransfer(_beneficiary, _tokenAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
|
||||
* @param _beneficiary Address receiving the tokens
|
||||
* @param _tokenAmount Number of tokens to be purchased
|
||||
*/
|
||||
function _processPurchase(
|
||||
address _beneficiary,
|
||||
uint256 _tokenAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
_deliverTokens(_beneficiary, _tokenAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)
|
||||
* @param _beneficiary Address receiving the tokens
|
||||
* @param _weiAmount Value in wei involved in the purchase
|
||||
*/
|
||||
function _updatePurchasingState(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
// optional override
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Override to extend the way in which ether is converted to tokens.
|
||||
* @param _weiAmount Value in wei to be converted into tokens
|
||||
* @return Number of tokens that can be purchased with the specified _weiAmount
|
||||
*/
|
||||
function _getTokenAmount(uint256 _weiAmount)
|
||||
internal view returns (uint256)
|
||||
{
|
||||
return _weiAmount.mul(rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Determines how ETH is stored/forwarded on purchases.
|
||||
*/
|
||||
function _forwardFunds() internal {
|
||||
wallet.transfer(msg.value);
|
||||
}
|
||||
}
|
||||
42
contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Normal file
42
contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Normal file
@ -0,0 +1,42 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../../ownership/Ownable.sol";
|
||||
import "../validation/TimedCrowdsale.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title FinalizableCrowdsale
|
||||
* @dev Extension of Crowdsale where an owner can do extra work
|
||||
* after finishing.
|
||||
*/
|
||||
contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
bool public isFinalized = false;
|
||||
|
||||
event Finalized();
|
||||
|
||||
/**
|
||||
* @dev Must be called after crowdsale ends, to do some extra finalization
|
||||
* work. Calls the contract's finalization function.
|
||||
*/
|
||||
function finalize() public onlyOwner {
|
||||
require(!isFinalized);
|
||||
require(hasClosed());
|
||||
|
||||
finalization();
|
||||
emit Finalized();
|
||||
|
||||
isFinalized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Can be overridden to add finalization logic. The overriding function
|
||||
* should call super.finalization() to ensure the chain of finalization is
|
||||
* executed entirely.
|
||||
*/
|
||||
function finalization() internal {
|
||||
}
|
||||
|
||||
}
|
||||
42
contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol
Normal file
42
contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol
Normal file
@ -0,0 +1,42 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../validation/TimedCrowdsale.sol";
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
import "../../math/SafeMath.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title PostDeliveryCrowdsale
|
||||
* @dev Crowdsale that locks tokens from withdrawal until it ends.
|
||||
*/
|
||||
contract PostDeliveryCrowdsale is TimedCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
mapping(address => uint256) public balances;
|
||||
|
||||
/**
|
||||
* @dev Withdraw tokens only after crowdsale ends.
|
||||
*/
|
||||
function withdrawTokens() public {
|
||||
require(hasClosed());
|
||||
uint256 amount = balances[msg.sender];
|
||||
require(amount > 0);
|
||||
balances[msg.sender] = 0;
|
||||
_deliverTokens(msg.sender, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides parent by storing balances instead of issuing tokens right away.
|
||||
* @param _beneficiary Token purchaser
|
||||
* @param _tokenAmount Amount of tokens purchased
|
||||
*/
|
||||
function _processPurchase(
|
||||
address _beneficiary,
|
||||
uint256 _tokenAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
|
||||
}
|
||||
|
||||
}
|
||||
72
contracts/crowdsale/distribution/RefundableCrowdsale.sol
Normal file
72
contracts/crowdsale/distribution/RefundableCrowdsale.sol
Normal file
@ -0,0 +1,72 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "./FinalizableCrowdsale.sol";
|
||||
import "../../payment/RefundEscrow.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RefundableCrowdsale
|
||||
* @dev Extension of Crowdsale contract that adds a funding goal, and
|
||||
* the possibility of users getting a refund if goal is not met.
|
||||
*/
|
||||
contract RefundableCrowdsale is FinalizableCrowdsale {
|
||||
using SafeMath for uint256;
|
||||
|
||||
// minimum amount of funds to be raised in weis
|
||||
uint256 public 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);
|
||||
escrow = new RefundEscrow(wallet);
|
||||
goal = _goal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Investors can claim refunds here if crowdsale is unsuccessful
|
||||
*/
|
||||
function claimRefund() public {
|
||||
require(isFinalized);
|
||||
require(!goalReached());
|
||||
|
||||
escrow.withdraw(msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 owner calls finalize()
|
||||
*/
|
||||
function finalization() internal {
|
||||
if (goalReached()) {
|
||||
escrow.close();
|
||||
escrow.beneficiaryWithdraw();
|
||||
} else {
|
||||
escrow.enableRefunds();
|
||||
}
|
||||
|
||||
super.finalization();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
|
||||
*/
|
||||
function _forwardFunds() internal {
|
||||
escrow.deposit.value(msg.value)(msg.sender);
|
||||
}
|
||||
|
||||
}
|
||||
50
contracts/crowdsale/emission/AllowanceCrowdsale.sol
Normal file
50
contracts/crowdsale/emission/AllowanceCrowdsale.sol
Normal file
@ -0,0 +1,50 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
import "../../token/ERC20/ERC20Basic.sol";
|
||||
import "../../token/ERC20/SafeERC20.sol";
|
||||
import "../../math/SafeMath.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 ERC20;
|
||||
|
||||
address public 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));
|
||||
tokenWallet = _tokenWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks the amount of tokens left in the allowance.
|
||||
* @return Amount of tokens left in the allowance
|
||||
*/
|
||||
function remainingTokens() public view returns (uint256) {
|
||||
return token.allowance(tokenWallet, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 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);
|
||||
}
|
||||
}
|
||||
28
contracts/crowdsale/emission/MintedCrowdsale.sol
Normal file
28
contracts/crowdsale/emission/MintedCrowdsale.sol
Normal file
@ -0,0 +1,28 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../token/ERC20/MintableToken.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(MintableToken(address(token)).mint(_beneficiary, _tokenAmount));
|
||||
}
|
||||
}
|
||||
56
contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Normal file
56
contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Normal file
@ -0,0 +1,56 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
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 public initialRate;
|
||||
uint256 public 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(_initialRate >= _finalRate);
|
||||
require(_finalRate > 0);
|
||||
initialRate = _initialRate;
|
||||
finalRate = _finalRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the rate of tokens per wei at the present time.
|
||||
* Note that, as price _increases_ with time, the rate _decreases_.
|
||||
* @return The number of tokens a buyer gets per wei at a given time
|
||||
*/
|
||||
function getCurrentRate() public view returns (uint256) {
|
||||
// solium-disable-next-line security/no-block-members
|
||||
uint256 elapsedTime = block.timestamp.sub(openingTime);
|
||||
uint256 timeRange = closingTime.sub(openingTime);
|
||||
uint256 rateRange = initialRate.sub(finalRate);
|
||||
return initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 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);
|
||||
}
|
||||
|
||||
}
|
||||
48
contracts/crowdsale/validation/CappedCrowdsale.sol
Normal file
48
contracts/crowdsale/validation/CappedCrowdsale.sol
Normal file
@ -0,0 +1,48 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
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 public 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);
|
||||
cap = _cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks whether the cap has been reached.
|
||||
* @return Whether the cap was reached
|
||||
*/
|
||||
function capReached() public view returns (bool) {
|
||||
return weiRaised >= cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior requiring purchase to respect the funding cap.
|
||||
* @param _beneficiary Token purchaser
|
||||
* @param _weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
require(weiRaised.add(_weiAmount) <= cap);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../../math/SafeMath.sol";
|
||||
import "../Crowdsale.sol";
|
||||
import "../../ownership/Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title IndividuallyCappedCrowdsale
|
||||
* @dev Crowdsale with per-user caps.
|
||||
*/
|
||||
contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
mapping(address => uint256) public contributions;
|
||||
mapping(address => uint256) public caps;
|
||||
|
||||
/**
|
||||
* @dev Sets a specific user's maximum contribution.
|
||||
* @param _beneficiary Address to be capped
|
||||
* @param _cap Wei limit for individual contribution
|
||||
*/
|
||||
function setUserCap(address _beneficiary, uint256 _cap) external onlyOwner {
|
||||
caps[_beneficiary] = _cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets a group of users' maximum contribution.
|
||||
* @param _beneficiaries List of addresses to be capped
|
||||
* @param _cap Wei limit for individual contribution
|
||||
*/
|
||||
function setGroupCap(
|
||||
address[] _beneficiaries,
|
||||
uint256 _cap
|
||||
)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
for (uint256 i = 0; i < _beneficiaries.length; i++) {
|
||||
caps[_beneficiaries[i]] = _cap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the cap of a specific user.
|
||||
* @param _beneficiary Address whose cap is to be checked
|
||||
* @return Current cap for individual user
|
||||
*/
|
||||
function getUserCap(address _beneficiary) public view returns (uint256) {
|
||||
return caps[_beneficiary];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the amount contributed so far by a sepecific user.
|
||||
* @param _beneficiary Address of contributor
|
||||
* @return User contribution so far
|
||||
*/
|
||||
function getUserContribution(address _beneficiary)
|
||||
public view returns (uint256)
|
||||
{
|
||||
return contributions[_beneficiary];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior requiring purchase to respect the user's funding cap.
|
||||
* @param _beneficiary Token purchaser
|
||||
* @param _weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
{
|
||||
super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
require(contributions[_beneficiary].add(_weiAmount) <= caps[_beneficiary]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior to update user 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);
|
||||
}
|
||||
|
||||
}
|
||||
64
contracts/crowdsale/validation/TimedCrowdsale.sol
Normal file
64
contracts/crowdsale/validation/TimedCrowdsale.sol
Normal file
@ -0,0 +1,64 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
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 public openingTime;
|
||||
uint256 public closingTime;
|
||||
|
||||
/**
|
||||
* @dev Reverts if not in crowdsale time range.
|
||||
*/
|
||||
modifier onlyWhileOpen {
|
||||
// solium-disable-next-line security/no-block-members
|
||||
require(block.timestamp >= openingTime && block.timestamp <= closingTime);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Constructor, takes crowdsale opening and closing times.
|
||||
* @param _openingTime Crowdsale opening time
|
||||
* @param _closingTime Crowdsale closing time
|
||||
*/
|
||||
constructor(uint256 _openingTime, uint256 _closingTime) public {
|
||||
// solium-disable-next-line security/no-block-members
|
||||
require(_openingTime >= block.timestamp);
|
||||
require(_closingTime >= _openingTime);
|
||||
|
||||
openingTime = _openingTime;
|
||||
closingTime = _closingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
|
||||
* @return Whether crowdsale period has elapsed
|
||||
*/
|
||||
function hasClosed() public view returns (bool) {
|
||||
// solium-disable-next-line security/no-block-members
|
||||
return block.timestamp > closingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Extend parent behavior requiring to be within contributing period
|
||||
* @param _beneficiary Token purchaser
|
||||
* @param _weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
onlyWhileOpen
|
||||
{
|
||||
super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
}
|
||||
|
||||
}
|
||||
27
contracts/crowdsale/validation/WhitelistedCrowdsale.sol
Normal file
27
contracts/crowdsale/validation/WhitelistedCrowdsale.sol
Normal file
@ -0,0 +1,27 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../Crowdsale.sol";
|
||||
import "../../access/Whitelist.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title WhitelistedCrowdsale
|
||||
* @dev Crowdsale in which only whitelisted users can contribute.
|
||||
*/
|
||||
contract WhitelistedCrowdsale is Whitelist, Crowdsale {
|
||||
/**
|
||||
* @dev Extend parent behavior requiring beneficiary to be in whitelist.
|
||||
* @param _beneficiary Token beneficiary
|
||||
* @param _weiAmount Amount of wei contributed
|
||||
*/
|
||||
function _preValidatePurchase(
|
||||
address _beneficiary,
|
||||
uint256 _weiAmount
|
||||
)
|
||||
internal
|
||||
onlyIfWhitelisted(_beneficiary)
|
||||
{
|
||||
super._preValidatePurchase(_beneficiary, _weiAmount);
|
||||
}
|
||||
|
||||
}
|
||||
66
contracts/examples/RBACWithAdmin.sol
Normal file
66
contracts/examples/RBACWithAdmin.sol
Normal file
@ -0,0 +1,66 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../access/rbac/RBAC.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RBACWithAdmin
|
||||
* @author Matt Condon (@Shrugs)
|
||||
* @dev It's recommended that you define constants in the contract,
|
||||
* like ROLE_ADMIN below, to avoid typos.
|
||||
* @notice RBACWithAdmin is probably too expansive and powerful for your
|
||||
* application; an admin is actually able to change any address to any role
|
||||
* which is a very large API surface. It's recommended that you follow a strategy
|
||||
* of strictly defining the abilities of your roles
|
||||
* and the API-surface of your contract.
|
||||
* This is just an example for example's sake.
|
||||
*/
|
||||
contract RBACWithAdmin is RBAC {
|
||||
/**
|
||||
* A constant role name for indicating admins.
|
||||
*/
|
||||
string public constant ROLE_ADMIN = "admin";
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to admins
|
||||
* // reverts
|
||||
*/
|
||||
modifier onlyAdmin()
|
||||
{
|
||||
checkRole(msg.sender, ROLE_ADMIN);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev constructor. Sets msg.sender as admin by default
|
||||
*/
|
||||
constructor()
|
||||
public
|
||||
{
|
||||
addRole(msg.sender, ROLE_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add a role to an address
|
||||
* @param _addr address
|
||||
* @param _roleName the name of the role
|
||||
*/
|
||||
function adminAddRole(address _addr, string _roleName)
|
||||
public
|
||||
onlyAdmin
|
||||
{
|
||||
addRole(_addr, _roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove a role from an address
|
||||
* @param _addr address
|
||||
* @param _roleName the name of the role
|
||||
*/
|
||||
function adminRemoveRole(address _addr, string _roleName)
|
||||
public
|
||||
onlyAdmin
|
||||
{
|
||||
removeRole(_addr, _roleName);
|
||||
}
|
||||
}
|
||||
60
contracts/examples/SampleCrowdsale.sol
Normal file
60
contracts/examples/SampleCrowdsale.sol
Normal file
@ -0,0 +1,60 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../crowdsale/validation/CappedCrowdsale.sol";
|
||||
import "../crowdsale/distribution/RefundableCrowdsale.sol";
|
||||
import "../crowdsale/emission/MintedCrowdsale.sol";
|
||||
import "../token/ERC20/MintableToken.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 MintableToken {
|
||||
|
||||
string public constant name = "Sample Crowdsale Token";
|
||||
string public constant symbol = "SCT";
|
||||
uint8 public constant decimals = 18;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* After adding multiple features it's good practice to run integration tests
|
||||
* to ensure that subcontracts works together as intended.
|
||||
*/
|
||||
// XXX There doesn't seem to be a way to split this line that keeps solium
|
||||
// happy. See:
|
||||
// https://github.com/duaraghav8/Solium/issues/205
|
||||
// --elopio - 2018-05-10
|
||||
// solium-disable-next-line max-len
|
||||
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
|
||||
|
||||
constructor(
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
uint256 _cap,
|
||||
MintableToken _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);
|
||||
}
|
||||
}
|
||||
40
contracts/examples/SimpleSavingsWallet.sol
Normal file
40
contracts/examples/SimpleSavingsWallet.sol
Normal file
@ -0,0 +1,40 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../ownership/Heritable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title SimpleSavingsWallet
|
||||
* @dev Simplest form of savings wallet whose ownership can be claimed by a heir
|
||||
* if owner dies.
|
||||
* In this example, we take a very simple savings wallet providing two operations
|
||||
* (to send and receive funds) and extend its capabilities by making it Heritable.
|
||||
* The account that creates the contract is set as owner, who has the authority to
|
||||
* choose an heir account. Heir account can reclaim the contract ownership in the
|
||||
* case that the owner dies.
|
||||
*/
|
||||
contract SimpleSavingsWallet is Heritable {
|
||||
|
||||
event Sent(address indexed payee, uint256 amount, uint256 balance);
|
||||
event Received(address indexed payer, uint256 amount, uint256 balance);
|
||||
|
||||
|
||||
constructor(uint256 _heartbeatTimeout) Heritable(_heartbeatTimeout) public {}
|
||||
|
||||
/**
|
||||
* @dev wallet can receive funds.
|
||||
*/
|
||||
function () external payable {
|
||||
emit Received(msg.sender, msg.value, address(this).balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev wallet can send funds
|
||||
*/
|
||||
function sendTo(address _payee, uint256 _amount) public onlyOwner {
|
||||
require(_payee != address(0) && _payee != address(this));
|
||||
require(_amount > 0);
|
||||
_payee.transfer(_amount);
|
||||
emit Sent(_payee, _amount, address(this).balance);
|
||||
}
|
||||
}
|
||||
30
contracts/examples/SimpleToken.sol
Normal file
30
contracts/examples/SimpleToken.sol
Normal file
@ -0,0 +1,30 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../token/ERC20/StandardToken.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
|
||||
* `StandardToken` functions.
|
||||
*/
|
||||
contract SimpleToken is StandardToken {
|
||||
|
||||
string public constant name = "SimpleToken";
|
||||
string public constant symbol = "SIM";
|
||||
uint8 public constant decimals = 18;
|
||||
|
||||
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));
|
||||
|
||||
/**
|
||||
* @dev Constructor that gives msg.sender all of existing tokens.
|
||||
*/
|
||||
constructor() public {
|
||||
totalSupply_ = INITIAL_SUPPLY;
|
||||
balances[msg.sender] = INITIAL_SUPPLY;
|
||||
emit Transfer(address(0), msg.sender, INITIAL_SUPPLY);
|
||||
}
|
||||
|
||||
}
|
||||
20
contracts/introspection/ERC165.sol
Normal file
20
contracts/introspection/ERC165.sol
Normal file
@ -0,0 +1,20 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title ERC165
|
||||
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
|
||||
*/
|
||||
interface ERC165 {
|
||||
|
||||
/**
|
||||
* @notice Query if a contract implements an interface
|
||||
* @param _interfaceId The interface identifier, as specified in ERC-165
|
||||
* @dev Interface identification is specified in ERC-165. This function
|
||||
* uses less than 30,000 gas.
|
||||
*/
|
||||
function supportsInterface(bytes4 _interfaceId)
|
||||
external
|
||||
view
|
||||
returns (bool);
|
||||
}
|
||||
54
contracts/introspection/SupportsInterfaceWithLookup.sol
Normal file
54
contracts/introspection/SupportsInterfaceWithLookup.sol
Normal file
@ -0,0 +1,54 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./ERC165.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title SupportsInterfaceWithLookup
|
||||
* @author Matt Condon (@shrugs)
|
||||
* @dev Implements ERC165 using a lookup table.
|
||||
*/
|
||||
contract SupportsInterfaceWithLookup is ERC165 {
|
||||
|
||||
bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7;
|
||||
/**
|
||||
* 0x01ffc9a7 ===
|
||||
* bytes4(keccak256('supportsInterface(bytes4)'))
|
||||
*/
|
||||
|
||||
/**
|
||||
* @dev a mapping of interface id to whether or not it's supported
|
||||
*/
|
||||
mapping(bytes4 => bool) internal supportedInterfaces;
|
||||
|
||||
/**
|
||||
* @dev A contract implementing SupportsInterfaceWithLookup
|
||||
* implement ERC165 itself
|
||||
*/
|
||||
constructor()
|
||||
public
|
||||
{
|
||||
_registerInterface(InterfaceId_ERC165);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev implement supportsInterface(bytes4) using a lookup table
|
||||
*/
|
||||
function supportsInterface(bytes4 _interfaceId)
|
||||
external
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return supportedInterfaces[_interfaceId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev private method for registering an interface
|
||||
*/
|
||||
function _registerInterface(bytes4 _interfaceId)
|
||||
internal
|
||||
{
|
||||
require(_interfaceId != 0xffffffff);
|
||||
supportedInterfaces[_interfaceId] = true;
|
||||
}
|
||||
}
|
||||
22
contracts/lifecycle/Destructible.sol
Normal file
22
contracts/lifecycle/Destructible.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../ownership/Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Destructible
|
||||
* @dev Base contract that can be destroyed by owner. All funds in contract will be sent to the owner.
|
||||
*/
|
||||
contract Destructible is Ownable {
|
||||
/**
|
||||
* @dev Transfers the current balance to the owner and terminates the contract.
|
||||
*/
|
||||
function destroy() public onlyOwner {
|
||||
selfdestruct(owner);
|
||||
}
|
||||
|
||||
function destroyAndSend(address _recipient) public onlyOwner {
|
||||
selfdestruct(_recipient);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../ownership/Ownable.sol";
|
||||
@ -8,17 +8,13 @@ import "../ownership/Ownable.sol";
|
||||
* @title Pausable
|
||||
* @dev Base contract which allows children to implement an emergency stop mechanism.
|
||||
*/
|
||||
contract Pausable is Migratable, Ownable {
|
||||
contract Pausable is Ownable {
|
||||
event Pause();
|
||||
event Unpause();
|
||||
|
||||
bool public paused = false;
|
||||
|
||||
|
||||
function initialize(address _sender) isInitializer("Pausable", "1.9.0") public {
|
||||
Ownable.initialize(_sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Modifier to make a function callable only when the contract is not paused.
|
||||
*/
|
||||
@ -38,7 +34,7 @@ contract Pausable is Migratable, Ownable {
|
||||
/**
|
||||
* @dev called by the owner to pause, triggers stopped state
|
||||
*/
|
||||
function pause() onlyOwner whenNotPaused public {
|
||||
function pause() public onlyOwner whenNotPaused {
|
||||
paused = true;
|
||||
emit Pause();
|
||||
}
|
||||
@ -46,7 +42,7 @@ contract Pausable is Migratable, Ownable {
|
||||
/**
|
||||
* @dev called by the owner to unpause, returns to normal state
|
||||
*/
|
||||
function unpause() onlyOwner whenPaused public {
|
||||
function unpause() public onlyOwner whenPaused {
|
||||
paused = false;
|
||||
emit Unpause();
|
||||
}
|
||||
|
||||
36
contracts/lifecycle/TokenDestructible.sol
Normal file
36
contracts/lifecycle/TokenDestructible.sol
Normal file
@ -0,0 +1,36 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../ownership/Ownable.sol";
|
||||
import "../token/ERC20/ERC20Basic.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title TokenDestructible:
|
||||
* @author Remco Bloemen <remco@2π.com>
|
||||
* @dev Base contract that can be destroyed by owner. All funds in contract including
|
||||
* listed tokens will be sent to the owner.
|
||||
*/
|
||||
contract TokenDestructible is Ownable {
|
||||
|
||||
constructor() public payable { }
|
||||
|
||||
/**
|
||||
* @notice Terminate contract and refund to owner
|
||||
* @param _tokens List of addresses of ERC20 or ERC20Basic token contracts to
|
||||
refund.
|
||||
* @notice The called token contracts could try to re-enter this contract. Only
|
||||
supply token contracts you trust.
|
||||
*/
|
||||
function destroy(address[] _tokens) public onlyOwner {
|
||||
|
||||
// Transfer tokens to owner
|
||||
for (uint256 i = 0; i < _tokens.length; i++) {
|
||||
ERC20Basic token = ERC20Basic(_tokens[i]);
|
||||
uint256 balance = token.balanceOf(this);
|
||||
token.transfer(owner, balance);
|
||||
}
|
||||
|
||||
// Transfer Eth to owner and terminate contract
|
||||
selfdestruct(owner);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
@ -6,19 +6,19 @@ pragma solidity ^0.4.21;
|
||||
* @dev Assorted math operations
|
||||
*/
|
||||
library Math {
|
||||
function max64(uint64 a, uint64 b) internal pure returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
function max64(uint64 _a, uint64 _b) internal pure returns (uint64) {
|
||||
return _a >= _b ? _a : _b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal pure returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
function min64(uint64 _a, uint64 _b) internal pure returns (uint64) {
|
||||
return _a < _b ? _a : _b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
function max256(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
return _a >= _b ? _a : _b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
function min256(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
return _a < _b ? _a : _b;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
@ -10,39 +10,43 @@ library SafeMath {
|
||||
/**
|
||||
* @dev Multiplies two numbers, throws on overflow.
|
||||
*/
|
||||
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
||||
if (a == 0) {
|
||||
function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
|
||||
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
|
||||
// benefit is lost if 'b' is also tested.
|
||||
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
|
||||
if (_a == 0) {
|
||||
return 0;
|
||||
}
|
||||
c = a * b;
|
||||
assert(c / a == b);
|
||||
|
||||
c = _a * _b;
|
||||
assert(c / _a == _b);
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Integer division of two numbers, truncating the quotient.
|
||||
*/
|
||||
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
// assert(b > 0); // Solidity automatically throws when dividing by 0
|
||||
// uint256 c = a / b;
|
||||
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
|
||||
return a / b;
|
||||
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
// assert(_b > 0); // Solidity automatically throws when dividing by 0
|
||||
// uint256 c = _a / _b;
|
||||
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
|
||||
return _a / _b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
|
||||
*/
|
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
assert(b <= a);
|
||||
return a - b;
|
||||
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
assert(_b <= _a);
|
||||
return _a - _b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Adds two numbers, throws on overflow.
|
||||
*/
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
||||
c = a + b;
|
||||
assert(c >= a);
|
||||
function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
|
||||
c = _a + _b;
|
||||
assert(c >= _a);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
21
contracts/mocks/AllowanceCrowdsaleImpl.sol
Normal file
21
contracts/mocks/AllowanceCrowdsaleImpl.sol
Normal file
@ -0,0 +1,21 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/emission/AllowanceCrowdsale.sol";
|
||||
|
||||
|
||||
contract AllowanceCrowdsaleImpl is AllowanceCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token,
|
||||
address _tokenWallet
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
AllowanceCrowdsale(_tokenWallet)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
21
contracts/mocks/AutoIncrementingImpl.sol
Normal file
21
contracts/mocks/AutoIncrementingImpl.sol
Normal file
@ -0,0 +1,21 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../AutoIncrementing.sol";
|
||||
|
||||
|
||||
contract AutoIncrementingImpl {
|
||||
using AutoIncrementing for AutoIncrementing.Counter;
|
||||
|
||||
uint256 public theId;
|
||||
|
||||
// use whatever key you want to track your counters
|
||||
mapping(string => AutoIncrementing.Counter) private counters;
|
||||
|
||||
function doThing(string _key)
|
||||
public
|
||||
returns (uint256)
|
||||
{
|
||||
theId = counters[_key].nextId();
|
||||
return theId;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../token/ERC20/BasicToken.sol";
|
||||
@ -7,9 +7,9 @@ import "../token/ERC20/BasicToken.sol";
|
||||
// mock class using BasicToken
|
||||
contract BasicTokenMock is BasicToken {
|
||||
|
||||
function BasicTokenMock(address initialAccount, uint256 initialBalance) public {
|
||||
balances[initialAccount] = initialBalance;
|
||||
totalSupply_ = initialBalance;
|
||||
constructor(address _initialAccount, uint256 _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
totalSupply_ = _initialBalance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,16 +1,9 @@
|
||||
pragma solidity ^0.4.18;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../access/SignatureBouncer.sol";
|
||||
|
||||
|
||||
contract SignatureBouncerMock is SignatureBouncer {
|
||||
function initialize(address _sender)
|
||||
isInitializer("SignatureBouncerMock", "1.9.0")
|
||||
public
|
||||
{
|
||||
SignatureBouncer.initialize(_sender);
|
||||
}
|
||||
|
||||
function checkValidSignature(address _address, bytes _sig)
|
||||
public
|
||||
view
|
||||
@ -20,10 +13,54 @@ contract SignatureBouncerMock is SignatureBouncer {
|
||||
}
|
||||
|
||||
function onlyWithValidSignature(bytes _sig)
|
||||
onlyValidSignature(_sig)
|
||||
public
|
||||
onlyValidSignature(_sig)
|
||||
view
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function checkValidSignatureAndMethod(address _address, bytes _sig)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return isValidSignatureAndMethod(_address, _sig);
|
||||
}
|
||||
|
||||
function onlyWithValidSignatureAndMethod(bytes _sig)
|
||||
public
|
||||
onlyValidSignatureAndMethod(_sig)
|
||||
view
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function checkValidSignatureAndData(
|
||||
address _address,
|
||||
bytes,
|
||||
uint,
|
||||
bytes _sig
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return isValidSignatureAndData(_address, _sig);
|
||||
}
|
||||
|
||||
function onlyWithValidSignatureAndData(uint, bytes _sig)
|
||||
public
|
||||
onlyValidSignatureAndData(_sig)
|
||||
view
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function theWrongMethod(bytes)
|
||||
public
|
||||
pure
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/BurnableToken.sol";
|
||||
|
||||
|
||||
contract BurnableTokenMock is BurnableToken {
|
||||
|
||||
function BurnableTokenMock(address initialAccount, uint initialBalance) public {
|
||||
balances[initialAccount] = initialBalance;
|
||||
totalSupply_ = initialBalance;
|
||||
constructor(address _initialAccount, uint _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
totalSupply_ = _initialBalance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
21
contracts/mocks/CappedCrowdsaleImpl.sol
Normal file
21
contracts/mocks/CappedCrowdsaleImpl.sol
Normal file
@ -0,0 +1,21 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/validation/CappedCrowdsale.sol";
|
||||
|
||||
|
||||
contract CappedCrowdsaleImpl is CappedCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token,
|
||||
uint256 _cap
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
CappedCrowdsale(_cap)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
18
contracts/mocks/ConditionalEscrowMock.sol
Normal file
18
contracts/mocks/ConditionalEscrowMock.sol
Normal file
@ -0,0 +1,18 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../payment/ConditionalEscrow.sol";
|
||||
|
||||
|
||||
// mock class using ConditionalEscrow
|
||||
contract ConditionalEscrowMock is ConditionalEscrow {
|
||||
mapping(address => bool) public allowed;
|
||||
|
||||
function setAllowed(address _payee, bool _allowed) public {
|
||||
allowed[_payee] = _allowed;
|
||||
}
|
||||
|
||||
function withdrawalAllowed(address _payee) public view returns (bool) {
|
||||
return allowed[_payee];
|
||||
}
|
||||
}
|
||||
8
contracts/mocks/DestructibleMock.sol
Normal file
8
contracts/mocks/DestructibleMock.sol
Normal file
@ -0,0 +1,8 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../lifecycle/Destructible.sol";
|
||||
|
||||
|
||||
contract DestructibleMock is Destructible {
|
||||
function() public payable {}
|
||||
}
|
||||
@ -1,11 +1,16 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/StandardToken.sol";
|
||||
import "../token/ERC20/DetailedERC20.sol";
|
||||
|
||||
|
||||
contract DetailedERC20Mock is StandardToken, DetailedERC20 {
|
||||
function DetailedERC20Mock(string _name, string _symbol, uint8 _decimals) public {
|
||||
DetailedERC20.initialize(_name, _symbol, _decimals);
|
||||
}
|
||||
constructor(
|
||||
string _name,
|
||||
string _symbol,
|
||||
uint8 _decimals
|
||||
)
|
||||
DetailedERC20(_name, _symbol, _decimals)
|
||||
public
|
||||
{}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../ECRecovery.sol";
|
||||
@ -7,19 +7,19 @@ import "../ECRecovery.sol";
|
||||
contract ECRecoveryMock {
|
||||
using ECRecovery for bytes32;
|
||||
|
||||
function recover(bytes32 hash, bytes sig)
|
||||
function recover(bytes32 _hash, bytes _sig)
|
||||
public
|
||||
pure
|
||||
returns (address)
|
||||
{
|
||||
return hash.recover(sig);
|
||||
return _hash.recover(_sig);
|
||||
}
|
||||
|
||||
function toEthSignedMessageHash(bytes32 hash)
|
||||
function toEthSignedMessageHash(bytes32 _hash)
|
||||
public
|
||||
pure
|
||||
returns (bytes32)
|
||||
{
|
||||
return hash.toEthSignedMessageHash();
|
||||
return _hash.toEthSignedMessageHash();
|
||||
}
|
||||
}
|
||||
|
||||
12
contracts/mocks/ERC20WithMetadataMock.sol
Normal file
12
contracts/mocks/ERC20WithMetadataMock.sol
Normal file
@ -0,0 +1,12 @@
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "../token/ERC20/StandardToken.sol";
|
||||
import "../proposals/ERC1046/TokenMetadata.sol";
|
||||
|
||||
|
||||
contract ERC20WithMetadataMock is StandardToken, ERC20WithMetadata {
|
||||
constructor(string _tokenURI) public
|
||||
ERC20WithMetadata(_tokenURI)
|
||||
{
|
||||
}
|
||||
}
|
||||
34
contracts/mocks/ERC223TokenMock.sol
Normal file
34
contracts/mocks/ERC223TokenMock.sol
Normal file
@ -0,0 +1,34 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/BasicToken.sol";
|
||||
|
||||
|
||||
contract ERC223ContractInterface {
|
||||
function tokenFallback(address _from, uint256 _value, bytes _data) external;
|
||||
}
|
||||
|
||||
|
||||
contract ERC223TokenMock is BasicToken {
|
||||
|
||||
constructor(address _initialAccount, uint256 _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
totalSupply_ = _initialBalance;
|
||||
}
|
||||
|
||||
// ERC223 compatible transfer function (except the name)
|
||||
function transferERC223(address _to, uint256 _value, bytes _data) public
|
||||
returns (bool success)
|
||||
{
|
||||
transfer(_to, _value);
|
||||
bool isContract = false;
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly {
|
||||
isContract := not(iszero(extcodesize(_to)))
|
||||
}
|
||||
if (isContract) {
|
||||
ERC223ContractInterface receiver = ERC223ContractInterface(_to);
|
||||
receiver.tokenFallback(msg.sender, _value, _data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC721/ERC721BasicToken.sol";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC721/ERC721Receiver.sol";
|
||||
|
||||
@ -7,15 +7,22 @@ contract ERC721ReceiverMock is ERC721Receiver {
|
||||
bytes4 retval;
|
||||
bool reverts;
|
||||
|
||||
event Received(address _address, uint256 _tokenId, bytes _data, uint256 _gas);
|
||||
event Received(
|
||||
address _operator,
|
||||
address _from,
|
||||
uint256 _tokenId,
|
||||
bytes _data,
|
||||
uint256 _gas
|
||||
);
|
||||
|
||||
function ERC721ReceiverMock(bytes4 _retval, bool _reverts) public {
|
||||
constructor(bytes4 _retval, bool _reverts) public {
|
||||
retval = _retval;
|
||||
reverts = _reverts;
|
||||
}
|
||||
|
||||
function onERC721Received(
|
||||
address _address,
|
||||
address _operator,
|
||||
address _from,
|
||||
uint256 _tokenId,
|
||||
bytes _data
|
||||
)
|
||||
@ -24,7 +31,8 @@ contract ERC721ReceiverMock is ERC721Receiver {
|
||||
{
|
||||
require(!reverts);
|
||||
emit Received(
|
||||
_address,
|
||||
_operator,
|
||||
_from,
|
||||
_tokenId,
|
||||
_data,
|
||||
gasleft() // msg.gas was deprecated in solidityv0.4.21
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC721/ERC721Token.sol";
|
||||
|
||||
@ -9,9 +9,9 @@ import "../token/ERC721/ERC721Token.sol";
|
||||
* and a public setter for metadata URI
|
||||
*/
|
||||
contract ERC721TokenMock is ERC721Token {
|
||||
function ERC721TokenMock(string name, string symbol) public {
|
||||
ERC721Token.initialize(name, symbol);
|
||||
}
|
||||
constructor(string name, string symbol) public
|
||||
ERC721Token(name, symbol)
|
||||
{ }
|
||||
|
||||
function mint(address _to, uint256 _tokenId) public {
|
||||
super._mint(_to, _tokenId);
|
||||
@ -24,4 +24,8 @@ contract ERC721TokenMock is ERC721Token {
|
||||
function setTokenURI(uint256 _tokenId, string _uri) public {
|
||||
super._setTokenURI(_tokenId, _uri);
|
||||
}
|
||||
|
||||
function _removeTokenFrom(address _from, uint256 _tokenId) public {
|
||||
super.removeTokenFrom(_from, _tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
22
contracts/mocks/FinalizableCrowdsaleImpl.sol
Normal file
22
contracts/mocks/FinalizableCrowdsaleImpl.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/MintableToken.sol";
|
||||
import "../crowdsale/distribution/FinalizableCrowdsale.sol";
|
||||
|
||||
|
||||
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
MintableToken _token
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
TimedCrowdsale(_openingTime, _closingTime)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
16
contracts/mocks/ForceEther.sol
Normal file
16
contracts/mocks/ForceEther.sol
Normal file
@ -0,0 +1,16 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
// @title Force Ether into a contract.
|
||||
// @notice even
|
||||
// if the contract is not payable.
|
||||
// @notice To use, construct the contract with the target as argument.
|
||||
// @author Remco Bloemen <remco@neufund.org>
|
||||
contract ForceEther {
|
||||
|
||||
constructor() public payable { }
|
||||
|
||||
function destroyAndSend(address _recipient) public {
|
||||
selfdestruct(_recipient);
|
||||
}
|
||||
}
|
||||
12
contracts/mocks/HasNoEtherTest.sol
Normal file
12
contracts/mocks/HasNoEtherTest.sol
Normal file
@ -0,0 +1,12 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../../contracts/ownership/HasNoEther.sol";
|
||||
|
||||
|
||||
contract HasNoEtherTest is HasNoEther {
|
||||
|
||||
// Constructor with explicit payable — should still fail
|
||||
constructor() public payable {
|
||||
}
|
||||
|
||||
}
|
||||
24
contracts/mocks/IncreasingPriceCrowdsaleImpl.sol
Normal file
24
contracts/mocks/IncreasingPriceCrowdsaleImpl.sol
Normal file
@ -0,0 +1,24 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../crowdsale/price/IncreasingPriceCrowdsale.sol";
|
||||
import "../math/SafeMath.sol";
|
||||
|
||||
|
||||
contract IncreasingPriceCrowdsaleImpl is IncreasingPriceCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
address _wallet,
|
||||
ERC20 _token,
|
||||
uint256 _initialRate,
|
||||
uint256 _finalRate
|
||||
)
|
||||
public
|
||||
Crowdsale(_initialRate, _wallet, _token)
|
||||
TimedCrowdsale(_openingTime, _closingTime)
|
||||
IncreasingPriceCrowdsale(_initialRate, _finalRate)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
19
contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol
Normal file
19
contracts/mocks/IndividuallyCappedCrowdsaleImpl.sol
Normal file
@ -0,0 +1,19 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
|
||||
|
||||
|
||||
contract IndividuallyCappedCrowdsaleImpl is IndividuallyCappedCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
17
contracts/mocks/InsecureTargetBounty.sol
Normal file
17
contracts/mocks/InsecureTargetBounty.sol
Normal file
@ -0,0 +1,17 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import {Bounty, Target} from "../../contracts/Bounty.sol";
|
||||
|
||||
|
||||
contract InsecureTargetMock is Target {
|
||||
function checkInvariant() public returns(bool) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract InsecureTargetBounty is Bounty {
|
||||
function deployContract() internal returns (address) {
|
||||
return new InsecureTargetMock();
|
||||
}
|
||||
}
|
||||
13
contracts/mocks/LimitBalanceMock.sol
Normal file
13
contracts/mocks/LimitBalanceMock.sol
Normal file
@ -0,0 +1,13 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../LimitBalance.sol";
|
||||
|
||||
|
||||
// mock class using LimitBalance
|
||||
contract LimitBalanceMock is LimitBalance(1000) {
|
||||
|
||||
function limitedDeposit() public payable limitedPayable {
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../../contracts/math/Math.sol";
|
||||
@ -8,19 +8,19 @@ contract MathMock {
|
||||
uint64 public result64;
|
||||
uint256 public result256;
|
||||
|
||||
function max64(uint64 a, uint64 b) public {
|
||||
result64 = Math.max64(a, b);
|
||||
function max64(uint64 _a, uint64 _b) public {
|
||||
result64 = Math.max64(_a, _b);
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) public {
|
||||
result64 = Math.min64(a, b);
|
||||
function min64(uint64 _a, uint64 _b) public {
|
||||
result64 = Math.min64(_a, _b);
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) public {
|
||||
result256 = Math.max256(a, b);
|
||||
function max256(uint256 _a, uint256 _b) public {
|
||||
result256 = Math.max256(_a, _b);
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) public {
|
||||
result256 = Math.min256(a, b);
|
||||
function min256(uint256 _a, uint256 _b) public {
|
||||
result256 = Math.min256(_a, _b);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,19 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import { MerkleProof } from "../MerkleProof.sol";
|
||||
|
||||
|
||||
contract MerkleProofWrapper {
|
||||
|
||||
function verifyProof(bytes32[] _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
|
||||
function verifyProof(
|
||||
bytes32[] _proof,
|
||||
bytes32 _root,
|
||||
bytes32 _leaf
|
||||
)
|
||||
public
|
||||
pure
|
||||
returns (bool)
|
||||
{
|
||||
return MerkleProof.verifyProof(_proof, _root, _leaf);
|
||||
}
|
||||
}
|
||||
|
||||
50
contracts/mocks/MessageHelper.sol
Normal file
50
contracts/mocks/MessageHelper.sol
Normal file
@ -0,0 +1,50 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
contract MessageHelper {
|
||||
|
||||
event Show(bytes32 b32, uint256 number, string text);
|
||||
event Buy(bytes32 b32, uint256 number, string text, uint256 value);
|
||||
|
||||
function showMessage(
|
||||
bytes32 _message,
|
||||
uint256 _number,
|
||||
string _text
|
||||
)
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
emit Show(_message, _number, _text);
|
||||
return true;
|
||||
}
|
||||
|
||||
function buyMessage(
|
||||
bytes32 _message,
|
||||
uint256 _number,
|
||||
string _text
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (bool)
|
||||
{
|
||||
emit Buy(
|
||||
_message,
|
||||
_number,
|
||||
_text,
|
||||
msg.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function fail() public {
|
||||
require(false);
|
||||
}
|
||||
|
||||
function call(address _to, bytes _data) public returns (bool) {
|
||||
// solium-disable-next-line security/no-low-level-calls
|
||||
if (_to.call(_data))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
19
contracts/mocks/MintedCrowdsaleImpl.sol
Normal file
19
contracts/mocks/MintedCrowdsaleImpl.sol
Normal file
@ -0,0 +1,19 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/MintableToken.sol";
|
||||
import "../crowdsale/emission/MintedCrowdsale.sol";
|
||||
|
||||
|
||||
contract MintedCrowdsaleImpl is MintedCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
MintableToken _token
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../lifecycle/Pausable.sol";
|
||||
@ -9,9 +9,7 @@ contract PausableMock is Pausable {
|
||||
bool public drasticMeasureTaken;
|
||||
uint256 public count;
|
||||
|
||||
function PausableMock() public {
|
||||
Ownable.initialize(msg.sender);
|
||||
|
||||
constructor() public {
|
||||
drasticMeasureTaken = false;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/PausableToken.sol";
|
||||
|
||||
@ -6,10 +6,8 @@ import "../token/ERC20/PausableToken.sol";
|
||||
// mock class using PausableToken
|
||||
contract PausableTokenMock is PausableToken {
|
||||
|
||||
function PausableTokenMock(address initialAccount, uint initialBalance) public {
|
||||
Ownable.initialize(msg.sender);
|
||||
|
||||
balances[initialAccount] = initialBalance;
|
||||
constructor(address _initialAccount, uint _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
contracts/mocks/PostDeliveryCrowdsaleImpl.sol
Normal file
22
contracts/mocks/PostDeliveryCrowdsaleImpl.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
|
||||
|
||||
|
||||
contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token
|
||||
)
|
||||
public
|
||||
TimedCrowdsale(_openingTime, _closingTime)
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../payment/PullPayment.sol";
|
||||
@ -7,11 +7,11 @@ import "../payment/PullPayment.sol";
|
||||
// mock class using PullPayment
|
||||
contract PullPaymentMock is PullPayment {
|
||||
|
||||
function PullPaymentMock() public payable { }
|
||||
constructor() public payable { }
|
||||
|
||||
// test helper function to call asyncSend
|
||||
function callSend(address dest, uint256 amount) public {
|
||||
asyncSend(dest, amount);
|
||||
// test helper function to call asyncTransfer
|
||||
function callTransfer(address _dest, uint256 _amount) public {
|
||||
asyncTransfer(_dest, _amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
contracts/mocks/RBACCappedTokenMock.sol
Normal file
12
contracts/mocks/RBACCappedTokenMock.sol
Normal file
@ -0,0 +1,12 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/RBACMintableToken.sol";
|
||||
import "../token/ERC20/CappedToken.sol";
|
||||
|
||||
|
||||
contract RBACCappedTokenMock is CappedToken, RBACMintableToken {
|
||||
constructor(uint256 _cap)
|
||||
CappedToken(_cap)
|
||||
public
|
||||
{}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../ownership/rbac/RBACWithAdmin.sol";
|
||||
import "../examples/RBACWithAdmin.sol";
|
||||
|
||||
|
||||
contract RBACMock is RBACWithAdmin {
|
||||
@ -16,11 +16,9 @@ contract RBACMock is RBACWithAdmin {
|
||||
_;
|
||||
}
|
||||
|
||||
function RBACMock(address[] _advisors)
|
||||
constructor(address[] _advisors)
|
||||
public
|
||||
{
|
||||
RBACWithAdmin.initialize(msg.sender);
|
||||
|
||||
addRole(msg.sender, ROLE_ADVISOR);
|
||||
|
||||
for (uint256 i = 0; i < _advisors.length; i++) {
|
||||
@ -29,37 +27,37 @@ contract RBACMock is RBACWithAdmin {
|
||||
}
|
||||
|
||||
function onlyAdminsCanDoThis()
|
||||
external
|
||||
onlyAdmin
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function onlyAdvisorsCanDoThis()
|
||||
external
|
||||
onlyRole(ROLE_ADVISOR)
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function eitherAdminOrAdvisorCanDoThis()
|
||||
external
|
||||
onlyAdminOrAdvisor
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function nobodyCanDoThis()
|
||||
external
|
||||
onlyRole("unknown")
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
// admins can remove advisor's role
|
||||
function removeAdvisor(address _addr)
|
||||
onlyAdmin
|
||||
public
|
||||
onlyAdmin
|
||||
{
|
||||
// revert if the user isn't an advisor
|
||||
// (perhaps you want to soft-fail here instead?)
|
||||
|
||||
11
contracts/mocks/ReentrancyAttack.sol
Normal file
11
contracts/mocks/ReentrancyAttack.sol
Normal file
@ -0,0 +1,11 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
contract ReentrancyAttack {
|
||||
|
||||
function callSender(bytes4 _data) public {
|
||||
// solium-disable-next-line security/no-low-level-calls
|
||||
require(msg.sender.call(abi.encodeWithSelector(_data)));
|
||||
}
|
||||
|
||||
}
|
||||
45
contracts/mocks/ReentrancyMock.sol
Normal file
45
contracts/mocks/ReentrancyMock.sol
Normal file
@ -0,0 +1,45 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../ReentrancyGuard.sol";
|
||||
import "./ReentrancyAttack.sol";
|
||||
|
||||
|
||||
contract ReentrancyMock is ReentrancyGuard {
|
||||
|
||||
uint256 public counter;
|
||||
|
||||
constructor() public {
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
function callback() external nonReentrant {
|
||||
count();
|
||||
}
|
||||
|
||||
function countLocalRecursive(uint256 _n) public nonReentrant {
|
||||
if (_n > 0) {
|
||||
count();
|
||||
countLocalRecursive(_n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
function countThisRecursive(uint256 _n) public nonReentrant {
|
||||
if (_n > 0) {
|
||||
count();
|
||||
// solium-disable-next-line security/no-low-level-calls
|
||||
bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", _n - 1));
|
||||
require(result == true);
|
||||
}
|
||||
}
|
||||
|
||||
function countAndCall(ReentrancyAttack _attacker) public nonReentrant {
|
||||
count();
|
||||
bytes4 func = bytes4(keccak256("callback()"));
|
||||
_attacker.callSender(func);
|
||||
}
|
||||
|
||||
function count() private {
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
}
|
||||
24
contracts/mocks/RefundableCrowdsaleImpl.sol
Normal file
24
contracts/mocks/RefundableCrowdsaleImpl.sol
Normal file
@ -0,0 +1,24 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/MintableToken.sol";
|
||||
import "../crowdsale/distribution/RefundableCrowdsale.sol";
|
||||
|
||||
|
||||
contract RefundableCrowdsaleImpl is RefundableCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
MintableToken _token,
|
||||
uint256 _goal
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
TimedCrowdsale(_openingTime, _closingTime)
|
||||
RefundableCrowdsale(_goal)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
@ -35,7 +35,7 @@ contract ERC20SucceedingMock is ERC20 {
|
||||
function totalSupply() public view returns (uint256) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function transfer(address, uint256) public returns (bool) {
|
||||
return true;
|
||||
}
|
||||
@ -64,32 +64,32 @@ contract SafeERC20Helper {
|
||||
ERC20 failing;
|
||||
ERC20 succeeding;
|
||||
|
||||
function SafeERC20Helper() public {
|
||||
constructor() public {
|
||||
failing = new ERC20FailingMock();
|
||||
succeeding = new ERC20SucceedingMock();
|
||||
}
|
||||
|
||||
function doFailingTransfer() public {
|
||||
failing.safeTransfer(0, 0);
|
||||
failing.safeTransfer(address(0), 0);
|
||||
}
|
||||
|
||||
function doFailingTransferFrom() public {
|
||||
failing.safeTransferFrom(0, 0, 0);
|
||||
failing.safeTransferFrom(address(0), address(0), 0);
|
||||
}
|
||||
|
||||
function doFailingApprove() public {
|
||||
failing.safeApprove(0, 0);
|
||||
failing.safeApprove(address(0), 0);
|
||||
}
|
||||
|
||||
function doSucceedingTransfer() public {
|
||||
succeeding.safeTransfer(0, 0);
|
||||
succeeding.safeTransfer(address(0), 0);
|
||||
}
|
||||
|
||||
function doSucceedingTransferFrom() public {
|
||||
succeeding.safeTransferFrom(0, 0, 0);
|
||||
succeeding.safeTransferFrom(address(0), address(0), 0);
|
||||
}
|
||||
|
||||
function doSucceedingApprove() public {
|
||||
succeeding.safeApprove(0, 0);
|
||||
succeeding.safeApprove(address(0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "../math/SafeMath.sol";
|
||||
@ -6,19 +6,19 @@ import "../math/SafeMath.sol";
|
||||
|
||||
contract SafeMathMock {
|
||||
|
||||
function mul(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return SafeMath.mul(a, b);
|
||||
function mul(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return SafeMath.mul(_a, _b);
|
||||
}
|
||||
|
||||
function div(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return SafeMath.div(a, b);
|
||||
function div(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return SafeMath.div(_a, _b);
|
||||
}
|
||||
|
||||
function sub(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return SafeMath.sub(a, b);
|
||||
function sub(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return SafeMath.sub(_a, _b);
|
||||
}
|
||||
|
||||
function add(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return SafeMath.add(a, b);
|
||||
function add(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return SafeMath.add(_a, _b);
|
||||
}
|
||||
}
|
||||
|
||||
17
contracts/mocks/SecureTargetBounty.sol
Normal file
17
contracts/mocks/SecureTargetBounty.sol
Normal file
@ -0,0 +1,17 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import {Bounty, Target} from "../../contracts/Bounty.sol";
|
||||
|
||||
|
||||
contract SecureTargetMock is Target {
|
||||
function checkInvariant() public returns(bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract SecureTargetBounty is Bounty {
|
||||
function deployContract() internal returns (address) {
|
||||
return new SecureTargetMock();
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
pragma solidity ^0.4.18;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/StandardBurnableToken.sol";
|
||||
|
||||
|
||||
contract StandardBurnableTokenMock is StandardBurnableToken {
|
||||
|
||||
function StandardBurnableTokenMock(address initialAccount, uint initialBalance) public {
|
||||
balances[initialAccount] = initialBalance;
|
||||
totalSupply_ = initialBalance;
|
||||
constructor(address _initialAccount, uint _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
totalSupply_ = _initialBalance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/StandardToken.sol";
|
||||
|
||||
@ -6,9 +6,9 @@ import "../token/ERC20/StandardToken.sol";
|
||||
// mock class using StandardToken
|
||||
contract StandardTokenMock is StandardToken {
|
||||
|
||||
function StandardTokenMock(address initialAccount, uint256 initialBalance) public {
|
||||
balances[initialAccount] = initialBalance;
|
||||
totalSupply_ = initialBalance;
|
||||
constructor(address _initialAccount, uint256 _initialBalance) public {
|
||||
balances[_initialAccount] = _initialBalance;
|
||||
totalSupply_ = _initialBalance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
contracts/mocks/SupportsInterfaceWithLookupMock.sol
Normal file
12
contracts/mocks/SupportsInterfaceWithLookupMock.sol
Normal file
@ -0,0 +1,12 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../introspection/SupportsInterfaceWithLookup.sol";
|
||||
|
||||
|
||||
contract SupportsInterfaceWithLookupMock is SupportsInterfaceWithLookup {
|
||||
function registerInterface(bytes4 _interfaceId)
|
||||
public
|
||||
{
|
||||
_registerInterface(_interfaceId);
|
||||
}
|
||||
}
|
||||
22
contracts/mocks/TimedCrowdsaleImpl.sol
Normal file
22
contracts/mocks/TimedCrowdsaleImpl.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/validation/TimedCrowdsale.sol";
|
||||
|
||||
|
||||
contract TimedCrowdsaleImpl is TimedCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _openingTime,
|
||||
uint256 _closingTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token
|
||||
)
|
||||
public
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
TimedCrowdsale(_openingTime, _closingTime)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
14
contracts/mocks/WhitelistMock.sol
Normal file
14
contracts/mocks/WhitelistMock.sol
Normal file
@ -0,0 +1,14 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../access/Whitelist.sol";
|
||||
|
||||
|
||||
contract WhitelistMock is Whitelist {
|
||||
|
||||
function onlyWhitelistedCanDoThis()
|
||||
external
|
||||
onlyIfWhitelisted(msg.sender)
|
||||
view
|
||||
{
|
||||
}
|
||||
}
|
||||
19
contracts/mocks/WhitelistedCrowdsaleImpl.sol
Normal file
19
contracts/mocks/WhitelistedCrowdsaleImpl.sol
Normal file
@ -0,0 +1,19 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../crowdsale/validation/WhitelistedCrowdsale.sol";
|
||||
import "../crowdsale/Crowdsale.sol";
|
||||
|
||||
|
||||
contract WhitelistedCrowdsaleImpl is Crowdsale, WhitelistedCrowdsale {
|
||||
|
||||
constructor (
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
ERC20 _token
|
||||
)
|
||||
Crowdsale(_rate, _wallet, _token)
|
||||
public
|
||||
{
|
||||
}
|
||||
}
|
||||
26
contracts/ownership/CanReclaimToken.sol
Normal file
26
contracts/ownership/CanReclaimToken.sol
Normal file
@ -0,0 +1,26 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Ownable.sol";
|
||||
import "../token/ERC20/ERC20Basic.sol";
|
||||
import "../token/ERC20/SafeERC20.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Contracts that should be able to recover tokens
|
||||
* @author SylTi
|
||||
* @dev This allow a contract to recover any ERC20 token received in a contract by transferring the balance to the contract owner.
|
||||
* This will prevent any accidental loss of tokens.
|
||||
*/
|
||||
contract CanReclaimToken is Ownable {
|
||||
using SafeERC20 for ERC20Basic;
|
||||
|
||||
/**
|
||||
* @dev Reclaim all ERC20Basic compatible tokens
|
||||
* @param _token ERC20Basic The address of the token contract
|
||||
*/
|
||||
function reclaimToken(ERC20Basic _token) external onlyOwner {
|
||||
uint256 balance = _token.balanceOf(this);
|
||||
_token.safeTransfer(owner, balance);
|
||||
}
|
||||
|
||||
}
|
||||
39
contracts/ownership/Claimable.sol
Normal file
39
contracts/ownership/Claimable.sol
Normal file
@ -0,0 +1,39 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Claimable
|
||||
* @dev Extension for the Ownable contract, where the ownership needs to be claimed.
|
||||
* This allows the new owner to accept the transfer.
|
||||
*/
|
||||
contract Claimable is Ownable {
|
||||
address public pendingOwner;
|
||||
|
||||
/**
|
||||
* @dev Modifier throws if called by any account other than the pendingOwner.
|
||||
*/
|
||||
modifier onlyPendingOwner() {
|
||||
require(msg.sender == pendingOwner);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to set the pendingOwner address.
|
||||
* @param newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public onlyOwner {
|
||||
pendingOwner = newOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the pendingOwner address to finalize the transfer.
|
||||
*/
|
||||
function claimOwnership() public onlyPendingOwner {
|
||||
emit OwnershipTransferred(owner, pendingOwner);
|
||||
owner = pendingOwner;
|
||||
pendingOwner = address(0);
|
||||
}
|
||||
}
|
||||
22
contracts/ownership/Contactable.sol
Normal file
22
contracts/ownership/Contactable.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Contactable token
|
||||
* @dev Basic version of a contactable contract, allowing the owner to provide a string with their
|
||||
* contact information.
|
||||
*/
|
||||
contract Contactable is Ownable {
|
||||
|
||||
string public contactInformation;
|
||||
|
||||
/**
|
||||
* @dev Allows the owner to set a string with their contact information.
|
||||
* @param _info The contact information to attach to the contract.
|
||||
*/
|
||||
function setContactInformation(string _info) public onlyOwner {
|
||||
contactInformation = _info;
|
||||
}
|
||||
}
|
||||
40
contracts/ownership/DelayedClaimable.sol
Normal file
40
contracts/ownership/DelayedClaimable.sol
Normal file
@ -0,0 +1,40 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Claimable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title DelayedClaimable
|
||||
* @dev Extension for the Claimable contract, where the ownership needs to be claimed before/after
|
||||
* a certain block number.
|
||||
*/
|
||||
contract DelayedClaimable is Claimable {
|
||||
|
||||
uint256 public end;
|
||||
uint256 public start;
|
||||
|
||||
/**
|
||||
* @dev Used to specify the time period during which a pending
|
||||
* owner can claim ownership.
|
||||
* @param _start The earliest time ownership can be claimed.
|
||||
* @param _end The latest time ownership can be claimed.
|
||||
*/
|
||||
function setLimits(uint256 _start, uint256 _end) public onlyOwner {
|
||||
require(_start <= _end);
|
||||
end = _end;
|
||||
start = _start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the pendingOwner address to finalize the transfer, as long as it is called within
|
||||
* the specified start and end time.
|
||||
*/
|
||||
function claimOwnership() public onlyPendingOwner {
|
||||
require((block.number <= end) && (block.number >= start));
|
||||
emit OwnershipTransferred(owner, pendingOwner);
|
||||
owner = pendingOwner;
|
||||
pendingOwner = address(0);
|
||||
end = 0;
|
||||
}
|
||||
|
||||
}
|
||||
22
contracts/ownership/HasNoContracts.sol
Normal file
22
contracts/ownership/HasNoContracts.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Contracts that should not own Contracts
|
||||
* @author Remco Bloemen <remco@2π.com>
|
||||
* @dev Should contracts (anything Ownable) end up being owned by this contract, it allows the owner
|
||||
* of this contract to reclaim ownership of the contracts.
|
||||
*/
|
||||
contract HasNoContracts is Ownable {
|
||||
|
||||
/**
|
||||
* @dev Reclaim ownership of Ownable contracts
|
||||
* @param _contractAddr The address of the Ownable to be reclaimed.
|
||||
*/
|
||||
function reclaimContract(address _contractAddr) external onlyOwner {
|
||||
Ownable contractInst = Ownable(_contractAddr);
|
||||
contractInst.transferOwnership(owner);
|
||||
}
|
||||
}
|
||||
41
contracts/ownership/HasNoEther.sol
Normal file
41
contracts/ownership/HasNoEther.sol
Normal file
@ -0,0 +1,41 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Contracts that should not own Ether
|
||||
* @author Remco Bloemen <remco@2π.com>
|
||||
* @dev This tries to block incoming ether to prevent accidental loss of Ether. Should Ether end up
|
||||
* in the contract, it will allow the owner to reclaim this Ether.
|
||||
* @notice Ether can still be sent to this contract by:
|
||||
* calling functions labeled `payable`
|
||||
* `selfdestruct(contract_address)`
|
||||
* mining directly to the contract address
|
||||
*/
|
||||
contract HasNoEther is Ownable {
|
||||
|
||||
/**
|
||||
* @dev Constructor that rejects incoming Ether
|
||||
* The `payable` flag is added so we can access `msg.value` without compiler warning. If we
|
||||
* leave out payable, then Solidity will allow inheriting contracts to implement a payable
|
||||
* constructor. By doing it this way we prevent a payable constructor from working. Alternatively
|
||||
* we could use assembly to access msg.value.
|
||||
*/
|
||||
constructor() public payable {
|
||||
require(msg.value == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Disallows direct send by setting a default function without the `payable` flag.
|
||||
*/
|
||||
function() external {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfer all Ether held by the contract to the owner.
|
||||
*/
|
||||
function reclaimEther() external onlyOwner {
|
||||
owner.transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
35
contracts/ownership/HasNoTokens.sol
Normal file
35
contracts/ownership/HasNoTokens.sol
Normal file
@ -0,0 +1,35 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./CanReclaimToken.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Contracts that should not own Tokens
|
||||
* @author Remco Bloemen <remco@2π.com>
|
||||
* @dev This blocks incoming ERC223 tokens to prevent accidental loss of tokens.
|
||||
* Should tokens (any ERC20Basic compatible) end up in the contract, it allows the
|
||||
* owner to reclaim the tokens.
|
||||
*/
|
||||
contract HasNoTokens is CanReclaimToken {
|
||||
|
||||
/**
|
||||
* @dev Reject all ERC223 compatible tokens
|
||||
* @param _from address The address that is transferring the tokens
|
||||
* @param _value uint256 the amount of the specified token
|
||||
* @param _data Bytes The data passed from the caller.
|
||||
*/
|
||||
function tokenFallback(
|
||||
address _from,
|
||||
uint256 _value,
|
||||
bytes _data
|
||||
)
|
||||
external
|
||||
pure
|
||||
{
|
||||
_from;
|
||||
_value;
|
||||
_data;
|
||||
revert();
|
||||
}
|
||||
|
||||
}
|
||||
126
contracts/ownership/Heritable.sol
Normal file
126
contracts/ownership/Heritable.sol
Normal file
@ -0,0 +1,126 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Heritable
|
||||
* @dev The Heritable contract provides ownership transfer capabilities, in the
|
||||
* case that the current owner stops "heartbeating". Only the heir can pronounce the
|
||||
* owner's death.
|
||||
*/
|
||||
contract Heritable is Ownable {
|
||||
address private heir_;
|
||||
|
||||
// Time window the owner has to notify they are alive.
|
||||
uint256 private heartbeatTimeout_;
|
||||
|
||||
// Timestamp of the owner's death, as pronounced by the heir.
|
||||
uint256 private timeOfDeath_;
|
||||
|
||||
event HeirChanged(address indexed owner, address indexed newHeir);
|
||||
event OwnerHeartbeated(address indexed owner);
|
||||
event OwnerProclaimedDead(
|
||||
address indexed owner,
|
||||
address indexed heir,
|
||||
uint256 timeOfDeath
|
||||
);
|
||||
event HeirOwnershipClaimed(
|
||||
address indexed previousOwner,
|
||||
address indexed newOwner
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @dev Throw an exception if called by any account other than the heir's.
|
||||
*/
|
||||
modifier onlyHeir() {
|
||||
require(msg.sender == heir_);
|
||||
_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notice Create a new Heritable Contract with heir address 0x0.
|
||||
* @param _heartbeatTimeout time available for the owner to notify they are alive,
|
||||
* before the heir can take ownership.
|
||||
*/
|
||||
constructor(uint256 _heartbeatTimeout) public {
|
||||
setHeartbeatTimeout(_heartbeatTimeout);
|
||||
}
|
||||
|
||||
function setHeir(address _newHeir) public onlyOwner {
|
||||
require(_newHeir != owner);
|
||||
heartbeat();
|
||||
emit HeirChanged(owner, _newHeir);
|
||||
heir_ = _newHeir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Use these getter functions to access the internal variables in
|
||||
* an inherited contract.
|
||||
*/
|
||||
function heir() public view returns(address) {
|
||||
return heir_;
|
||||
}
|
||||
|
||||
function heartbeatTimeout() public view returns(uint256) {
|
||||
return heartbeatTimeout_;
|
||||
}
|
||||
|
||||
function timeOfDeath() public view returns(uint256) {
|
||||
return timeOfDeath_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev set heir = 0x0
|
||||
*/
|
||||
function removeHeir() public onlyOwner {
|
||||
heartbeat();
|
||||
heir_ = address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Heir can pronounce the owners death. To claim the ownership, they will
|
||||
* have to wait for `heartbeatTimeout` seconds.
|
||||
*/
|
||||
function proclaimDeath() public onlyHeir {
|
||||
require(ownerLives());
|
||||
emit OwnerProclaimedDead(owner, heir_, timeOfDeath_);
|
||||
// solium-disable-next-line security/no-block-members
|
||||
timeOfDeath_ = block.timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Owner can send a heartbeat if they were mistakenly pronounced dead.
|
||||
*/
|
||||
function heartbeat() public onlyOwner {
|
||||
emit OwnerHeartbeated(owner);
|
||||
timeOfDeath_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows heir to transfer ownership only if heartbeat has timed out.
|
||||
*/
|
||||
function claimHeirOwnership() public onlyHeir {
|
||||
require(!ownerLives());
|
||||
// solium-disable-next-line security/no-block-members
|
||||
require(block.timestamp >= timeOfDeath_ + heartbeatTimeout_);
|
||||
emit OwnershipTransferred(owner, heir_);
|
||||
emit HeirOwnershipClaimed(owner, heir_);
|
||||
owner = heir_;
|
||||
timeOfDeath_ = 0;
|
||||
}
|
||||
|
||||
function setHeartbeatTimeout(uint256 _newHeartbeatTimeout)
|
||||
internal onlyOwner
|
||||
{
|
||||
require(ownerLives());
|
||||
heartbeatTimeout_ = _newHeartbeatTimeout;
|
||||
}
|
||||
|
||||
function ownerLives() internal view returns (bool) {
|
||||
return timeOfDeath_ == 0;
|
||||
}
|
||||
}
|
||||
15
contracts/ownership/NoOwner.sol
Normal file
15
contracts/ownership/NoOwner.sol
Normal file
@ -0,0 +1,15 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./HasNoEther.sol";
|
||||
import "./HasNoTokens.sol";
|
||||
import "./HasNoContracts.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Base contract for contracts that should not own things.
|
||||
* @author Remco Bloemen <remco@2π.com>
|
||||
* @dev Solves a class of errors where a contract accidentally becomes owner of Ether, Tokens or
|
||||
* Owned contracts. See respective base contracts for details.
|
||||
*/
|
||||
contract NoOwner is HasNoEther, HasNoTokens, HasNoContracts {
|
||||
}
|
||||
@ -1,6 +1,4 @@
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "zos-lib/contracts/migrations/Migratable.sol";
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
@ -8,18 +6,23 @@ import "zos-lib/contracts/migrations/Migratable.sol";
|
||||
* @dev The Ownable contract has an owner address, and provides basic authorization control
|
||||
* functions, this simplifies the implementation of "user permissions".
|
||||
*/
|
||||
contract Ownable is Migratable {
|
||||
contract Ownable {
|
||||
address public owner;
|
||||
|
||||
|
||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
||||
event OwnershipRenounced(address indexed previousOwner);
|
||||
event OwnershipTransferred(
|
||||
address indexed previousOwner,
|
||||
address indexed newOwner
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
|
||||
* account.
|
||||
*/
|
||||
function initialize(address _sender) public isInitializer("Ownable", "1.9.0") {
|
||||
owner = _sender;
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,13 +34,31 @@ contract Ownable is Migratable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to transfer control of the contract to a newOwner.
|
||||
* @param newOwner The address to transfer ownership to.
|
||||
* @dev Allows the current owner to relinquish control of the contract.
|
||||
* @notice Renouncing to ownership will leave the contract without an owner.
|
||||
* It will not be possible to call the functions with the `onlyOwner`
|
||||
* modifier anymore.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public onlyOwner {
|
||||
require(newOwner != address(0));
|
||||
emit OwnershipTransferred(owner, newOwner);
|
||||
owner = newOwner;
|
||||
function renounceOwnership() public onlyOwner {
|
||||
emit OwnershipRenounced(owner);
|
||||
owner = address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to transfer control of the contract to a newOwner.
|
||||
* @param _newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function transferOwnership(address _newOwner) public onlyOwner {
|
||||
_transferOwnership(_newOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers control of the contract to a newOwner.
|
||||
* @param _newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function _transferOwnership(address _newOwner) internal {
|
||||
require(_newOwner != address(0));
|
||||
emit OwnershipTransferred(owner, _newOwner);
|
||||
owner = _newOwner;
|
||||
}
|
||||
}
|
||||
|
||||
62
contracts/ownership/Superuser.sol
Normal file
62
contracts/ownership/Superuser.sol
Normal file
@ -0,0 +1,62 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
import "./Ownable.sol";
|
||||
import "../access/rbac/RBAC.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Superuser
|
||||
* @dev The Superuser contract defines a single superuser who can transfer the ownership
|
||||
* of a contract to a new address, even if he is not the owner.
|
||||
* A superuser can transfer his role to a new address.
|
||||
*/
|
||||
contract Superuser is Ownable, RBAC {
|
||||
string public constant ROLE_SUPERUSER = "superuser";
|
||||
|
||||
constructor () public {
|
||||
addRole(msg.sender, ROLE_SUPERUSER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Throws if called by any account that's not a superuser.
|
||||
*/
|
||||
modifier onlySuperuser() {
|
||||
checkRole(msg.sender, ROLE_SUPERUSER);
|
||||
_;
|
||||
}
|
||||
|
||||
modifier onlyOwnerOrSuperuser() {
|
||||
require(msg.sender == owner || isSuperuser(msg.sender));
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev getter to determine if address has superuser role
|
||||
*/
|
||||
function isSuperuser(address _addr)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
return hasRole(_addr, ROLE_SUPERUSER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current superuser to transfer his role to a newSuperuser.
|
||||
* @param _newSuperuser The address to transfer ownership to.
|
||||
*/
|
||||
function transferSuperuser(address _newSuperuser) public onlySuperuser {
|
||||
require(_newSuperuser != address(0));
|
||||
removeRole(msg.sender, ROLE_SUPERUSER);
|
||||
addRole(_newSuperuser, ROLE_SUPERUSER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current superuser or owner to transfer control of the contract to a newOwner.
|
||||
* @param _newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser {
|
||||
_transferOwnership(_newOwner);
|
||||
}
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "./Roles.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RBAC (Role-Based Access Control)
|
||||
* @author Matt Condon (@Shrugs)
|
||||
* @dev Stores and provides setters and getters for roles and addresses.
|
||||
* @dev Supports unlimited numbers of roles and addresses.
|
||||
* @dev See //contracts/mocks/RBACMock.sol for an example of usage.
|
||||
* This RBAC method uses strings to key roles. It may be beneficial
|
||||
* for you to write your own implementation of this interface using Enums or similar.
|
||||
* It's also recommended that you define constants in the contract, like ROLE_ADMIN below,
|
||||
* to avoid typos.
|
||||
*/
|
||||
contract RBAC {
|
||||
using Roles for Roles.Role;
|
||||
|
||||
mapping (string => Roles.Role) private roles;
|
||||
|
||||
event RoleAdded(address addr, string roleName);
|
||||
event RoleRemoved(address addr, string roleName);
|
||||
|
||||
/**
|
||||
* @dev reverts if addr does not have role
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
* // reverts
|
||||
*/
|
||||
function checkRole(address addr, string roleName)
|
||||
view
|
||||
public
|
||||
{
|
||||
roles[roleName].check(addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev determine if addr has role
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
* @return bool
|
||||
*/
|
||||
function hasRole(address addr, string roleName)
|
||||
view
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
return roles[roleName].has(addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add a role to an address
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
*/
|
||||
function addRole(address addr, string roleName)
|
||||
internal
|
||||
{
|
||||
roles[roleName].add(addr);
|
||||
emit RoleAdded(addr, roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove a role from an address
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
*/
|
||||
function removeRole(address addr, string roleName)
|
||||
internal
|
||||
{
|
||||
roles[roleName].remove(addr);
|
||||
emit RoleRemoved(addr, roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to a single role (uses msg.sender as addr)
|
||||
* @param roleName the name of the role
|
||||
* // reverts
|
||||
*/
|
||||
modifier onlyRole(string roleName)
|
||||
{
|
||||
checkRole(msg.sender, roleName);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to a set of roles (uses msg.sender as addr)
|
||||
* @param roleNames the names of the roles to scope access to
|
||||
* // reverts
|
||||
*
|
||||
* @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this
|
||||
* see: https://github.com/ethereum/solidity/issues/2467
|
||||
*/
|
||||
// modifier onlyRoles(string[] roleNames) {
|
||||
// bool hasAnyRole = false;
|
||||
// for (uint8 i = 0; i < roleNames.length; i++) {
|
||||
// if (hasRole(msg.sender, roleNames[i])) {
|
||||
// hasAnyRole = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// require(hasAnyRole);
|
||||
|
||||
// _;
|
||||
// }
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
pragma solidity ^0.4.21;
|
||||
|
||||
import "./RBAC.sol";
|
||||
import "zos-lib/contracts/migrations/Migratable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title RBACWithAdmin
|
||||
* @author Matt Condon (@Shrugs)
|
||||
* @dev It's recommended that you define constants in the contract,
|
||||
* @dev like ROLE_ADMIN below, to avoid typos.
|
||||
*/
|
||||
contract RBACWithAdmin is RBAC, Migratable {
|
||||
/**
|
||||
* A constant role name for indicating admins.
|
||||
*/
|
||||
string public constant ROLE_ADMIN = "admin";
|
||||
|
||||
/**
|
||||
* @dev modifier to scope access to admins
|
||||
* // reverts
|
||||
*/
|
||||
modifier onlyAdmin()
|
||||
{
|
||||
checkRole(msg.sender, ROLE_ADMIN);
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev constructor. Sets initialAdmin as admin.
|
||||
*/
|
||||
function initialize(address initialAdmin)
|
||||
isInitializer("RBACWithAdmin", "1.9.0")
|
||||
public
|
||||
{
|
||||
addRole(initialAdmin, ROLE_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev add a role to an address
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
*/
|
||||
function adminAddRole(address addr, string roleName)
|
||||
onlyAdmin
|
||||
public
|
||||
{
|
||||
addRole(addr, roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev remove a role from an address
|
||||
* @param addr address
|
||||
* @param roleName the name of the role
|
||||
*/
|
||||
function adminRemoveRole(address addr, string roleName)
|
||||
onlyAdmin
|
||||
public
|
||||
{
|
||||
removeRole(addr, roleName);
|
||||
}
|
||||
}
|
||||
22
contracts/payment/ConditionalEscrow.sol
Normal file
22
contracts/payment/ConditionalEscrow.sol
Normal file
@ -0,0 +1,22 @@
|
||||
pragma solidity ^0.4.23;
|
||||
|
||||
import "./Escrow.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title ConditionalEscrow
|
||||
* @dev Base abstract escrow to only allow withdrawal if a condition is met.
|
||||
*/
|
||||
contract ConditionalEscrow is Escrow {
|
||||
/**
|
||||
* @dev Returns whether an address is allowed to withdraw their funds. To be
|
||||
* implemented by derived contracts.
|
||||
* @param _payee The destination address of the funds.
|
||||
*/
|
||||
function withdrawalAllowed(address _payee) public view returns (bool);
|
||||
|
||||
function withdraw(address _payee) public {
|
||||
require(withdrawalAllowed(_payee));
|
||||
super.withdraw(_payee);
|
||||
}
|
||||
}
|
||||
51
contracts/payment/Escrow.sol
Normal file
51
contracts/payment/Escrow.sol
Normal file
@ -0,0 +1,51 @@
|
||||
pragma solidity ^0.4.23;
|
||||
|
||||
import "../math/SafeMath.sol";
|
||||
import "../ownership/Ownable.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title Escrow
|
||||
* @dev Base escrow contract, holds funds destinated to a payee until they
|
||||
* withdraw them. The contract that uses the escrow as its payment method
|
||||
* should be its owner, and provide public methods redirecting to the escrow's
|
||||
* deposit and withdraw.
|
||||
*/
|
||||
contract Escrow is Ownable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
event Deposited(address indexed payee, uint256 weiAmount);
|
||||
event Withdrawn(address indexed payee, uint256 weiAmount);
|
||||
|
||||
mapping(address => uint256) private deposits;
|
||||
|
||||
function depositsOf(address _payee) public view returns (uint256) {
|
||||
return deposits[_payee];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Stores the sent amount as credit to be withdrawn.
|
||||
* @param _payee The destination address of the funds.
|
||||
*/
|
||||
function deposit(address _payee) public onlyOwner payable {
|
||||
uint256 amount = msg.value;
|
||||
deposits[_payee] = deposits[_payee].add(amount);
|
||||
|
||||
emit Deposited(_payee, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw accumulated balance for a payee.
|
||||
* @param _payee The address whose funds will be withdrawn and transferred to.
|
||||
*/
|
||||
function withdraw(address _payee) public onlyOwner {
|
||||
uint256 payment = deposits[_payee];
|
||||
assert(address(this).balance >= payment);
|
||||
|
||||
deposits[_payee] = 0;
|
||||
|
||||
_payee.transfer(payment);
|
||||
|
||||
emit Withdrawn(_payee, payment);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user