Compare commits

..

331 Commits

Author SHA1 Message Date
Fabio Berger
174b360593 Publish
- 0x.js@1.0.1
 - @0xproject/abi-gen@1.0.8
 - @0xproject/assert@1.0.8
 - @0xproject/base-contract@2.0.2
 - @0xproject/connect@2.0.0
 - @0xproject/contract-wrappers@1.0.1
 - contracts@2.1.43
 - @0xproject/dev-utils@1.0.7
 - ethereum-types@1.0.6
 - @0xproject/fill-scenarios@1.0.1
 - @0xproject/forwarder-helper@1.0.1
 - @0xproject/json-schemas@1.0.1
 - @0xproject/metacoin@0.0.18
 - @0xproject/migrations@1.0.7
 - @0xproject/monorepo-scripts@1.0.8
 - @0xproject/order-utils@1.0.1
 - @0xproject/order-watcher@1.0.1
 - @0xproject/react-docs@1.0.8
 - @0xproject/react-shared@1.0.9
 - @0xproject/sol-compiler@1.1.2
 - @0xproject/sol-cov@2.1.2
 - @0xproject/sol-resolver@1.0.8
 - @0xproject/sra-report@1.0.8
 - @0xproject/sra-spec@1.0.1
 - @0xproject/subproviders@2.0.2
 - @0xproject/testnet-faucets@1.0.44
 - @0xproject/tslint-config@1.0.7
 - @0xproject/types@1.0.1
 - @0xproject/typescript-typings@2.0.0
 - @0xproject/utils@1.0.8
 - @0xproject/web3-wrapper@2.0.2
 - @0xproject/website@0.0.47
2018-09-05 11:16:45 +01:00
Fabio Berger
481a752e70 Updated CHANGELOGS 2018-09-05 11:16:34 +01:00
Fabio Berger
38acdfd632 Update CHANGELOG's to publish non-RC versions 2018-09-05 11:06:11 +01:00
Francesco Agosti
561e525778 Merge pull request #1058 from 0xProject/fix/connect/use-big-number-in-requests
[connect] Use BigNumber instead of string where appropriate in OrderConfigRequest
2018-09-04 17:25:51 -07:00
fragosti
69eb820d0d Change orderConfig from POST to GET like in spec 2018-09-04 15:49:30 -07:00
Alex Browne
447f16fc4f Merge pull request #1057 from 0xProject/deployment/copy-testnet-artifacts
Remove/rename/update all artifacts in preparation for v2 launch
2018-09-04 18:31:48 -04:00
Alex Browne
1769609245 Update order-watcher/package.json 2018-09-04 18:17:51 -04:00
Alex Browne
e1dcdac1bb add packages/sol-cov/test/fixtures/artifacts to .prettierignore 2018-09-04 18:14:59 -04:00
Alex Browne
9d45d19c80 More small artifacts updates/changes 2018-09-04 18:10:23 -04:00
Alex Browne
9858bb0ce4 Fix bug in contracts tests 2018-09-04 18:10:13 -04:00
fragosti
a3527a77a6 Add to CHANGELOG 2018-09-04 14:49:39 -07:00
fragosti
33a45fa739 Use BigNumber instead of string where appropriate in OrderConfigRequest 2018-09-04 14:44:56 -07:00
Alex Browne
e70882a657 More small chnages/bug fixes 2018-09-04 17:22:22 -04:00
Alex Browne
e456332da7 Rename and update some artifact locations 2018-09-04 16:47:28 -04:00
Alex Browne
4ed84c5dc5 Rename 2.0.0-beta-testnet to 2.0.0-testnet 2018-09-04 16:11:17 -04:00
Alex Browne
2fe3f40be9 Add missing testnet addresses to 2.0.0-mainnet artifacts 2018-09-04 16:09:59 -04:00
Alex Browne
44bfdb718f Copy artifacts from 2.0.0-beta-testnet that do not appear in 2.0.0-mainnet 2018-09-04 16:09:44 -04:00
Alex Browne
3524efc41c Merge pull request #1055 from 0xProject/deployment/2.0.0-beta-testnet/ropsten
Ropsten/Kovan Contract deployment
2018-09-04 15:54:48 -04:00
Francesco Agosti
01210c291c Merge pull request #1044 from 0xProject/feature/website/update-portal-v2
[website] Update portal for v2
2018-09-04 12:37:53 -07:00
Jacob Evans
192d4b4dbf Merge branch 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo into deployment/2.0.0-beta-testnet/ropsten 2018-09-04 20:32:43 +01:00
Jacob Evans
68246fc335 Revert Forwarder address for Ganache 2018-09-04 20:29:01 +01:00
Fabio Berger
7ef86636aa merge development 2018-09-04 20:26:02 +01:00
Fabio Berger
a5859c6cee Merge pull request #1038 from 0xProject/feature/contracts/mainnetMigrations
Mainnet migrations
2018-09-04 20:23:48 +01:00
Fabio Berger
3463903d02 Merge branch 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo into deployment/2.0.0-beta-testnet/ropsten
* 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo:
  Revert the exchange address change
  Tslint magic-number
2018-09-04 20:22:32 +01:00
Jacob Evans
4b0f1a8431 Remove Rinkeby from Exchange.json 2018-09-04 20:21:50 +01:00
Jacob Evans
603e8aa671 Revert the exchange address change 2018-09-04 20:18:23 +01:00
fragosti
6eb980abe2 Add to changelog 2018-09-04 12:11:17 -07:00
fragosti
46b168e10f Run linter 2018-09-04 12:09:24 -07:00
Jacob Evans
508e6ccf89 Tslint magic-number 2018-09-04 19:57:05 +01:00
fragosti
a173c5fc38 Merge branch 'feature/website/update-portal-v2' of https://github.com/0xProject/0x-monorepo into feature/website/update-portal-v2 2018-09-04 11:55:42 -07:00
fragosti
f5237f7971 Use order parser utils from order utils 2018-09-04 11:55:08 -07:00
Amir Bandeali
6f7a5d00e6 Update prettierignore 2018-09-04 11:47:26 -07:00
Fabio Berger
4061723863 merge back weth9 2018-09-04 19:42:54 +01:00
Jacob Evans
ab1b52ba87 Ropsten/Kovan Contract deployment 2018-09-04 19:41:05 +01:00
Fabio Berger
16e94ecb40 Merge branch 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo into deployment/2.0.0-beta-testnet/ropsten
* 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo:
  Ropsten/Kovan Contract deployment
2018-09-04 19:35:48 +01:00
Jacob Evans
6bb2c5877c Ropsten/Kovan Contract deployment 2018-09-04 19:29:40 +01:00
fragosti
a14450f367 Add order parsers to order-util 2018-09-04 11:22:31 -07:00
Amir Bandeali
85df313a7a Update mainnet artifacts 2018-09-04 11:07:56 -07:00
Amir Bandeali
66ed6b9b88 Update mainnet configs 2018-09-04 11:07:56 -07:00
Amir Bandeali
9304d09da6 Add mainnet migrations 2018-09-04 11:07:56 -07:00
fragosti
e61dbbb6cf Merge https://github.com/0xProject/0x-monorepo into feature/website/update-portal-v2 2018-09-04 10:53:18 -07:00
Fabio Berger
1690f59857 Remove unused imports and console.log 2018-09-04 18:42:50 +01:00
Fabio Berger
c916dd6ebb Add back order validation logic 2018-09-04 18:39:53 +01:00
Fabio Berger
8a683b8541 Fix imports 2018-09-04 18:37:41 +01:00
Fabio Berger
4883b8be10 remove console log 2018-09-04 18:37:33 +01:00
Fabio Berger
51760f9bdd merge development 2018-09-04 18:37:24 +01:00
Fabio Berger
6a619a4084 Merge pull request #1054 from 0xProject/addValidationMethods
Temporarily Add Back Validation Methods
2018-09-04 18:04:03 +01:00
Jacob Evans
feeafa193a Ropsten/Kovan Contract deployment 2018-09-04 18:01:21 +01:00
Fabio Berger
8d8528996a Export abstract fetchers 2018-09-04 17:44:27 +01:00
Amir Bandeali
965d609829 Merge pull request #1050 from 0xProject/refactor/contracts/multisig
Update MultiSig and add more tests
2018-09-04 09:12:16 -07:00
Leonid Logvinov
a52714bcf3 Merge pull request #1052 from 0xProject/feature/remove-types
[typescript-typings] Remove types that were moved to DefinitelyTyped
2018-09-04 17:54:54 +02:00
Fabio Berger
bbfd7647a8 Export missing type 2018-09-04 16:52:21 +01:00
Fabio Berger
0aba5a3be4 Merge branch 'development' into addValidationMethods
* development:
  Remove unused imports
2018-09-04 16:51:27 +01:00
Fabio Berger
61bf5864a8 Merge branch 'development' of github.com:0xProject/0x-monorepo into development
* 'development' of github.com:0xProject/0x-monorepo:
  Remove unused imports
