Compare commits

...

141 Commits

Author SHA1 Message Date
0e65947efb Release v1.12.0 2018-08-10 19:09:13 -03:00
59cb2e2d0f release candidate v1.12.0-rc.2 2018-08-03 15:47:22 -03:00
418a6b5791 Crowdsale inheritance order (#1128)
* Changed Crowdsale inheritance order.

* Changed FinalizableCrowdsale inheritance order.

(cherry picked from commit 3d86c58d2c)
2018-08-02 18:37:39 -03:00
3806d6128e release candidate v1.12.0-rc.1 2018-08-01 15:00:38 -03:00
4d799f3cbe Sorted .soliumrc.json rules. 2018-08-01 13:09:40 -03:00
07a27f0e5e Disabled Solium's error-reason rule. (#1138) 2018-08-01 12:56:28 -03:00
ca9e317259 Update Truffle and Solium (#1105)
* fixed visibility warnings

* solved visibility and line length warning

* change a test assertion that fails due to chai dependence update

* linter, constructor style and solved visibility warnings

* Changed Windows line endings to Unix.
2018-08-01 10:11:37 -03:00
9638ecd87a Typo fix. 2018-08-01 08:31:05 -03:00
56735a706c Use address(this) instead of this (#1134)
* Use address(this) instead of this

It's preferred to use `address(this)` vs `this`

* Change to address(this) vs this
2018-07-31 13:36:38 -03:00
2765350248 Prefix all parameters with underscore (#1133) 2018-07-31 13:06:53 -03:00
1200969eb6 Refactor/reentrancy guard gas optimization #1056 (#1057)
* optimizing ReentrancyGuard gas usage

* style fixed
2018-07-27 22:36:17 -03:00
90b98a7bef Add pure to tokenFallback function (#1122)
Silences warning
2018-07-27 22:25:39 -03:00
16429b1522 Making visibility explicit for storage variables (#759)
* Making visibility explicit for storage variables

* Made BasicToken's variables internal.
2018-07-27 17:50:33 -03:00
ae2980b072 Add EditorConfig (#1119)
* Add EditorConfig file.

This allows users with a wide variety of editors to easily code in
OpenZeppelin's preferred 2 space indentation code style.

See https://editorconfig.org for more information.

* Eslint: Always disallow trailing space

* Eslint: Error on missing EOL at file end
2018-07-27 14:55:24 -03:00
f5b0bb3246 Added more comprehensive usage information to the Getting Started guide: (#1089)
* Added an Architecture section that speaks to the different types of contracts
* Added a Tests section that provides high-level visibility into what is used for unit testing
* Added a How To Use and Modify OpenZeppelin Contracts section
* Added development principles to the existing Security section
2018-07-27 13:33:13 -03:00
4c6575bf2f fix: solium linting errors (#1113)
* fix: solium linting errors, fixes #1092

* fix: remove uppercase requirement
2018-07-26 23:53:24 -03:00
2f6c8b05f6 Test/assertRevert: Fix late return bug (#1123)
We now ensure that if an exception is thrown while awaiting the promise,
the exception _has_ to be a revert. We throw 'Expected revert not
received' only afterwards. This solves any problems with confusing the
word 'revert'.

Fix #775
2018-07-26 23:53:06 -03:00
567b773242 Prefer const in test files (#1117)
* Removed all instances of var.

* Sorted eslintrc rules.

* Made eslint rule severity explicit.

* Now prefering const over let.
2018-07-26 13:25:10 -03:00
6e19ed47be fix: bounty tests, superceeds #799 (#1112)
* fix: bounty tests, superceeds #799

* fix: updates from PR notes
2018-07-26 12:17:16 -03:00
e6c15b34da Remove chai-as-promised (#1116)
* Test: Remove chai-as-promised calls

* Test/Helpers: expectThrow accepts optional message

* NPM: Remove chai-as-promised

* Contracts/DestructibleMock: Fix lint
2018-07-26 11:53:33 -03:00
afe9113b18 fix: move RBAC to //access (#1114) 2018-07-25 12:03:25 -03:00
73be06412f Remove payable from Destructible constructor (#1107)
* Destructible no longer has a payable constructor.

* Fixed linter errors.
2018-07-23 15:44:14 -03:00
23074676c4 Improved documentation for _preValidatePurchase method in Crowdsale (#1101)
* Improved documentation for _preValidatePurchase in Crowdsale

* Added newline at EOF
2018-07-22 14:41:34 -03:00
3c69cf658c Removed JSHint (unused). (#1088) 2018-07-20 17:05:11 -03:00
6bd8842ab5 removed and tested unecessary gas cost (#1017)
* removed and tested unecessary gas cost

* linted

* Revert package-lock.json update.

This reverts commit 054598ce7f.

* Added clarifying comments.
2018-07-20 16:57:39 -03:00
d20d03c149 Remove redundant modifiers from safeTransferFrom (#1029) (#1030) 2018-07-20 16:18:24 -03:00
ebd4b5e73d decrease approval condition fix (greater than and equal to) (#1063)
* decrease approval condition fix (greater than and equal to)

* sol lint fixed

* Improved standard token decreaseApprovalTests.
2018-07-20 14:52:22 -03:00
1ecda54449 Input check sequence modification for gas efficiency (#1043)
* Update StandardToken.sol

* Slight improvement in gas efficiency

Users tend to attempt to over-spend more than they attempt to burn non-burnable tokens. If the contract checks for overspending before assuring tokens are not being burnt a slight amount of gas might be saved in the long term.
2018-07-20 14:52:02 -03:00
67b67b791e Changed before for beforeAll, refactored Bouncer tests. (#1094)
* Changed before for beforeAll, refactored Bouncer tests.

* Fixed linter errors.

* fix: updates for SignatureBouncer tests and voucher construction
2018-07-20 12:25:40 -03:00
ce0c3274ee made remaining public fallback functions external (#1080) 2018-07-20 12:25:25 -03:00
90b3050ad7 minor RBAC.sol documentation fix (#1060) 2018-07-20 12:09:47 -03:00
c95ea5125d Fix MerkleProof natspec comments (#1083) 2018-07-19 22:32:34 -03:00
11266b0d56 Fix ReentrancyGuard comments (#1084) 2018-07-19 22:10:15 -03:00
45d6943913 Fix typos (#1082) 2018-07-19 21:48:20 -03:00
5f6d511af9 Fix typo in Crowdsale.sol (#1035) 2018-07-19 21:47:53 -03:00
7dbb7a8b8e Merge branch 'release-v1.11.0' 2018-07-19 18:01:53 -03:00
3318b91697 feat: add AutoIncrementing contract (#1023)
* feat: add AutoIncrementing contract

* feat: allow multiple counters per instance

* fix: some linting errors

* feat: use recommended implementaiton

* fix: remove .only in tests

* fix: PR notes

* fix: add note about incrementing counter
2018-07-18 16:38:07 -07:00
cea2a85a42 Remove Babel (#1074)
* Test helpers no longer rely on Babel.

* Behaviours are no longer imported.

* Removed Babel dependency.

* Fixed linter errors.
2018-07-18 19:37:16 -03:00
99e4b081dc ECRecover test should revert because of wrong calldata size (#1050)
* Assume that token is mintable.

* ECRecover test should revert because of wrong calldata size

* fix: use expectThrow

* fix: ignore failing test until solc^0.5.0
2018-07-16 18:38:57 -04:00
b120b9aff7 moved ERC165 interface IDs from ERC721 implementation files to the interface file (#1070) 2018-07-15 11:05:45 -04:00
cc9fa57777 v1.11.0 2018-07-13 17:07:14 -03:00
40b5594f52 Promisify web3 sync requests in tests (#1009) 2018-07-10 14:01:51 -07:00
4575a240f7 Create CODE_OF_CONDUCT.md (#1061)
* Create CODE_OF_CONDUCT.md

* fix: update to raw text from website rather than github's provided one
2018-07-05 15:44:20 -03:00
eb4dfea6e9 v1.11.0-rc.1 2018-07-03 19:32:58 -03:00
8fd072cf8e Escrows (#1014)
* Added basic Escrow

* PullPayment now uses an Escrow, removing all trust from the contract

* Abstracted the Escrow tests to a behaviour

* Added ConditionalEscrow

* Added RefundableEscrow.

* RefundableCrowdsale now uses a RefundEscrow, removed RefundVault.

* Renaming after code review.

* Added log test helper.

* Now allowing empty deposits and withdrawals.

* Style fixes.

* Minor review comments.

* Add Deposited and Withdrawn events, removed Refunded

* The base Escrow is now Ownable, users of it (owners) must provide methods to access it.
2018-07-03 18:54:55 -03:00
c2ad8c3f57 Update the use of call() with selector only. (#1033) 2018-06-30 17:55:03 -03:00
fd253d6b8d Fix dependency warnings (#1053)
* update package-lock generated by npm

* run npm audit fix
2018-06-30 17:39:28 -03:00
7d8e3ca8b2 Align ERC721 Receiver with current ERC721 standard. (#1047)
* Align ERC721 Receiver with current ERC721 standard.
Adds a second address field to onERC721Received
onERC721Received(address,address,uint256,bytes)
Updates the function signature to 0x150b7a02 from 0xf0b9e5ba

* Add _operator to onERC721Received

* Fix error caused by formatOnSave

* Fixed comments on ERC721Receiver
Removed "Must use 50,000 gas or less"
Corrected the function signature
2018-06-28 20:11:18 -07:00
6b37ba36a1 Remove ERC827 token. (#1045)
Implementing this token is unsafe as per comments here:
https://github.com/ethereum/EIPs/issues/827#issuecomment-397857455
2018-06-28 13:32:07 -03:00
dc1e352cc4 Don't emit Approval event when approval is cleared on transfer (#1039) 2018-06-24 23:04:57 -07:00
f18c3bc438 feat: initial implementation of ERC1046 (#933)
* feat: initial implementation of ERC1046
2018-06-17 16:21:05 -07:00
0047e79681 ignore truffle generated file (#1019) 2018-06-16 19:30:48 -03:00
74a62a1314 using SafeERC20 to implement safeTransfer in Crowdsale (#1006)
* introduced safeTransfer to Crowdsale

* Removed .node-xmlhttprequest-sync-7601
2018-06-16 12:46:19 -03:00
92b695f2fb Fix/whitelisted crowdsale (#981)
* fix: swithc WhitelistedCrowdsale to use Whitelist.sol

* feat: refactor whitelist.sol, rbac.sol and whitelistedcrowdsale.sol

* feat: add event arg assets and update whitelist

* fix: update modifier comment and also test isWhitelisted

* fix: remove onlyWhitelisted backwards compat attempt, fix explicit inheritance

* fix: remove underscore prefix from event args

* fix: user access/Whitelist
2018-06-15 14:11:50 -07:00
Rob
ee78f67985 fixing comment - changing '_to' to '_spender' (#1007) 2018-06-15 12:08:28 -03:00
07020e9544 Remove redundant @dev tags (#995)
* Remove redundant @dev tags

* Remove redundant @notice tags
2018-06-14 15:19:59 -07:00
b4406d385f Use abi.encodeWithSignature together with raw call() (#1008) 2018-06-14 18:50:39 -03:00
78e39aa2ad Do not use implicit type conversion for address literals (#1002)
Uses the explicit address(0) for the zero address
2018-06-13 16:21:24 -07:00
e4ed8f0705 Added explicit integer sizes to uint variables in StandardToken (#1004) 2018-06-13 11:54:54 -07:00
5daaf60d11 Make contracts 4.24 compatible (#951)
* Make contracts 4.24 compatible
2018-06-13 11:34:32 -07:00
e1dc1411fc WIP: Fix/erc721 (#993)
* fix: defer lookup-specific info to implementations

* fix: change inheritance order, fix import
2018-06-12 18:46:32 -03:00
9f1d294ba4 Move Whitelist contract to access directory (#994) 2018-06-11 19:35:29 -03:00
9951acf6d8 Added aflesher as an author to SignatureBouncer.sol (#996) 2018-06-11 13:48:00 -07:00
72792a724d ownable: add a notice on renounceOwnership (#937)
* ownable: add a notice on renounceOwnership

* Apply the suggestion by @shrugs
2018-06-10 16:39:54 -03:00
b0292cf628 Add isValidSignatureAndData to Bouncer to verify method calls (#973) 2018-06-09 14:45:53 -07:00
39385f9f4e Addressed unchecked return value in AllowanceCrowdsale #945 using SafeERC20 (#946)
* addressed unchecked return value in AllowanceCrowdsale #945 using SafeERC20
2018-06-08 17:00:46 -07:00
7a61371b19 Updated documentation Uppercasing function name for ERC02 basic token (#720) 2018-06-08 16:30:48 -07:00
259b9da3e6 add 165 to 721 (#972)
* make _tokenId indexed in Transfer and Approval events

via: https://github.com/ethereum/EIPs/pull/1124/files

* fix: make name() and symbol() external instead of public

* feat: implement ERC721's ERC165

* feat: erc165 tests

* fix: don't use chai-as-promised in direct await

* fix: reorganize to /introspection

* feat: abstract all erc165 tests to a behavior

* feat: disallow registering 0xffffffff
2018-06-08 18:50:12 -03:00
5326e7c36e Removed redundant modifiers from CappedToken. (#969) 2018-06-06 11:29:54 -07:00
feb665136c 1.10.0 2018-06-05 17:40:24 -03:00
7fb84b42d5 Refactoring Superuser contract to allow Owners to transfer ownership … (#978)
* Refactoring Superuser contract to allow Owners to transfer ownership when they are not superusers #50

* Refactoring tests to create a contract instance for each of them #50
2018-06-05 17:28:42 -03:00
5db0d7d1a0 included command to add upstream (#959) 2018-06-04 18:31:32 -07:00
512e8218ca Add a comment on Detailed ERC20 token #953 (#960)
* add a comment on detailed erc20 token #953
2018-06-04 18:13:09 -07:00
9d6ffae8cb removed mentions of 'development' branch in Contribution Guidelines (#966) 2018-06-04 17:34:04 -07:00
2a997a8e92 Fixed wrong variable name in SampleCrowdsale.test.js. (#916) 2018-06-04 16:49:46 -07:00
5651538045 Clarified the rationaly behind the mul branch test. (#970) 2018-06-04 16:04:08 -07:00
10e84aecaf Fix Node 10 compatibility (#949)
*  update sha3 1.2.0 -> 1.2.2 for node 10 compatibility

* update nan 2.6.2 -> 2.10.0 for node 10 compatibility

* commit new package-lock.json format generated by npm 6
2018-06-04 17:26:23 -03:00
2637bd89be fix: add comment about rbacwithadmin being rather powerful (#936)
* fix: add comment about rbacwithadmin being rather powerful
* fix: move RBACWithAdmin to examples
2018-06-04 12:32:57 -07:00
32ec8b5398 Add Status Embark to README (#956)
* Update README.md

* update embark import to use the v1.9.0 tag instead of master

* Update README.md
2018-06-04 15:21:55 -03:00
a0c03ee61c Adding new Superuser contract with test (#952)
* Adding new Superuser contract + tests
2018-06-03 16:14:30 -07:00
e3f866c982 fix: remove daylimit.sol, closes #925 (#964) 2018-06-01 13:16:47 -07:00
5ab9024b6a update balance syntax for solidity 0.4.23 (#940) 2018-05-30 16:10:08 -07:00
d5f06ab32f addressed TokenVesting contstructor natspec updates in #742 (#935) 2018-05-29 10:45:40 -06:00
746673a94f style: use the max-len solidity rule (#944) 2018-05-14 11:42:32 -06:00
ba4cf03da7 contracts mocks: replace deprecated constant with view (#931) 2018-05-10 10:43:15 -06:00
39370ff690 Adding RBAC Mintable token (#923)
* added the RBACMintableToken
* added MintedCrowdsale with RBACMintableToken test
* added a mintable behaviour for tests
* moved minting tests in behaviour
* created a minted crowdsale behaviour to be tested with both mintable and rbacmintable token
2018-05-09 18:01:25 -07:00
ad12381549 update constructor syntax for solidity 0.4.23 in numerous contracts (#921)
* update solidity-coverage to ^0.5.0

* update truffle dependency to ^4.1.8

* update solium to ^1.1.7

* update all contracts to solidity ^0.4.23
2018-05-08 18:02:00 -07:00
20b85be6aa Ownable behavior (#929)
* added function to renounce ownership

* Provide an Ownable behavior for testing (#905)

* Fix indentation

* Convert to use should assertions
2018-05-08 17:33:37 -07:00
4223c9d50e feat: refactor whitelist.sol to use RBAC (#893)
* feat: refactor whitelist.sol to use RBAC

* fix: remove poor backwards compat attempt
2018-05-08 17:20:28 -07:00
f0eea31bdf Fix ERC721Token.sol code indent (#909) 2018-05-07 11:39:54 -07:00
ce0a928a6c Fix typos in ERC721BasicToken comments (#889) 2018-05-07 11:20:12 -07:00
85f079ee89 Removing more asserts in favor of require (#834)
* Removed asserts and replaced them in favor of require

* Adapted tests to work with requires
2018-05-03 14:04:02 -03:00
7e44204d9b added function to renounce ownership (#907) 2018-05-03 13:25:18 -03:00
4a10f727c4 1.9.0 2018-04-26 16:36:06 -03:00
e79dc645e4 Merge branch 'rename-openzeppelin-solidity' 2018-04-26 16:35:19 -03:00
0e5799c93b Clean up npm package (#904)
* ignore everything but official contracts for npm

* add tests to npm package

* remove truffle migrations stuff

* remove seemingly unused npm dependency

* clean up dependencies
2018-04-26 12:36:41 -03:00
90413e75f1 add version script to update ethpm.json (#906) 2018-04-25 20:32:09 -03:00
9c262571ae rename to openzeppelin-solidity 2018-04-25 19:19:15 -03:00
76fe1548ae Fix ERC721 test is not checking name and symbol properly #910 (#911) 2018-04-23 20:36:47 -03:00
8f2a4785cb Make ERC827 methods payable (#838)
* Make ERC827 methods payable

* Suppress linter errors

* Add some ERC827 payable tests

* Remove failOnBuy method from MessageHelper

* Fix linter warning

* Fix tests
2018-04-23 15:16:55 +02:00
16535fbb87 Update ERC827.sol to not use function overloading (#871)
* Update ERC827.sol to not use function overloading

* updated tests for erc827 function name changes

* fixed broken test

* removed findMethod from erc827 tests that is no longer necessary
2018-04-23 13:39:34 +02:00
77cc33fc5c cleaned up unsued variable definition (#753) 2018-04-20 16:01:05 -03:00
0b33d29e41 Add travis job to run test suite with solc nightly (#902)
Job is allowed to fail, and is run just for information purposes
2018-04-19 12:12:36 -03:00
61dfdde6c4 Updated send to sent. Matching indentation of closing comment. (#897) 2018-04-18 14:48:16 -03:00
e8be9a7bd0 Remove suggestion to rebase (#899) 2018-04-18 14:47:22 -03:00
dd8758fedf move misplaced MathMock (#900) 2018-04-18 14:47:00 -03:00
c63b203c1d Small SafeMath.sol gas improvements (add & mul). (#894) 2018-04-17 19:16:30 -03:00
c191757c6e rename truffle.js to truffle-config.js (#886) 2018-04-17 17:14:38 -03:00
f4bdaf49a1 Increase test coverage to 93% #549 (#768)
* Increase test coverage to 93% #549

* cover missing AllowanceCrowdsale branch

* improve Heritable coverage

* fix lint errors

* proper equal assert

* address review comments

* remove unneeded const definitions and imports

* use assertRevert

* reword scenario description

* Increase test coverage to 93% #549

* cover missing AllowanceCrowdsale branch

* improve Heritable coverage

* fix lint errors

* proper equal assert

* address review comments

* remove unneeded const definitions and imports

* use assertRevert

* reword scenario description

* move HIGH_GOAL constant to the scope where it's used

* remove const at top level

* address review comments
2018-04-17 15:05:34 -03:00
6a7114fdb4 Bouncer contract implementation (#883)
* feat: implement bouncer contracts

* fix: rename Bouncer to SignatureBouncer
2018-04-17 11:36:24 -03:00
0926729c8f Add StandardBurnableToken implementation (#870)
* Add StandardBurnableToken implementation

BurnableToken that extends from StandardToken and adds a
burnFrom method that decrements allowance. Equivalent to
a transferFrom plus burn in a single operation.

* Return event object from expectEvent helper

* Add comment on Approval event in burnFrom function

* Improvements on burnable token tests

- Inject initial balance as a parameter to the behaviour
- Use expectEvent helper for assertions on events
- Use chai bignumber for numbers
- Change to bdd-style assertions
2018-04-11 16:15:33 -03:00
9e1c934ffd Various fixes and formatting chores (#885)
* fix: clean up solium linting errors

* fix: make various contracts natspec compliant

* fix: this.balance deprecated; convert to address(this).balance

* fix: contract.call deprecated and switch to gasleft()

* fix: ignore empty block rule project-wide

* fix: add ignore cases for the rest of the linting warnings
2018-04-10 20:31:29 -03:00
a7e91856f3 Update to Truffle 4.1.5 and Ganache 6.1.0 (#876)
* Update to ganache-cli v6.1.0 and truffle v4.1.0

* Update to stable version of ganache-cli

* fix: update event emission warning

- Fix event emission warnings for solidity 4.21 after truffle has been
updated to use this version

* fix pr review comments

* update to truffle v4.1.5

* update package-lock

* add additional emit keywords

* update solidity-coverage to 0.4.15

* update to solium 1.1.6

* fix MerkleProof coverage analysis by testing through wrapper

* change version pragma to ^0.4.21

* fix solium linting errors
2018-04-09 20:48:32 -03:00
06666be93a change MerkleProof interface to take array of bytes32 (#879) 2018-04-08 12:36:16 -03:00
915f74c5f6 remove collaborators and audits from README (#866) 2018-04-04 21:17:27 -03:00
3d3f20f7e3 Removing obsolete comment - explicit check in place (#851) 2018-04-04 09:53:55 -03:00
03a3302abd add missing await in IndividuallyCappedCrowdsale (#867) 2018-04-03 18:50:24 -03:00
bd5f7f5774 Fix SafeMath test file (#865) 2018-04-03 17:54:48 -03:00
a6bef44790 fix: remove admin functionality from RBAC.sol fixes #802 (#836)
- splits the admin part of RBAC.sol into RBACWithAdmin.sol
2018-04-03 16:56:31 -03:00
a9c777faa6 docs: fix contributing link (#848)
* docs: fix contributing link
2018-04-03 15:56:01 -03:00
44a404aae5 Remove unnecessary import from ERC721Token.sol (#855)
The DeprecatedERC721.sol isn't implemented or necessary.
2018-04-03 11:32:52 -03:00
1d2d18f9da Small gas improvement in SafeMath.sol (#811) 2018-03-28 15:00:10 -03:00
82ce197e44 tests: fix most of the static warnings (#844) 2018-03-28 13:33:58 -03:00
42787e2a75 added awaits (#845) 2018-03-26 21:55:52 -03:00
9bc43c8d0f make ethjs-abi a devDependency (#843) 2018-03-26 16:24:12 -03:00
cacf03641c v1.8.0 2018-03-23 15:14:10 -03:00
e96164feea ERC721 full implementation (#803)
* Rename current ERC721 implementation to BaseERC721

* Implement ERC721 optional & approveAll functionality

* Support for new ERC721 interface

- Tests for new features are pending
- ERC721 is abstract, since it requires metadata implementation
- Move some methods into DeprecatedERC721 contract
- Reorganise base vs full implementation
- Pending tokenByIndex

* Add more tests for ERC721

* Implement suggestions by @dekz

* Update comments in ERC721 contracts

* Implement tokensByIndex extension

- Remove restrictions from mock mint and burn calls

* Add default implementation for metadata URI

This allows token implementation to be non-abstract

* Allow operators to call approve on a token

* Remove gas stipend restriction in call to 721 receiver

* Remove deprecated implementation

We only want to keep the interface, for interacting with already deployed contracts

* Add notice to isContract helper on constract constructors

* Change natspec delimiters for consistency

* Minor linting fixes

* Add constant modifier to ERC721_RECEIVED magic value

* Use 4-params safeTransferFrom for implementing the 3-params overload

* Minor text changes in natspec comments

* Use address(0) instead of 0 or 0x0

* Use if-statements instead of boolean one-liners for clarity

:-(

* Keep ownedTokensCount state var in sync in full ERC721 implementation

* Fix incorrect comparison when burning ERC721 tokens with metadata

* Use address(0) instead of 0 in one more place in ERC721

* Throw when querying balance for the zero address

Required by the spec

* Update links to approved version of EIP721

* Use explicit size for uint

* Remove unneeded internal function in ERC721

Also rename addToken and removeToken for added clarity

* Use underscore instead of 'do' prefix for internal methods in ERC721

* Fix failing test due to events reordering in ERC721 safe transfer

* Fix bug introduced in 74db03ba06

* Remove do prefix for internal setTokenUri method

* Allow transfers to self in ERC721
2018-03-23 15:11:59 -03:00
9f52e94339 Move ERC20 tests to ERC20 custom folder (#772) 2018-03-22 17:37:05 -03:00
c9936e231d Changed test assertion description for clarity (#831) 2018-03-22 16:36:28 -03:00
e299a7950e Change ECRecovery recover method's visibility to internal (#818)
* Change ECRecovery recover method's visibility to internal

* Adopt the test

* Remove unused imports
2018-03-21 21:38:31 -03:00
b33260ac44 Remove assert and send in favor of transfer for PullPayment.sol (#823)
* Removed assert from send() and changed to transfer()

* Slightly adapted docs
2018-03-21 18:30:58 -03:00
3fb8ecad76 Gender of signer is irrelevant and distracting (#822) 2018-03-19 11:50:07 -03:00
c3cbdb4599 Fix version error for truffle-flattener. (#794) 2018-03-16 13:16:41 -05:00
7586e383c2 Fixes typo in SafeMath subtraction docs (#806) 2018-03-12 12:27:17 -05:00
d1146e8c8b Add Whitelist contract (#746)
* Add Whitelist contract
2018-03-08 10:49:38 -08:00
8d4eee412d Bugfix/fix individuallycapped flaky test (#789)
* Fix InvididuallyCappedCrowdsale flaky test

* Fix IndividuallyCappedCrowdsale flaky test
2018-03-05 18:23:01 -08:00
903751ce0d Tiny indentation fix in MintedCrowdsale (#792)
Tiny indentation fix in MintedCrowdsale
2018-03-05 17:46:00 -08:00
9fd61177c3 Fixed typo in Crowdsale contract comment (#793) 2018-03-05 16:06:58 -03:00
3c48912730 Fix capped crowdsale flaky test (#773) 2018-03-02 15:20:00 -03:00
b3a8602928 Use constructor arguments (#731) 2018-02-26 18:24:19 -03:00
5ef8554727 Add Transfer event to Burnable Token. (#735)
Fixes #732
2018-02-20 15:44:50 -07:00
241 changed files with 11822 additions and 5922 deletions

12
.editorconfig Normal file
View 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

View File

@ -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",
}
}

View File

@ -12,7 +12,7 @@
Next, we need to know what your environment looks like.
- Which version of OpenZeppelin are you using?
- What network are you deploying to? testrpc? Ganache? Ropsten?
- What network are you deploying to? Ganache? Ropsten?
- How are you deploying your OpenZeppelin-backed contracts? truffle? Remix? Let us know!
## 📝 Details

View File

@ -11,7 +11,7 @@ Fixes #
<!-- 3. Before submitting, please review the following checklist: -->
- [ ] 📘 I've reviewed the [OpenZeppelin Contributor Guidelines](/docs/CONTRIBUTING.md)
- [ ] 📘 I've reviewed the [OpenZeppelin Contributor Guidelines](../blob/master/CONTRIBUTING.md)
- [ ] ✅ I've added tests where applicable to test my new functionality.
- [ ] 📖 I've made sure that my contracts are well-documented.
- [ ] 🎨 I've run the JS/Solidity linters and fixed any issues (`npm run lint:all:fix`).
- [ ] 🎨 I've run the JS/Solidity linters and fixed any issues (`npm run lint:all:fix`).

3
.gitignore vendored
View File

@ -34,3 +34,6 @@ build/
# lol macs
.DS_Store/
# truffle
.node-xmlhttprequest-*

View File

@ -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"
]
}

View File

@ -2,9 +2,14 @@
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"quotes": ["error", "double"],
"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"]

View File

@ -10,10 +10,12 @@ cache:
env:
-
- SOLIDITY_COVERAGE=true
- SOLC_NIGHTLY=true
matrix:
fast_finish: true
allow_failures:
- env: SOLIDITY_COVERAGE=true
- env: SOLC_NIGHTLY=true
before_script:
- truffle version
script:

73
CODE_OF_CONDUCT.md Normal file
View 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

View File

@ -5,29 +5,28 @@ We really appreciate and value contributions to OpenZeppelin. Please take 5' to
## Contribution guidelines
Smart contracts manage value and are highly vulnerable to errors and attacks. We have very strict guidelines, please make sure to review them: ["Contribution guidelines wiki entry"](https://github.com/OpenZeppelin/zeppelin-solidity/wiki/Contribution-guidelines).
Smart contracts manage value and are highly vulnerable to errors and attacks. We have very strict guidelines, please make sure to review them: ["Contribution guidelines wiki entry"](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/Contribution-guidelines).
## Creating Pull Requests (PRs)
As a contributor, you are expected to fork this repository, work on your own fork and then submit pull requests. The pull requests will be reviewed and eventually merged into the main repo. See ["Fork-a-Repo"](https://help.github.com/articles/fork-a-repo/) for how this works.
*IMPORTANT*
* Please use `rebase` instead of `merge` when updating your fork.
* Please see ["Git flow wiki entry"](https://github.com/OpenZeppelin/zeppelin-solidity/wiki/Git-flow) for understanding how to use branches in this repository.
* Please see ["Git flow wiki entry"](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/Git-flow) for understanding how to use branches in this repository.
## A typical workflow
1) Make sure your fork is up to date with the main repository:
```
cd zeppelin-solidity
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 `zeppelin-solidity` represents your fork's local copy.
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
@ -41,7 +40,7 @@ git commit "Fix some bug #123"
git push origin fix/some-bug-#123
```
4) Go to [github.com/OpenZeppelin/zeppelin-solidity](https://github.com/OpenZeppelin/zeppelin-solidity) in your web browser and issue a new pull request.
4) Go to [github.com/OpenZeppelin/openzeppelin-solidity](https://github.com/OpenZeppelin/zeppelin-solidity) in your web browser and issue a new pull request.
*IMPORTANT* Read the PR template very carefully and make sure to follow all the instructions. These instructions
refer to some very important conditions that your PR must meet in order to be accepted, such as making sure that all tests pass, JS linting tests pass, solidity linting tests pass, etc.
@ -52,8 +51,8 @@ refer to some very important conditions that your PR must meet in order to be ac
## All set!
If you have any questions feel free to post them to github.com/OpenZeppelin/zeppelin-solidity/issues.
If you have any questions feel free to post them to github.com/OpenZeppelin/openzeppelin-solidity/issues.
Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as ["Good first issue"](https://github.com/OpenZeppelin/zeppelin-solidity/labels/good%20first%20issue).
Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as ["Good first issue"](https://github.com/OpenZeppelin/openzeppelin-solidity/labels/good%20first%20issue).
Thanks for your time and code!

113
README.md
View File

@ -1,7 +1,7 @@
# Zeppelin Solidity
[![NPM Package](https://img.shields.io/npm/v/zeppelin-solidity.svg?style=flat-square)](https://www.npmjs.org/package/zeppelin-solidity)
[![Build Status](https://img.shields.io/travis/OpenZeppelin/zeppelin-solidity.svg?branch=master&style=flat-square)](https://travis-ci.org/OpenZeppelin/zeppelin-solidity)
[![Coverage Status](https://img.shields.io/coveralls/github/OpenZeppelin/zeppelin-solidity/master.svg?style=flat-square)](https://coveralls.io/github/OpenZeppelin/zeppelin-solidity?branch=master)
# OpenZeppelin Solidity
[![NPM Package](https://img.shields.io/npm/v/openzeppelin-solidity.svg?style=flat-square)](https://www.npmjs.org/package/openzeppelin-solidity)
[![Build Status](https://img.shields.io/travis/OpenZeppelin/openzeppelin-solidity.svg?branch=master&style=flat-square)](https://travis-ci.org/OpenZeppelin/openzeppelin-solidity)
[![Coverage Status](https://img.shields.io/coveralls/github/OpenZeppelin/openzeppelin-solidity/master.svg?style=flat-square)](https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master)
OpenZeppelin is a library for writing secure [Smart Contracts](https://en.wikipedia.org/wiki/Smart_contract) on Ethereum.
@ -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,28 +25,91 @@ 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 zeppelin-solidity
npm install -E openzeppelin-solidity
```
**Note that OpenZeppelin does not currently follow semantic versioning.** You may encounter breaking changes upon a minor version bump. We recommend pinning the version of OpenZeppelin you use, as done by the `-E` (`--save-exact`) option.
After that, you'll get all the library's contracts in the `node_modules/zeppelin-solidity/contracts` folder. You can use the contracts in the library like so:
After that, you'll get all the library's contracts in the `node_modules/openzeppelin-solidity/contracts` folder. You can use the contracts in the library like so:
```js
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
```solidity
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';
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 crowdsales 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 contracts 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 contracts 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 Mochas JavaScript testing framework and Chais assertion library. To learn more about how to tests are structured, please reference OpenZeppelins 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 frameworks 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 applications attack surface is.
Youll 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 OpenZeppelins 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
@ -56,27 +123,9 @@ Building a distributed application, protocol or organization with OpenZeppelin?
Interested in contributing to OpenZeppelin?
- Framework proposal and roadmap: https://medium.com/zeppelin-blog/zeppelin-framework-proposal-and-development-roadmap-fdfa9a3a32ab#.iain47pak
- Issue tracker: https://github.com/OpenZeppelin/zeppelin-solidity/issues
- Contribution guidelines: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/CONTRIBUTING.md
- Wiki: https://github.com/OpenZeppelin/zeppelin-solidity/wiki
## Collaborating organizations and audits by OpenZeppelin
- [Golem](https://golem.network/)
- [Mediachain](http://www.mediachain.io/)
- [Truffle](http://truffleframework.com/)
- [Firstblood](https://firstblood.io/)
- [Rootstock](https://www.rsk.co/)
- [Consensys](https://consensys.net/)
- [DigixGlobal](https://www.dgx.io/)
- [Coinfund](https://coinfund.io/)
- [DemocracyEarth](https://democracy.earth/)
- [Signatura](https://signatura.co/)
- [Ether.camp](http://www.ether.camp/)
- [Aragon](https://aragon.one/)
- [Wings](https://wings.ai/)
among others...
- Issue tracker: https://github.com/OpenZeppelin/openzeppelin-solidity/issues
- Contribution guidelines: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md
- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki
## License
Code released under the [MIT License](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/LICENSE).
Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE).

2
contracts/.npmignore Normal file
View File

@ -0,0 +1,2 @@
mocks
examples

View File

@ -0,0 +1,29 @@
pragma solidity ^0.4.24;
/**
* Utility library of inline functions on addresses
*/
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
* @return whether the target address is a contract
*/
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.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(_addr) }
return size > 0;
}
}

View 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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./payment/PullPayment.sol";
@ -30,20 +30,20 @@ contract Bounty is PullPayment, Destructible {
function createTarget() public returns(Target) {
Target target = Target(deployContract());
researchers[target] = msg.sender;
TargetCreated(target);
emit TargetCreated(target);
return target;
}
/**
* @dev Sends the contract funds to the researcher that proved the contract is broken.
* @param target contract
* @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 != 0);
function claim(Target _target) public {
address researcher = researchers[_target];
require(researcher != address(0));
// Check Target contract invariants
require(!target.checkInvariant());
asyncSend(researcher, this.balance);
require(!_target.checkInvariant());
asyncTransfer(researcher, address(this).balance);
claimed = true;
}

View File

@ -1,74 +0,0 @@
pragma solidity ^0.4.18;
/**
* @title DayLimit
* @dev Base contract that enables methods to be protected by placing a linear limit (specifiable)
* on a particular resource per calendar day. Is multiowned to allow the limit to be altered.
*/
contract DayLimit {
uint256 public dailyLimit;
uint256 public spentToday;
uint256 public lastDay;
/**
* @dev Constructor that sets the passed value as a dailyLimit.
* @param _limit uint256 to represent the daily limit.
*/
function DayLimit(uint256 _limit) public {
dailyLimit = _limit;
lastDay = today();
}
/**
* @dev sets the daily limit. Does not alter the amount already spent today.
* @param _newLimit uint256 to represent the new limit.
*/
function _setDailyLimit(uint256 _newLimit) internal {
dailyLimit = _newLimit;
}
/**
* @dev Resets the amount already spent today.
*/
function _resetSpentToday() internal {
spentToday = 0;
}
/**
* @dev Checks to see if there is enough resource to spend today. If true, the resource may be expended.
* @param _value uint256 representing the amount of resource to spend.
* @return A boolean that is True if the resource was spent and false otherwise.
*/
function underLimit(uint256 _value) internal returns (bool) {
// reset the spend limit if we're on a different day to last time.
if (today() > lastDay) {
spentToday = 0;
lastDay = today();
}
// check to see if there's enough left - if so, subtract and return true.
// overflow protection // dailyLimit check
if (spentToday + _value >= spentToday && spentToday + _value <= dailyLimit) {
spentToday += _value;
return true;
}
return false;
}
/**
* @dev Private function to determine today's index
* @return uint256 of today's index.
*/
function today() private view returns (uint256) {
return now / 1 days;
}
/**
* @dev Simple modifier for daily limit.
*/
modifier limitedDaily(uint256 _value) {
require(underLimit(_value));
_;
}
}

View File

@ -1,34 +1,42 @@
pragma solidity ^0.4.18;
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 his 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()
* @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()
*/
function recover(bytes32 hash, bytes sig) public pure returns (address) {
function recover(bytes32 _hash, bytes _sig)
internal
pure
returns (address)
{
bytes32 r;
bytes32 s;
uint8 v;
//Check the signature length
if (sig.length != 65) {
// Check the signature length
if (_sig.length != 65) {
return (address(0));
}
// Divide the signature in r, s and v variables
// ecrecover takes the signature parameters, and the only way to get them
// 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
@ -40,8 +48,25 @@ library ECRecovery {
if (v != 27 && v != 28) {
return (address(0));
} else {
return ecrecover(hash, v, r, s);
// solium-disable-next-line arg-overflow
return ecrecover(_hash, v, r, s);
}
}
/**
* toEthSignedMessageHash
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
* and hash the result
*/
function toEthSignedMessageHash(bytes32 _hash)
internal
pure
returns (bytes32)
{
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)
);
}
}

View File

@ -1,11 +1,11 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
/**
* @title LimitBalance
* @dev Simple contract to limit the balance of child contract.
* @dev Note this doesn't prevent other contracts to send funds by using selfdestruct(address);
* @dev See: https://github.com/ConsenSys/smart-contract-best-practices#remember-that-ether-can-be-forcibly-sent-to-an-account
* 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 {
@ -15,7 +15,7 @@ contract LimitBalance {
* @dev Constructor that sets the passed value as a limit.
* @param _limit uint256 to represent the limit.
*/
function LimitBalance(uint256 _limit) public {
constructor(uint256 _limit) public {
limit = _limit;
}
@ -23,7 +23,7 @@ contract LimitBalance {
* @dev Checks if limit was reached. Case true, it throws.
*/
modifier limitedPayable() {
require(this.balance <= limit);
require(address(this).balance <= limit);
_;
}

View File

@ -1,40 +1,39 @@
pragma solidity ^0.4.18;
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(bytes _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
// Check if proof length is a multiple of 32
if (_proof.length % 32 != 0) {
return false;
}
bytes32 proofElement;
function verifyProof(
bytes32[] _proof,
bytes32 _root,
bytes32 _leaf
)
internal
pure
returns (bool)
{
bytes32 computedHash = _leaf;
for (uint256 i = 32; i <= _proof.length; i += 32) {
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
}
for (uint256 i = 0; i < _proof.length; i++) {
bytes32 proofElement = _proof[i];
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));
}
}

View File

@ -1,32 +1,39 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
/**
* @title Helps contracts guard agains reentrancy attacks.
* @author Remco Bloemen <remco@2π.com>
* @notice If you mark a function `nonReentrant`, you should also
* @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.
*/
bool private reentrancy_lock = false;
uint private reentrancyLock = REENTRANCY_GUARD_FREE;
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* @notice If you mark a function `nonReentrant`, you should also
* mark it `external`. Calling one nonReentrant function from
* 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 a `external`
* `private` function doing the actual work, and an `external`
* wrapper marked as `nonReentrant`.
*/
modifier nonReentrant() {
require(!reentrancy_lock);
reentrancy_lock = true;
require(reentrancyLock == REENTRANCY_GUARD_FREE);
reentrancyLock = REENTRANCY_GUARD_LOCKED;
_;
reentrancy_lock = false;
reentrancyLock = REENTRANCY_GUARD_FREE;
}
}

View File

@ -0,0 +1,159 @@
pragma solidity ^0.4.24;
import "../ownership/Ownable.sol";
import "../access/rbac/RBAC.sol";
import "../ECRecovery.sol";
/**
* @title SignatureBouncer
* @author PhABC, Shrugs and aflesher
* @dev Bouncer allows users to submit a signature as a permission to do an action.
* 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 Ownable, RBAC {
using ECRecovery for bytes32;
string public constant ROLE_BOUNCER = "bouncer";
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
*/
modifier onlyValidSignature(bytes _sig)
{
require(isValidSignature(msg.sender, _sig));
_;
}
/**
* @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)
public
onlyOwner
{
require(_bouncer != address(0));
addRole(_bouncer, ROLE_BOUNCER);
}
/**
* @dev allows the owner to remove bouncer addresses
*/
function removeBouncer(address _bouncer)
public
onlyOwner
{
require(_bouncer != address(0));
removeRole(_bouncer, ROLE_BOUNCER);
}
/**
* @dev is the signature of `this + sender` from a bouncer?
* @return bool
*/
function isValidSignature(address _address, bytes _sig)
internal
view
returns (bool)
{
return isValidDataHash(
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
* and then recover the signature and check it against the bouncer role
* @return bool
*/
function isValidDataHash(bytes32 _hash, bytes _sig)
internal
view
returns (bool)
{
address signer = _hash
.toEthSignedMessageHash()
.recover(_sig);
return hasRole(signer, ROLE_BOUNCER);
}
}

View 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]);
}
}
}

View 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);
// _;
// }
}

View File

@ -1,11 +1,11 @@
pragma solidity ^0.4.18;
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];
}
}

View File

@ -1,7 +1,9 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../math/SafeMath.sol";
import "../token/ERC20/SafeERC20.sol";
/**
* @title Crowdsale
@ -10,14 +12,14 @@ import "../math/SafeMath.sol";
* 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 / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* 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;
@ -25,7 +27,10 @@ contract Crowdsale {
// Address where funds are collected
address public wallet;
// How many token units a buyer gets per wei
// How many token units a buyer gets per wei.
// The rate is the conversion between wei and the smallest and indivisible token unit.
// 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
@ -38,14 +43,19 @@ contract Crowdsale {
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
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
*/
function Crowdsale(uint256 _rate, address _wallet, ERC20 _token) public {
constructor(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
@ -82,7 +92,12 @@ contract Crowdsale {
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount);
@ -95,11 +110,19 @@ contract Crowdsale {
// -----------------------------------------
/**
* @dev Validation of an incoming purchase. Use require statemens to revert state when conditions are not met. Use super to concatenate validations.
* @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 {
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
@ -109,7 +132,12 @@ contract Crowdsale {
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
function _postValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
// optional override
}
@ -118,8 +146,13 @@ contract Crowdsale {
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transfer(_beneficiary, _tokenAmount);
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
token.safeTransfer(_beneficiary, _tokenAmount);
}
/**
@ -127,7 +160,12 @@ contract Crowdsale {
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
function _processPurchase(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
_deliverTokens(_beneficiary, _tokenAmount);
}
@ -136,7 +174,12 @@ contract Crowdsale {
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
function _updatePurchasingState(
address _beneficiary,
uint256 _weiAmount
)
internal
{
// optional override
}
@ -145,7 +188,9 @@ contract Crowdsale {
* @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) {
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate);
}

View File

@ -1,15 +1,16 @@
pragma solidity ^0.4.18;
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 {
contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
using SafeMath for uint256;
bool public isFinalized = false;
@ -20,12 +21,12 @@ contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() onlyOwner public {
function finalize() public onlyOwner {
require(!isFinalized);
require(hasClosed());
finalization();
Finalized();
emit Finalized();
isFinalized = true;
}
@ -37,4 +38,5 @@ contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
*/
function finalization() internal {
}
}

View File

@ -1,9 +1,10 @@
pragma solidity ^0.4.18;
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.
@ -13,15 +14,6 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
mapping(address => uint256) public balances;
/**
* @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);
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
@ -32,4 +24,19 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
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);
}
}

View File

@ -1,16 +1,15 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../../math/SafeMath.sol";
import "./FinalizableCrowdsale.sol";
import "./utils/RefundVault.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.
* Uses a RefundVault as the crowdsale's vault.
*/
contract RefundableCrowdsale is FinalizableCrowdsale {
using SafeMath for uint256;
@ -18,16 +17,16 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
// minimum amount of funds to be raised in weis
uint256 public goal;
// refund vault used to hold funds while crowdsale is running
RefundVault public vault;
// refund escrow used to hold funds while crowdsale is running
RefundEscrow private escrow;
/**
* @dev Constructor, creates RefundVault.
* @dev Constructor, creates RefundEscrow.
* @param _goal Funding goal
*/
function RefundableCrowdsale(uint256 _goal) public {
constructor(uint256 _goal) public {
require(_goal > 0);
vault = new RefundVault(wallet);
escrow = new RefundEscrow(wallet);
goal = _goal;
}
@ -38,11 +37,11 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
require(isFinalized);
require(!goalReached());
vault.refund(msg.sender);
escrow.withdraw(msg.sender);
}
/**
* @dev Checks whether funding goal was reached.
* @dev Checks whether funding goal was reached.
* @return Whether funding goal was reached
*/
function goalReached() public view returns (bool) {
@ -50,23 +49,24 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
}
/**
* @dev vault finalization task, called when owner calls finalize()
* @dev escrow finalization task, called when owner calls finalize()
*/
function finalization() internal {
if (goalReached()) {
vault.close();
escrow.close();
escrow.beneficiaryWithdraw();
} else {
vault.enableRefunds();
escrow.enableRefunds();
}
super.finalization();
}
/**
* @dev Overrides Crowdsale fund forwarding, sending funds to vault.
* @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
*/
function _forwardFunds() internal {
vault.deposit.value(msg.value)(msg.sender);
escrow.deposit.value(msg.value)(msg.sender);
}
}

View File

@ -1,66 +0,0 @@
pragma solidity ^0.4.18;
import "../../../math/SafeMath.sol";
import "../../../ownership/Ownable.sol";
/**
* @title RefundVault
* @dev This contract is used for storing funds while a crowdsale
* is in progress. Supports refunding the money if crowdsale fails,
* and forwarding it if crowdsale is successful.
*/
contract RefundVault is Ownable {
using SafeMath for uint256;
enum State { Active, Refunding, Closed }
mapping (address => uint256) public deposited;
address public wallet;
State public state;
event Closed();
event RefundsEnabled();
event Refunded(address indexed beneficiary, uint256 weiAmount);
/**
* @param _wallet Vault address
*/
function RefundVault(address _wallet) public {
require(_wallet != address(0));
wallet = _wallet;
state = State.Active;
}
/**
* @param investor Investor address
*/
function deposit(address investor) onlyOwner public payable {
require(state == State.Active);
deposited[investor] = deposited[investor].add(msg.value);
}
function close() onlyOwner public {
require(state == State.Active);
state = State.Closed;
Closed();
wallet.transfer(this.balance);
}
function enableRefunds() onlyOwner public {
require(state == State.Active);
state = State.Refunding;
RefundsEnabled();
}
/**
* @param investor Investor address
*/
function refund(address investor) public {
require(state == State.Refunding);
uint256 depositedValue = deposited[investor];
deposited[investor] = 0;
investor.transfer(depositedValue);
Refunded(investor, depositedValue);
}
}

View File

@ -1,7 +1,9 @@
pragma solidity ^0.4.18;
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";
@ -11,14 +13,15 @@ import "../../math/SafeMath.sol";
*/
contract AllowanceCrowdsale is Crowdsale {
using SafeMath for uint256;
using SafeERC20 for ERC20;
address public tokenWallet;
/**
* @dev Constructor, takes token wallet address.
* @dev Constructor, takes token wallet address.
* @param _tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
*/
function AllowanceCrowdsale(address _tokenWallet) public {
constructor(address _tokenWallet) public {
require(_tokenWallet != address(0));
tokenWallet = _tokenWallet;
}
@ -36,7 +39,12 @@ contract AllowanceCrowdsale is Crowdsale {
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
token.transferFrom(tokenWallet, _beneficiary, _tokenAmount);
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
token.safeTransferFrom(tokenWallet, _beneficiary, _tokenAmount);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../Crowdsale.sol";
import "../../token/ERC20/MintableToken.sol";
@ -7,16 +7,22 @@ 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.
* 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 {
require(MintableToken(token).mint(_beneficiary, _tokenAmount));
* @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));
}
}

View File

@ -1,11 +1,12 @@
pragma solidity ^0.4.18;
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.
* @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.
*/
@ -16,11 +17,11 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
uint256 public finalRate;
/**
* @dev Constructor, takes intial and final rates of tokens received per wei contributed.
* @dev Constructor, takes initial and final rates of tokens received per wei contributed.
* @param _initialRate Number of tokens a buyer gets per wei at the start of the crowdsale
* @param _finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
*/
function IncreasingPriceCrowdsale(uint256 _initialRate, uint256 _finalRate) public {
constructor(uint256 _initialRate, uint256 _finalRate) public {
require(_initialRate >= _finalRate);
require(_finalRate > 0);
initialRate = _initialRate;
@ -28,12 +29,13 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
}
/**
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @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) {
uint256 elapsedTime = now.sub(openingTime);
// 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));
@ -44,7 +46,9 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
* @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) {
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
uint256 currentRate = getCurrentRate();
return currentRate.mul(_weiAmount);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../../math/SafeMath.sol";
import "../Crowdsale.sol";
@ -17,13 +17,13 @@ contract CappedCrowdsale is Crowdsale {
* @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
* @param _cap Max amount of wei to be contributed
*/
function CappedCrowdsale(uint256 _cap) public {
constructor(uint256 _cap) public {
require(_cap > 0);
cap = _cap;
}
/**
* @dev Checks whether the cap has been reached.
* @dev Checks whether the cap has been reached.
* @return Whether the cap was reached
*/
function capReached() public view returns (bool) {
@ -35,7 +35,12 @@ contract CappedCrowdsale is Crowdsale {
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
super._preValidatePurchase(_beneficiary, _weiAmount);
require(weiRaised.add(_weiAmount) <= cap);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^ 0.4.18;
pragma solidity ^0.4.24;
import "../../math/SafeMath.sol";
import "../Crowdsale.sol";
@ -9,7 +9,7 @@ import "../../ownership/Ownable.sol";
* @title IndividuallyCappedCrowdsale
* @dev Crowdsale with per-user caps.
*/
contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
using SafeMath for uint256;
mapping(address => uint256) public contributions;
@ -29,14 +29,20 @@ contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
* @param _beneficiaries List of addresses to be capped
* @param _cap Wei limit for individual contribution
*/
function setGroupCap(address[] _beneficiaries, uint256 _cap) external onlyOwner {
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.
* @dev Returns the cap of a specific user.
* @param _beneficiary Address whose cap is to be checked
* @return Current cap for individual user
*/
@ -49,7 +55,9 @@ contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
* @param _beneficiary Address of contributor
* @return User contribution so far
*/
function getUserContribution(address _beneficiary) public view returns (uint256) {
function getUserContribution(address _beneficiary)
public view returns (uint256)
{
return contributions[_beneficiary];
}
@ -58,7 +66,12 @@ contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
super._preValidatePurchase(_beneficiary, _weiAmount);
require(contributions[_beneficiary].add(_weiAmount) <= caps[_beneficiary]);
}
@ -68,7 +81,12 @@ contract IndividuallyCappedCrowdsale is Crowdsale, Ownable {
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
function _updatePurchasingState(
address _beneficiary,
uint256 _weiAmount
)
internal
{
super._updatePurchasingState(_beneficiary, _weiAmount);
contributions[_beneficiary] = contributions[_beneficiary].add(_weiAmount);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../../math/SafeMath.sol";
import "../Crowdsale.sol";
@ -15,10 +15,11 @@ contract TimedCrowdsale is Crowdsale {
uint256 public closingTime;
/**
* @dev Reverts if not in crowdsale time range.
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(now >= openingTime && now <= closingTime);
// solium-disable-next-line security/no-block-members
require(block.timestamp >= openingTime && block.timestamp <= closingTime);
_;
}
@ -27,8 +28,9 @@ contract TimedCrowdsale is Crowdsale {
* @param _openingTime Crowdsale opening time
* @param _closingTime Crowdsale closing time
*/
function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public {
require(_openingTime >= now);
constructor(uint256 _openingTime, uint256 _closingTime) public {
// solium-disable-next-line security/no-block-members
require(_openingTime >= block.timestamp);
require(_closingTime >= _openingTime);
openingTime = _openingTime;
@ -40,15 +42,22 @@ contract TimedCrowdsale is Crowdsale {
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return now > closingTime;
// 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 {
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
onlyWhileOpen
{
super._preValidatePurchase(_beneficiary, _weiAmount);
}

View File

@ -1,57 +1,26 @@
pragma solidity ^ 0.4.18;
pragma solidity ^0.4.24;
import "../Crowdsale.sol";
import "../../ownership/Ownable.sol";
import "../../access/Whitelist.sol";
/**
* @title WhitelistedCrowdsale
* @dev Crowdsale in which only whitelisted users can contribute.
*/
contract WhitelistedCrowdsale is Crowdsale, Ownable {
mapping(address => bool) public whitelist;
/**
* @dev Reverts if beneficiary is not whitelisted. Can be used when extending this contract.
*/
modifier isWhitelisted(address _beneficiary) {
require(whitelist[_beneficiary]);
_;
}
/**
* @dev Adds single address to whitelist.
* @param _beneficiary Address to be added to the whitelist
*/
function addToWhitelist(address _beneficiary) external onlyOwner {
whitelist[_beneficiary] = true;
}
/**
* @dev Adds list of addresses to whitelist. Not overloaded due to limitations with truffle testing.
* @param _beneficiaries Addresses to be added to the whitelist
*/
function addManyToWhitelist(address[] _beneficiaries) external onlyOwner {
for (uint256 i = 0; i < _beneficiaries.length; i++) {
whitelist[_beneficiaries[i]] = true;
}
}
/**
* @dev Removes single address from whitelist.
* @param _beneficiary Address to be removed to the whitelist
*/
function removeFromWhitelist(address _beneficiary) external onlyOwner {
whitelist[_beneficiary] = false;
}
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 isWhitelisted(_beneficiary) {
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
onlyIfWhitelisted(_beneficiary)
{
super._preValidatePurchase(_beneficiary, _weiAmount);
}

View 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);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../crowdsale/validation/CappedCrowdsale.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol";
@ -13,9 +13,9 @@ import "../token/ERC20/MintableToken.sol";
*/
contract SampleCrowdsaleToken is MintableToken {
string public constant name = "Sample Crowdsale Token"; // solium-disable-line uppercase
string public constant symbol = "SCT"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
string public constant name = "Sample Crowdsale Token";
string public constant symbol = "SCT";
uint8 public constant decimals = 18;
}
@ -31,9 +31,23 @@ contract SampleCrowdsaleToken is MintableToken {
* 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 {
function SampleCrowdsale(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _goal) public
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)

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.11;
pragma solidity ^0.4.24;
import "../ownership/Heritable.sol";
@ -19,22 +19,22 @@ contract SimpleSavingsWallet is Heritable {
event Received(address indexed payer, uint256 amount, uint256 balance);
function SimpleSavingsWallet(uint256 _heartbeatTimeout) Heritable(_heartbeatTimeout) public {}
constructor(uint256 _heartbeatTimeout) Heritable(_heartbeatTimeout) public {}
/**
* @dev wallet can receive funds.
*/
function () public payable {
Received(msg.sender, msg.value, this.balance);
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 != 0 && payee != address(this));
require(amount > 0);
payee.transfer(amount);
Sent(payee, amount, this.balance);
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);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/StandardToken.sol";
@ -12,19 +12,19 @@ import "../token/ERC20/StandardToken.sol";
*/
contract SimpleToken is StandardToken {
string public constant name = "SimpleToken"; // solium-disable-line uppercase
string public constant symbol = "SIM"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
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.
*/
function SimpleToken() public {
constructor() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
emit Transfer(address(0), msg.sender, INITIAL_SUPPLY);
}
}

View 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);
}

View 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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../ownership/Ownable.sol";
@ -9,17 +9,14 @@ import "../ownership/Ownable.sol";
* @dev Base contract that can be destroyed by owner. All funds in contract will be sent to the owner.
*/
contract Destructible is Ownable {
function Destructible() public payable { }
/**
* @dev Transfers the current balance to the owner and terminates the contract.
*/
function destroy() onlyOwner public {
function destroy() public onlyOwner {
selfdestruct(owner);
}
function destroyAndSend(address _recipient) onlyOwner public {
function destroyAndSend(address _recipient) public onlyOwner {
selfdestruct(_recipient);
}
}

View File

@ -1,21 +0,0 @@
pragma solidity ^0.4.18;
import "../ownership/Ownable.sol";
/**
* @title Migrations
* @dev This is a truffle contract, needed for truffle integration, not meant for use by Zeppelin users.
*/
contract Migrations is Ownable {
uint256 public lastCompletedMigration;
function setCompleted(uint256 completed) onlyOwner public {
lastCompletedMigration = completed;
}
function upgrade(address newAddress) onlyOwner public {
Migrations upgraded = Migrations(newAddress);
upgraded.setCompleted(lastCompletedMigration);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../ownership/Ownable.sol";
@ -34,16 +34,16 @@ contract Pausable is Ownable {
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
function pause() public onlyOwner whenNotPaused {
paused = true;
Pause();
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
function unpause() public onlyOwner whenPaused {
paused = false;
Unpause();
emit Unpause();
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../ownership/Ownable.sol";
import "../token/ERC20/ERC20Basic.sol";
@ -12,20 +12,20 @@ import "../token/ERC20/ERC20Basic.sol";
*/
contract TokenDestructible is Ownable {
function TokenDestructible() public payable { }
constructor() public payable { }
/**
* @notice Terminate contract and refund to owner
* @param tokens List of addresses of ERC20 or ERC20Basic token contracts to
* @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) onlyOwner public {
function destroy(address[] _tokens) public onlyOwner {
// Transfer tokens to owner
for (uint256 i = 0; i < tokens.length; i++) {
ERC20Basic token = ERC20Basic(tokens[i]);
for (uint256 i = 0; i < _tokens.length; i++) {
ERC20Basic token = ERC20Basic(_tokens[i]);
uint256 balance = token.balanceOf(this);
token.transfer(owner, balance);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
/**
@ -6,19 +6,19 @@ pragma solidity ^0.4.18;
* @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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
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) {
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;
}
uint256 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 c;
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 Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
* @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) {
uint256 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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/emission/AllowanceCrowdsale.sol";
@ -6,12 +6,12 @@ import "../crowdsale/emission/AllowanceCrowdsale.sol";
contract AllowanceCrowdsaleImpl is AllowanceCrowdsale {
function AllowanceCrowdsaleImpl (
constructor (
uint256 _rate,
address _wallet,
ERC20 _token,
address _tokenWallet
)
)
public
Crowdsale(_rate, _wallet, _token)
AllowanceCrowdsale(_tokenWallet)

View 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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
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;
}
}

View File

@ -0,0 +1,66 @@
pragma solidity ^0.4.24;
import "../access/SignatureBouncer.sol";
contract SignatureBouncerMock is SignatureBouncer {
function checkValidSignature(address _address, bytes _sig)
public
view
returns (bool)
{
return isValidSignature(_address, _sig);
}
function onlyWithValidSignature(bytes _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
{
}
}

View File

@ -1,13 +1,13 @@
pragma solidity ^0.4.18;
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;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/CappedCrowdsale.sol";
@ -6,12 +6,12 @@ import "../crowdsale/validation/CappedCrowdsale.sol";
contract CappedCrowdsaleImpl is CappedCrowdsale {
function CappedCrowdsaleImpl (
constructor (
uint256 _rate,
address _wallet,
ERC20 _token,
uint256 _cap
)
)
public
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)

View 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];
}
}

View File

@ -1,25 +0,0 @@
pragma solidity ^0.4.18;
import "../../contracts/DayLimit.sol";
contract DayLimitMock is DayLimit {
uint256 public totalSpending;
function DayLimitMock(uint256 _value) public DayLimit(_value) {
totalSpending = 0;
}
function attemptSpend(uint256 _value) external limitedDaily(_value) {
totalSpending += _value;
}
function setDailyLimit(uint256 _newLimit) external {
_setDailyLimit(_newLimit);
}
function resetSpentToday() external {
_resetSpentToday();
}
}

View File

@ -0,0 +1,8 @@
pragma solidity ^0.4.24;
import "../lifecycle/Destructible.sol";
contract DestructibleMock is Destructible {
function() public payable {}
}

View File

@ -1,9 +1,16 @@
pragma solidity ^0.4.18;
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) DetailedERC20(_name, _symbol, _decimals) public {}
constructor(
string _name,
string _symbol,
uint8 _decimals
)
DetailedERC20(_name, _symbol, _decimals)
public
{}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../ECRecovery.sol";
@ -7,10 +7,19 @@ import "../ECRecovery.sol";
contract ECRecoveryMock {
using ECRecovery for bytes32;
address public addrRecovered;
function recover(bytes32 hash, bytes sig) public returns (address) {
addrRecovered = hash.recover(sig);
function recover(bytes32 _hash, bytes _sig)
public
pure
returns (address)
{
return _hash.recover(_sig);
}
function toEthSignedMessageHash(bytes32 _hash)
public
pure
returns (bytes32)
{
return _hash.toEthSignedMessageHash();
}
}

View 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)
{
}
}

View File

@ -1,16 +1,18 @@
pragma solidity ^0.4.18;
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 {
function ERC223TokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply_ = initialBalance;
constructor(address _initialAccount, uint256 _initialBalance) public {
balances[_initialAccount] = _initialBalance;
totalSupply_ = _initialBalance;
}
// ERC223 compatible transfer function (except the name)
@ -18,11 +20,12 @@ contract ERC223TokenMock is BasicToken {
returns (bool success)
{
transfer(_to, _value);
bool is_contract = false;
bool isContract = false;
// solium-disable-next-line security/no-inline-assembly
assembly {
is_contract := not(iszero(extcodesize(_to)))
isContract := not(iszero(extcodesize(_to)))
}
if (is_contract) {
if (isContract) {
ERC223ContractInterface receiver = ERC223ContractInterface(_to);
receiver.tokenFallback(msg.sender, _value, _data);
}

View File

@ -0,0 +1,18 @@
pragma solidity ^0.4.24;
import "../token/ERC721/ERC721BasicToken.sol";
/**
* @title ERC721BasicTokenMock
* This mock just provides a public mint and burn functions for testing purposes
*/
contract ERC721BasicTokenMock is ERC721BasicToken {
function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId);
}
function burn(uint256 _tokenId) public {
super._burn(ownerOf(_tokenId), _tokenId);
}
}

View File

@ -0,0 +1,42 @@
pragma solidity ^0.4.24;
import "../token/ERC721/ERC721Receiver.sol";
contract ERC721ReceiverMock is ERC721Receiver {
bytes4 retval;
bool reverts;
event Received(
address _operator,
address _from,
uint256 _tokenId,
bytes _data,
uint256 _gas
);
constructor(bytes4 _retval, bool _reverts) public {
retval = _retval;
reverts = _reverts;
}
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes _data
)
public
returns(bytes4)
{
require(!reverts);
emit Received(
_operator,
_from,
_tokenId,
_data,
gasleft() // msg.gas was deprecated in solidityv0.4.21
);
return retval;
}
}

View File

@ -1,19 +1,31 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC721/ERC721Token.sol";
/**
* @title ERC721TokenMock
* This mock just provides a public mint and burn functions for testing purposes.
* This mock just provides a public mint and burn functions for testing purposes,
* and a public setter for metadata URI
*/
contract ERC721TokenMock is ERC721Token {
function ERC721TokenMock() ERC721Token() public { }
constructor(string name, string symbol) public
ERC721Token(name, symbol)
{ }
function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId);
}
function burn(uint256 _tokenId) public {
super._burn(_tokenId);
super._burn(ownerOf(_tokenId), _tokenId);
}
function setTokenURI(uint256 _tokenId, string _uri) public {
super._setTokenURI(_tokenId, _uri);
}
function _removeTokenFrom(address _from, uint256 _tokenId) public {
super.removeTokenFrom(_from, _tokenId);
}
}

View File

@ -1,15 +0,0 @@
pragma solidity ^0.4.13;
import "../token/ERC827/ERC827Token.sol";
// mock class using ERC827 Token
contract ERC827TokenMock is ERC827Token {
function ERC827TokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply_ = initialBalance;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/MintableToken.sol";
import "../crowdsale/distribution/FinalizableCrowdsale.sol";
@ -6,13 +6,13 @@ import "../crowdsale/distribution/FinalizableCrowdsale.sol";
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
function FinalizableCrowdsaleImpl (
constructor (
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
MintableToken _token
)
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
// @title Force Ether into a contract.
@ -8,7 +8,7 @@ pragma solidity ^0.4.18;
// @author Remco Bloemen <remco@neufund.org>
contract ForceEther {
function ForceEther() public payable { }
constructor() public payable { }
function destroyAndSend(address _recipient) public {
selfdestruct(_recipient);

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../../contracts/ownership/HasNoEther.sol";
@ -6,7 +6,7 @@ import "../../contracts/ownership/HasNoEther.sol";
contract HasNoEtherTest is HasNoEther {
// Constructor with explicit payable — should still fail
function HasNoEtherTest() public payable {
constructor() public payable {
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../crowdsale/price/IncreasingPriceCrowdsale.sol";
import "../math/SafeMath.sol";
@ -6,14 +6,14 @@ import "../math/SafeMath.sol";
contract IncreasingPriceCrowdsaleImpl is IncreasingPriceCrowdsale {
function IncreasingPriceCrowdsaleImpl (
constructor (
uint256 _openingTime,
uint256 _closingTime,
address _wallet,
ERC20 _token,
uint256 _initialRate,
uint256 _finalRate
)
)
public
Crowdsale(_initialRate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)

View File

@ -1,16 +1,16 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
contract IndividuallyCappedCrowdsaleImpl is IndividuallyCappedCrowdsale {
function IndividuallyCappedCrowdsaleImpl (
constructor (
uint256 _rate,
address _wallet,
ERC20 _token
)
)
public
Crowdsale(_rate, _wallet, _token)
{

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol";

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../LimitBalance.sol";

View File

@ -0,0 +1,26 @@
pragma solidity ^0.4.24;
import "../../contracts/math/Math.sol";
contract MathMock {
uint64 public result64;
uint256 public result256;
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 max256(uint256 _a, uint256 _b) public {
result256 = Math.max256(_a, _b);
}
function min256(uint256 _a, uint256 _b) public {
result256 = Math.min256(_a, _b);
}
}

View File

@ -0,0 +1,19 @@
pragma solidity ^0.4.24;
import { MerkleProof } from "../MerkleProof.sol";
contract MerkleProofWrapper {
function verifyProof(
bytes32[] _proof,
bytes32 _root,
bytes32 _leaf
)
public
pure
returns (bool)
{
return MerkleProof.verifyProof(_proof, _root, _leaf);
}
}

View File

@ -1,11 +1,37 @@
pragma solidity ^0.4.11;
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) {
Show(message, number, text);
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;
}
@ -13,8 +39,9 @@ contract MessageHelper {
require(false);
}
function call(address to, bytes data) public returns (bool) {
if (to.call(data))
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;

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/MintableToken.sol";
import "../crowdsale/emission/MintedCrowdsale.sol";
@ -6,11 +6,11 @@ import "../crowdsale/emission/MintedCrowdsale.sol";
contract MintedCrowdsaleImpl is MintedCrowdsale {
function MintedCrowdsaleImpl (
constructor (
uint256 _rate,
address _wallet,
MintableToken _token
)
)
public
Crowdsale(_rate, _wallet, _token)
{

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../lifecycle/Pausable.sol";
@ -9,7 +9,7 @@ contract PausableMock is Pausable {
bool public drasticMeasureTaken;
uint256 public count;
function PausableMock() public {
constructor() public {
drasticMeasureTaken = false;
count = 0;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/PausableToken.sol";
@ -6,8 +6,8 @@ import "../token/ERC20/PausableToken.sol";
// mock class using PausableToken
contract PausableTokenMock is PausableToken {
function PausableTokenMock(address initialAccount, uint initialBalance) public {
balances[initialAccount] = initialBalance;
constructor(address _initialAccount, uint _initialBalance) public {
balances[_initialAccount] = _initialBalance;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
@ -6,13 +6,13 @@ import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
contract PostDeliveryCrowdsaleImpl is PostDeliveryCrowdsale {
function PostDeliveryCrowdsaleImpl (
constructor (
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
ERC20 _token
)
)
public
TimedCrowdsale(_openingTime, _closingTime)
Crowdsale(_rate, _wallet, _token)

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
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);
}
}

View 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
{}
}

View File

@ -1,9 +1,9 @@
pragma solidity ^0.4.8;
pragma solidity ^0.4.24;
import "../ownership/rbac/RBAC.sol";
import "../examples/RBACWithAdmin.sol";
contract RBACMock is RBAC {
contract RBACMock is RBACWithAdmin {
string constant ROLE_ADVISOR = "advisor";
@ -16,7 +16,7 @@ contract RBACMock is RBAC {
_;
}
function RBACMock(address[] _advisors)
constructor(address[] _advisors)
public
{
addRole(msg.sender, ROLE_ADVISOR);
@ -27,37 +27,37 @@ contract RBACMock is RBAC {
}
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?)

View File

@ -1,10 +1,11 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
contract ReentrancyAttack {
function callSender(bytes4 data) public {
require(msg.sender.call(data));
function callSender(bytes4 _data) public {
// solium-disable-next-line security/no-low-level-calls
require(msg.sender.call(abi.encodeWithSelector(_data)));
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../ReentrancyGuard.sol";
import "./ReentrancyAttack.sol";
@ -8,7 +8,7 @@ contract ReentrancyMock is ReentrancyGuard {
uint256 public counter;
function ReentrancyMock() public {
constructor() public {
counter = 0;
}
@ -16,26 +16,26 @@ contract ReentrancyMock is ReentrancyGuard {
count();
}
function countLocalRecursive(uint256 n) public nonReentrant {
if (n > 0) {
function countLocalRecursive(uint256 _n) public nonReentrant {
if (_n > 0) {
count();
countLocalRecursive(n - 1);
countLocalRecursive(_n - 1);
}
}
function countThisRecursive(uint256 n) public nonReentrant {
bytes4 func = bytes4(keccak256("countThisRecursive(uint256)"));
if (n > 0) {
function countThisRecursive(uint256 _n) public nonReentrant {
if (_n > 0) {
count();
bool result = this.call(func, n - 1);
// solium-disable-next-line security/no-low-level-calls
bool result = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", _n - 1));
require(result == true);
}
}
function countAndCall(ReentrancyAttack attacker) public nonReentrant {
function countAndCall(ReentrancyAttack _attacker) public nonReentrant {
count();
bytes4 func = bytes4(keccak256("callback()"));
attacker.callSender(func);
_attacker.callSender(func);
}
function count() private {

View File

@ -1,18 +1,19 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/MintableToken.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol";
contract RefundableCrowdsaleImpl is RefundableCrowdsale {
function RefundableCrowdsaleImpl (
constructor (
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
MintableToken _token,
uint256 _goal
)
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../token/ERC20/SafeERC20.sol";
@ -21,11 +21,11 @@ contract ERC20FailingMock is ERC20 {
return false;
}
function balanceOf(address) public constant returns (uint256) {
function balanceOf(address) public view returns (uint256) {
return 0;
}
function allowance(address, address) public constant returns (uint256) {
function allowance(address, address) public view returns (uint256) {
return 0;
}
}
@ -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;
}
@ -48,11 +48,11 @@ contract ERC20SucceedingMock is ERC20 {
return true;
}
function balanceOf(address) public constant returns (uint256) {
function balanceOf(address) public view returns (uint256) {
return 0;
}
function allowance(address, address) public constant returns (uint256) {
function allowance(address, address) public view returns (uint256) {
return 0;
}
}
@ -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);
}
}

View File

@ -1,21 +1,24 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../math/SafeMath.sol";
contract SafeMathMock {
uint256 public result;
function multiply(uint256 a, uint256 b) public {
result = SafeMath.mul(a, b);
function mul(uint256 _a, uint256 _b) public pure returns (uint256) {
return SafeMath.mul(_a, _b);
}
function subtract(uint256 a, uint256 b) public {
result = SafeMath.sub(a, b);
function div(uint256 _a, uint256 _b) public pure returns (uint256) {
return SafeMath.div(_a, _b);
}
function add(uint256 a, uint256 b) public {
result = SafeMath.add(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);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import {Bounty, Target} from "../../contracts/Bounty.sol";

View File

@ -0,0 +1,13 @@
pragma solidity ^0.4.24;
import "../token/ERC20/StandardBurnableToken.sol";
contract StandardBurnableTokenMock is StandardBurnableToken {
constructor(address _initialAccount, uint _initialBalance) public {
balances[_initialAccount] = _initialBalance;
totalSupply_ = _initialBalance;
}
}

View File

@ -1,13 +1,14 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
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;
}
}

View 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);
}
}

View File

@ -1,17 +1,18 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/TimedCrowdsale.sol";
contract TimedCrowdsaleImpl is TimedCrowdsale {
function TimedCrowdsaleImpl (
constructor (
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
ERC20 _token
)
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)

View 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
{
}
}

View File

@ -1,19 +1,19 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/WhitelistedCrowdsale.sol";
import "../crowdsale/Crowdsale.sol";
contract WhitelistedCrowdsaleImpl is WhitelistedCrowdsale {
contract WhitelistedCrowdsaleImpl is Crowdsale, WhitelistedCrowdsale {
function WhitelistedCrowdsaleImpl (
constructor (
uint256 _rate,
address _wallet,
ERC20 _token
)
public
)
Crowdsale(_rate, _wallet, _token)
public
{
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Ownable.sol";
import "../token/ERC20/ERC20Basic.sol";
@ -16,11 +16,11 @@ contract CanReclaimToken is Ownable {
/**
* @dev Reclaim all ERC20Basic compatible tokens
* @param token ERC20Basic The address of the token contract
* @param _token ERC20Basic The address of the token contract
*/
function reclaimToken(ERC20Basic token) external onlyOwner {
uint256 balance = token.balanceOf(this);
token.safeTransfer(owner, balance);
function reclaimToken(ERC20Basic _token) external onlyOwner {
uint256 balance = _token.balanceOf(this);
_token.safeTransfer(owner, balance);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Ownable.sol";
@ -24,15 +24,15 @@ contract Claimable is Ownable {
* @dev Allows the current owner to set the pendingOwner address.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
function transferOwnership(address newOwner) public onlyOwner {
pendingOwner = newOwner;
}
/**
* @dev Allows the pendingOwner address to finalize the transfer.
*/
function claimOwnership() onlyPendingOwner public {
OwnershipTransferred(owner, pendingOwner);
function claimOwnership() public onlyPendingOwner {
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Ownable.sol";
@ -14,9 +14,9 @@ contract Contactable is Ownable {
/**
* @dev Allows the owner to set a string with their contact information.
* @param info The contact information to attach to the contract.
* @param _info The contact information to attach to the contract.
*/
function setContactInformation(string info) onlyOwner public {
contactInformation = info;
function setContactInformation(string _info) public onlyOwner {
contactInformation = _info;
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Claimable.sol";
@ -19,7 +19,7 @@ contract DelayedClaimable is Claimable {
* @param _start The earliest time ownership can be claimed.
* @param _end The latest time ownership can be claimed.
*/
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
function setLimits(uint256 _start, uint256 _end) public onlyOwner {
require(_start <= _end);
end = _end;
start = _start;
@ -29,9 +29,9 @@ contract DelayedClaimable is Claimable {
* @dev Allows the pendingOwner address to finalize the transfer, as long as it is called within
* the specified start and end time.
*/
function claimOwnership() onlyPendingOwner public {
function claimOwnership() public onlyPendingOwner {
require((block.number <= end) && (block.number >= start));
OwnershipTransferred(owner, pendingOwner);
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
end = 0;

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Ownable.sol";
@ -13,10 +13,10 @@ contract HasNoContracts is Ownable {
/**
* @dev Reclaim ownership of Ownable contracts
* @param contractAddr The address of the Ownable to be reclaimed.
* @param _contractAddr The address of the Ownable to be reclaimed.
*/
function reclaimContract(address contractAddr) external onlyOwner {
Ownable contractInst = Ownable(contractAddr);
function reclaimContract(address _contractAddr) external onlyOwner {
Ownable contractInst = Ownable(_contractAddr);
contractInst.transferOwnership(owner);
}
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.24;
import "./Ownable.sol";
@ -7,27 +7,27 @@ 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 send to this contract by:
* 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
* @dev The `payable` flag is added so we can access `msg.value` without compiler warning. If we
* 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.
*/
function HasNoEther() public payable {
constructor() public payable {
require(msg.value == 0);
}
/**
* @dev Disallows direct send by settings a default function without the `payable` flag.
* @dev Disallows direct send by setting a default function without the `payable` flag.
*/
function() external {
}
@ -36,6 +36,6 @@ contract HasNoEther is Ownable {
* @dev Transfer all Ether held by the contract to the owner.
*/
function reclaimEther() external onlyOwner {
assert(owner.send(this.balance));
owner.transfer(address(this).balance);
}
}

Some files were not shown because too many files have changed in this diff Show More