Compare commits
373 Commits
@0xproject
...
@0xproject
Author | SHA1 | Date | |
---|---|---|---|
|
b5d88079d9 | ||
|
266440f7c3 | ||
|
ab28e6af35 | ||
|
63d97f4c88 | ||
|
2da7626b53 | ||
|
98db4b1543 | ||
|
bc067baf0d | ||
|
3624c63a46 | ||
|
08ba4ffd61 | ||
|
d5379ab320 | ||
|
c613b6741d | ||
|
4394036e34 | ||
|
a7a007435c | ||
|
24e0fbd7b9 | ||
|
059162a90a | ||
|
250a9a4809 | ||
|
f7917cfa65 | ||
|
10f54893ef | ||
|
93736c1567 | ||
|
260db053fe | ||
|
57b4396193 | ||
|
a21cf0ad83 | ||
|
748091c768 | ||
|
f614a2425f | ||
|
39a336ca6d | ||
|
37c55302e7 | ||
|
bce43a0050 | ||
|
678deccfca | ||
|
81b08c0339 | ||
|
efe173e4f7 | ||
|
cca12b7170 | ||
|
49e494ab8d | ||
|
42083e1408 | ||
|
3cd7253f7b | ||
|
343b922ec1 | ||
|
6deb027bdf | ||
|
ad56c9ea78 | ||
|
dde918e9a0 | ||
|
8990b92dd6 | ||
|
75679835a7 | ||
|
2540660262 | ||
|
75d6970e6c | ||
|
98c1952956 | ||
|
b3a868da0e | ||
|
20f18c3054 | ||
|
a64bee9f83 | ||
|
f1ecb8c5cb | ||
|
a4153144db | ||
|
d6e0dc4bd2 | ||
|
fed7e0c858 | ||
|
8ee34c49a9 | ||
|
194a5de564 | ||
|
cc7710abd2 | ||
|
10f3ee32a4 | ||
|
8c985eb579 | ||
|
3a93c8a6e0 | ||
|
86cc98b245 | ||
|
ddc0813d90 | ||
|
a02e6c0441 | ||
|
52ac84335c | ||
|
97616eb8e4 | ||
|
9e3d1cd63d | ||
|
f4e4eef48e | ||
|
16720d4fc7 | ||
|
f884cc826f | ||
|
1059acf56f | ||
|
c3be851c18 | ||
|
00051ae5bb | ||
|
9ad4a135d2 | ||
|
f80faf0b48 | ||
|
8b7888b736 | ||
|
a9ec51ac10 | ||
|
c1fb0d7fdf | ||
|
67e689158f | ||
|
dbbf04bc7d | ||
|
bad6761e13 | ||
|
6ffdc318e7 | ||
|
de7470d936 | ||
|
b9eb2b3918 | ||
|
2b6a9911f5 | ||
|
005b7a55e8 | ||
|
ac14dd2b29 | ||
|
c354129b6f | ||
|
c7e26cd448 | ||
|
033340e304 | ||
|
9ae60d0abe | ||
|
2471e10346 | ||
|
005a2e12ba | ||
|
6dff24906e | ||
|
398b292636 | ||
|
545472a38f | ||
|
28f5cd0641 | ||
|
144561c53b | ||
|
a737cfa004 | ||
|
21f6072186 | ||
|
94badedad4 | ||
|
8531f52456 | ||
|
092b184f45 | ||
|
b2ff7bda02 | ||
|
e0ff3484cf | ||
|
95e84aae49 | ||
|
338b7d2ec0 | ||
|
37ab789e84 | ||
|
957af23a64 | ||
|
d4077ae970 | ||
|
17d4b467d4 | ||
|
ac878d8fdb | ||
|
ac04dbf7e4 | ||
|
cfddea931d | ||
|
a6672e0190 | ||
|
5347bf587f | ||
|
63ffdb3895 | ||
|
e7b1374f23 | ||
|
ceff5c9c2b | ||
|
dddfe8ae50 | ||
|
c0498944c3 | ||
|
5cc11912a7 | ||
|
bf3795d2ac | ||
|
bc48bc99c3 | ||
|
51bfd1ca5e | ||
|
9160cd4983 | ||
|
c55a419178 | ||
|
63d79faa85 | ||
|
70e412e375 | ||
|
a51919db0e | ||
|
60971be35a | ||
|
cb99ebf78a | ||
|
6f02a3f40d | ||
|
0591f1d32a | ||
|
1402119c84 | ||
|
a162281529 | ||
|
8c18a8fefc | ||
|
48f6452c3b | ||
|
bd002caadd | ||
|
d6090921a8 | ||
|
78a693e092 | ||
|
3f61d27656 | ||
|
30525d15f4 | ||
|
c429409ed7 | ||
|
2bdaa58d71 | ||
|
75826fd559 | ||
|
0ce6f03ed5 | ||
|
5d73eebf6a | ||
|
13aa98f0f3 | ||
|
4a94f8b1ca | ||
|
f8532b3f51 | ||
|
b244f3e2c0 | ||
|
f33ecfd2fc | ||
|
f15751d800 | ||
|
e5e439adb9 | ||
|
2d8f423cee | ||
|
5905fdb73b | ||
|
4ed9323804 | ||
|
d77c6e13b0 | ||
|
4e10f2c6f2 | ||
|
d3edb9721c | ||
|
1b35a6e3b5 | ||
|
900a8aee76 | ||
|
de9f5d350f | ||
|
e45f0b0eaf | ||
|
2e7b218f40 | ||
|
7fbfd9ccd9 | ||
|
1db5ff617f | ||
|
ac5376a1ca | ||
|
600ffd93a6 | ||
|
22597674d2 | ||
|
adf5acd5c4 | ||
|
055bcb52f8 | ||
|
6174267f69 | ||
|
e8c8d3e722 | ||
|
d20f713fad | ||
|
b40861747b | ||
|
b73df28454 | ||
|
5afc739397 | ||
|
9eecf3683b | ||
|
7570f3db51 | ||
|
04dd4ce6d1 | ||
|
977d55c61b | ||
|
ebe731ea86 | ||
|
b853f04972 | ||
|
49cdd85b1d | ||
|
47f8b5d6fc | ||
|
78ef98c27c | ||
|
411813d8d9 | ||
|
64f41259eb | ||
|
fc3acec669 | ||
|
b85db17e75 | ||
|
a05530f821 | ||
|
173b36c54c | ||
|
55ca971186 | ||
|
284930eb58 | ||
|
902691e289 | ||
|
0afe55f2ff | ||
|
21910a7129 | ||
|
9c89d1e99b | ||
|
408f573188 | ||
|
574270d061 | ||
|
9af5e3ba8e | ||
|
89033e01e8 | ||
|
6f2ab23bd0 | ||
|
264b25c58d | ||
|
2116548eed | ||
|
57fca16d7b | ||
|
a900255820 | ||
|
bd7565ceda | ||
|
880cd6e440 | ||
|
b830c28d83 | ||
|
4a316571ff | ||
|
5e1a2bd972 | ||
|
fc33eacd2c | ||
|
748a8a8ae3 | ||
|
7516959c9f | ||
|
311b925919 | ||
|
5d88a56452 | ||
|
ebddf82819 | ||
|
d0448c2bbd | ||
|
d8d1c98a40 | ||
|
f49b231e91 | ||
|
7a43e19116 | ||
|
e4b664bafa | ||
|
98d06d6d25 | ||
|
9f0dfb1e1a | ||
|
37cb18e1da | ||
|
3e5d427d4e | ||
|
8bce407aec | ||
|
7a5376621f | ||
|
29f6adc2ed | ||
|
5446de6308 | ||
|
5e84e9689f | ||
|
9540db2aad | ||
|
7dd28d6fab | ||
|
1bfaefb240 | ||
|
c48cf3ab3b | ||
|
c64dcec772 | ||
|
45dc2be083 | ||
|
31f6fc065f | ||
|
8dea48ebef | ||
|
97150cf55f | ||
|
b0484eafe3 | ||
|
1b799e98e8 | ||
|
e6840c60c7 | ||
|
ba59879e7f | ||
|
f3deabccf4 | ||
|
393f9e5a29 | ||
|
c10807c4e3 | ||
|
4e8ec2359d | ||
|
79cf6969f9 | ||
|
3167bfde1a | ||
|
cbd72b6e3d | ||
|
fcca63a2dc | ||
|
90e28220fa | ||
|
35c324f67c | ||
|
301e491952 | ||
|
03e18ff7c6 | ||
|
d23487bda9 | ||
|
3238925aa4 | ||
|
abd308455a | ||
|
a44f77a838 | ||
|
5b6c91bb3f | ||
|
6701ec68bd | ||
|
7b259c3f4c | ||
|
ecbdf5f12b | ||
|
3e70ab015b | ||
|
dab7f1a739 | ||
|
f6438725eb | ||
|
a03b1d4d6c | ||
|
14345ab24e | ||
|
60e2dfdbda | ||
|
83ffbd05be | ||
|
88be6b5e0d | ||
|
aa47f85f48 | ||
|
fec9c8f1c6 | ||
|
93f7e33f6a | ||
|
fd4b4f8f82 | ||
|
0003666050 | ||
|
b947609ff1 | ||
|
38afd108f8 | ||
|
65f709d50a | ||
|
f5dbf212e3 | ||
|
f6e1bf78c8 | ||
|
950f279508 | ||
|
e46807c28b | ||
|
e2559798df | ||
|
ccc18620bf | ||
|
febe00db4f | ||
|
6f36048a8e | ||
|
2457ecb7e7 | ||
|
30622631ff | ||
|
4bab402e95 | ||
|
91de15d50e | ||
|
d40a670d0b | ||
|
4ade674ada | ||
|
401ef2edef | ||
|
9201273939 | ||
|
5b07669bd0 | ||
|
3c7155afb0 | ||
|
2378747570 | ||
|
a75981da14 | ||
|
d5f964b58e | ||
|
2df569b727 | ||
|
65aecc0024 | ||
|
074082ec94 | ||
|
6b9f0af828 | ||
|
bfabf765e3 | ||
|
e74f736eff | ||
|
45483557a5 | ||
|
a22d2dc7ee | ||
|
9ec2b5a2d5 | ||
|
af40989f5f | ||
|
d57619b5db | ||
|
c692115cdc | ||
|
dfe58e4975 | ||
|
4e59be9afc | ||
|
190bf2599c | ||
|
f1a22e9bd7 | ||
|
7b46cef83d | ||
|
8da7d39998 | ||
|
91702bbae2 | ||
|
90674d9038 | ||
|
c0a14a4a41 | ||
|
8d6132736b | ||
|
8687b9533c | ||
|
07942a7aec | ||
|
3d1b7c10e8 | ||
|
cf46d2c704 | ||
|
4434856add | ||
|
52d511df21 | ||
|
50f58f9121 | ||
|
7a20c7b946 | ||
|
ce0e60ed84 | ||
|
4ad0a6c7b7 | ||
|
b8d8651e43 | ||
|
cbb5a425df | ||
|
45b68832aa | ||
|
6dfcaaf889 | ||
|
8131c5d6bc | ||
|
df5779b6d1 | ||
|
4a5a0c8c78 | ||
|
b3a17624c8 | ||
|
e63841a604 | ||
|
7ec95e8c29 | ||
|
b217495465 | ||
|
db6ddc0c4b | ||
|
800dd5fb4f | ||
|
3dc4eb4421 | ||
|
75664b6651 | ||
|
327b4ba554 | ||
|
50b725c687 | ||
|
72419816a8 | ||
|
9a4e6da02f | ||
|
823b6c4d7d | ||
|
8d122006ba | ||
|
0e45497acb | ||
|
fe7a62ba9a | ||
|
b88a56e6b7 | ||
|
297cbd996d | ||
|
f55234b4a0 | ||
|
f76c88c549 | ||
|
863966787f | ||
|
7ed31d2fba | ||
|
6273339f7c | ||
|
29f2ae605e | ||
|
6450844d7f | ||
|
9834395a48 | ||
|
f429032eef | ||
|
5088b7f23c | ||
|
28246abec3 | ||
|
a1959df911 | ||
|
775d1efd46 | ||
|
849e203812 | ||
|
80ed724f3a | ||
|
5c056b57b7 | ||
|
4779ebfd20 |
@@ -2,6 +2,7 @@ version: 2
|
||||
|
||||
jobs:
|
||||
build:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
environment:
|
||||
@@ -10,34 +11,26 @@ jobs:
|
||||
steps:
|
||||
- checkout
|
||||
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
|
||||
- restore_cache:
|
||||
name: Restore Yarn Package Cache
|
||||
keys:
|
||||
- yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
||||
- yarn-packages-{{ .Branch }}
|
||||
- yarn-packages-master
|
||||
- yarn-packages-
|
||||
- run:
|
||||
name: install-yarn
|
||||
command: sudo npm install --global yarn@1.9.4
|
||||
- run:
|
||||
name: yarn
|
||||
command: yarn --frozen-lockfile install || yarn --frozen-lockfile install
|
||||
- save_cache:
|
||||
name: Save Yarn Package Cache
|
||||
key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
||||
paths:
|
||||
- node_modules/
|
||||
- run: >
|
||||
if [ -z "$(git diff --name-only development packages/website)" ]; then
|
||||
yarn build --exclude website
|
||||
else
|
||||
yarn build
|
||||
fi
|
||||
- run: yarn build:ci:no_website
|
||||
- save_cache:
|
||||
key: repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo
|
||||
build-website:
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: cd packages/website && yarn build
|
||||
test-contracts-ganache:
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
@@ -50,7 +43,7 @@ jobs:
|
||||
test-contracts-geth:
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
- image: albrow/0x-devnet
|
||||
- image: 0xorg/devnet
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -60,9 +53,10 @@ jobs:
|
||||
# initialized
|
||||
- run: sleep 10 && TEST_PROVIDER=geth yarn wsrun test contracts
|
||||
test-publish:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
- image: verdaccio/verdaccio
|
||||
- image: 0xorg/verdaccio
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -98,6 +92,7 @@ jobs:
|
||||
- run: yarn wsrun test:circleci @0xproject/order-watcher
|
||||
- run: yarn wsrun test:circleci @0xproject/sol-compiler
|
||||
- run: yarn wsrun test:circleci @0xproject/sol-cov
|
||||
- run: yarn wsrun test:circleci @0xproject/sol-doc
|
||||
- run: yarn wsrun test:circleci @0xproject/sra-report
|
||||
- run: yarn wsrun test:circleci @0xproject/subproviders
|
||||
- run: yarn wsrun test:circleci @0xproject/web3-wrapper
|
||||
@@ -150,6 +145,10 @@ jobs:
|
||||
key: coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/sol-cov/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-sol-doc-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/sol-doc/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-sra-report-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
@@ -170,8 +169,10 @@ jobs:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn prettier:ci
|
||||
- run: yarn lerna run lint
|
||||
- run: yarn prettier:ci
|
||||
- run: cd packages/0x.js && yarn build:umd:prod
|
||||
- run: yarn bundlesize
|
||||
submit-coverage:
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
@@ -216,6 +217,9 @@ jobs:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-sol-doc-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-sra-report-{{ .Environment.CIRCLE_SHA1 }}
|
||||
@@ -234,6 +238,9 @@ workflows:
|
||||
main:
|
||||
jobs:
|
||||
- build
|
||||
- build-website:
|
||||
requires:
|
||||
- build
|
||||
- test-contracts-ganache:
|
||||
requires:
|
||||
- build
|
||||
|
@@ -27,15 +27,16 @@ If you're developing on 0x now or are interested in using 0x infrastructure in t
|
||||
| [`@0xproject/assert`](/packages/assert) | [](https://www.npmjs.com/package/@0xproject/assert) | Type and schema assertions used by our packages |
|
||||
| [`@0xproject/base-contract`](/packages/base-contract) | [](https://www.npmjs.com/package/@0xproject/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts |
|
||||
| [`@0xproject/connect`](/packages/connect) | [](https://www.npmjs.com/package/@0xproject/connect) | A Javascript library for interacting with the Standard Relayer API |
|
||||
| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [](https://www.npmjs.com/package/@0xproject/sol-compiler) | A thin wrapper around Solc.js that outputs artifacts, resolves imports, only re-compiles when needed, and other niceties. |
|
||||
| [`@0xproject/dev-utils`](/packages/dev-utils) | [](https://www.npmjs.com/package/@0xproject/dev-utils) | Dev utils to be shared across 0x projects and packages |
|
||||
| [`@0xproject/json-schemas`](/packages/json-schemas) | [](https://www.npmjs.com/package/@0xproject/json-schemas) | 0x-related json schemas |
|
||||
| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts |
|
||||
| [`@0xproject/order-utils`](/packages/order-utils) | [](https://www.npmjs.com/package/@0xproject/order-utils) | A set of utilities for generating, parsing, signing and validating 0x orders. |
|
||||
| [`@0xproject/react-docs`](/packages/react-docs) | [](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON |
|
||||
| [`@0xproject/react-shared`](/packages/react-shared) | [](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components |
|
||||
| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [](https://www.npmjs.com/package/@0xproject/sol-compiler) | A thin wrapper around Solc.js that outputs artifacts, resolves imports, only re-compiles when needed, and other niceties. |
|
||||
| [`@0xproject/sol-cov`](/packages/sol-cov) | [](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool |
|
||||
| [`@0xproject/sra-spec`](/packages/sra-spec) | [](https://www.npmjs.com/package/@0xproject/sra-spec) | OpenAPI specification for the standard relayer API |
|
||||
| [`@0xproject/sra-report`](/packages/sra-report) | [](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance |
|
||||
| [`@0xproject/sol-cov`](/packages/sol-cov) | [](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool |
|
||||
| [`@0xproject/subproviders`](/packages/subproviders) | [](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) |
|
||||
| [`@0xproject/tslint-config`](/packages/tslint-config) | [](https://www.npmjs.com/package/@0xproject/tslint-config) | Custom 0x development TSLint rules |
|
||||
| [`@0xproject/types`](/packages/types) | [](https://www.npmjs.com/package/@0xproject/types) | Shared type declarations |
|
||||
|
17
package.json
17
package.json
@@ -25,6 +25,7 @@
|
||||
"lerna": "lerna",
|
||||
"build": "wsrun build $PKG --fast-exit -r --stages",
|
||||
"build:no_website": "wsrun build $PKG --fast-exit -r --stages --exclude @0xproject/website",
|
||||
"build:ci:no_website": "wsrun build:ci $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",
|
||||
@@ -35,16 +36,25 @@
|
||||
"test": "wsrun test $PKG --fast-exit --serial --exclude-missing",
|
||||
"generate_doc": "node ./packages/monorepo-scripts/lib/doc_generate_and_upload.js",
|
||||
"test:generate_docs:circleci": "for i in ${npm_package_config_packagesWithDocPages}; do yarn generate_doc --package $i --shouldUpload false --isStaging true || break -1; done;",
|
||||
"lint": "wsrun lint $PKG --fast-exit --parallel --exclude-missing",
|
||||
"comment:postinstall": "HACK: For some reason `yarn` is not setting up symlinks properly for order-utils. We temporarily set them manually. Remove this after V2 refactor is complete."
|
||||
"bundlesize": "bundlesize",
|
||||
"lint": "wsrun lint $PKG --fast-exit --parallel --exclude-missing"
|
||||
},
|
||||
"config": {
|
||||
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic",
|
||||
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-cov ethereum-types"
|
||||
},
|
||||
"bundlesize": [
|
||||
{
|
||||
"path": "packages/0x.js/_bundles/index.min.js"
|
||||
},
|
||||
{
|
||||
"path": "packages/instant/public/main.bundle.js"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"@0x-lerna-fork/lerna": "3.0.0-beta.25",
|
||||
"async-child-process": "^1.1.1",
|
||||
"bundlesize": "^0.17.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"ganache-cli": "6.1.3",
|
||||
"lcov-result-merger": "^3.0.0",
|
||||
@@ -54,8 +64,5 @@
|
||||
"source-map-support": "^0.5.6",
|
||||
"typescript": "3.0.1",
|
||||
"wsrun": "^2.2.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"ethers": "0xproject/ethers.js#eip-838-reasons"
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ webpack.config.js
|
||||
yarn-error.log
|
||||
test/
|
||||
/src/
|
||||
/_bundles/
|
||||
/contract_templates/
|
||||
/generated_docs/
|
||||
/scripts/
|
||||
|
@@ -1,4 +1,67 @@
|
||||
[
|
||||
{
|
||||
"version": "1.0.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Drastically reduce the bundle size by removing unused parts of included contract artifacts."
|
||||
}
|
||||
],
|
||||
"timestamp": 1537369748
|
||||
},
|
||||
{
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add ZRX & WETH mainnet contract addresses into the included artifacts"
|
||||
}
|
||||
],
|
||||
"timestamp": 1537265493
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.1",
|
||||
|
@@ -5,6 +5,34 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.8 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.7 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.6 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.5 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.3 - _September 19, 2018_
|
||||
|
||||
* Drastically reduce the bundle size by removing unused parts of included contract artifacts.
|
||||
|
||||
## v1.0.2 - _September 18, 2018_
|
||||
|
||||
* Add ZRX & WETH mainnet contract addresses into the included artifacts
|
||||
|
||||
## v1.0.1 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -21,7 +49,7 @@ CHANGELOG
|
||||
|
||||
* 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)
|
||||
|
||||
## v1.0.1-rc.3 - _August 14, 2018_
|
||||
## v1.0.1-rc.3 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
* Update ecSignOrderHashAsync to return the signature as a string for immediate use in contracts (#914)
|
||||
@@ -38,11 +66,11 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0-rc.2 - _July 20, 2018_
|
||||
## v1.0.0-rc.2 - _July 19, 2018_
|
||||
|
||||
* Remove `zeroEx.assetData` and instead re-export it's static functions directly off `ZeroEx`
|
||||
|
||||
## v1.0.0-rc.1 - _July 20, 2018_
|
||||
## v1.0.0-rc.1 - _July 19, 2018_
|
||||
|
||||
* Remove tokenRegistry wrapper (#863)
|
||||
* Rename `zeroEx.token` to `zeroEx.erc20Token`, and add `zeroEx.erc721Token` (#863)
|
||||
@@ -82,7 +110,7 @@ CHANGELOG
|
||||
* Renamed createOrderStateWatcher to createOrderWatcherAsync since it is now async (#579)
|
||||
* Renamed ZeroExError to ContractWrappersErrors since they now lives in the @0xproject/contract-wrappers subpackage (#579)
|
||||
|
||||
## v0.37.2 - _May 5, 2018_
|
||||
## v0.37.2 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
## 0x.js
|
||||
|
||||
A TypeScript/Javascript library for interacting with the 0x protocol.
|
||||
A TypeScript/Javascript library for interacting with the 0x protocol. It is a high level package which combines a number of underlying packages such as order-utils and order-watcher.
|
||||
|
||||
### Read the [Documentation](https://0xproject.com/docs/0x.js).
|
||||
|
||||
@@ -19,7 +19,14 @@ npm install 0x.js --save
|
||||
**Import**
|
||||
|
||||
```javascript
|
||||
import { ZeroEx } from '0x.js';
|
||||
import {
|
||||
assetDataUtils,
|
||||
BigNumber,
|
||||
ContractWrappers,
|
||||
generatePseudoRandomSalt,
|
||||
orderHashUtils,
|
||||
signatureUtils,
|
||||
} from '0x.js';
|
||||
```
|
||||
|
||||
If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "0x.js",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.8",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -16,6 +16,7 @@
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "yarn build:all",
|
||||
"build:ci": "yarn build:commonjs",
|
||||
"build:all": "run-p build:umd:prod build:commonjs",
|
||||
"lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*",
|
||||
"test:circleci": "run-s test:coverage",
|
||||
@@ -41,23 +42,22 @@
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@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",
|
||||
"@0xproject/abi-gen": "^1.0.13",
|
||||
"@0xproject/dev-utils": "^1.0.12",
|
||||
"@0xproject/migrations": "^1.0.14",
|
||||
"@0xproject/monorepo-scripts": "^1.0.11",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/node": "*",
|
||||
"@types/sinon": "^2.2.2",
|
||||
"@types/web3-provider-engine": "^14.0.0",
|
||||
"awesome-typescript-loader": "^3.1.3",
|
||||
"awesome-typescript-loader": "^5.2.1",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-bignumber": "^2.0.1",
|
||||
"copyfiles": "^2.0.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"json-loader": "^0.5.4",
|
||||
"make-promises-safe": "^1.1.0",
|
||||
"mocha": "^4.1.0",
|
||||
"npm-run-all": "^4.1.2",
|
||||
@@ -69,22 +69,22 @@
|
||||
"tslint": "5.11.0",
|
||||
"typedoc": "0.12.0",
|
||||
"typescript": "3.0.1",
|
||||
"uglifyjs-webpack-plugin": "^1.3.0",
|
||||
"webpack": "^3.1.0"
|
||||
"uglifyjs-webpack-plugin": "^2.0.1",
|
||||
"webpack": "^4.20.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/contract-wrappers": "^2.0.2",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/order-watcher": "^2.1.1",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"ethers": "4.0.0-beta.14",
|
||||
"lodash": "^4.17.5",
|
||||
"web3-provider-engine": "14.0.6"
|
||||
},
|
||||
|
@@ -2,8 +2,7 @@
|
||||
* This is to generate the umd bundle only
|
||||
*/
|
||||
const _ = require('lodash');
|
||||
const webpack = require('webpack');
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const path = require('path');
|
||||
const production = process.env.NODE_ENV === 'production';
|
||||
|
||||
@@ -16,6 +15,7 @@ if (production) {
|
||||
|
||||
module.exports = {
|
||||
entry,
|
||||
mode: 'production',
|
||||
output: {
|
||||
path: path.resolve(__dirname, '_bundles'),
|
||||
filename: '[name].js',
|
||||
@@ -27,19 +27,18 @@ module.exports = {
|
||||
extensions: ['.ts', '.js', '.json'],
|
||||
},
|
||||
devtool: 'source-map',
|
||||
plugins: [
|
||||
// TODO: Revert to webpack bundled version with webpack v4.
|
||||
// The v3 series bundled version does not support ES6 and
|
||||
// fails to build.
|
||||
new UglifyJsPlugin({
|
||||
sourceMap: true,
|
||||
uglifyOptions: {
|
||||
mangle: {
|
||||
reserved: ['BigNumber'],
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
sourceMap: true,
|
||||
terserOptions: {
|
||||
mangle: {
|
||||
reserved: ['BigNumber'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
@@ -59,10 +58,6 @@ module.exports = {
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.json$/,
|
||||
loader: 'json-loader',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
@@ -1,4 +1,49 @@
|
||||
[
|
||||
{
|
||||
"version": "1.0.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.8",
|
||||
|
@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.13 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.12 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.11 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.10 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.9 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.8 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -17,7 +37,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.5 - _August 14, 2018_
|
||||
## v1.0.5 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -37,7 +57,7 @@ CHANGELOG
|
||||
|
||||
* Fix the abi-gen entry point in package.json (#901)
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Convert e_r_c to erc in generated file names (#822)
|
||||
* Remove the output directory before writing to it (#822)
|
||||
@@ -55,7 +75,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.3.1 - _June 1, 2018_
|
||||
## v0.3.1 - _May 31, 2018_
|
||||
|
||||
* Incorrect publish that was unpublished
|
||||
|
||||
@@ -63,7 +83,7 @@ CHANGELOG
|
||||
|
||||
* Properly export the executable binary (#588)
|
||||
|
||||
## v0.2.13 - _May 5, 2018_
|
||||
## v0.2.13 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/abi-gen",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.13",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -11,6 +11,7 @@
|
||||
"lint": "tslint --project .",
|
||||
"clean": "shx rm -rf lib",
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"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",
|
||||
@@ -30,10 +31,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md",
|
||||
"dependencies": {
|
||||
"@0xproject/typescript-typings": "^2.0.0",
|
||||
"@0xproject/utils": "^1.0.8",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"chalk": "^2.3.0",
|
||||
"ethereum-types": "^1.0.6",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"glob": "^7.1.2",
|
||||
"handlebars": "^4.0.11",
|
||||
"lodash": "^4.17.5",
|
||||
@@ -44,11 +45,11 @@
|
||||
"yargs": "^10.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/glob": "5.0.35",
|
||||
"@types/handlebars": "^4.0.36",
|
||||
"@types/mkdirp": "^0.5.1",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/node": "*",
|
||||
"@types/sleep": "^0.0.7",
|
||||
"@types/tmp": "^0.0.33",
|
||||
"@types/yargs": "^10.0.0",
|
||||
|
@@ -1,4 +1,49 @@
|
||||
[
|
||||
{
|
||||
"version": "1.0.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.8",
|
||||
|
@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.13 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.12 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.11 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.10 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.9 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.8 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -17,7 +37,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.5 - _August 14, 2018_
|
||||
## v1.0.5 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -37,7 +57,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Fix bug in string enum assertion. We erroneously were checking against the enum keys, not values (#821)
|
||||
|
||||
@@ -53,7 +73,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.2.11 - _June 1, 2018_
|
||||
## v0.2.11 - _May 31, 2018_
|
||||
|
||||
* Incorrect publish that was unpublished
|
||||
|
||||
@@ -61,7 +81,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.2.9 - _May 5, 2018_
|
||||
## v0.2.9 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/assert",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.13",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -9,6 +9,7 @@
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"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",
|
||||
@@ -28,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/assert/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/valid-url": "^1.0.2",
|
||||
@@ -44,9 +45,9 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/json-schemas": "^1.0.1",
|
||||
"@0xproject/typescript-typings": "^2.0.0",
|
||||
"@0xproject/utils": "^1.0.8",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"lodash": "^4.17.5",
|
||||
"valid-url": "^1.0.9"
|
||||
},
|
||||
|
60
packages/asset-buyer/CHANGELOG.json
Normal file
60
packages/asset-buyer/CHANGELOG.json
Normal file
@@ -0,0 +1,60 @@
|
||||
[
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Expand AssetBuyer to work with multiple assets at once",
|
||||
"pr": 1086
|
||||
},
|
||||
{
|
||||
"note": "Fix minRate and maxRate calculation",
|
||||
"pr": 1113
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538475601,
|
||||
"version": "1.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.0-rc.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Init"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
31
packages/asset-buyer/CHANGELOG.md
Normal file
31
packages/asset-buyer/CHANGELOG.md
Normal file
@@ -0,0 +1,31 @@
|
||||
<!--
|
||||
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
|
||||
Edit the package's CHANGELOG.json file only.
|
||||
-->
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v2.0.0 - _October 4, 2018_
|
||||
|
||||
* Expand AssetBuyer to work with multiple assets at once (#1086)
|
||||
* Fix minRate and maxRate calculation (#1113)
|
||||
|
||||
## v1.0.3 - _October 2, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.2 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0-rc.1 - _Invalid date_
|
||||
|
||||
* Init
|
85
packages/asset-buyer/README.md
Normal file
85
packages/asset-buyer/README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
## @0xproject/asset-buyer
|
||||
|
||||
**Warning: In Beta, has not been extensively tested.**
|
||||
|
||||
Convenience package for buying assets represented on the Ethereum blockchain using 0x. In its simplest form, the package helps in the usage of the [0x forwarder contract](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/forwarder-specification.md), which allows users to execute [Wrapped Ether](https://weth.io/) based 0x orders without having to set allowances, wrap Ether or own ZRX, meaning they can buy tokens with Ether alone. Given some liquidity (0x signed orders), it helps estimate the Ether cost of buying a certain asset (giving a range) and then buying that asset.
|
||||
|
||||
In its more advanced and useful form, it integrates with the [Standard Relayer API](https://github.com/0xProject/standard-relayer-api) and takes care of sourcing liquidity for you given an SRA compliant endpoint. The final result is a library that tells you what assets are available, provides an Ether based quote for any asset desired, and allows you to buy that asset using Ether alone.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
yarn add @0xproject/asset-buyer
|
||||
```
|
||||
|
||||
**Import**
|
||||
|
||||
```typescript
|
||||
import { AssetBuyer } from '@0xproject/asset-buyer';
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```javascript
|
||||
var AssetBuyer = require('@0xproject/asset-buyer').AssetBuyer;
|
||||
```
|
||||
|
||||
If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`:
|
||||
|
||||
```json
|
||||
"compilerOptions": {
|
||||
"typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"],
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
|
||||
|
||||
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
|
||||
|
||||
### Install dependencies
|
||||
|
||||
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
|
||||
|
||||
```bash
|
||||
yarn config set workspaces-experimental true
|
||||
```
|
||||
|
||||
Then install dependencies
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
|
||||
|
||||
```bash
|
||||
PKG=@0xproject/asset-buyer yarn build
|
||||
```
|
||||
|
||||
Or continuously rebuild on change:
|
||||
|
||||
```bash
|
||||
PKG=@0xproject/asset-buyer yarn watch
|
||||
```
|
||||
|
||||
### Clean
|
||||
|
||||
```bash
|
||||
yarn clean
|
||||
```
|
||||
|
||||
### Lint
|
||||
|
||||
```bash
|
||||
yarn lint
|
||||
```
|
||||
|
||||
### Run Tests
|
||||
|
||||
```bash
|
||||
yarn test
|
||||
```
|
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "@0xproject/forwarder-helper",
|
||||
"version": "1.0.1",
|
||||
"name": "@0xproject/asset-buyer",
|
||||
"version": "2.0.0",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
"description": "Convenience object for working with the forwarder contract",
|
||||
"description": "Convenience package for discovering and buying assets with Ether.",
|
||||
"main": "lib/src/index.js",
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
@@ -18,10 +18,8 @@
|
||||
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --exit",
|
||||
"clean": "shx rm -rf lib test_temp scripts",
|
||||
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
|
||||
"manual:postpublish": "yarn build; node ./scripts/postpublish.js",
|
||||
"docs:stage": "node scripts/stage_docs.js",
|
||||
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES",
|
||||
"upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json"
|
||||
"build:ci": "yarn build",
|
||||
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
|
||||
},
|
||||
"config": {
|
||||
"postpublish": {
|
||||
@@ -37,21 +35,26 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/0x-monorepo/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/forwarder-helper/README.md",
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/asset-buyer/README.md",
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@types/node": "^8.0.53",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/connect": "^3.0.1",
|
||||
"@0xproject/contract-wrappers": "^2.0.2",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"lodash": "^4.17.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "^4.14.116",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/node": "*",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-bignumber": "^2.0.1",
|
291
packages/asset-buyer/src/asset_buyer.ts
Normal file
291
packages/asset-buyer/src/asset_buyer.ts
Normal file
@@ -0,0 +1,291 @@
|
||||
import { ContractWrappers } from '@0xproject/contract-wrappers';
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { SignedOrder } from '@0xproject/order-utils';
|
||||
import { ObjectMap } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { Provider } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { BasicOrderProvider } from './order_providers/basic_order_provider';
|
||||
import { StandardRelayerAPIOrderProvider } from './order_providers/standard_relayer_api_order_provider';
|
||||
import {
|
||||
AssetBuyerError,
|
||||
AssetBuyerOpts,
|
||||
BuyQuote,
|
||||
BuyQuoteExecutionOpts,
|
||||
BuyQuoteRequestOpts,
|
||||
OrderProvider,
|
||||
OrderProviderResponse,
|
||||
OrdersAndFillableAmounts,
|
||||
} from './types';
|
||||
|
||||
import { assert } from './utils/assert';
|
||||
import { assetDataUtils } from './utils/asset_data_utils';
|
||||
import { buyQuoteCalculator } from './utils/buy_quote_calculator';
|
||||
import { orderProviderResponseProcessor } from './utils/order_provider_response_processor';
|
||||
|
||||
interface OrdersEntry {
|
||||
ordersAndFillableAmounts: OrdersAndFillableAmounts;
|
||||
lastRefreshTime: number;
|
||||
}
|
||||
|
||||
export class AssetBuyer {
|
||||
public readonly provider: Provider;
|
||||
public readonly orderProvider: OrderProvider;
|
||||
public readonly networkId: number;
|
||||
public readonly orderRefreshIntervalMs: number;
|
||||
public readonly expiryBufferSeconds: number;
|
||||
private readonly _contractWrappers: ContractWrappers;
|
||||
// cache of orders along with the time last updated keyed by assetData
|
||||
private readonly _ordersEntryMap: ObjectMap<OrdersEntry> = {};
|
||||
/**
|
||||
* Instantiates a new AssetBuyer instance given existing liquidity in the form of orders and feeOrders.
|
||||
* @param provider The Provider instance you would like to use for interacting with the Ethereum network.
|
||||
* @param orders A non-empty array of objects that conform to SignedOrder. All orders must have the same makerAssetData and takerAssetData (WETH).
|
||||
* @param feeOrders A array of objects that conform to SignedOrder. All orders must have the same makerAssetData (ZRX) and takerAssetData (WETH). Defaults to an empty array.
|
||||
* @param options Initialization options for the AssetBuyer. See type definition for details.
|
||||
*
|
||||
* @return An instance of AssetBuyer
|
||||
*/
|
||||
public static getAssetBuyerForProvidedOrders(
|
||||
provider: Provider,
|
||||
orders: SignedOrder[],
|
||||
feeOrders: SignedOrder[] = [],
|
||||
options: Partial<AssetBuyerOpts> = {},
|
||||
): AssetBuyer {
|
||||
assert.isWeb3Provider('provider', provider);
|
||||
assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
|
||||
assert.doesConformToSchema('feeOrders', feeOrders, schemas.signedOrdersSchema);
|
||||
assert.areValidProvidedOrders('orders', orders);
|
||||
assert.areValidProvidedOrders('feeOrders', feeOrders);
|
||||
assert.assert(orders.length !== 0, `Expected orders to contain at least one order`);
|
||||
const orderProvider = new BasicOrderProvider(_.concat(orders, feeOrders));
|
||||
const assetBuyer = new AssetBuyer(provider, orderProvider, options);
|
||||
return assetBuyer;
|
||||
}
|
||||
/**
|
||||
* Instantiates a new AssetBuyer instance given a [Standard Relayer API](https://github.com/0xProject/standard-relayer-api) endpoint
|
||||
* @param provider The Provider instance you would like to use for interacting with the Ethereum network.
|
||||
* @param sraApiUrl The standard relayer API base HTTP url you would like to source orders from.
|
||||
* @param options Initialization options for the AssetBuyer. See type definition for details.
|
||||
*
|
||||
* @return An instance of AssetBuyer
|
||||
*/
|
||||
public static getAssetBuyerForStandardRelayerAPIUrl(
|
||||
provider: Provider,
|
||||
sraApiUrl: string,
|
||||
options: Partial<AssetBuyerOpts> = {},
|
||||
): AssetBuyer {
|
||||
assert.isWeb3Provider('provider', provider);
|
||||
assert.isWebUri('sraApiUrl', sraApiUrl);
|
||||
const orderProvider = new StandardRelayerAPIOrderProvider(sraApiUrl);
|
||||
const assetBuyer = new AssetBuyer(provider, orderProvider, options);
|
||||
return assetBuyer;
|
||||
}
|
||||
/**
|
||||
* Instantiates a new AssetBuyer instance
|
||||
* @param provider The Provider instance you would like to use for interacting with the Ethereum network.
|
||||
* @param orderProvider An object that conforms to OrderProvider, see type for definition.
|
||||
* @param options Initialization options for the AssetBuyer. See type definition for details.
|
||||
*
|
||||
* @return An instance of AssetBuyer
|
||||
*/
|
||||
constructor(provider: Provider, orderProvider: OrderProvider, options: Partial<AssetBuyerOpts> = {}) {
|
||||
const { networkId, orderRefreshIntervalMs, expiryBufferSeconds } = {
|
||||
...constants.DEFAULT_ASSET_BUYER_OPTS,
|
||||
...options,
|
||||
};
|
||||
assert.isWeb3Provider('provider', provider);
|
||||
assert.isValidOrderProvider('orderProvider', orderProvider);
|
||||
assert.isNumber('networkId', networkId);
|
||||
assert.isNumber('orderRefreshIntervalMs', orderRefreshIntervalMs);
|
||||
assert.isNumber('expiryBufferSeconds', expiryBufferSeconds);
|
||||
this.provider = provider;
|
||||
this.orderProvider = orderProvider;
|
||||
this.networkId = networkId;
|
||||
this.orderRefreshIntervalMs = orderRefreshIntervalMs;
|
||||
this.expiryBufferSeconds = expiryBufferSeconds;
|
||||
this._contractWrappers = new ContractWrappers(this.provider, {
|
||||
networkId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get a `BuyQuote` containing all information relevant to fulfilling a buy given a desired assetData.
|
||||
* You can then pass the `BuyQuote` to `executeBuyQuoteAsync` to execute the buy.
|
||||
* @param assetData The assetData of the desired asset to buy (for more info: https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md).
|
||||
* @param assetBuyAmount The amount of asset to buy.
|
||||
* @param options Options for the request. See type definition for more information.
|
||||
*
|
||||
* @return An object that conforms to BuyQuote that satisfies the request. See type definition for more information.
|
||||
*/
|
||||
public async getBuyQuoteAsync(
|
||||
assetData: string,
|
||||
assetBuyAmount: BigNumber,
|
||||
options: Partial<BuyQuoteRequestOpts> = {},
|
||||
): Promise<BuyQuote> {
|
||||
const { feePercentage, shouldForceOrderRefresh, slippagePercentage } = {
|
||||
...constants.DEFAULT_BUY_QUOTE_REQUEST_OPTS,
|
||||
...options,
|
||||
};
|
||||
assert.isString('assetData', assetData);
|
||||
assert.isBigNumber('assetBuyAmount', assetBuyAmount);
|
||||
assert.isValidPercentage('feePercentage', feePercentage);
|
||||
assert.isBoolean('shouldForceOrderRefresh', shouldForceOrderRefresh);
|
||||
assert.isNumber('slippagePercentage', slippagePercentage);
|
||||
const zrxTokenAssetData = this._getZrxTokenAssetDataOrThrow();
|
||||
const [ordersAndFillableAmounts, feeOrdersAndFillableAmounts] = await Promise.all([
|
||||
this._getOrdersAndFillableAmountsAsync(assetData, shouldForceOrderRefresh),
|
||||
this._getOrdersAndFillableAmountsAsync(zrxTokenAssetData, shouldForceOrderRefresh),
|
||||
shouldForceOrderRefresh,
|
||||
]);
|
||||
if (ordersAndFillableAmounts.orders.length === 0) {
|
||||
throw new Error(`${AssetBuyerError.AssetUnavailable}: For assetData ${assetData}`);
|
||||
}
|
||||
const buyQuote = buyQuoteCalculator.calculate(
|
||||
ordersAndFillableAmounts,
|
||||
feeOrdersAndFillableAmounts,
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
slippagePercentage,
|
||||
);
|
||||
return buyQuote;
|
||||
}
|
||||
/**
|
||||
* Get a `BuyQuote` containing all information relevant to fulfilling a buy given a desired ERC20 token address.
|
||||
* You can then pass the `BuyQuote` to `executeBuyQuoteAsync` to execute the buy.
|
||||
* @param tokenAddress The ERC20 token address.
|
||||
* @param assetBuyAmount The amount of asset to buy.
|
||||
* @param options Options for the request. See type definition for more information.
|
||||
*
|
||||
* @return An object that conforms to BuyQuote that satisfies the request. See type definition for more information.
|
||||
*/
|
||||
public async getBuyQuoteForERC20TokenAddressAsync(
|
||||
tokenAddress: string,
|
||||
assetBuyAmount: BigNumber,
|
||||
options: Partial<BuyQuoteRequestOpts> = {},
|
||||
): Promise<BuyQuote> {
|
||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||
assert.isBigNumber('assetBuyAmount', assetBuyAmount);
|
||||
const assetData = assetDataUtils.encodeERC20AssetData(tokenAddress);
|
||||
const buyQuote = this.getBuyQuoteAsync(assetData, assetBuyAmount, options);
|
||||
return buyQuote;
|
||||
}
|
||||
/**
|
||||
* Given a BuyQuote and desired rate, attempt to execute the buy.
|
||||
* @param buyQuote An object that conforms to BuyQuote. See type definition for more information.
|
||||
* @param options Options for the execution of the BuyQuote. See type definition for more information.
|
||||
*
|
||||
* @return A promise of the txHash.
|
||||
*/
|
||||
public async executeBuyQuoteAsync(
|
||||
buyQuote: BuyQuote,
|
||||
options: Partial<BuyQuoteExecutionOpts> = {},
|
||||
): Promise<string> {
|
||||
const { ethAmount, takerAddress, feeRecipient } = {
|
||||
...constants.DEFAULT_BUY_QUOTE_EXECUTION_OPTS,
|
||||
...options,
|
||||
};
|
||||
assert.isValidBuyQuote('buyQuote', buyQuote);
|
||||
if (!_.isUndefined(ethAmount)) {
|
||||
assert.isBigNumber('ethAmount', ethAmount);
|
||||
}
|
||||
if (!_.isUndefined(takerAddress)) {
|
||||
assert.isETHAddressHex('takerAddress', takerAddress);
|
||||
}
|
||||
assert.isETHAddressHex('feeRecipient', feeRecipient);
|
||||
const { orders, feeOrders, feePercentage, assetBuyAmount, worstCaseQuoteInfo } = buyQuote;
|
||||
// if no takerAddress is provided, try to get one from the provider
|
||||
let finalTakerAddress;
|
||||
if (!_.isUndefined(takerAddress)) {
|
||||
finalTakerAddress = takerAddress;
|
||||
} else {
|
||||
const web3Wrapper = new Web3Wrapper(this.provider);
|
||||
const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const firstAvailableAddress = _.head(availableAddresses);
|
||||
if (!_.isUndefined(firstAvailableAddress)) {
|
||||
finalTakerAddress = firstAvailableAddress;
|
||||
} else {
|
||||
throw new Error(AssetBuyerError.NoAddressAvailable);
|
||||
}
|
||||
}
|
||||
// if no ethAmount is provided, default to the worst ethAmount from buyQuote
|
||||
const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
|
||||
orders,
|
||||
assetBuyAmount,
|
||||
finalTakerAddress,
|
||||
ethAmount || worstCaseQuoteInfo.totalEthAmount,
|
||||
feeOrders,
|
||||
feePercentage,
|
||||
feeRecipient,
|
||||
);
|
||||
return txHash;
|
||||
}
|
||||
/**
|
||||
* Grab orders from the map, if there is a miss or it is time to refresh, fetch and process the orders
|
||||
*/
|
||||
private async _getOrdersAndFillableAmountsAsync(
|
||||
assetData: string,
|
||||
shouldForceOrderRefresh: boolean,
|
||||
): Promise<OrdersAndFillableAmounts> {
|
||||
// try to get ordersEntry from the map
|
||||
const ordersEntryIfExists = this._ordersEntryMap[assetData];
|
||||
// we should refresh if:
|
||||
// we do not have any orders OR
|
||||
// we are forced to OR
|
||||
// we have some last refresh time AND that time was sufficiently long ago
|
||||
const shouldRefresh =
|
||||
_.isUndefined(ordersEntryIfExists) ||
|
||||
shouldForceOrderRefresh ||
|
||||
// tslint:disable:restrict-plus-operands
|
||||
ordersEntryIfExists.lastRefreshTime + this.orderRefreshIntervalMs < Date.now();
|
||||
if (!shouldRefresh) {
|
||||
const result = ordersEntryIfExists.ordersAndFillableAmounts;
|
||||
return result;
|
||||
}
|
||||
const etherTokenAssetData = this._getEtherTokenAssetDataOrThrow();
|
||||
const zrxTokenAssetData = this._getZrxTokenAssetDataOrThrow();
|
||||
// construct orderProvider request
|
||||
const orderProviderRequest = {
|
||||
makerAssetData: assetData,
|
||||
takerAssetData: etherTokenAssetData,
|
||||
networkId: this.networkId,
|
||||
};
|
||||
const request = orderProviderRequest;
|
||||
// get provider response
|
||||
const response = await this.orderProvider.getOrdersAsync(request);
|
||||
// since the order provider is an injected dependency, validate that it respects the API
|
||||
// ie. it should only return maker/taker assetDatas that are specified
|
||||
orderProviderResponseProcessor.throwIfInvalidResponse(response, request);
|
||||
// process the responses into one object
|
||||
const isMakerAssetZrxToken = assetData === zrxTokenAssetData;
|
||||
const ordersAndFillableAmounts = await orderProviderResponseProcessor.processAsync(
|
||||
response,
|
||||
isMakerAssetZrxToken,
|
||||
this.expiryBufferSeconds,
|
||||
this._contractWrappers.orderValidator,
|
||||
);
|
||||
const lastRefreshTime = Date.now();
|
||||
const updatedOrdersEntry = {
|
||||
ordersAndFillableAmounts,
|
||||
lastRefreshTime,
|
||||
};
|
||||
this._ordersEntryMap[assetData] = updatedOrdersEntry;
|
||||
return ordersAndFillableAmounts;
|
||||
}
|
||||
/**
|
||||
* Get the assetData that represents the WETH token.
|
||||
* Will throw if WETH does not exist for the current network.
|
||||
*/
|
||||
private _getEtherTokenAssetDataOrThrow(): string {
|
||||
return assetDataUtils.getEtherTokenAssetDataOrThrow(this._contractWrappers);
|
||||
}
|
||||
/**
|
||||
* Get the assetData that represents the ZRX token.
|
||||
* Will throw if ZRX does not exist for the current network.
|
||||
*/
|
||||
private _getZrxTokenAssetDataOrThrow(): string {
|
||||
return assetDataUtils.getZrxTokenAssetDataOrThrow(this._contractWrappers);
|
||||
}
|
||||
}
|
34
packages/asset-buyer/src/constants.ts
Normal file
34
packages/asset-buyer/src/constants.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { AssetBuyerOpts, BuyQuoteExecutionOpts, BuyQuoteRequestOpts } from './types';
|
||||
|
||||
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
const MAINNET_NETWORK_ID = 1;
|
||||
|
||||
const DEFAULT_ASSET_BUYER_OPTS: AssetBuyerOpts = {
|
||||
networkId: MAINNET_NETWORK_ID,
|
||||
orderRefreshIntervalMs: 10000, // 10 seconds
|
||||
expiryBufferSeconds: 15,
|
||||
};
|
||||
|
||||
const DEFAULT_BUY_QUOTE_REQUEST_OPTS: BuyQuoteRequestOpts = {
|
||||
feePercentage: 0,
|
||||
shouldForceOrderRefresh: false,
|
||||
slippagePercentage: 0.2, // 20% slippage protection
|
||||
};
|
||||
|
||||
// Other default values are dynamically determined
|
||||
const DEFAULT_BUY_QUOTE_EXECUTION_OPTS: BuyQuoteExecutionOpts = {
|
||||
feeRecipient: NULL_ADDRESS,
|
||||
};
|
||||
|
||||
export const constants = {
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
NULL_ADDRESS,
|
||||
MAINNET_NETWORK_ID,
|
||||
ETHER_TOKEN_DECIMALS: 18,
|
||||
DEFAULT_ASSET_BUYER_OPTS,
|
||||
DEFAULT_BUY_QUOTE_EXECUTION_OPTS,
|
||||
DEFAULT_BUY_QUOTE_REQUEST_OPTS,
|
||||
MAX_PER_PAGE: 10000,
|
||||
};
|
18
packages/asset-buyer/src/index.ts
Normal file
18
packages/asset-buyer/src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export { Provider } from 'ethereum-types';
|
||||
export { SignedOrder } from '@0xproject/types';
|
||||
export { BigNumber } from '@0xproject/utils';
|
||||
|
||||
export { AssetBuyer } from './asset_buyer';
|
||||
export { BasicOrderProvider } from './order_providers/basic_order_provider';
|
||||
export { StandardRelayerAPIOrderProvider } from './order_providers/standard_relayer_api_order_provider';
|
||||
export {
|
||||
AssetBuyerError,
|
||||
AssetBuyerOpts,
|
||||
BuyQuote,
|
||||
BuyQuoteExecutionOpts,
|
||||
BuyQuoteRequestOpts,
|
||||
OrderProvider,
|
||||
OrderProviderRequest,
|
||||
OrderProviderResponse,
|
||||
SignedOrderWithRemainingFillableMakerAssetAmount,
|
||||
} from './types';
|
@@ -0,0 +1,32 @@
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { OrderProvider, OrderProviderRequest, OrderProviderResponse } from '../types';
|
||||
import { assert } from '../utils/assert';
|
||||
|
||||
export class BasicOrderProvider implements OrderProvider {
|
||||
public readonly orders: SignedOrder[];
|
||||
/**
|
||||
* Instantiates a new BasicOrderProvider instance
|
||||
* @param orders An array of objects that conform to SignedOrder to fetch from.
|
||||
* @return An instance of BasicOrderProvider
|
||||
*/
|
||||
constructor(orders: SignedOrder[]) {
|
||||
assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
|
||||
this.orders = orders;
|
||||
}
|
||||
/**
|
||||
* Given an object that conforms to OrderFetcherRequest, return the corresponding OrderProviderResponse that satisfies the request.
|
||||
* @param orderProviderRequest An instance of OrderFetcherRequest. See type for more information.
|
||||
* @return An instance of OrderProviderResponse. See type for more information.
|
||||
*/
|
||||
public async getOrdersAsync(orderProviderRequest: OrderProviderRequest): Promise<OrderProviderResponse> {
|
||||
assert.isValidOrderProviderRequest('orderProviderRequest', orderProviderRequest);
|
||||
const { makerAssetData, takerAssetData } = orderProviderRequest;
|
||||
const orders = _.filter(this.orders, order => {
|
||||
return order.makerAssetData === makerAssetData && order.takerAssetData === takerAssetData;
|
||||
});
|
||||
return { orders };
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
import { HttpClient } from '@0xproject/connect';
|
||||
import { APIOrder, OrderbookResponse } from '@0xproject/types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {
|
||||
AssetBuyerError,
|
||||
OrderProvider,
|
||||
OrderProviderRequest,
|
||||
OrderProviderResponse,
|
||||
SignedOrderWithRemainingFillableMakerAssetAmount,
|
||||
} from '../types';
|
||||
import { assert } from '../utils/assert';
|
||||
import { orderUtils } from '../utils/order_utils';
|
||||
|
||||
export class StandardRelayerAPIOrderProvider implements OrderProvider {
|
||||
public readonly apiUrl: string;
|
||||
private readonly _sraClient: HttpClient;
|
||||
/**
|
||||
* Given an array of APIOrder objects from a standard relayer api, return an array
|
||||
* of SignedOrderWithRemainingFillableMakerAssetAmounts
|
||||
*/
|
||||
private static _getSignedOrderWithRemainingFillableMakerAssetAmountFromApi(
|
||||
apiOrders: APIOrder[],
|
||||
): SignedOrderWithRemainingFillableMakerAssetAmount[] {
|
||||
const result = _.map(apiOrders, apiOrder => {
|
||||
const { order, metaData } = apiOrder;
|
||||
// calculate remainingFillableMakerAssetAmount from api metadata, else assume order is completely fillable
|
||||
const remainingFillableTakerAssetAmount = _.get(
|
||||
metaData,
|
||||
'remainingTakerAssetAmount',
|
||||
order.takerAssetAmount,
|
||||
);
|
||||
const remainingFillableMakerAssetAmount = orderUtils.calculateRemainingMakerAssetAmount(
|
||||
order,
|
||||
remainingFillableTakerAssetAmount,
|
||||
);
|
||||
const newOrder = {
|
||||
...order,
|
||||
remainingFillableMakerAssetAmount,
|
||||
};
|
||||
return newOrder;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Instantiates a new StandardRelayerAPIOrderProvider instance
|
||||
* @param apiUrl The standard relayer API base HTTP url you would like to source orders from.
|
||||
* @return An instance of StandardRelayerAPIOrderProvider
|
||||
*/
|
||||
constructor(apiUrl: string) {
|
||||
assert.isWebUri('apiUrl', apiUrl);
|
||||
this.apiUrl = apiUrl;
|
||||
this._sraClient = new HttpClient(apiUrl);
|
||||
}
|
||||
/**
|
||||
* Given an object that conforms to OrderProviderRequest, return the corresponding OrderProviderResponse that satisfies the request.
|
||||
* @param orderProviderRequest An instance of OrderProviderRequest. See type for more information.
|
||||
* @return An instance of OrderProviderResponse. See type for more information.
|
||||
*/
|
||||
public async getOrdersAsync(orderProviderRequest: OrderProviderRequest): Promise<OrderProviderResponse> {
|
||||
assert.isValidOrderProviderRequest('orderProviderRequest', orderProviderRequest);
|
||||
const { makerAssetData, takerAssetData, networkId } = orderProviderRequest;
|
||||
const orderbookRequest = { baseAssetData: makerAssetData, quoteAssetData: takerAssetData };
|
||||
const requestOpts = { networkId };
|
||||
let orderbook: OrderbookResponse;
|
||||
try {
|
||||
orderbook = await this._sraClient.getOrderbookAsync(orderbookRequest, requestOpts);
|
||||
} catch (err) {
|
||||
throw new Error(AssetBuyerError.StandardRelayerApiError);
|
||||
}
|
||||
const apiOrders = orderbook.asks.records;
|
||||
const orders = StandardRelayerAPIOrderProvider._getSignedOrderWithRemainingFillableMakerAssetAmountFromApi(
|
||||
apiOrders,
|
||||
);
|
||||
return {
|
||||
orders,
|
||||
};
|
||||
}
|
||||
}
|
116
packages/asset-buyer/src/types.ts
Normal file
116
packages/asset-buyer/src/types.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
/**
|
||||
* makerAssetData: The assetData representing the desired makerAsset.
|
||||
* takerAssetData: The assetData representing the desired takerAsset.
|
||||
* networkId: The networkId that the desired orders should be for.
|
||||
*/
|
||||
export interface OrderProviderRequest {
|
||||
makerAssetData: string;
|
||||
takerAssetData: string;
|
||||
networkId: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* orders: An array of orders with optional remaining fillable makerAsset amounts. See type for more info.
|
||||
*/
|
||||
export interface OrderProviderResponse {
|
||||
orders: SignedOrderWithRemainingFillableMakerAssetAmount[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A normal SignedOrder with one extra optional property `remainingFillableMakerAssetAmount`
|
||||
* remainingFillableMakerAssetAmount: The amount of the makerAsset that is available to be filled
|
||||
*/
|
||||
export interface SignedOrderWithRemainingFillableMakerAssetAmount extends SignedOrder {
|
||||
remainingFillableMakerAssetAmount?: BigNumber;
|
||||
}
|
||||
/**
|
||||
* Given an OrderProviderRequest, get an OrderProviderResponse.
|
||||
*/
|
||||
export interface OrderProvider {
|
||||
getOrdersAsync: (orderProviderRequest: OrderProviderRequest) => Promise<OrderProviderResponse>;
|
||||
}
|
||||
|
||||
/**
|
||||
* assetData: String that represents a specific asset (for more info: https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md).
|
||||
* assetBuyAmount: The amount of asset to buy.
|
||||
* orders: An array of objects conforming to SignedOrder. These orders can be used to cover the requested assetBuyAmount plus slippage.
|
||||
* feeOrders: An array of objects conforming to SignedOrder. These orders can be used to cover the fees for the orders param above.
|
||||
* feePercentage: Optional affiliate fee percentage used to calculate the eth amounts above.
|
||||
* bestCaseQuoteInfo: Info about the best case price for the asset.
|
||||
* worstCaseQuoteInfo: Info about the worst case price for the asset.
|
||||
*/
|
||||
export interface BuyQuote {
|
||||
assetData: string;
|
||||
assetBuyAmount: BigNumber;
|
||||
orders: SignedOrder[];
|
||||
feeOrders: SignedOrder[];
|
||||
feePercentage?: number;
|
||||
bestCaseQuoteInfo: BuyQuoteInfo;
|
||||
worstCaseQuoteInfo: BuyQuoteInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* ethPerAssetPrice: The price of one unit of the desired asset in ETH
|
||||
* feeEthAmount: The amount of eth required to pay the affiliate fee.
|
||||
* totalEthAmount: the total amount of eth required to complete the buy. (Filling orders, feeOrders, and paying affiliate fee)
|
||||
*/
|
||||
export interface BuyQuoteInfo {
|
||||
ethPerAssetPrice: BigNumber;
|
||||
feeEthAmount: BigNumber;
|
||||
totalEthAmount: BigNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* feePercentage: The affiliate fee percentage. Defaults to 0.
|
||||
* shouldForceOrderRefresh: If set to true, new orders and state will be fetched instead of waiting for the next orderRefreshIntervalMs. Defaults to false.
|
||||
* slippagePercentage: The percentage buffer to add to account for slippage. Affects max ETH price estimates. Defaults to 0.2 (20%).
|
||||
*/
|
||||
export interface BuyQuoteRequestOpts {
|
||||
feePercentage: number;
|
||||
shouldForceOrderRefresh: boolean;
|
||||
slippagePercentage: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* ethAmount: The desired amount of eth to spend. Defaults to buyQuote.worstCaseQuoteInfo.totalEthAmount.
|
||||
* takerAddress: The address to perform the buy. Defaults to the first available address from the provider.
|
||||
* feeRecipient: The address where affiliate fees are sent. Defaults to null address (0x000...000).
|
||||
*/
|
||||
export interface BuyQuoteExecutionOpts {
|
||||
ethAmount?: BigNumber;
|
||||
takerAddress?: string;
|
||||
feeRecipient: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* networkId: The ethereum network id. Defaults to 1 (mainnet).
|
||||
* orderRefreshIntervalMs: The interval in ms that getBuyQuoteAsync should trigger an refresh of orders and order states. Defaults to 10000ms (10s).
|
||||
* expiryBufferSeconds: The number of seconds to add when calculating whether an order is expired or not. Defaults to 15s.
|
||||
*/
|
||||
export interface AssetBuyerOpts {
|
||||
networkId: number;
|
||||
orderRefreshIntervalMs: number;
|
||||
expiryBufferSeconds: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible errors thrown by an AssetBuyer instance or associated static methods.
|
||||
*/
|
||||
export enum AssetBuyerError {
|
||||
NoEtherTokenContractFound = 'NO_ETHER_TOKEN_CONTRACT_FOUND',
|
||||
NoZrxTokenContractFound = 'NO_ZRX_TOKEN_CONTRACT_FOUND',
|
||||
StandardRelayerApiError = 'STANDARD_RELAYER_API_ERROR',
|
||||
InsufficientAssetLiquidity = 'INSUFFICIENT_ASSET_LIQUIDITY',
|
||||
InsufficientZrxLiquidity = 'INSUFFICIENT_ZRX_LIQUIDITY',
|
||||
NoAddressAvailable = 'NO_ADDRESS_AVAILABLE',
|
||||
InvalidOrderProviderResponse = 'INVALID_ORDER_PROVIDER_RESPONSE',
|
||||
AssetUnavailable = 'ASSET_UNAVAILABLE',
|
||||
}
|
||||
|
||||
export interface OrdersAndFillableAmounts {
|
||||
orders: SignedOrder[];
|
||||
remainingFillableMakerAssetAmounts: BigNumber[];
|
||||
}
|
56
packages/asset-buyer/src/utils/assert.ts
Normal file
56
packages/asset-buyer/src/utils/assert.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { assert as sharedAssert } from '@0xproject/assert';
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { BuyQuote, BuyQuoteInfo, OrderProvider, OrderProviderRequest } from '../types';
|
||||
|
||||
export const assert = {
|
||||
...sharedAssert,
|
||||
isValidBuyQuote(variableName: string, buyQuote: BuyQuote): void {
|
||||
sharedAssert.isHexString(`${variableName}.assetData`, buyQuote.assetData);
|
||||
sharedAssert.doesConformToSchema(`${variableName}.orders`, buyQuote.orders, schemas.signedOrdersSchema);
|
||||
sharedAssert.doesConformToSchema(`${variableName}.feeOrders`, buyQuote.feeOrders, schemas.signedOrdersSchema);
|
||||
assert.isValidBuyQuoteInfo(`${variableName}.bestCaseQuoteInfo`, buyQuote.bestCaseQuoteInfo);
|
||||
assert.isValidBuyQuoteInfo(`${variableName}.worstCaseQuoteInfo`, buyQuote.worstCaseQuoteInfo);
|
||||
sharedAssert.isBigNumber(`${variableName}.assetBuyAmount`, buyQuote.assetBuyAmount);
|
||||
if (!_.isUndefined(buyQuote.feePercentage)) {
|
||||
sharedAssert.isNumber(`${variableName}.feePercentage`, buyQuote.feePercentage);
|
||||
}
|
||||
},
|
||||
isValidBuyQuoteInfo(variableName: string, buyQuoteInfo: BuyQuoteInfo): void {
|
||||
sharedAssert.isBigNumber(`${variableName}.ethPerAssetPrice`, buyQuoteInfo.ethPerAssetPrice);
|
||||
sharedAssert.isBigNumber(`${variableName}.feeEthAmount`, buyQuoteInfo.feeEthAmount);
|
||||
sharedAssert.isBigNumber(`${variableName}.totalEthAmount`, buyQuoteInfo.totalEthAmount);
|
||||
},
|
||||
isValidOrderProvider(variableName: string, orderFetcher: OrderProvider): void {
|
||||
sharedAssert.isFunction(`${variableName}.getOrdersAsync`, orderFetcher.getOrdersAsync);
|
||||
},
|
||||
isValidOrderProviderRequest(variableName: string, orderFetcherRequest: OrderProviderRequest): void {
|
||||
sharedAssert.isHexString(`${variableName}.makerAssetData`, orderFetcherRequest.makerAssetData);
|
||||
sharedAssert.isHexString(`${variableName}.takerAssetData`, orderFetcherRequest.takerAssetData);
|
||||
sharedAssert.isNumber(`${variableName}.networkId`, orderFetcherRequest.networkId);
|
||||
},
|
||||
areValidProvidedOrders(variableName: string, orders: SignedOrder[]): void {
|
||||
if (orders.length === 0) {
|
||||
return;
|
||||
}
|
||||
const makerAssetData = orders[0].makerAssetData;
|
||||
const takerAssetData = orders[0].takerAssetData;
|
||||
const filteredOrders = _.filter(
|
||||
orders,
|
||||
order => order.makerAssetData === makerAssetData && order.takerAssetData === takerAssetData,
|
||||
);
|
||||
sharedAssert.assert(
|
||||
orders.length === filteredOrders.length,
|
||||
`Expected all orders in ${variableName} to have the same makerAssetData and takerAssetData.`,
|
||||
);
|
||||
},
|
||||
isValidPercentage(variableName: string, percentage: number): void {
|
||||
assert.isNumber(variableName, percentage);
|
||||
assert.assert(
|
||||
percentage >= 0 && percentage <= 1,
|
||||
`Expected ${variableName} to be between 0 and 1, but is ${percentage}`,
|
||||
);
|
||||
},
|
||||
};
|
26
packages/asset-buyer/src/utils/asset_data_utils.ts
Normal file
26
packages/asset-buyer/src/utils/asset_data_utils.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ContractWrappers } from '@0xproject/contract-wrappers';
|
||||
import { assetDataUtils as sharedAssetDataUtils } from '@0xproject/order-utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { AssetBuyerError } from '../types';
|
||||
|
||||
export const assetDataUtils = {
|
||||
...sharedAssetDataUtils,
|
||||
getEtherTokenAssetDataOrThrow(contractWrappers: ContractWrappers): string {
|
||||
const etherTokenAddressIfExists = contractWrappers.etherToken.getContractAddressIfExists();
|
||||
if (_.isUndefined(etherTokenAddressIfExists)) {
|
||||
throw new Error(AssetBuyerError.NoEtherTokenContractFound);
|
||||
}
|
||||
const etherTokenAssetData = sharedAssetDataUtils.encodeERC20AssetData(etherTokenAddressIfExists);
|
||||
return etherTokenAssetData;
|
||||
},
|
||||
getZrxTokenAssetDataOrThrow(contractWrappers: ContractWrappers): string {
|
||||
let zrxTokenAssetData: string;
|
||||
try {
|
||||
zrxTokenAssetData = contractWrappers.exchange.getZRXAssetData();
|
||||
} catch (err) {
|
||||
throw new Error(AssetBuyerError.NoZrxTokenContractFound);
|
||||
}
|
||||
return zrxTokenAssetData;
|
||||
},
|
||||
};
|
179
packages/asset-buyer/src/utils/buy_quote_calculator.ts
Normal file
179
packages/asset-buyer/src/utils/buy_quote_calculator.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
import { marketUtils, rateUtils } from '@0xproject/order-utils';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from '../constants';
|
||||
import { AssetBuyerError, BuyQuote, BuyQuoteInfo, OrdersAndFillableAmounts } from '../types';
|
||||
|
||||
// Calculates a buy quote for orders that have WETH as the takerAsset
|
||||
export const buyQuoteCalculator = {
|
||||
calculate(
|
||||
ordersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
feeOrdersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
assetBuyAmount: BigNumber,
|
||||
feePercentage: number,
|
||||
slippagePercentage: number,
|
||||
): BuyQuote {
|
||||
const orders = ordersAndFillableAmounts.orders;
|
||||
const remainingFillableMakerAssetAmounts = ordersAndFillableAmounts.remainingFillableMakerAssetAmounts;
|
||||
const feeOrders = feeOrdersAndFillableAmounts.orders;
|
||||
const remainingFillableFeeAmounts = feeOrdersAndFillableAmounts.remainingFillableMakerAssetAmounts;
|
||||
const slippageBufferAmount = assetBuyAmount.mul(slippagePercentage).round();
|
||||
// find the orders that cover the desired assetBuyAmount (with slippage)
|
||||
const {
|
||||
resultOrders,
|
||||
remainingFillAmount,
|
||||
ordersRemainingFillableMakerAssetAmounts,
|
||||
} = marketUtils.findOrdersThatCoverMakerAssetFillAmount(orders, assetBuyAmount, {
|
||||
remainingFillableMakerAssetAmounts,
|
||||
slippageBufferAmount,
|
||||
});
|
||||
// if we do not have enough orders to cover the desired assetBuyAmount, throw
|
||||
if (remainingFillAmount.gt(constants.ZERO_AMOUNT)) {
|
||||
throw new Error(AssetBuyerError.InsufficientAssetLiquidity);
|
||||
}
|
||||
// given the orders calculated above, find the fee-orders that cover the desired assetBuyAmount (with slippage)
|
||||
// TODO(bmillman): optimization
|
||||
// update this logic to find the minimum amount of feeOrders to cover the worst case as opposed to
|
||||
// finding order that cover all fees, this will help with estimating ETH and minimizing gas usage
|
||||
const {
|
||||
resultFeeOrders,
|
||||
remainingFeeAmount,
|
||||
feeOrdersRemainingFillableMakerAssetAmounts,
|
||||
} = marketUtils.findFeeOrdersThatCoverFeesForTargetOrders(resultOrders, feeOrders, {
|
||||
remainingFillableMakerAssetAmounts: ordersRemainingFillableMakerAssetAmounts,
|
||||
remainingFillableFeeAmounts,
|
||||
});
|
||||
// if we do not have enough feeOrders to cover the fees, throw
|
||||
if (remainingFeeAmount.gt(constants.ZERO_AMOUNT)) {
|
||||
throw new Error(AssetBuyerError.InsufficientZrxLiquidity);
|
||||
}
|
||||
// assetData information for the result
|
||||
const assetData = orders[0].makerAssetData;
|
||||
// compile the resulting trimmed set of orders for makerAsset and feeOrders that are needed for assetBuyAmount
|
||||
const trimmedOrdersAndFillableAmounts: OrdersAndFillableAmounts = {
|
||||
orders: resultOrders,
|
||||
remainingFillableMakerAssetAmounts: ordersRemainingFillableMakerAssetAmounts,
|
||||
};
|
||||
const trimmedFeeOrdersAndFillableAmounts: OrdersAndFillableAmounts = {
|
||||
orders: resultFeeOrders,
|
||||
remainingFillableMakerAssetAmounts: feeOrdersRemainingFillableMakerAssetAmounts,
|
||||
};
|
||||
const bestCaseQuoteInfo = calculateQuoteInfo(
|
||||
trimmedOrdersAndFillableAmounts,
|
||||
trimmedFeeOrdersAndFillableAmounts,
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
);
|
||||
// in order to calculate the maxRate, reverse the ordersAndFillableAmounts such that they are sorted from worst rate to best rate
|
||||
const worstCaseQuoteInfo = calculateQuoteInfo(
|
||||
reverseOrdersAndFillableAmounts(trimmedOrdersAndFillableAmounts),
|
||||
reverseOrdersAndFillableAmounts(trimmedFeeOrdersAndFillableAmounts),
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
);
|
||||
|
||||
return {
|
||||
assetData,
|
||||
orders: resultOrders,
|
||||
feeOrders: resultFeeOrders,
|
||||
bestCaseQuoteInfo,
|
||||
worstCaseQuoteInfo,
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function calculateQuoteInfo(
|
||||
ordersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
feeOrdersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
assetBuyAmount: BigNumber,
|
||||
feePercentage: number,
|
||||
): BuyQuoteInfo {
|
||||
// find the total eth and zrx needed to buy assetAmount from the resultOrders from left to right
|
||||
const [ethAmountToBuyAsset, zrxAmountToBuyAsset] = findEthAndZrxAmountNeededToBuyAsset(
|
||||
ordersAndFillableAmounts,
|
||||
assetBuyAmount,
|
||||
);
|
||||
// find the total eth needed to buy fees
|
||||
const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
|
||||
const ethAmountBeforeAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees);
|
||||
const totalEthAmount = ethAmountBeforeAffiliateFee.mul(feePercentage + 1);
|
||||
// divide into the assetBuyAmount in order to find rate of makerAsset / WETH
|
||||
const ethPerAssetPrice = ethAmountBeforeAffiliateFee.div(assetBuyAmount);
|
||||
return {
|
||||
totalEthAmount,
|
||||
feeEthAmount: totalEthAmount.minus(ethAmountBeforeAffiliateFee),
|
||||
ethPerAssetPrice,
|
||||
};
|
||||
}
|
||||
|
||||
// given an OrdersAndFillableAmounts, reverse the orders and remainingFillableMakerAssetAmounts properties
|
||||
function reverseOrdersAndFillableAmounts(ordersAndFillableAmounts: OrdersAndFillableAmounts): OrdersAndFillableAmounts {
|
||||
const ordersCopy = _.clone(ordersAndFillableAmounts.orders);
|
||||
const remainingFillableMakerAssetAmountsCopy = _.clone(ordersAndFillableAmounts.remainingFillableMakerAssetAmounts);
|
||||
return {
|
||||
orders: ordersCopy.reverse(),
|
||||
remainingFillableMakerAssetAmounts: remainingFillableMakerAssetAmountsCopy.reverse(),
|
||||
};
|
||||
}
|
||||
|
||||
function findEthAmountNeededToBuyFees(
|
||||
feeOrdersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
feeAmount: BigNumber,
|
||||
): BigNumber {
|
||||
const { orders, remainingFillableMakerAssetAmounts } = feeOrdersAndFillableAmounts;
|
||||
const result = _.reduce(
|
||||
orders,
|
||||
(acc, order, index) => {
|
||||
const remainingFillableMakerAssetAmount = remainingFillableMakerAssetAmounts[index];
|
||||
const amountToFill = BigNumber.min(acc.remainingFeeAmount, remainingFillableMakerAssetAmount);
|
||||
const feeAdjustedRate = rateUtils.getFeeAdjustedRateOfFeeOrder(order);
|
||||
const ethAmountForThisOrder = feeAdjustedRate.mul(amountToFill);
|
||||
return {
|
||||
ethAmount: acc.ethAmount.plus(ethAmountForThisOrder),
|
||||
remainingFeeAmount: BigNumber.max(constants.ZERO_AMOUNT, acc.remainingFeeAmount.minus(amountToFill)),
|
||||
};
|
||||
},
|
||||
{
|
||||
ethAmount: constants.ZERO_AMOUNT,
|
||||
remainingFeeAmount: feeAmount,
|
||||
},
|
||||
);
|
||||
return result.ethAmount;
|
||||
}
|
||||
|
||||
function findEthAndZrxAmountNeededToBuyAsset(
|
||||
ordersAndFillableAmounts: OrdersAndFillableAmounts,
|
||||
assetBuyAmount: BigNumber,
|
||||
): [BigNumber, BigNumber] {
|
||||
const { orders, remainingFillableMakerAssetAmounts } = ordersAndFillableAmounts;
|
||||
const result = _.reduce(
|
||||
orders,
|
||||
(acc, order, index) => {
|
||||
const remainingFillableMakerAssetAmount = remainingFillableMakerAssetAmounts[index];
|
||||
const amountToFill = BigNumber.min(acc.remainingAssetBuyAmount, remainingFillableMakerAssetAmount);
|
||||
// find the amount of eth required to fill amountToFill (amountToFill / makerAssetAmount) * takerAssetAmount
|
||||
const ethAmountForThisOrder = amountToFill
|
||||
.mul(order.takerAssetAmount)
|
||||
.dividedToIntegerBy(order.makerAssetAmount);
|
||||
// find the amount of zrx required to fill fees for amountToFill (amountToFill / makerAssetAmount) * takerFee
|
||||
const zrxAmountForThisOrder = amountToFill.mul(order.takerFee).dividedToIntegerBy(order.makerAssetAmount);
|
||||
return {
|
||||
ethAmount: acc.ethAmount.plus(ethAmountForThisOrder),
|
||||
zrxAmount: acc.zrxAmount.plus(zrxAmountForThisOrder),
|
||||
remainingAssetBuyAmount: BigNumber.max(
|
||||
constants.ZERO_AMOUNT,
|
||||
acc.remainingAssetBuyAmount.minus(amountToFill),
|
||||
),
|
||||
};
|
||||
},
|
||||
{
|
||||
ethAmount: constants.ZERO_AMOUNT,
|
||||
zrxAmount: constants.ZERO_AMOUNT,
|
||||
remainingAssetBuyAmount: assetBuyAmount,
|
||||
},
|
||||
);
|
||||
return [result.ethAmount, result.zrxAmount];
|
||||
}
|
@@ -0,0 +1,172 @@
|
||||
import { OrderAndTraderInfo, OrderStatus, OrderValidatorWrapper } from '@0xproject/contract-wrappers';
|
||||
import { sortingUtils } from '@0xproject/order-utils';
|
||||
import { RemainingFillableCalculator } from '@0xproject/order-utils/lib/src/remaining_fillable_calculator';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from '../constants';
|
||||
import {
|
||||
AssetBuyerError,
|
||||
OrderProviderRequest,
|
||||
OrderProviderResponse,
|
||||
OrdersAndFillableAmounts,
|
||||
SignedOrderWithRemainingFillableMakerAssetAmount,
|
||||
} from '../types';
|
||||
|
||||
import { orderUtils } from './order_utils';
|
||||
|
||||
export const orderProviderResponseProcessor = {
|
||||
throwIfInvalidResponse(response: OrderProviderResponse, request: OrderProviderRequest): void {
|
||||
const { makerAssetData, takerAssetData } = request;
|
||||
_.forEach(response.orders, order => {
|
||||
if (order.makerAssetData !== makerAssetData || order.takerAssetData !== takerAssetData) {
|
||||
throw new Error(AssetBuyerError.InvalidOrderProviderResponse);
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Take the responses for the target orders to buy and fee orders and process them.
|
||||
* Processing includes:
|
||||
* - Drop orders that are expired or not open orders (null taker address)
|
||||
* - If shouldValidateOnChain, attempt to grab fillable amounts from on-chain otherwise assume completely fillable
|
||||
* - Sort by rate
|
||||
*/
|
||||
async processAsync(
|
||||
orderProviderResponse: OrderProviderResponse,
|
||||
isMakerAssetZrxToken: boolean,
|
||||
expiryBufferSeconds: number,
|
||||
orderValidator?: OrderValidatorWrapper,
|
||||
): Promise<OrdersAndFillableAmounts> {
|
||||
// drop orders that are expired or not open
|
||||
const filteredOrders = filterOutExpiredAndNonOpenOrders(orderProviderResponse.orders, expiryBufferSeconds);
|
||||
// set the orders to be sorted equal to the filtered orders
|
||||
let unsortedOrders = filteredOrders;
|
||||
// if an orderValidator is provided, use on chain information to calculate remaining fillable makerAsset amounts
|
||||
if (!_.isUndefined(orderValidator)) {
|
||||
// TODO(bmillman): improvement
|
||||
// try/catch this request and throw a more domain specific error
|
||||
const takerAddresses = _.map(filteredOrders, () => constants.NULL_ADDRESS);
|
||||
const ordersAndTradersInfo = await orderValidator.getOrdersAndTradersInfoAsync(
|
||||
filteredOrders,
|
||||
takerAddresses,
|
||||
);
|
||||
// take orders + on chain information and find the valid orders and remaining fillable maker asset amounts
|
||||
unsortedOrders = getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain(
|
||||
filteredOrders,
|
||||
ordersAndTradersInfo,
|
||||
isMakerAssetZrxToken,
|
||||
);
|
||||
}
|
||||
// sort orders by rate
|
||||
// TODO(bmillman): optimization
|
||||
// provide a feeRate to the sorting function to more accurately sort based on the current market for ZRX tokens
|
||||
const sortedOrders = isMakerAssetZrxToken
|
||||
? sortingUtils.sortFeeOrdersByFeeAdjustedRate(unsortedOrders)
|
||||
: sortingUtils.sortOrdersByFeeAdjustedRate(unsortedOrders);
|
||||
// unbundle orders and fillable amounts and compile final result
|
||||
const result = unbundleOrdersWithAmounts(sortedOrders);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Given an array of orders, return a new array with expired and non open orders filtered out.
|
||||
*/
|
||||
function filterOutExpiredAndNonOpenOrders(
|
||||
orders: SignedOrderWithRemainingFillableMakerAssetAmount[],
|
||||
expiryBufferSeconds: number,
|
||||
): SignedOrderWithRemainingFillableMakerAssetAmount[] {
|
||||
const result = _.filter(orders, order => {
|
||||
return orderUtils.isOpenOrder(order) && !orderUtils.willOrderExpire(order, expiryBufferSeconds);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of orders and corresponding on-chain infos, return a subset of the orders
|
||||
* that are still fillable orders with their corresponding remainingFillableMakerAssetAmounts.
|
||||
*/
|
||||
function getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain(
|
||||
inputOrders: SignedOrder[],
|
||||
ordersAndTradersInfo: OrderAndTraderInfo[],
|
||||
isMakerAssetZrxToken: boolean,
|
||||
): SignedOrderWithRemainingFillableMakerAssetAmount[] {
|
||||
// iterate through the input orders and find the ones that are still fillable
|
||||
// for the orders that are still fillable, calculate the remaining fillable maker asset amount
|
||||
const result = _.reduce(
|
||||
inputOrders,
|
||||
(accOrders, order, index) => {
|
||||
// get corresponding on-chain state for the order
|
||||
const { orderInfo, traderInfo } = ordersAndTradersInfo[index];
|
||||
// if the order IS NOT fillable, do not add anything to the accumulations and continue iterating
|
||||
if (orderInfo.orderStatus !== OrderStatus.FILLABLE) {
|
||||
return accOrders;
|
||||
}
|
||||
// if the order IS fillable, add the order and calculate the remaining fillable amount
|
||||
const transferrableAssetAmount = BigNumber.min([traderInfo.makerAllowance, traderInfo.makerBalance]);
|
||||
const transferrableFeeAssetAmount = BigNumber.min([
|
||||
traderInfo.makerZrxAllowance,
|
||||
traderInfo.makerZrxBalance,
|
||||
]);
|
||||
const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
|
||||
const remainingMakerAssetAmount = orderUtils.calculateRemainingMakerAssetAmount(
|
||||
order,
|
||||
remainingTakerAssetAmount,
|
||||
);
|
||||
const remainingFillableCalculator = new RemainingFillableCalculator(
|
||||
order.makerFee,
|
||||
order.makerAssetAmount,
|
||||
isMakerAssetZrxToken,
|
||||
transferrableAssetAmount,
|
||||
transferrableFeeAssetAmount,
|
||||
remainingMakerAssetAmount,
|
||||
);
|
||||
const remainingFillableAmount = remainingFillableCalculator.computeRemainingFillable();
|
||||
// if the order does not have any remaining fillable makerAsset, do not add anything to the accumulations and continue iterating
|
||||
if (remainingFillableAmount.lte(constants.ZERO_AMOUNT)) {
|
||||
return accOrders;
|
||||
}
|
||||
const orderWithRemainingFillableMakerAssetAmount = {
|
||||
...order,
|
||||
remainingFillableMakerAssetAmount: remainingFillableAmount,
|
||||
};
|
||||
const newAccOrders = _.concat(accOrders, orderWithRemainingFillableMakerAssetAmount);
|
||||
return newAccOrders;
|
||||
},
|
||||
[] as SignedOrderWithRemainingFillableMakerAssetAmount[],
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of orders with remaining fillable maker asset amounts. Unbundle into an instance of OrdersAndRemainingFillableMakerAssetAmounts.
|
||||
* If an order is missing a corresponding remainingFillableMakerAssetAmount, assume it is completely fillable.
|
||||
*/
|
||||
function unbundleOrdersWithAmounts(
|
||||
ordersWithAmounts: SignedOrderWithRemainingFillableMakerAssetAmount[],
|
||||
): OrdersAndFillableAmounts {
|
||||
const result = _.reduce(
|
||||
ordersWithAmounts,
|
||||
(acc, orderWithAmount) => {
|
||||
const { orders, remainingFillableMakerAssetAmounts } = acc;
|
||||
const { remainingFillableMakerAssetAmount, ...order } = orderWithAmount;
|
||||
// if we are still missing a remainingFillableMakerAssetAmount, assume the order is completely fillable
|
||||
const newRemainingAmount = remainingFillableMakerAssetAmount || order.makerAssetAmount;
|
||||
// if remaining amount is less than or equal to zero, do not add it
|
||||
if (newRemainingAmount.lte(constants.ZERO_AMOUNT)) {
|
||||
return acc;
|
||||
}
|
||||
const newAcc = {
|
||||
orders: _.concat(orders, order),
|
||||
remainingFillableMakerAssetAmounts: _.concat(remainingFillableMakerAssetAmounts, newRemainingAmount),
|
||||
};
|
||||
return newAcc;
|
||||
},
|
||||
{
|
||||
orders: [] as SignedOrder[],
|
||||
remainingFillableMakerAssetAmounts: [] as BigNumber[],
|
||||
},
|
||||
);
|
||||
return result;
|
||||
}
|
30
packages/asset-buyer/src/utils/order_utils.ts
Normal file
30
packages/asset-buyer/src/utils/order_utils.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { constants } from '../constants';
|
||||
|
||||
export const orderUtils = {
|
||||
isOrderExpired(order: SignedOrder): boolean {
|
||||
return orderUtils.willOrderExpire(order, 0);
|
||||
},
|
||||
willOrderExpire(order: SignedOrder, secondsFromNow: number): boolean {
|
||||
const millisecondsInSecond = 1000;
|
||||
const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round();
|
||||
return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.minus(secondsFromNow));
|
||||
},
|
||||
calculateRemainingMakerAssetAmount(order: SignedOrder, remainingTakerAssetAmount: BigNumber): BigNumber {
|
||||
if (remainingTakerAssetAmount.eq(0)) {
|
||||
return constants.ZERO_AMOUNT;
|
||||
}
|
||||
return remainingTakerAssetAmount.times(order.makerAssetAmount).dividedToIntegerBy(order.takerAssetAmount);
|
||||
},
|
||||
calculateRemainingTakerAssetAmount(order: SignedOrder, remainingMakerAssetAmount: BigNumber): BigNumber {
|
||||
if (remainingMakerAssetAmount.eq(0)) {
|
||||
return constants.ZERO_AMOUNT;
|
||||
}
|
||||
return remainingMakerAssetAmount.times(order.takerAssetAmount).dividedToIntegerBy(order.makerAssetAmount);
|
||||
},
|
||||
isOpenOrder(order: SignedOrder): boolean {
|
||||
return order.takerAddress === constants.NULL_ADDRESS;
|
||||
},
|
||||
};
|
160
packages/asset-buyer/test/buy_quote_calculator_test.ts
Normal file
160
packages/asset-buyer/test/buy_quote_calculator_test.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
import { orderFactory } from '@0xproject/order-utils/lib/src/order_factory';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
import 'mocha';
|
||||
|
||||
import { AssetBuyerError, OrdersAndFillableAmounts } from '../src/types';
|
||||
import { buyQuoteCalculator } from '../src/utils/buy_quote_calculator';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
// tslint:disable:custom-no-magic-numbers
|
||||
describe('buyQuoteCalculator', () => {
|
||||
describe('#calculate', () => {
|
||||
let ordersAndFillableAmounts: OrdersAndFillableAmounts;
|
||||
let smallFeeOrderAndFillableAmount: OrdersAndFillableAmounts;
|
||||
let allFeeOrdersAndFillableAmounts: OrdersAndFillableAmounts;
|
||||
beforeEach(() => {
|
||||
// generate two orders for our desired maker asset
|
||||
// the first order has a rate of 4 makerAsset / WETH with a takerFee of 200 ZRX and has only 200 / 400 makerAsset units left to fill (half fillable)
|
||||
// the second order has a rate of 2 makerAsset / WETH with a takerFee of 100 ZRX and has 200 / 200 makerAsset units left to fill (completely fillable)
|
||||
// generate one order for fees
|
||||
// the fee order has a rate of 1 ZRX / WETH with no taker fee and has 100 ZRX left to fill (completely fillable)
|
||||
const firstOrder = orderFactory.createSignedOrderFromPartial({
|
||||
makerAssetAmount: new BigNumber(400),
|
||||
takerAssetAmount: new BigNumber(100),
|
||||
takerFee: new BigNumber(200),
|
||||
});
|
||||
const firstRemainingFillAmount = new BigNumber(200);
|
||||
const secondOrder = orderFactory.createSignedOrderFromPartial({
|
||||
makerAssetAmount: new BigNumber(200),
|
||||
takerAssetAmount: new BigNumber(100),
|
||||
takerFee: new BigNumber(100),
|
||||
});
|
||||
const secondRemainingFillAmount = secondOrder.makerAssetAmount;
|
||||
ordersAndFillableAmounts = {
|
||||
orders: [firstOrder, secondOrder],
|
||||
remainingFillableMakerAssetAmounts: [firstRemainingFillAmount, secondRemainingFillAmount],
|
||||
};
|
||||
const smallFeeOrder = orderFactory.createSignedOrderFromPartial({
|
||||
makerAssetAmount: new BigNumber(100),
|
||||
takerAssetAmount: new BigNumber(100),
|
||||
});
|
||||
smallFeeOrderAndFillableAmount = {
|
||||
orders: [smallFeeOrder],
|
||||
remainingFillableMakerAssetAmounts: [smallFeeOrder.makerAssetAmount],
|
||||
};
|
||||
const largeFeeOrder = orderFactory.createSignedOrderFromPartial({
|
||||
makerAssetAmount: new BigNumber(110),
|
||||
takerAssetAmount: new BigNumber(200),
|
||||
takerFee: new BigNumber(10),
|
||||
});
|
||||
allFeeOrdersAndFillableAmounts = {
|
||||
orders: [smallFeeOrder, largeFeeOrder],
|
||||
remainingFillableMakerAssetAmounts: [
|
||||
smallFeeOrder.makerAssetAmount,
|
||||
largeFeeOrder.makerAssetAmount.minus(largeFeeOrder.takerFee),
|
||||
],
|
||||
};
|
||||
});
|
||||
it('should throw if not enough maker asset liquidity', () => {
|
||||
// we have 400 makerAsset units available to fill but attempt to calculate a quote for 500 makerAsset units
|
||||
expect(() =>
|
||||
buyQuoteCalculator.calculate(
|
||||
ordersAndFillableAmounts,
|
||||
smallFeeOrderAndFillableAmount,
|
||||
new BigNumber(500),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
).to.throw(AssetBuyerError.InsufficientAssetLiquidity);
|
||||
});
|
||||
it('should throw if not enough ZRX liquidity', () => {
|
||||
// we request 300 makerAsset units but the ZRX order is only enough to fill the first order, which only has 200 makerAssetUnits available
|
||||
expect(() =>
|
||||
buyQuoteCalculator.calculate(
|
||||
ordersAndFillableAmounts,
|
||||
smallFeeOrderAndFillableAmount,
|
||||
new BigNumber(300),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
).to.throw(AssetBuyerError.InsufficientZrxLiquidity);
|
||||
});
|
||||
it('calculates a correct buyQuote with no slippage', () => {
|
||||
// we request 200 makerAsset units which can be filled using the first order
|
||||
// the first order requires a fee of 100 ZRX from the taker which can be filled by the feeOrder
|
||||
const assetBuyAmount = new BigNumber(200);
|
||||
const feePercentage = 0.02;
|
||||
const slippagePercentage = 0;
|
||||
const buyQuote = buyQuoteCalculator.calculate(
|
||||
ordersAndFillableAmounts,
|
||||
smallFeeOrderAndFillableAmount,
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
slippagePercentage,
|
||||
);
|
||||
// test if orders are correct
|
||||
expect(buyQuote.orders).to.deep.equal([ordersAndFillableAmounts.orders[0]]);
|
||||
expect(buyQuote.feeOrders).to.deep.equal([smallFeeOrderAndFillableAmount.orders[0]]);
|
||||
// test if rates are correct
|
||||
// 50 eth to fill the first order + 100 eth for fees
|
||||
const expectedFillEthAmount = new BigNumber(150);
|
||||
const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
|
||||
const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
|
||||
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
|
||||
// because we have no slippage protection, minRate is equal to maxRate
|
||||
expect(buyQuote.worstCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
||||
expect(buyQuote.worstCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
||||
expect(buyQuote.worstCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
|
||||
// test if feePercentage gets passed through
|
||||
expect(buyQuote.feePercentage).to.equal(feePercentage);
|
||||
});
|
||||
it('calculates a correct buyQuote with with slippage', () => {
|
||||
// we request 200 makerAsset units which can be filled using the first order
|
||||
// however with 50% slippage we are protecting the buy with 100 extra makerAssetUnits
|
||||
// so we need enough orders to fill 300 makerAssetUnits
|
||||
// 300 makerAssetUnits can only be filled using both orders
|
||||
// the first order requires a fee of 100 ZRX from the taker which can be filled by the feeOrder
|
||||
const assetBuyAmount = new BigNumber(200);
|
||||
const feePercentage = 0.02;
|
||||
const slippagePercentage = 0.5;
|
||||
const buyQuote = buyQuoteCalculator.calculate(
|
||||
ordersAndFillableAmounts,
|
||||
allFeeOrdersAndFillableAmounts,
|
||||
assetBuyAmount,
|
||||
feePercentage,
|
||||
slippagePercentage,
|
||||
);
|
||||
// test if orders are correct
|
||||
expect(buyQuote.orders).to.deep.equal(ordersAndFillableAmounts.orders);
|
||||
expect(buyQuote.feeOrders).to.deep.equal(allFeeOrdersAndFillableAmounts.orders);
|
||||
// test if rates are correct
|
||||
// 50 eth to fill the first order + 100 eth for fees
|
||||
const expectedFillEthAmount = new BigNumber(150);
|
||||
const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
|
||||
const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
|
||||
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
||||
expect(buyQuote.bestCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
|
||||
// 100 eth to fill the first order + 200 eth for fees
|
||||
const expectedWorstFillEthAmount = new BigNumber(300);
|
||||
const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.mul(feePercentage + 1);
|
||||
const expectedWorstFeeEthAmount = expectedWorstTotalEthAmount.minus(expectedWorstFillEthAmount);
|
||||
const expectedWorstEthPerAssetPrice = expectedWorstFillEthAmount.div(assetBuyAmount);
|
||||
expect(buyQuote.worstCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedWorstFeeEthAmount);
|
||||
expect(buyQuote.worstCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedWorstTotalEthAmount);
|
||||
expect(buyQuote.worstCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedWorstEthPerAssetPrice);
|
||||
// test if feePercentage gets passed through
|
||||
expect(buyQuote.feePercentage).to.equal(feePercentage);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,4 +1,54 @@
|
||||
[
|
||||
{
|
||||
"version": "3.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"version": "3.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Change the way we detect BN to work with the newest ethers.js",
|
||||
"pr": 1069
|
||||
},
|
||||
{
|
||||
"note": "Add baseContract._throwIfRevertWithReasonCallResult",
|
||||
"pr": 1069
|
||||
}
|
||||
],
|
||||
"timestamp": 1538157789
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "2.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "2.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "2.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "2.0.2",
|
||||
|
@@ -5,6 +5,27 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.0.1 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.0 - _September 28, 2018_
|
||||
|
||||
* Change the way we detect BN to work with the newest ethers.js (#1069)
|
||||
* Add baseContract._throwIfRevertWithReasonCallResult (#1069)
|
||||
|
||||
## v2.0.5 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.4 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.3 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.2 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -17,7 +38,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.0-rc.1 - _August 14, 2018_
|
||||
## v2.0.0-rc.1 - _August 13, 2018_
|
||||
|
||||
* Added strict encoding/decoding checks for sendTransaction and call (#915)
|
||||
|
||||
@@ -37,7 +58,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -53,7 +74,7 @@ CHANGELOG
|
||||
|
||||
* Update EthersJs to fix the `value.toLowerCase()` is not a function bug caused by `ethers.js` breaking patch version https://github.com/ethers-io/ethers.js/issues/201
|
||||
|
||||
## v0.3.3 - _June 1, 2018_
|
||||
## v0.3.3 - _May 31, 2018_
|
||||
|
||||
* Incorrect publish that was unpublished
|
||||
|
||||
@@ -61,7 +82,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.3.1 - _May 5, 2018_
|
||||
## v0.3.1 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/base-contract",
|
||||
"version": "2.0.2",
|
||||
"version": "3.0.1",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -9,6 +9,7 @@
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"clean": "shx rm -rf lib",
|
||||
"test": "yarn run_mocha",
|
||||
"rebuild_and_test": "run-s clean build test",
|
||||
@@ -28,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"chai": "^4.0.1",
|
||||
"copyfiles": "^2.0.0",
|
||||
@@ -40,11 +41,11 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"ethers": "4.0.0-beta.14",
|
||||
"lodash": "^4.17.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -20,6 +20,11 @@ export interface EthersInterfaceByFunctionSignature {
|
||||
[key: string]: ethers.Interface;
|
||||
}
|
||||
|
||||
const REVERT_ERROR_SELECTOR = '08c379a0';
|
||||
const REVERT_ERROR_SELECTOR_OFFSET = 2;
|
||||
const REVERT_ERROR_SELECTOR_BYTES_LENGTH = 4;
|
||||
const REVERT_ERROR_SELECTOR_END = REVERT_ERROR_SELECTOR_OFFSET + REVERT_ERROR_SELECTOR_BYTES_LENGTH * 2;
|
||||
|
||||
export class BaseContract {
|
||||
protected _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature;
|
||||
protected _web3Wrapper: Web3Wrapper;
|
||||
@@ -61,7 +66,7 @@ export class BaseContract {
|
||||
}
|
||||
}
|
||||
protected static _bnToBigNumber(_type: string, value: any): any {
|
||||
return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
|
||||
return _.isObject(value) && value._hex ? new BigNumber(value.toString()) : value;
|
||||
}
|
||||
protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
|
||||
txData: T,
|
||||
@@ -82,15 +87,24 @@ export class BaseContract {
|
||||
}
|
||||
return txDataWithDefaults;
|
||||
}
|
||||
protected static _throwIfRevertWithReasonCallResult(rawCallResult: string): void {
|
||||
if (rawCallResult.slice(REVERT_ERROR_SELECTOR_OFFSET, REVERT_ERROR_SELECTOR_END) === REVERT_ERROR_SELECTOR) {
|
||||
const revertReason = ethers.utils.defaultAbiCoder.decode(
|
||||
['string'],
|
||||
ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH),
|
||||
);
|
||||
throw new Error(revertReason);
|
||||
}
|
||||
}
|
||||
// Throws if the given arguments cannot be safely/correctly encoded based on
|
||||
// the given inputAbi. An argument may not be considered safely encodeable
|
||||
// if it overflows the corresponding Solidity type, there is a bug in the
|
||||
// encoder, or the encoder performs unsafe type coercion.
|
||||
public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): void {
|
||||
const coder = ethers.utils.AbiCoder.defaultCoder;
|
||||
const coder = new ethers.AbiCoder();
|
||||
const params = abiUtils.parseEthersParams(inputAbi);
|
||||
const rawEncoded = coder.encode(params.names, params.types, args);
|
||||
const rawDecoded = coder.decode(params.names, params.types, rawEncoded);
|
||||
const rawEncoded = coder.encode(inputAbi, args);
|
||||
const rawDecoded = coder.decode(inputAbi, rawEncoded);
|
||||
for (let i = 0; i < rawDecoded.length; i++) {
|
||||
const original = args[i];
|
||||
const decoded = rawDecoded[i];
|
||||
|
@@ -1,4 +1,60 @@
|
||||
[
|
||||
{
|
||||
"version": "3.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"version": "3.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Change /order_config request to a POST instead of GET",
|
||||
"pr": 1091
|
||||
}
|
||||
],
|
||||
"timestamp": 1538157789
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "2.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Import SRA-related types from @0xproject/types",
|
||||
"pr": 1085
|
||||
}
|
||||
],
|
||||
"timestamp": 1537875740
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "2.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537369748,
|
||||
"version": "2.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"changes": [
|
||||
|
@@ -5,6 +5,30 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.0.1 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.0 - _September 28, 2018_
|
||||
|
||||
* Change /order_config request to a POST instead of GET (#1091)
|
||||
|
||||
## v2.0.4 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.3 - _September 25, 2018_
|
||||
|
||||
* Import SRA-related types from @0xproject/types (#1085)
|
||||
|
||||
## v2.0.2 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.1 - _September 19, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.0 - _September 5, 2018_
|
||||
|
||||
* Change `OrderConfigRequest` to use BigNumber instead of string for relevant fields. (#1058)
|
||||
@@ -18,7 +42,7 @@ CHANGELOG
|
||||
* Updated for SRA v2 (#974)
|
||||
* Stopped exporting `Order` type (#924)
|
||||
|
||||
## v1.0.5 - _August 14, 2018_
|
||||
## v1.0.5 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -38,7 +62,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Remove `WebSocketOrderbookChannel` from the public interface and replace with `orderbookChannelFactory`
|
||||
|
||||
@@ -62,7 +86,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.6.12 - _May 5, 2018_
|
||||
## v0.6.12 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/connect",
|
||||
"version": "2.0.0",
|
||||
"version": "3.0.1",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -16,6 +16,7 @@
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"clean": "shx rm -rf lib test_temp generated_docs",
|
||||
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
|
||||
"lint": "tslint --project .",
|
||||
@@ -43,12 +44,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md",
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"lodash": "^4.17.5",
|
||||
"query-string": "^5.0.1",
|
||||
"sinon": "^4.0.0",
|
||||
@@ -56,7 +57,7 @@
|
||||
"websocket": "^1.0.25"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/fetch-mock": "^6.0.3",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^2.2.42",
|
||||
|
@@ -1,19 +1,10 @@
|
||||
import { assert } from '@0xproject/assert';
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { fetchAsync } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import * as queryString from 'query-string';
|
||||
|
||||
import { schemas as clientSchemas } from './schemas/schemas';
|
||||
import {
|
||||
APIOrder,
|
||||
AssetPairsRequestOpts,
|
||||
AssetPairsResponse,
|
||||
Client,
|
||||
FeeRecipientsResponse,
|
||||
HttpRequestOptions,
|
||||
HttpRequestType,
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrderConfigRequest,
|
||||
@@ -22,14 +13,21 @@ import {
|
||||
OrdersResponse,
|
||||
PagedRequestOpts,
|
||||
RequestOpts,
|
||||
} from './types';
|
||||
SignedOrder,
|
||||
} from '@0xproject/types';
|
||||
import { fetchAsync } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import * as queryString from 'query-string';
|
||||
|
||||
import { schemas as clientSchemas } from './schemas/schemas';
|
||||
import { Client, HttpRequestOptions, HttpRequestType } from './types';
|
||||
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';
|
||||
|
||||
const TRAILING_SLASHES_REGEX = /\/+$/;
|
||||
|
||||
/**
|
||||
* This class includes all the functionality related to interacting with a set of HTTP endpoints
|
||||
* that implement the standard relayer API v0
|
||||
* that implement the standard relayer API v2
|
||||
*/
|
||||
export class HttpClient implements Client {
|
||||
private readonly _apiEndpointUrl: string;
|
||||
@@ -151,7 +149,7 @@ export class HttpClient implements Client {
|
||||
params: requestOpts,
|
||||
payload: request,
|
||||
};
|
||||
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Get, httpRequestOpts);
|
||||
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
|
||||
const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson);
|
||||
return fees;
|
||||
}
|
||||
|
@@ -1,23 +1,20 @@
|
||||
export { HttpClient } from './http_client';
|
||||
export { ordersChannelFactory } from './orders_channel_factory';
|
||||
export { Client, OrdersChannel, OrdersChannelHandler } from './types';
|
||||
export {
|
||||
Client,
|
||||
OrderConfigRequest,
|
||||
OrderConfigResponse,
|
||||
OrdersChannel,
|
||||
OrdersChannelHandler,
|
||||
OrdersChannelSubscriptionOpts,
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrdersRequestOpts,
|
||||
PagedRequestOpts,
|
||||
APIOrder,
|
||||
AssetPairsRequestOpts,
|
||||
RequestOpts,
|
||||
AssetPairsResponse,
|
||||
FeeRecipientsResponse,
|
||||
APIOrder,
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrderConfigRequest,
|
||||
OrderConfigResponse,
|
||||
OrdersChannelSubscriptionOpts,
|
||||
OrdersRequestOpts,
|
||||
OrdersResponse,
|
||||
PagedRequestOpts,
|
||||
PaginatedCollection,
|
||||
} from './types';
|
||||
|
||||
export { SignedOrder } from '@0xproject/types';
|
||||
RequestOpts,
|
||||
SignedOrder,
|
||||
} from '@0xproject/types';
|
||||
|
@@ -1,5 +1,18 @@
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import {
|
||||
APIOrder,
|
||||
AssetPairsItem,
|
||||
AssetPairsRequestOpts,
|
||||
FeeRecipientsResponse,
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrderConfigRequest,
|
||||
OrderConfigResponse,
|
||||
OrdersChannelSubscriptionOpts,
|
||||
OrdersRequestOpts,
|
||||
PagedRequestOpts,
|
||||
PaginatedCollection,
|
||||
SignedOrder,
|
||||
} from '@0xproject/types';
|
||||
|
||||
export interface Client {
|
||||
getAssetPairsAsync: (
|
||||
@@ -18,140 +31,12 @@ export interface OrdersChannel {
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* baseAssetData: The address of assetData designated as the baseToken in the currency pair calculation of price
|
||||
* quoteAssetData: The address of assetData designated as the quoteToken in the currency pair calculation of price
|
||||
* limit: Maximum number of bids and asks in orderbook snapshot
|
||||
*/
|
||||
export interface OrdersChannelSubscriptionOpts {
|
||||
baseAssetData: string;
|
||||
quoteAssetData: string;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
export interface OrdersChannelHandler {
|
||||
onUpdate: (channel: OrdersChannel, subscriptionOpts: OrdersChannelSubscriptionOpts, orders: APIOrder[]) => void;
|
||||
onError: (channel: OrdersChannel, err: Error, subscriptionOpts?: OrdersChannelSubscriptionOpts) => void;
|
||||
onClose: (channel: OrdersChannel) => void;
|
||||
}
|
||||
|
||||
export type OrdersChannelMessage = UpdateOrdersChannelMessage | UnknownOrdersChannelMessage;
|
||||
|
||||
export enum OrdersChannelMessageTypes {
|
||||
Update = 'update',
|
||||
Unknown = 'unknown',
|
||||
}
|
||||
|
||||
export interface UpdateOrdersChannelMessage {
|
||||
type: OrdersChannelMessageTypes.Update;
|
||||
requestId: string;
|
||||
payload: APIOrder[];
|
||||
}
|
||||
|
||||
export interface UnknownOrdersChannelMessage {
|
||||
type: OrdersChannelMessageTypes.Unknown;
|
||||
requestId: string;
|
||||
payload: undefined;
|
||||
}
|
||||
|
||||
export enum WebsocketConnectionEventType {
|
||||
Close = 'close',
|
||||
Error = 'error',
|
||||
Message = 'message',
|
||||
}
|
||||
|
||||
export enum WebsocketClientEventType {
|
||||
Connect = 'connect',
|
||||
ConnectFailed = 'connectFailed',
|
||||
}
|
||||
|
||||
export type OrdersResponse = PaginatedCollection<APIOrder>;
|
||||
|
||||
export interface APIOrder {
|
||||
order: SignedOrder;
|
||||
metaData: object;
|
||||
}
|
||||
|
||||
export interface AssetPairsRequestOpts {
|
||||
assetDataA?: string;
|
||||
assetDataB?: string;
|
||||
}
|
||||
|
||||
export type AssetPairsResponse = PaginatedCollection<AssetPairsItem>;
|
||||
|
||||
export interface AssetPairsItem {
|
||||
assetDataA: Asset;
|
||||
assetDataB: Asset;
|
||||
}
|
||||
|
||||
export interface Asset {
|
||||
assetData: string;
|
||||
minAmount: BigNumber;
|
||||
maxAmount: BigNumber;
|
||||
precision: number;
|
||||
}
|
||||
|
||||
export interface OrdersRequestOpts {
|
||||
makerAssetProxyId?: string;
|
||||
takerAssetProxyId?: string;
|
||||
makerAssetAddress?: string;
|
||||
takerAssetAddress?: string;
|
||||
exchangeAddress?: string;
|
||||
senderAddress?: string;
|
||||
makerAssetData?: string;
|
||||
takerAssetData?: string;
|
||||
makerAddress?: string;
|
||||
takerAddress?: string;
|
||||
traderAddress?: string;
|
||||
feeRecipientAddress?: string;
|
||||
}
|
||||
|
||||
export interface OrderbookRequest {
|
||||
baseAssetData: string;
|
||||
quoteAssetData: string;
|
||||
}
|
||||
|
||||
export interface OrderbookResponse {
|
||||
bids: PaginatedCollection<APIOrder>;
|
||||
asks: PaginatedCollection<APIOrder>;
|
||||
}
|
||||
|
||||
export interface PaginatedCollection<T> {
|
||||
total: number;
|
||||
page: number;
|
||||
perPage: number;
|
||||
records: T[];
|
||||
}
|
||||
|
||||
export interface OrderConfigRequest {
|
||||
makerAddress: string;
|
||||
takerAddress: string;
|
||||
makerAssetAmount: BigNumber;
|
||||
takerAssetAmount: BigNumber;
|
||||
makerAssetData: string;
|
||||
takerAssetData: string;
|
||||
exchangeAddress: string;
|
||||
expirationTimeSeconds: BigNumber;
|
||||
}
|
||||
|
||||
export interface OrderConfigResponse {
|
||||
makerFee: BigNumber;
|
||||
takerFee: BigNumber;
|
||||
feeRecipientAddress: string;
|
||||
senderAddress: string;
|
||||
}
|
||||
|
||||
export type FeeRecipientsResponse = PaginatedCollection<string>;
|
||||
|
||||
export interface RequestOpts {
|
||||
networkId?: number;
|
||||
}
|
||||
|
||||
export interface PagedRequestOpts {
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
}
|
||||
|
||||
export interface HttpRequestOptions {
|
||||
params?: object;
|
||||
payload?: object;
|
||||
|
@@ -2,7 +2,7 @@ import { assert } from '@0xproject/assert';
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types';
|
||||
import { OrdersChannelMessage, OrdersChannelMessageTypes } from '@0xproject/types';
|
||||
|
||||
import { relayerResponseJsonParsers } from './relayer_response_json_parsers';
|
||||
|
||||
|
@@ -9,7 +9,7 @@ import {
|
||||
OrderbookResponse,
|
||||
OrderConfigResponse,
|
||||
OrdersResponse,
|
||||
} from '../types';
|
||||
} from '@0xproject/types';
|
||||
|
||||
import { typeConverters } from './type_converters';
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { orderParsingUtils } from '@0xproject/order-utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { APIOrder } from '../types';
|
||||
import { APIOrder } from '@0xproject/types';
|
||||
|
||||
export const typeConverters = {
|
||||
convertOrderbookStringFieldsToBigNumber(orderbook: any): any {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { OrdersChannelMessageTypes, OrdersChannelSubscriptionOpts } from '@0xproject/types';
|
||||
import * as _ from 'lodash';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as WebSocket from 'websocket';
|
||||
|
||||
import { OrdersChannel, OrdersChannelHandler, OrdersChannelMessageTypes, OrdersChannelSubscriptionOpts } from './types';
|
||||
import { OrdersChannel, OrdersChannelHandler } from './types';
|
||||
import { assert } from './utils/assert';
|
||||
import { ordersChannelMessageParser } from './utils/orders_channel_message_parser';
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { AssetPairsResponse } from '../../../src/types';
|
||||
import { AssetPairsResponse } from '@0xproject/types';
|
||||
|
||||
export const assetDataPairsResponse: AssetPairsResponse = {
|
||||
total: 43,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { FeeRecipientsResponse } from '../../../src/types';
|
||||
import { FeeRecipientsResponse } from '@0xproject/types';
|
||||
|
||||
export const feeRecipientsResponse: FeeRecipientsResponse = {
|
||||
total: 3,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { OrderConfigResponse } from '../../../src/types';
|
||||
import { OrderConfigResponse } from '@0xproject/types';
|
||||
|
||||
export const orderConfigResponse: OrderConfigResponse = {
|
||||
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { OrderbookResponse } from '../../../src/types';
|
||||
import { OrderbookResponse } from '@0xproject/types';
|
||||
|
||||
export const orderbookResponse: OrderbookResponse = {
|
||||
bids: {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { OrdersResponse } from '../../../src/types';
|
||||
import { OrdersResponse } from '@0xproject/types';
|
||||
|
||||
export const ordersResponse: OrdersResponse = {
|
||||
total: 984,
|
||||
|
@@ -148,12 +148,12 @@ describe('HttpClient', () => {
|
||||
};
|
||||
const url = `${relayUrl}/order_config`;
|
||||
it('gets order config', async () => {
|
||||
fetchMock.get(url, orderConfigResponseJSON);
|
||||
fetchMock.post(url, orderConfigResponseJSON);
|
||||
const fees = await relayerClient.getOrderConfigAsync(request);
|
||||
expect(fees).to.be.deep.equal(orderConfigResponse);
|
||||
});
|
||||
it('does not mutate input', async () => {
|
||||
fetchMock.get(url, orderConfigResponseJSON);
|
||||
fetchMock.post(url, orderConfigResponseJSON);
|
||||
const makerAssetAmountBefore = request.makerAssetAmount;
|
||||
const takerAssetAmountBefore = request.takerAssetAmount;
|
||||
const expirationTimeSecondsBefore = request.expirationTimeSeconds;
|
||||
@@ -163,7 +163,7 @@ describe('HttpClient', () => {
|
||||
expect(expirationTimeSecondsBefore).to.be.deep.equal(request.expirationTimeSeconds);
|
||||
});
|
||||
it('throws an error for invalid JSON response', async () => {
|
||||
fetchMock.get(url, { test: 'dummy' });
|
||||
fetchMock.post(url, { test: 'dummy' });
|
||||
expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected();
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +1,74 @@
|
||||
[
|
||||
{
|
||||
"version": "2.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "2.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note":
|
||||
"Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too.",
|
||||
"pr": 1080
|
||||
},
|
||||
{
|
||||
"note":
|
||||
"Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it",
|
||||
"pr": 1080
|
||||
}
|
||||
],
|
||||
"timestamp": 1537907159
|
||||
},
|
||||
{
|
||||
"version": "1.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1537875740
|
||||
},
|
||||
{
|
||||
"version": "1.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1537541580
|
||||
},
|
||||
{
|
||||
"version": "1.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Drastically reduce the bundle size by removing unused parts of included contract artifacts."
|
||||
}
|
||||
],
|
||||
"timestamp": 1537369748
|
||||
},
|
||||
{
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add ZRX & WETH mainnet contract addresses into the included artifacts"
|
||||
}
|
||||
],
|
||||
"timestamp": 1537265493
|
||||
},
|
||||
{
|
||||
"version": "1.0.1",
|
||||
"changes": [
|
||||
|
@@ -5,6 +5,35 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v2.0.2 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.1 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.0 - _September 25, 2018_
|
||||
|
||||
* Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too. (#1080)
|
||||
* Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it (#1080)
|
||||
|
||||
## v1.0.5 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.3 - _September 19, 2018_
|
||||
|
||||
* Drastically reduce the bundle size by removing unused parts of included contract artifacts.
|
||||
|
||||
## v1.0.2 - _September 18, 2018_
|
||||
|
||||
* Add ZRX & WETH mainnet contract addresses into the included artifacts
|
||||
|
||||
## v1.0.1 - _September 5, 2018_
|
||||
|
||||
* Add `OrderValidatorWrapper`
|
||||
@@ -22,7 +51,7 @@ CHANGELOG
|
||||
* Remove superfluous exported types: `ContractEvent`, `Token`, `OrderFillRequest`, `ContractEventArgs`, `LogEvent`, `OnOrderStateChangeCallback`, `ECSignature`, `OrderStateValid`, `OrderStateInvalid`, `OrderState`, `FilterObject`, `TransactionReceipt` & `TransactionReceiptWithDecodedLogs` (#924)
|
||||
* Added Transaction Encoder for use with 0x Exchange executeTransaction (#975)
|
||||
|
||||
## v1.0.1-rc.3 - _August 14, 2018_
|
||||
## v1.0.1-rc.3 - _August 13, 2018_
|
||||
|
||||
* Added strict encoding/decoding checks for sendTransaction and call (#915)
|
||||
* Add ForwarderWrapper (#934)
|
||||
@@ -40,7 +69,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0-rc.1 - _July 20, 2018_
|
||||
## v1.0.0-rc.1 - _July 19, 2018_
|
||||
|
||||
* Update blockstream to v5.0 and propogate up caught errors to active subscriptions (#815)
|
||||
* Update to v2 of 0x rpotocol (#822)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/contract-wrappers",
|
||||
"version": "1.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "Smart TS wrappers for 0x smart contracts",
|
||||
"keywords": [
|
||||
"0xproject",
|
||||
@@ -12,6 +12,7 @@
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "yarn pre_build && tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"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/**/*",
|
||||
@@ -20,7 +21,7 @@
|
||||
"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": "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-trimmed/$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",
|
||||
@@ -41,18 +42,17 @@
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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",
|
||||
"@0xproject/abi-gen": "^1.0.13",
|
||||
"@0xproject/dev-utils": "^1.0.12",
|
||||
"@0xproject/migrations": "^1.0.14",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/node": "*",
|
||||
"@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",
|
||||
"chai-bignumber": "^2.0.1",
|
||||
@@ -72,19 +72,19 @@
|
||||
"web3-provider-engine": "14.0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/fill-scenarios": "^1.0.7",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"ethereumjs-blockstream": "6.0.0",
|
||||
"ethereumjs-util": "^5.1.1",
|
||||
"ethers": "3.0.22",
|
||||
"ethers": "4.0.0-beta.14",
|
||||
"js-sha3": "^0.7.0",
|
||||
"lodash": "^4.17.5",
|
||||
"uuid": "^3.1.0"
|
||||
|
@@ -58,7 +58,7 @@ export class ContractWrappers {
|
||||
*/
|
||||
public orderValidator: OrderValidatorWrapper;
|
||||
|
||||
private _web3Wrapper: Web3Wrapper;
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
/**
|
||||
* Instantiates a new ContractWrappers instance.
|
||||
* @param provider The Provider instance you would like the 0x.js library to use for interacting with
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import {
|
||||
BlockParamLiteral,
|
||||
ContractAbi,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
LogEntry,
|
||||
LogWithDecodedArgs,
|
||||
RawLog,
|
||||
RawLogEntry,
|
||||
} from 'ethereum-types';
|
||||
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
@@ -157,7 +158,8 @@ export abstract class ContractWrapper {
|
||||
return addressIfExists;
|
||||
}
|
||||
}
|
||||
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, log: LogEntry): void {
|
||||
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, rawLog: RawLogEntry): void {
|
||||
const log: LogEntry = marshaller.unmarshalLog(rawLog);
|
||||
_.forEach(this._filters, (filter: FilterObject, filterToken: string) => {
|
||||
if (filterUtils.matchesFilter(log, filter)) {
|
||||
const decodedLog = this._tryToDecodeLogOrNoop(log) as LogWithDecodedArgs<ArgsType>;
|
||||
@@ -174,8 +176,8 @@ export abstract class ContractWrapper {
|
||||
throw new Error(ContractWrappersError.SubscriptionAlreadyPresent);
|
||||
}
|
||||
this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
|
||||
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
|
||||
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
|
||||
this._blockstreamGetBlockOrNullAsync.bind(this),
|
||||
this._blockstreamGetLogsAsync.bind(this),
|
||||
ContractWrapper._onBlockAndLogStreamerError.bind(this, isVerbose),
|
||||
);
|
||||
const catchAllLogFilter = {};
|
||||
@@ -194,6 +196,32 @@ export abstract class ContractWrapper {
|
||||
this._onLogStateChanged.bind(this, isRemoved),
|
||||
);
|
||||
}
|
||||
// This method only exists in order to comply with the expected interface of Blockstream's constructor
|
||||
private async _blockstreamGetBlockOrNullAsync(hash: string): Promise<Block | null> {
|
||||
const shouldIncludeTransactionData = false;
|
||||
const blockOrNull = await this._web3Wrapper.sendRawPayloadAsync<Block | null>({
|
||||
method: 'eth_getBlockByHash',
|
||||
params: [hash, shouldIncludeTransactionData],
|
||||
});
|
||||
return blockOrNull;
|
||||
}
|
||||
// This method only exists in order to comply with the expected interface of Blockstream's constructor
|
||||
private async _blockstreamGetLatestBlockOrNullAsync(): Promise<Block | null> {
|
||||
const shouldIncludeTransactionData = false;
|
||||
const blockOrNull = await this._web3Wrapper.sendRawPayloadAsync<Block | null>({
|
||||
method: 'eth_getBlockByNumber',
|
||||
params: [BlockParamLiteral.Latest, shouldIncludeTransactionData],
|
||||
});
|
||||
return blockOrNull;
|
||||
}
|
||||
// This method only exists in order to comply with the expected interface of Blockstream's constructor
|
||||
private async _blockstreamGetLogsAsync(filterOptions: FilterObject): Promise<RawLogEntry[]> {
|
||||
const logs = await this._web3Wrapper.sendRawPayloadAsync<RawLogEntry[]>({
|
||||
method: 'eth_getLogs',
|
||||
params: [filterOptions],
|
||||
});
|
||||
return logs as RawLogEntry[];
|
||||
}
|
||||
// HACK: This should be a package-scoped method (which doesn't exist in TS)
|
||||
// We don't want this method available in the public interface for all classes
|
||||
// who inherit from ContractWrapper, and it is only used by the internal implementation
|
||||
@@ -212,11 +240,14 @@ export abstract class ContractWrapper {
|
||||
delete this._blockAndLogStreamerIfExists;
|
||||
}
|
||||
private async _reconcileBlockAsync(): Promise<void> {
|
||||
const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest);
|
||||
const latestBlockOrNull = await this._blockstreamGetLatestBlockOrNullAsync();
|
||||
if (_.isNull(latestBlockOrNull)) {
|
||||
return; // noop
|
||||
}
|
||||
// We need to coerce to Block type cause Web3.Block includes types for mempool blocks
|
||||
if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
|
||||
// If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
|
||||
await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block);
|
||||
await this._blockAndLogStreamerIfExists.reconcileNewBlock(latestBlockOrNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import { TransactionOpts } from '../types';
|
||||
import { assert } from '../utils/assert';
|
||||
import { calldataOptimizationUtils } from '../utils/calldata_optimization_utils';
|
||||
import { constants } from '../utils/constants';
|
||||
import { utils } from '../utils/utils';
|
||||
|
||||
import { ContractWrapper } from './contract_wrapper';
|
||||
import { ForwarderContract } from './generated/forwarder';
|
||||
@@ -57,7 +58,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
takerAddress: string,
|
||||
ethAmount: BigNumber,
|
||||
signedFeeOrders: SignedOrder[] = [],
|
||||
feePercentage: BigNumber = constants.ZERO_AMOUNT,
|
||||
feePercentage: number = 0,
|
||||
feeRecipientAddress: string = constants.NULL_ADDRESS,
|
||||
txOpts: TransactionOpts = {},
|
||||
): Promise<string> {
|
||||
@@ -66,7 +67,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||
assert.isBigNumber('ethAmount', ethAmount);
|
||||
assert.doesConformToSchema('signedFeeOrders', signedFeeOrders, schemas.signedOrdersSchema);
|
||||
assert.isBigNumber('feePercentage', feePercentage);
|
||||
assert.isNumber('feePercentage', feePercentage);
|
||||
assert.isETHAddressHex('feeRecipientAddress', feeRecipientAddress);
|
||||
assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
|
||||
// other assertions
|
||||
@@ -76,6 +77,8 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
this.getZRXTokenAddress(),
|
||||
this.getEtherTokenAddress(),
|
||||
);
|
||||
// format feePercentage
|
||||
const formattedFeePercentage = utils.numberPercentageToEtherTokenAmountPercentage(feePercentage);
|
||||
// lowercase input addresses
|
||||
const normalizedTakerAddress = takerAddress.toLowerCase();
|
||||
const normalizedFeeRecipientAddress = feeRecipientAddress.toLowerCase();
|
||||
@@ -89,7 +92,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
_.map(optimizedMarketOrders, order => order.signature),
|
||||
optimizedFeeOrders,
|
||||
_.map(optimizedFeeOrders, order => order.signature),
|
||||
feePercentage,
|
||||
formattedFeePercentage,
|
||||
feeRecipientAddress,
|
||||
{
|
||||
value: ethAmount,
|
||||
@@ -124,7 +127,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
takerAddress: string,
|
||||
ethAmount: BigNumber,
|
||||
signedFeeOrders: SignedOrder[] = [],
|
||||
feePercentage: BigNumber = constants.ZERO_AMOUNT,
|
||||
feePercentage: number = 0,
|
||||
feeRecipientAddress: string = constants.NULL_ADDRESS,
|
||||
txOpts: TransactionOpts = {},
|
||||
): Promise<string> {
|
||||
@@ -134,7 +137,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||
assert.isBigNumber('ethAmount', ethAmount);
|
||||
assert.doesConformToSchema('signedFeeOrders', signedFeeOrders, schemas.signedOrdersSchema);
|
||||
assert.isBigNumber('feePercentage', feePercentage);
|
||||
assert.isNumber('feePercentage', feePercentage);
|
||||
assert.isETHAddressHex('feeRecipientAddress', feeRecipientAddress);
|
||||
assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
|
||||
// other assertions
|
||||
@@ -144,6 +147,8 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
this.getZRXTokenAddress(),
|
||||
this.getEtherTokenAddress(),
|
||||
);
|
||||
// format feePercentage
|
||||
const formattedFeePercentage = utils.numberPercentageToEtherTokenAmountPercentage(feePercentage);
|
||||
// lowercase input addresses
|
||||
const normalizedTakerAddress = takerAddress.toLowerCase();
|
||||
const normalizedFeeRecipientAddress = feeRecipientAddress.toLowerCase();
|
||||
@@ -158,7 +163,7 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
_.map(optimizedMarketOrders, order => order.signature),
|
||||
optimizedFeeOrders,
|
||||
_.map(optimizedFeeOrders, order => order.signature),
|
||||
feePercentage,
|
||||
formattedFeePercentage,
|
||||
feeRecipientAddress,
|
||||
{
|
||||
value: ethAmount,
|
||||
|
@@ -3,7 +3,6 @@ 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 {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { assert as sharedAssert } from '@0xproject/assert';
|
||||
// HACK: We need those two unused imports because they're actually used by sharedAssert which gets injected here
|
||||
import { Schema } from '@0xproject/json-schemas'; // tslint:disable-line:no-unused-variable
|
||||
import { signatureUtils, assetDataUtils } from '@0xproject/order-utils';
|
||||
import { assetDataUtils, signatureUtils } from '@0xproject/order-utils';
|
||||
import { Order } from '@0xproject/types'; // tslint:disable-line:no-unused-variable
|
||||
import { BigNumber } from '@0xproject/utils'; // tslint:disable-line:no-unused-variable
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
|
@@ -12,4 +12,6 @@ export const constants = {
|
||||
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
|
||||
DEFAULT_BLOCK_POLLING_INTERVAL: 1000,
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
ONE_AMOUNT: new BigNumber(1),
|
||||
ETHER_TOKEN_DECIMALS: 18,
|
||||
};
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { RevertReason } from '@0xproject/types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';
|
||||
@@ -24,7 +23,7 @@ const contractCallErrorTransformer = (error: Error) => {
|
||||
const schemaErrorTransformer = (error: Error) => {
|
||||
if (_.includes(error.message, constants.INVALID_TAKER_FORMAT)) {
|
||||
const errMsg =
|
||||
'Order taker must be of type string. If you want anyone to be able to fill an order - pass ZeroEx.NULL_ADDRESS';
|
||||
'Order taker must be of type string. If you want anyone to be able to fill an order - pass NULL_ADDRESS';
|
||||
return new Error(errMsg);
|
||||
}
|
||||
return error;
|
||||
@@ -46,7 +45,7 @@ const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
|
||||
// tslint:disable-next-line:only-arrow-functions
|
||||
descriptor.value = async function(...args: any[]): Promise<any> {
|
||||
try {
|
||||
const result = await originalMethod.apply(this, args);
|
||||
const result = await originalMethod.apply(this, args); // tslint:disable-line:no-invalid-this
|
||||
return result;
|
||||
} catch (error) {
|
||||
const transformedError = errorTransformer(error);
|
||||
@@ -73,7 +72,7 @@ const syncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
|
||||
// tslint:disable-next-line:only-arrow-functions
|
||||
descriptor.value = function(...args: any[]): any {
|
||||
try {
|
||||
const result = originalMethod.apply(this, args);
|
||||
const result = originalMethod.apply(this, args); // tslint:disable-line:no-invalid-this
|
||||
return result;
|
||||
} catch (error) {
|
||||
const transformedError = errorTransformer(error);
|
||||
|
@@ -34,7 +34,7 @@ const ERR_MSG_MAPPING = {
|
||||
};
|
||||
|
||||
export class ExchangeTransferSimulator {
|
||||
private _store: AbstractBalanceAndProxyAllowanceLazyStore;
|
||||
private readonly _store: AbstractBalanceAndProxyAllowanceLazyStore;
|
||||
private static _throwValidationError(
|
||||
failureReason: FailureReason,
|
||||
tradeSide: TradeSide,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { ConstructorAbi, ContractAbi, EventAbi, FallbackAbi, FilterObject, LogEntry, MethodAbi } from 'ethereum-types';
|
||||
import { ContractAbi, EventAbi, FilterObject, LogEntry } from 'ethereum-types';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as jsSHA3 from 'js-sha3';
|
||||
import * as _ from 'lodash';
|
||||
|
@@ -23,7 +23,7 @@ const EIP712_ZEROEX_TRANSACTION_SCHEMA: EIP712Schema = {
|
||||
* can submit this to the blockchain. The Exchange context executes as if UserA had directly submitted this transaction.
|
||||
*/
|
||||
export class TransactionEncoder {
|
||||
private _exchangeInstance: ExchangeContract;
|
||||
private readonly _exchangeInstance: ExchangeContract;
|
||||
constructor(exchangeInstance: ExchangeContract) {
|
||||
this._exchangeInstance = exchangeInstance;
|
||||
}
|
||||
|
@@ -1,4 +1,7 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
|
||||
import { constants } from './constants';
|
||||
|
||||
export const utils = {
|
||||
getCurrentUnixTimestampSec(): BigNumber {
|
||||
@@ -8,4 +11,7 @@ export const utils = {
|
||||
getCurrentUnixTimestampMs(): BigNumber {
|
||||
return new BigNumber(Date.now());
|
||||
},
|
||||
numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber {
|
||||
return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage);
|
||||
},
|
||||
};
|
||||
|
@@ -3,7 +3,6 @@ import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
import 'mocha';
|
||||
|
||||
import { assert } from '../src/utils/assert';
|
||||
import { calldataOptimizationUtils } from '../src/utils/calldata_optimization_utils';
|
||||
import { constants } from '../src/utils/constants';
|
||||
|
||||
|
@@ -229,11 +229,17 @@ describe('ERC721Wrapper', () => {
|
||||
it('should set the proxy approval', async () => {
|
||||
const tokenId = await tokenUtils.mintDummyERC721Async(tokenAddress, ownerAddress);
|
||||
|
||||
const approvalBeforeSet = await contractWrappers.erc721Token.isProxyApprovedAsync(tokenAddress, tokenId);
|
||||
expect(approvalBeforeSet).to.be.false();
|
||||
const isProxyApprovedBeforeSet = await contractWrappers.erc721Token.isProxyApprovedAsync(
|
||||
tokenAddress,
|
||||
tokenId,
|
||||
);
|
||||
expect(isProxyApprovedBeforeSet).to.be.false();
|
||||
await contractWrappers.erc721Token.setProxyApprovalAsync(tokenAddress, tokenId);
|
||||
const approvalAfterSet = await contractWrappers.erc721Token.isProxyApprovedAsync(tokenAddress, tokenId);
|
||||
expect(approvalAfterSet).to.be.true();
|
||||
const isProxyApprovedAfterSet = await contractWrappers.erc721Token.isProxyApprovedAsync(
|
||||
tokenAddress,
|
||||
tokenId,
|
||||
);
|
||||
expect(isProxyApprovedAfterSet).to.be.true();
|
||||
});
|
||||
});
|
||||
describe('#subscribe', () => {
|
||||
@@ -357,7 +363,6 @@ describe('ERC721Wrapper', () => {
|
||||
);
|
||||
contractWrappers.erc721Token.unsubscribe(subscriptionToken);
|
||||
|
||||
const tokenId = await tokenUtils.mintDummyERC721Async(tokenAddress, ownerAddress);
|
||||
const isApproved = true;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await contractWrappers.erc721Token.setApprovalForAllAsync(
|
||||
@@ -373,15 +378,11 @@ describe('ERC721Wrapper', () => {
|
||||
});
|
||||
});
|
||||
describe('#getLogsAsync', () => {
|
||||
let tokenTransferProxyAddress: string;
|
||||
const blockRange: BlockRange = {
|
||||
fromBlock: 0,
|
||||
toBlock: BlockParamLiteral.Latest,
|
||||
};
|
||||
let txHash: string;
|
||||
before(() => {
|
||||
tokenTransferProxyAddress = contractWrappers.erc721Proxy.getContractAddress();
|
||||
});
|
||||
it('should get logs with decoded args emitted by ApprovalForAll', async () => {
|
||||
const isApprovedForAll = true;
|
||||
txHash = await contractWrappers.erc721Token.setApprovalForAllAsync(
|
||||
|
@@ -344,7 +344,7 @@ describe('EtherTokenWrapper', () => {
|
||||
etherTokenAddress = tokenUtils.getWethTokenAddress();
|
||||
erc20ProxyAddress = contractWrappers.erc20Proxy.getContractAddress();
|
||||
// Start the block range after all migrations to avoid unexpected logs
|
||||
const currentBlock = await web3Wrapper.getBlockNumberAsync();
|
||||
const currentBlock: number = await web3Wrapper.getBlockNumberAsync();
|
||||
const fromBlock = currentBlock + 1;
|
||||
blockRange = {
|
||||
fromBlock,
|
||||
|
@@ -1,14 +1,12 @@
|
||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||
import { DoneCallback, SignedOrder } from '@0xproject/types';
|
||||
import { assetDataUtils } from '@0xproject/order-utils';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as chai from 'chai';
|
||||
import { BlockParamLiteral } from 'ethereum-types';
|
||||
import 'mocha';
|
||||
|
||||
import { ContractWrappers, ExchangeCancelEventArgs, ExchangeEvents, ExchangeFillEventArgs, OrderStatus } from '../src';
|
||||
import { DecodedLogEvent } from '../src/types';
|
||||
import { ContractWrappers, OrderStatus } from '../src';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
import { constants } from './utils/constants';
|
||||
|
@@ -1,15 +1,14 @@
|
||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||
import { DoneCallback, SignedOrder } from '@0xproject/types';
|
||||
import { assetDataUtils } from '@0xproject/order-utils';
|
||||
import { 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 { ContractWrappers, OrderStatus } from '../src';
|
||||
import { OrderInfo, TraderInfo } from '../src/types';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
import { constants } from './utils/constants';
|
||||
@@ -26,7 +25,6 @@ describe('OrderValidator', () => {
|
||||
blockPollingIntervalMs: 0,
|
||||
};
|
||||
const fillableAmount = new BigNumber(5);
|
||||
const partialFillAmount = new BigNumber(2);
|
||||
let contractWrappers: ContractWrappers;
|
||||
let fillScenarios: FillScenarios;
|
||||
let exchangeContractAddress: string;
|
||||
|
122
packages/contract-wrappers/test/revert_validation_test.ts
Normal file
122
packages/contract-wrappers/test/revert_validation_test.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||
import { runV2MigrationsAsync } from '@0xproject/migrations';
|
||||
import { assetDataUtils } from '@0xproject/order-utils';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { ContractWrappers } from '../src';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
import { constants } from './utils/constants';
|
||||
import { tokenUtils } from './utils/token_utils';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('Revert Validation ExchangeWrapper', () => {
|
||||
let contractWrappers: ContractWrappers;
|
||||
let userAddresses: string[];
|
||||
let zrxTokenAddress: string;
|
||||
let fillScenarios: FillScenarios;
|
||||
let exchangeContractAddress: string;
|
||||
let makerTokenAddress: string;
|
||||
let takerTokenAddress: string;
|
||||
let coinbase: string;
|
||||
let makerAddress: string;
|
||||
let anotherMakerAddress: string;
|
||||
let takerAddress: string;
|
||||
let makerAssetData: string;
|
||||
let takerAssetData: string;
|
||||
let feeRecipient: string;
|
||||
let txHash: string;
|
||||
let blockchainLifecycle: BlockchainLifecycle;
|
||||
let web3Wrapper: Web3Wrapper;
|
||||
const fillableAmount = new BigNumber(5);
|
||||
const takerTokenFillAmount = new BigNumber(5);
|
||||
let signedOrder: SignedOrder;
|
||||
const config = {
|
||||
networkId: constants.TESTRPC_NETWORK_ID,
|
||||
blockPollingIntervalMs: 0,
|
||||
};
|
||||
before(async () => {
|
||||
// vmErrorsOnRPCResponse is useful for quick feedback and testing during development
|
||||
// but is not the default behaviour in production. Here we ensure our failure cases
|
||||
// are handled in an environment which behaves similar to production
|
||||
const provider = web3Factory.getRpcProvider({
|
||||
shouldUseInProcessGanache: true,
|
||||
shouldThrowErrorsOnGanacheRPCResponse: false,
|
||||
});
|
||||
web3Wrapper = new Web3Wrapper(provider);
|
||||
blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
const txDefaults = {
|
||||
gas: devConstants.GAS_LIMIT,
|
||||
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||
};
|
||||
const artifactsDir = `src/artifacts`;
|
||||
// Re-deploy the artifacts in this provider, rather than in the default provider exposed in
|
||||
// the beforeAll hook. This is due to the fact that the default provider enabled vmErrorsOnRPCResponse
|
||||
// and we are explicity testing with vmErrorsOnRPCResponse disabled.
|
||||
await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
|
||||
await blockchainLifecycle.startAsync();
|
||||
contractWrappers = new ContractWrappers(provider, config);
|
||||
exchangeContractAddress = contractWrappers.exchange.getContractAddress();
|
||||
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
|
||||
zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
|
||||
fillScenarios = new FillScenarios(
|
||||
provider,
|
||||
userAddresses,
|
||||
zrxTokenAddress,
|
||||
exchangeContractAddress,
|
||||
contractWrappers.erc20Proxy.getContractAddress(),
|
||||
contractWrappers.erc721Proxy.getContractAddress(),
|
||||
);
|
||||
[coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
|
||||
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
|
||||
[makerAssetData, takerAssetData] = [
|
||||
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
|
||||
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
|
||||
];
|
||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
fillableAmount,
|
||||
);
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
describe('#fillOrderAsync', () => {
|
||||
it('should throw the revert reason when shouldValidate is true and a fill would revert', async () => {
|
||||
// Create a scenario where the fill will revert
|
||||
const makerTokenBalance = await contractWrappers.erc20Token.getBalanceAsync(
|
||||
makerTokenAddress,
|
||||
makerAddress,
|
||||
);
|
||||
// Transfer all of the tokens from maker to create a failure scenario
|
||||
txHash = await contractWrappers.erc20Token.transferAsync(
|
||||
makerTokenAddress,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
makerTokenBalance,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
|
||||
expect(
|
||||
contractWrappers.exchange.fillOrderAsync(signedOrder, takerTokenFillAmount, takerAddress, {
|
||||
shouldValidate: true,
|
||||
}),
|
||||
).to.be.rejectedWith('TRANSFER_FAILED');
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,6 +1,5 @@
|
||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { DoneCallback } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import 'mocha';
|
||||
import * as Sinon from 'sinon';
|
||||
@@ -18,17 +17,11 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('SubscriptionTest', () => {
|
||||
let contractWrappers: ContractWrappers;
|
||||
let userAddresses: string[];
|
||||
let coinbase: string;
|
||||
let addressWithoutFunds: string;
|
||||
const config = {
|
||||
networkId: constants.TESTRPC_NETWORK_ID,
|
||||
};
|
||||
before(async () => {
|
||||
contractWrappers = new ContractWrappers(provider, config);
|
||||
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
|
||||
coinbase = userAddresses[0];
|
||||
addressWithoutFunds = userAddresses[1];
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -39,7 +32,6 @@ describe('SubscriptionTest', () => {
|
||||
describe('#subscribe', () => {
|
||||
const indexFilterValues = {};
|
||||
let tokenAddress: string;
|
||||
const allowanceAmount = new BigNumber(42);
|
||||
let stubs: Sinon.SinonStub[] = [];
|
||||
before(() => {
|
||||
const tokenAddresses = tokenUtils.getDummyERC20TokenAddresses();
|
||||
@@ -53,7 +45,7 @@ describe('SubscriptionTest', () => {
|
||||
it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => {
|
||||
(async () => {
|
||||
const callback = (err: Error | null, _logEvent?: DecodedLogEvent<ERC20TokenApprovalEventArgs>) =>
|
||||
_.noop;
|
||||
_.noop.bind(_);
|
||||
contractWrappers.erc20Token.subscribe(
|
||||
tokenAddress,
|
||||
ERC20TokenEvents.Approval,
|
||||
@@ -61,7 +53,7 @@ describe('SubscriptionTest', () => {
|
||||
callback,
|
||||
);
|
||||
stubs = [
|
||||
Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws(
|
||||
Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockIfExistsAsync').throws(
|
||||
new Error('JSON RPC error'),
|
||||
),
|
||||
];
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||
import { assetDataUtils, signatureUtils, generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils';
|
||||
import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils, signatureUtils } from '@0xproject/order-utils';
|
||||
import { SignedOrder, SignerType } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import 'mocha';
|
||||
|
@@ -65,10 +65,12 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
[{{> params inputs=ctor.inputs}}],
|
||||
BaseContract._bigNumberToString,
|
||||
);
|
||||
const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}});
|
||||
const iface = new ethers.Interface(abi);
|
||||
const deployInfo = iface.deployFunction;
|
||||
const txData = deployInfo.encode(bytecode, [{{> params inputs=ctor.inputs}}]);
|
||||
const web3Wrapper = new Web3Wrapper(provider);
|
||||
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
{data: txData},
|
||||
txDefaults,
|
||||
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
|
||||
);
|
||||
|
@@ -8,10 +8,8 @@ async callAsync(
|
||||
const inputAbi = self._lookupAbi(functionSignature).inputs;
|
||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
|
||||
BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]);
|
||||
const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}}(
|
||||
{{> params inputs=inputs}}
|
||||
) as ethers.CallDescription;
|
||||
const encodedData = ethersFunction.data;
|
||||
const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}};
|
||||
const encodedData = ethersFunction.encode([{{> params inputs=inputs}}]);
|
||||
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
||||
{
|
||||
to: self.address,
|
||||
@@ -21,7 +19,8 @@ async callAsync(
|
||||
self._web3Wrapper.getContractDefaults(),
|
||||
);
|
||||
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
|
||||
let resultArray = ethersFunction.parse(rawCallResult);
|
||||
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
|
||||
let resultArray = ethersFunction.decode(rawCallResult);
|
||||
const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs;
|
||||
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
|
||||
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this));
|
||||
|
@@ -12,9 +12,7 @@ public {{this.tsName}} = {
|
||||
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
|
||||
BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]);
|
||||
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
||||
{{> params inputs=inputs}}
|
||||
).data;
|
||||
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
|
||||
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
||||
{
|
||||
to: self.address,
|
||||
@@ -37,9 +35,7 @@ public {{this.tsName}} = {
|
||||
const self = this as any as {{contractName}}Contract;
|
||||
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
|
||||
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
||||
{{> params inputs=inputs}}
|
||||
).data;
|
||||
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
|
||||
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
||||
{
|
||||
to: self.address,
|
||||
@@ -57,9 +53,7 @@ public {{this.tsName}} = {
|
||||
const self = this as any as {{contractName}}Contract;
|
||||
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
|
||||
const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
||||
{{> params inputs=inputs}}
|
||||
).data;
|
||||
const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
{{> callAsync}}
|
||||
|
@@ -1,14 +1,35 @@
|
||||
## Contracts
|
||||
|
||||
Smart contracts that implement the 0x protocol.
|
||||
Smart contracts that implement the 0x protocol. Addresses of the deployed contracts can be found [here](https://0xproject.com/wiki#Deployed-Addresses).
|
||||
|
||||
## Usage
|
||||
|
||||
* [Docs](https://0xproject.com/docs/contracts)
|
||||
* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture)
|
||||
* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions)
|
||||
* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses)
|
||||
* [0x protocol message format](https://0xproject.com/wiki#Message-Format)
|
||||
### 2.0.0
|
||||
|
||||
Contracts that make up and interact with version 2.0.0 of the protocol can be found in the `src/2.0.0` directory. The contents of this directory are broken down into the following subdirectories:
|
||||
|
||||
* protocol
|
||||
* This directory contains the contracts that make up version 2.0.0. A full specification can be found [here](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md).
|
||||
* extensions
|
||||
* This directory contains contracts that interact with the 2.0.0 contracts and will be used in production, such as the [Forwarder](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/forwarder-specification.md) contract.
|
||||
* examples
|
||||
* This directory contains example implementations of contracts that interact with the protocol but are _not_ intended for use in production. Examples include [filter](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#filter-contracts) contracts, a [Wallet](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#wallet) contract, and a [Validator](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#validator) contract, among others.
|
||||
* tokens
|
||||
* This directory contains implementations of different tokens and token standards, including [wETH](https://weth.io/), ZRX, [ERC20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md), and [ERC721](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md).
|
||||
* multisig
|
||||
* This directory contains the [Gnosis MultiSigWallet](https://github.com/gnosis/MultiSigWallet) and a custom extension that adds a timelock to transactions within the MultiSigWallet.
|
||||
* utils
|
||||
* This directory contains libraries and utils that are shared across all of the other directories.
|
||||
* test
|
||||
* This directory contains mocks and other contracts that are used solely for testing contracts within the other directories.
|
||||
|
||||
### 1.0.0
|
||||
|
||||
Contracts that make up version 1.0.0 of the protocol can be found in `src/1.0.0`. These contracts are considered deprecated and will have limited support going forward.
|
||||
|
||||
## Bug bounty
|
||||
|
||||
A bug bounty for the 2.0.0 contracts is ongoing! Instructions can be found [here](https://0xproject.com/wiki#Bug-Bounty).
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "contracts",
|
||||
"version": "2.1.43",
|
||||
"version": "2.1.49",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -12,6 +12,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn pre_build && tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"pre_build": "run-s compile copy_artifacts generate_contract_wrappers",
|
||||
"copy_artifacts": "copyfiles -u 4 '../migrations/artifacts/development/**/*' ./lib/artifacts;",
|
||||
"test": "yarn run_mocha",
|
||||
@@ -45,16 +46,16 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/contracts/README.md",
|
||||
"devDependencies": {
|
||||
"@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",
|
||||
"@0xproject/abi-gen": "^1.0.13",
|
||||
"@0xproject/dev-utils": "^1.0.12",
|
||||
"@0xproject/sol-compiler": "^1.1.7",
|
||||
"@0xproject/sol-cov": "^2.1.7",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/bn.js": "^4.11.0",
|
||||
"@types/ethereumjs-abi": "^0.6.0",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/node": "*",
|
||||
"@types/yargs": "^10.0.0",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
@@ -72,18 +73,18 @@
|
||||
"yargs": "^10.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"@types/js-combinatorics": "^0.5.29",
|
||||
"bn.js": "^4.11.8",
|
||||
"ethereum-types": "^1.0.6",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"ethereumjs-abi": "0.6.5",
|
||||
"ethereumjs-util": "^5.1.1",
|
||||
"ethers": "3.0.22",
|
||||
"ethers": "4.0.0-beta.14",
|
||||
"js-combinatorics": "^0.5.3",
|
||||
"lodash": "^4.17.5"
|
||||
}
|
||||
|
@@ -269,7 +269,10 @@ describe('MultiSigWalletWithTimeLock', () => {
|
||||
expect(confirmRes.logs).to.have.length(2);
|
||||
|
||||
const blockNum = await web3Wrapper.getBlockNumberAsync();
|
||||
const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
|
||||
const blockInfo = await web3Wrapper.getBlockIfExistsAsync(blockNum);
|
||||
if (_.isUndefined(blockInfo)) {
|
||||
throw new Error(`Unexpectedly failed to fetch block at #${blockNum}`);
|
||||
}
|
||||
const timestamp = new BigNumber(blockInfo.timestamp);
|
||||
const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.callAsync(txId));
|
||||
|
||||
|
@@ -35,6 +35,9 @@ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise<nu
|
||||
* @returns a new Promise which will resolve with the timestamp in seconds.
|
||||
*/
|
||||
export async function getLatestBlockTimestampAsync(): Promise<number> {
|
||||
const currentBlock = await web3Wrapper.getBlockAsync('latest');
|
||||
return currentBlock.timestamp;
|
||||
const currentBlockIfExists = await web3Wrapper.getBlockIfExistsAsync('latest');
|
||||
if (_.isUndefined(currentBlockIfExists)) {
|
||||
throw new Error(`Unable to fetch latest block.`);
|
||||
}
|
||||
return currentBlockIfExists.timestamp;
|
||||
}
|
||||
|
@@ -1,4 +1,49 @@
|
||||
[
|
||||
{
|
||||
"version": "1.0.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.7",
|
||||
|
@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.12 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.11 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.10 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.9 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.8 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.7 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -17,7 +37,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _August 14, 2018_
|
||||
## v1.0.4 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -33,7 +53,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -59,7 +79,7 @@ CHANGELOG
|
||||
* Pass SolCompilerArtifactAdapter to CoverageSubprovider (#589)
|
||||
* Move callbackErrorReporter over from 0x.js (#579)
|
||||
|
||||
## v0.4.1 - _May 5, 2018_
|
||||
## v0.4.1 - _May 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/dev-utils",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.12",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -9,6 +9,7 @@
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"test": "yarn run_mocha",
|
||||
"rebuild_and_test": "run-s clean build test",
|
||||
"test:circleci": "yarn test:coverage",
|
||||
@@ -28,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/dev-utils/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"chai": "^4.0.1",
|
||||
@@ -42,12 +43,12 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"lodash": "^4.17.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -14,6 +14,7 @@ import { env, EnvVars } from './env';
|
||||
export interface Web3Config {
|
||||
hasAddresses?: boolean; // default: true
|
||||
shouldUseInProcessGanache?: boolean; // default: false
|
||||
shouldThrowErrorsOnGanacheRPCResponse?: boolean; // default: true
|
||||
rpcUrl?: string; // default: localhost:8545
|
||||
shouldUseFakeGasEstimate?: boolean; // default: true
|
||||
}
|
||||
@@ -41,15 +42,19 @@ export const web3Factory = {
|
||||
if (!_.isUndefined(config.rpcUrl)) {
|
||||
throw new Error('Cannot use both GanacheSubrovider and RPCSubprovider');
|
||||
}
|
||||
const shouldThrowErrorsOnGanacheRPCResponse =
|
||||
_.isUndefined(config.shouldThrowErrorsOnGanacheRPCResponse) ||
|
||||
config.shouldThrowErrorsOnGanacheRPCResponse;
|
||||
provider.addProvider(
|
||||
new GanacheSubprovider({
|
||||
vmErrorsOnRPCResponse: shouldThrowErrorsOnGanacheRPCResponse,
|
||||
gasLimit: constants.GAS_LIMIT,
|
||||
logger,
|
||||
verbose: env.parseBoolean(EnvVars.VerboseGanache),
|
||||
port: 8545,
|
||||
network_id: 50,
|
||||
mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',
|
||||
}),
|
||||
} as any), // TODO remove any once types are merged in DefinitelyTyped
|
||||
);
|
||||
} else {
|
||||
provider.addProvider(new RPCSubprovider(config.rpcUrl || constants.RPC_URL));
|
||||
|
@@ -1,4 +1,49 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1538693146,
|
||||
"version": "1.0.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1538475601,
|
||||
"version": "1.0.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.6",
|
||||
|
@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.11 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.10 - _October 2, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.9 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.8 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.7 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.6 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -13,7 +33,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _August 14, 2018_
|
||||
## v1.0.4 - _August 13, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
@@ -29,12 +49,12 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _July 20, 2018_
|
||||
## v1.0.0 - _July 19, 2018_
|
||||
|
||||
* Add `TraceParams` interface for `debug_traceTransaction` parameters (#675)
|
||||
* Add `TransactionReceiptStatus` type (#812)
|
||||
* Add Artifact types: `CompilerSettings`, `CompilerOptions`, `OutputField` (#924)
|
||||
|
||||
## v0.0.2 - _June 1, 2018_
|
||||
## v0.0.2 - _May 31, 2018_
|
||||
|
||||
* Initial publish (#642)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethereum-types",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.11",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -9,6 +9,7 @@
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"clean": "shx rm -rf lib generated_docs",
|
||||
"lint": "tslint --project .",
|
||||
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
|
||||
@@ -28,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/ethereum-types/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"copyfiles": "^2.0.0",
|
||||
"make-promises-safe": "^1.1.0",
|
||||
"shx": "^0.2.2",
|
||||
@@ -36,7 +37,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/node": "*",
|
||||
"bignumber.js": "~4.1.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -181,6 +181,7 @@ export interface CallData extends CallTxDataBase {
|
||||
export interface FilterObject {
|
||||
fromBlock?: number | string;
|
||||
toBlock?: number | string;
|
||||
blockHash?: string;
|
||||
address?: string;
|
||||
topics?: LogTopic[];
|
||||
}
|
||||
@@ -238,7 +239,7 @@ export enum AbiType {
|
||||
Fallback = 'fallback',
|
||||
}
|
||||
|
||||
export type ContractEventArg = string | BigNumber | number | boolean;
|
||||
export type ContractEventArg = any;
|
||||
|
||||
export interface DecodedLogArgs {
|
||||
[argName: string]: ContractEventArg;
|
||||
@@ -324,9 +325,59 @@ export interface ContractNetworkData {
|
||||
constructorArgs: string;
|
||||
}
|
||||
|
||||
export type ParamDescription = string;
|
||||
|
||||
export interface StandardContractOutput {
|
||||
abi: ContractAbi;
|
||||
evm: EvmOutput;
|
||||
devdoc?: DevdocOutput;
|
||||
}
|
||||
|
||||
export interface StandardOutput {
|
||||
errors: SolcError[];
|
||||
sources: {
|
||||
[fileName: string]: {
|
||||
id: number;
|
||||
ast?: object;
|
||||
legacyAST?: object;
|
||||
};
|
||||
};
|
||||
contracts: {
|
||||
[fileName: string]: {
|
||||
[contractName: string]: StandardContractOutput;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type ErrorType =
|
||||
| 'JSONError'
|
||||
| 'IOError'
|
||||
| 'ParserError'
|
||||
| 'DocstringParsingError'
|
||||
| 'SyntaxError'
|
||||
| 'DeclarationError'
|
||||
| 'TypeError'
|
||||
| 'UnimplementedFeatureError'
|
||||
| 'InternalCompilerError'
|
||||
| 'Exception'
|
||||
| 'CompilerError'
|
||||
| 'FatalError'
|
||||
| 'Warning';
|
||||
export type ErrorSeverity = 'error' | 'warning';
|
||||
|
||||
export interface SolcError {
|
||||
sourceLocation?: SourceLocation;
|
||||
type: ErrorType;
|
||||
component: 'general' | 'ewasm';
|
||||
severity: ErrorSeverity;
|
||||
message: string;
|
||||
formattedMessage?: string;
|
||||
}
|
||||
|
||||
export interface SourceLocation {
|
||||
file: string;
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
export interface EvmOutput {
|
||||
@@ -339,6 +390,20 @@ export interface EvmBytecodeOutput {
|
||||
sourceMap: string;
|
||||
}
|
||||
|
||||
export interface DevdocOutput {
|
||||
title: string;
|
||||
author: string;
|
||||
methods: {
|
||||
[signature: string]: {
|
||||
details: string;
|
||||
params: {
|
||||
[name: string]: ParamDescription;
|
||||
};
|
||||
return?: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface ContractVersionData {
|
||||
compiler: CompilerOpts;
|
||||
sources: {
|
||||
@@ -432,4 +497,4 @@ export interface CompilerOptions {
|
||||
compilerSettings?: CompilerSettings;
|
||||
contracts?: string[] | '*';
|
||||
solcVersion?: string;
|
||||
}
|
||||
} // tslint:disable-line:max-file-line-count
|
||||
|
@@ -1,4 +1,58 @@
|
||||
[
|
||||
{
|
||||
"version": "1.0.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1538693146
|
||||
},
|
||||
{
|
||||
"timestamp": 1538157789,
|
||||
"version": "1.0.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537907159,
|
||||
"version": "1.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537875740,
|
||||
"version": "1.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1537541580,
|
||||
"version": "1.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Drastically reduce the bundle size by removing unused parts of included contract artifacts."
|
||||
}
|
||||
],
|
||||
"timestamp": 1537369748
|
||||
},
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.1",
|
||||
|
@@ -5,6 +5,30 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.7 - _October 4, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.6 - _September 28, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.5 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _September 25, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.3 - _September 21, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.2 - _September 19, 2018_
|
||||
|
||||
* Drastically reduce the bundle size by removing unused parts of included contract artifacts.
|
||||
|
||||
## v1.0.1 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
@@ -17,7 +41,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1-rc.3 - _August 14, 2018_
|
||||
## v1.0.1-rc.3 - _August 13, 2018_
|
||||
|
||||
* Updated to use latest orderFactory interface, fixed `feeRecipient` spelling error in public interface (#936)
|
||||
* Dependencies updated
|
||||
@@ -34,7 +58,7 @@ CHANGELOG
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0-rc.1 - _July 20, 2018_
|
||||
## v1.0.0-rc.1 - _July 19, 2018_
|
||||
|
||||
* Make fill-scenarios compatible with V2 of 0x protocol (#656)
|
||||
|
||||
|
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "@0xproject/fill-scenarios",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.7",
|
||||
"description": "0x order fill scenario generator",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "yarn pre_build && tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"pre_build": "run-s update_artifacts generate_contract_wrappers",
|
||||
"update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json lib/artifacts; done;",
|
||||
"update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-trimmed/$i.json lib/artifacts; done;",
|
||||
"generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
|
||||
"copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
|
||||
"clean": "shx rm -rf lib src/generated_contract_wrappers",
|
||||
@@ -26,8 +27,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/fill-scenarios/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/abi-gen": "^1.0.8",
|
||||
"@0xproject/tslint-config": "^1.0.7",
|
||||
"@0xproject/abi-gen": "^1.0.13",
|
||||
"@0xproject/tslint-config": "^1.0.8",
|
||||
"@types/lodash": "4.14.104",
|
||||
"copyfiles": "^2.0.0",
|
||||
"make-promises-safe": "^1.1.0",
|
||||
@@ -37,14 +38,14 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"ethereum-types": "^1.0.6",
|
||||
"ethers": "3.0.22",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/types": "^1.1.4",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
"@0xproject/web3-wrapper": "^3.0.3",
|
||||
"ethereum-types": "^1.0.11",
|
||||
"ethers": "4.0.0-beta.14",
|
||||
"lodash": "^4.17.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,30 +0,0 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1536142250,
|
||||
"version": "1.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.1-rc.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1535377027
|
||||
},
|
||||
{
|
||||
"version": "1.0.1-rc.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add initial forwarderHelperFactory",
|
||||
"pr": 997
|
||||
}
|
||||
],
|
||||
"timestamp": 1535133899
|
||||
}
|
||||
]
|
@@ -1,18 +0,0 @@
|
||||
<!--
|
||||
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
|
||||
Edit the package's CHANGELOG.json file only.
|
||||
-->
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.0.1 - _September 5, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1-rc.2 - _August 27, 2018_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1-rc.1 - _August 24, 2018_
|
||||
|
||||
* Add initial forwarderHelperFactory (#997)
|
@@ -1,5 +0,0 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
export const constants = {
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user