2018-09-04 16:51:15 +01:00
Fabio Berger
56847a53f4 Add PR nr 2018-09-04 16:41:43 +01:00
Fabio Berger
8324ab3af7 Update yarn.lock 2018-09-04 16:27:26 +01:00
Fabio Berger
d496a7585c Add validateFillOrderThrowIfInvalidAsync and validateOrderFillableOrThrowAsync to ExchangeWrapper 2018-09-04 16:27:16 +01:00
Fabio Berger
8d7f2a993a Import fetchers from contract-wrappers 2018-09-04 16:24:01 +01:00
Fabio Berger
ed786f3e8f Export fetchers from contract-wrappers 2018-09-04 16:23:29 +01:00
Fabio Berger
539c243733 Move fetchers to contract-wrappers 2018-09-04 16:23:02 +01:00
Leonid Logvinov
40e0c829b3 Fix the version 2018-09-04 17:06:09 +02:00
Amir Bandeali
e34b1f2f8b Remove TODOs that will not be addressed 2018-09-04 07:57:47 -07:00
Amir Bandeali
f6b6619c08 Fix geth tests 2018-09-04 07:57:47 -07:00
Amir Bandeali
e480e08aa4 Add test for external_call visibility 2018-09-04 07:57:47 -07:00
Amir Bandeali
652cf7a976 Add MultiSigWalletWithTimeLock revert reasons to tests 2018-09-04 07:57:47 -07:00
Amir Bandeali
7a8ab6fbe8 Update MultiSigWalletWithTimeLock to 0.4.24 2018-09-04 07:57:47 -07:00
Amir Bandeali
9deec8ec35 Add more tests for MultiSigWalletWithTimeLock 2018-09-04 07:57:47 -07:00
Amir Bandeali
3f1586045c Add test for executeRemoveAuthorizedAddressAtIndex when called by non-owner 2018-09-04 07:57:47 -07:00
Amir Bandeali
ada5563b1f Update to most recent multisig 2018-09-04 07:57:47 -07:00
Leonid Logvinov
6b41a570a5 Change doc gen configs 2018-09-04 16:36:18 +02:00
Leonid Logvinov
cebf6bfb34 Move types used in public interfaces to dependencies 2018-09-04 16:36:18 +02:00
Leonid Logvinov
47a1b48ad8 Add temporarily missing web3-provider-engine types in website 2018-09-04 16:36:18 +02:00
Leonid Logvinov
ef82a9d2a6 Add CHANGELOG entry 2018-09-04 16:36:18 +02:00
Leonid Logvinov
ba6351841d Add temporarily missing web3-provider-engine types in subproviders 2018-09-04 16:36:18 +02:00
Leonid Logvinov
cdc786a1e3 Remove types for web3-provider-engine from typescript-typings 2018-09-04 16:36:18 +02:00
Leonid Logvinov
3ea137a78f Remove types for eth-lightwallet from typescript-typings 2018-09-04 16:36:18 +02:00
Leonid Logvinov
b525ccc825 Remove types for detect-node from typescript-typings 2018-09-04 16:36:18 +02:00
Leonid Logvinov
77acbdd3ea Remove types for ganache-core from typescript-typings 2018-09-04 16:36:18 +02:00
Leonid Logvinov
c13190ceab Remove types for newman from typescript-typings 2018-09-04 16:36:18 +02:00
Leonid Logvinov
78d4fc59a5 Merge pull request #1053 from 0xProject/fix/linter_issues
[website] Remove unused imports
2018-09-04 16:35:54 +02:00
Leonid Logvinov
f9e86c057d Remove unused imports 2018-09-04 16:08:35 +02:00
Amir Bandeali
1d8e133a30 Merge pull request #1051 from 0xProject/fix/contracts/style
Apply styling fixes to contracts
2018-09-03 21:22:03 -07:00
Amir Bandeali
99fbf384fd Apply styling fixes 2018-09-03 20:55:37 -07:00
Amir Bandeali
cb4fcf4de7 Revert in Forwarder constructor if ERC20 proxy isn't registered 2018-09-03 20:35:00 -07:00
Brandon Millman
675964dc5c Merge pull request #1048 from 0xProject/feature/website/patch-v2-landing
[website] Final tweaks for landing page
2018-08-30 17:26:47 -07:00
Brandon Millman
6432f85eb0 Wording change for first benefit 2018-08-30 17:14:17 -07:00
Francesco Agosti
66eef758c6 Merge pull request #1047 from 0xProject/feature/re-add-no-unused-variables
Re-add no-unused-variable tslint rule
2018-08-30 15:38:21 -07:00
Brandon Millman
c64f0ba34b Tweaks to benefits and use cases 2018-08-30 15:26:03 -07:00
Brandon Millman
6deffb6b28 Update yarn lock 2018-08-30 15:19:33 -07:00
Greg Hysen
5802713801 Merge pull request #1046 from 0xProject/fix/contracts/roundingFeeTestsMatchOrders
Test cases for rounding fees in matchOrders
2018-08-30 14:27:01 -07:00
Brandon Millman
11df29fa8e Update exchange ABI for decoding logs 2018-08-30 14:23:09 -07:00
Brandon Millman
f4a41e80b8 Remove LogError legacy stuff 2018-08-30 14:04:55 -07:00
Brandon Millman
5c655b55d3 Update comment for validation 2018-08-30 14:01:04 -07:00
Brandon Millman
63c15b6f4f Remove commented out block 2018-08-30 14:00:10 -07:00
Brandon Millman
4f2bc29744 Remove cancel check 2018-08-30 13:59:42 -07:00
fragosti
2cac431c41 Final tweaks for landing page 2018-08-30 13:53:30 -07:00
fragosti
80b7a7842c run prettier 2018-08-30 13:47:33 -07:00
Brandon Millman
8c7cec9822 Merge pull request #1040 from 0xProject/feature/website/v2-tweaks
[website] Landing page tweaks for v2 launch
2018-08-30 13:46:37 -07:00
Brandon Millman
971a4087d2 Update yarn lock 2018-08-30 13:36:44 -07:00
Brandon Millman
660e670d38 Update generate and fill order flows 2018-08-30 13:36:44 -07:00
Brandon Millman
052824f4e3 Token registry from old 0x version 2018-08-30 13:36:44 -07:00
fragosti
1d5ef4d0ca Fix unused vars for react-shared and website 2018-08-30 13:28:07 -07:00
Brandon Millman
a6440b94f4 Fix import 2018-08-30 13:24:24 -07:00
Brandon Millman
01685b7622 Fix contract not deployed on network bug in ContractWrapper class 2018-08-30 13:24:24 -07:00
Brandon Millman
397fefa8d7 Update typings version 2018-08-30 13:24:24 -07:00
Brandon Millman
82a01ef020 Initial changes for v2 portal 2018-08-30 13:24:24 -07:00
Brandon Millman
a224ce347e Revert whats new text 2018-08-30 13:21:07 -07:00
Amir Bandeali
81ba2a8411 Merge pull request #1045 from 0xProject/feature/contracts/cancelOrderInternal
Add cancelOrderInternal, use within batchCancelOrders
2018-08-30 13:07:51 -07:00
Amir Bandeali
a6e8b28da5 Merge pull request #1043 from 0xProject/feature/contracts/edgeCaseTests
Add edge case tests
2018-08-30 13:07:19 -07:00
Brandon Millman
e90dbf66f3 Add new exchange everywhere graphic 2018-08-30 12:29:47 -07:00
Greg Hysen
0be2219beb Test cases for rounding fees in matchOrders 2018-08-30 12:23:11 -07:00
Amir Bandeali
09b4d5e0e4 Add cancelOrderInternal, use within batchCancelOrders 2018-08-30 12:10:24 -07:00
Brandon Millman
60f1bcf51f Remove unused render methods in landing page 2018-08-30 12:09:54 -07:00
Brandon Millman
431ac3b401 Update yarn lock 2018-08-30 12:05:29 -07:00
Francesco Agosti
50781bd77a Merge pull request #1042 from 0xProject/feature/website/v2-tweaks-fra
[website] Add rotating text to landing header and careers button to topbar
2018-08-30 11:55:28 -07:00
fragosti
c3361bb86e Remove conflict strings 2018-08-30 11:52:08 -07:00
fragosti
fd5ad69c26 Add careers page to top bar 2018-08-30 11:49:27 -07:00
fragosti
b1f97a27f3 Final tweaks 2018-08-30 11:49:27 -07:00
fragosti
febddcb356 Remove redundant import 2018-08-30 11:49:27 -07:00
fragosti
74d5af34eb Add TypedText component and use it on landing page 2018-08-30 11:49:27 -07:00
fragosti
365890291f Add generic title changes 2018-08-30 11:48:49 -07:00
Brandon Millman
0368de701f Added todo comments for missing items 2018-08-30 11:44:09 -07:00
Brandon Millman
f5e7b7e7e0 Add title header to use cases section 2018-08-30 11:39:25 -07:00
Brandon Millman
038c21324e Make hero image responsive 2018-08-30 11:39:25 -07:00
Brandon Millman
5d008ee83e Update what's new styling 2018-08-30 11:39:25 -07:00
Amir Bandeali
d0f6933980 Add tests for token that returns >32 bytes 2018-08-30 09:27:28 -07:00
Amir Bandeali
14793f30b5 Add more proxy tests 2018-08-30 09:27:28 -07:00
Amir Bandeali
86319291e3 Update used addresses for authorizable tests 2018-08-30 09:27:28 -07:00
Amir Bandeali
afa2dd7374 Add test for fillOrder and dispatchTransferFrom where maker == taker 2018-08-30 09:26:44 -07:00
fragosti
1312e4caf2 Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/website/v2-tweaks 2018-08-29 16:39:25 -07:00
Amir Bandeali
eb4517d737 Merge pull request #1041 from 0xProject/refactor/contracts/assetProxyOwnerVersion
Update AssetProxyOwner to 0.4.24, remove redundant code
2018-08-29 15:57:53 -07:00
Amir Bandeali
d80701c277 Fix geth tests 2018-08-29 15:35:09 -07:00
Amir Bandeali
bf3ab1127d Remove unused imports 2018-08-29 14:42:42 -07:00
Amir Bandeali
dcb12b6ad6 Update AssetProxyOwner to 0.4.24 2018-08-29 14:12:10 -07:00
Francesco Agosti
f87420a776 Merge pull request #1023 from 0xProject/website/feature/react-16
[website] Upgrade all the things to React 16
2018-08-29 14:04:17 -07:00
Greg Hysen
6cedf5362b Merge pull request #1039 from 0xProject/fix/contracts/audit2Fixes
Fixes as-per Audit for LibBytes + ERC20 Proxy Comments
2018-08-29 13:53:49 -07:00
Greg Hysen
aa833ef074 Typos in LibBytes tests 2018-08-29 13:26:46 -07:00
Greg Hysen
5f1c9cfee5 Reverted syntax used by readBytes4 in AssetProxyOwner to be compatible with Solidity v0.4.10 2018-08-29 13:15:40 -07:00
Greg Hysen
62b93cf2eb More tests for LibBytes 2018-08-29 13:14:51 -07:00
Brandon Millman
b1c5f6e8f1 Update use cases section 2018-08-29 12:45:24 -07:00
Brandon Millman
3bc9b309f6 Update tokenization section 2018-08-29 12:45:24 -07:00
Brandon Millman
6924a2b681 Update benefits 2018-08-29 12:45:24 -07:00
Brandon Millman
d93d4c34f5 Update whats new 2018-08-29 12:45:24 -07:00
Brandon Millman
557267477e Add new header image 2018-08-29 12:45:16 -07:00
Brandon Millman
b9f7979e91 Replace projects section with relayers 2018-08-29 12:45:15 -07:00
Greg Hysen
8c803ab232 Updated comments for ERC20 proxy to clarify how we load the token address from calldata (3.18 from audit) 2018-08-29 12:25:06 -07:00
fragosti
422e5e4dd7 Apply prettier 2018-08-29 11:57:52 -07:00
fragosti
2aea820d89 Merge branch 'development' of https://github.com/0xProject/0x-monorepo into website/feature/react-16 2018-08-29 11:42:44 -07:00
Greg Hysen
1c3b2b7141 Updated readBytes4 to match spec + added unit tests. These are 3.5/3.6 from audit 2018-08-29 11:39:52 -07:00
Alex Browne
e7d5ceb9c5 feat: Add support for TypeScript project references (#991)
* Update all package.json and tsconfig.json

* fix(contracts): Make test/utils/web3_wrapper.ts compatible with project refs

* Fix webpack config for 0x.js

* Fix linter errors by adding rootDir to tsconfig.json as needed

* Add build:ts and watch:ts commands to package.json

* Update sra-spec to work with project references

* Update tsconfig.json with latest new/removed packages

* Add TypeScript as devDependency at root

* Add missing rootDir to forwarder-helper package

* Use a separate tsconfig file for typedoc

* Fix linter errors

* Apply PR feedback (add comments)

* Fix 0x.js tsconfig
2018-08-29 11:15:30 -07:00
fragosti
68af0e9eb7 Change VersionDropDown to use material-ui 3 2018-08-28 18:08:06 -07:00
fragosti
a18d0f6229 Upgrade version of react-shared in website 2018-08-28 17:49:15 -07:00
fragosti
031807df9c Upgrade react-copy-to-clipboard 2018-08-28 15:52:09 -07:00
fragosti
72710be04b Remove react-tap-event-plugin from react-shared 2018-08-28 15:37:20 -07:00
fragosti
ac135d55d3 Upgrade material ui in react-docs 2018-08-28 15:32:15 -07:00
fragosti
1d55e94659 Update lockfile 2018-08-28 15:27:24 -07:00
fragosti
86284f1c7e Merge branch 'development' of https://github.com/0xProject/0x-monorepo into website/feature/react-16 2018-08-28 15:25:08 -07:00
fragosti
61a4ae7fc4 Update material-ui in react-shared 2018-08-28 15:15:54 -07:00
fragosti
55fab3d98f Revert "Simplify dropdown component"
This reverts commit 91a9014a50.
2018-08-28 15:07:29 -07:00
fragosti
de11b62e30 Revert "Have new Popover component working in React 16"
This reverts commit 5785ec0713.
2018-08-28 15:07:28 -07:00
fragosti
8e14e65b60 Revert "Enable hovering state for dropdown"
This reverts commit ac1640140c.
2018-08-28 15:07:24 -07:00
fragosti
2d1d14d2e4 Upgrade material ui to 0.20.0 2018-08-28 15:04:34 -07:00
Brandon Millman
f44644ad90 Merge pull request #1022 from 0xProject/feature/contract-wrappers/order-validator
[contract-wrappers] Write wrapper for OrderValidator contract
2018-08-28 14:20:57 -07:00
fragosti
ac1640140c Enable hovering state for dropdown 2018-08-28 13:53:49 -07:00
Greg Hysen
1402a0aa22 Merge pull request #1036 from 0xProject/fix/contracts/calculateFillResults
Making rounding consistent in calculateFillResults
2018-08-28 13:51:38 -07:00
Amir Bandeali
f225f9e7c8 Making rounding consistent in calculateFillResults 2018-08-28 13:25:05 -07:00
Amir Bandeali
14fdb71a71 safeGetPartialAmount (#1035)
* Added Test "Should transfer correct amounts when left order is fully filled and values pass isRoundingErrorCeil but fail isRoundingErrorFloor"

* Added RoundingError exception to reference function for getPartialAmount

* Added RoundingError exception to reference function for getPartialAmount

* Added isRoundingErrorCeil to getPartialAmountCeil reference funtion

* Computed new values  for "Should give right maker a better buy price when correct price is not integral" that does not have a rounding error

* Almost all tests for match orders are passing after adding isRoundingErrorCeil check

* WIP commit: Added rounding error checks to getPartialAmount

* WIP commit: Added rounding error checks to getPartialAmount

* Use safe versions of getPartialAmount

* Update Exchange internals tests

* Run linter

* Found new values for "Should transfer correct amounts when right order fill amount deviates from amount derived by `Exchange.fillOrder`"

* Fixed merge conflicts

* Run all tests

* Cleaned up some comments on match Orders tests

* Fix tests for geth
2018-08-28 13:00:49 -07:00
Brandon Millman
9c4c4fb19a Export missing types and add OrderValidatorWrapper to hidden constructors 2018-08-28 12:03:21 -07:00
fragosti
5785ec0713 Have new Popover component working in React 16 2018-08-27 18:29:35 -07:00
Alex Browne
2eab0e30b7 fix(contracts): Catch cases where the actual error differs from the expected error (#1032)
* Catch cases where the actual error differs from the expected error

* Add tests for testWithReferenceFuncAsync

* Small style and comment fixes
2018-08-27 16:07:38 -07:00
Brandon Millman
2c846ff145 Add OrderValidatorWrapper to public interface 2018-08-27 16:06:34 -07:00
Brandon Millman
ca0dfc6610 Add contract-wrappers changelog entry for OrderValidatorWrapper 2018-08-27 13:57:48 -07:00
Brandon Millman
0fd44ee2c1 Fix broken test 2018-08-27 13:53:51 -07:00
Brandon Millman
7271fc0bab Add getBalancesAndAllowances to wrapper 2018-08-27 13:49:44 -07:00
Brandon Millman
6c039bbeb1 Update OrderValidator artifact to include getBalancesAndAllowances function 2018-08-27 13:43:19 -07:00
Brandon Millman
38e6d26145 Add params to all function comments 2018-08-27 13:31:12 -07:00
Brandon Millman
b0f210dea9 Add getERC721Owner to wrapper 2018-08-27 13:21:14 -07:00
Brandon Millman
f7469080f9 Update getOrdersAndTradersInfo to return an array instead 2018-08-27 13:21:10 -07:00
Amir Bandeali
fb5ea5d99f Merge pull request #1030 from 0xProject/fix/contracts/forwarderFillOrderNoThrow
Remove redundant mstores from fillOrderNoThrow
2018-08-27 13:07:57 -07:00
Brandon Millman
be2f4cbdca Add getBalanceAndAllowance to wrapper 2018-08-27 13:04:54 -07:00
Brandon Millman
68f2dc11b4 Add getTraderInfo and getTradersInfo to wrapper 2018-08-27 13:04:54 -07:00
Brandon Millman
d6c670dfcb Add getOrderAndTraderInfoAsync to wrapper 2018-08-27 13:04:54 -07:00
Brandon Millman
0736c41357 Add test for order validator 2018-08-27 13:04:54 -07:00
Brandon Millman
898bd75a18 Remove some unused variables in forwarder wrapper test 2018-08-27 13:04:54 -07:00
Brandon Millman
260313a6ae Initial OrderValidator wrapper 2018-08-27 13:04:54 -07:00
Amir Bandeali
6a99bfa68e Add clarifying comments 2018-08-27 12:01:58 -07:00
Amir Bandeali
f60adbdd72 Remove redundant mstores from fillOrderNoThrow 2018-08-27 11:54:20 -07:00
Alex Browne
1be310cef4 Merge pull request #1031 from 0xProject/fix/internal-tests-division-by-zero-assertion
Use correct error message for division by zero
2018-08-27 11:48:47 -07:00
Alex Browne
ff4f86f1d6 fix(contracts): Use correct error message for division by zero 2018-08-27 11:19:25 -07:00
Fabio Berger
f4a4fefe42 Exit with non-error code at end of publishRelease 2018-08-27 15:02:12 +01:00
Fabio Berger
00a4fa5f7c Publish
- 0x.js@1.0.1-rc.6
 - @0xproject/abi-gen@1.0.7
 - @0xproject/assert@1.0.7
 - @0xproject/base-contract@2.0.1
 - @0xproject/connect@2.0.0-rc.2
 - @0xproject/contract-wrappers@1.0.1-rc.5
 - contracts@2.1.42
 - @0xproject/dev-utils@1.0.6
 - @0xproject/fill-scenarios@1.0.1-rc.5
 - @0xproject/forwarder-helper@1.0.1-rc.2
 - @0xproject/json-schemas@1.0.1-rc.6
 - @0xproject/metacoin@0.0.17
 - @0xproject/migrations@1.0.6
 - @0xproject/monorepo-scripts@1.0.7
 - @0xproject/order-utils@1.0.1-rc.6
 - @0xproject/order-watcher@1.0.1-rc.5
 - @0xproject/react-docs@1.0.7
 - @0xproject/react-shared@1.0.8
 - @0xproject/sol-compiler@1.1.1
 - @0xproject/sol-cov@2.1.1
 - @0xproject/sol-resolver@1.0.7
 - @0xproject/sra-report@1.0.7
 - @0xproject/sra-spec@1.0.1-rc.6
 - @0xproject/subproviders@2.0.1
 - @0xproject/testnet-faucets@1.0.43
 - @0xproject/types@1.0.1-rc.6
 - @0xproject/utils@1.0.7
 - @0xproject/web3-wrapper@2.0.1
 - @0xproject/website@0.0.46
2018-08-27 14:48:24 +01:00
Fabio Berger
4475fefd07 Updated CHANGELOGS 2018-08-27 14:47:56 +01:00
Fabio Berger
cd08a9c121 Fix prettier 2018-08-27 13:43:29 +01:00
Fabio Berger
b0c4eb8333 Update changelog files for RC packages 2018-08-27 13:16:31 +01:00
Fabio Berger
368dbda8f0 Merge pull request #1028 from 0xProject/fix-ci
Fix `test_publish` CI Test
2018-08-27 13:09:11 +01:00
Fabio Berger
bc4149683e Skip doc generation for local publishes since we test this in a separate CI test 2018-08-27 12:39:10 +01:00
Fabio Berger
6174d9ebb7 Fix typo 2018-08-27 12:34:34 +01:00
Fabio Berger
e4fc8a8414 Use absolute path 2018-08-27 12:05:55 +01:00
Fabio Berger
907972c466 Merge branch 'development' into fix-ci
* development:
  Run yarn a second time if the first fails
2018-08-27 11:43:35 +01:00
Fabio Berger
49f5fe635f Merge branch 'development' of github.com:0xProject/0x-monorepo into development
* 'development' of github.com:0xProject/0x-monorepo:
  Run yarn a second time if the first fails
2018-08-27 11:43:22 +01:00
Fabio Berger
77290c1efa Run yarn a second time if the first fails 2018-08-27 10:51:38 +01:00
Fabio Berger
4ac43a9fd2 Try relative to root dir 2018-08-27 10:38:06 +01:00
Fabio Berger
cc77d1dd49 merge development 2018-08-27 10:35:16 +01:00
Fabio Berger
51161784e8 Merge branch 'development' of github.com:0xProject/0x-monorepo into development
* 'development' of github.com:0xProject/0x-monorepo:
  Fix command
  Move md files to lib folder during build
  Change exit code to failure
  Fix sra-spec `main` and `types` in package.json
  Issue #1025 BlockParam unroll
  fix: Use yarn version 1.9.4 on CI
2018-08-27 10:34:45 +01:00
Fabio Berger
cb7660fbe7 Merge pull request #1009 from 0xProject/fix/ci-yarn-1.9.4
fix: Use yarn version 1.9.4 on CI
2018-08-27 10:33:02 +01:00
Fabio Berger
82e51b8787 Fix command 2018-08-27 10:15:27 +01:00
Fabio Berger
fffa96bba7 Move md files to lib folder during build 2018-08-27 10:15:13 +01:00
Fabio Berger
e6cb2e0fcd Change exit code to failure 2018-08-27 10:14:43 +01:00
Fabio Berger
38abeaed9c Fix sra-spec main and types in package.json 2018-08-27 10:13:17 +01:00
Fabio Berger
90c9e3496a Actual relative path 2018-08-27 10:10:07 +01:00
Fabio Berger
9fc8a6e214 Try relative path 2018-08-27 10:09:51 +01:00
Fabio Berger
9df87a199a Merge pull request #1026 from 0xProject/fix/contract-wrappers/block-param-literal
[contract_templates] Issue #1025 BlockParam unroll
2018-08-27 10:07:06 +01:00
Jacob Evans
7e9ba50502 Issue #1025 BlockParam unroll
BlockParam unrolls into number | BlockParamLiteral, though BlockParamLiteral does not get imported. This results in type build errors in downstream projects where tslint checks libs
2018-08-27 15:59:43 +10:00
Fabio Berger
41559c39b9 Fix command 2018-08-26 23:43:19 +01:00
Fabio Berger
6a6b424c86 Move md files to lib folder during build 2018-08-26 23:35:47 +01:00
Fabio Berger
3a5c6ed00f Fix sra-spec main and types in package.json 2018-08-26 23:05:04 +01:00
Fabio Berger
db54588d05 Add BlockParamLiteral to template 2018-08-26 22:00:51 +01:00
Fabio Berger
52fde551e4 Remove check since this method is now used in multiple places 2018-08-26 21:16:32 +01:00
Fabio Berger
40cf805e5e Also use failure exit code if unexpected error occurs 2018-08-26 20:54:15 +01:00
Fabio Berger
09d6496135 Change exit code to failure 2018-08-26 20:53:21 +01:00
Fabio Berger
c4dadf4bfd Combine imports 2018-08-26 17:49:06 +01:00
Fabio Berger
35ba3e6f7c Bumop 0x.js version 2018-08-26 17:35:17 +01:00
Fabio Berger
3ac182ee91 Fix file path to main and types in package.json 2018-08-26 17:12:13 +01:00
Amir Bandeali
00e7c70b4d Merge pull request #986 from 0xProject/feature/contracts/assertions
Add more assertions to assertValidFill
2018-08-24 20:03:28 -07:00
Amir Bandeali
0aa9ed3839 Merge pull request #1008 from 0xProject/fix/contracts/robustMatching
Robustness in Order Matching
2018-08-24 19:00:53 -07:00
Remco Bloemen
d652deea23 Merge branch 'fix/contracts/robustMatching' of github.com:0xProject/0x.js into fix/contracts/robustMatching 2018-08-24 18:54:15 -07:00
Greg Hysen
878db3b849 Added comments to order matching 2018-08-24 18:48:29 -07:00
Greg Hysen
ec2e726be0 Rephrased some of the math in MixinMatchOrders to improve readability 2018-08-24 18:20:26 -07:00
Greg Hysen
287830d6e0 Run all tests 2018-08-24 18:20:26 -07:00
Greg Hysen
c7a7ae7e18 Give right maker better price when correct value is not integral 2018-08-24 18:20:26 -07:00
Greg Hysen
1c7ba6a315 Extract only fill event logs 2018-08-24 18:20:26 -07:00
Greg Hysen
0a6f107243 Added temporary @todo to MixinMatchOrders 2018-08-24 18:20:25 -07:00
Greg Hysen
a93f95c55e Wording in MixinMatchOrders 2018-08-24 18:20:25 -07:00
Greg Hysen
6833e243b7 Addressed linter errors in match order tesster 2018-08-24 18:20:25 -07:00
Greg Hysen
81dc893d1d Removed a redundant comment from matchOrders 2018-08-24 18:20:25 -07:00
Greg Hysen
f8e565bc06 Tests for matchOrders edge cases 2018-08-24 18:20:25 -07:00
Greg Hysen
ba15fb6a06 Swapped direction of expect values to match output in failure cases 2018-08-24 18:20:25 -07:00
Greg Hysen
1e6b83719a Renaming verify -> assert in order matching 2018-08-24 18:20:25 -07:00
Greg Hysen
9fcb2dda73 Fixed a function comment 2018-08-24 18:20:25 -07:00
Greg Hysen
9a5ec8d030 Added function signature comments 2018-08-24 18:20:25 -07:00
Greg Hysen
ac872e5181 Added expect messages for checking left/right order states 2018-08-24 18:20:25 -07:00
Greg Hysen
70863cca08 Ran prettier and linter 2018-08-24 18:20:25 -07:00
Greg Hysen
5a1dce15be Updated all existing match order tests to use new format 2018-08-24 18:19:43 -07:00
Greg Hysen
d291256158 Passes comprehensive test 2018-08-24 18:18:30 -07:00
Greg Hysen
8c706ac639 Verify logs 2018-08-24 18:18:30 -07:00
Greg Hysen
f697814849 First balance test with intentional values 2018-08-24 18:18:30 -07:00
Greg Hysen
ca5c9e77c0 Ironing out the new set of test cases for order matchubng 2018-08-24 18:17:27 -07:00
Greg Hysen
a32b201afe Rounding for fees in match orders addressed, plus example 2018-08-24 18:17:27 -07:00
Greg Hysen
0ecdf1e213 All existing tests pass. 2018-08-24 18:17:26 -07:00
Greg Hysen
057891b342 Added fees to matchOrders (previously in calculateFillResults 2018-08-24 18:17:26 -07:00
Greg Hysen
407f63ef20 Removed calculateFillResults from matchOrders workflow. Eliminates compounded rounding errors. 2018-08-24 18:17:26 -07:00
Amir Bandeali
f938c989e3 Merge pull request #1002 from 0xProject/feature/contracts/mutex
[contracts] Add mutexes and reentrancy guards
2018-08-24 18:15:22 -07:00
Amir Bandeali
c8500cab10 Fix build 2018-08-24 17:30:56 -07:00
Amir Bandeali
c28c3db63f Only use one nonReentrant modifier, remove modifier from fillOrderNoThrow variations 2018-08-24 17:30:56 -07:00
Amir Bandeali
a09ee90739 Add tests for matchOrders 2018-08-24 17:30:56 -07:00
Amir Bandeali
7d5a23969d Add reentrancy tests for fillOrder and wrapper functions 2018-08-24 17:30:56 -07:00
Amir Bandeali
56c3c29feb Update ReentrantERC20Token with new functions and check that revert is occuring for correct reason 2018-08-24 17:30:56 -07:00
Amir Bandeali
c75212bef0 Add nonReentrant modifiers on functions that use getCurrentContextAddress only, add lockMutex modifier on functions that make external calls 2018-08-24 17:30:56 -07:00
Amir Bandeali
6d0dedc62c Split modifiers into check only and check, lock, unlock 2018-08-24 17:30:56 -07:00
Amir Bandeali
cf12daea2f Add ReentrantToken 2018-08-24 17:30:56 -07:00
Amir Bandeali
6f88e9bdbd Add internal fill functions, add reentrancy guard to public functions that make external calls 2018-08-24 17:30:56 -07:00
Amir Bandeali
d8cb56caa3 Add ReentrancyGuard contract 2018-08-24 17:30:56 -07:00
Amir Bandeali
044415e23d Remove redundant sload from getCurrentContextAddress 2018-08-24 17:30:56 -07:00
Remco Bloemen
6b866d6053 Revert maker not equal taker check 2018-08-24 17:29:52 -07:00
Amir Bandeali
74ce893f52 Merge pull request #1003 from 0xProject/feature/contracts/roundup
[contracts] Add getPartialAmountCeil and isRoundingErrorCeil
2018-08-24 17:29:09 -07:00
Amir Bandeali
cc1fac9bbe Fix linting errors 2018-08-24 17:02:42 -07:00
Amir Bandeali
94e01be9ed Merge pull request #1021 from 0xProject/feature/contracts/skipselftransfer
[Contracts] Skip self transfers
2018-08-24 16:58:46 -07:00
fragosti
91a9014a50 Simplify dropdown component 2018-08-24 16:48:48 -07:00
Remco Bloemen
e215992859 Fix mixin api 2018-08-24 16:46:24 -07:00
Remco Bloemen
e6f5cac878 Fix double definition of error 2018-08-24 16:46:24 -07:00
Remco Bloemen
29971f36cf Split into assertFillable and assertValidFill 2018-08-24 16:46:24 -07:00
Remco Bloemen
3e4493b389 Disallow self filling 2018-08-24 16:46:24 -07:00
Remco Bloemen
749c6ecc30 Add revert reasons to types 2018-08-24 16:46:24 -07:00
Remco Bloemen
e6e7bae445 Remove BUG_ from revert reasons 2018-08-24 16:46:23 -07:00
Remco Bloemen
a1d8943552 Document accetable price check 2018-08-24 16:46:23 -07:00
Remco Bloemen
07e56b3cc7 Fix taker overpay check 2018-08-24 16:46:23 -07:00
Remco Bloemen
b16f5f55fb Check fillable early 2018-08-24 16:46:23 -07:00
Remco Bloemen
d92fd43791 Update for new assertValidFill signature 2018-08-24 16:46:23 -07:00
Remco Bloemen
e706fa76ac Add overfill and price assertion to assertValidFill 2018-08-24 16:46:23 -07:00
Remco Bloemen
11328bd93d Skip self-transfers 2018-08-24 16:26:48 -07:00
Remco Bloemen
bc686fcbf3 Stylistic fixes 2018-08-24 16:17:02 -07:00
Remco Bloemen
80291caf7c Append -Floor to getPartialAmount and isRoundingError 2018-08-24 16:16:44 -07:00
Brandon Millman
cd5e9a5115 Merge pull request #1018 from 0xProject/fix/migrations/order-validator-testnet
[migrations] Add testnet network info to OrderValidator artifact
2018-08-24 16:06:10 -07:00
fragosti
ad161a973e Change all onTouchTap to onClick 2018-08-24 15:59:14 -07:00
fragosti
103e1aa250 Upgrade typescript version used by sra-spec 2018-08-24 15:45:43 -07:00
fragosti
641d86cb98 Add typescript dependency to typescript-typings (no idea how it was working) 2018-08-24 15:40:04 -07:00
fragosti
813b2ca1fb Bump react-highlight in react-shared once more 2018-08-24 15:29:22 -07:00
fragosti
ec96c3bb77 Upgrade react-shared used by website to one that depends on react 16 2018-08-24 15:15:55 -07:00
fragosti
65120e84e2 Upgrade react-highlight to version that depends on React 16 2018-08-24 15:11:14 -07:00
Amir Bandeali
82b51db17e Merge pull request #1015 from 0xProject/feature/contracts/removeCallerSigType
Remove SignatureType.Caller
2018-08-24 15:09:39 -07:00
fragosti
374ee2db32 Upgrade react in react-docs 2018-08-24 15:05:46 -07:00
Brandon Millman
3557cd93fc Add testnet network info to OrderValidator artifact 2018-08-24 14:42:07 -07:00
Amir Bandeali
0629a7d143 Remove remaining Trezor references 2018-08-24 14:40:00 -07:00
Greg Hysen
a27112cbef SignatureType.Trezor -> SignatureType.EthSign in Signature Validator tests 2018-08-24 14:40:00 -07:00
Greg Hysen
d039a1adda Fixed linter in signatureUtils 2018-08-24 14:40:00 -07:00
Greg Hysen
bb4d449e92 Test case for Trezor Model T signature 2018-08-24 14:40:00 -07:00
Greg Hysen
241534a63d Fixed trezor personal message in client+contracts; added a test using message signed by Trezor One (firmware v1.6.2) 2018-08-24 14:40:00 -07:00
Amir Bandeali
1932aff35c Remove Trezor SignatureType 2018-08-24 14:40:00 -07:00
Amir Bandeali
4f27991959 Remove SigntureType.Caller from signingUtils 2018-08-24 14:39:08 -07:00
Amir Bandeali
8ce4f9c784 Remove SignatureType.Caller 2018-08-24 14:39:08 -07:00
Amir Bandeali
7351bf0b14 Merge pull request #1012 from 0xProject/feature/contracts/staticcall
Use staticcall for external function calls in MixinSignatureValidator
2018-08-24 14:38:54 -07:00
fragosti
48ab151ec2 Update react and remove tap event plugin [deprecated] 2018-08-24 14:20:55 -07:00
Remco Bloemen
f6080367fe Disambiguate the operator precedence 2018-08-24 14:11:45 -07:00
Remco Bloemen
7f78d7da9d Add tests 2018-08-24 14:09:51 -07:00
Remco Bloemen
6734f2f1bc Add docs 2018-08-24 14:09:51 -07:00
Remco Bloemen
0fb7617a78 Fix incorect modulus 2018-08-24 14:09:51 -07:00
Remco Bloemen
4219af1430 Add DIVISION_BY_ZERO to getPartialAmount for consistency 2018-08-24 14:09:51 -07:00
Remco Bloemen
c109d1f545 Remove .only 2018-08-24 14:09:51 -07:00
Remco Bloemen
50fab9feb3 Improve getPartialAmountCeil docs 2018-08-24 14:09:51 -07:00
Remco Bloemen
3dad6ee55e Add tests for getPartialAmountCeil 2018-08-24 14:09:51 -07:00
Remco Bloemen
5d70df771b Add isRoundingErrorCeil 2018-08-24 14:09:50 -07:00
Remco Bloemen
ab5df342e1 Add getPartialAmountCeil 2018-08-24 14:09:50 -07:00
Amir Bandeali
6a9669a409 Rethrow Wallet and Validator errors 2018-08-24 14:06:46 -07:00
Remco Bloemen
e68942ee78 Handle zero case 2018-08-24 13:45:10 -07:00
Remco Bloemen
4159e45aff Update tests 2018-08-24 13:45:10 -07:00
Remco Bloemen
92497d7df4 Fix isRoundingError 2018-08-24 13:45:10 -07:00
fragosti
44a430802e Merge branch 'development' of https://github.com/0xProject/0x-monorepo into website/feature/react-16 2018-08-24 13:38:30 -07:00
Amir Bandeali
070eff6f3a Rename TestStaticCall => TestStaticCallReceiver 2018-08-24 13:32:04 -07:00
Amir Bandeali
681ed822ec Revert if undefined function called in AssetProxies 2018-08-24 13:19:07 -07:00
Amir Bandeali
0a1ae2c311 Remove pragma experimental v0.5.0 and use staticcall is assembly 2018-08-24 13:19:07 -07:00
Amir Bandeali
c5f8b9c2d2 Add pragma experimental v0.5.0 to SignatureValidator and add tests 2018-08-24 13:19:07 -07:00
fragosti
6b03cfd40d Add new react and types 2018-08-24 12:05:54 -07:00
Francesco Agosti
7f36574a57 Merge pull request #1011 from 0xProject/sra-api/rename/sra-spec
[sra-spec] Rename the sra-api package to sra-spec
2018-08-24 12:00:39 -07:00
fragosti
b637ca105a Merge branch 'development' of https://github.com/0xProject/0x-monorepo into sra-api/rename/sra-spec 2018-08-24 11:16:28 -07:00
fragosti
9ffddb47b8 Merge branch 'development' of https://github.com/0xProject/0x-monorepo into sra-api/rename/sra-spec 2018-08-24 11:14:34 -07:00
fragosti
7bcaac4e10 Ignore api.json in public 2018-08-24 11:11:56 -07:00
fragosti
d4592c0a60 Run prettier 2018-08-24 10:20:17 -07:00
fragosti
1d6699585e Add sra-spec to prettier ignore 2018-08-23 17:53:21 -07:00
fragosti
a75c298de0 Point to new s3 bucket 2018-08-23 17:31:11 -07:00
fragosti
d603d8da47 Rename sra-api to sra-spec 2018-08-23 17:30:20 -07:00
Alex Browne
a551d0a6dd fix: Use yarn version 1.9.4 on CI 2018-08-23 16:45:18 -07:00
412 changed files with 35946 additions and 110267 deletions

View File

@@ -18,11 +18,11 @@ jobs:
- yarn-packages-master
- yarn-packages-
- run:
name: yarn
command: yarn --frozen-lockfile install || true
name: install-yarn
command: sudo npm install --global yarn@1.9.4
- run:
name: yarn
command: yarn --frozen-lockfile install
command: yarn --frozen-lockfile install || yarn --frozen-lockfile install
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
@@ -254,4 +254,4 @@ workflows:
- build
- submit-coverage:
requires:
- test-rest
- test-rest

5
.gitignore vendored
View File

@@ -88,7 +88,7 @@ packages/0x.js/src/artifacts/
packages/order-utils/src/artifacts/
# unstable generated contract artifacts:
packages/migrations/artifacts/2.0.0/
packages/migrations/artifacts/development/
# generated contract watcher
packages/0x.js/src/generated_contract_wrappers/
@@ -99,8 +99,9 @@ packages/fill-scenarios/src/generated_contract_wrappers/
packages/order-watcher/src/generated_contract_wrappers/
packages/order-utils/src/generated_contract_wrappers/
packages/migrations/src/1.0.0/contract_wrappers
packages/migrations/src/2.0.0-testnet/contract_wrappers
packages/migrations/src/2.0.0/contract_wrappers
packages/migrations/src/2.0.0-beta-testnet/contract_wrappers
packages/migrations/src/development/contract_wrappers
# solc-bin in sol-compiler
packages/sol-compiler/solc_bin/

View File

@@ -8,18 +8,20 @@ lib
/packages/order-watcher/src/generated_contract_wrappers/
/packages/order-utils/src/generated_contract_wrappers/
/packages/migrations/src/1.0.0/contract_wrappers
/packages/migrations/src/2.0.0-testnet/contract_wrappers
/packages/migrations/src/2.0.0/contract_wrappers
/packages/migrations/src/2.0.0-beta-testnet/contract_wrappers
/packages/0x.js/src/artifacts
/packages/contracts/src/artifacts
/packages/contract-wrappers/src/artifacts
/packages/order-watcher/src/artifacts
/packages/metacoin/artifacts
/packages/sra-api/public/
/packages/sra-spec/public/
/packages/contract-wrappers/test/artifacts
/packages/order-watcher/test/artifacts
/packages/migrations/artifacts/1.0.0
/packages/migrations/artifacts/2.0.0-testnet
/packages/migrations/artifacts/2.0.0
/packages/migrations/artifacts/2.0.0-beta-testnet
/packages/migrations/artifacts/development
package.json
scripts/postpublish_utils.js
packages/sol-cov/test/fixtures/artifacts

View File

@@ -33,7 +33,7 @@ If you're developing on 0x now or are interested in using 0x infrastructure in t
| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts |
| [`@0xproject/react-docs`](/packages/react-docs) | [![npm](https://img.shields.io/npm/v/@0xproject/react-docs.svg)](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON |
| [`@0xproject/react-shared`](/packages/react-shared) | [![npm](https://img.shields.io/npm/v/@0xproject/react-shared.svg)](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components |
| [`@0xproject/sra-api`](/packages/sra-api) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-api.svg)](https://www.npmjs.com/package/@0xproject/sra-api) | OpenAPI specification for the standard relayer API |
| [`@0xproject/sra-spec`](/packages/sra-spec) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-spec.svg)](https://www.npmjs.com/package/@0xproject/sra-spec) | OpenAPI specification for the standard relayer API |
| [`@0xproject/sra-report`](/packages/sra-report) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-report.svg)](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance |
| [`@0xproject/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-cov.svg)](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool |
| [`@0xproject/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0xproject/subproviders.svg)](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) |

View File

@@ -23,10 +23,11 @@
"install:all": "yarn install",
"wsrun": "wsrun",
"lerna": "lerna",
"watch": "wsrun watch_without_deps $PKG --fast-exit -r --stages --done-criteria='complete|successfully'",
"build": "wsrun build $PKG --fast-exit -r --stages",
"build:no_website": "wsrun build $PKG --fast-exit -r --stages --exclude @0xproject/website",
"build:monorepo_scripts": "PKG=@0xproject/monorepo-scripts yarn build",
"build:ts": "tsc -b",
"watch:ts": "tsc -b -w",
"clean": "wsrun clean $PKG --fast-exit -r --parallel",
"remove_node_modules": "lerna clean --yes; rm -rf node_modules",
"rebuild": "run-s clean build",
@@ -51,6 +52,7 @@
"npm-run-all": "^4.1.2",
"prettier": "^1.11.1",
"source-map-support": "^0.5.6",
"typescript": "3.0.1",
"wsrun": "^2.2.0"
},
"resolutions": {

View File

@@ -1,4 +1,31 @@
[
{
"timestamp": 1536142250,
"version": "1.0.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "1.0.1-rc.6",
"changes": [
{
"note": "Fix missing `BlockParamLiteral` type import issue"
}
],
"timestamp": 1535377027
},
{
"version": "1.0.1-rc.5",
"changes": [
{
"note":
"Fix `main` and `types` package.json entries so that they point to the new location of index.d.ts and index.js"
}
]
},
{
"version": "1.0.1-rc.4",
"changes": [

View File

@@ -5,6 +5,18 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.0.1 - _September 5, 2018_
* Dependencies updated
## v1.0.1-rc.6 - _August 27, 2018_
* Fix missing `BlockParamLiteral` type import issue
## v1.0.1-rc.5 - _Invalid date_
* Fix `main` and `types` package.json entries so that they point to the new location of index.d.ts and index.js
## v1.0.1-rc.4 - _August 24, 2018_
* Re-organize the exported interface of 0x.js. Remove the `ZeroEx` class, and instead export the same exports as `0x.js`'s sub-packages: `@0xproject/contract-wrappers`, `@0xproject/order-utils` and `@0xproject/order-watcher` (#963)

View File

@@ -1,6 +1,6 @@
{
"name": "0x.js",
"version": "1.0.1-rc.4",
"version": "1.0.1",
"engines": {
"node": ">=6.12"
},
@@ -12,10 +12,9 @@
"tokens",
"exchange"
],
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"watch_without_deps": "tsc -w",
"build": "yarn build:all",
"build:all": "run-p build:umd:prod build:commonjs",
"lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*",
@@ -25,8 +24,8 @@
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf _bundles lib test_temp src/generated_contract_wrappers generated_docs",
"build:umd:prod": "NODE_ENV=production webpack",
"build:commonjs": "tsc",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES"
"build:commonjs": "tsc -b",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
@@ -42,15 +41,16 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@0xproject/abi-gen": "^1.0.6",
"@0xproject/dev-utils": "^1.0.5",
"@0xproject/migrations": "^1.0.5",
"@0xproject/monorepo-scripts": "^1.0.6",
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/abi-gen": "^1.0.8",
"@0xproject/dev-utils": "^1.0.7",
"@0xproject/migrations": "^1.0.7",
"@0xproject/monorepo-scripts": "^1.0.8",
"@0xproject/tslint-config": "^1.0.7",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"@types/node": "^8.0.53",
"@types/sinon": "^2.2.2",
"@types/web3-provider-engine": "^14.0.0",
"awesome-typescript-loader": "^3.1.3",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
@@ -73,17 +73,17 @@
"webpack": "^3.1.0"
},
"dependencies": {
"@0xproject/assert": "^1.0.6",
"@0xproject/base-contract": "^2.0.0",
"@0xproject/contract-wrappers": "^1.0.1-rc.4",
"@0xproject/order-utils": "^1.0.1-rc.4",
"@0xproject/order-watcher": "^1.0.1-rc.4",
"@0xproject/subproviders": "^2.0.0",
"@0xproject/types": "^1.0.1-rc.5",
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/web3-wrapper": "^2.0.0",
"ethereum-types": "^1.0.5",
"@0xproject/assert": "^1.0.8",
"@0xproject/base-contract": "^2.0.2",
"@0xproject/contract-wrappers": "^1.0.1",
"@0xproject/order-utils": "^1.0.1",
"@0xproject/order-watcher": "^1.0.1",
"@0xproject/subproviders": "^2.0.2",
"@0xproject/types": "^1.0.1",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"@0xproject/web3-wrapper": "^2.0.2",
"ethereum-types": "^1.0.6",
"ethers": "3.0.22",
"lodash": "^4.17.5",
"web3-provider-engine": "14.0.6"

View File

@@ -9,6 +9,7 @@ export {
ERC20ProxyWrapper,
ERC721ProxyWrapper,
ForwarderWrapper,
OrderValidatorWrapper,
IndexedFilterValues,
BlockRange,
ContractWrappersConfig,
@@ -42,6 +43,10 @@ export {
DecodedLogEvent,
ExchangeEventArgs,
TransactionEncoder,
BalanceAndAllowance,
OrderAndTraderInfo,
TraderInfo,
ValidateOrderFillableOpts,
} from '@0xproject/contract-wrappers';
export { OrderWatcher, OnOrderStateChangeCallback, OrderWatcherConfig } from '@0xproject/order-watcher';

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "src"
},
"include": ["./src/**/*", "./test/**/*"]
"include": ["./src/**/*"]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -47,8 +47,13 @@ module.exports = {
use: [
{
loader: 'awesome-typescript-loader',
// tsconfig.json contains some options required for
// project references which do not work with webback.
// We override those options here.
query: {
declaration: false,
declarationMap: false,
composite: false,
},
},
],

View File

@@ -1,4 +1,22 @@
[
{
"timestamp": 1536142250,
"version": "1.0.8",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535377027,
"version": "1.0.7",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535133899,
"version": "1.0.6",

View File

@@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.0.8 - _September 5, 2018_
* Dependencies updated
## v1.0.7 - _August 27, 2018_
* Dependencies updated
## v1.0.6 - _August 24, 2018_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/abi-gen",
"version": "1.0.6",
"version": "1.0.8",
"engines": {
"node": ">=6.12"
},
@@ -8,10 +8,9 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"watch_without_deps": "tsc -w",
"lint": "tslint --project .",
"clean": "shx rm -rf lib",
"build": "tsc",
"build": "tsc -b",
"test": "yarn run_mocha",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit",
"test:circleci": "yarn test:coverage",
@@ -31,10 +30,10 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md",
"dependencies": {
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"chalk": "^2.3.0",
"ethereum-types": "^1.0.5",
"ethereum-types": "^1.0.6",
"glob": "^7.1.2",
"handlebars": "^4.0.11",
"lodash": "^4.17.5",
@@ -45,7 +44,7 @@
"yargs": "^10.0.3"
},
"devDependencies": {
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/tslint-config": "^1.0.7",
"@types/glob": "5.0.35",
"@types/handlebars": "^4.0.36",
"@types/mkdirp": "^0.5.1",

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -1,4 +1,22 @@
[
{
"timestamp": 1536142250,
"version": "1.0.8",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535377027,
"version": "1.0.7",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535133899,
"version": "1.0.6",

View File

@@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.0.8 - _September 5, 2018_
* Dependencies updated
## v1.0.7 - _August 27, 2018_
* Dependencies updated
## v1.0.6 - _August 24, 2018_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/assert",
"version": "1.0.6",
"version": "1.0.8",
"engines": {
"node": ">=6.12"
},
@@ -8,8 +8,7 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"watch_without_deps": "tsc -w",
"build": "tsc",
"build": "tsc -b",
"clean": "shx rm -rf lib test_temp",
"lint": "tslint --project .",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --exit",
@@ -29,7 +28,7 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/assert/README.md",
"devDependencies": {
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/tslint-config": "^1.0.7",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"@types/valid-url": "^1.0.2",
@@ -45,9 +44,9 @@
"typescript": "3.0.1"
},
"dependencies": {
"@0xproject/json-schemas": "^1.0.1-rc.5",
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/json-schemas": "^1.0.1",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"lodash": "^4.17.5",
"valid-url": "^1.0.9"
},

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -1,4 +1,22 @@
[
{
"timestamp": 1536142250,
"version": "2.0.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535377027,
"version": "2.0.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1535133899,
"version": "2.0.0",

View File

@@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v2.0.2 - _September 5, 2018_
* Dependencies updated
## v2.0.1 - _August 27, 2018_
* Dependencies updated
## v2.0.0 - _August 24, 2018_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/base-contract",
"version": "2.0.0",
"version": "2.0.2",
"engines": {
"node": ">=6.12"
},
@@ -8,8 +8,7 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"watch_without_deps": "tsc -w",
"build": "tsc",
"build": "tsc -b",
"clean": "shx rm -rf lib",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s clean build test",
@@ -29,7 +28,7 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md",
"devDependencies": {
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/tslint-config": "^1.0.7",
"@types/lodash": "4.14.104",
"chai": "^4.0.1",
"copyfiles": "^2.0.0",
@@ -41,10 +40,10 @@
"typescript": "3.0.1"
},
"dependencies": {
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/web3-wrapper": "^2.0.0",
"ethereum-types": "^1.0.5",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"@0xproject/web3-wrapper": "^2.0.2",
"ethereum-types": "^1.0.6",
"ethers": "3.0.22",
"lodash": "^4.17.5"
},

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "."
},
"include": ["src/**/*", "test/**/*"]
}

View File

@@ -1,4 +1,23 @@
[
{
"version": "2.0.0",
"changes": [
{
"note": "Change `OrderConfigRequest` to use BigNumber instead of string for relevant fields.",
"pr": 1058
}
],
"timestamp": 1536142250
},
{
"version": "2.0.0-rc.2",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1535377027
},
{
"version": "2.0.0-rc.1",
"changes": [

View File

@@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v2.0.0 - _September 5, 2018_
* Change `OrderConfigRequest` to use BigNumber instead of string for relevant fields. (#1058)
## v2.0.0-rc.2 - _August 27, 2018_
* Dependencies updated
## v2.0.0-rc.1 - _August 24, 2018_
* Updated for SRA v2 (#974)

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/connect",
"version": "2.0.0-rc.1",
"version": "2.0.0",
"engines": {
"node": ">=6.12"
},
@@ -15,8 +15,7 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"watch_without_deps": "tsc -w",
"build": "tsc",
"build": "tsc -b",
"clean": "shx rm -rf lib test_temp generated_docs",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"lint": "tslint --project .",
@@ -26,7 +25,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"test:circleci": "yarn test:coverage",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES"
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
@@ -44,11 +43,12 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md",
"dependencies": {
"@0xproject/assert": "^1.0.6",
"@0xproject/json-schemas": "^1.0.1-rc.5",
"@0xproject/types": "^1.0.1-rc.5",
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/assert": "^1.0.8",
"@0xproject/json-schemas": "^1.0.1",
"@0xproject/order-utils": "^1.0.1",
"@0xproject/types": "^1.0.1",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"lodash": "^4.17.5",
"query-string": "^5.0.1",
"sinon": "^4.0.0",
@@ -56,7 +56,7 @@
"websocket": "^1.0.25"
},
"devDependencies": {
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/tslint-config": "^1.0.7",
"@types/fetch-mock": "^6.0.3",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",

View File

@@ -151,7 +151,7 @@ export class HttpClient implements Client {
params: requestOpts,
payload: request,
};
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Get, httpRequestOpts);
const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson);
return fees;
}

View File

@@ -126,12 +126,12 @@ export interface PaginatedCollection<T> {
export interface OrderConfigRequest {
makerAddress: string;
takerAddress: string;
makerAssetAmount: string;
takerAssetAmount: string;
makerAssetAmount: BigNumber;
takerAssetAmount: BigNumber;
makerAssetData: string;
takerAssetData: string;
exchangeAddress: string;
expirationTimeSeconds: string;
expirationTimeSeconds: BigNumber;
}
export interface OrderConfigResponse {

View File

@@ -1,5 +1,6 @@
import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import { orderParsingUtils } from '@0xproject/order-utils';
import {
APIOrder,
@@ -19,7 +20,7 @@ export const relayerResponseJsonParsers = {
},
parseAssetPairsItemsJson(json: any): AssetPairsItem[] {
return json.map((assetDataPair: any) => {
return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [
return orderParsingUtils.convertStringsFieldsToBigNumbers(assetDataPair, [
'assetDataA.minAmount',
'assetDataA.maxAmount',
'assetDataB.minAmount',
@@ -44,6 +45,6 @@ export const relayerResponseJsonParsers = {
},
parseOrderConfigResponseJson(json: any): OrderConfigResponse {
assert.doesConformToSchema('orderConfigResponse', json, schemas.relayerApiOrderConfigResponseSchema);
return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']);
return orderParsingUtils.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']);
},
};

View File

@@ -1,4 +1,4 @@
import { BigNumber } from '@0xproject/utils';
import { orderParsingUtils } from '@0xproject/order-utils';
import * as _ from 'lodash';
import { APIOrder } from '../types';
@@ -21,28 +21,6 @@ export const typeConverters = {
};
},
convertAPIOrderStringFieldsToBigNumber(apiOrder: any): APIOrder {
return { ...apiOrder, order: typeConverters.convertOrderStringFieldsToBigNumber(apiOrder.order) };
},
convertOrderStringFieldsToBigNumber(order: any): any {
return typeConverters.convertStringsFieldsToBigNumbers(order, [
'makerAssetAmount',
'takerAssetAmount',
'makerFee',
'takerFee',
'expirationTimeSeconds',
'salt',
]);
},
convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any {
const result = _.assign({}, obj);
_.each(fields, field => {
_.update(result, field, (value: string) => {
if (_.isUndefined(value)) {
throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`);
}
return new BigNumber(value);
});
});
return result;
return { ...apiOrder, order: orderParsingUtils.convertOrderStringFieldsToBigNumber(apiOrder.order) };
},
};

View File

@@ -1,3 +1,4 @@
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as dirtyChai from 'dirty-chai';
@@ -138,21 +139,21 @@ describe('HttpClient', () => {
const request = {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
expirationTimeSeconds: '1532560590',
makerAssetAmount: new BigNumber('10000000000000000'),
takerAssetAmount: new BigNumber('20000000000000000'),
expirationTimeSeconds: new BigNumber('1532560590'),
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
};
const url = `${relayUrl}/order_config`;
it('gets order config', async () => {
fetchMock.post(url, orderConfigResponseJSON);
fetchMock.get(url, orderConfigResponseJSON);
const fees = await relayerClient.getOrderConfigAsync(request);
expect(fees).to.be.deep.equal(orderConfigResponse);
});
it('does not mutate input', async () => {
fetchMock.post(url, orderConfigResponseJSON);
fetchMock.get(url, orderConfigResponseJSON);
const makerAssetAmountBefore = request.makerAssetAmount;
const takerAssetAmountBefore = request.takerAssetAmount;
const expirationTimeSecondsBefore = request.expirationTimeSeconds;
@@ -162,7 +163,7 @@ describe('HttpClient', () => {
expect(expirationTimeSecondsBefore).to.be.deep.equal(request.expirationTimeSeconds);
});
it('throws an error for invalid JSON response', async () => {
fetchMock.post(url, { test: 'dummy' });
fetchMock.get(url, { test: 'dummy' });
expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected();
});
});

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -1,4 +1,37 @@
[
{
"version": "1.0.1",
"changes": [
{
"note": "Add `OrderValidatorWrapper`"
},
{
"note":
"Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK`",
"pr": 1044
},
{
"note":
"Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations",
"pr": 1054
},
{
"note":
"Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper",
"pr": 1054
}
],
"timestamp": 1536142250
},
{
"version": "1.0.1-rc.5",
"changes": [
{
"note": "Fix missing `BlockParamLiteral` type import issue"
}
],
"timestamp": 1535377027
},
{
"version": "1.0.1-rc.4",
"changes": [

View File

@@ -5,6 +5,17 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.0.1 - _September 5, 2018_
* Add `OrderValidatorWrapper`
* Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK` (#1044)
* Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations (#1054)
* Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper (#1054)
## v1.0.1-rc.5 - _August 27, 2018_
* Fix missing `BlockParamLiteral` type import issue
## v1.0.1-rc.4 - _August 24, 2018_
* Export missing types: `TransactionEncoder`, `ContractAbi`, `JSONRPCRequestPayload`, `JSONRPCResponsePayload`, `JSONRPCErrorCallback`, `AbiDefinition`, `FunctionAbi`, `EventAbi`, `EventParameter`, `DecodedLogArgs`, `MethodAbi`, `ConstructorAbi`, `FallbackAbi`, `DataItem`, `ConstructorStateMutability`, `StateMutability` & `ExchangeSignatureValidatorApprovalEventArgs` (#924)

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/contract-wrappers",
"version": "1.0.1-rc.4",
"version": "1.0.1",
"description": "Smart TS wrappers for 0x smart contracts",
"keywords": [
"0xproject",
@@ -11,26 +11,23 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"watch_without_deps": "yarn pre_build && tsc -w",
"build": "yarn pre_build && tsc",
"pre_build": "run-s update_artifacts_v2_beta update_artifacts_v2 generate_contract_wrappers copy_artifacts",
"generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token|ZRXToken|ERC20Token|ERC721Token|WETH9|ERC20Proxy|ERC721Proxy|Forwarder).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers",
"build": "yarn pre_build && tsc -b",
"pre_build": "run-s update_artifacts generate_contract_wrappers copy_artifacts",
"generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token|ZRXToken|ERC20Token|ERC721Token|WETH9|ERC20Proxy|ERC721Proxy|Forwarder|OrderValidator).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers",
"lint": "tslint --project . --exclude **/src/contract_wrappers/**/* --exclude **/lib/**/*",
"test:circleci": "run-s test:coverage",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"update_artifacts_v2_beta": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json src/artifacts; done;",
"update_artifacts_v2": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;",
"update_artifacts": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;",
"copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts",
"clean": "shx rm -rf _bundles lib test_temp test/artifacts src/contract_wrappers/generated src/artifacts generated_docs",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES"
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"contracts_v2_beta": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator",
"contracts_v2": "DummyERC20Token DummyERC721Token",
"contracts_v2": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator DummyERC20Token DummyERC721Token",
"postpublish": {
"assets": []
}
@@ -44,16 +41,17 @@
"node": ">=6.0.0"
},
"devDependencies": {
"@0xproject/abi-gen": "^1.0.6",
"@0xproject/dev-utils": "^1.0.5",
"@0xproject/migrations": "^1.0.5",
"@0xproject/subproviders": "^2.0.0",
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/abi-gen": "^1.0.8",
"@0xproject/dev-utils": "^1.0.7",
"@0xproject/migrations": "^1.0.7",
"@0xproject/subproviders": "^2.0.2",
"@0xproject/tslint-config": "^1.0.7",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"@types/node": "^8.0.53",
"@types/sinon": "^2.2.2",
"@types/uuid": "^3.4.2",
"@types/web3-provider-engine": "^14.0.0",
"awesome-typescript-loader": "^3.1.3",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
@@ -74,16 +72,16 @@
"web3-provider-engine": "14.0.6"
},
"dependencies": {
"@0xproject/assert": "^1.0.6",
"@0xproject/base-contract": "^2.0.0",
"@0xproject/fill-scenarios": "^1.0.1-rc.4",
"@0xproject/json-schemas": "^1.0.1-rc.5",
"@0xproject/order-utils": "^1.0.1-rc.4",
"@0xproject/types": "^1.0.1-rc.5",
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/web3-wrapper": "^2.0.0",
"ethereum-types": "^1.0.5",
"@0xproject/assert": "^1.0.8",
"@0xproject/base-contract": "^2.0.2",
"@0xproject/fill-scenarios": "^1.0.1",
"@0xproject/json-schemas": "^1.0.1",
"@0xproject/order-utils": "^1.0.1",
"@0xproject/types": "^1.0.1",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"@0xproject/web3-wrapper": "^2.0.2",
"ethereum-types": "^1.0.6",
"ethereumjs-blockstream": "5.0.0",
"ethereumjs-util": "^5.1.1",
"ethers": "3.0.22",

View File

@@ -8,6 +8,7 @@ import * as ERC721Proxy from './artifacts/ERC721Proxy.json';
import * as ERC721Token from './artifacts/ERC721Token.json';
import * as Exchange from './artifacts/Exchange.json';
import * as Forwarder from './artifacts/Forwarder.json';
import * as OrderValidator from './artifacts/OrderValidator.json';
import * as EtherToken from './artifacts/WETH9.json';
import * as ZRXToken from './artifacts/ZRXToken.json';
@@ -22,4 +23,5 @@ export const artifacts = {
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
};

View File

@@ -12,6 +12,7 @@ import { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper';
import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper';
import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper';
import { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper';
import { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper';
import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema';
import { contractWrappersPrivateNetworkConfigSchema } from './schemas/contract_wrappers_private_network_config_schema';
import { contractWrappersPublicNetworkConfigSchema } from './schemas/contract_wrappers_public_network_config_schema';
@@ -52,6 +53,10 @@ export class ContractWrappers {
* An instance of the ForwarderWrapper class containing methods for interacting with any Forwarder smart contract.
*/
public forwarder: ForwarderWrapper;
/**
* An instance of the OrderValidatorWrapper class containing methods for interacting with any OrderValidator smart contract.
*/
public orderValidator: OrderValidatorWrapper;
private _web3Wrapper: Web3Wrapper;
/**
@@ -106,6 +111,8 @@ export class ContractWrappers {
this.exchange = new ExchangeWrapper(
this._web3Wrapper,
config.networkId,
this.erc20Token,
this.erc721Token,
config.exchangeContractAddress,
config.zrxContractAddress,
blockPollingIntervalMs,
@@ -116,6 +123,7 @@ export class ContractWrappers {
config.forwarderContractAddress,
config.zrxContractAddress,
);
this.orderValidator = new OrderValidatorWrapper(this._web3Wrapper, config.networkId);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all

View File

@@ -1,7 +1,14 @@
import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractArtifact } from 'ethereum-types';
import { BlockParamLiteral, ContractAbi, FilterObject, LogEntry, LogWithDecodedArgs, RawLog } from 'ethereum-types';
import {
BlockParamLiteral,
ContractAbi,
ContractArtifact,
FilterObject,
LogEntry,
LogWithDecodedArgs,
RawLog,
} from 'ethereum-types';
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
import * as _ from 'lodash';
@@ -138,9 +145,12 @@ export abstract class ContractWrapper {
}
protected _getContractAddress(artifact: ContractArtifact, addressIfExists?: string): string {
if (_.isUndefined(addressIfExists)) {
if (_.isUndefined(artifact.networks[this._networkId])) {
throw new Error(ContractWrappersError.ContractNotDeployedOnNetwork);
}
const contractAddress = artifact.networks[this._networkId].address;
if (_.isUndefined(contractAddress)) {
throw new Error(ContractWrappersError.ExchangeContractDoesNotExist);
throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contractName]);
}
return contractAddress;
} else {

View File

@@ -1,12 +1,19 @@
import { schemas } from '@0xproject/json-schemas';
import { assetDataUtils } from '@0xproject/order-utils';
import {
assetDataUtils,
BalanceAndProxyAllowanceLazyStore,
ExchangeTransferSimulator,
OrderValidationUtils,
} from '@0xproject/order-utils';
import { AssetProxyId, Order, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types';
import { BlockParamLiteral, ContractAbi, LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { AssetBalanceAndProxyAllowanceFetcher } from '../fetchers/asset_balance_and_proxy_allowance_fetcher';
import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { methodOptsSchema } from '../schemas/method_opts_schema';
import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema';
import { txOptsSchema } from '../schemas/tx_opts_schema';
@@ -17,13 +24,17 @@ import {
IndexedFilterValues,
MethodOpts,
OrderInfo,
OrderStatus,
OrderTransactionOpts,
ValidateOrderFillableOpts,
} from '../types';
import { assert } from '../utils/assert';
import { decorators } from '../utils/decorators';
import { TransactionEncoder } from '../utils/transaction_encoder';
import { ContractWrapper } from './contract_wrapper';
import { ERC20TokenWrapper } from './erc20_token_wrapper';
import { ERC721TokenWrapper } from './erc721_token_wrapper';
import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange';
/**
@@ -33,6 +44,8 @@ import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated
export class ExchangeWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.Exchange.compilerOutput.abi;
private _exchangeContractIfExists?: ExchangeContract;
private _erc721TokenWrapper: ERC721TokenWrapper;
private _erc20TokenWrapper: ERC20TokenWrapper;
private _contractAddressIfExists?: string;
private _zrxContractAddressIfExists?: string;
/**
@@ -48,11 +61,15 @@ export class ExchangeWrapper extends ContractWrapper {
constructor(
web3Wrapper: Web3Wrapper,
networkId: number,
erc20TokenWrapper: ERC20TokenWrapper,
erc721TokenWrapper: ERC721TokenWrapper,
contractAddressIfExists?: string,
zrxContractAddressIfExists?: string,
blockPollingIntervalMs?: number,
) {
super(web3Wrapper, networkId, blockPollingIntervalMs);
this._erc20TokenWrapper = erc20TokenWrapper;
this._erc721TokenWrapper = erc721TokenWrapper;
this._contractAddressIfExists = contractAddressIfExists;
this._zrxContractAddressIfExists = zrxContractAddressIfExists;
}
@@ -1084,6 +1101,64 @@ export class ExchangeWrapper extends ContractWrapper {
);
return logs;
}
/**
* Validate if the supplied order is fillable, and throw if it isn't
* @param signedOrder SignedOrder of interest
* @param opts ValidateOrderFillableOpts options (e.g expectedFillTakerTokenAmount.
* If it isn't supplied, we check if the order is fillable for a non-zero amount)
*/
public async validateOrderFillableOrThrowAsync(
signedOrder: SignedOrder,
opts: ValidateOrderFillableOpts = {},
): Promise<void> {
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
BlockParamLiteral.Latest,
);
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const expectedFillTakerTokenAmountIfExists = opts.expectedFillTakerTokenAmount;
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
await orderValidationUtils.validateOrderFillableOrThrowAsync(
exchangeTradeSimulator,
signedOrder,
this.getZRXAssetData(),
expectedFillTakerTokenAmountIfExists,
);
}
/**
* Validate a call to FillOrder and throw if it wouldn't succeed
* @param signedOrder SignedOrder of interest
* @param fillTakerAssetAmount Amount we'd like to fill the order for
* @param takerAddress The taker of the order
*/
public async validateFillOrderThrowIfInvalidAsync(
signedOrder: SignedOrder,
fillTakerAssetAmount: BigNumber,
takerAddress: string,
): Promise<void> {
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
BlockParamLiteral.Latest,
);
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeSimulator,
this._web3Wrapper.getProvider(),
signedOrder,
fillTakerAssetAmount,
takerAddress,
this.getZRXAssetData(),
);
}
/**
* Retrieves the Ethereum address of the Exchange contract deployed on the network
* that the user-passed web3 provider is connected to.

View File

@@ -0,0 +1,187 @@
import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractAbi } from 'ethereum-types';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { BalanceAndAllowance, OrderAndTraderInfo, TraderInfo } from '../types';
import { assert } from '../utils/assert';
import { ContractWrapper } from './contract_wrapper';
import { OrderValidatorContract } from './generated/order_validator';
/**
* This class includes the functionality related to interacting with the OrderValidator contract.
*/
export class OrderValidatorWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.OrderValidator.compilerOutput.abi;
private _orderValidatorContractIfExists?: OrderValidatorContract;
/**
* Instantiate OrderValidatorWrapper
* @param web3Wrapper Web3Wrapper instance to use
* @param networkId Desired networkId
*/
constructor(web3Wrapper: Web3Wrapper, networkId: number) {
super(web3Wrapper, networkId);
}
/**
* Get an object conforming to OrderAndTraderInfo containing on-chain information of the provided order and address
* @param order An object conforming to SignedOrder
* @param takerAddress An ethereum address
* @return OrderAndTraderInfo
*/
public async getOrderAndTraderInfoAsync(order: SignedOrder, takerAddress: string): Promise<OrderAndTraderInfo> {
assert.doesConformToSchema('order', order, schemas.signedOrderSchema);
assert.isETHAddressHex('takerAddress', takerAddress);
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const orderAndTraderInfo = await OrderValidatorContractInstance.getOrderAndTraderInfo.callAsync(
order,
takerAddress,
);
const result = {
orderInfo: orderAndTraderInfo[0],
traderInfo: orderAndTraderInfo[1],
};
return result;
}
/**
* Get an array of objects conforming to OrderAndTraderInfo containing on-chain information of the provided orders and addresses
* @param orders An array of objects conforming to SignedOrder
* @param takerAddresses An array of ethereum addresses
* @return array of OrderAndTraderInfo
*/
public async getOrdersAndTradersInfoAsync(
orders: SignedOrder[],
takerAddresses: string[],
): Promise<OrderAndTraderInfo[]> {
assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
_.forEach(takerAddresses, (takerAddress, index) =>
assert.isETHAddressHex(`takerAddresses[${index}]`, takerAddress),
);
assert.assert(orders.length === takerAddresses.length, 'Expected orders.length to equal takerAddresses.length');
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const ordersAndTradersInfo = await OrderValidatorContractInstance.getOrdersAndTradersInfo.callAsync(
orders,
takerAddresses,
);
const orderInfos = ordersAndTradersInfo[0];
const traderInfos = ordersAndTradersInfo[1];
const result = _.map(orderInfos, (orderInfo, index) => {
const traderInfo = traderInfos[index];
return {
orderInfo,
traderInfo,
};
});
return result;
}
/**
* Get an object conforming to TraderInfo containing on-chain balance and allowances for maker and taker of order
* @param order An object conforming to SignedOrder
* @param takerAddress An ethereum address
* @return TraderInfo
*/
public async getTraderInfoAsync(order: SignedOrder, takerAddress: string): Promise<TraderInfo> {
assert.doesConformToSchema('order', order, schemas.signedOrderSchema);
assert.isETHAddressHex('takerAddress', takerAddress);
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const result = await OrderValidatorContractInstance.getTraderInfo.callAsync(order, takerAddress);
return result;
}
/**
* Get an array of objects conforming to TraderInfo containing on-chain balance and allowances for maker and taker of order
* @param orders An array of objects conforming to SignedOrder
* @param takerAddresses An array of ethereum addresses
* @return array of TraderInfo
*/
public async getTradersInfoAsync(orders: SignedOrder[], takerAddresses: string[]): Promise<TraderInfo[]> {
assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
_.forEach(takerAddresses, (takerAddress, index) =>
assert.isETHAddressHex(`takerAddresses[${index}]`, takerAddress),
);
assert.assert(orders.length === takerAddresses.length, 'Expected orders.length to equal takerAddresses.length');
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const result = await OrderValidatorContractInstance.getTradersInfo.callAsync(orders, takerAddresses);
return result;
}
/**
* Get an object conforming to BalanceAndAllowance containing on-chain balance and allowance for some address and assetData
* @param address An ethereum address
* @param assetData An encoded string that can be decoded by a specified proxy contract
* @return BalanceAndAllowance
*/
public async getBalanceAndAllowanceAsync(address: string, assetData: string): Promise<BalanceAndAllowance> {
assert.isETHAddressHex('address', address);
assert.isHexString('assetData', assetData);
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const balanceAndAllowance = await OrderValidatorContractInstance.getBalanceAndAllowance.callAsync(
address,
assetData,
);
const result = {
balance: balanceAndAllowance[0],
allowance: balanceAndAllowance[1],
};
return result;
}
/**
* Get an array of objects conforming to BalanceAndAllowance containing on-chain balance and allowance for some address and array of assetDatas
* @param address An ethereum address
* @param assetDatas An array of encoded strings that can be decoded by a specified proxy contract
* @return BalanceAndAllowance
*/
public async getBalancesAndAllowancesAsync(address: string, assetDatas: string[]): Promise<BalanceAndAllowance[]> {
assert.isETHAddressHex('address', address);
_.forEach(assetDatas, (assetData, index) => assert.isHexString(`assetDatas[${index}]`, assetData));
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const balancesAndAllowances = await OrderValidatorContractInstance.getBalancesAndAllowances.callAsync(
address,
assetDatas,
);
const balances = balancesAndAllowances[0];
const allowances = balancesAndAllowances[1];
const result = _.map(balances, (balance, index) => {
const allowance = allowances[index];
return {
balance,
allowance,
};
});
return result;
}
/**
* Get owner address of tokenId by calling `token.ownerOf(tokenId)`, but returns a null owner instead of reverting on an unowned token.
* @param tokenAddress An ethereum address
* @param tokenId An ERC721 tokenId
* @return Owner of tokenId or null address if unowned
*/
public async getERC721TokenOwnerAsync(tokenAddress: string, tokenId: BigNumber): Promise<string | undefined> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('tokenId', tokenId);
const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync();
const result = await OrderValidatorContractInstance.getERC721TokenOwner.callAsync(tokenAddress, tokenId);
return result;
}
// HACK: We don't want this method to be visible to the other units within that package but not to the end user.
// TS doesn't give that possibility and therefore we make it private and access it over an any cast. Because of that tslint sees it as unused.
// tslint:disable-next-line:no-unused-variable
private _invalidateContractInstance(): void {
delete this._orderValidatorContractIfExists;
}
private async _getOrderValidatorContractAsync(): Promise<OrderValidatorContract> {
if (!_.isUndefined(this._orderValidatorContractIfExists)) {
return this._orderValidatorContractIfExists;
}
const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(artifacts.OrderValidator);
const contractInstance = new OrderValidatorContract(
abi,
address,
this._web3Wrapper.getProvider(),
this._web3Wrapper.getContractDefaults(),
);
this._orderValidatorContractIfExists = contractInstance;
return this._orderValidatorContractIfExists;
}
}

View File

@@ -1,8 +1,11 @@
// tslint:disable:no-unnecessary-type-assertion
import { BlockParamLiteral, ERC20TokenWrapper, ERC721TokenWrapper } from '@0xproject/contract-wrappers';
import { AbstractBalanceAndProxyAllowanceFetcher, assetDataUtils } from '@0xproject/order-utils';
import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { BlockParamLiteral } from 'ethereum-types';
import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper';
import { ERC721TokenWrapper } from '../contract_wrappers/erc721_token_wrapper';
export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndProxyAllowanceFetcher {
private readonly _erc20Token: ERC20TokenWrapper;

View File

@@ -1,7 +1,10 @@
// tslint:disable:no-unnecessary-type-assertion
import { BlockParamLiteral, ExchangeWrapper } from '@0xproject/contract-wrappers';
import { AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';
import { BlockParamLiteral } from 'ethereum-types';
import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
export class OrderFilledCancelledFetcher implements AbstractOrderFilledCancelledFetcher {
private readonly _exchange: ExchangeWrapper;

View File

@@ -6,6 +6,7 @@ export { ExchangeWrapper } from './contract_wrappers/exchange_wrapper';
export { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper';
export { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper';
export { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper';
export { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper';
export { TransactionEncoder } from './utils/transaction_encoder';
@@ -21,6 +22,10 @@ export {
OrderInfo,
EventCallback,
DecodedLogEvent,
BalanceAndAllowance,
OrderAndTraderInfo,
TraderInfo,
ValidateOrderFillableOpts,
} from './types';
export { Order, SignedOrder, AssetProxyId } from '@0xproject/types';
@@ -81,3 +86,8 @@ export {
ExchangeEventArgs,
ExchangeEvents,
} from './contract_wrappers/generated/exchange';
export { AbstractBalanceAndProxyAllowanceFetcher, AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils';
export { AssetBalanceAndProxyAllowanceFetcher } from './fetchers/asset_balance_and_proxy_allowance_fetcher';
export { OrderFilledCancelledFetcher } from './fetchers/order_filled_cancelled_fetcher';

View File

@@ -188,3 +188,24 @@ export enum OrderStatus {
FULLY_FILLED,
CANCELLED,
}
export interface TraderInfo {
makerBalance: BigNumber;
makerAllowance: BigNumber;
takerBalance: BigNumber;
takerAllowance: BigNumber;
makerZrxBalance: BigNumber;
makerZrxAllowance: BigNumber;
takerZrxBalance: BigNumber;
takerZrxAllowance: BigNumber;
}
export interface OrderAndTraderInfo {
orderInfo: OrderInfo;
traderInfo: TraderInfo;
}
export interface BalanceAndAllowance {
balance: BigNumber;
allowance: BigNumber;
}

View File

@@ -358,7 +358,7 @@ describe('ExchangeWrapper', () => {
describe('#getVersionAsync', () => {
it('should return version the hash', async () => {
const version = await contractWrappers.exchange.getVersionAsync();
const VERSION = '2.0.1-alpha';
const VERSION = '2.0.0';
expect(version).to.be.equal(VERSION);
});
});

View File

@@ -25,10 +25,8 @@ describe('ForwarderWrapper', () => {
blockPollingIntervalMs: 0,
};
const fillableAmount = new BigNumber(5);
const takerTokenFillAmount = new BigNumber(5);
let contractWrappers: ContractWrappers;
let fillScenarios: FillScenarios;
let forwarderContractAddress: string;
let exchangeContractAddress: string;
let zrxTokenAddress: string;
let userAddresses: string[];
@@ -46,7 +44,6 @@ describe('ForwarderWrapper', () => {
before(async () => {
await blockchainLifecycle.startAsync();
contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
forwarderContractAddress = contractWrappers.forwarder.getContractAddress();
exchangeContractAddress = contractWrappers.exchange.getContractAddress();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
zrxTokenAddress = tokenUtils.getProtocolTokenAddress();

View File

@@ -0,0 +1,142 @@
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
import { DoneCallback, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { BlockParamLiteral } from 'ethereum-types';
import * as _ from 'lodash';
import 'mocha';
import { ContractWrappers, ExchangeCancelEventArgs, ExchangeEvents, ExchangeFillEventArgs, OrderStatus } from '../src';
import { DecodedLogEvent, OrderInfo, TraderInfo } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { tokenUtils } from './utils/token_utils';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('OrderValidator', () => {
const contractWrappersConfig = {
networkId: constants.TESTRPC_NETWORK_ID,
blockPollingIntervalMs: 0,
};
const fillableAmount = new BigNumber(5);
const partialFillAmount = new BigNumber(2);
let contractWrappers: ContractWrappers;
let fillScenarios: FillScenarios;
let exchangeContractAddress: string;
let zrxTokenAddress: string;
let zrxTokenAssetData: string;
let userAddresses: string[];
let coinbase: string;
let makerAddress: string;
let takerAddress: string;
let feeRecipient: string;
let anotherMakerAddress: string;
let makerTokenAddress: string;
let takerTokenAddress: string;
let makerAssetData: string;
let takerAssetData: string;
let signedOrder: SignedOrder;
let anotherSignedOrder: SignedOrder;
before(async () => {
await blockchainLifecycle.startAsync();
contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
exchangeContractAddress = contractWrappers.exchange.getContractAddress();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
zrxTokenAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
fillScenarios = new FillScenarios(
provider,
userAddresses,
zrxTokenAddress,
exchangeContractAddress,
contractWrappers.erc20Proxy.getContractAddress(),
contractWrappers.erc721Proxy.getContractAddress(),
);
[coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
[makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
takerTokenAddress = tokenUtils.getWethTokenAddress();
[makerAssetData, takerAssetData] = [
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
];
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerAssetData,
takerAssetData,
makerAddress,
constants.NULL_ADDRESS,
fillableAmount,
);
anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
zrxTokenAssetData,
takerAssetData,
makerAddress,
constants.NULL_ADDRESS,
fillableAmount,
);
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('#getOrdersAndTradersInfoAsync', () => {
let signedOrders: SignedOrder[];
let takerAddresses: string[];
let ordersInfo: OrderInfo[];
let tradersInfo: TraderInfo[];
beforeEach(async () => {
signedOrders = [signedOrder, anotherSignedOrder];
takerAddresses = [takerAddress, takerAddress];
const ordersAndTradersInfo = await contractWrappers.orderValidator.getOrdersAndTradersInfoAsync(
signedOrders,
takerAddresses,
);
ordersInfo = _.map(ordersAndTradersInfo, orderAndTraderInfo => orderAndTraderInfo.orderInfo);
tradersInfo = _.map(ordersAndTradersInfo, orderAndTraderInfo => orderAndTraderInfo.traderInfo);
});
it('should return the same number of order infos and trader infos as input orders', async () => {
expect(ordersInfo.length).to.be.equal(signedOrders.length);
expect(tradersInfo.length).to.be.equal(takerAddresses.length);
});
it('should return correct on-chain order info for input orders', async () => {
const firstOrderInfo = ordersInfo[0];
const secondOrderInfo = ordersInfo[1];
expect(firstOrderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(firstOrderInfo.orderTakerAssetFilledAmount).to.bignumber.equal(constants.ZERO_AMOUNT);
expect(secondOrderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(secondOrderInfo.orderTakerAssetFilledAmount).to.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return correct on-chain trader info for input takers', async () => {
const firstTraderInfo = tradersInfo[0];
const secondTraderInfo = tradersInfo[1];
expect(firstTraderInfo.makerBalance).to.bignumber.equal(new BigNumber(5));
expect(firstTraderInfo.makerAllowance).to.bignumber.equal(new BigNumber(5));
expect(firstTraderInfo.takerBalance).to.bignumber.equal(new BigNumber(0));
expect(firstTraderInfo.takerAllowance).to.bignumber.equal(new BigNumber(0));
expect(firstTraderInfo.makerZrxBalance).to.bignumber.equal(new BigNumber(5));
expect(firstTraderInfo.makerZrxAllowance).to.bignumber.equal(new BigNumber(5));
expect(firstTraderInfo.takerZrxBalance).to.bignumber.equal(new BigNumber(0));
expect(firstTraderInfo.takerZrxAllowance).to.bignumber.equal(new BigNumber(0));
expect(secondTraderInfo.makerBalance).to.bignumber.equal(new BigNumber(5));
expect(secondTraderInfo.makerAllowance).to.bignumber.equal(new BigNumber(5));
expect(secondTraderInfo.takerBalance).to.bignumber.equal(new BigNumber(0));
expect(secondTraderInfo.takerAllowance).to.bignumber.equal(new BigNumber(0));
expect(secondTraderInfo.makerZrxBalance).to.bignumber.equal(new BigNumber(5));
expect(secondTraderInfo.makerZrxAllowance).to.bignumber.equal(new BigNumber(5));
expect(secondTraderInfo.takerZrxBalance).to.bignumber.equal(new BigNumber(0));
expect(secondTraderInfo.takerZrxAllowance).to.bignumber.equal(new BigNumber(0));
});
});
});

View File

@@ -15,4 +15,5 @@ export const constants = {
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(10 ** 27), // tslint:disable-line:custom-no-magic-numbers
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
NUM_DUMMY_ERC721_TO_DEPLOY: 1,
ZERO_AMOUNT: new BigNumber(0),
};

View File

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "."
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -2,7 +2,7 @@
// tslint:disable:no-unused-variable
// tslint:disable:no-unbound-method
import { BaseContract } from '@0xproject/base-contract';
import { BlockParam, CallData, ContractAbi, ContractArtifact, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types';
import { BlockParam, BlockParamLiteral, CallData, ContractAbi, ContractArtifact, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types';
import { BigNumber, classUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethers from 'ethers';

View File

@@ -1,5 +1,5 @@
{
"artifactsDir": "../migrations/artifacts/2.0.0",
"artifactsDir": "../migrations/artifacts/development",
"contractsDir": "src/",
"compilerSettings": {
"optimizer": {
@@ -23,6 +23,7 @@
"DummyERC20Token",
"DummyERC721Receiver",
"DummyERC721Token",
"DummyMultipleReturnERC20Token",
"DummyNoReturnERC20Token",
"ERC20Proxy",
"ERC20Token",
@@ -40,6 +41,7 @@
"MultiSigWallet",
"MultiSigWalletWithTimeLock",
"OrderValidator",
"ReentrantERC20Token",
"TestAssetProxyOwner",
"TestAssetProxyDispatcher",
"TestConstants",
@@ -47,6 +49,7 @@
"TestLibs",
"TestExchangeInternals",
"TestSignatureValidator",
"TestStaticCallReceiver",
"TokenRegistry",
"Validator",
"Wallet",

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "contracts",
"version": "2.1.41",
"version": "2.1.43",
"engines": {
"node": ">=6.12"
},
@@ -11,10 +11,9 @@
"test": "test"
},
"scripts": {
"watch_without_deps": "yarn pre_build && tsc -w",
"build": "yarn pre_build && tsc",
"build": "yarn pre_build && tsc -b",
"pre_build": "run-s compile copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles -u 4 '../migrations/artifacts/2.0.0/**/*' ./lib/artifacts;",
"copy_artifacts": "copyfiles -u 4 '../migrations/artifacts/development/**/*' ./lib/artifacts;",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
@@ -33,7 +32,7 @@
"lint-contracts": "solhint src/2.0.0/**/**/**/**/*.sol"
},
"config": {
"abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|DummyNoReturnERC20Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|InvalidERC721Receiver|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|OrderValidator|TestAssetProxyOwner|TestAssetProxyDispatcher|TestConstants|TestExchangeInternals|TestLibBytes|TestLibs|TestSignatureValidator|Validator|Wallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json"
"abis": "../migrations/artifacts/development/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|InvalidERC721Receiver|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|OrderValidator|ReentrantERC20Token|TestAssetProxyOwner|TestAssetProxyDispatcher|TestConstants|TestExchangeInternals|TestLibBytes|TestLibs|TestSignatureValidator|TestStaticCallReceiver|Validator|Wallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json"
},
"repository": {
"type": "git",
@@ -46,12 +45,12 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/contracts/README.md",
"devDependencies": {
"@0xproject/abi-gen": "^1.0.6",
"@0xproject/dev-utils": "^1.0.5",
"@0xproject/sol-compiler": "^1.1.0",
"@0xproject/sol-cov": "^2.1.0",
"@0xproject/subproviders": "^2.0.0",
"@0xproject/tslint-config": "^1.0.6",
"@0xproject/abi-gen": "^1.0.8",
"@0xproject/dev-utils": "^1.0.7",
"@0xproject/sol-compiler": "^1.1.2",
"@0xproject/sol-cov": "^2.1.2",
"@0xproject/subproviders": "^2.0.2",
"@0xproject/tslint-config": "^1.0.7",
"@types/bn.js": "^4.11.0",
"@types/ethereumjs-abi": "^0.6.0",
"@types/lodash": "4.14.104",
@@ -73,15 +72,15 @@
"yargs": "^10.0.3"
},
"dependencies": {
"@0xproject/base-contract": "^2.0.0",
"@0xproject/order-utils": "^1.0.1-rc.4",
"@0xproject/types": "^1.0.1-rc.5",
"@0xproject/typescript-typings": "^1.0.5",
"@0xproject/utils": "^1.0.6",
"@0xproject/web3-wrapper": "^2.0.0",
"@0xproject/base-contract": "^2.0.2",
"@0xproject/order-utils": "^1.0.1",
"@0xproject/types": "^1.0.1",
"@0xproject/typescript-typings": "^2.0.0",
"@0xproject/utils": "^1.0.8",
"@0xproject/web3-wrapper": "^2.0.2",
"@types/js-combinatorics": "^0.5.29",
"bn.js": "^4.11.8",
"ethereum-types": "^1.0.5",
"ethereum-types": "^1.0.6",
"ethereumjs-abi": "0.6.5",
"ethereumjs-util": "^5.1.1",
"ethers": "3.0.22",

View File

@@ -37,7 +37,7 @@ contract Whitelist is
bytes internal TX_ORIGIN_SIGNATURE;
// solhint-enable var-name-mixedcase
byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x06";
byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x05";
constructor (address _exchange)
public

View File

@@ -34,7 +34,6 @@ contract Forwarder is
MixinExchangeWrapper,
MixinForwarderCore
{
constructor (
address _exchange,
bytes memory _zrxAssetData,

View File

@@ -31,7 +31,6 @@ contract MixinAssets is
LibConstants,
MAssets
{
using LibBytes for bytes;
bytes4 constant internal ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));

View File

@@ -34,7 +34,6 @@ contract MixinExchangeWrapper is
LibConstants,
MExchangeWrapper
{
/// @dev Fills the input order.
/// Returns false if the transaction would otherwise revert.
/// @param order Order struct containing order specifications.
@@ -61,7 +60,7 @@ contract MixinExchangeWrapper is
// Call `fillOrder` and handle any exceptions gracefully
assembly {
let success := call(
gas, // forward all gas, TODO: look into gas consumption of assert/throw
gas, // forward all gas
exchange, // call address of Exchange contract
0, // transfer 0 wei
add(fillOrderCalldata, 32), // pointer to start of input (skip array length in first 32 bytes)
@@ -69,20 +68,14 @@ contract MixinExchangeWrapper is
fillOrderCalldata, // write output over input
128 // output size is 128 bytes
)
switch success
case 0 {
mstore(fillResults, 0)
mstore(add(fillResults, 32), 0)
mstore(add(fillResults, 64), 0)
mstore(add(fillResults, 96), 0)
}
case 1 {
if success {
mstore(fillResults, mload(fillOrderCalldata))
mstore(add(fillResults, 32), mload(add(fillOrderCalldata, 32)))
mstore(add(fillResults, 64), mload(add(fillOrderCalldata, 64)))
mstore(add(fillResults, 96), mload(add(fillOrderCalldata, 96)))
}
}
// fillResults values will be 0 by default if call was unsuccessful
return fillResults;
}
@@ -163,7 +156,7 @@ contract MixinExchangeWrapper is
// Convert the remaining amount of makerAsset to buy into remaining amount
// of takerAsset to sell, assuming entire amount can be sold in the current order
uint256 remainingTakerAssetFillAmount = getPartialAmount(
uint256 remainingTakerAssetFillAmount = getPartialAmountFloor(
orders[i].takerAssetAmount,
orders[i].makerAssetAmount,
remainingMakerAssetFillAmount
@@ -231,7 +224,7 @@ contract MixinExchangeWrapper is
// Convert the remaining amount of ZRX to buy into remaining amount
// of WETH to sell, assuming entire amount can be sold in the current order.
uint256 remainingWethSellAmount = getPartialAmount(
uint256 remainingWethSellAmount = getPartialAmountFloor(
orders[i].takerAssetAmount,
safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees
remainingZrxBuyAmount

View File

@@ -39,7 +39,6 @@ contract MixinForwarderCore is
MExchangeWrapper,
IForwarderCore
{
using LibBytes for bytes;
/// @dev Constructor approves ERC20 proxy to transfer ZRX and WETH on this contract's behalf.
@@ -47,10 +46,12 @@ contract MixinForwarderCore is
public
{
address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
if (proxyAddress != address(0)) {
ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
ZRX_TOKEN.approve(proxyAddress, MAX_UINT);
}
require(
proxyAddress != address(0),
"UNREGISTERED_ASSET_PROXY"
);
ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
ZRX_TOKEN.approve(proxyAddress, MAX_UINT);
}
/// @dev Purchases as much of orders' makerAssets as possible by selling up to 95% of transaction's ETH value.
@@ -87,7 +88,7 @@ contract MixinForwarderCore is
uint256 makerAssetAmountPurchased;
if (orders[0].makerAssetData.equals(ZRX_ASSET_DATA)) {
// Calculate amount of WETH that won't be spent on ETH fees.
wethSellAmount = getPartialAmount(
wethSellAmount = getPartialAmountFloor(
PERCENTAGE_DENOMINATOR,
safeAdd(PERCENTAGE_DENOMINATOR, feePercentage),
msg.value
@@ -103,7 +104,7 @@ contract MixinForwarderCore is
makerAssetAmountPurchased = safeSub(orderFillResults.makerAssetFilledAmount, orderFillResults.takerFeePaid);
} else {
// 5% of WETH is reserved for filling feeOrders and paying feeRecipient.
wethSellAmount = getPartialAmount(
wethSellAmount = getPartialAmountFloor(
MAX_WETH_FILL_PERCENTAGE,
PERCENTAGE_DENOMINATOR,
msg.value

View File

@@ -28,7 +28,6 @@ contract MixinWeth is
LibConstants,
MWeth
{
/// @dev Default payabale function, this allows us to withdraw WETH
function ()
public
@@ -82,7 +81,7 @@ contract MixinWeth is
uint256 wethRemaining = safeSub(msg.value, wethSold);
// Calculate ETH fee to pay to feeRecipient.
uint256 ethFee = getPartialAmount(
uint256 ethFee = getPartialAmountFloor(
feePercentage,
PERCENTAGE_DENOMINATOR,
wethSoldExcludingFeeOrders

View File

@@ -24,7 +24,6 @@ import "../interfaces/IAssets.sol";
contract MAssets is
IAssets
{
/// @dev Transfers given amount of asset to sender.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param amount Amount of asset to transfer to sender.

View File

@@ -28,11 +28,11 @@ import "../../utils/LibBytes/LibBytes.sol";
contract OrderValidator {
using LibBytes for bytes;
bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
using LibBytes for bytes;
struct TraderInfo {
uint256 makerBalance; // Maker's balance of makerAsset
uint256 makerAllowance; // Maker's allowance to corresponding AssetProxy

View File

@@ -1,13 +1,14 @@
// solhint-disable
pragma solidity ^0.4.10;
pragma solidity ^0.4.15;
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <stefan.george@consensys.net>
contract MultiSigWallet {
uint constant public MAX_OWNER_COUNT = 50;
/*
* Events
*/
event Confirmation(address indexed sender, uint indexed transactionId);
event Revocation(address indexed sender, uint indexed transactionId);
event Submission(uint indexed transactionId);
@@ -18,6 +19,14 @@ contract MultiSigWallet {
event OwnerRemoval(address indexed owner);
event RequirementChange(uint required);
/*
* Constants
*/
uint constant public MAX_OWNER_COUNT = 50;
/*
* Storage
*/
mapping (uint => Transaction) public transactions;
mapping (uint => mapping (address => bool)) public confirmations;
mapping (address => bool) public isOwner;
@@ -32,60 +41,54 @@ contract MultiSigWallet {
bool executed;
}
/*
* Modifiers
*/
modifier onlyWallet() {
if (msg.sender != address(this))
throw;
require(msg.sender == address(this));
_;
}
modifier ownerDoesNotExist(address owner) {
if (isOwner[owner])
throw;
require(!isOwner[owner]);
_;
}
modifier ownerExists(address owner) {
if (!isOwner[owner])
throw;
require(isOwner[owner]);
_;
}
modifier transactionExists(uint transactionId) {
if (transactions[transactionId].destination == 0)
throw;
require(transactions[transactionId].destination != 0);
_;
}
modifier confirmed(uint transactionId, address owner) {
if (!confirmations[transactionId][owner])
throw;
require(confirmations[transactionId][owner]);
_;
}
modifier notConfirmed(uint transactionId, address owner) {
if (confirmations[transactionId][owner])
throw;
require(!confirmations[transactionId][owner]);
_;
}
modifier notExecuted(uint transactionId) {
if (transactions[transactionId].executed)
throw;
require(!transactions[transactionId].executed);
_;
}
modifier notNull(address _address) {
if (_address == 0)
throw;
require(_address != 0);
_;
}
modifier validRequirement(uint ownerCount, uint _required) {
if ( ownerCount > MAX_OWNER_COUNT
|| _required > ownerCount
|| _required == 0
|| ownerCount == 0)
throw;
require(ownerCount <= MAX_OWNER_COUNT
&& _required <= ownerCount
&& _required != 0
&& ownerCount != 0);
_;
}
@@ -108,8 +111,7 @@ contract MultiSigWallet {
validRequirement(_owners.length, _required)
{
for (uint i=0; i<_owners.length; i++) {
if (isOwner[_owners[i]] || _owners[i] == 0)
throw;
require(!isOwner[_owners[i]] && _owners[i] != 0);
isOwner[_owners[i]] = true;
}
owners = _owners;
@@ -151,7 +153,7 @@ contract MultiSigWallet {
/// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet.
/// @param owner Address of owner to be replaced.
/// @param owner Address of new owner.
/// @param newOwner Address of new owner.
function replaceOwner(address owner, address newOwner)
public
onlyWallet
@@ -222,20 +224,44 @@ contract MultiSigWallet {
/// @param transactionId Transaction ID.
function executeTransaction(uint transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
if (isConfirmed(transactionId)) {
Transaction tx = transactions[transactionId];
tx.executed = true;
if (tx.destination.call.value(tx.value)(tx.data))
Transaction storage txn = transactions[transactionId];
txn.executed = true;
if (external_call(txn.destination, txn.value, txn.data.length, txn.data))
Execution(transactionId);
else {
ExecutionFailure(transactionId);
tx.executed = false;
txn.executed = false;
}
}
}
// call has been separated into its own function in order to take advantage
// of the Solidity's code generator to produce a loop that copies tx.data into memory.
function external_call(address destination, uint value, uint dataLength, bytes data) internal returns (bool) {
bool result;
assembly {
let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
result := call(
sub(gas, 34710), // 34710 is the value that solidity is currently emitting
// It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
// callNewAccountGas (25000, in case the destination address does not exist and needs creating)
destination,
value,
d,
dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
x,
0 // Output is ignored, therefore the output size is zero
)
}
return result;
}
/// @dev Returns the confirmation status of a transaction.
/// @param transactionId Transaction ID.
/// @return Confirmation status.
@@ -364,4 +390,4 @@ contract MultiSigWallet {
for (i=from; i<to; i++)
_transactionIds[i - from] = transactionIdsTemp[i];
}
}
}

View File

@@ -16,47 +16,57 @@
*/
// solhint-disable
pragma solidity ^0.4.10;
pragma solidity 0.4.24;
import "./MultiSigWallet.sol";
/// @title Multisignature wallet with time lock- Allows multiple parties to execute a transaction after a time lock has passed.
/// @author Amir Bandeali - <amir@0xProject.com>
contract MultiSigWalletWithTimeLock is MultiSigWallet {
// solhint-disable not-rely-on-time
contract MultiSigWalletWithTimeLock is
MultiSigWallet
{
event ConfirmationTimeSet(uint256 indexed transactionId, uint256 confirmationTime);
event TimeLockChange(uint256 secondsTimeLocked);
event ConfirmationTimeSet(uint indexed transactionId, uint confirmationTime);
event TimeLockChange(uint secondsTimeLocked);
uint256 public secondsTimeLocked;
uint public secondsTimeLocked;
mapping (uint256 => uint256) public confirmationTimes;
mapping (uint => uint) public confirmationTimes;
modifier notFullyConfirmed(uint transactionId) {
require(!isConfirmed(transactionId));
modifier notFullyConfirmed(uint256 transactionId) {
require(
!isConfirmed(transactionId),
"TX_FULLY_CONFIRMED"
);
_;
}
modifier fullyConfirmed(uint transactionId) {
require(isConfirmed(transactionId));
modifier fullyConfirmed(uint256 transactionId) {
require(
isConfirmed(transactionId),
"TX_NOT_FULLY_CONFIRMED"
);
_;
}
modifier pastTimeLock(uint transactionId) {
require(block.timestamp >= confirmationTimes[transactionId] + secondsTimeLocked);
modifier pastTimeLock(uint256 transactionId) {
require(
block.timestamp >= confirmationTimes[transactionId] + secondsTimeLocked,
"TIME_LOCK_INCOMPLETE"
);
_;
}
/*
* Public functions
*/
/// @dev Contract constructor sets initial owners, required number of confirmations, and time lock.
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
function MultiSigWalletWithTimeLock(address[] _owners, uint _required, uint _secondsTimeLocked)
constructor (
address[] _owners,
uint256 _required,
uint256 _secondsTimeLocked
)
public
MultiSigWallet(_owners, _required)
{
@@ -65,17 +75,17 @@ contract MultiSigWalletWithTimeLock is MultiSigWallet {
/// @dev Changes the duration of the time lock for transactions.
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
function changeTimeLock(uint _secondsTimeLocked)
function changeTimeLock(uint256 _secondsTimeLocked)
public
onlyWallet
{
secondsTimeLocked = _secondsTimeLocked;
TimeLockChange(_secondsTimeLocked);
emit TimeLockChange(_secondsTimeLocked);
}
/// @dev Allows an owner to confirm a transaction.
/// @param transactionId Transaction ID.
function confirmTransaction(uint transactionId)
function confirmTransaction(uint256 transactionId)
public
ownerExists(msg.sender)
transactionExists(transactionId)
@@ -83,52 +93,35 @@ contract MultiSigWalletWithTimeLock is MultiSigWallet {
notFullyConfirmed(transactionId)
{
confirmations[transactionId][msg.sender] = true;
Confirmation(msg.sender, transactionId);
emit Confirmation(msg.sender, transactionId);
if (isConfirmed(transactionId)) {
setConfirmationTime(transactionId, block.timestamp);
}
}
/// @dev Allows an owner to revoke a confirmation for a transaction.
/// @param transactionId Transaction ID.
function revokeConfirmation(uint transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
notFullyConfirmed(transactionId)
{
confirmations[transactionId][msg.sender] = false;
Revocation(msg.sender, transactionId);
}
/// @dev Allows anyone to execute a confirmed transaction.
/// @param transactionId Transaction ID.
function executeTransaction(uint transactionId)
function executeTransaction(uint256 transactionId)
public
notExecuted(transactionId)
fullyConfirmed(transactionId)
pastTimeLock(transactionId)
{
Transaction storage tx = transactions[transactionId];
tx.executed = true;
if (tx.destination.call.value(tx.value)(tx.data))
Execution(transactionId);
else {
ExecutionFailure(transactionId);
tx.executed = false;
Transaction storage txn = transactions[transactionId];
txn.executed = true;
if (external_call(txn.destination, txn.value, txn.data.length, txn.data)) {
emit Execution(transactionId);
} else {
emit ExecutionFailure(transactionId);
txn.executed = false;
}
}
/*
* Internal functions
*/
/// @dev Sets the time of when a submission first passed.
function setConfirmationTime(uint transactionId, uint confirmationTime)
function setConfirmationTime(uint256 transactionId, uint256 confirmationTime)
internal
{
confirmationTimes[transactionId] = confirmationTime;
ConfirmationTimeSet(transactionId, confirmationTime);
emit ConfirmationTimeSet(transactionId, confirmationTime);
}
}

View File

@@ -18,7 +18,6 @@
pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol";
@@ -59,15 +58,64 @@ contract ERC20Proxy is
mstore(96, 0)
revert(0, 100)
}
/////// Token contract address ///////
// The token address is found as follows:
// * It is stored at offset 4 in `assetData` contents.
// * This is stored at offset 32 from `assetData`.
// * The offset to `assetData` from Params is stored at offset
// 4 in calldata.
// * The offset of Params in calldata is 4.
// So we read location 4 and add 32 + 4 + 4 to it.
// `transferFrom`.
// The function is marked `external`, so no abi decodeding is done for
// us. Instead, we expect the `calldata` memory to contain the
// following:
//
// | Area | Offset | Length | Contents |
// |----------|--------|---------|-------------------------------------|
// | Header | 0 | 4 | function selector |
// | Params | | 4 * 32 | function parameters: |
// | | 4 | | 1. offset to assetData (*) |
// | | 36 | | 2. from |
// | | 68 | | 3. to |
// | | 100 | | 4. amount |
// | Data | | | assetData: |
// | | 132 | 32 | assetData Length |
// | | 164 | ** | assetData Contents |
//
// (*): offset is computed from start of function parameters, so offset
// by an additional 4 bytes in the calldata.
//
// (**): see table below to compute length of assetData Contents
//
// WARNING: The ABIv2 specification allows additional padding between
// the Params and Data section. This will result in a larger
// offset to assetData.
// Asset data itself is encoded as follows:
//
// | Area | Offset | Length | Contents |
// |----------|--------|---------|-------------------------------------|
// | Header | 0 | 4 | function selector |
// | Params | | 1 * 32 | function parameters: |
// | | 4 | 12 + 20 | 1. token address |
// We construct calldata for the `token.transferFrom` ABI.
// The layout of this calldata is in the table below.
//
// | Area | Offset | Length | Contents |
// |----------|--------|---------|-------------------------------------|
// | Header | 0 | 4 | function selector |
// | Params | | 3 * 32 | function parameters: |
// | | 4 | | 1. from |
// | | 36 | | 2. to |
// | | 68 | | 3. amount |
/////// Read token address from calldata ///////
// * The token address is stored in `assetData`.
//
// * The "offset to assetData" is stored at offset 4 in the calldata (table 1).
// [assetDataOffsetFromParams = calldataload(4)]
//
// * Notes that the "offset to assetData" is relative to the "Params" area of calldata;
// add 4 bytes to account for the length of the "Header" area (table 1).
// [assetDataOffsetFromHeader = assetDataOffsetFromParams + 4]
//
// * The "token address" is offset 32+4=36 bytes into "assetData" (tables 1 & 2).
// [tokenOffset = assetDataOffsetFromHeader + 36 = calldataload(4) + 4 + 36]
let token := calldataload(add(calldataload(4), 40))
/////// Setup Header Area ///////
@@ -118,6 +166,9 @@ contract ERC20Proxy is
mstore(96, 0)
revert(0, 100)
}
// Revert if undefined function is called
revert(0, 0)
}
}

View File

@@ -18,7 +18,6 @@
pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol";
@@ -80,6 +79,8 @@ contract ERC721Proxy is
// (*): offset is computed from start of function parameters, so offset
// by an additional 4 bytes in the calldata.
//
// (**): see table below to compute length of assetData Contents
//
// WARNING: The ABIv2 specification allows additional padding between
// the Params and Data section. This will result in a larger
// offset to assetData.
@@ -152,6 +153,9 @@ contract ERC721Proxy is
mstore(96, 0)
revert(0, 100)
}
// Revert if undefined function is called
revert(0, 0)
}
}

View File

@@ -26,7 +26,6 @@ contract MixinAuthorizable is
Ownable,
MAuthorizable
{
/// @dev Only authorized addresses can invoke functions with this modifier.
modifier onlyAuthorized {
require(

View File

@@ -24,7 +24,6 @@ import "./IAuthorizable.sol";
contract IAssetProxy is
IAuthorizable
{
/// @dev Transfers assets. Either succeeds or throws.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param from Address to transfer asset from.

View File

@@ -24,7 +24,6 @@ import "../../../utils/Ownable/IOwnable.sol";
contract IAuthorizable is
IOwnable
{
/// @dev Authorizes an address.
/// @param target Address to authorize.
function addAuthorizedAddress(address target)

View File

@@ -24,7 +24,6 @@ import "../interfaces/IAuthorizable.sol";
contract MAuthorizable is
IAuthorizable
{
// Event logged when a new address is authorized.
event AuthorizedAddressAdded(
address indexed target,

View File

@@ -16,14 +16,16 @@
*/
pragma solidity 0.4.10;
pragma solidity 0.4.24;
import "../../multisig/MultiSigWalletWithTimeLock.sol";
import "../../utils/LibBytes/LibBytes.sol";
contract AssetProxyOwner is
MultiSigWalletWithTimeLock
{
using LibBytes for bytes;
event AssetProxyRegistration(address assetProxyContract, bool isRegistered);
@@ -36,9 +38,15 @@ contract AssetProxyOwner is
/// @dev Function will revert if the transaction does not call `removeAuthorizedAddressAtIndex`
/// on an approved AssetProxy contract.
modifier validRemoveAuthorizedAddressAtIndexTx(uint256 transactionId) {
Transaction storage tx = transactions[transactionId];
require(isAssetProxyRegistered[tx.destination]);
require(readBytes4(tx.data, 0) == REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR);
Transaction storage txn = transactions[transactionId];
require(
isAssetProxyRegistered[txn.destination],
"UNREGISTERED_ASSET_PROXY"
);
require(
txn.data.readBytes4(0) == REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR,
"INVALID_FUNCTION_SELECTOR"
);
_;
}
@@ -48,7 +56,7 @@ contract AssetProxyOwner is
/// @param _assetProxyContracts Array of AssetProxy contract addresses.
/// @param _required Number of required confirmations.
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
function AssetProxyOwner(
constructor (
address[] memory _owners,
address[] memory _assetProxyContracts,
uint256 _required,
@@ -59,7 +67,10 @@ contract AssetProxyOwner is
{
for (uint256 i = 0; i < _assetProxyContracts.length; i++) {
address assetProxy = _assetProxyContracts[i];
require(assetProxy != address(0));
require(
assetProxy != address(0),
"INVALID_ASSET_PROXY"
);
isAssetProxyRegistered[assetProxy] = true;
}
}
@@ -74,7 +85,7 @@ contract AssetProxyOwner is
notNull(assetProxyContract)
{
isAssetProxyRegistered[assetProxyContract] = isRegistered;
AssetProxyRegistration(assetProxyContract, isRegistered);
emit AssetProxyRegistration(assetProxyContract, isRegistered);
}
/// @dev Allows execution of `removeAuthorizedAddressAtIndex` without time lock.
@@ -85,35 +96,13 @@ contract AssetProxyOwner is
fullyConfirmed(transactionId)
validRemoveAuthorizedAddressAtIndexTx(transactionId)
{
Transaction storage tx = transactions[transactionId];
tx.executed = true;
// solhint-disable-next-line avoid-call-value
if (tx.destination.call.value(tx.value)(tx.data))
Execution(transactionId);
else {
ExecutionFailure(transactionId);
tx.executed = false;
Transaction storage txn = transactions[transactionId];
txn.executed = true;
if (external_call(txn.destination, txn.value, txn.data.length, txn.data)) {
emit Execution(transactionId);
} else {
emit ExecutionFailure(transactionId);
txn.executed = false;
}
}
/// @dev Reads an unpadded bytes4 value from a position in a byte array.
/// @param b Byte array containing a bytes4 value.
/// @param index Index in byte array of bytes4 value.
/// @return bytes4 value from byte array.
function readBytes4(
bytes memory b,
uint256 index
)
internal
returns (bytes4 result)
{
require(b.length >= index + 4);
assembly {
result := mload(add(b, 32))
// Solidity does not require us to clean the trailing bytes.
// We do it anyway
result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
}
return result;
}
}

View File

@@ -37,7 +37,6 @@ contract Exchange is
MixinAssetProxyDispatcher,
MixinWrapperFunctions
{
string constant public VERSION = "2.0.1-alpha";
// Mixins are instantiated in the order they are inherited

View File

@@ -19,7 +19,6 @@
pragma solidity 0.4.24;
import "../../utils/Ownable/Ownable.sol";
import "../../utils/LibBytes/LibBytes.sol";
import "./mixins/MAssetProxyDispatcher.sol";
import "../AssetProxy/interfaces/IAssetProxy.sol";
@@ -28,8 +27,6 @@ contract MixinAssetProxyDispatcher is
Ownable,
MAssetProxyDispatcher
{
using LibBytes for bytes;
// Mapping from Asset Proxy Id's to their respective Asset Proxy
mapping (bytes4 => IAssetProxy) public assetProxies;
@@ -83,14 +80,14 @@ contract MixinAssetProxyDispatcher is
internal
{
// Do nothing if no amount should be transferred.
if (amount > 0) {
if (amount > 0 && from != to) {
// Ensure assetData length is valid
require(
assetData.length > 3,
"LENGTH_GREATER_THAN_3_REQUIRED"
);
// Lookup assetProxy
// Lookup assetProxy. We do not use `LibBytes.readBytes4` for gas efficiency reasons.
bytes4 assetProxyId;
assembly {
assetProxyId := and(mload(

View File

@@ -19,6 +19,7 @@
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/ReentrancyGuard/ReentrancyGuard.sol";
import "./libs/LibConstants.sol";
import "./libs/LibFillResults.sol";
import "./libs/LibOrder.sol";
@@ -30,6 +31,7 @@ import "./mixins/MAssetProxyDispatcher.sol";
contract MixinExchangeCore is
ReentrancyGuard,
LibConstants,
LibMath,
LibOrder,
@@ -54,6 +56,7 @@ contract MixinExchangeCore is
/// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
function cancelOrdersUpTo(uint256 targetOrderEpoch)
external
nonReentrant
{
address makerAddress = getCurrentContextAddress();
// If this function is called via `executeTransaction`, we only update the orderEpoch for the makerAddress/msg.sender combination.
@@ -72,7 +75,11 @@ contract MixinExchangeCore is
// Update orderEpoch
orderEpoch[makerAddress][senderAddress] = newOrderEpoch;
emit CancelUpTo(makerAddress, senderAddress, newOrderEpoch);
emit CancelUpTo(
makerAddress,
senderAddress,
newOrderEpoch
);
}
/// @dev Fills the input order.
@@ -86,43 +93,14 @@ contract MixinExchangeCore is
bytes memory signature
)
public
nonReentrant
returns (FillResults memory fillResults)
{
// Fetch order info
OrderInfo memory orderInfo = getOrderInfo(order);
// Fetch taker address
address takerAddress = getCurrentContextAddress();
// Get amount of takerAsset to fill
uint256 remainingTakerAssetAmount = safeSub(order.takerAssetAmount, orderInfo.orderTakerAssetFilledAmount);
uint256 takerAssetFilledAmount = min256(takerAssetFillAmount, remainingTakerAssetAmount);
// Validate context
assertValidFill(
fillResults = fillOrderInternal(
order,
orderInfo,
takerAddress,
takerAssetFillAmount,
takerAssetFilledAmount,
signature
);
// Compute proportional fill amounts
fillResults = calculateFillResults(order, takerAssetFilledAmount);
// Update exchange internal state
updateFilledState(
order,
takerAddress,
orderInfo.orderHash,
orderInfo.orderTakerAssetFilledAmount,
fillResults
);
// Settle order
settleOrder(order, takerAddress, fillResults);
return fillResults;
}
@@ -131,15 +109,9 @@ contract MixinExchangeCore is
/// @param order Order to cancel. Order must be OrderStatus.FILLABLE.
function cancelOrder(Order memory order)
public
nonReentrant
{
// Fetch current order status
OrderInfo memory orderInfo = getOrderInfo(order);
// Validate context
assertValidCancel(order, orderInfo);
// Perform cancel
updateCancelledState(order, orderInfo.orderHash);
cancelOrderInternal(order);
}
/// @dev Gets information about an order: status, hash, and amount filled.
@@ -203,6 +175,84 @@ contract MixinExchangeCore is
return orderInfo;
}
/// @dev Fills the input order.
/// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
/// @param signature Proof that order has been created by maker.
/// @return Amounts filled and fees paid by maker and taker.
function fillOrderInternal(
Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (FillResults memory fillResults)
{
// Fetch order info
OrderInfo memory orderInfo = getOrderInfo(order);
// Fetch taker address
address takerAddress = getCurrentContextAddress();
// Assert that the order is fillable by taker
assertFillableOrder(
order,
orderInfo,
takerAddress,
signature
);
// Get amount of takerAsset to fill
uint256 remainingTakerAssetAmount = safeSub(order.takerAssetAmount, orderInfo.orderTakerAssetFilledAmount);
uint256 takerAssetFilledAmount = min256(takerAssetFillAmount, remainingTakerAssetAmount);
// Validate context
assertValidFill(
order,
orderInfo,
takerAssetFillAmount,
takerAssetFilledAmount,
fillResults.makerAssetFilledAmount
);
// Compute proportional fill amounts
fillResults = calculateFillResults(order, takerAssetFilledAmount);
// Update exchange internal state
updateFilledState(
order,
takerAddress,
orderInfo.orderHash,
orderInfo.orderTakerAssetFilledAmount,
fillResults
);
// Settle order
settleOrder(
order,
takerAddress,
fillResults
);
return fillResults;
}
/// @dev After calling, the order can not be filled anymore.
/// Throws if order is invalid or sender does not have permission to cancel.
/// @param order Order to cancel. Order must be OrderStatus.FILLABLE.
function cancelOrderInternal(Order memory order)
internal
{
// Fetch current order status
OrderInfo memory orderInfo = getOrderInfo(order);
// Validate context
assertValidCancel(order, orderInfo);
// Perform cancel
updateCancelledState(order, orderInfo.orderHash);
}
/// @dev Updates state with results of a fill order.
/// @param order that was filled.
/// @param takerAddress Address of taker who filled the order.
@@ -259,20 +309,16 @@ contract MixinExchangeCore is
order.takerAssetData
);
}
/// @dev Validates context for fillOrder. Succeeds or throws.
/// @param order to be filled.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order.
/// @param takerAddress Address of order taker.
/// @param takerAssetFillAmount Desired amount of order to fill by taker.
/// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
/// @param signature Proof that the orders was created by its maker.
function assertValidFill(
function assertFillableOrder(
Order memory order,
OrderInfo memory orderInfo,
address takerAddress,
uint256 takerAssetFillAmount,
uint256 takerAssetFilledAmount,
bytes memory signature
)
internal
@@ -283,13 +329,7 @@ contract MixinExchangeCore is
orderInfo.orderStatus == uint8(OrderStatus.FILLABLE),
"ORDER_UNFILLABLE"
);
// Revert if fill amount is invalid
require(
takerAssetFillAmount != 0,
"INVALID_TAKER_AMOUNT"
);
// Validate sender is allowed to fill this order
if (order.senderAddress != address(0)) {
require(
@@ -297,7 +337,7 @@ contract MixinExchangeCore is
"INVALID_SENDER"
);
}
// Validate taker is allowed to fill this order
if (order.takerAddress != address(0)) {
require(
@@ -305,7 +345,7 @@ contract MixinExchangeCore is
"INVALID_TAKER"
);
}
// Validate Maker signature (check only if first time seen)
if (orderInfo.orderTakerAssetFilledAmount == 0) {
require(
@@ -317,15 +357,69 @@ contract MixinExchangeCore is
"INVALID_ORDER_SIGNATURE"
);
}
// Validate fill order rounding
}
/// @dev Validates context for fillOrder. Succeeds or throws.
/// @param order to be filled.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order.
/// @param takerAssetFillAmount Desired amount of order to fill by taker.
/// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
/// @param makerAssetFilledAmount Amount of makerAsset that will be transfered.
function assertValidFill(
Order memory order,
OrderInfo memory orderInfo,
uint256 takerAssetFillAmount, // TODO: use FillResults
uint256 takerAssetFilledAmount,
uint256 makerAssetFilledAmount
)
internal
view
{
// Revert if fill amount is invalid
// TODO: reconsider necessity for v2.1
require(
!isRoundingError(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerAssetAmount
),
"ROUNDING_ERROR"
takerAssetFillAmount != 0,
"INVALID_TAKER_AMOUNT"
);
// Make sure taker does not pay more than desired amount
// NOTE: This assertion should never fail, it is here
// as an extra defence against potential bugs.
require(
takerAssetFilledAmount <= takerAssetFillAmount,
"TAKER_OVERPAY"
);
// Make sure order is not overfilled
// NOTE: This assertion should never fail, it is here
// as an extra defence against potential bugs.
require(
safeAdd(orderInfo.orderTakerAssetFilledAmount, takerAssetFilledAmount) <= order.takerAssetAmount,
"ORDER_OVERFILL"
);
// Make sure order is filled at acceptable price.
// The order has an implied price from the makers perspective:
// order price = order.makerAssetAmount / order.takerAssetAmount
// i.e. the number of makerAsset maker is paying per takerAsset. The
// maker is guaranteed to get this price or a better (lower) one. The
// actual price maker is getting in this fill is:
// fill price = makerAssetFilledAmount / takerAssetFilledAmount
// We need `fill price <= order price` for the fill to be fair to maker.
// This amounts to:
// makerAssetFilledAmount order.makerAssetAmount
// ------------------------ <= -----------------------
// takerAssetFilledAmount order.takerAssetAmount
// or, equivalently:
// makerAssetFilledAmount * order.takerAssetAmount <=
// order.makerAssetAmount * takerAssetFilledAmount
// NOTE: This assertion should never fail, it is here
// as an extra defence against potential bugs.
require(
safeMul(makerAssetFilledAmount, order.takerAssetAmount)
<=
safeMul(order.makerAssetAmount, takerAssetFilledAmount),
"INVALID_FILL_PRICE"
);
}
@@ -376,17 +470,17 @@ contract MixinExchangeCore is
{
// Compute proportional transfer amounts
fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
fillResults.makerAssetFilledAmount = getPartialAmount(
fillResults.makerAssetFilledAmount = safeGetPartialAmountFloor(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerAssetAmount
);
fillResults.makerFeePaid = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
fillResults.makerFeePaid = safeGetPartialAmountFloor(
fillResults.makerAssetFilledAmount,
order.makerAssetAmount,
order.makerFee
);
fillResults.takerFeePaid = getPartialAmount(
fillResults.takerFeePaid = safeGetPartialAmountFloor(
takerAssetFilledAmount,
order.takerAssetAmount,
order.takerFee

View File

@@ -14,6 +14,7 @@
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/ReentrancyGuard/ReentrancyGuard.sol";
import "./libs/LibConstants.sol";
import "./libs/LibMath.sol";
import "./libs/LibOrder.sol";
@@ -25,6 +26,7 @@ import "./mixins/MAssetProxyDispatcher.sol";
contract MixinMatchOrders is
ReentrancyGuard,
LibConstants,
LibMath,
MAssetProxyDispatcher,
@@ -48,6 +50,7 @@ contract MixinMatchOrders is
bytes memory rightSignature
)
public
nonReentrant
returns (LibFillResults.MatchedFillResults memory matchedFillResults)
{
// We assume that rightOrder.takerAssetData == leftOrder.makerAssetData and rightOrder.makerAssetData == leftOrder.takerAssetData.
@@ -61,8 +64,20 @@ contract MixinMatchOrders is
// Fetch taker address
address takerAddress = getCurrentContextAddress();
// Either our context is valid or we revert
assertFillableOrder(
leftOrder,
leftOrderInfo,
takerAddress,
leftSignature
);
assertFillableOrder(
rightOrder,
rightOrderInfo,
takerAddress,
rightSignature
);
assertValidMatch(leftOrder, rightOrder);
// Compute proportional fill amounts
@@ -77,20 +92,18 @@ contract MixinMatchOrders is
assertValidFill(
leftOrder,
leftOrderInfo,
takerAddress,
matchedFillResults.left.takerAssetFilledAmount,
matchedFillResults.left.takerAssetFilledAmount,
leftSignature
matchedFillResults.left.makerAssetFilledAmount
);
assertValidFill(
rightOrder,
rightOrderInfo,
takerAddress,
matchedFillResults.right.takerAssetFilledAmount,
matchedFillResults.right.takerAssetFilledAmount,
rightSignature
matchedFillResults.right.makerAssetFilledAmount
);
// Update exchange state
updateFilledState(
leftOrder,
@@ -106,7 +119,7 @@ contract MixinMatchOrders is
rightOrderInfo.orderTakerAssetFilledAmount,
matchedFillResults.right
);
// Settle matched orders. Succeeds or throws.
settleMatchedOrders(
leftOrder,
@@ -162,62 +175,85 @@ contract MixinMatchOrders is
pure
returns (LibFillResults.MatchedFillResults memory matchedFillResults)
{
// We settle orders at the exchange rate of the right order.
// The amount saved by the left maker goes to the taker.
// Either the left or right order will be fully filled; possibly both.
// The left order is fully filled iff the right order can sell more than left can buy.
// That is: the amount required to fill the left order is less than or equal to
// the amount we can spend from the right order:
// <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightMakerToTakerRatio>
// <leftTakerAssetAmountRemaining> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount> / <rightOrder.takerAssetAmount>
// <leftTakerAssetAmountRemaining> * <rightOrder.takerAssetAmount> <= <rightTakerAssetAmountRemaining> * <rightOrder.makerAssetAmount>
// Derive maker asset amounts for left & right orders, given store taker assert amounts
uint256 leftTakerAssetAmountRemaining = safeSub(leftOrder.takerAssetAmount, leftOrderTakerAssetFilledAmount);
uint256 leftMakerAssetAmountRemaining = safeGetPartialAmountFloor(
leftOrder.makerAssetAmount,
leftOrder.takerAssetAmount,
leftTakerAssetAmountRemaining
);
uint256 rightTakerAssetAmountRemaining = safeSub(rightOrder.takerAssetAmount, rightOrderTakerAssetFilledAmount);
uint256 leftTakerAssetFilledAmount;
uint256 rightTakerAssetFilledAmount;
if (
safeMul(leftTakerAssetAmountRemaining, rightOrder.takerAssetAmount) <=
safeMul(rightTakerAssetAmountRemaining, rightOrder.makerAssetAmount)
) {
// Left order will be fully filled: maximally fill left
leftTakerAssetFilledAmount = leftTakerAssetAmountRemaining;
uint256 rightMakerAssetAmountRemaining = safeGetPartialAmountFloor(
rightOrder.makerAssetAmount,
rightOrder.takerAssetAmount,
rightTakerAssetAmountRemaining
);
// The right order receives an amount proportional to how much was spent.
rightTakerAssetFilledAmount = getPartialAmount(
rightOrder.takerAssetAmount,
rightOrder.makerAssetAmount,
leftTakerAssetFilledAmount
// Calculate fill results for maker and taker assets: at least one order will be fully filled.
// The maximum amount the left maker can buy is `leftTakerAssetAmountRemaining`
// The maximum amount the right maker can sell is `rightMakerAssetAmountRemaining`
// We have two distinct cases for calculating the fill results:
// Case 1.
// If the left maker can buy more than the right maker can sell, then only the right order is fully filled.
// If the left maker can buy exactly what the right maker can sell, then both orders are fully filled.
// Case 2.
// If the left maker cannot buy more than the right maker can sell, then only the left order is fully filled.
if (leftTakerAssetAmountRemaining >= rightMakerAssetAmountRemaining) {
// Case 1: Right order is fully filled
matchedFillResults.right.makerAssetFilledAmount = rightMakerAssetAmountRemaining;
matchedFillResults.right.takerAssetFilledAmount = rightTakerAssetAmountRemaining;
matchedFillResults.left.takerAssetFilledAmount = matchedFillResults.right.makerAssetFilledAmount;
// Round down to ensure the maker's exchange rate does not exceed the price specified by the order.
// We favor the maker when the exchange rate must be rounded.
matchedFillResults.left.makerAssetFilledAmount = safeGetPartialAmountFloor(
leftOrder.makerAssetAmount,
leftOrder.takerAssetAmount,
matchedFillResults.left.takerAssetFilledAmount
);
} else {
// Right order will be fully filled: maximally fill right
rightTakerAssetFilledAmount = rightTakerAssetAmountRemaining;
// The left order receives an amount proportional to how much was spent.
leftTakerAssetFilledAmount = getPartialAmount(
rightOrder.makerAssetAmount,
// Case 2: Left order is fully filled
matchedFillResults.left.makerAssetFilledAmount = leftMakerAssetAmountRemaining;
matchedFillResults.left.takerAssetFilledAmount = leftTakerAssetAmountRemaining;
matchedFillResults.right.makerAssetFilledAmount = matchedFillResults.left.takerAssetFilledAmount;
// Round up to ensure the maker's exchange rate does not exceed the price specified by the order.
// We favor the maker when the exchange rate must be rounded.
matchedFillResults.right.takerAssetFilledAmount = safeGetPartialAmountCeil(
rightOrder.takerAssetAmount,
rightTakerAssetFilledAmount
rightOrder.makerAssetAmount,
matchedFillResults.right.makerAssetFilledAmount
);
}
// Calculate fill results for left order
matchedFillResults.left = calculateFillResults(
leftOrder,
leftTakerAssetFilledAmount
);
// Calculate fill results for right order
matchedFillResults.right = calculateFillResults(
rightOrder,
rightTakerAssetFilledAmount
);
// Calculate amount given to taker
matchedFillResults.leftMakerAssetSpreadAmount = safeSub(
matchedFillResults.left.makerAssetFilledAmount,
matchedFillResults.right.takerAssetFilledAmount
);
// Compute fees for left order
matchedFillResults.left.makerFeePaid = safeGetPartialAmountFloor(
matchedFillResults.left.makerAssetFilledAmount,
leftOrder.makerAssetAmount,
leftOrder.makerFee
);
matchedFillResults.left.takerFeePaid = safeGetPartialAmountFloor(
matchedFillResults.left.takerAssetFilledAmount,
leftOrder.takerAssetAmount,
leftOrder.takerFee
);
// Compute fees for right order
matchedFillResults.right.makerFeePaid = safeGetPartialAmountFloor(
matchedFillResults.right.makerAssetFilledAmount,
rightOrder.makerAssetAmount,
rightOrder.makerFee
);
matchedFillResults.right.takerFeePaid = safeGetPartialAmountFloor(
matchedFillResults.right.takerAssetFilledAmount,
rightOrder.takerAssetAmount,
rightOrder.takerFee
);
// Return fill results
return matchedFillResults;
}

View File

@@ -19,6 +19,7 @@
pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
import "../../utils/ReentrancyGuard/ReentrancyGuard.sol";
import "./mixins/MSignatureValidator.sol";
import "./mixins/MTransactions.sol";
import "./interfaces/IWallet.sol";
@@ -26,6 +27,7 @@ import "./interfaces/IValidator.sol";
contract MixinSignatureValidator is
ReentrancyGuard,
MSignatureValidator,
MTransactions
{
@@ -48,14 +50,16 @@ contract MixinSignatureValidator is
)
external
{
require(
isValidSignature(
hash,
signerAddress,
signature
),
"INVALID_SIGNATURE"
);
if (signerAddress != msg.sender) {
require(
isValidSignature(
hash,
signerAddress,
signature
),
"INVALID_SIGNATURE"
);
}
preSigned[hash][signerAddress] = true;
}
@@ -67,6 +71,7 @@ contract MixinSignatureValidator is
bool approval
)
external
nonReentrant
{
address signerAddress = getCurrentContextAddress();
allowedValidators[signerAddress][validatorAddress] = approval;
@@ -172,26 +177,14 @@ contract MixinSignatureValidator is
isValid = signerAddress == recovered;
return isValid;
// Implicitly signed by caller.
// The signer has initiated the call. In the case of non-contract
// accounts it means the transaction itself was signed.
// Example: let's say for a particular operation three signatures
// A, B and C are required. To submit the transaction, A and B can
// give a signature to C, who can then submit the transaction using
// `Caller` for his own signature. Or A and C can sign and B can
// submit using `Caller`. Having `Caller` allows this flexibility.
} else if (signatureType == SignatureType.Caller) {
require(
signature.length == 0,
"LENGTH_0_REQUIRED"
);
isValid = signerAddress == msg.sender;
return isValid;
// Signature verified by wallet contract.
// If used with an order, the maker of the order is the wallet contract.
} else if (signatureType == SignatureType.Wallet) {
isValid = IWallet(signerAddress).isValidSignature(hash, signature);
isValid = isValidWalletSignature(
hash,
signerAddress,
signature
);
return isValid;
// Signature verified by validator contract.
@@ -209,7 +202,8 @@ contract MixinSignatureValidator is
if (!allowedValidators[signerAddress][validatorAddress]) {
return false;
}
isValid = IValidator(validatorAddress).isValidSignature(
isValid = isValidValidatorSignature(
validatorAddress,
hash,
signerAddress,
signature
@@ -220,34 +214,6 @@ contract MixinSignatureValidator is
} else if (signatureType == SignatureType.PreSigned) {
isValid = preSigned[hash][signerAddress];
return isValid;
// Signature from Trezor hardware wallet.
// It differs from web3.eth_sign in the encoding of message length
// (Bitcoin varint encoding vs ascii-decimal, the latter is not
// self-terminating which leads to ambiguities).
// See also:
// https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
// https://github.com/trezor/trezor-mcu/blob/master/firmware/ethereum.c#L602
// https://github.com/trezor/trezor-mcu/blob/master/firmware/crypto.c#L36
} else if (signatureType == SignatureType.Trezor) {
require(
signature.length == 65,
"LENGTH_65_REQUIRED"
);
v = uint8(signature[0]);
r = signature.readBytes32(1);
s = signature.readBytes32(33);
recovered = ecrecover(
keccak256(abi.encodePacked(
"\x19Ethereum Signed Message:\n\x20",
hash
)),
v,
r,
s
);
isValid = signerAddress == recovered;
return isValid;
}
// Anything else is illegal (We do not return false because
@@ -257,4 +223,102 @@ contract MixinSignatureValidator is
// signature was invalid.)
revert("SIGNATURE_UNSUPPORTED");
}
/// @dev Verifies signature using logic defined by Wallet contract.
/// @param hash Any 32 byte hash.
/// @param walletAddress Address that should have signed the given hash
/// and defines its own signature verification method.
/// @param signature Proof that the hash has been signed by signer.
/// @return True if signature is valid for given wallet..
function isValidWalletSignature(
bytes32 hash,
address walletAddress,
bytes signature
)
internal
view
returns (bool isValid)
{
bytes memory calldata = abi.encodeWithSelector(
IWallet(walletAddress).isValidSignature.selector,
hash,
signature
);
assembly {
let cdStart := add(calldata, 32)
let success := staticcall(
gas, // forward all gas
walletAddress, // address of Wallet contract
cdStart, // pointer to start of input
mload(calldata), // length of input
cdStart, // write output over input
32 // output size is 32 bytes
)
switch success
case 0 {
// Revert with `Error("WALLET_ERROR")`
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
mstore(64, 0x0000000c57414c4c45545f4552524f5200000000000000000000000000000000)
mstore(96, 0)
revert(0, 100)
}
case 1 {
// Signature is valid if call did not revert and returned true
isValid := mload(cdStart)
}
}
return isValid;
}
/// @dev Verifies signature using logic defined by Validator contract.
/// @param validatorAddress Address of validator contract.
/// @param hash Any 32 byte hash.
/// @param signerAddress Address that should have signed the given hash.
/// @param signature Proof that the hash has been signed by signer.
/// @return True if the address recovered from the provided signature matches the input signer address.
function isValidValidatorSignature(
address validatorAddress,
bytes32 hash,
address signerAddress,
bytes signature
)
internal
view
returns (bool isValid)
{
bytes memory calldata = abi.encodeWithSelector(
IValidator(signerAddress).isValidSignature.selector,
hash,
signerAddress,
signature
);
assembly {
let cdStart := add(calldata, 32)
let success := staticcall(
gas, // forward all gas
validatorAddress, // address of Validator contract
cdStart, // pointer to start of input
mload(calldata), // length of input
cdStart, // write output over input
32 // output size is 32 bytes
)
switch success
case 0 {
// Revert with `Error("VALIDATOR_ERROR")`
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
mstore(64, 0x0000000f56414c494441544f525f4552524f5200000000000000000000000000)
mstore(96, 0)
revert(0, 100)
}
case 1 {
// Signature is valid if call did not revert and returned true
isValid := mload(cdStart)
}
}
return isValid;
}
}

View File

@@ -28,7 +28,6 @@ contract MixinTransactions is
MSignatureValidator,
MTransactions
{
// Mapping of transaction hash => executed
// This prevents transactions from being executed more than once.
mapping (bytes32 => bool) public transactions;
@@ -36,15 +35,6 @@ contract MixinTransactions is
// Address of current transaction signer
address public currentContextAddress;
// Hash for the EIP712 ZeroEx Transaction Schema
bytes32 constant internal EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = keccak256(abi.encodePacked(
"ZeroExTransaction(",
"uint256 salt,",
"address signerAddress,",
"bytes data",
")"
));
/// @dev Executes an exchange method call in the context of signer.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash.
/// @param signerAddress Address of transaction signer.
@@ -155,7 +145,8 @@ contract MixinTransactions is
view
returns (address)
{
address contextAddress = currentContextAddress == address(0) ? msg.sender : currentContextAddress;
address currentContextAddress_ = currentContextAddress;
address contextAddress = currentContextAddress_ == address(0) ? msg.sender : currentContextAddress_;
return contextAddress;
}
}

View File

@@ -19,20 +19,23 @@
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/ReentrancyGuard/ReentrancyGuard.sol";
import "./libs/LibMath.sol";
import "./libs/LibOrder.sol";
import "./libs/LibFillResults.sol";
import "./libs/LibAbiEncoder.sol";
import "./mixins/MExchangeCore.sol";
import "./mixins/MWrapperFunctions.sol";
contract MixinWrapperFunctions is
ReentrancyGuard,
LibMath,
LibFillResults,
LibAbiEncoder,
MExchangeCore
MExchangeCore,
MWrapperFunctions
{
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
/// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
@@ -43,17 +46,14 @@ contract MixinWrapperFunctions is
bytes memory signature
)
public
nonReentrant
returns (FillResults memory fillResults)
{
fillResults = fillOrder(
fillResults = fillOrKillOrderInternal(
order,
takerAssetFillAmount,
signature
);
require(
fillResults.takerAssetFilledAmount == takerAssetFillAmount,
"COMPLETE_FILL_FAILED"
);
return fillResults;
}
@@ -81,27 +81,21 @@ contract MixinWrapperFunctions is
// Delegate to `fillOrder` and handle any exceptions gracefully
assembly {
let success := delegatecall(
gas, // forward all gas, TODO: look into gas consumption of assert/throw
gas, // forward all gas
address, // call address of this contract
add(fillOrderCalldata, 32), // pointer to start of input (skip array length in first 32 bytes)
mload(fillOrderCalldata), // length of input
fillOrderCalldata, // write output over input
128 // output size is 128 bytes
)
switch success
case 0 {
mstore(fillResults, 0)
mstore(add(fillResults, 32), 0)
mstore(add(fillResults, 64), 0)
mstore(add(fillResults, 96), 0)
}
case 1 {
if success {
mstore(fillResults, mload(fillOrderCalldata))
mstore(add(fillResults, 32), mload(add(fillOrderCalldata, 32)))
mstore(add(fillResults, 64), mload(add(fillOrderCalldata, 64)))
mstore(add(fillResults, 96), mload(add(fillOrderCalldata, 96)))
}
}
// fillResults values will be 0 by default if call was unsuccessful
return fillResults;
}
@@ -117,11 +111,12 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
nonReentrant
returns (FillResults memory totalFillResults)
{
uint256 ordersLength = orders.length;
for (uint256 i = 0; i != ordersLength; i++) {
FillResults memory singleFillResults = fillOrder(
FillResults memory singleFillResults = fillOrderInternal(
orders[i],
takerAssetFillAmounts[i],
signatures[i]
@@ -143,11 +138,12 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
nonReentrant
returns (FillResults memory totalFillResults)
{
uint256 ordersLength = orders.length;
for (uint256 i = 0; i != ordersLength; i++) {
FillResults memory singleFillResults = fillOrKillOrder(
FillResults memory singleFillResults = fillOrKillOrderInternal(
orders[i],
takerAssetFillAmounts[i],
signatures[i]
@@ -195,6 +191,7 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
nonReentrant
returns (FillResults memory totalFillResults)
{
bytes memory takerAssetData = orders[0].takerAssetData;
@@ -210,7 +207,7 @@ contract MixinWrapperFunctions is
uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
// Attempt to sell the remaining amount of takerAsset
FillResults memory singleFillResults = fillOrder(
FillResults memory singleFillResults = fillOrderInternal(
orders[i],
remainingTakerAssetFillAmount,
signatures[i]
@@ -282,6 +279,7 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
nonReentrant
returns (FillResults memory totalFillResults)
{
bytes memory makerAssetData = orders[0].makerAssetData;
@@ -298,14 +296,14 @@ contract MixinWrapperFunctions is
// Convert the remaining amount of makerAsset to buy into remaining amount
// of takerAsset to sell, assuming entire amount can be sold in the current order
uint256 remainingTakerAssetFillAmount = getPartialAmount(
uint256 remainingTakerAssetFillAmount = getPartialAmountFloor(
orders[i].takerAssetAmount,
orders[i].makerAssetAmount,
remainingMakerAssetFillAmount
);
// Attempt to sell the remaining amount of takerAsset
FillResults memory singleFillResults = fillOrder(
FillResults memory singleFillResults = fillOrderInternal(
orders[i],
remainingTakerAssetFillAmount,
signatures[i]
@@ -350,7 +348,7 @@ contract MixinWrapperFunctions is
// Convert the remaining amount of makerAsset to buy into remaining amount
// of takerAsset to sell, assuming entire amount can be sold in the current order
uint256 remainingTakerAssetFillAmount = getPartialAmount(
uint256 remainingTakerAssetFillAmount = getPartialAmountFloor(
orders[i].takerAssetAmount,
orders[i].makerAssetAmount,
remainingMakerAssetFillAmount
@@ -378,10 +376,11 @@ contract MixinWrapperFunctions is
/// @param orders Array of order specifications.
function batchCancelOrders(LibOrder.Order[] memory orders)
public
nonReentrant
{
uint256 ordersLength = orders.length;
for (uint256 i = 0; i != ordersLength; i++) {
cancelOrder(orders[i]);
cancelOrderInternal(orders[i]);
}
}
@@ -400,4 +399,28 @@ contract MixinWrapperFunctions is
}
return ordersInfo;
}
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
/// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
/// @param signature Proof that order has been created by maker.
function fillOrKillOrderInternal(
LibOrder.Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (FillResults memory fillResults)
{
fillResults = fillOrderInternal(
order,
takerAssetFillAmount,
signature
);
require(
fillResults.takerAssetFilledAmount == takerAssetFillAmount,
"COMPLETE_FILL_FAILED"
);
return fillResults;
}
}

View File

@@ -20,6 +20,7 @@ pragma solidity 0.4.24;
contract LibEIP712 {
// EIP191 header for EIP712 prefix
string constant internal EIP191_HEADER = "\x19\x01";

View File

@@ -24,7 +24,6 @@ import "../../../utils/SafeMath/SafeMath.sol";
contract LibFillResults is
SafeMath
{
struct FillResults {
uint256 makerAssetFilledAmount; // Total amount of makerAsset(s) filled.
uint256 takerAssetFilledAmount; // Total amount of takerAsset(s) filled.

View File

@@ -24,13 +24,13 @@ import "../../../utils/SafeMath/SafeMath.sol";
contract LibMath is
SafeMath
{
/// @dev Calculates partial value given a numerator and denominator.
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target.
function getPartialAmount(
/// @return Partial value of target rounded down.
function safeGetPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -39,6 +39,20 @@ contract LibMath is
pure
returns (uint256 partialAmount)
{
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
require(
!isRoundingErrorFloor(
numerator,
denominator,
target
),
"ROUNDING_ERROR"
);
partialAmount = safeDiv(
safeMul(numerator, target),
denominator
@@ -46,12 +60,112 @@ contract LibMath is
return partialAmount;
}
/// @dev Checks if rounding error > 0.1%.
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target rounded up.
function safeGetPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
require(
!isRoundingErrorCeil(
numerator,
denominator,
target
),
"ROUNDING_ERROR"
);
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using safeDiv.
partialAmount = safeDiv(
safeAdd(
safeMul(numerator, target),
safeSub(denominator, 1)
),
denominator
);
return partialAmount;
}
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target rounded down.
function getPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
partialAmount = safeDiv(
safeMul(numerator, target),
denominator
);
return partialAmount;
}
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target rounded up.
function getPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using safeDiv.
partialAmount = safeDiv(
safeAdd(
safeMul(numerator, target),
safeSub(denominator, 1)
),
denominator
);
return partialAmount;
}
/// @dev Checks if rounding error >= 0.1% when rounding down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return Rounding error is present.
function isRoundingError(
function isRoundingErrorFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -60,16 +174,80 @@ contract LibMath is
pure
returns (bool isError)
{
uint256 remainder = mulmod(target, numerator, denominator);
if (remainder == 0) {
return false; // No rounding error.
}
uint256 errPercentageTimes1000000 = safeDiv(
safeMul(remainder, 1000000),
safeMul(numerator, target)
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
isError = errPercentageTimes1000000 > 1000;
// The absolute rounding error is the difference between the rounded
// value and the ideal value. The relative rounding error is the
// absolute rounding error divided by the absolute value of the
// ideal value. This is undefined when the ideal value is zero.
//
// The ideal value is `numerator * target / denominator`.
// Let's call `numerator * target % denominator` the remainder.
// The absolute error is `remainder / denominator`.
//
// When the ideal value is zero, we require the absolute error to
// be zero. Fortunately, this is always the case. The ideal value is
// zero iff `numerator == 0` and/or `target == 0`. In this case the
// remainder and absolute error are also zero.
if (target == 0 || numerator == 0) {
return false;
}
// Otherwise, we want the relative rounding error to be strictly
// less than 0.1%.
// The relative error is `remainder / (numerator * target)`.
// We want the relative error less than 1 / 1000:
// remainder / (numerator * denominator) < 1 / 1000
// or equivalently:
// 1000 * remainder < numerator * target
// so we have a rounding error iff:
// 1000 * remainder >= numerator * target
uint256 remainder = mulmod(
target,
numerator,
denominator
);
isError = safeMul(1000, remainder) >= safeMul(numerator, target);
return isError;
}
/// @dev Checks if rounding error >= 0.1% when rounding up.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return Rounding error is present.
function isRoundingErrorCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (bool isError)
{
require(
denominator > 0,
"DIVISION_BY_ZERO"
);
// See the comments in `isRoundingError`.
if (target == 0 || numerator == 0) {
// When either is zero, the ideal value and rounded value are zero
// and there is no rounding error. (Although the relative error
// is undefined.)
return false;
}
// Compute remainder as before
uint256 remainder = mulmod(
target,
numerator,
denominator
);
remainder = safeSub(denominator, remainder) % denominator;
isError = safeMul(1000, remainder) >= safeMul(numerator, target);
return isError;
}
}

View File

@@ -24,7 +24,6 @@ import "./LibEIP712.sol";
contract LibOrder is
LibEIP712
{
// Hash for the EIP712 Order Schema
bytes32 constant internal EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(
"Order(",

View File

@@ -24,7 +24,6 @@ import "../interfaces/IAssetProxyDispatcher.sol";
contract MAssetProxyDispatcher is
IAssetProxyDispatcher
{
// Logs registration of new asset proxy
event AssetProxyRegistered(
bytes4 id, // Id of new registered AssetProxy.

View File

@@ -59,6 +59,24 @@ contract MExchangeCore is
uint256 orderEpoch // Orders with specified makerAddress and senderAddress with a salt less than this value are considered cancelled.
);
/// @dev Fills the input order.
/// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
/// @param signature Proof that order has been created by maker.
/// @return Amounts filled and fees paid by maker and taker.
function fillOrderInternal(
LibOrder.Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (LibFillResults.FillResults memory fillResults);
/// @dev After calling, the order can not be filled anymore.
/// @param order Order struct containing order specifications.
function cancelOrderInternal(LibOrder.Order memory order)
internal;
/// @dev Updates state with results of a fill order.
/// @param order that was filled.
/// @param takerAddress Address of taker who filled the order.
@@ -83,21 +101,33 @@ contract MExchangeCore is
bytes32 orderHash
)
internal;
/// @dev Validates context for fillOrder. Succeeds or throws.
/// @param order to be filled.
/// @param orderInfo Status, orderHash, and amount already filled of order.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order.
/// @param takerAddress Address of order taker.
/// @param takerAssetFillAmount Desired amount of order to fill by taker.
/// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
/// @param signature Proof that the orders was created by its maker.
function assertValidFill(
function assertFillableOrder(
LibOrder.Order memory order,
LibOrder.OrderInfo memory orderInfo,
address takerAddress,
bytes memory signature
)
internal
view;
/// @dev Validates context for fillOrder. Succeeds or throws.
/// @param order to be filled.
/// @param orderInfo Status, orderHash, and amount already filled of order.
/// @param takerAssetFillAmount Desired amount of order to fill by taker.
/// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
/// @param makerAssetFilledAmount Amount of makerAsset that will be transfered.
function assertValidFill(
LibOrder.Order memory order,
LibOrder.OrderInfo memory orderInfo,
uint256 takerAssetFillAmount,
uint256 takerAssetFilledAmount,
bytes memory signature
uint256 makerAssetFilledAmount
)
internal
view;

View File

@@ -26,7 +26,6 @@ import "../interfaces/IMatchOrders.sol";
contract MMatchOrders is
IMatchOrders
{
/// @dev Validates context for matchOrders. Succeeds or throws.
/// @param leftOrder First order to match.
/// @param rightOrder Second order to match.

View File

@@ -36,11 +36,40 @@ contract MSignatureValidator is
Invalid, // 0x01
EIP712, // 0x02
EthSign, // 0x03
Caller, // 0x04
Wallet, // 0x05
Validator, // 0x06
PreSigned, // 0x07
Trezor, // 0x08
NSignatureTypes // 0x09, number of signature types. Always leave at end.
Wallet, // 0x04
Validator, // 0x05
PreSigned, // 0x06
NSignatureTypes // 0x07, number of signature types. Always leave at end.
}
/// @dev Verifies signature using logic defined by Wallet contract.
/// @param hash Any 32 byte hash.
/// @param walletAddress Address that should have signed the given hash
/// and defines its own signature verification method.
/// @param signature Proof that the hash has been signed by signer.
/// @return True if the address recovered from the provided signature matches the input signer address.
function isValidWalletSignature(
bytes32 hash,
address walletAddress,
bytes signature
)
internal
view
returns (bool isValid);
/// @dev Verifies signature using logic defined by Validator contract.
/// @param validatorAddress Address of validator contract.
/// @param hash Any 32 byte hash.
/// @param signerAddress Address that should have signed the given hash.
/// @param signature Proof that the hash has been signed by signer.
/// @return True if the address recovered from the provided signature matches the input signer address.
function isValidValidatorSignature(
address validatorAddress,
bytes32 hash,
address signerAddress,
bytes signature
)
internal
view
returns (bool isValid);
}

View File

@@ -23,6 +23,28 @@ import "../interfaces/ITransactions.sol";
contract MTransactions is
ITransactions
{
// Hash for the EIP712 ZeroEx Transaction Schema
bytes32 constant internal EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = keccak256(abi.encodePacked(
"ZeroExTransaction(",
"uint256 salt,",
"address signerAddress,",
"bytes data",
")"
));
/// @dev Calculates EIP712 hash of the Transaction.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash.
/// @param signerAddress Address of transaction signer.
/// @param data AbiV2 encoded calldata.
/// @return EIP712 hash of the Transaction.
function hashZeroExTransaction(
uint256 salt,
address signerAddress,
bytes memory data
)
internal
pure
returns (bytes32 result);
/// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
/// If calling a fill function, this address will represent the taker.

View File

@@ -0,0 +1,41 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
import "../interfaces/IWrapperFunctions.sol";
contract MWrapperFunctions is
IWrapperFunctions
{
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
/// @param order LibOrder.Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
/// @param signature Proof that order has been created by maker.
function fillOrKillOrderInternal(
LibOrder.Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (LibFillResults.FillResults memory fillResults);
}

View File

@@ -0,0 +1,69 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "./DummyERC20Token.sol";
// solhint-disable no-empty-blocks
contract DummyMultipleReturnERC20Token is
DummyERC20Token
{
constructor (
string _name,
string _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
DummyERC20Token(
_name,
_symbol,
_decimals,
_totalSupply
)
{}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
emit Transfer(
_from,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return 64 bytes (equiavalent to true, true)
assembly {
mstore(0, 1)
mstore(32, 1)
return(0, 64)
}
}
}

View File

@@ -25,7 +25,6 @@ import "./DummyERC20Token.sol";
contract DummyNoReturnERC20Token is
DummyERC20Token
{
constructor (
string _name,
string _symbol,

View File

@@ -24,7 +24,6 @@ import "../../tokens/ERC721Token/IERC721Receiver.sol";
contract DummyERC721Receiver is
IERC721Receiver
{
// Function selector for ERC721Receiver.onERC721Received
// 0x150b7a02
bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));

View File

@@ -0,0 +1,188 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
import "../../tokens/ERC20Token/ERC20Token.sol";
import "../../protocol/Exchange/interfaces/IExchange.sol";
import "../../protocol/Exchange/libs/LibOrder.sol";
// solhint-disable no-unused-vars
contract ReentrantERC20Token is
ERC20Token
{
using LibBytes for bytes;
// solhint-disable-next-line var-name-mixedcase
IExchange internal EXCHANGE;
bytes internal constant REENTRANCY_ILLEGAL_REVERT_REASON = abi.encodeWithSelector(
bytes4(keccak256("Error(string)")),
"REENTRANCY_ILLEGAL"
);
// All of these functions are potentially vulnerable to reentrancy
// We do not test any "noThrow" functions because `fillOrderNoThrow` makes a delegatecall to `fillOrder`
enum ExchangeFunction {
FILL_ORDER,
FILL_OR_KILL_ORDER,
BATCH_FILL_ORDERS,
BATCH_FILL_OR_KILL_ORDERS,
MARKET_BUY_ORDERS,
MARKET_SELL_ORDERS,
MATCH_ORDERS,
CANCEL_ORDER,
BATCH_CANCEL_ORDERS,
CANCEL_ORDERS_UP_TO,
SET_SIGNATURE_VALIDATOR_APPROVAL
}
uint8 internal currentFunctionId = 0;
constructor (address _exchange)
public
{
EXCHANGE = IExchange(_exchange);
}
/// @dev Set the current function that will be called when `transferFrom` is called.
/// @param _currentFunctionId Id that corresponds to function name.
function setCurrentFunction(uint8 _currentFunctionId)
external
{
currentFunctionId = _currentFunctionId;
}
/// @dev A version of `transferFrom` that attempts to reenter the Exchange contract.
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
// This order would normally be invalid, but it will be used strictly for testing reentrnacy.
// Any reentrancy checks will happen before any other checks that invalidate the order.
LibOrder.Order memory order;
// Initialize remaining null parameters
bytes memory signature;
LibOrder.Order[] memory orders;
uint256[] memory takerAssetFillAmounts;
bytes[] memory signatures;
bytes memory calldata;
// Create calldata for function that corresponds to currentFunctionId
if (currentFunctionId == uint8(ExchangeFunction.FILL_ORDER)) {
calldata = abi.encodeWithSelector(
EXCHANGE.fillOrder.selector,
order,
0,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.FILL_OR_KILL_ORDER)) {
calldata = abi.encodeWithSelector(
EXCHANGE.fillOrKillOrder.selector,
order,
0,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_FILL_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.batchFillOrders.selector,
orders,
takerAssetFillAmounts,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_FILL_OR_KILL_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.batchFillOrKillOrders.selector,
orders,
takerAssetFillAmounts,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MARKET_BUY_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.marketBuyOrders.selector,
orders,
0,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MARKET_SELL_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.marketSellOrders.selector,
orders,
0,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MATCH_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.matchOrders.selector,
order,
order,
signature,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDER)) {
calldata = abi.encodeWithSelector(
EXCHANGE.cancelOrder.selector,
order
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_CANCEL_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.batchCancelOrders.selector,
orders
);
} else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDERS_UP_TO)) {
calldata = abi.encodeWithSelector(
EXCHANGE.cancelOrdersUpTo.selector,
0
);
} else if (currentFunctionId == uint8(ExchangeFunction.SET_SIGNATURE_VALIDATOR_APPROVAL)) {
calldata = abi.encodeWithSelector(
EXCHANGE.setSignatureValidatorApproval.selector,
address(0),
false
);
}
// Call Exchange function, swallow error
address(EXCHANGE).call(calldata);
// Revert reason is 100 bytes
bytes memory returnData = new bytes(100);
// Copy return data
assembly {
returndatacopy(add(returnData, 32), 0, 100)
}
// Revert if function reverted with REENTRANCY_ILLEGAL error
require(!REENTRANCY_ILLEGAL_REVERT_REASON.equals(returnData));
// Transfer will return true if function failed for any other reason
return true;
}
}

View File

@@ -16,7 +16,7 @@
*/
pragma solidity 0.4.10;
pragma solidity 0.4.24;
import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol";
@@ -25,8 +25,7 @@ import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol";
contract TestAssetProxyOwner is
AssetProxyOwner
{
function TestAssetProxyOwner(
constructor (
address[] memory _owners,
address[] memory _assetProxyContracts,
uint256 _required,
@@ -38,6 +37,7 @@ contract TestAssetProxyOwner is
function testValidRemoveAuthorizedAddressAtIndexTx(uint256 id)
public
view
validRemoveAuthorizedAddressAtIndexTx(id)
returns (bool)
{
@@ -50,23 +50,9 @@ contract TestAssetProxyOwner is
/// @return Successful if data is a call to `removeAuthorizedAddressAtIndex`.
function isFunctionRemoveAuthorizedAddressAtIndex(bytes memory data)
public
pure
returns (bool)
{
return readBytes4(data, 0) == REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR;
}
/// @dev Reads an unpadded bytes4 value from a position in a byte array.
/// @param b Byte array containing a bytes4 value.
/// @param index Index in byte array of bytes4 value.
/// @return bytes4 value from byte array.
function publicReadBytes4(
bytes memory b,
uint256 index
)
public
returns (bytes4 result)
{
result = readBytes4(b, index);
return result;
return data.readBytes4(0) == REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR;
}
}

View File

@@ -63,11 +63,12 @@ contract TestExchangeInternals is
}
/// @dev Calculates partial value given a numerator and denominator.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target.
function publicGetPartialAmount(
function publicSafeGetPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -76,15 +77,67 @@ contract TestExchangeInternals is
pure
returns (uint256 partialAmount)
{
return getPartialAmount(numerator, denominator, target);
return safeGetPartialAmountFloor(numerator, denominator, target);
}
/// @dev Checks if rounding error > 0.1%.
/// @dev Calculates partial value given a numerator and denominator.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target.
function publicSafeGetPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (uint256 partialAmount)
{
return safeGetPartialAmountCeil(numerator, denominator, target);
}
/// @dev Calculates partial value given a numerator and denominator.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target.
function publicGetPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (uint256 partialAmount)
{
return getPartialAmountFloor(numerator, denominator, target);
}
/// @dev Calculates partial value given a numerator and denominator.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return Partial value of target.
function publicGetPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (uint256 partialAmount)
{
return getPartialAmountCeil(numerator, denominator, target);
}
/// @dev Checks if rounding error >= 0.1%.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return Rounding error is present.
function publicIsRoundingError(
function publicIsRoundingErrorFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -93,7 +146,24 @@ contract TestExchangeInternals is
pure
returns (bool isError)
{
return isRoundingError(numerator, denominator, target);
return isRoundingErrorFloor(numerator, denominator, target);
}
/// @dev Checks if rounding error >= 0.1%.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return Rounding error is present.
function publicIsRoundingErrorCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (bool isError)
{
return isRoundingErrorCeil(numerator, denominator, target);
}
/// @dev Updates state with results of a fill order.

View File

@@ -31,7 +31,6 @@ contract TestLibs is
LibFillResults,
LibAbiEncoder
{
function publicAbiEncodeFillOrder(
Order memory order,
uint256 takerAssetFillAmount,
@@ -49,7 +48,7 @@ contract TestLibs is
return fillOrderCalldata;
}
function publicGetPartialAmount(
function publicGetPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -58,7 +57,7 @@ contract TestLibs is
pure
returns (uint256 partialAmount)
{
partialAmount = getPartialAmount(
partialAmount = getPartialAmountFloor(
numerator,
denominator,
target
@@ -66,7 +65,24 @@ contract TestLibs is
return partialAmount;
}
function publicIsRoundingError(
function publicGetPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (uint256 partialAmount)
{
partialAmount = getPartialAmountCeil(
numerator,
denominator,
target
);
return partialAmount;
}
function publicIsRoundingErrorFloor(
uint256 numerator,
uint256 denominator,
uint256 target
@@ -75,7 +91,24 @@ contract TestLibs is
pure
returns (bool isError)
{
isError = isRoundingError(
isError = isRoundingErrorFloor(
numerator,
denominator,
target
);
return isError;
}
function publicIsRoundingErrorCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
public
pure
returns (bool isError)
{
isError = isRoundingErrorCeil(
numerator,
denominator,
target

View File

@@ -26,7 +26,6 @@ contract TestSignatureValidator is
MixinSignatureValidator,
MixinTransactions
{
function publicIsValidSignature(
bytes32 hash,
address signer,

View File

@@ -0,0 +1,81 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "../../tokens/ERC20Token/IERC20Token.sol";
// solhint-disable no-unused-vars
contract TestStaticCallReceiver {
uint256 internal state = 1;
/// @dev Updates state and returns true. Intended to be used with `Validator` signature type.
/// @param hash Message hash that is signed.
/// @param signerAddress Address that should have signed the given hash.
/// @param signature Proof of signing.
/// @return Validity of order signature.
function isValidSignature(
bytes32 hash,
address signerAddress,
bytes signature
)
external
returns (bool isValid)
{
updateState();
return true;
}
/// @dev Updates state and returns true. Intended to be used with `Wallet` signature type.
/// @param hash Message hash that is signed.
/// @param signature Proof of signing.
/// @return Validity of order signature.
function isValidSignature(
bytes32 hash,
bytes signature
)
external
returns (bool isValid)
{
updateState();
return true;
}
/// @dev Approves an ERC20 token to spend tokens from this address.
/// @param token Address of ERC20 token.
/// @param spender Address that will spend tokens.
/// @param value Amount of tokens spender is approved to spend.
function approveERC20(
address token,
address spender,
uint256 value
)
external
{
IERC20Token(token).approve(spender, value);
}
/// @dev Increments state variable.
function updateState()
internal
{
state++;
}
}

View File

@@ -24,7 +24,6 @@ import "./IERC20Token.sol";
contract ERC20Token is
IERC20Token
{
mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed;

View File

@@ -26,7 +26,6 @@ contract MintableERC20Token is
SafeMath,
UnlimitedAllowanceERC20Token
{
/// @dev Mints new tokens
/// @param _to Address of the beneficiary that will own the minted token
/// @param _value Amount of tokens to mint

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