Compare commits
354 Commits
protocol@e
...
@0x/protoc
Author | SHA1 | Date | |
---|---|---|---|
|
e0d705703d | ||
|
01a6d933ca | ||
|
9b9f0b91d7 | ||
|
0d0fef841d | ||
|
17adfbea32 | ||
|
80594622b2 | ||
|
0dba5a5a3a | ||
|
4dae8de1b6 | ||
|
0046bb26d8 | ||
|
fe935f787c | ||
|
1b527ffcd8 | ||
|
9f5324d9c3 | ||
|
3647392a04 | ||
|
1d49662c58 | ||
|
6324b08b4d | ||
|
fe73b63aaa | ||
|
192d0b17d9 | ||
|
aa74d04083 | ||
|
d586f5727d | ||
|
98fc79a085 | ||
|
c12a10b96e | ||
|
d3d4a08f91 | ||
|
9ce090c8cd | ||
|
980d60deb8 | ||
|
d6d79e51e7 | ||
|
3ef5de93bb | ||
|
ab7dc33ca4 | ||
|
14dcee5bb6 | ||
|
9856e78609 | ||
|
2801b066b3 | ||
|
5bc8b13fc3 | ||
|
36dba8f5be | ||
|
ee2c069889 | ||
|
6ca14ed7b2 | ||
|
a5babb9a34 | ||
|
661cc4669d | ||
|
553ba5c868 | ||
|
d03d2f254d | ||
|
feb91a04b0 | ||
|
4d63f33aba | ||
|
b72b8b5ffd | ||
|
f7cb7a0f51 | ||
|
9fcb28f5d8 | ||
|
982173471c | ||
|
e77958425f | ||
|
6af4d71573 | ||
|
ee985240fb | ||
|
2aadbda527 | ||
|
297c73abcc | ||
|
4c9e1b21ec | ||
|
41685d1545 | ||
|
b9c25112ed | ||
|
f0738fc122 | ||
|
42baf504b7 | ||
|
56038d122f | ||
|
c4446b6c0e | ||
|
eaed2958c3 | ||
|
a045a3afb8 | ||
|
1cc59ab1ab | ||
|
2c6a714b71 | ||
|
d8c97d6720 | ||
|
d6bc702550 | ||
|
2838cb9420 | ||
|
b10cfc50d3 | ||
|
2e6317b01e | ||
|
50e99e6eac | ||
|
8f2f4554eb | ||
|
67d9678a3a | ||
|
f70341fb48 | ||
|
14cd24ea47 | ||
|
78328056d7 | ||
|
0045a60b0f | ||
|
e4e71c76e1 | ||
|
ca8127545f | ||
|
7b709089ce | ||
|
190f7e45f2 | ||
|
0dcc3a6fc3 | ||
|
c2e8cae293 | ||
|
83da7caab4 | ||
|
fd69a0c273 | ||
|
9b131199ad | ||
|
f5c486050b | ||
|
1f41fe6a20 | ||
|
7f4080e0a2 | ||
|
db76da58d7 | ||
|
cf8fc0ff8e | ||
|
2d16f83e37 | ||
|
4057bdab91 | ||
|
1cd10f0ac9 | ||
|
68f87b2432 | ||
|
69bafc3bcd | ||
|
2c44b06b7b | ||
|
0233f00b4e | ||
|
fedb53187d | ||
|
6774d2f588 | ||
|
cf740b74f5 | ||
|
177c00463a | ||
|
49b0e32129 | ||
|
938fc94756 | ||
|
1561d91c2b | ||
|
9a28e51f51 | ||
|
f55eaa867b | ||
|
6b2856424a | ||
|
da757c4700 | ||
|
75e6654884 | ||
|
87308e7693 | ||
|
d5eef93a76 | ||
|
a7f23a982e | ||
|
9eadc5fc28 | ||
|
92ad1a612e | ||
|
09413c0e12 | ||
|
23788b41d5 | ||
|
ccf999a495 | ||
|
aa1016ee5f | ||
|
423ef57344 | ||
|
c18149e82f | ||
|
d14aebf724 | ||
|
ba719a9631 | ||
|
d36034d958 | ||
|
7750c57620 | ||
|
4d027e11d1 | ||
|
470e9a4697 | ||
|
7c51412e2f | ||
|
b3d1f3cd10 | ||
|
389bb77439 | ||
|
4327885a00 | ||
|
0aef0afbbb | ||
|
fa4c3a4f5f | ||
|
1d7c527c5c | ||
|
cbe3135e4b | ||
|
955ad49711 | ||
|
8d6f6e76e0 | ||
|
9337115650 | ||
|
fa45a44fe4 | ||
|
c9c7ac8559 | ||
|
c881723578 | ||
|
c9c30d3a76 | ||
|
73dfdb5b69 | ||
|
e638268f94 | ||
|
0bfd765481 | ||
|
1f12893735 | ||
|
dd3d9337c4 | ||
|
904214f4a8 | ||
|
64c090c4b4 | ||
|
e24474f152 | ||
|
29fa408256 | ||
|
1b94cc68af | ||
|
f5b4bb3035 | ||
|
afd880f28c | ||
|
cd14cdd168 | ||
|
c8ff53a75f | ||
|
6d08add20b | ||
|
29f9c725e3 | ||
|
a83453f07f | ||
|
ae365ce92c | ||
|
77a592e891 | ||
|
9a1df67d6b | ||
|
4b91411faf | ||
|
622a542d57 | ||
|
cba53a9a50 | ||
|
e186f27f63 | ||
|
4cd767ecb8 | ||
|
f6e85aedf1 | ||
|
b3ee294ba5 | ||
|
1c242def93 | ||
|
f0fe6f2f69 | ||
|
f86d555e49 | ||
|
b0f2c40463 | ||
|
87be6fbb8a | ||
|
9141a9d2c8 | ||
|
7f75de347e | ||
|
329f7761c3 | ||
|
0d8e83cd75 | ||
|
e5d60b8077 | ||
|
ae2fe55efa | ||
|
6073607d3e | ||
|
389ebb5df8 | ||
|
fd9655e9d4 | ||
|
6480aaa189 | ||
|
38969bb0a8 | ||
|
1847ab93af | ||
|
c1177416f5 | ||
|
4fdd203211 | ||
|
4bc11776d7 | ||
|
eb12eac5f3 | ||
|
5f5b951998 | ||
|
8e90547604 | ||
|
fbea74d7ff | ||
|
dcea16bc13 | ||
|
d59a074bd7 | ||
|
39cc4f4dbf | ||
|
85bcf87af8 | ||
|
a0fe1c610f | ||
|
5d21af1a0a | ||
|
f6edbd210c | ||
|
e084807a8f | ||
|
1c7d512829 | ||
|
df0e0866e4 | ||
|
9e6efc3676 | ||
|
3aef29dace | ||
|
9a16e00577 | ||
|
84e4819e6e | ||
|
25dd6bc79a | ||
|
5d2cdb00c2 | ||
|
0f701f42d3 | ||
|
3e3e82d3f7 | ||
|
c57bf86273 | ||
|
f470d282ee | ||
|
b8a2526da5 | ||
|
97575bbde9 | ||
|
e5ed8b2c81 | ||
|
61fbae3ae2 | ||
|
5c2255c841 | ||
|
e036dee6c5 | ||
|
8583aab241 | ||
|
5d05b62821 | ||
|
0063e8178f | ||
|
ec6e5dd517 | ||
|
9d08fefa1c | ||
|
2fdca24d4e | ||
|
42ec0b144e | ||
|
3f6ce78b46 | ||
|
c1300c1068 | ||
|
9a641cfab6 | ||
|
60345d4465 | ||
|
11dfea47a6 | ||
|
55e9dd39a2 | ||
|
1993929bed | ||
|
e1d81de517 | ||
|
a6b3a21635 | ||
|
fd59cdc2db | ||
|
98e11b5189 | ||
|
3bebc7cd62 | ||
|
56dab6ae8c | ||
|
285f98e9e9 | ||
|
8ae9f59f20 | ||
|
4c341c5ca3 | ||
|
a3c912c2af | ||
|
5e72eb9af9 | ||
|
9b08b73c06 | ||
|
76c7eb7c3e | ||
|
9b2e5a3adb | ||
|
813d703d12 | ||
|
83005d0f3d | ||
|
d07ffd2688 | ||
|
4170f970d0 | ||
|
dcde12dd70 | ||
|
84a60ec982 | ||
|
9615570dc6 | ||
|
880a9c3da0 | ||
|
c44bd9d42d | ||
|
90b441330b | ||
|
e12ed1eddf | ||
|
ac94023ab3 | ||
|
281e6acca5 | ||
|
2f1b520409 | ||
|
21b4eb3d26 | ||
|
644f6c7d28 | ||
|
0647b9e4f8 | ||
|
82d42eeede | ||
|
6ef4d95043 | ||
|
6044140f86 | ||
|
4da1ef0f56 | ||
|
8c668a3918 | ||
|
f1ff1cde39 | ||
|
1668a24e31 | ||
|
4b7c376d96 | ||
|
bb4a9c656c | ||
|
6ab07b6304 | ||
|
8903f1ab01 | ||
|
415535612a | ||
|
5248a135c3 | ||
|
602290925c | ||
|
01813746e8 | ||
|
7d668d8801 | ||
|
797a00a33a | ||
|
4b3d98f43c | ||
|
9ff77c1cd5 | ||
|
18a8351671 | ||
|
9a994dfcd3 | ||
|
b7adc5a889 | ||
|
10b0d7f363 | ||
|
e2c905a15f | ||
|
8589ba728c | ||
|
43512fd07a | ||
|
c090608d99 | ||
|
89817428ed | ||
|
fce3664258 | ||
|
aa522fe49b | ||
|
c03653ebd7 | ||
|
ae08f77381 | ||
|
73a07e512d | ||
|
7cff09f40a | ||
|
a6d690f10a | ||
|
d7cff52e75 | ||
|
cf1f29a37d | ||
|
9af22110b4 | ||
|
2c187c7e85 | ||
|
d46756ae2e | ||
|
d9a16ed1f9 | ||
|
57a1120997 | ||
|
0945d4cef2 | ||
|
8f6f7ad453 | ||
|
bb4fad37fa | ||
|
d06daf2957 | ||
|
34314960ef | ||
|
832ba737ec | ||
|
6950fdbebb | ||
|
1849b1bb9a | ||
|
a883139220 | ||
|
bb2c26cb94 | ||
|
ba09a0b2bf | ||
|
b2d54f0238 | ||
|
4a3096495b | ||
|
23f6e9e53c | ||
|
d7dbc0576d | ||
|
15fb00e958 | ||
|
1d9295cc94 | ||
|
79f36cf6fb | ||
|
6ce4458a5d | ||
|
fad6e65c07 | ||
|
840c85373e | ||
|
0479bb5fe1 | ||
|
9ecc31ed54 | ||
|
eb29abd36c | ||
|
d202e01522 | ||
|
e838a6801b | ||
|
7439871aa0 | ||
|
317f2138c5 | ||
|
e5834f1901 | ||
|
5063446f93 | ||
|
0caf495a1a | ||
|
a20de0fc69 | ||
|
9aa0065d2d | ||
|
c24855e627 | ||
|
6bb72dd775 | ||
|
77d1ed257c | ||
|
5d265360c4 | ||
|
c9097f6e8b | ||
|
d3df985a42 | ||
|
7267420874 | ||
|
17e81432f1 | ||
|
57c767c3b1 | ||
|
dbb1c88ad9 | ||
|
254b850a8b | ||
|
e2242e5955 | ||
|
7a0255fee7 | ||
|
ec6522cfbf | ||
|
1bf96e91bb | ||
|
eb733cc58f | ||
|
d9fdcf813b | ||
|
88bd1c9cea | ||
|
9e759e82b4 | ||
|
da433854ac |
@@ -4,12 +4,13 @@ jobs:
|
||||
build:
|
||||
resource_class: xlarge
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
environment:
|
||||
NODE_OPTIONS: '--max-old-space-size=16384'
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- checkout
|
||||
- run: git submodule update --init --recursive
|
||||
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
|
||||
- run:
|
||||
name: install-yarn
|
||||
@@ -19,7 +20,6 @@ jobs:
|
||||
command: yarn --frozen-lockfile --ignore-engines install || yarn --frozen-lockfile --ignore-engines install
|
||||
- setup_remote_docker
|
||||
- run: yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci
|
||||
- run: yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts
|
||||
- save_cache:
|
||||
key: repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
test-exchange-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
test-integrations-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
test-contracts-staking-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
test-contracts-extra-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -71,19 +71,30 @@ jobs:
|
||||
test-contracts-rest-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-multisig -p @0x/contracts-utils -p @0x/contracts-exchange-libs -p @0x/contracts-erc20 -p @0x/contracts-erc721 -p @0x/contracts-erc1155 -p @0x/contracts-asset-proxy -p @0x/contracts-broker -p @0x/contracts-zero-ex -m --serial -c test:circleci
|
||||
test-foundry:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: ghcr.io/foundry-rs/foundry:latest
|
||||
working_directory: ~/repo/contracts/zero-ex
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
# - run: forge install
|
||||
- run: forge test
|
||||
test-publish:
|
||||
resource_class: large
|
||||
environment:
|
||||
NODE_OPTIONS: '--max-old-space-size=6442'
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
- image: 0xorg/verdaccio
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
@@ -97,7 +108,7 @@ jobs:
|
||||
path: ~/.npm/_logs
|
||||
test-doc-generation:
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -108,8 +119,10 @@ jobs:
|
||||
no_output_timeout: 1200
|
||||
test-rest:
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
environment:
|
||||
RUST_ROUTER: 'true'
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
@@ -117,7 +130,6 @@ jobs:
|
||||
- run: yarn wsrun -p @0x/contracts-test-utils -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/contract-artifacts -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/contract-wrappers-test -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/migrations -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/order-utils -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/asset-swapper -m --serial -c test:circleci
|
||||
- save_cache:
|
||||
@@ -136,7 +148,7 @@ jobs:
|
||||
resource_class: large
|
||||
working_directory: ~/repo
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
@@ -147,7 +159,7 @@ jobs:
|
||||
- run: yarn diff_md_docs:ci
|
||||
submit-coverage:
|
||||
docker:
|
||||
- image: node:12
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
@@ -181,6 +193,9 @@ workflows:
|
||||
# - test-contracts-extra-ganache:
|
||||
# requires:
|
||||
# - build
|
||||
- test-foundry:
|
||||
requires:
|
||||
- build
|
||||
- test-contracts-rest-ganache:
|
||||
requires:
|
||||
- build
|
||||
|
1
.github/autolabeler.yml
vendored
1
.github/autolabeler.yml
vendored
@@ -1,7 +1,6 @@
|
||||
python: ['python-packages']
|
||||
contracts: ['contracts']
|
||||
@0x/contract-addresses: ['packages/contract-addresses']
|
||||
@0x/migrations: ['packages/migrations']
|
||||
@0x/order-utils: ['packages/order-utils']
|
||||
@0x/contract-artifacts: ['packages/contract-artifacts']
|
||||
@0x/contract-wrappers: ['packages/contract-wrappers']
|
||||
|
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
node-version: 16
|
||||
- uses: actions/setup-python@v2
|
||||
- name: 'configure git'
|
||||
run: |
|
||||
|
12
.gitignore
vendored
12
.gitignore
vendored
@@ -75,8 +75,9 @@ generated_docs/
|
||||
|
||||
TODO.md
|
||||
|
||||
# VSCode file
|
||||
# IDE file
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# generated contract artifacts/
|
||||
contracts/broker/generated-artifacts/
|
||||
@@ -172,6 +173,15 @@ contracts/zero-ex/test/generated-wrappers/
|
||||
contracts/treasury/generated-wrappers/
|
||||
contracts/treasury/test/generated-wrappers/
|
||||
|
||||
# foundry artifacts
|
||||
contracts/zero-ex/foundry-artifacts/
|
||||
|
||||
# foundry cache
|
||||
contracts/zero-ex/foundry-cache/
|
||||
|
||||
# typechain wrappers
|
||||
contracts/zero-ex/typechain-wrappers/
|
||||
|
||||
# Doc README copy
|
||||
packages/*/docs/README.md
|
||||
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "contracts/zero-ex/contracts/deps/forge-std"]
|
||||
path = contracts/zero-ex/contracts/deps/forge-std
|
||||
url = https://github.com/foundry-rs/forge-std
|
18
CODEOWNERS
18
CODEOWNERS
@@ -1,18 +1,20 @@
|
||||
# See https://help.github.com/articles/about-codeowners/
|
||||
|
||||
# for more info about CODEOWNERS file
|
||||
|
||||
# It uses the same pattern rule for gitignore file
|
||||
|
||||
# https://git-scm.com/docs/gitignore#_pattern_format
|
||||
|
||||
# Website
|
||||
packages/asset-swapper/ @BMillman19 @fragosti @dave4506
|
||||
packages/instant/ @BMillman19 @fragosti @dave4506
|
||||
packages/asset-swapper/ @dekz @dextracker @kyu-c
|
||||
|
||||
# Dev tools & setup
|
||||
.circleci/ @dorothy-zbornak
|
||||
packages/contract-addresses/ @abandeali1
|
||||
packages/contract-artifacts/ @abandeali1
|
||||
packages/order-utils/ @dorothy-zbornak
|
||||
|
||||
.circleci/ @dekz
|
||||
packages/contract-addresses/ @dekz @dextracker @kyu-c
|
||||
packages/contract-artifacts/ @dekz
|
||||
packages/protocol-utils/ @dekz
|
||||
|
||||
# Protocol/smart contracts
|
||||
contracts/ @abandeali1 @hysz @dorothy-zbornak @mzhu25
|
||||
|
||||
contracts/ @dekz @dextracker
|
||||
|
@@ -38,7 +38,6 @@ These packages are all under development. See [/contracts/README.md](/contracts/
|
||||
| [`@0x/protocol-utils`](/packages/protocol-utils) | [](https://www.npmjs.com/package/@0x/protocol-utils) | A set of utilities for generating, parsing, signing and validating 0x orders |
|
||||
| [`@0x/contract-addresses`](/packages/contract-addresses) | [](https://www.npmjs.com/package/@0x/contract-addresses) | A tiny utility library for getting known deployed contract addresses for a particular network. |
|
||||
| [`@0x/contract-wrappers`](/packages/contract-wrappers) | [](https://www.npmjs.com/package/@0x/contract-wrappers) | JS/TS wrappers for interacting with the 0x smart contracts |
|
||||
| [`@0x/migrations`](/packages/migrations) | [](https://www.npmjs.com/package/@0x/migrations) | Migration tool for deploying 0x smart contracts on private testnets |
|
||||
| [`@0x/contract-artifacts`](/packages/contract-artifacts) | [](https://www.npmjs.com/package/@0x/contract-artifacts) | 0x smart contract compilation artifacts | |
|
||||
|
||||
## Usage
|
||||
|
@@ -1,4 +1,166 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1660073235,
|
||||
"version": "3.3.35",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1659750766,
|
||||
"version": "3.3.34",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "3.3.33",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "3.3.32",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "3.3.31",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "3.3.30",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "3.3.29",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "3.3.28",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "3.3.27",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "3.3.26",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "3.3.25",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "3.3.24",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "3.3.23",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "3.3.22",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "3.3.21",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631710679,
|
||||
"version": "3.3.20",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631120757,
|
||||
"version": "3.3.19",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "3.3.18",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "3.3.17",
|
||||
|
@@ -5,6 +5,78 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.3.35 - _August 9, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.34 - _August 6, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.33 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.32 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.31 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.30 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.29 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.28 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.27 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.26 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.25 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.24 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.23 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.22 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.21 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.20 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.19 - _September 8, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.18 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.17 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc20",
|
||||
"version": "3.3.17",
|
||||
"version": "3.3.35",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,18 +51,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/tokens",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.6.0",
|
||||
"@0x/contracts-gen": "^2.0.38",
|
||||
"@0x/contracts-test-utils": "^5.4.9",
|
||||
"@0x/contracts-utils": "^4.7.17",
|
||||
"@0x/dev-utils": "^4.2.7",
|
||||
"@0x/sol-compiler": "^4.7.3",
|
||||
"@0x/abi-gen": "^5.8.0",
|
||||
"@0x/contracts-gen": "^2.0.46",
|
||||
"@0x/contracts-test-utils": "^5.4.26",
|
||||
"@0x/contracts-utils": "^4.8.16",
|
||||
"@0x/dev-utils": "^4.2.14",
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/ts-doc-gen": "^0.0.28",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"@0x/types": "^3.3.3",
|
||||
"@0x/typescript-typings": "^5.2.0",
|
||||
"@0x/utils": "^6.4.3",
|
||||
"@0x/web3-wrapper": "^7.5.3",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "12.12.54",
|
||||
@@ -70,7 +70,7 @@
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-bignumber": "^3.0.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"ethereum-types": "^3.5.0",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"lodash": "^4.17.11",
|
||||
"make-promises-safe": "^1.1.0",
|
||||
"mocha": "^6.2.0",
|
||||
@@ -79,10 +79,10 @@
|
||||
"solhint": "^1.4.1",
|
||||
"tslint": "5.11.0",
|
||||
"typedoc": "~0.16.11",
|
||||
"typescript": "4.2.2"
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.4.0",
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"ethers": "~4.0.4"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,4 +1,157 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1660073235,
|
||||
"version": "5.4.26",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1659750766,
|
||||
"version": "5.4.25",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "5.4.24",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "5.4.23",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "5.4.22",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "5.4.21",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "5.4.20",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "5.4.19",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "5.4.18",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "5.4.17",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "5.4.16",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "5.4.15",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "5.4.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "5.4.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "5.4.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631710679,
|
||||
"version": "5.4.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "5.4.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "5.4.9",
|
||||
|
@@ -5,6 +5,74 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v5.4.26 - _August 9, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.25 - _August 6, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.24 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.23 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.22 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.21 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.20 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.19 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.18 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.17 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.16 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.15 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.14 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.13 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.12 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.11 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.10 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.9 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-test-utils",
|
||||
"version": "5.4.9",
|
||||
"version": "5.4.26",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -34,28 +34,28 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/test-utils",
|
||||
"devDependencies": {
|
||||
"@0x/sol-compiler": "^4.7.3",
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.11.0",
|
||||
"typescript": "4.2.2"
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/assert": "^3.0.27",
|
||||
"@0x/base-contract": "^6.4.0",
|
||||
"@0x/contract-addresses": "^6.6.1",
|
||||
"@0x/dev-utils": "^4.2.7",
|
||||
"@0x/json-schemas": "^6.1.3",
|
||||
"@0x/assert": "^3.0.34",
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"@0x/contract-addresses": "^6.19.1",
|
||||
"@0x/dev-utils": "^4.2.14",
|
||||
"@0x/json-schemas": "^6.4.4",
|
||||
"@0x/order-utils": "^10.4.28",
|
||||
"@0x/sol-coverage": "^4.0.37",
|
||||
"@0x/sol-profiler": "^4.1.27",
|
||||
"@0x/sol-trace": "^3.0.37",
|
||||
"@0x/subproviders": "^6.5.3",
|
||||
"@0x/types": "^3.3.3",
|
||||
"@0x/typescript-typings": "^5.2.0",
|
||||
"@0x/utils": "^6.4.3",
|
||||
"@0x/web3-wrapper": "^7.5.3",
|
||||
"@0x/sol-coverage": "^4.0.45",
|
||||
"@0x/sol-profiler": "^4.1.35",
|
||||
"@0x/sol-trace": "^3.0.45",
|
||||
"@0x/subproviders": "^6.6.5",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"@types/bn.js": "^4.11.0",
|
||||
"@types/js-combinatorics": "^0.5.29",
|
||||
"@types/lodash": "4.14.104",
|
||||
@@ -67,7 +67,7 @@
|
||||
"chai-bignumber": "^3.0.0",
|
||||
"decimal.js": "^10.2.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"ethereum-types": "^3.5.0",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"ethereumjs-util": "^7.0.10",
|
||||
"ethers": "~4.0.4",
|
||||
"js-combinatorics": "^0.5.3",
|
||||
|
@@ -1,4 +1,193 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1660073235,
|
||||
"version": "1.4.18",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1659750766,
|
||||
"version": "1.4.17",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "1.4.16",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "1.4.15",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "1.4.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "1.4.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "1.4.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "1.4.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "1.4.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "1.4.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "1.4.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "1.4.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "1.4.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "1.4.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "1.4.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634147078,
|
||||
"version": "1.4.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1633374058,
|
||||
"version": "1.4.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1632957537,
|
||||
"version": "1.4.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.4.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Support cast vote by signature in Treasury"
|
||||
}
|
||||
],
|
||||
"timestamp": 1631710679
|
||||
},
|
||||
{
|
||||
"timestamp": 1631120757,
|
||||
"version": "1.3.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "1.3.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "1.3.3",
|
||||
|
@@ -5,6 +5,90 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.4.18 - _August 9, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.17 - _August 6, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.16 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.15 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.14 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.13 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.12 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.11 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.10 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.9 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.8 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.7 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.6 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.5 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.4 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.3 - _October 13, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.2 - _October 4, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.1 - _September 29, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.0 - _September 15, 2021_
|
||||
|
||||
* Support cast vote by signature in Treasury
|
||||
|
||||
## v1.3.5 - _September 8, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.4 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.3 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
60
contracts/treasury/contracts/external/ISablier.sol
vendored
Normal file
60
contracts/treasury/contracts/external/ISablier.sol
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
pragma solidity ^0.6.12;
|
||||
|
||||
/**
|
||||
* @title ISablier
|
||||
* @author Sablier
|
||||
*/
|
||||
interface ISablier {
|
||||
/**
|
||||
* @notice Emits when a stream is successfully created.
|
||||
*/
|
||||
event CreateStream(
|
||||
uint256 indexed streamId,
|
||||
address indexed sender,
|
||||
address indexed recipient,
|
||||
uint256 deposit,
|
||||
address tokenAddress,
|
||||
uint256 startTime,
|
||||
uint256 stopTime
|
||||
);
|
||||
|
||||
/**
|
||||
* @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream.
|
||||
*/
|
||||
event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount);
|
||||
|
||||
/**
|
||||
* @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis.
|
||||
*/
|
||||
event CancelStream(
|
||||
uint256 indexed streamId,
|
||||
address indexed sender,
|
||||
address indexed recipient,
|
||||
uint256 senderBalance,
|
||||
uint256 recipientBalance
|
||||
);
|
||||
|
||||
function balanceOf(uint256 streamId, address who) external view returns (uint256 balance);
|
||||
|
||||
function getStream(uint256 streamId)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
address sender,
|
||||
address recipient,
|
||||
uint256 deposit,
|
||||
address token,
|
||||
uint256 startTime,
|
||||
uint256 stopTime,
|
||||
uint256 remainingBalance,
|
||||
uint256 ratePerSecond
|
||||
);
|
||||
|
||||
function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
|
||||
external
|
||||
returns (uint256 streamId);
|
||||
|
||||
function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool);
|
||||
|
||||
function cancelStream(uint256 streamId) external returns (bool);
|
||||
}
|
@@ -136,8 +136,9 @@ interface IZrxTreasury {
|
||||
returns (uint256 proposalId);
|
||||
|
||||
/// @dev Casts a vote for the given proposal. Only callable
|
||||
/// during the voting period for that proposal. See
|
||||
/// `getVotingPower` for how voting power is computed.
|
||||
/// during the voting period for that proposal.
|
||||
/// One address can only vote once.
|
||||
/// See `getVotingPower` for how voting power is computed.
|
||||
/// @param proposalId The ID of the proposal to vote on.
|
||||
/// @param support Whether to support the proposal or not.
|
||||
/// @param operatedPoolIds The pools operated by `msg.sender`. The
|
||||
@@ -150,6 +151,28 @@ interface IZrxTreasury {
|
||||
)
|
||||
external;
|
||||
|
||||
/// @dev Casts a vote for the given proposal, by signature.
|
||||
/// Only callable during the voting period for that proposal.
|
||||
/// One address/voter can only vote once.
|
||||
/// See `getVotingPower` for how voting power is computed.
|
||||
/// @param proposalId The ID of the proposal to vote on.
|
||||
/// @param support Whether to support the proposal or not.
|
||||
/// @param operatedPoolIds The pools operated by the signer. The
|
||||
/// ZRX currently delegated to those pools will be accounted
|
||||
/// for in the voting power.
|
||||
/// @param v the v field of the signature
|
||||
/// @param r the r field of the signature
|
||||
/// @param s the s field of the signature
|
||||
function castVoteBySignature(
|
||||
uint256 proposalId,
|
||||
bool support,
|
||||
bytes32[] memory operatedPoolIds,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
)
|
||||
external;
|
||||
|
||||
/// @dev Executes a proposal that has passed and is
|
||||
/// currently executable.
|
||||
/// @param proposalId The ID of the proposal to execute.
|
||||
|
@@ -34,11 +34,25 @@ contract ZrxTreasury is
|
||||
using LibRichErrorsV06 for bytes;
|
||||
using LibBytesV06 for bytes;
|
||||
|
||||
/// Contract name
|
||||
string private constant CONTRACT_NAME = "Zrx Treasury";
|
||||
|
||||
/// Contract version
|
||||
string private constant CONTRACT_VERSION = "1.0.0";
|
||||
|
||||
/// The EIP-712 typehash for the contract's domain
|
||||
bytes32 private constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
|
||||
|
||||
/// The EIP-712 typehash for the vote struct
|
||||
bytes32 private constant VOTE_TYPEHASH = keccak256("TreasuryVote(uint256 proposalId,bool support,bytes32[] operatedPoolIds)");
|
||||
|
||||
// Immutables
|
||||
IStaking public immutable override stakingProxy;
|
||||
DefaultPoolOperator public immutable override defaultPoolOperator;
|
||||
bytes32 public immutable override defaultPoolId;
|
||||
uint256 public immutable override votingPeriod;
|
||||
bytes32 immutable domainSeparator;
|
||||
|
||||
uint256 public override proposalThreshold;
|
||||
uint256 public override quorumThreshold;
|
||||
|
||||
@@ -67,6 +81,15 @@ contract ZrxTreasury is
|
||||
defaultPoolId = params.defaultPoolId;
|
||||
IStaking.Pool memory defaultPool = stakingProxy_.getStakingPool(params.defaultPoolId);
|
||||
defaultPoolOperator = DefaultPoolOperator(defaultPool.operator);
|
||||
domainSeparator = keccak256(
|
||||
abi.encode(
|
||||
DOMAIN_TYPEHASH,
|
||||
keccak256(bytes(CONTRACT_NAME)),
|
||||
_getChainId(),
|
||||
keccak256(bytes(CONTRACT_VERSION)),
|
||||
address(this)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// solhint-disable
|
||||
@@ -105,7 +128,7 @@ contract ZrxTreasury is
|
||||
/// be executed if it passes. Must be at least two epochs
|
||||
/// from the current epoch.
|
||||
/// @param description A text description for the proposal.
|
||||
/// @param operatedPoolIds The pools operated by `msg.sender`. The
|
||||
/// @param operatedPoolIds The pools operated by the signer. The
|
||||
/// ZRX currently delegated to those pools will be accounted
|
||||
/// for in the voting power.
|
||||
/// @return proposalId The ID of the newly created proposal.
|
||||
@@ -150,8 +173,9 @@ contract ZrxTreasury is
|
||||
}
|
||||
|
||||
/// @dev Casts a vote for the given proposal. Only callable
|
||||
/// during the voting period for that proposal. See
|
||||
/// `getVotingPower` for how voting power is computed.
|
||||
/// during the voting period for that proposal.
|
||||
/// One address can only vote once.
|
||||
/// See `getVotingPower` for how voting power is computed.
|
||||
/// @param proposalId The ID of the proposal to vote on.
|
||||
/// @param support Whether to support the proposal or not.
|
||||
/// @param operatedPoolIds The pools operated by `msg.sender`. The
|
||||
@@ -165,43 +189,39 @@ contract ZrxTreasury is
|
||||
public
|
||||
override
|
||||
{
|
||||
if (proposalId >= proposalCount()) {
|
||||
revert("castVote/INVALID_PROPOSAL_ID");
|
||||
}
|
||||
if (hasVoted[proposalId][msg.sender]) {
|
||||
revert("castVote/ALREADY_VOTED");
|
||||
}
|
||||
return _castVote(msg.sender, proposalId, support, operatedPoolIds);
|
||||
}
|
||||
|
||||
Proposal memory proposal = proposals[proposalId];
|
||||
if (
|
||||
proposal.voteEpoch != stakingProxy.currentEpoch() ||
|
||||
_hasVoteEnded(proposal.voteEpoch)
|
||||
) {
|
||||
revert("castVote/VOTING_IS_CLOSED");
|
||||
}
|
||||
|
||||
uint256 votingPower = getVotingPower(msg.sender, operatedPoolIds);
|
||||
if (votingPower == 0) {
|
||||
revert("castVote/NO_VOTING_POWER");
|
||||
}
|
||||
|
||||
if (support) {
|
||||
proposals[proposalId].votesFor = proposals[proposalId].votesFor
|
||||
.safeAdd(votingPower);
|
||||
hasVoted[proposalId][msg.sender] = true;
|
||||
} else {
|
||||
proposals[proposalId].votesAgainst = proposals[proposalId].votesAgainst
|
||||
.safeAdd(votingPower);
|
||||
hasVoted[proposalId][msg.sender] = true;
|
||||
}
|
||||
|
||||
emit VoteCast(
|
||||
msg.sender,
|
||||
operatedPoolIds,
|
||||
proposalId,
|
||||
support,
|
||||
votingPower
|
||||
/// @dev Casts a vote for the given proposal, by signature.
|
||||
/// Only callable during the voting period for that proposal.
|
||||
/// One address/voter can only vote once.
|
||||
/// See `getVotingPower` for how voting power is computed.
|
||||
/// @param proposalId The ID of the proposal to vote on.
|
||||
/// @param support Whether to support the proposal or not.
|
||||
/// @param operatedPoolIds The pools operated by voter. The
|
||||
/// ZRX currently delegated to those pools will be accounted
|
||||
/// for in the voting power.
|
||||
/// @param v the v field of the signature
|
||||
/// @param r the r field of the signature
|
||||
/// @param s the s field of the signature
|
||||
function castVoteBySignature(
|
||||
uint256 proposalId,
|
||||
bool support,
|
||||
bytes32[] memory operatedPoolIds,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
)
|
||||
public
|
||||
override
|
||||
{
|
||||
bytes32 structHash = keccak256(
|
||||
abi.encode(VOTE_TYPEHASH, proposalId, support, keccak256(abi.encodePacked(operatedPoolIds)))
|
||||
);
|
||||
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
|
||||
address signatory = ecrecover(digest, v, r, s);
|
||||
|
||||
return _castVote(signatory, proposalId, support, operatedPoolIds);
|
||||
}
|
||||
|
||||
/// @dev Executes a proposal that has passed and is
|
||||
@@ -373,4 +393,60 @@ contract ZrxTreasury is
|
||||
.safeAdd(votingPeriod);
|
||||
return block.timestamp > voteEndTime;
|
||||
}
|
||||
|
||||
/// @dev Casts a vote for the given proposal. Only callable
|
||||
/// during the voting period for that proposal. See
|
||||
/// `getVotingPower` for how voting power is computed.
|
||||
function _castVote(
|
||||
address voter,
|
||||
uint256 proposalId,
|
||||
bool support,
|
||||
bytes32[] memory operatedPoolIds
|
||||
)
|
||||
private
|
||||
{
|
||||
if (proposalId >= proposalCount()) {
|
||||
revert("_castVote/INVALID_PROPOSAL_ID");
|
||||
}
|
||||
if (hasVoted[proposalId][voter]) {
|
||||
revert("_castVote/ALREADY_VOTED");
|
||||
}
|
||||
|
||||
Proposal memory proposal = proposals[proposalId];
|
||||
if (
|
||||
proposal.voteEpoch != stakingProxy.currentEpoch() ||
|
||||
_hasVoteEnded(proposal.voteEpoch)
|
||||
) {
|
||||
revert("_castVote/VOTING_IS_CLOSED");
|
||||
}
|
||||
|
||||
uint256 votingPower = getVotingPower(voter, operatedPoolIds);
|
||||
if (votingPower == 0) {
|
||||
revert("_castVote/NO_VOTING_POWER");
|
||||
}
|
||||
|
||||
if (support) {
|
||||
proposals[proposalId].votesFor = proposals[proposalId].votesFor
|
||||
.safeAdd(votingPower);
|
||||
} else {
|
||||
proposals[proposalId].votesAgainst = proposals[proposalId].votesAgainst
|
||||
.safeAdd(votingPower);
|
||||
}
|
||||
hasVoted[proposalId][voter] = true;
|
||||
|
||||
emit VoteCast(
|
||||
voter,
|
||||
operatedPoolIds,
|
||||
proposalId,
|
||||
support,
|
||||
votingPower
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Gets the Ethereum chain id
|
||||
function _getChainId() private pure returns (uint256) {
|
||||
uint256 chainId;
|
||||
assembly { chainId := chainid() }
|
||||
return chainId;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-treasury",
|
||||
"version": "1.3.3",
|
||||
"version": "1.4.18",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -32,9 +32,9 @@
|
||||
"publish:private": "yarn build && gitpkg publish"
|
||||
},
|
||||
"config": {
|
||||
"publicInterfaceContracts": "ZrxTreasury,DefaultPoolOperator",
|
||||
"publicInterfaceContracts": "ZrxTreasury,DefaultPoolOperator,ISablier",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||
"abis": "./test/generated-artifacts/@(DefaultPoolOperator|IStaking|IZrxTreasury|ZrxTreasury).json"
|
||||
"abis": "./test/generated-artifacts/@(DefaultPoolOperator|ISablier|IStaking|IZrxTreasury|ZrxTreasury).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -46,14 +46,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/treasury",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.6.0",
|
||||
"@0x/contract-addresses": "^6.6.1",
|
||||
"@0x/abi-gen": "^5.8.0",
|
||||
"@0x/contract-addresses": "^6.19.1",
|
||||
"@0x/contracts-asset-proxy": "^3.7.19",
|
||||
"@0x/contracts-erc20": "^3.3.17",
|
||||
"@0x/contracts-gen": "^2.0.38",
|
||||
"@0x/contracts-erc20": "^3.3.35",
|
||||
"@0x/contracts-gen": "^2.0.46",
|
||||
"@0x/contracts-staking": "^2.0.45",
|
||||
"@0x/contracts-test-utils": "^5.4.9",
|
||||
"@0x/sol-compiler": "^4.7.3",
|
||||
"@0x/contracts-test-utils": "^5.4.26",
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/ts-doc-gen": "^0.0.28",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"@types/isomorphic-fetch": "^0.0.35",
|
||||
@@ -69,17 +69,17 @@
|
||||
"solhint": "^1.4.1",
|
||||
"tslint": "5.11.0",
|
||||
"typedoc": "~0.16.11",
|
||||
"typescript": "4.2.2"
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.4.0",
|
||||
"@0x/protocol-utils": "^1.8.3",
|
||||
"@0x/subproviders": "^6.5.3",
|
||||
"@0x/types": "^3.3.3",
|
||||
"@0x/typescript-typings": "^5.2.0",
|
||||
"@0x/utils": "^6.4.3",
|
||||
"@0x/web3-wrapper": "^7.5.3",
|
||||
"ethereum-types": "^3.5.0",
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"@0x/protocol-utils": "^11.16.2",
|
||||
"@0x/subproviders": "^6.6.5",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"ethereumjs-util": "^7.0.10"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -6,8 +6,10 @@
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as DefaultPoolOperator from '../generated-artifacts/DefaultPoolOperator.json';
|
||||
import * as ISablier from '../generated-artifacts/ISablier.json';
|
||||
import * as ZrxTreasury from '../generated-artifacts/ZrxTreasury.json';
|
||||
export const artifacts = {
|
||||
ZrxTreasury: ZrxTreasury as ContractArtifact,
|
||||
DefaultPoolOperator: DefaultPoolOperator as ContractArtifact,
|
||||
ISablier: ISablier as ContractArtifact,
|
||||
};
|
||||
|
@@ -3,6 +3,8 @@ import { ERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { Web3ProviderEngine } from '@0x/subproviders';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { ISablierContract } from './wrappers';
|
||||
|
||||
interface ProposedAction {
|
||||
target: string;
|
||||
data: string;
|
||||
@@ -17,8 +19,14 @@ interface Proposal {
|
||||
|
||||
const { zrxToken } = getContractAddressesForChainOrThrow(1);
|
||||
const zrx = new ERC20TokenContract(zrxToken, new Web3ProviderEngine());
|
||||
const maticToken = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0';
|
||||
const matic = new ERC20TokenContract(maticToken, new Web3ProviderEngine());
|
||||
const maticToken = new ERC20TokenContract('0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', new Web3ProviderEngine());
|
||||
const sablier = new ISablierContract('0xcd18eaa163733da39c232722cbc4e8940b1d8888', new Web3ProviderEngine());
|
||||
|
||||
const ONE_YEAR_IN_SECONDS = new BigNumber('31536000');
|
||||
const PROPOSAL_2_ZRX_AMOUNT = new BigNumber('485392999999999970448000');
|
||||
const PROPOSAL_2_MATIC_AMOUNT = new BigNumber('378035999999999992944000');
|
||||
const PROPOSAL_2_STREAM_START_TIME = new BigNumber('1635188400');
|
||||
const PROPOSAL_2_RECIPIENT = '0x976378445d31d81b15576811450a7b9797206807';
|
||||
|
||||
export const proposals: Proposal[] = [
|
||||
{
|
||||
@@ -44,8 +52,8 @@ export const proposals: Proposal[] = [
|
||||
value: new BigNumber(0),
|
||||
},
|
||||
{
|
||||
target: maticToken,
|
||||
data: matic
|
||||
target: maticToken.address,
|
||||
data: maticToken
|
||||
.transfer('0xab66cc8fd10457ebc9d13b9760c835f0a4cbc487', new BigNumber('420000e18'))
|
||||
.getABIEncodedTransactionData(),
|
||||
value: new BigNumber(0),
|
||||
@@ -54,4 +62,46 @@ export const proposals: Proposal[] = [
|
||||
description:
|
||||
'# Z-2 0x/Polygon Grant Budget for 0xEVE\n\n## Summary\n\nWe propose to transfer 10% of the new Treasury allocation from the recently announced 0x/Polygon initiative to the 0x Ecosystem Value Experiment (0xEVE). The purpose is not so much to increase the budget as it is to enable access to the MATIC that was allocated to the Treasury after 0xEVE was established and to expand the original goals to include use cases on the Polygon Network. A snapshot vote was held to gauge community sentiment with 100% in favor https://snapshot.org/#/0xgov.eth/proposal/QmdcZAAcmNgM3R6CVY586G4sSoPwm6T3CS39DCQ4gPDPB4.\n\n## Background\n\nA proposal to establish the 0x Ecosystem Value Experiment (0xEVE) was passed in early June with a budget of 400K ZRX, which was then transferred to the 0xEVE multisig to fund operations. Shortly afterwards, 0xLabs and 0xPolygon allocated 3.3M ZRX and 4.2M MATIC to the 0xDAO Treasury with the shared goal of bringing 1M new users to the Polygon Network via 0x-powered applications.<br/><br/>\nSince that time, 0xEVE has established a grant program and published a framework for projects seeking support from the 0xDAO. However, because 0xEVE has no access to these new funds, it will be extremely difficult given the current market conditions (and the commensurate devaluation of our operating budget in USD terms) for us to incorporate this new goal into the grant program in any meaningful way, particularly because we are not able to spend any of the MATIC in the Treasury.\n\n## Request for Approval\n\nIn keeping with the original structure of the budget where ~10% of the Treasury was allocated to 0xEVE to fund opportunities such as grants, we propose that 10% of the new funding (ZRX and MATIC) be allocated to 0xEVE to fund activities associated with this new initiative. A separate multisig has been set up to manage and track these expenditures.<br/><br/>\nCompensation will remain as authorized in the original budget, and the new funding will be allocated 100% to grants and other operational activities specific to Polygon. In accordance with the grant program framework, this will enable 0xEVE to fast track grants under $50k using its own budget, while larger grants will require an onchain community vote and will be awarded from Treasury funds.<br/><br/>\nAdditionally, as 0x protocol deploys to additional chains, for any future allocations from similar joint initiatives, we recommend that they be structured the same way (90/10 split between the Treasury and 0xEVE) so that 0xEVE can actively participate in evaluating, distributing, and managing grants and other associated efforts designed to accelerate adoption and ecosystem value capture on those networks.<br/><br/>\nAs stipulated in Z-1, 0xEVE is a limited-duration experiment (26 weeks) and any funds not used will be returned to the Treasury when the experiment concludes.\n\n## Action Required\n\nTransfer 330,813 ZRX and 420,000 MATIC to 0xEVE gnosis safe multisig 0xAB66CC8FD10457ebC9D13B9760C835F0a4CbC487',
|
||||
},
|
||||
{
|
||||
actions: [
|
||||
{
|
||||
target: zrxToken,
|
||||
data: zrx.approve(sablier.address, PROPOSAL_2_ZRX_AMOUNT).getABIEncodedTransactionData(),
|
||||
value: new BigNumber(0),
|
||||
},
|
||||
{
|
||||
target: maticToken.address,
|
||||
data: maticToken.approve(sablier.address, PROPOSAL_2_MATIC_AMOUNT).getABIEncodedTransactionData(),
|
||||
value: new BigNumber(0),
|
||||
},
|
||||
{
|
||||
target: sablier.address,
|
||||
data: sablier
|
||||
.createStream(
|
||||
PROPOSAL_2_RECIPIENT,
|
||||
PROPOSAL_2_ZRX_AMOUNT,
|
||||
zrxToken,
|
||||
PROPOSAL_2_STREAM_START_TIME,
|
||||
PROPOSAL_2_STREAM_START_TIME.plus(ONE_YEAR_IN_SECONDS),
|
||||
)
|
||||
.getABIEncodedTransactionData(),
|
||||
value: new BigNumber(0),
|
||||
},
|
||||
{
|
||||
target: sablier.address,
|
||||
data: sablier
|
||||
.createStream(
|
||||
PROPOSAL_2_RECIPIENT,
|
||||
PROPOSAL_2_MATIC_AMOUNT,
|
||||
maticToken.address,
|
||||
PROPOSAL_2_STREAM_START_TIME,
|
||||
PROPOSAL_2_STREAM_START_TIME.plus(ONE_YEAR_IN_SECONDS),
|
||||
)
|
||||
.getABIEncodedTransactionData(),
|
||||
value: new BigNumber(0),
|
||||
},
|
||||
],
|
||||
description:
|
||||
'# Z-3 Trader.xyz Grant\n\n## Summary\n\nThis proposal seeks authorization of a $950k grant from the treasury to trader.xyz. The community has discussed the merits of the proposal in the governance forum and signaled strong support for moving forward in a snapshot poll:\n\n1. https://gov.0x.org/t/grant-proposal-trader-xyz/1005/\n2. https://snapshot.org/#/0xgov.eth/proposal/Qmcf2C3KmQ1W1XBGownLWsA8yX9hpzY6peLUGKNJnPzN9y\n\n## Grant Details\n\n### What category best describes your grant request?\n\n1. 0x orderbook\n2. 0x protocol feature development\n\n### Grant amount requested\n\n**Amount**: $950k split 50/50 between $ZRX and $MATIC (note: an upfront payment of $50k in $ZRX and $MATIC is being made from the 0xEVE grant budget)\n\n**Price reference**:\n1. [https://www.tradingview.com/symbols/ZRXUSD/technicals/](https://www.tradingview.com/symbols/ZRXUSD/technicals/) ($ZRX 30-day EMA as of 10/4/2021 = 0.97859)\n2. [https://www.tradingview.com/symbols/MATICUSD/technicals/](https://www.tradingview.com/symbols/MATICUSD/technicals/) ($MATIC 30-day EMA as of 10/4/2021 = 1.2564959)\n\n**Payment details**: $950k streamed from Sablier over 365 days (485,393 ZRX + 378,036 MATIC)\n\n**Receiving address**: 0x976378445D31D81b15576811450A7b9797206807 (Gnosis Safe)\n\n### Team background\n\nCore team is comprised of two former 0x core team members (Patryk Adas - former Matcha lead designer, and John Johnson - former Matcha lead engineer)\n\n### Project background\n\nTrader.xyz is a dapp that provides a user-focused trading experience with the goal of becoming the flagship, 0x-powered application for discovering and trading NFTs\n\n### Description of work to be funded\n\nSee detailed explanation at https://gov.0x.org/t/grant-proposal-trader-xyz/1005\n\n### Budget breakdown\n\nSee detailed explanation at https://gov.0x.org/t/grant-proposal-trader-xyz/1005\n\n### Benefit to 0x ecosystem\n\n1. Become the gold standard for exchanging NFTs with 0x protocol\n2. Enable 0xDAO to build organic development capabilities\n3. Improve protocol documentation and developer resources\n4. Add OSS API protocol features\n\n### Risk/Reward factors\n\nRisks include competition, mindshare, flywheel of liquidity, etc. We believe our product and team have the potential to mitigate these risks and bring to market several features and capabilities that will be market-leading.\n\n### Additional info\n\nOur team has a track record of delivering high quality projects, and in order for us to continue our work, we need capital and support. We prefer not to go the venture capital route and instead work directly with the 0xDAO for the best synergies and to align value with 0x. We proved out an initial brand, design, and engineering concept via OTC orders, and it is already the highest quality OTC swap on the market. We would like to work with 0xDAO directly to make sure 0x has a foothold in the NFT market as it continues to evolve and develop. We want to do what Matcha did for DEX ERC20 trading.\n\n## Action Required\n\nStream 485,393 ZRX and 378,036 MATIC to Gnosis Safe 0x976378445D31D81b15576811450A7b9797206807 over 365 days',
|
||||
},
|
||||
];
|
||||
|
@@ -4,4 +4,5 @@
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
export * from '../generated-wrappers/default_pool_operator';
|
||||
export * from '../generated-wrappers/i_sablier';
|
||||
export * from '../generated-wrappers/zrx_treasury';
|
||||
|
@@ -6,10 +6,12 @@
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as DefaultPoolOperator from '../test/generated-artifacts/DefaultPoolOperator.json';
|
||||
import * as ISablier from '../test/generated-artifacts/ISablier.json';
|
||||
import * as IStaking from '../test/generated-artifacts/IStaking.json';
|
||||
import * as IZrxTreasury from '../test/generated-artifacts/IZrxTreasury.json';
|
||||
import * as ZrxTreasury from '../test/generated-artifacts/ZrxTreasury.json';
|
||||
export const artifacts = {
|
||||
ISablier: ISablier as ContractArtifact,
|
||||
DefaultPoolOperator: DefaultPoolOperator as ContractArtifact,
|
||||
IStaking: IStaking as ContractArtifact,
|
||||
IZrxTreasury: IZrxTreasury as ContractArtifact,
|
||||
|
@@ -7,7 +7,7 @@ import * as _ from 'lodash';
|
||||
import { proposals } from '../src/proposals';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { ZrxTreasuryContract, ZrxTreasuryEvents } from './wrappers';
|
||||
import { ISablierEvents, ZrxTreasuryContract, ZrxTreasuryEvents } from './wrappers';
|
||||
|
||||
const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/mzhu25/zeroex-staking';
|
||||
const STAKING_PROXY_ADDRESS = '0xa26e80e7dea86279c6d778d702cc413e6cffa777';
|
||||
@@ -15,9 +15,11 @@ const TREASURY_ADDRESS = '0x0bb1810061c2f5b2088054ee184e6c79e1591101';
|
||||
const PROPOSER = process.env.PROPOSER || constants.NULL_ADDRESS;
|
||||
const VOTER = '0xba4f44e774158408e2dc6c5cb65bc995f0a89180';
|
||||
const VOTER_OPERATED_POOLS = ['0x0000000000000000000000000000000000000000000000000000000000000017'];
|
||||
const VOTER_2 = '0x9a4eb1101c0c053505bd71d2ffa27ed902dead85';
|
||||
const VOTER_2_OPERATED_POOLS = ['0x0000000000000000000000000000000000000000000000000000000000000029'];
|
||||
blockchainTests.configure({
|
||||
fork: {
|
||||
unlockedAccounts: [PROPOSER, VOTER],
|
||||
unlockedAccounts: [PROPOSER, VOTER, VOTER_2],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -219,4 +221,80 @@ blockchainTests.fork.skip('Treasury proposal mainnet fork tests', env => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('Proposal 2', () => {
|
||||
it('works', async () => {
|
||||
const proposal = proposals[2];
|
||||
let executionEpoch: BigNumber;
|
||||
if (proposal.executionEpoch) {
|
||||
executionEpoch = proposal.executionEpoch;
|
||||
} else {
|
||||
const currentEpoch = await staking.currentEpoch().callAsync();
|
||||
executionEpoch = currentEpoch.plus(2);
|
||||
}
|
||||
const pools = await querySubgraphAsync(PROPOSER);
|
||||
const proposeTx = treasury.propose(proposal.actions, executionEpoch, proposal.description, pools);
|
||||
|
||||
const calldata = proposeTx.getABIEncodedTransactionData();
|
||||
logUtils.log('ZrxTreasury.propose calldata:');
|
||||
logUtils.log(calldata);
|
||||
|
||||
const proposalId = await proposeTx.callAsync({ from: PROPOSER });
|
||||
const receipt = await proposeTx.awaitTransactionSuccessAsync({ from: PROPOSER });
|
||||
verifyEventsFromLogs(
|
||||
receipt.logs,
|
||||
[
|
||||
{
|
||||
...proposal,
|
||||
proposalId,
|
||||
executionEpoch,
|
||||
proposer: PROPOSER,
|
||||
operatedPoolIds: pools,
|
||||
},
|
||||
],
|
||||
ZrxTreasuryEvents.ProposalCreated,
|
||||
);
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
await treasury
|
||||
.castVote(proposalId, true, VOTER_OPERATED_POOLS)
|
||||
.awaitTransactionSuccessAsync({ from: VOTER });
|
||||
await treasury
|
||||
.castVote(proposalId, true, VOTER_2_OPERATED_POOLS)
|
||||
.awaitTransactionSuccessAsync({ from: VOTER_2 });
|
||||
await env.web3Wrapper.increaseTimeAsync(votingPeriod.plus(1).toNumber());
|
||||
await env.web3Wrapper.mineBlockAsync();
|
||||
const executeTx = await treasury.execute(proposalId, proposal.actions).awaitTransactionSuccessAsync();
|
||||
|
||||
verifyEventsFromLogs(
|
||||
executeTx.logs,
|
||||
[
|
||||
{
|
||||
proposalId,
|
||||
},
|
||||
],
|
||||
ZrxTreasuryEvents.ProposalExecuted,
|
||||
);
|
||||
|
||||
verifyEventsFromLogs(
|
||||
executeTx.logs,
|
||||
[
|
||||
{
|
||||
recipient: '0x976378445D31D81b15576811450A7b9797206807',
|
||||
deposit: new BigNumber('485392999999999970448000'),
|
||||
tokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498',
|
||||
startTime: new BigNumber(1635188400),
|
||||
stopTime: new BigNumber(1666724400),
|
||||
},
|
||||
{
|
||||
recipient: '0x976378445D31D81b15576811450A7b9797206807',
|
||||
deposit: new BigNumber('378035999999999992944000'),
|
||||
tokenAddress: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
|
||||
startTime: new BigNumber(1635188400),
|
||||
stopTime: new BigNumber(1666724400),
|
||||
},
|
||||
],
|
||||
ISablierEvents.CreateStream,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -17,8 +17,9 @@ import {
|
||||
randomAddress,
|
||||
verifyEventsFromLogs,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
import { TreasuryVote } from '@0x/protocol-utils';
|
||||
import { BigNumber, hexUtils } from '@0x/utils';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { DefaultPoolOperatorContract, ZrxTreasuryContract, ZrxTreasuryEvents } from './wrappers';
|
||||
@@ -55,6 +56,8 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
let nonDefaultPoolId: string;
|
||||
let poolOperator: string;
|
||||
let delegator: string;
|
||||
let relayer: string;
|
||||
let delegatorPrivateKey: string;
|
||||
let actions: ProposedAction[];
|
||||
|
||||
async function deployStakingAsync(): Promise<void> {
|
||||
@@ -105,7 +108,10 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
[admin, poolOperator, delegator] = await env.getAccountAddressesAsync();
|
||||
const accounts = await env.getAccountAddressesAsync();
|
||||
[admin, poolOperator, delegator, relayer] = accounts;
|
||||
delegatorPrivateKey = hexUtils.toHex(constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(delegator)]);
|
||||
|
||||
zrx = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
erc20Artifacts.DummyERC20Token,
|
||||
env.provider,
|
||||
@@ -399,7 +405,7 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
expect(await treasury.proposalCount().callAsync()).to.bignumber.equal(1);
|
||||
});
|
||||
});
|
||||
describe('castVote()', () => {
|
||||
describe('castVote() and castVoteBySignature()', () => {
|
||||
const VOTE_PROPOSAL_ID = new BigNumber(0);
|
||||
const DELEGATOR_VOTING_POWER = new BigNumber(420);
|
||||
|
||||
@@ -418,17 +424,18 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
.propose(actions, currentEpoch.plus(2), PROPOSAL_DESCRIPTION, [])
|
||||
.awaitTransactionSuccessAsync({ from: delegator });
|
||||
});
|
||||
// castVote()
|
||||
it('Cannot vote on invalid proposalId', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
const tx = treasury
|
||||
.castVote(INVALID_PROPOSAL_ID, true, [])
|
||||
.awaitTransactionSuccessAsync({ from: delegator });
|
||||
return expect(tx).to.revertWith('castVote/INVALID_PROPOSAL_ID');
|
||||
return expect(tx).to.revertWith('_castVote/INVALID_PROPOSAL_ID');
|
||||
});
|
||||
it('Cannot vote before voting period starts', async () => {
|
||||
const tx = treasury.castVote(VOTE_PROPOSAL_ID, true, []).awaitTransactionSuccessAsync({ from: delegator });
|
||||
return expect(tx).to.revertWith('castVote/VOTING_IS_CLOSED');
|
||||
return expect(tx).to.revertWith('_castVote/VOTING_IS_CLOSED');
|
||||
});
|
||||
it('Cannot vote after voting period ends', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
@@ -436,14 +443,14 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
await env.web3Wrapper.increaseTimeAsync(TREASURY_PARAMS.votingPeriod.plus(1).toNumber());
|
||||
await env.web3Wrapper.mineBlockAsync();
|
||||
const tx = treasury.castVote(VOTE_PROPOSAL_ID, true, []).awaitTransactionSuccessAsync({ from: delegator });
|
||||
return expect(tx).to.revertWith('castVote/VOTING_IS_CLOSED');
|
||||
return expect(tx).to.revertWith('_castVote/VOTING_IS_CLOSED');
|
||||
});
|
||||
it('Cannot vote twice on same proposal', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
await treasury.castVote(VOTE_PROPOSAL_ID, true, []).awaitTransactionSuccessAsync({ from: delegator });
|
||||
const tx = treasury.castVote(VOTE_PROPOSAL_ID, false, []).awaitTransactionSuccessAsync({ from: delegator });
|
||||
return expect(tx).to.revertWith('castVote/ALREADY_VOTED');
|
||||
return expect(tx).to.revertWith('_castVote/ALREADY_VOTED');
|
||||
});
|
||||
it('Can cast a valid vote', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
@@ -465,6 +472,109 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
ZrxTreasuryEvents.VoteCast,
|
||||
);
|
||||
});
|
||||
// castVoteBySignature()
|
||||
it('Cannot vote by signature on invalid proposalId', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
const vote = new TreasuryVote({
|
||||
proposalId: INVALID_PROPOSAL_ID,
|
||||
verifyingContract: admin,
|
||||
});
|
||||
const signature = vote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const tx = treasury
|
||||
.castVoteBySignature(INVALID_PROPOSAL_ID, true, [], signature.v, signature.r, signature.s)
|
||||
.awaitTransactionSuccessAsync({ from: relayer });
|
||||
return expect(tx).to.revertWith('_castVote/INVALID_PROPOSAL_ID');
|
||||
});
|
||||
it('Cannot vote by signature before voting period starts', async () => {
|
||||
const vote = new TreasuryVote({
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
verifyingContract: admin,
|
||||
});
|
||||
const signature = vote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const tx = treasury
|
||||
.castVoteBySignature(VOTE_PROPOSAL_ID, true, [], signature.v, signature.r, signature.s)
|
||||
.awaitTransactionSuccessAsync({ from: relayer });
|
||||
return expect(tx).to.revertWith('_castVote/VOTING_IS_CLOSED');
|
||||
});
|
||||
it('Cannot vote by signature after voting period ends', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
await env.web3Wrapper.increaseTimeAsync(TREASURY_PARAMS.votingPeriod.plus(1).toNumber());
|
||||
await env.web3Wrapper.mineBlockAsync();
|
||||
|
||||
const vote = new TreasuryVote({
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
verifyingContract: admin,
|
||||
});
|
||||
const signature = vote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const tx = treasury
|
||||
.castVoteBySignature(VOTE_PROPOSAL_ID, true, [], signature.v, signature.r, signature.s)
|
||||
.awaitTransactionSuccessAsync({ from: relayer });
|
||||
return expect(tx).to.revertWith('_castVote/VOTING_IS_CLOSED');
|
||||
});
|
||||
it('Can recover the address from signature correctly', async () => {
|
||||
const vote = new TreasuryVote({
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
verifyingContract: admin,
|
||||
});
|
||||
const signature = vote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const publicKey = ethUtil.ecrecover(
|
||||
ethUtil.toBuffer(vote.getEIP712Hash()),
|
||||
signature.v,
|
||||
ethUtil.toBuffer(signature.r),
|
||||
ethUtil.toBuffer(signature.s),
|
||||
);
|
||||
const address = ethUtil.publicToAddress(publicKey);
|
||||
|
||||
expect(ethUtil.bufferToHex(address)).to.be.equal(delegator);
|
||||
});
|
||||
it('Can cast a valid vote by signature', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
|
||||
const vote = new TreasuryVote({
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
verifyingContract: treasury.address,
|
||||
chainId: 1337,
|
||||
support: false,
|
||||
});
|
||||
const signature = vote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const tx = await treasury
|
||||
.castVoteBySignature(VOTE_PROPOSAL_ID, false, [], signature.v, signature.r, signature.s)
|
||||
.awaitTransactionSuccessAsync({ from: relayer });
|
||||
|
||||
verifyEventsFromLogs(
|
||||
tx.logs,
|
||||
[
|
||||
{
|
||||
voter: delegator,
|
||||
operatedPoolIds: [],
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
support: vote.support,
|
||||
votingPower: DELEGATOR_VOTING_POWER,
|
||||
},
|
||||
],
|
||||
ZrxTreasuryEvents.VoteCast,
|
||||
);
|
||||
});
|
||||
it('Cannot vote by signature twice on same proposal', async () => {
|
||||
await fastForwardToNextEpochAsync();
|
||||
await fastForwardToNextEpochAsync();
|
||||
await treasury.castVote(VOTE_PROPOSAL_ID, true, []).awaitTransactionSuccessAsync({ from: delegator });
|
||||
|
||||
const secondVote = new TreasuryVote({
|
||||
proposalId: VOTE_PROPOSAL_ID,
|
||||
verifyingContract: treasury.address,
|
||||
chainId: 1337,
|
||||
support: false,
|
||||
});
|
||||
const signature = secondVote.getSignatureWithKey(delegatorPrivateKey);
|
||||
const secondVoteTx = treasury
|
||||
.castVoteBySignature(VOTE_PROPOSAL_ID, false, [], signature.v, signature.r, signature.s)
|
||||
.awaitTransactionSuccessAsync({ from: relayer });
|
||||
return expect(secondVoteTx).to.revertWith('_castVote/ALREADY_VOTED');
|
||||
});
|
||||
});
|
||||
describe('execute()', () => {
|
||||
let passedProposalId: BigNumber;
|
||||
@@ -473,7 +583,7 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
let ongoingVoteProposalId: BigNumber;
|
||||
|
||||
before(async () => {
|
||||
// OPerator has enough ZRX to create and pass a proposal
|
||||
// Operator has enough ZRX to create and pass a proposal
|
||||
await staking.stake(TREASURY_PARAMS.quorumThreshold).awaitTransactionSuccessAsync({ from: poolOperator });
|
||||
await staking
|
||||
.moveStake(
|
||||
@@ -549,7 +659,7 @@ blockchainTests.resets('Treasury governance', env => {
|
||||
});
|
||||
it('Cannot execute before or after the execution epoch', async () => {
|
||||
const tooEarly = treasury.execute(passedProposalId, actions).awaitTransactionSuccessAsync();
|
||||
expect(tooEarly).to.revertWith('_assertProposalExecutable/CANNOT_EXECUTE_THIS_EPOCH');
|
||||
await expect(tooEarly).to.revertWith('_assertProposalExecutable/CANNOT_EXECUTE_THIS_EPOCH');
|
||||
await fastForwardToNextEpochAsync();
|
||||
// Proposal 0 is executable here
|
||||
await fastForwardToNextEpochAsync();
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
export * from '../test/generated-wrappers/default_pool_operator';
|
||||
export * from '../test/generated-wrappers/i_sablier';
|
||||
export * from '../test/generated-wrappers/i_staking';
|
||||
export * from '../test/generated-wrappers/i_zrx_treasury';
|
||||
export * from '../test/generated-wrappers/zrx_treasury';
|
||||
|
@@ -4,8 +4,10 @@
|
||||
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
||||
"files": [
|
||||
"generated-artifacts/DefaultPoolOperator.json",
|
||||
"generated-artifacts/ISablier.json",
|
||||
"generated-artifacts/ZrxTreasury.json",
|
||||
"test/generated-artifacts/DefaultPoolOperator.json",
|
||||
"test/generated-artifacts/ISablier.json",
|
||||
"test/generated-artifacts/IStaking.json",
|
||||
"test/generated-artifacts/IZrxTreasury.json",
|
||||
"test/generated-artifacts/ZrxTreasury.json"
|
||||
|
@@ -1,4 +1,167 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1660073235,
|
||||
"version": "4.8.16",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1659750766,
|
||||
"version": "4.8.15",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "4.8.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "4.8.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "4.8.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "4.8.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "4.8.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "4.8.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "4.8.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "4.8.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "4.8.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "4.8.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "4.8.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "4.8.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "4.8.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631710679,
|
||||
"version": "4.8.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "4.8.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Added FundRecoveryFeature to the 0x EP",
|
||||
"pr": 306
|
||||
}
|
||||
],
|
||||
"timestamp": 1631120757
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "4.7.18",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "4.7.17",
|
||||
|
@@ -5,6 +5,78 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v4.8.16 - _August 9, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.15 - _August 6, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.14 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.13 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.12 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.11 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.10 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.9 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.8 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.7 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.6 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.5 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.4 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.3 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.2 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.1 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.8.0 - _September 8, 2021_
|
||||
|
||||
* Added FundRecoveryFeature to the 0x EP (#306)
|
||||
|
||||
## v4.7.18 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.7.17 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-utils",
|
||||
"version": "4.7.17",
|
||||
"version": "4.8.16",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -50,15 +50,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/utils",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.6.0",
|
||||
"@0x/contracts-gen": "^2.0.38",
|
||||
"@0x/contracts-test-utils": "^5.4.9",
|
||||
"@0x/dev-utils": "^4.2.7",
|
||||
"@0x/abi-gen": "^5.8.0",
|
||||
"@0x/contracts-gen": "^2.0.46",
|
||||
"@0x/contracts-test-utils": "^5.4.26",
|
||||
"@0x/dev-utils": "^4.2.14",
|
||||
"@0x/order-utils": "^10.4.28",
|
||||
"@0x/sol-compiler": "^4.7.3",
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"@0x/types": "^3.3.3",
|
||||
"@0x/web3-wrapper": "^7.5.3",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"@types/bn.js": "^4.11.0",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
@@ -76,14 +76,14 @@
|
||||
"solhint": "^1.4.1",
|
||||
"truffle": "^5.0.32",
|
||||
"tslint": "5.11.0",
|
||||
"typescript": "4.2.2"
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.4.0",
|
||||
"@0x/typescript-typings": "^5.2.0",
|
||||
"@0x/utils": "^6.4.3",
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"bn.js": "^4.11.8",
|
||||
"ethereum-types": "^3.5.0"
|
||||
"ethereum-types": "^3.7.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@@ -1,4 +1,216 @@
|
||||
[
|
||||
{
|
||||
"version": "0.36.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add Foundry support",
|
||||
"pr": 534
|
||||
}
|
||||
],
|
||||
"timestamp": 1659976271
|
||||
},
|
||||
{
|
||||
"timestamp": 1659750766,
|
||||
"version": "0.36.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.36.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add Synthetix support in Ethereum and Optimism bridge adapters",
|
||||
"pr": 518
|
||||
}
|
||||
],
|
||||
"timestamp": 1658950329
|
||||
},
|
||||
{
|
||||
"version": "0.35.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Adds support for Velodrome OptimismBridgeAdapter",
|
||||
"pr": 494
|
||||
}
|
||||
],
|
||||
"timestamp": 1655244958
|
||||
},
|
||||
{
|
||||
"version": "0.34.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Splits BridgeAdapter up by chain",
|
||||
"pr": 487
|
||||
},
|
||||
{
|
||||
"note": "Add stETH wrap/unwrap support",
|
||||
"pr": 476
|
||||
},
|
||||
{
|
||||
"note": "Adds support for BancorV3 to EthereumBridgeAdapter",
|
||||
"pr": 492
|
||||
}
|
||||
],
|
||||
"timestamp": 1654284040
|
||||
},
|
||||
{
|
||||
"version": "0.33.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add support for GMX and Platypus to bridge adapter",
|
||||
"pr": 478
|
||||
}
|
||||
],
|
||||
"timestamp": 1652919697
|
||||
},
|
||||
{
|
||||
"version": "0.32.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add support for `BalancerV2Batch` fills in FQT",
|
||||
"pr": 462
|
||||
}
|
||||
],
|
||||
"timestamp": 1650611093
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "0.31.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "0.31.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.31.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add ERC721OrdersFeature, ERC1155OrdersFeature, and ERC165Feature",
|
||||
"pr": 429
|
||||
}
|
||||
],
|
||||
"timestamp": 1645569128
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "0.30.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.30.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `AaveV2` and `Compound` deposit/withdrawal liquidity source",
|
||||
"pr": 321
|
||||
}
|
||||
],
|
||||
"timestamp": 1638390144
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "0.29.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.29.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Prevent EP ETH balance from reducing when executin mtxs",
|
||||
"pr": 365
|
||||
}
|
||||
],
|
||||
"timestamp": 1637065617
|
||||
},
|
||||
{
|
||||
"version": "0.29.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Register transformERC20() and remove transformERC20Staging()",
|
||||
"pr": 355
|
||||
},
|
||||
{
|
||||
"note": "Add OtcOrders to FullMigration",
|
||||
"pr": 350
|
||||
}
|
||||
],
|
||||
"timestamp": 1635903615
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "0.29.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1633374058,
|
||||
"version": "0.29.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.29.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Export TransformERC20FeatureContract",
|
||||
"pr": 282
|
||||
}
|
||||
],
|
||||
"timestamp": 1632957537
|
||||
},
|
||||
{
|
||||
"timestamp": 1631710679,
|
||||
"version": "0.28.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631120757,
|
||||
"version": "0.28.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "0.28.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.28.2",
|
||||
"changes": [
|
||||
|
@@ -5,6 +5,93 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v0.36.2 - _August 8, 2022_
|
||||
|
||||
* Add Foundry support (#534)
|
||||
|
||||
## v0.36.1 - _August 6, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.36.0 - _July 27, 2022_
|
||||
|
||||
* Add Synthetix support in Ethereum and Optimism bridge adapters (#518)
|
||||
|
||||
## v0.35.0 - _June 14, 2022_
|
||||
|
||||
* Adds support for Velodrome OptimismBridgeAdapter (#494)
|
||||
|
||||
## v0.34.0 - _June 3, 2022_
|
||||
|
||||
* Splits BridgeAdapter up by chain (#487)
|
||||
* Add stETH wrap/unwrap support (#476)
|
||||
* Adds support for BancorV3 to EthereumBridgeAdapter (#492)
|
||||
|
||||
## v0.33.0 - _May 19, 2022_
|
||||
|
||||
* Add support for GMX and Platypus to bridge adapter (#478)
|
||||
|
||||
## v0.32.0 - _April 22, 2022_
|
||||
|
||||
* Add support for `BalancerV2Batch` fills in FQT (#462)
|
||||
|
||||
## v0.31.2 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.31.1 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.31.0 - _February 22, 2022_
|
||||
|
||||
* Add ERC721OrdersFeature, ERC1155OrdersFeature, and ERC165Feature (#429)
|
||||
|
||||
## v0.30.1 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.30.0 - _December 1, 2021_
|
||||
|
||||
* Add `AaveV2` and `Compound` deposit/withdrawal liquidity source (#321)
|
||||
|
||||
## v0.29.5 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.29.4 - _November 16, 2021_
|
||||
|
||||
* Prevent EP ETH balance from reducing when executin mtxs (#365)
|
||||
|
||||
## v0.29.3 - _November 3, 2021_
|
||||
|
||||
* Register transformERC20() and remove transformERC20Staging() (#355)
|
||||
* Add OtcOrders to FullMigration (#350)
|
||||
|
||||
## v0.29.2 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.29.1 - _October 4, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.29.0 - _September 29, 2021_
|
||||
|
||||
* Export TransformERC20FeatureContract (#282)
|
||||
|
||||
## v0.28.5 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.28.4 - _September 8, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.28.3 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v0.28.2 - _August 19, 2021_
|
||||
|
||||
* Add ethers as an explicit dependency (#310)
|
||||
|
@@ -2,6 +2,10 @@
|
||||
|
||||
This package contains contracts for the ZeroEx extensible contract architecture.
|
||||
|
||||
> **_NOTE:_** This repo is undergoing a tooling change. If adding a contract, you will need to
|
||||
> add it to `compiler.json`. You can generate the entire list by running the following:
|
||||
> `find . -type f -name "*.sol" | grep -v foundry | grep -v "contracts/dep" | grep -v "node_modules"`
|
||||
|
||||
## Installation
|
||||
|
||||
**Install**
|
||||
|
@@ -1,6 +1,212 @@
|
||||
{
|
||||
"artifactsDir": "./test/generated-artifacts",
|
||||
"contractsDir": "./contracts",
|
||||
"contracts": [
|
||||
"./contracts/src/IZeroEx.sol",
|
||||
"./contracts/src/ZeroEx.sol",
|
||||
"./contracts/src/ZeroExOptimized.sol",
|
||||
"./contracts/src/errors/LibCommonRichErrors.sol",
|
||||
"./contracts/src/errors/LibLiquidityProviderRichErrors.sol",
|
||||
"./contracts/src/errors/LibMetaTransactionsRichErrors.sol",
|
||||
"./contracts/src/errors/LibNFTOrdersRichErrors.sol",
|
||||
"./contracts/src/errors/LibNativeOrdersRichErrors.sol",
|
||||
"./contracts/src/errors/LibOwnableRichErrors.sol",
|
||||
"./contracts/src/errors/LibProxyRichErrors.sol",
|
||||
"./contracts/src/errors/LibSignatureRichErrors.sol",
|
||||
"./contracts/src/errors/LibSimpleFunctionRegistryRichErrors.sol",
|
||||
"./contracts/src/errors/LibTransformERC20RichErrors.sol",
|
||||
"./contracts/src/errors/LibWalletRichErrors.sol",
|
||||
"./contracts/src/external/FeeCollector.sol",
|
||||
"./contracts/src/external/FeeCollectorController.sol",
|
||||
"./contracts/src/external/FlashWallet.sol",
|
||||
"./contracts/src/external/IFlashWallet.sol",
|
||||
"./contracts/src/external/ILiquidityProviderSandbox.sol",
|
||||
"./contracts/src/external/LibFeeCollector.sol",
|
||||
"./contracts/src/external/LiquidityProviderSandbox.sol",
|
||||
"./contracts/src/external/PermissionlessTransformerDeployer.sol",
|
||||
"./contracts/src/external/TransformerDeployer.sol",
|
||||
"./contracts/src/features/BatchFillNativeOrdersFeature.sol",
|
||||
"./contracts/src/features/BootstrapFeature.sol",
|
||||
"./contracts/src/features/ERC165Feature.sol",
|
||||
"./contracts/src/features/FundRecoveryFeature.sol",
|
||||
"./contracts/src/features/LiquidityProviderFeature.sol",
|
||||
"./contracts/src/features/MetaTransactionsFeature.sol",
|
||||
"./contracts/src/features/NativeOrdersFeature.sol",
|
||||
"./contracts/src/features/OtcOrdersFeature.sol",
|
||||
"./contracts/src/features/OwnableFeature.sol",
|
||||
"./contracts/src/features/PancakeSwapFeature.sol",
|
||||
"./contracts/src/features/SimpleFunctionRegistryFeature.sol",
|
||||
"./contracts/src/features/TransformERC20Feature.sol",
|
||||
"./contracts/src/features/UniswapFeature.sol",
|
||||
"./contracts/src/features/UniswapV3Feature.sol",
|
||||
"./contracts/src/features/interfaces/IBatchFillNativeOrdersFeature.sol",
|
||||
"./contracts/src/features/interfaces/IBootstrapFeature.sol",
|
||||
"./contracts/src/features/interfaces/IERC1155OrdersFeature.sol",
|
||||
"./contracts/src/features/interfaces/IERC165Feature.sol",
|
||||
"./contracts/src/features/interfaces/IERC721OrdersFeature.sol",
|
||||
"./contracts/src/features/interfaces/IFeature.sol",
|
||||
"./contracts/src/features/interfaces/IFundRecoveryFeature.sol",
|
||||
"./contracts/src/features/interfaces/ILiquidityProviderFeature.sol",
|
||||
"./contracts/src/features/interfaces/IMetaTransactionsFeature.sol",
|
||||
"./contracts/src/features/interfaces/IMultiplexFeature.sol",
|
||||
"./contracts/src/features/interfaces/INativeOrdersEvents.sol",
|
||||
"./contracts/src/features/interfaces/INativeOrdersFeature.sol",
|
||||
"./contracts/src/features/interfaces/IOtcOrdersFeature.sol",
|
||||
"./contracts/src/features/interfaces/IOwnableFeature.sol",
|
||||
"./contracts/src/features/interfaces/IPancakeSwapFeature.sol",
|
||||
"./contracts/src/features/interfaces/ISimpleFunctionRegistryFeature.sol",
|
||||
"./contracts/src/features/interfaces/ITokenSpenderFeature.sol",
|
||||
"./contracts/src/features/interfaces/ITransformERC20Feature.sol",
|
||||
"./contracts/src/features/interfaces/IUniswapFeature.sol",
|
||||
"./contracts/src/features/interfaces/IUniswapV3Feature.sol",
|
||||
"./contracts/src/features/libs/LibNFTOrder.sol",
|
||||
"./contracts/src/features/libs/LibNativeOrder.sol",
|
||||
"./contracts/src/features/libs/LibSignature.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexFeature.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexLiquidityProvider.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexOtc.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexRfq.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexTransformERC20.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexUniswapV2.sol",
|
||||
"./contracts/src/features/multiplex/MultiplexUniswapV3.sol",
|
||||
"./contracts/src/features/native_orders/NativeOrdersCancellation.sol",
|
||||
"./contracts/src/features/native_orders/NativeOrdersInfo.sol",
|
||||
"./contracts/src/features/native_orders/NativeOrdersProtocolFees.sol",
|
||||
"./contracts/src/features/native_orders/NativeOrdersSettlement.sol",
|
||||
"./contracts/src/features/nft_orders/ERC1155OrdersFeature.sol",
|
||||
"./contracts/src/features/nft_orders/ERC721OrdersFeature.sol",
|
||||
"./contracts/src/features/nft_orders/NFTOrders.sol",
|
||||
"./contracts/src/fixins/FixinCommon.sol",
|
||||
"./contracts/src/fixins/FixinEIP712.sol",
|
||||
"./contracts/src/fixins/FixinERC1155Spender.sol",
|
||||
"./contracts/src/fixins/FixinERC721Spender.sol",
|
||||
"./contracts/src/fixins/FixinProtocolFees.sol",
|
||||
"./contracts/src/fixins/FixinReentrancyGuard.sol",
|
||||
"./contracts/src/fixins/FixinTokenSpender.sol",
|
||||
"./contracts/src/liquidity-providers/CurveLiquidityProvider.sol",
|
||||
"./contracts/src/liquidity-providers/MooniswapLiquidityProvider.sol",
|
||||
"./contracts/src/migrations/FullMigration.sol",
|
||||
"./contracts/src/migrations/InitialMigration.sol",
|
||||
"./contracts/src/migrations/LibBootstrap.sol",
|
||||
"./contracts/src/migrations/LibMigrate.sol",
|
||||
"./contracts/src/storage/LibERC1155OrdersStorage.sol",
|
||||
"./contracts/src/storage/LibERC721OrdersStorage.sol",
|
||||
"./contracts/src/storage/LibMetaTransactionsStorage.sol",
|
||||
"./contracts/src/storage/LibNativeOrdersStorage.sol",
|
||||
"./contracts/src/storage/LibOtcOrdersStorage.sol",
|
||||
"./contracts/src/storage/LibOwnableStorage.sol",
|
||||
"./contracts/src/storage/LibProxyStorage.sol",
|
||||
"./contracts/src/storage/LibReentrancyGuardStorage.sol",
|
||||
"./contracts/src/storage/LibSimpleFunctionRegistryStorage.sol",
|
||||
"./contracts/src/storage/LibStorage.sol",
|
||||
"./contracts/src/storage/LibTransformERC20Storage.sol",
|
||||
"./contracts/src/transformers/AffiliateFeeTransformer.sol",
|
||||
"./contracts/src/transformers/FillQuoteTransformer.sol",
|
||||
"./contracts/src/transformers/IERC20Transformer.sol",
|
||||
"./contracts/src/transformers/LibERC20Transformer.sol",
|
||||
"./contracts/src/transformers/LogMetadataTransformer.sol",
|
||||
"./contracts/src/transformers/PayTakerTransformer.sol",
|
||||
"./contracts/src/transformers/PositiveSlippageFeeTransformer.sol",
|
||||
"./contracts/src/transformers/Transformer.sol",
|
||||
"./contracts/src/transformers/WethTransformer.sol",
|
||||
"./contracts/src/transformers/bridges/AbstractBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/AvalancheBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/BSCBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/BridgeProtocols.sol",
|
||||
"./contracts/src/transformers/bridges/CeloBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/EthereumBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/FantomBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/IBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/OptimismBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/PolygonBridgeAdapter.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinAaveV2.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinBalancer.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinBalancerV2.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinBalancerV2Batch.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinBancor.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinBancorV3.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinCompound.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinCryptoCom.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinCurve.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinCurveV2.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinDodo.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinDodoV2.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinGMX.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinKyberDmm.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinLido.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinMStable.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinMakerPSM.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinMooniswap.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinNerve.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinPlatypus.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinShell.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinSynthetix.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinUniswap.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinUniswapV2.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinUniswapV3.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinVelodrome.sol",
|
||||
"./contracts/src/transformers/bridges/mixins/MixinZeroExBridge.sol",
|
||||
"./contracts/src/vendor/IERC1155Token.sol",
|
||||
"./contracts/src/vendor/IERC721Token.sol",
|
||||
"./contracts/src/vendor/IFeeRecipient.sol",
|
||||
"./contracts/src/vendor/ILiquidityProvider.sol",
|
||||
"./contracts/src/vendor/IMooniswapPool.sol",
|
||||
"./contracts/src/vendor/IPropertyValidator.sol",
|
||||
"./contracts/src/vendor/ITakerCallback.sol",
|
||||
"./contracts/src/vendor/IUniswapV2Pair.sol",
|
||||
"./contracts/src/vendor/IUniswapV3Pool.sol",
|
||||
"./contracts/src/vendor/v3/IERC20Bridge.sol",
|
||||
"./contracts/src/vendor/v3/IStaking.sol",
|
||||
"./contracts/test/ITestSimpleFunctionRegistryFeature.sol",
|
||||
"./contracts/test/TestBridge.sol",
|
||||
"./contracts/test/TestCallTarget.sol",
|
||||
"./contracts/test/TestDelegateCaller.sol",
|
||||
"./contracts/test/TestFeeCollectorController.sol",
|
||||
"./contracts/test/TestFeeRecipient.sol",
|
||||
"./contracts/test/TestFillQuoteTransformerBridge.sol",
|
||||
"./contracts/test/TestFillQuoteTransformerExchange.sol",
|
||||
"./contracts/test/TestFillQuoteTransformerHost.sol",
|
||||
"./contracts/test/TestFixinProtocolFees.sol",
|
||||
"./contracts/test/TestFixinTokenSpender.sol",
|
||||
"./contracts/test/TestFullMigration.sol",
|
||||
"./contracts/test/TestInitialMigration.sol",
|
||||
"./contracts/test/TestLibNativeOrder.sol",
|
||||
"./contracts/test/TestLibSignature.sol",
|
||||
"./contracts/test/TestMetaTransactionsNativeOrdersFeature.sol",
|
||||
"./contracts/test/TestMetaTransactionsTransformERC20Feature.sol",
|
||||
"./contracts/test/TestMigrator.sol",
|
||||
"./contracts/test/TestMintTokenERC20Transformer.sol",
|
||||
"./contracts/test/TestNFTOrderPresigner.sol",
|
||||
"./contracts/test/TestNativeOrdersFeature.sol",
|
||||
"./contracts/test/TestNoEthRecipient.sol",
|
||||
"./contracts/test/TestOrderSignerRegistryWithContractWallet.sol",
|
||||
"./contracts/test/TestPermissionlessTransformerDeployerSuicidal.sol",
|
||||
"./contracts/test/TestPermissionlessTransformerDeployerTransformer.sol",
|
||||
"./contracts/test/TestPropertyValidator.sol",
|
||||
"./contracts/test/TestRfqOriginRegistration.sol",
|
||||
"./contracts/test/TestSimpleFunctionRegistryFeatureImpl1.sol",
|
||||
"./contracts/test/TestSimpleFunctionRegistryFeatureImpl2.sol",
|
||||
"./contracts/test/TestStaking.sol",
|
||||
"./contracts/test/TestTransformERC20.sol",
|
||||
"./contracts/test/TestTransformerBase.sol",
|
||||
"./contracts/test/TestTransformerDeployerTransformer.sol",
|
||||
"./contracts/test/TestTransformerHost.sol",
|
||||
"./contracts/test/TestUniswapV3Feature.sol",
|
||||
"./contracts/test/TestWethTransformerHost.sol",
|
||||
"./contracts/test/TestZeroExFeature.sol",
|
||||
"./contracts/test/integration/TestCurve.sol",
|
||||
"./contracts/test/integration/TestLiquidityProvider.sol",
|
||||
"./contracts/test/integration/TestMooniswap.sol",
|
||||
"./contracts/test/integration/TestUniswapV2Factory.sol",
|
||||
"./contracts/test/integration/TestUniswapV2Pool.sol",
|
||||
"./contracts/test/integration/TestUniswapV3Factory.sol",
|
||||
"./contracts/test/integration/TestUniswapV3Pool.sol",
|
||||
"./contracts/test/tokens/TestMintableERC1155Token.sol",
|
||||
"./contracts/test/tokens/TestMintableERC20Token.sol",
|
||||
"./contracts/test/tokens/TestMintableERC721Token.sol",
|
||||
"./contracts/test/tokens/TestTokenSpenderERC20Token.sol",
|
||||
"./contracts/test/tokens/TestWeth.sol"
|
||||
],
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
|
1
contracts/zero-ex/contracts/deps/forge-std
Submodule
1
contracts/zero-ex/contracts/deps/forge-std
Submodule
Submodule contracts/zero-ex/contracts/deps/forge-std added at 1680d7fb3e
@@ -33,6 +33,10 @@ import "./features/interfaces/INativeOrdersFeature.sol";
|
||||
import "./features/interfaces/IBatchFillNativeOrdersFeature.sol";
|
||||
import "./features/interfaces/IMultiplexFeature.sol";
|
||||
import "./features/interfaces/IOtcOrdersFeature.sol";
|
||||
import "./features/interfaces/IFundRecoveryFeature.sol";
|
||||
import "./features/interfaces/IERC721OrdersFeature.sol";
|
||||
import "./features/interfaces/IERC1155OrdersFeature.sol";
|
||||
import "./features/interfaces/IERC165Feature.sol";
|
||||
|
||||
|
||||
/// @dev Interface for a fully featured Exchange Proxy.
|
||||
@@ -48,7 +52,11 @@ interface IZeroEx is
|
||||
INativeOrdersFeature,
|
||||
IBatchFillNativeOrdersFeature,
|
||||
IMultiplexFeature,
|
||||
IOtcOrdersFeature
|
||||
IOtcOrdersFeature,
|
||||
IFundRecoveryFeature,
|
||||
IERC721OrdersFeature,
|
||||
IERC1155OrdersFeature,
|
||||
IERC165Feature
|
||||
{
|
||||
// solhint-disable state-visibility
|
||||
|
||||
|
@@ -0,0 +1,229 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
|
||||
|
||||
library LibNFTOrdersRichErrors {
|
||||
|
||||
// solhint-disable func-name-mixedcase
|
||||
|
||||
function OverspentEthError(
|
||||
uint256 ethSpent,
|
||||
uint256 ethAvailable
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("OverspentEthError(uint256,uint256)")),
|
||||
ethSpent,
|
||||
ethAvailable
|
||||
);
|
||||
}
|
||||
|
||||
function InsufficientEthError(
|
||||
uint256 ethAvailable,
|
||||
uint256 orderAmount
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("InsufficientEthError(uint256,uint256)")),
|
||||
ethAvailable,
|
||||
orderAmount
|
||||
);
|
||||
}
|
||||
|
||||
function ERC721TokenMismatchError(
|
||||
address token1,
|
||||
address token2
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("ERC721TokenMismatchError(address,address)")),
|
||||
token1,
|
||||
token2
|
||||
);
|
||||
}
|
||||
|
||||
function ERC1155TokenMismatchError(
|
||||
address token1,
|
||||
address token2
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("ERC1155TokenMismatchError(address,address)")),
|
||||
token1,
|
||||
token2
|
||||
);
|
||||
}
|
||||
|
||||
function ERC20TokenMismatchError(
|
||||
address token1,
|
||||
address token2
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("ERC20TokenMismatchError(address,address)")),
|
||||
token1,
|
||||
token2
|
||||
);
|
||||
}
|
||||
|
||||
function NegativeSpreadError(
|
||||
uint256 sellOrderAmount,
|
||||
uint256 buyOrderAmount
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("NegativeSpreadError(uint256,uint256)")),
|
||||
sellOrderAmount,
|
||||
buyOrderAmount
|
||||
);
|
||||
}
|
||||
|
||||
function SellOrderFeesExceedSpreadError(
|
||||
uint256 sellOrderFees,
|
||||
uint256 spread
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("SellOrderFeesExceedSpreadError(uint256,uint256)")),
|
||||
sellOrderFees,
|
||||
spread
|
||||
);
|
||||
}
|
||||
|
||||
function OnlyTakerError(
|
||||
address sender,
|
||||
address taker
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("OnlyTakerError(address,address)")),
|
||||
sender,
|
||||
taker
|
||||
);
|
||||
}
|
||||
|
||||
function InvalidSignerError(
|
||||
address maker,
|
||||
address signer
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("InvalidSignerError(address,address)")),
|
||||
maker,
|
||||
signer
|
||||
);
|
||||
}
|
||||
|
||||
function OrderNotFillableError(
|
||||
address maker,
|
||||
uint256 nonce,
|
||||
uint8 orderStatus
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("OrderNotFillableError(address,uint256,uint8)")),
|
||||
maker,
|
||||
nonce,
|
||||
orderStatus
|
||||
);
|
||||
}
|
||||
|
||||
function TokenIdMismatchError(
|
||||
uint256 tokenId,
|
||||
uint256 orderTokenId
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("TokenIdMismatchError(uint256,uint256)")),
|
||||
tokenId,
|
||||
orderTokenId
|
||||
);
|
||||
}
|
||||
|
||||
function PropertyValidationFailedError(
|
||||
address propertyValidator,
|
||||
address token,
|
||||
uint256 tokenId,
|
||||
bytes memory propertyData,
|
||||
bytes memory errorData
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("PropertyValidationFailedError(address,address,uint256,bytes,bytes)")),
|
||||
propertyValidator,
|
||||
token,
|
||||
tokenId,
|
||||
propertyData,
|
||||
errorData
|
||||
);
|
||||
}
|
||||
|
||||
function ExceedsRemainingOrderAmount(
|
||||
uint128 remainingOrderAmount,
|
||||
uint128 fillAmount
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
bytes4(keccak256("ExceedsRemainingOrderAmount(uint128,uint128)")),
|
||||
remainingOrderAmount,
|
||||
fillAmount
|
||||
);
|
||||
}
|
||||
}
|
51
contracts/zero-ex/contracts/src/features/ERC165Feature.sol
Normal file
51
contracts/zero-ex/contracts/src/features/ERC165Feature.sol
Normal file
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../fixins/FixinCommon.sol";
|
||||
import "./interfaces/IFeature.sol";
|
||||
|
||||
|
||||
/// @dev Implements the ERC165 `supportsInterface` function
|
||||
contract ERC165Feature is
|
||||
IFeature,
|
||||
FixinCommon
|
||||
{
|
||||
/// @dev Name of this feature.
|
||||
string public constant override FEATURE_NAME = "ERC165";
|
||||
/// @dev Version of this feature.
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
|
||||
|
||||
/// @dev Indicates whether the 0x Exchange Proxy implements a particular
|
||||
/// ERC165 interface. This function should use at most 30,000 gas.
|
||||
/// @param interfaceId The interface identifier, as specified in ERC165.
|
||||
/// @return isSupported Whether the given interface is supported by the
|
||||
/// 0x Exchange Proxy.
|
||||
function supportInterface(bytes4 interfaceId)
|
||||
external
|
||||
pure
|
||||
returns (bool isSupported)
|
||||
{
|
||||
return interfaceId == 0x01ffc9a7 || // ERC-165 support
|
||||
interfaceId == 0x150b7a02 || // ERC-721 `ERC721TokenReceiver` support
|
||||
interfaceId == 0x4e2312e0; // ERC-1155 `ERC1155TokenReceiver` support
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../migrations/LibMigrate.sol";
|
||||
import "../fixins/FixinCommon.sol";
|
||||
import "./interfaces/IFeature.sol";
|
||||
import "./interfaces/IFundRecoveryFeature.sol";
|
||||
import "../transformers/LibERC20Transformer.sol";
|
||||
|
||||
contract FundRecoveryFeature is
|
||||
IFeature,
|
||||
IFundRecoveryFeature,
|
||||
FixinCommon
|
||||
{
|
||||
/// @dev Name of this feature.
|
||||
string public constant override FEATURE_NAME = "FundRecoveryFeature";
|
||||
/// @dev Version of this feature.
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
|
||||
|
||||
/// @dev Initialize and register this feature.
|
||||
/// Should be delegatecalled by `Migrate.migrate()`.
|
||||
/// @return success `LibMigrate.SUCCESS` on success.
|
||||
function migrate()
|
||||
external
|
||||
returns (bytes4 success)
|
||||
{
|
||||
_registerFeatureFunction(this.transferTrappedTokensTo.selector);
|
||||
return LibMigrate.MIGRATE_SUCCESS;
|
||||
}
|
||||
|
||||
/// @dev Recovers ERC20 tokens or ETH from the 0x Exchange Proxy contract
|
||||
/// @param erc20 ERC20 Token Address. (You can also pass in `0xeeeee...` to indicate ETH)
|
||||
/// @param amountOut Amount of tokens to withdraw.
|
||||
/// @param recipientWallet Recipient wallet address.
|
||||
function transferTrappedTokensTo(
|
||||
IERC20TokenV06 erc20,
|
||||
uint256 amountOut,
|
||||
address payable recipientWallet
|
||||
)
|
||||
external
|
||||
override
|
||||
onlyOwner
|
||||
{
|
||||
if(amountOut == uint256(-1)) {
|
||||
amountOut = LibERC20Transformer.getTokenBalanceOf(erc20, address(this));
|
||||
}
|
||||
LibERC20Transformer.transformerTransfer(erc20, recipientWallet, amountOut);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -78,7 +78,7 @@ contract MetaTransactionsFeature is
|
||||
/// @dev Name of this feature.
|
||||
string public constant override FEATURE_NAME = "MetaTransactions";
|
||||
/// @dev Version of this feature.
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 0);
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 1);
|
||||
/// @dev EIP712 typehash of the `MetaTransactionData` struct.
|
||||
bytes32 public immutable MTX_EIP712_TYPEHASH = keccak256(
|
||||
"MetaTransactionData("
|
||||
@@ -105,6 +105,17 @@ contract MetaTransactionsFeature is
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Ensures that the ETH balance of `this` does not go below the
|
||||
/// initial ETH balance before the call (excluding ETH attached to the call).
|
||||
modifier doesNotReduceEthBalance() {
|
||||
uint256 initialBalance = address(this).balance - msg.value;
|
||||
_;
|
||||
require(
|
||||
initialBalance <= address(this).balance,
|
||||
"MetaTransactionsFeature/ETH_LEAK"
|
||||
);
|
||||
}
|
||||
|
||||
constructor(address zeroExAddress)
|
||||
public
|
||||
FixinCommon()
|
||||
@@ -140,6 +151,7 @@ contract MetaTransactionsFeature is
|
||||
payable
|
||||
override
|
||||
nonReentrant(REENTRANCY_MTX)
|
||||
doesNotReduceEthBalance
|
||||
refundsAttachedEth
|
||||
returns (bytes memory returnResult)
|
||||
{
|
||||
@@ -164,6 +176,7 @@ contract MetaTransactionsFeature is
|
||||
payable
|
||||
override
|
||||
nonReentrant(REENTRANCY_MTX)
|
||||
doesNotReduceEthBalance
|
||||
refundsAttachedEth
|
||||
returns (bytes[] memory returnResults)
|
||||
{
|
||||
|
@@ -311,7 +311,7 @@ contract OtcOrdersFeature is
|
||||
// Unwrap WETH
|
||||
WETH.withdraw(order.makerAmount);
|
||||
// Transfer ETH to taker
|
||||
_transferEth(taker, order.makerAmount);
|
||||
_transferEth(payable(taker), order.makerAmount);
|
||||
|
||||
emit OtcOrderFilled(
|
||||
orderInfo.orderHash,
|
||||
@@ -622,16 +622,4 @@ contract OtcOrdersFeature is
|
||||
[txOrigin]
|
||||
[nonceBucket];
|
||||
}
|
||||
|
||||
function _transferEth(address recipient, uint256 amount)
|
||||
private
|
||||
{
|
||||
// Transfer ETH to recipient
|
||||
(bool success, bytes memory revertData) =
|
||||
recipient.call{value: amount}("");
|
||||
// Revert on failure
|
||||
if (!success) {
|
||||
revertData.rrevert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ contract TransformERC20Feature is
|
||||
_registerFeatureFunction(this.setTransformerDeployer.selector);
|
||||
_registerFeatureFunction(this.setQuoteSigner.selector);
|
||||
_registerFeatureFunction(this.getQuoteSigner.selector);
|
||||
_registerFeatureFunction(this.transformERC20Staging.selector);
|
||||
_registerFeatureFunction(this.transformERC20.selector);
|
||||
_registerFeatureFunction(this._transformERC20.selector);
|
||||
if (this.getTransformWallet() == IFlashWallet(address(0))) {
|
||||
// Create the transform wallet if it doesn't exist.
|
||||
@@ -145,44 +145,6 @@ contract TransformERC20Feature is
|
||||
LibTransformERC20Storage.getStorage().wallet = wallet;
|
||||
}
|
||||
|
||||
/// @dev Wrapper for `transformERC20`. This selector will be temporarily
|
||||
/// registered to the Exchange Proxy so that we can migrate 0x API
|
||||
/// with no downtime. Once 0x API has been updated to point to this
|
||||
/// function, we can safely re-register `transformERC20`, point
|
||||
/// 0x API back to `transformERC20`, and deregister this function.
|
||||
/// @param inputToken The token being provided by the sender.
|
||||
/// If `0xeee...`, ETH is implied and should be provided with the call.`
|
||||
/// @param outputToken The token to be acquired by the sender.
|
||||
/// `0xeee...` implies ETH.
|
||||
/// @param inputTokenAmount The amount of `inputToken` to take from the sender.
|
||||
/// If set to `uint256(-1)`, the entire spendable balance of the taker
|
||||
/// will be solt.
|
||||
/// @param minOutputTokenAmount The minimum amount of `outputToken` the sender
|
||||
/// must receive for the entire transformation to succeed. If set to zero,
|
||||
/// the minimum output token transfer will not be asserted.
|
||||
/// @param transformations The transformations to execute on the token balance(s)
|
||||
/// in sequence.
|
||||
/// @return outputTokenAmount The amount of `outputToken` received by the sender.
|
||||
function transformERC20Staging(
|
||||
IERC20TokenV06 inputToken,
|
||||
IERC20TokenV06 outputToken,
|
||||
uint256 inputTokenAmount,
|
||||
uint256 minOutputTokenAmount,
|
||||
Transformation[] memory transformations
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (uint256 outputTokenAmount)
|
||||
{
|
||||
return transformERC20(
|
||||
inputToken,
|
||||
outputToken,
|
||||
inputTokenAmount,
|
||||
minOutputTokenAmount,
|
||||
transformations
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Executes a series of transformations to convert an ERC20 `inputToken`
|
||||
/// to an ERC20 `outputToken`.
|
||||
/// @param inputToken The token being provided by the sender.
|
||||
@@ -283,8 +245,8 @@ contract TransformERC20Feature is
|
||||
}
|
||||
// Transfer output tokens from wallet to recipient
|
||||
outputTokenAmount = _executeOutputTokenTransfer(
|
||||
args.outputToken,
|
||||
state.wallet,
|
||||
args.outputToken,
|
||||
state.wallet,
|
||||
args.recipient
|
||||
);
|
||||
}
|
||||
|
@@ -0,0 +1,242 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../libs/LibNFTOrder.sol";
|
||||
import "../libs/LibSignature.sol";
|
||||
import "../../vendor/IERC1155Token.sol";
|
||||
|
||||
|
||||
/// @dev Feature for interacting with ERC1155 orders.
|
||||
interface IERC1155OrdersFeature {
|
||||
|
||||
/// @dev Emitted whenever an `ERC1155Order` is filled.
|
||||
/// @param direction Whether the order is selling or
|
||||
/// buying the ERC1155 token.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param taker The taker of the order.
|
||||
/// @param nonce The unique maker nonce in the order.
|
||||
/// @param erc20Token The address of the ERC20 token.
|
||||
/// @param erc20FillAmount The amount of ERC20 token filled.
|
||||
/// @param erc1155Token The address of the ERC1155 token.
|
||||
/// @param erc1155TokenId The ID of the ERC1155 asset.
|
||||
/// @param erc1155FillAmount The amount of ERC1155 asset filled.
|
||||
/// @param matcher Currently unused.
|
||||
event ERC1155OrderFilled(
|
||||
LibNFTOrder.TradeDirection direction,
|
||||
address maker,
|
||||
address taker,
|
||||
uint256 nonce,
|
||||
IERC20TokenV06 erc20Token,
|
||||
uint256 erc20FillAmount,
|
||||
IERC1155Token erc1155Token,
|
||||
uint256 erc1155TokenId,
|
||||
uint128 erc1155FillAmount,
|
||||
address matcher
|
||||
);
|
||||
|
||||
/// @dev Emitted whenever an `ERC1155Order` is cancelled.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param nonce The nonce of the order that was cancelled.
|
||||
event ERC1155OrderCancelled(
|
||||
address maker,
|
||||
uint256 nonce
|
||||
);
|
||||
|
||||
/// @dev Emitted when an `ERC1155Order` is pre-signed.
|
||||
/// Contains all the fields of the order.
|
||||
event ERC1155OrderPreSigned(
|
||||
LibNFTOrder.TradeDirection direction,
|
||||
address maker,
|
||||
address taker,
|
||||
uint256 expiry,
|
||||
uint256 nonce,
|
||||
IERC20TokenV06 erc20Token,
|
||||
uint256 erc20TokenAmount,
|
||||
LibNFTOrder.Fee[] fees,
|
||||
IERC1155Token erc1155Token,
|
||||
uint256 erc1155TokenId,
|
||||
LibNFTOrder.Property[] erc1155TokenProperties,
|
||||
uint128 erc1155TokenAmount
|
||||
);
|
||||
|
||||
/// @dev Sells an ERC1155 asset to fill the given order.
|
||||
/// @param buyOrder The ERC1155 buy order.
|
||||
/// @param signature The order signature from the maker.
|
||||
/// @param erc1155TokenId The ID of the ERC1155 asset being
|
||||
/// sold. If the given order specifies properties,
|
||||
/// the asset must satisfy those properties. Otherwise,
|
||||
/// it must equal the tokenId in the order.
|
||||
/// @param erc1155SellAmount The amount of the ERC1155 asset
|
||||
/// to sell.
|
||||
/// @param unwrapNativeToken If this parameter is true and the
|
||||
/// ERC20 token of the order is e.g. WETH, unwraps the
|
||||
/// token before transferring it to the taker.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC1155OrderCallback` on `msg.sender` after
|
||||
/// the ERC20 tokens have been transferred to `msg.sender`
|
||||
/// but before transferring the ERC1155 asset to the buyer.
|
||||
function sellERC1155(
|
||||
LibNFTOrder.ERC1155Order calldata buyOrder,
|
||||
LibSignature.Signature calldata signature,
|
||||
uint256 erc1155TokenId,
|
||||
uint128 erc1155SellAmount,
|
||||
bool unwrapNativeToken,
|
||||
bytes calldata callbackData
|
||||
)
|
||||
external;
|
||||
|
||||
/// @dev Buys an ERC1155 asset by filling the given order.
|
||||
/// @param sellOrder The ERC1155 sell order.
|
||||
/// @param signature The order signature.
|
||||
/// @param erc1155BuyAmount The amount of the ERC1155 asset
|
||||
/// to buy.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC1155OrderCallback` on `msg.sender` after
|
||||
/// the ERC1155 asset has been transferred to `msg.sender`
|
||||
/// but before transferring the ERC20 tokens to the seller.
|
||||
/// Native tokens acquired during the callback can be used
|
||||
/// to fill the order.
|
||||
function buyERC1155(
|
||||
LibNFTOrder.ERC1155Order calldata sellOrder,
|
||||
LibSignature.Signature calldata signature,
|
||||
uint128 erc1155BuyAmount,
|
||||
bytes calldata callbackData
|
||||
)
|
||||
external
|
||||
payable;
|
||||
|
||||
/// @dev Cancel a single ERC1155 order by its nonce. The caller
|
||||
/// should be the maker of the order. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonce The order nonce.
|
||||
function cancelERC1155Order(uint256 orderNonce)
|
||||
external;
|
||||
|
||||
/// @dev Cancel multiple ERC1155 orders by their nonces. The caller
|
||||
/// should be the maker of the orders. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonces The order nonces.
|
||||
function batchCancelERC1155Orders(uint256[] calldata orderNonces)
|
||||
external;
|
||||
|
||||
/// @dev Buys multiple ERC1155 assets by filling the
|
||||
/// given orders.
|
||||
/// @param sellOrders The ERC1155 sell orders.
|
||||
/// @param signatures The order signatures.
|
||||
/// @param erc1155TokenAmounts The amounts of the ERC1155 assets
|
||||
/// to buy for each order.
|
||||
/// @param callbackData The data (if any) to pass to the taker
|
||||
/// callback for each order. Refer to the `callbackData`
|
||||
/// parameter to for `buyERC1155`.
|
||||
/// @param revertIfIncomplete If true, reverts if this
|
||||
/// function fails to fill any individual order.
|
||||
/// @return successes An array of booleans corresponding to whether
|
||||
/// each order in `orders` was successfully filled.
|
||||
function batchBuyERC1155s(
|
||||
LibNFTOrder.ERC1155Order[] calldata sellOrders,
|
||||
LibSignature.Signature[] calldata signatures,
|
||||
uint128[] calldata erc1155TokenAmounts,
|
||||
bytes[] calldata callbackData,
|
||||
bool revertIfIncomplete
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (bool[] memory successes);
|
||||
|
||||
/// @dev Callback for the ERC1155 `safeTransferFrom` function.
|
||||
/// This callback can be used to sell an ERC1155 asset if
|
||||
/// a valid ERC1155 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`. This allows takers to sell their
|
||||
/// ERC1155 asset without first calling `setApprovalForAll`.
|
||||
/// @param operator The address which called `safeTransferFrom`.
|
||||
/// @param from The address which previously owned the token.
|
||||
/// @param tokenId The ID of the asset being transferred.
|
||||
/// @param value The amount being transferred.
|
||||
/// @param data Additional data with no specified format. If a
|
||||
/// valid ERC1155 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`, this function will try to fill
|
||||
/// the order using the received asset.
|
||||
/// @return success The selector of this function (0xf23a6e61),
|
||||
/// indicating that the callback succeeded.
|
||||
function onERC1155Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 tokenId,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
)
|
||||
external
|
||||
returns (bytes4 success);
|
||||
|
||||
/// @dev Approves an ERC1155 order on-chain. After pre-signing
|
||||
/// the order, the `PRESIGNED` signature type will become
|
||||
/// valid for that order and signer.
|
||||
/// @param order An ERC1155 order.
|
||||
function preSignERC1155Order(LibNFTOrder.ERC1155Order calldata order)
|
||||
external;
|
||||
|
||||
/// @dev Checks whether the given signature is valid for the
|
||||
/// the given ERC1155 order. Reverts if not.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @param signature The signature to validate.
|
||||
function validateERC1155OrderSignature(
|
||||
LibNFTOrder.ERC1155Order calldata order,
|
||||
LibSignature.Signature calldata signature
|
||||
)
|
||||
external
|
||||
view;
|
||||
|
||||
/// @dev If the given order is buying an ERC1155 asset, checks
|
||||
/// whether or not the given token ID satisfies the required
|
||||
/// properties specified in the order. If the order does not
|
||||
/// specify any properties, this function instead checks
|
||||
/// whether the given token ID matches the ID in the order.
|
||||
/// Reverts if any checks fail, or if the order is selling
|
||||
/// an ERC1155 asset.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @param erc1155TokenId The ID of the ERC1155 asset.
|
||||
function validateERC1155OrderProperties(
|
||||
LibNFTOrder.ERC1155Order calldata order,
|
||||
uint256 erc1155TokenId
|
||||
)
|
||||
external
|
||||
view;
|
||||
|
||||
/// @dev Get the order info for an ERC1155 order.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @return orderInfo Infor about the order.
|
||||
function getERC1155OrderInfo(LibNFTOrder.ERC1155Order calldata order)
|
||||
external
|
||||
view
|
||||
returns (LibNFTOrder.OrderInfo memory orderInfo);
|
||||
|
||||
/// @dev Get the EIP-712 hash of an ERC1155 order.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @return orderHash The order hash.
|
||||
function getERC1155OrderHash(LibNFTOrder.ERC1155Order calldata order)
|
||||
external
|
||||
view
|
||||
returns (bytes32 orderHash);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
/// @dev Implements the ERC165 `supportsInterface` function
|
||||
interface IERC165Feature {
|
||||
|
||||
/// @dev Indicates whether the 0x Exchange Proxy implements a particular
|
||||
/// ERC165 interface. This function should use at most 30,000 gas.
|
||||
/// @param interfaceId The interface identifier, as specified in ERC165.
|
||||
/// @return isSupported Whether the given interface is supported by the
|
||||
/// 0x Exchange Proxy.
|
||||
function supportInterface(bytes4 interfaceId)
|
||||
external
|
||||
pure
|
||||
returns (bool isSupported);
|
||||
}
|
@@ -0,0 +1,286 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../libs/LibNFTOrder.sol";
|
||||
import "../libs/LibSignature.sol";
|
||||
import "../../vendor/IERC721Token.sol";
|
||||
|
||||
|
||||
/// @dev Feature for interacting with ERC721 orders.
|
||||
interface IERC721OrdersFeature {
|
||||
|
||||
/// @dev Emitted whenever an `ERC721Order` is filled.
|
||||
/// @param direction Whether the order is selling or
|
||||
/// buying the ERC721 token.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param taker The taker of the order.
|
||||
/// @param nonce The unique maker nonce in the order.
|
||||
/// @param erc20Token The address of the ERC20 token.
|
||||
/// @param erc20TokenAmount The amount of ERC20 token
|
||||
/// to sell or buy.
|
||||
/// @param erc721Token The address of the ERC721 token.
|
||||
/// @param erc721TokenId The ID of the ERC721 asset.
|
||||
/// @param matcher If this order was matched with another using `matchERC721Orders()`,
|
||||
/// this will be the address of the caller. If not, this will be `address(0)`.
|
||||
event ERC721OrderFilled(
|
||||
LibNFTOrder.TradeDirection direction,
|
||||
address maker,
|
||||
address taker,
|
||||
uint256 nonce,
|
||||
IERC20TokenV06 erc20Token,
|
||||
uint256 erc20TokenAmount,
|
||||
IERC721Token erc721Token,
|
||||
uint256 erc721TokenId,
|
||||
address matcher
|
||||
);
|
||||
|
||||
/// @dev Emitted whenever an `ERC721Order` is cancelled.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param nonce The nonce of the order that was cancelled.
|
||||
event ERC721OrderCancelled(
|
||||
address maker,
|
||||
uint256 nonce
|
||||
);
|
||||
|
||||
/// @dev Emitted when an `ERC721Order` is pre-signed.
|
||||
/// Contains all the fields of the order.
|
||||
event ERC721OrderPreSigned(
|
||||
LibNFTOrder.TradeDirection direction,
|
||||
address maker,
|
||||
address taker,
|
||||
uint256 expiry,
|
||||
uint256 nonce,
|
||||
IERC20TokenV06 erc20Token,
|
||||
uint256 erc20TokenAmount,
|
||||
LibNFTOrder.Fee[] fees,
|
||||
IERC721Token erc721Token,
|
||||
uint256 erc721TokenId,
|
||||
LibNFTOrder.Property[] erc721TokenProperties
|
||||
);
|
||||
|
||||
/// @dev Sells an ERC721 asset to fill the given order.
|
||||
/// @param buyOrder The ERC721 buy order.
|
||||
/// @param signature The order signature from the maker.
|
||||
/// @param erc721TokenId The ID of the ERC721 asset being
|
||||
/// sold. If the given order specifies properties,
|
||||
/// the asset must satisfy those properties. Otherwise,
|
||||
/// it must equal the tokenId in the order.
|
||||
/// @param unwrapNativeToken If this parameter is true and the
|
||||
/// ERC20 token of the order is e.g. WETH, unwraps the
|
||||
/// token before transferring it to the taker.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC721OrderCallback` on `msg.sender` after
|
||||
/// the ERC20 tokens have been transferred to `msg.sender`
|
||||
/// but before transferring the ERC721 asset to the buyer.
|
||||
function sellERC721(
|
||||
LibNFTOrder.ERC721Order calldata buyOrder,
|
||||
LibSignature.Signature calldata signature,
|
||||
uint256 erc721TokenId,
|
||||
bool unwrapNativeToken,
|
||||
bytes calldata callbackData
|
||||
)
|
||||
external;
|
||||
|
||||
/// @dev Buys an ERC721 asset by filling the given order.
|
||||
/// @param sellOrder The ERC721 sell order.
|
||||
/// @param signature The order signature.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC721OrderCallback` on `msg.sender` after
|
||||
/// the ERC721 asset has been transferred to `msg.sender`
|
||||
/// but before transferring the ERC20 tokens to the seller.
|
||||
/// Native tokens acquired during the callback can be used
|
||||
/// to fill the order.
|
||||
function buyERC721(
|
||||
LibNFTOrder.ERC721Order calldata sellOrder,
|
||||
LibSignature.Signature calldata signature,
|
||||
bytes calldata callbackData
|
||||
)
|
||||
external
|
||||
payable;
|
||||
|
||||
/// @dev Cancel a single ERC721 order by its nonce. The caller
|
||||
/// should be the maker of the order. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonce The order nonce.
|
||||
function cancelERC721Order(uint256 orderNonce)
|
||||
external;
|
||||
|
||||
/// @dev Cancel multiple ERC721 orders by their nonces. The caller
|
||||
/// should be the maker of the orders. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonces The order nonces.
|
||||
function batchCancelERC721Orders(uint256[] calldata orderNonces)
|
||||
external;
|
||||
|
||||
/// @dev Buys multiple ERC721 assets by filling the
|
||||
/// given orders.
|
||||
/// @param sellOrders The ERC721 sell orders.
|
||||
/// @param signatures The order signatures.
|
||||
/// @param callbackData The data (if any) to pass to the taker
|
||||
/// callback for each order. Refer to the `callbackData`
|
||||
/// parameter to for `buyERC721`.
|
||||
/// @param revertIfIncomplete If true, reverts if this
|
||||
/// function fails to fill any individual order.
|
||||
/// @return successes An array of booleans corresponding to whether
|
||||
/// each order in `orders` was successfully filled.
|
||||
function batchBuyERC721s(
|
||||
LibNFTOrder.ERC721Order[] calldata sellOrders,
|
||||
LibSignature.Signature[] calldata signatures,
|
||||
bytes[] calldata callbackData,
|
||||
bool revertIfIncomplete
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (bool[] memory successes);
|
||||
|
||||
/// @dev Matches a pair of complementary orders that have
|
||||
/// a non-negative spread. Each order is filled at
|
||||
/// their respective price, and the matcher receives
|
||||
/// a profit denominated in the ERC20 token.
|
||||
/// @param sellOrder Order selling an ERC721 asset.
|
||||
/// @param buyOrder Order buying an ERC721 asset.
|
||||
/// @param sellOrderSignature Signature for the sell order.
|
||||
/// @param buyOrderSignature Signature for the buy order.
|
||||
/// @return profit The amount of profit earned by the caller
|
||||
/// of this function (denominated in the ERC20 token
|
||||
/// of the matched orders).
|
||||
function matchERC721Orders(
|
||||
LibNFTOrder.ERC721Order calldata sellOrder,
|
||||
LibNFTOrder.ERC721Order calldata buyOrder,
|
||||
LibSignature.Signature calldata sellOrderSignature,
|
||||
LibSignature.Signature calldata buyOrderSignature
|
||||
)
|
||||
external
|
||||
returns (uint256 profit);
|
||||
|
||||
/// @dev Matches pairs of complementary orders that have
|
||||
/// non-negative spreads. Each order is filled at
|
||||
/// their respective price, and the matcher receives
|
||||
/// a profit denominated in the ERC20 token.
|
||||
/// @param sellOrders Orders selling ERC721 assets.
|
||||
/// @param buyOrders Orders buying ERC721 assets.
|
||||
/// @param sellOrderSignatures Signatures for the sell orders.
|
||||
/// @param buyOrderSignatures Signatures for the buy orders.
|
||||
/// @return profits The amount of profit earned by the caller
|
||||
/// of this function for each pair of matched orders
|
||||
/// (denominated in the ERC20 token of the order pair).
|
||||
/// @return successes An array of booleans corresponding to
|
||||
/// whether each pair of orders was successfully matched.
|
||||
function batchMatchERC721Orders(
|
||||
LibNFTOrder.ERC721Order[] calldata sellOrders,
|
||||
LibNFTOrder.ERC721Order[] calldata buyOrders,
|
||||
LibSignature.Signature[] calldata sellOrderSignatures,
|
||||
LibSignature.Signature[] calldata buyOrderSignatures
|
||||
)
|
||||
external
|
||||
returns (uint256[] memory profits, bool[] memory successes);
|
||||
|
||||
/// @dev Callback for the ERC721 `safeTransferFrom` function.
|
||||
/// This callback can be used to sell an ERC721 asset if
|
||||
/// a valid ERC721 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`. This allows takers to sell their
|
||||
/// ERC721 asset without first calling `setApprovalForAll`.
|
||||
/// @param operator The address which called `safeTransferFrom`.
|
||||
/// @param from The address which previously owned the token.
|
||||
/// @param tokenId The ID of the asset being transferred.
|
||||
/// @param data Additional data with no specified format. If a
|
||||
/// valid ERC721 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`, this function will try to fill
|
||||
/// the order using the received asset.
|
||||
/// @return success The selector of this function (0x150b7a02),
|
||||
/// indicating that the callback succeeded.
|
||||
function onERC721Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 tokenId,
|
||||
bytes calldata data
|
||||
)
|
||||
external
|
||||
returns (bytes4 success);
|
||||
|
||||
/// @dev Approves an ERC721 order on-chain. After pre-signing
|
||||
/// the order, the `PRESIGNED` signature type will become
|
||||
/// valid for that order and signer.
|
||||
/// @param order An ERC721 order.
|
||||
function preSignERC721Order(LibNFTOrder.ERC721Order calldata order)
|
||||
external;
|
||||
|
||||
/// @dev Checks whether the given signature is valid for the
|
||||
/// the given ERC721 order. Reverts if not.
|
||||
/// @param order The ERC721 order.
|
||||
/// @param signature The signature to validate.
|
||||
function validateERC721OrderSignature(
|
||||
LibNFTOrder.ERC721Order calldata order,
|
||||
LibSignature.Signature calldata signature
|
||||
)
|
||||
external
|
||||
view;
|
||||
|
||||
/// @dev If the given order is buying an ERC721 asset, checks
|
||||
/// whether or not the given token ID satisfies the required
|
||||
/// properties specified in the order. If the order does not
|
||||
/// specify any properties, this function instead checks
|
||||
/// whether the given token ID matches the ID in the order.
|
||||
/// Reverts if any checks fail, or if the order is selling
|
||||
/// an ERC721 asset.
|
||||
/// @param order The ERC721 order.
|
||||
/// @param erc721TokenId The ID of the ERC721 asset.
|
||||
function validateERC721OrderProperties(
|
||||
LibNFTOrder.ERC721Order calldata order,
|
||||
uint256 erc721TokenId
|
||||
)
|
||||
external
|
||||
view;
|
||||
|
||||
/// @dev Get the current status of an ERC721 order.
|
||||
/// @param order The ERC721 order.
|
||||
/// @return status The status of the order.
|
||||
function getERC721OrderStatus(LibNFTOrder.ERC721Order calldata order)
|
||||
external
|
||||
view
|
||||
returns (LibNFTOrder.OrderStatus status);
|
||||
|
||||
/// @dev Get the EIP-712 hash of an ERC721 order.
|
||||
/// @param order The ERC721 order.
|
||||
/// @return orderHash The order hash.
|
||||
function getERC721OrderHash(LibNFTOrder.ERC721Order calldata order)
|
||||
external
|
||||
view
|
||||
returns (bytes32 orderHash);
|
||||
|
||||
/// @dev Get the order status bit vector for the given
|
||||
/// maker address and nonce range.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param nonceRange Order status bit vectors are indexed
|
||||
/// by maker address and the upper 248 bits of the
|
||||
/// order nonce. We define `nonceRange` to be these
|
||||
/// 248 bits.
|
||||
/// @return bitVector The order status bit vector for the
|
||||
/// given maker and nonce range.
|
||||
function getERC721OrderStatusBitVector(address maker, uint248 nonceRange)
|
||||
external
|
||||
view
|
||||
returns (uint256 bitVector);
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
|
||||
|
||||
/// @dev Exchange Proxy Recovery Functions
|
||||
interface IFundRecoveryFeature {
|
||||
|
||||
/// @dev calledFrom FundRecoveryFeature.transferTrappedTokensTo() This will be delegatecalled
|
||||
/// in the context of the Exchange Proxy instance being used.
|
||||
/// @param erc20 ERC20 Token Address.
|
||||
/// @param amountOut Amount of tokens to withdraw.
|
||||
/// @param recipientWallet Recipient wallet address.
|
||||
function transferTrappedTokensTo(
|
||||
IERC20TokenV06 erc20,
|
||||
uint256 amountOut,
|
||||
address payable recipientWallet
|
||||
)
|
||||
external;
|
||||
}
|
459
contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol
Normal file
459
contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol
Normal file
@@ -0,0 +1,459 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../../vendor/IERC1155Token.sol";
|
||||
import "../../vendor/IERC721Token.sol";
|
||||
import "../../vendor/IPropertyValidator.sol";
|
||||
|
||||
|
||||
/// @dev A library for common NFT order operations.
|
||||
library LibNFTOrder {
|
||||
|
||||
enum OrderStatus {
|
||||
INVALID,
|
||||
FILLABLE,
|
||||
UNFILLABLE,
|
||||
EXPIRED
|
||||
}
|
||||
|
||||
enum TradeDirection {
|
||||
SELL_NFT,
|
||||
BUY_NFT
|
||||
}
|
||||
|
||||
struct Property {
|
||||
IPropertyValidator propertyValidator;
|
||||
bytes propertyData;
|
||||
}
|
||||
|
||||
struct Fee {
|
||||
address recipient;
|
||||
uint256 amount;
|
||||
bytes feeData;
|
||||
}
|
||||
|
||||
// "Base struct" for ERC721Order and ERC1155, used
|
||||
// by the abstract contract `NFTOrders`.
|
||||
struct NFTOrder {
|
||||
TradeDirection direction;
|
||||
address maker;
|
||||
address taker;
|
||||
uint256 expiry;
|
||||
uint256 nonce;
|
||||
IERC20TokenV06 erc20Token;
|
||||
uint256 erc20TokenAmount;
|
||||
Fee[] fees;
|
||||
address nft;
|
||||
uint256 nftId;
|
||||
Property[] nftProperties;
|
||||
}
|
||||
|
||||
// All fields align with those of NFTOrder
|
||||
struct ERC721Order {
|
||||
TradeDirection direction;
|
||||
address maker;
|
||||
address taker;
|
||||
uint256 expiry;
|
||||
uint256 nonce;
|
||||
IERC20TokenV06 erc20Token;
|
||||
uint256 erc20TokenAmount;
|
||||
Fee[] fees;
|
||||
IERC721Token erc721Token;
|
||||
uint256 erc721TokenId;
|
||||
Property[] erc721TokenProperties;
|
||||
}
|
||||
|
||||
// All fields except `erc1155TokenAmount` align
|
||||
// with those of NFTOrder
|
||||
struct ERC1155Order {
|
||||
TradeDirection direction;
|
||||
address maker;
|
||||
address taker;
|
||||
uint256 expiry;
|
||||
uint256 nonce;
|
||||
IERC20TokenV06 erc20Token;
|
||||
uint256 erc20TokenAmount;
|
||||
Fee[] fees;
|
||||
IERC1155Token erc1155Token;
|
||||
uint256 erc1155TokenId;
|
||||
Property[] erc1155TokenProperties;
|
||||
// End of fields shared with NFTOrder
|
||||
uint128 erc1155TokenAmount;
|
||||
}
|
||||
|
||||
struct OrderInfo {
|
||||
bytes32 orderHash;
|
||||
OrderStatus status;
|
||||
// `orderAmount` is 1 for all ERC721Orders, and
|
||||
// `erc1155TokenAmount` for ERC1155Orders.
|
||||
uint128 orderAmount;
|
||||
// The remaining amount of the ERC721/ERC1155 asset
|
||||
// that can be filled for the order.
|
||||
uint128 remainingAmount;
|
||||
}
|
||||
|
||||
// The type hash for ERC721 orders, which is:
|
||||
// keccak256(abi.encodePacked(
|
||||
// "ERC721Order(",
|
||||
// "uint8 direction,",
|
||||
// "address maker,",
|
||||
// "address taker,",
|
||||
// "uint256 expiry,",
|
||||
// "uint256 nonce,",
|
||||
// "address erc20Token,",
|
||||
// "uint256 erc20TokenAmount,",
|
||||
// "Fee[] fees,",
|
||||
// "address erc721Token,",
|
||||
// "uint256 erc721TokenId,",
|
||||
// "Property[] erc721TokenProperties",
|
||||
// ")",
|
||||
// "Fee(",
|
||||
// "address recipient,",
|
||||
// "uint256 amount,",
|
||||
// "bytes feeData",
|
||||
// ")",
|
||||
// "Property(",
|
||||
// "address propertyValidator,",
|
||||
// "bytes propertyData",
|
||||
// ")"
|
||||
// ))
|
||||
uint256 private constant _ERC_721_ORDER_TYPEHASH =
|
||||
0x2de32b2b090da7d8ab83ca4c85ba2eb6957bc7f6c50cb4ae1995e87560d808ed;
|
||||
|
||||
// The type hash for ERC1155 orders, which is:
|
||||
// keccak256(abi.encodePacked(
|
||||
// "ERC1155Order(",
|
||||
// "uint8 direction,",
|
||||
// "address maker,",
|
||||
// "address taker,",
|
||||
// "uint256 expiry,",
|
||||
// "uint256 nonce,",
|
||||
// "address erc20Token,",
|
||||
// "uint256 erc20TokenAmount,",
|
||||
// "Fee[] fees,",
|
||||
// "address erc1155Token,",
|
||||
// "uint256 erc1155TokenId,",
|
||||
// "Property[] erc1155TokenProperties,",
|
||||
// "uint128 erc1155TokenAmount",
|
||||
// ")",
|
||||
// "Fee(",
|
||||
// "address recipient,",
|
||||
// "uint256 amount,",
|
||||
// "bytes feeData",
|
||||
// ")",
|
||||
// "Property(",
|
||||
// "address propertyValidator,",
|
||||
// "bytes propertyData",
|
||||
// ")"
|
||||
// ))
|
||||
uint256 private constant _ERC_1155_ORDER_TYPEHASH =
|
||||
0x930490b1bcedd2e5139e22c761fafd52e533960197c2283f3922c7fd8c880be9;
|
||||
|
||||
// keccak256(abi.encodePacked(
|
||||
// "Fee(",
|
||||
// "address recipient,",
|
||||
// "uint256 amount,",
|
||||
// "bytes feeData",
|
||||
// ")"
|
||||
// ))
|
||||
uint256 private constant _FEE_TYPEHASH =
|
||||
0xe68c29f1b4e8cce0bbcac76eb1334bdc1dc1f293a517c90e9e532340e1e94115;
|
||||
|
||||
// keccak256(abi.encodePacked(
|
||||
// "Property(",
|
||||
// "address propertyValidator,",
|
||||
// "bytes propertyData",
|
||||
// ")"
|
||||
// ))
|
||||
uint256 private constant _PROPERTY_TYPEHASH =
|
||||
0x6292cf854241cb36887e639065eca63b3af9f7f70270cebeda4c29b6d3bc65e8;
|
||||
|
||||
// keccak256("");
|
||||
bytes32 private constant _EMPTY_ARRAY_KECCAK256 =
|
||||
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
|
||||
|
||||
// keccak256(abi.encodePacked(keccak256(abi.encode(
|
||||
// _PROPERTY_TYPEHASH,
|
||||
// address(0),
|
||||
// keccak256("")
|
||||
// ))));
|
||||
bytes32 private constant _NULL_PROPERTY_STRUCT_HASH =
|
||||
0x720ee400a9024f6a49768142c339bf09d2dd9056ab52d20fbe7165faba6e142d;
|
||||
|
||||
uint256 private constant ADDRESS_MASK = (1 << 160) - 1;
|
||||
|
||||
// ERC721Order and NFTOrder fields are aligned, so
|
||||
// we can safely cast an ERC721Order to an NFTOrder.
|
||||
function asNFTOrder(ERC721Order memory erc721Order)
|
||||
internal
|
||||
pure
|
||||
returns (NFTOrder memory nftOrder)
|
||||
{
|
||||
assembly {
|
||||
nftOrder := erc721Order
|
||||
}
|
||||
}
|
||||
|
||||
// ERC1155Order and NFTOrder fields are aligned with
|
||||
// the exception of the last field `erc1155TokenAmount`
|
||||
// in ERC1155Order, so we can safely cast an ERC1155Order
|
||||
// to an NFTOrder.
|
||||
function asNFTOrder(ERC1155Order memory erc1155Order)
|
||||
internal
|
||||
pure
|
||||
returns (NFTOrder memory nftOrder)
|
||||
{
|
||||
assembly {
|
||||
nftOrder := erc1155Order
|
||||
}
|
||||
}
|
||||
|
||||
// ERC721Order and NFTOrder fields are aligned, so
|
||||
// we can safely cast an MFTOrder to an ERC721Order.
|
||||
function asERC721Order(NFTOrder memory nftOrder)
|
||||
internal
|
||||
pure
|
||||
returns (ERC721Order memory erc721Order)
|
||||
{
|
||||
assembly {
|
||||
erc721Order := nftOrder
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: This is only safe if `nftOrder` was previously
|
||||
// cast from an `ERC1155Order` and the original
|
||||
// `erc1155TokenAmount` memory word has not been corrupted!
|
||||
function asERC1155Order(
|
||||
NFTOrder memory nftOrder
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (ERC1155Order memory erc1155Order)
|
||||
{
|
||||
assembly {
|
||||
erc1155Order := nftOrder
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Get the struct hash of an ERC721 order.
|
||||
/// @param order The ERC721 order.
|
||||
/// @return structHash The struct hash of the order.
|
||||
function getERC721OrderStructHash(ERC721Order memory order)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 structHash)
|
||||
{
|
||||
bytes32 propertiesHash = _propertiesHash(order.erc721TokenProperties);
|
||||
bytes32 feesHash = _feesHash(order.fees);
|
||||
|
||||
// Hash in place, equivalent to:
|
||||
// return keccak256(abi.encode(
|
||||
// _ERC_721_ORDER_TYPEHASH,
|
||||
// order.direction,
|
||||
// order.maker,
|
||||
// order.taker,
|
||||
// order.expiry,
|
||||
// order.nonce,
|
||||
// order.erc20Token,
|
||||
// order.erc20TokenAmount,
|
||||
// feesHash,
|
||||
// order.erc721Token,
|
||||
// order.erc721TokenId,
|
||||
// propertiesHash
|
||||
// ));
|
||||
assembly {
|
||||
if lt(order, 32) { invalid() } // Don't underflow memory.
|
||||
|
||||
let typeHashPos := sub(order, 32) // order - 32
|
||||
let feesHashPos := add(order, 224) // order + (32 * 7)
|
||||
let propertiesHashPos := add(order, 320) // order + (32 * 10)
|
||||
|
||||
let typeHashMemBefore := mload(typeHashPos)
|
||||
let feeHashMemBefore := mload(feesHashPos)
|
||||
let propertiesHashMemBefore := mload(propertiesHashPos)
|
||||
|
||||
mstore(typeHashPos, _ERC_721_ORDER_TYPEHASH)
|
||||
mstore(feesHashPos, feesHash)
|
||||
mstore(propertiesHashPos, propertiesHash)
|
||||
structHash := keccak256(typeHashPos, 384 /* 32 * 12 */ )
|
||||
|
||||
mstore(typeHashPos, typeHashMemBefore)
|
||||
mstore(feesHashPos, feeHashMemBefore)
|
||||
mstore(propertiesHashPos, propertiesHashMemBefore)
|
||||
}
|
||||
return structHash;
|
||||
}
|
||||
|
||||
/// @dev Get the struct hash of an ERC1155 order.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @return structHash The struct hash of the order.
|
||||
function getERC1155OrderStructHash(ERC1155Order memory order)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 structHash)
|
||||
{
|
||||
bytes32 propertiesHash = _propertiesHash(order.erc1155TokenProperties);
|
||||
bytes32 feesHash = _feesHash(order.fees);
|
||||
|
||||
// Hash in place, equivalent to:
|
||||
// return keccak256(abi.encode(
|
||||
// _ERC_1155_ORDER_TYPEHASH,
|
||||
// order.direction,
|
||||
// order.maker,
|
||||
// order.taker,
|
||||
// order.expiry,
|
||||
// order.nonce,
|
||||
// order.erc20Token,
|
||||
// order.erc20TokenAmount,
|
||||
// feesHash,
|
||||
// order.erc1155Token,
|
||||
// order.erc1155TokenId,
|
||||
// propertiesHash,
|
||||
// order.erc1155TokenAmount
|
||||
// ));
|
||||
assembly {
|
||||
if lt(order, 32) { invalid() } // Don't underflow memory.
|
||||
|
||||
let typeHashPos := sub(order, 32) // order - 32
|
||||
let feesHashPos := add(order, 224) // order + (32 * 7)
|
||||
let propertiesHashPos := add(order, 320) // order + (32 * 10)
|
||||
|
||||
let typeHashMemBefore := mload(typeHashPos)
|
||||
let feesHashMemBefore := mload(feesHashPos)
|
||||
let propertiesHashMemBefore := mload(propertiesHashPos)
|
||||
|
||||
mstore(typeHashPos, _ERC_1155_ORDER_TYPEHASH)
|
||||
mstore(feesHashPos, feesHash)
|
||||
mstore(propertiesHashPos, propertiesHash)
|
||||
structHash := keccak256(typeHashPos, 416 /* 32 * 12 */ )
|
||||
|
||||
mstore(typeHashPos, typeHashMemBefore)
|
||||
mstore(feesHashPos, feesHashMemBefore)
|
||||
mstore(propertiesHashPos, propertiesHashMemBefore)
|
||||
}
|
||||
return structHash;
|
||||
}
|
||||
|
||||
// Hashes the `properties` array as part of computing the
|
||||
// EIP-712 hash of an `ERC721Order` or `ERC1155Order`.
|
||||
function _propertiesHash(Property[] memory properties)
|
||||
private
|
||||
pure
|
||||
returns (bytes32 propertiesHash)
|
||||
{
|
||||
uint256 numProperties = properties.length;
|
||||
// We give `properties.length == 0` and `properties.length == 1`
|
||||
// special treatment because we expect these to be the most common.
|
||||
if (numProperties == 0) {
|
||||
propertiesHash = _EMPTY_ARRAY_KECCAK256;
|
||||
} else if (numProperties == 1) {
|
||||
Property memory property = properties[0];
|
||||
if (
|
||||
address(property.propertyValidator) == address(0) &&
|
||||
property.propertyData.length == 0
|
||||
) {
|
||||
propertiesHash = _NULL_PROPERTY_STRUCT_HASH;
|
||||
} else {
|
||||
// propertiesHash = keccak256(abi.encodePacked(keccak256(abi.encode(
|
||||
// _PROPERTY_TYPEHASH,
|
||||
// properties[0].propertyValidator,
|
||||
// keccak256(properties[0].propertyData)
|
||||
// ))));
|
||||
bytes32 dataHash = keccak256(property.propertyData);
|
||||
assembly {
|
||||
// Load free memory pointer
|
||||
let mem := mload(64)
|
||||
mstore(mem, _PROPERTY_TYPEHASH)
|
||||
// property.propertyValidator
|
||||
mstore(add(mem, 32), and(ADDRESS_MASK, mload(property)))
|
||||
// keccak256(property.propertyData)
|
||||
mstore(add(mem, 64), dataHash)
|
||||
mstore(mem, keccak256(mem, 96))
|
||||
propertiesHash := keccak256(mem, 32)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bytes32[] memory propertyStructHashArray = new bytes32[](numProperties);
|
||||
for (uint256 i = 0; i < numProperties; i++) {
|
||||
propertyStructHashArray[i] = keccak256(abi.encode(
|
||||
_PROPERTY_TYPEHASH,
|
||||
properties[i].propertyValidator,
|
||||
keccak256(properties[i].propertyData)
|
||||
));
|
||||
}
|
||||
assembly {
|
||||
propertiesHash := keccak256(add(propertyStructHashArray, 32), mul(numProperties, 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hashes the `fees` array as part of computing the
|
||||
// EIP-712 hash of an `ERC721Order` or `ERC1155Order`.
|
||||
function _feesHash(Fee[] memory fees)
|
||||
private
|
||||
pure
|
||||
returns (bytes32 feesHash)
|
||||
{
|
||||
uint256 numFees = fees.length;
|
||||
// We give `fees.length == 0` and `fees.length == 1`
|
||||
// special treatment because we expect these to be the most common.
|
||||
if (numFees == 0) {
|
||||
feesHash = _EMPTY_ARRAY_KECCAK256;
|
||||
} else if (numFees == 1) {
|
||||
// feesHash = keccak256(abi.encodePacked(keccak256(abi.encode(
|
||||
// _FEE_TYPEHASH,
|
||||
// fees[0].recipient,
|
||||
// fees[0].amount,
|
||||
// keccak256(fees[0].feeData)
|
||||
// ))));
|
||||
Fee memory fee = fees[0];
|
||||
bytes32 dataHash = keccak256(fee.feeData);
|
||||
assembly {
|
||||
// Load free memory pointer
|
||||
let mem := mload(64)
|
||||
mstore(mem, _FEE_TYPEHASH)
|
||||
// fee.recipient
|
||||
mstore(add(mem, 32), and(ADDRESS_MASK, mload(fee)))
|
||||
// fee.amount
|
||||
mstore(add(mem, 64), mload(add(fee, 32)))
|
||||
// keccak256(fee.feeData)
|
||||
mstore(add(mem, 96), dataHash)
|
||||
mstore(mem, keccak256(mem, 128))
|
||||
feesHash := keccak256(mem, 32)
|
||||
}
|
||||
} else {
|
||||
bytes32[] memory feeStructHashArray = new bytes32[](numFees);
|
||||
for (uint256 i = 0; i < numFees; i++) {
|
||||
feeStructHashArray[i] = keccak256(abi.encode(
|
||||
_FEE_TYPEHASH,
|
||||
fees[i].recipient,
|
||||
fees[i].amount,
|
||||
keccak256(fees[i].feeData)
|
||||
));
|
||||
}
|
||||
assembly {
|
||||
feesHash := keccak256(add(feeStructHashArray, 32), mul(numFees, 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,7 +44,8 @@ library LibSignature {
|
||||
ILLEGAL,
|
||||
INVALID,
|
||||
EIP712,
|
||||
ETHSIGN
|
||||
ETHSIGN,
|
||||
PRESIGNED
|
||||
}
|
||||
|
||||
/// @dev Encoded EC signature.
|
||||
@@ -146,6 +147,15 @@ library LibSignature {
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// If a feature supports pre-signing, it wouldn't use
|
||||
// `getSignerOfHash` on a pre-signed order.
|
||||
if (signature.signatureType == SignatureType.PRESIGNED) {
|
||||
LibSignatureRichErrors.SignatureValidationError(
|
||||
LibSignatureRichErrors.SignatureValidationErrorCodes.UNSUPPORTED,
|
||||
hash
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Solidity should check that the signature type is within enum range for us
|
||||
// when abi-decoding.
|
||||
}
|
||||
|
@@ -622,15 +622,6 @@ contract MultiplexFeature is
|
||||
_executeBatchSell(batchSellParams).boughtAmount;
|
||||
}
|
||||
|
||||
// Transfers some amount of ETH to the given recipient and
|
||||
// reverts if the transfer fails.
|
||||
function _transferEth(address payable recipient, uint256 amount)
|
||||
private
|
||||
{
|
||||
(bool success,) = recipient.call{value: amount}("");
|
||||
require(success, "MultiplexFeature::_transferEth/TRANSFER_FAILED");
|
||||
}
|
||||
|
||||
// This function computes the "target" address of hop index `i` within
|
||||
// a multi-hop sell.
|
||||
// If `i == 0`, the target is the address which should hold the input
|
||||
|
@@ -0,0 +1,635 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../../fixins/FixinERC1155Spender.sol";
|
||||
import "../../migrations/LibMigrate.sol";
|
||||
import "../../storage/LibERC1155OrdersStorage.sol";
|
||||
import "../interfaces/IFeature.sol";
|
||||
import "../interfaces/IERC1155OrdersFeature.sol";
|
||||
import "../libs/LibNFTOrder.sol";
|
||||
import "../libs/LibSignature.sol";
|
||||
import "./NFTOrders.sol";
|
||||
|
||||
|
||||
/// @dev Feature for interacting with ERC1155 orders.
|
||||
contract ERC1155OrdersFeature is
|
||||
IFeature,
|
||||
IERC1155OrdersFeature,
|
||||
FixinERC1155Spender,
|
||||
NFTOrders
|
||||
{
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibSafeMathV06 for uint128;
|
||||
using LibNFTOrder for LibNFTOrder.ERC1155Order;
|
||||
using LibNFTOrder for LibNFTOrder.NFTOrder;
|
||||
|
||||
/// @dev Name of this feature.
|
||||
string public constant override FEATURE_NAME = "ERC1155Orders";
|
||||
/// @dev Version of this feature.
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
|
||||
|
||||
/// @dev The magic return value indicating the success of a `onERC1155Received`.
|
||||
bytes4 private constant ERC1155_RECEIVED_MAGIC_BYTES = this.onERC1155Received.selector;
|
||||
|
||||
|
||||
constructor(address zeroExAddress, IEtherTokenV06 weth)
|
||||
public
|
||||
NFTOrders(zeroExAddress, weth)
|
||||
{}
|
||||
|
||||
/// @dev Initialize and register this feature.
|
||||
/// Should be delegatecalled by `Migrate.migrate()`.
|
||||
/// @return success `LibMigrate.SUCCESS` on success.
|
||||
function migrate()
|
||||
external
|
||||
returns (bytes4 success)
|
||||
{
|
||||
_registerFeatureFunction(this.sellERC1155.selector);
|
||||
_registerFeatureFunction(this.buyERC1155.selector);
|
||||
_registerFeatureFunction(this.cancelERC1155Order.selector);
|
||||
_registerFeatureFunction(this.batchBuyERC1155s.selector);
|
||||
_registerFeatureFunction(this.onERC1155Received.selector);
|
||||
_registerFeatureFunction(this.preSignERC1155Order.selector);
|
||||
_registerFeatureFunction(this.validateERC1155OrderSignature.selector);
|
||||
_registerFeatureFunction(this.validateERC1155OrderProperties.selector);
|
||||
_registerFeatureFunction(this.getERC1155OrderInfo.selector);
|
||||
_registerFeatureFunction(this.getERC1155OrderHash.selector);
|
||||
return LibMigrate.MIGRATE_SUCCESS;
|
||||
}
|
||||
|
||||
/// @dev Sells an ERC1155 asset to fill the given order.
|
||||
/// @param buyOrder The ERC1155 buy order.
|
||||
/// @param signature The order signature from the maker.
|
||||
/// @param erc1155TokenId The ID of the ERC1155 asset being
|
||||
/// sold. If the given order specifies properties,
|
||||
/// the asset must satisfy those properties. Otherwise,
|
||||
/// it must equal the tokenId in the order.
|
||||
/// @param erc1155SellAmount The amount of the ERC1155 asset
|
||||
/// to sell.
|
||||
/// @param unwrapNativeToken If this parameter is true and the
|
||||
/// ERC20 token of the order is e.g. WETH, unwraps the
|
||||
/// token before transferring it to the taker.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC1155OrderCallback` on `msg.sender` after
|
||||
/// the ERC20 tokens have been transferred to `msg.sender`
|
||||
/// but before transferring the ERC1155 asset to the buyer.
|
||||
function sellERC1155(
|
||||
LibNFTOrder.ERC1155Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
uint256 erc1155TokenId,
|
||||
uint128 erc1155SellAmount,
|
||||
bool unwrapNativeToken,
|
||||
bytes memory callbackData
|
||||
)
|
||||
public
|
||||
override
|
||||
{
|
||||
_sellERC1155(
|
||||
buyOrder,
|
||||
signature,
|
||||
SellParams(
|
||||
erc1155SellAmount,
|
||||
erc1155TokenId,
|
||||
unwrapNativeToken,
|
||||
msg.sender, // taker
|
||||
msg.sender, // owner
|
||||
callbackData
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Buys an ERC1155 asset by filling the given order.
|
||||
/// @param sellOrder The ERC1155 sell order.
|
||||
/// @param signature The order signature.
|
||||
/// @param erc1155BuyAmount The amount of the ERC1155 asset
|
||||
/// to buy.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC1155OrderCallback` on `msg.sender` after
|
||||
/// the ERC1155 asset has been transferred to `msg.sender`
|
||||
/// but before transferring the ERC20 tokens to the seller.
|
||||
/// Native tokens acquired during the callback can be used
|
||||
/// to fill the order.
|
||||
function buyERC1155(
|
||||
LibNFTOrder.ERC1155Order memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
uint128 erc1155BuyAmount,
|
||||
bytes memory callbackData
|
||||
)
|
||||
public
|
||||
override
|
||||
payable
|
||||
{
|
||||
uint256 ethBalanceBefore = address(this).balance
|
||||
.safeSub(msg.value);
|
||||
_buyERC1155(
|
||||
sellOrder,
|
||||
signature,
|
||||
BuyParams(
|
||||
erc1155BuyAmount,
|
||||
msg.value,
|
||||
callbackData
|
||||
)
|
||||
);
|
||||
uint256 ethBalanceAfter = address(this).balance;
|
||||
// Cannot use pre-existing ETH balance
|
||||
if (ethBalanceAfter < ethBalanceBefore) {
|
||||
LibNFTOrdersRichErrors.OverspentEthError(
|
||||
ethBalanceBefore - ethBalanceAfter + msg.value,
|
||||
msg.value
|
||||
).rrevert();
|
||||
}
|
||||
// Refund
|
||||
_transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore);
|
||||
}
|
||||
|
||||
/// @dev Cancel a single ERC1155 order by its nonce. The caller
|
||||
/// should be the maker of the order. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonce The order nonce.
|
||||
function cancelERC1155Order(uint256 orderNonce)
|
||||
public
|
||||
override
|
||||
{
|
||||
// The bitvector is indexed by the lower 8 bits of the nonce.
|
||||
uint256 flag = 1 << (orderNonce & 255);
|
||||
// Update order cancellation bit vector to indicate that the order
|
||||
// has been cancelled/filled by setting the designated bit to 1.
|
||||
LibERC1155OrdersStorage.getStorage().orderCancellationByMaker
|
||||
[msg.sender][uint248(orderNonce >> 8)] |= flag;
|
||||
|
||||
emit ERC1155OrderCancelled(msg.sender, orderNonce);
|
||||
}
|
||||
|
||||
/// @dev Cancel multiple ERC1155 orders by their nonces. The caller
|
||||
/// should be the maker of the orders. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonces The order nonces.
|
||||
function batchCancelERC1155Orders(uint256[] calldata orderNonces)
|
||||
external
|
||||
override
|
||||
{
|
||||
for (uint256 i = 0; i < orderNonces.length; i++) {
|
||||
cancelERC1155Order(orderNonces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Buys multiple ERC1155 assets by filling the
|
||||
/// given orders.
|
||||
/// @param sellOrders The ERC1155 sell orders.
|
||||
/// @param signatures The order signatures.
|
||||
/// @param erc1155FillAmounts The amounts of the ERC1155 assets
|
||||
/// to buy for each order.
|
||||
/// @param callbackData The data (if any) to pass to the taker
|
||||
/// callback for each order. Refer to the `callbackData`
|
||||
/// parameter to for `buyERC1155`.
|
||||
/// @param revertIfIncomplete If true, reverts if this
|
||||
/// function fails to fill any individual order.
|
||||
/// @return successes An array of booleans corresponding to whether
|
||||
/// each order in `orders` was successfully filled.
|
||||
function batchBuyERC1155s(
|
||||
LibNFTOrder.ERC1155Order[] memory sellOrders,
|
||||
LibSignature.Signature[] memory signatures,
|
||||
uint128[] calldata erc1155FillAmounts,
|
||||
bytes[] memory callbackData,
|
||||
bool revertIfIncomplete
|
||||
)
|
||||
public
|
||||
override
|
||||
payable
|
||||
returns (bool[] memory successes)
|
||||
{
|
||||
require(
|
||||
sellOrders.length == signatures.length &&
|
||||
sellOrders.length == erc1155FillAmounts.length &&
|
||||
sellOrders.length == callbackData.length,
|
||||
"ERC1155OrdersFeature::batchBuyERC1155s/ARRAY_LENGTH_MISMATCH"
|
||||
);
|
||||
successes = new bool[](sellOrders.length);
|
||||
|
||||
uint256 ethBalanceBefore = address(this).balance
|
||||
.safeSub(msg.value);
|
||||
if (revertIfIncomplete) {
|
||||
for (uint256 i = 0; i < sellOrders.length; i++) {
|
||||
// Will revert if _buyERC1155 reverts.
|
||||
_buyERC1155(
|
||||
sellOrders[i],
|
||||
signatures[i],
|
||||
BuyParams(
|
||||
erc1155FillAmounts[i],
|
||||
address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available
|
||||
callbackData[i]
|
||||
)
|
||||
);
|
||||
successes[i] = true;
|
||||
}
|
||||
} else {
|
||||
for (uint256 i = 0; i < sellOrders.length; i++) {
|
||||
// Delegatecall `_buyERC1155` to catch swallow reverts while
|
||||
// preserving execution context.
|
||||
// Note that `_buyERC1155` is a public function but should _not_
|
||||
// be registered in the Exchange Proxy.
|
||||
(successes[i], ) = _implementation.delegatecall(
|
||||
abi.encodeWithSelector(
|
||||
this._buyERC1155.selector,
|
||||
sellOrders[i],
|
||||
signatures[i],
|
||||
BuyParams(
|
||||
erc1155FillAmounts[i],
|
||||
address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available
|
||||
callbackData[i]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot use pre-existing ETH balance
|
||||
uint256 ethBalanceAfter = address(this).balance;
|
||||
if (ethBalanceAfter < ethBalanceBefore) {
|
||||
LibNFTOrdersRichErrors.OverspentEthError(
|
||||
msg.value + (ethBalanceBefore - ethBalanceAfter),
|
||||
msg.value
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Refund
|
||||
_transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore);
|
||||
}
|
||||
|
||||
/// @dev Callback for the ERC1155 `safeTransferFrom` function.
|
||||
/// This callback can be used to sell an ERC1155 asset if
|
||||
/// a valid ERC1155 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`. This allows takers to sell their
|
||||
/// ERC1155 asset without first calling `setApprovalForAll`.
|
||||
/// @param operator The address which called `safeTransferFrom`.
|
||||
/// @param tokenId The ID of the asset being transferred.
|
||||
/// @param value The amount being transferred.
|
||||
/// @param data Additional data with no specified format. If a
|
||||
/// valid ERC1155 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`, this function will try to fill
|
||||
/// the order using the received asset.
|
||||
/// @return success The selector of this function (0xf23a6e61),
|
||||
/// indicating that the callback succeeded.
|
||||
function onERC1155Received(
|
||||
address operator,
|
||||
address /* from */,
|
||||
uint256 tokenId,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
)
|
||||
external
|
||||
override
|
||||
returns (bytes4 success)
|
||||
{
|
||||
// Decode the order, signature, and `unwrapNativeToken` from
|
||||
// `data`. If `data` does not encode such parameters, this
|
||||
// will throw.
|
||||
(
|
||||
LibNFTOrder.ERC1155Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
bool unwrapNativeToken
|
||||
) = abi.decode(
|
||||
data,
|
||||
(LibNFTOrder.ERC1155Order, LibSignature.Signature, bool)
|
||||
);
|
||||
|
||||
// `onERC1155Received` is called by the ERC1155 token contract.
|
||||
// Check that it matches the ERC1155 token in the order.
|
||||
if (msg.sender != address(buyOrder.erc1155Token)) {
|
||||
LibNFTOrdersRichErrors.ERC1155TokenMismatchError(
|
||||
msg.sender,
|
||||
address(buyOrder.erc1155Token)
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
_sellERC1155(
|
||||
buyOrder,
|
||||
signature,
|
||||
SellParams(
|
||||
value.safeDowncastToUint128(),
|
||||
tokenId,
|
||||
unwrapNativeToken,
|
||||
operator, // taker
|
||||
address(this), // owner (we hold the NFT currently)
|
||||
new bytes(0) // No taker callback
|
||||
)
|
||||
);
|
||||
|
||||
return ERC1155_RECEIVED_MAGIC_BYTES;
|
||||
}
|
||||
|
||||
/// @dev Approves an ERC1155 order on-chain. After pre-signing
|
||||
/// the order, the `PRESIGNED` signature type will become
|
||||
/// valid for that order and signer.
|
||||
/// @param order An ERC1155 order.
|
||||
function preSignERC1155Order(LibNFTOrder.ERC1155Order memory order)
|
||||
public
|
||||
override
|
||||
{
|
||||
require(
|
||||
order.maker == msg.sender,
|
||||
"ERC1155OrdersFeature::preSignERC1155Order/MAKER_MISMATCH"
|
||||
);
|
||||
bytes32 orderHash = getERC1155OrderHash(order);
|
||||
|
||||
LibERC1155OrdersStorage.Storage storage stor =
|
||||
LibERC1155OrdersStorage.getStorage();
|
||||
// Set `preSigned` to true on the order state variable
|
||||
// to indicate that the order has been pre-signed.
|
||||
stor.orderState[orderHash].preSigned = true;
|
||||
|
||||
emit ERC1155OrderPreSigned(
|
||||
order.direction,
|
||||
order.maker,
|
||||
order.taker,
|
||||
order.expiry,
|
||||
order.nonce,
|
||||
order.erc20Token,
|
||||
order.erc20TokenAmount,
|
||||
order.fees,
|
||||
order.erc1155Token,
|
||||
order.erc1155TokenId,
|
||||
order.erc1155TokenProperties,
|
||||
order.erc1155TokenAmount
|
||||
);
|
||||
}
|
||||
|
||||
// Core settlement logic for selling an ERC1155 asset.
|
||||
// Used by `sellERC1155` and `onERC1155Received`.
|
||||
function _sellERC1155(
|
||||
LibNFTOrder.ERC1155Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
SellParams memory params
|
||||
)
|
||||
private
|
||||
{
|
||||
uint256 erc20FillAmount = _sellNFT(
|
||||
buyOrder.asNFTOrder(),
|
||||
signature,
|
||||
params
|
||||
);
|
||||
|
||||
emit ERC1155OrderFilled(
|
||||
buyOrder.direction,
|
||||
buyOrder.maker,
|
||||
params.taker,
|
||||
buyOrder.nonce,
|
||||
buyOrder.erc20Token,
|
||||
erc20FillAmount,
|
||||
buyOrder.erc1155Token,
|
||||
params.tokenId,
|
||||
params.sellAmount,
|
||||
address(0)
|
||||
);
|
||||
}
|
||||
|
||||
// Core settlement logic for buying an ERC1155 asset.
|
||||
// Used by `buyERC1155` and `batchBuyERC1155s`.
|
||||
function _buyERC1155(
|
||||
LibNFTOrder.ERC1155Order memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
BuyParams memory params
|
||||
)
|
||||
public
|
||||
payable
|
||||
{
|
||||
uint256 erc20FillAmount = _buyNFT(
|
||||
sellOrder.asNFTOrder(),
|
||||
signature,
|
||||
params
|
||||
);
|
||||
|
||||
emit ERC1155OrderFilled(
|
||||
sellOrder.direction,
|
||||
sellOrder.maker,
|
||||
msg.sender,
|
||||
sellOrder.nonce,
|
||||
sellOrder.erc20Token,
|
||||
erc20FillAmount,
|
||||
sellOrder.erc1155Token,
|
||||
sellOrder.erc1155TokenId,
|
||||
params.buyAmount,
|
||||
address(0)
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Checks whether the given signature is valid for the
|
||||
/// the given ERC1155 order. Reverts if not.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @param signature The signature to validate.
|
||||
function validateERC1155OrderSignature(
|
||||
LibNFTOrder.ERC1155Order memory order,
|
||||
LibSignature.Signature memory signature
|
||||
)
|
||||
public
|
||||
override
|
||||
view
|
||||
{
|
||||
bytes32 orderHash = getERC1155OrderHash(order);
|
||||
_validateOrderSignature(orderHash, signature, order.maker);
|
||||
}
|
||||
|
||||
/// @dev Validates that the given signature is valid for the
|
||||
/// given maker and order hash. Reverts if the signature
|
||||
/// is not valid.
|
||||
/// @param orderHash The hash of the order that was signed.
|
||||
/// @param signature The signature to check.
|
||||
/// @param maker The maker of the order.
|
||||
function _validateOrderSignature(
|
||||
bytes32 orderHash,
|
||||
LibSignature.Signature memory signature,
|
||||
address maker
|
||||
)
|
||||
internal
|
||||
override
|
||||
view
|
||||
{
|
||||
if (signature.signatureType == LibSignature.SignatureType.PRESIGNED) {
|
||||
// Check if order hash has been pre-signed by the maker.
|
||||
bool isPreSigned = LibERC1155OrdersStorage.getStorage()
|
||||
.orderState[orderHash].preSigned;
|
||||
if (!isPreSigned) {
|
||||
LibNFTOrdersRichErrors.InvalidSignerError(maker, address(0)).rrevert();
|
||||
}
|
||||
} else {
|
||||
address signer = LibSignature.getSignerOfHash(orderHash, signature);
|
||||
if (signer != maker) {
|
||||
LibNFTOrdersRichErrors.InvalidSignerError(maker, signer).rrevert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Transfers an NFT asset.
|
||||
/// @param token The address of the NFT contract.
|
||||
/// @param from The address currently holding the asset.
|
||||
/// @param to The address to transfer the asset to.
|
||||
/// @param tokenId The ID of the asset to transfer.
|
||||
/// @param amount The amount of the asset to transfer. Always
|
||||
/// 1 for ERC721 assets.
|
||||
function _transferNFTAssetFrom(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
override
|
||||
{
|
||||
_transferERC1155AssetFrom(IERC1155Token(token), from, to, tokenId, amount);
|
||||
}
|
||||
|
||||
/// @dev Updates storage to indicate that the given order
|
||||
/// has been filled by the given amount.
|
||||
/// @param orderHash The hash of `order`.
|
||||
/// @param fillAmount The amount (denominated in the NFT asset)
|
||||
/// that the order has been filled by.
|
||||
function _updateOrderState(
|
||||
LibNFTOrder.NFTOrder memory /* order */,
|
||||
bytes32 orderHash,
|
||||
uint128 fillAmount
|
||||
)
|
||||
internal
|
||||
override
|
||||
{
|
||||
LibERC1155OrdersStorage.Storage storage stor = LibERC1155OrdersStorage.getStorage();
|
||||
uint128 filledAmount = stor.orderState[orderHash].filledAmount;
|
||||
// Filled amount should never overflow 128 bits
|
||||
assert(filledAmount + fillAmount > filledAmount);
|
||||
stor.orderState[orderHash].filledAmount = filledAmount + fillAmount;
|
||||
}
|
||||
|
||||
/// @dev If the given order is buying an ERC1155 asset, checks
|
||||
/// whether or not the given token ID satisfies the required
|
||||
/// properties specified in the order. If the order does not
|
||||
/// specify any properties, this function instead checks
|
||||
/// whether the given token ID matches the ID in the order.
|
||||
/// Reverts if any checks fail, or if the order is selling
|
||||
/// an ERC1155 asset.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @param erc1155TokenId The ID of the ERC1155 asset.
|
||||
function validateERC1155OrderProperties(
|
||||
LibNFTOrder.ERC1155Order memory order,
|
||||
uint256 erc1155TokenId
|
||||
)
|
||||
public
|
||||
override
|
||||
view
|
||||
{
|
||||
_validateOrderProperties(
|
||||
order.asNFTOrder(),
|
||||
erc1155TokenId
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Get the order info for an ERC1155 order.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @return orderInfo Info about the order.
|
||||
function getERC1155OrderInfo(LibNFTOrder.ERC1155Order memory order)
|
||||
public
|
||||
override
|
||||
view
|
||||
returns (LibNFTOrder.OrderInfo memory orderInfo)
|
||||
{
|
||||
orderInfo.orderAmount = order.erc1155TokenAmount;
|
||||
orderInfo.orderHash = getERC1155OrderHash(order);
|
||||
|
||||
// Only buy orders with `erc1155TokenId` == 0 can be property
|
||||
// orders.
|
||||
if (order.erc1155TokenProperties.length > 0 &&
|
||||
(order.direction != LibNFTOrder.TradeDirection.BUY_NFT ||
|
||||
order.erc1155TokenId != 0))
|
||||
{
|
||||
orderInfo.status = LibNFTOrder.OrderStatus.INVALID;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// Buy orders cannot use ETH as the ERC20 token, since ETH cannot be
|
||||
// transferred from the buyer by a contract.
|
||||
if (order.direction == LibNFTOrder.TradeDirection.BUY_NFT &&
|
||||
address(order.erc20Token) == NATIVE_TOKEN_ADDRESS)
|
||||
{
|
||||
orderInfo.status = LibNFTOrder.OrderStatus.INVALID;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// Check for expiry.
|
||||
if (order.expiry <= block.timestamp) {
|
||||
orderInfo.status = LibNFTOrder.OrderStatus.EXPIRED;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
{
|
||||
LibERC1155OrdersStorage.Storage storage stor =
|
||||
LibERC1155OrdersStorage.getStorage();
|
||||
|
||||
LibERC1155OrdersStorage.OrderState storage orderState =
|
||||
stor.orderState[orderInfo.orderHash];
|
||||
orderInfo.remainingAmount = order.erc1155TokenAmount
|
||||
.safeSub128(orderState.filledAmount);
|
||||
|
||||
// `orderCancellationByMaker` is indexed by maker and nonce.
|
||||
uint256 orderCancellationBitVector =
|
||||
stor.orderCancellationByMaker[order.maker][uint248(order.nonce >> 8)];
|
||||
// The bitvector is indexed by the lower 8 bits of the nonce.
|
||||
uint256 flag = 1 << (order.nonce & 255);
|
||||
|
||||
if (orderInfo.remainingAmount == 0 ||
|
||||
orderCancellationBitVector & flag != 0)
|
||||
{
|
||||
orderInfo.status = LibNFTOrder.OrderStatus.UNFILLABLE;
|
||||
return orderInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, the order is fillable.
|
||||
orderInfo.status = LibNFTOrder.OrderStatus.FILLABLE;
|
||||
}
|
||||
|
||||
/// @dev Get the order info for an NFT order.
|
||||
/// @param order The NFT order.
|
||||
/// @return orderInfo Info about the order.
|
||||
function _getOrderInfo(LibNFTOrder.NFTOrder memory order)
|
||||
internal
|
||||
override
|
||||
view
|
||||
returns (LibNFTOrder.OrderInfo memory orderInfo)
|
||||
{
|
||||
return getERC1155OrderInfo(order.asERC1155Order());
|
||||
}
|
||||
|
||||
/// @dev Get the EIP-712 hash of an ERC1155 order.
|
||||
/// @param order The ERC1155 order.
|
||||
/// @return orderHash The order hash.
|
||||
function getERC1155OrderHash(LibNFTOrder.ERC1155Order memory order)
|
||||
public
|
||||
override
|
||||
view
|
||||
returns (bytes32 orderHash)
|
||||
{
|
||||
return _getEIP712Hash(LibNFTOrder.getERC1155OrderStructHash(order));
|
||||
}
|
||||
}
|
@@ -0,0 +1,931 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../../fixins/FixinERC721Spender.sol";
|
||||
import "../../migrations/LibMigrate.sol";
|
||||
import "../../storage/LibERC721OrdersStorage.sol";
|
||||
import "../interfaces/IFeature.sol";
|
||||
import "../interfaces/IERC721OrdersFeature.sol";
|
||||
import "../libs/LibNFTOrder.sol";
|
||||
import "../libs/LibSignature.sol";
|
||||
import "./NFTOrders.sol";
|
||||
|
||||
|
||||
/// @dev Feature for interacting with ERC721 orders.
|
||||
contract ERC721OrdersFeature is
|
||||
IFeature,
|
||||
IERC721OrdersFeature,
|
||||
FixinERC721Spender,
|
||||
NFTOrders
|
||||
{
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibNFTOrder for LibNFTOrder.ERC721Order;
|
||||
using LibNFTOrder for LibNFTOrder.NFTOrder;
|
||||
|
||||
/// @dev Name of this feature.
|
||||
string public constant override FEATURE_NAME = "ERC721Orders";
|
||||
/// @dev Version of this feature.
|
||||
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
|
||||
|
||||
/// @dev The magic return value indicating the success of a `onERC721Received`.
|
||||
bytes4 private constant ERC721_RECEIVED_MAGIC_BYTES = this.onERC721Received.selector;
|
||||
|
||||
|
||||
constructor(address zeroExAddress, IEtherTokenV06 weth)
|
||||
public
|
||||
NFTOrders(zeroExAddress, weth)
|
||||
{}
|
||||
|
||||
/// @dev Initialize and register this feature.
|
||||
/// Should be delegatecalled by `Migrate.migrate()`.
|
||||
/// @return success `LibMigrate.SUCCESS` on success.
|
||||
function migrate()
|
||||
external
|
||||
returns (bytes4 success)
|
||||
{
|
||||
_registerFeatureFunction(this.sellERC721.selector);
|
||||
_registerFeatureFunction(this.buyERC721.selector);
|
||||
_registerFeatureFunction(this.cancelERC721Order.selector);
|
||||
_registerFeatureFunction(this.batchBuyERC721s.selector);
|
||||
_registerFeatureFunction(this.matchERC721Orders.selector);
|
||||
_registerFeatureFunction(this.batchMatchERC721Orders.selector);
|
||||
_registerFeatureFunction(this.onERC721Received.selector);
|
||||
_registerFeatureFunction(this.preSignERC721Order.selector);
|
||||
_registerFeatureFunction(this.validateERC721OrderSignature.selector);
|
||||
_registerFeatureFunction(this.validateERC721OrderProperties.selector);
|
||||
_registerFeatureFunction(this.getERC721OrderStatus.selector);
|
||||
_registerFeatureFunction(this.getERC721OrderHash.selector);
|
||||
_registerFeatureFunction(this.getERC721OrderStatusBitVector.selector);
|
||||
return LibMigrate.MIGRATE_SUCCESS;
|
||||
}
|
||||
|
||||
/// @dev Sells an ERC721 asset to fill the given order.
|
||||
/// @param buyOrder The ERC721 buy order.
|
||||
/// @param signature The order signature from the maker.
|
||||
/// @param erc721TokenId The ID of the ERC721 asset being
|
||||
/// sold. If the given order specifies properties,
|
||||
/// the asset must satisfy those properties. Otherwise,
|
||||
/// it must equal the tokenId in the order.
|
||||
/// @param unwrapNativeToken If this parameter is true and the
|
||||
/// ERC20 token of the order is e.g. WETH, unwraps the
|
||||
/// token before transferring it to the taker.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC721OrderCallback` on `msg.sender` after
|
||||
/// the ERC20 tokens have been transferred to `msg.sender`
|
||||
/// but before transferring the ERC721 asset to the buyer.
|
||||
function sellERC721(
|
||||
LibNFTOrder.ERC721Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
uint256 erc721TokenId,
|
||||
bool unwrapNativeToken,
|
||||
bytes memory callbackData
|
||||
)
|
||||
public
|
||||
override
|
||||
{
|
||||
_sellERC721(
|
||||
buyOrder,
|
||||
signature,
|
||||
erc721TokenId,
|
||||
unwrapNativeToken,
|
||||
msg.sender, // taker
|
||||
msg.sender, // owner
|
||||
callbackData
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Buys an ERC721 asset by filling the given order.
|
||||
/// @param sellOrder The ERC721 sell order.
|
||||
/// @param signature The order signature.
|
||||
/// @param callbackData If this parameter is non-zero, invokes
|
||||
/// `zeroExERC721OrderCallback` on `msg.sender` after
|
||||
/// the ERC721 asset has been transferred to `msg.sender`
|
||||
/// but before transferring the ERC20 tokens to the seller.
|
||||
/// Native tokens acquired during the callback can be used
|
||||
/// to fill the order.
|
||||
function buyERC721(
|
||||
LibNFTOrder.ERC721Order memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
bytes memory callbackData
|
||||
)
|
||||
public
|
||||
override
|
||||
payable
|
||||
{
|
||||
uint256 ethBalanceBefore = address(this).balance
|
||||
.safeSub(msg.value);
|
||||
_buyERC721(
|
||||
sellOrder,
|
||||
signature,
|
||||
msg.value,
|
||||
callbackData
|
||||
);
|
||||
uint256 ethBalanceAfter = address(this).balance;
|
||||
// Cannot use pre-existing ETH balance
|
||||
if (ethBalanceAfter < ethBalanceBefore) {
|
||||
LibNFTOrdersRichErrors.OverspentEthError(
|
||||
msg.value + (ethBalanceBefore - ethBalanceAfter),
|
||||
msg.value
|
||||
).rrevert();
|
||||
}
|
||||
// Refund
|
||||
_transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore);
|
||||
}
|
||||
|
||||
/// @dev Cancel a single ERC721 order by its nonce. The caller
|
||||
/// should be the maker of the order. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonce The order nonce.
|
||||
function cancelERC721Order(uint256 orderNonce)
|
||||
public
|
||||
override
|
||||
{
|
||||
// Mark order as cancelled
|
||||
_setOrderStatusBit(msg.sender, orderNonce);
|
||||
emit ERC721OrderCancelled(msg.sender, orderNonce);
|
||||
}
|
||||
|
||||
/// @dev Cancel multiple ERC721 orders by their nonces. The caller
|
||||
/// should be the maker of the orders. Silently succeeds if
|
||||
/// an order with the same nonce has already been filled or
|
||||
/// cancelled.
|
||||
/// @param orderNonces The order nonces.
|
||||
function batchCancelERC721Orders(uint256[] calldata orderNonces)
|
||||
external
|
||||
override
|
||||
{
|
||||
for (uint256 i = 0; i < orderNonces.length; i++) {
|
||||
cancelERC721Order(orderNonces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Buys multiple ERC721 assets by filling the
|
||||
/// given orders.
|
||||
/// @param sellOrders The ERC721 sell orders.
|
||||
/// @param signatures The order signatures.
|
||||
/// @param revertIfIncomplete If true, reverts if this
|
||||
/// function fails to fill any individual order.
|
||||
/// @param callbackData The data (if any) to pass to the taker
|
||||
/// callback for each order. Refer to the `callbackData`
|
||||
/// parameter to for `buyERC721`.
|
||||
/// @return successes An array of booleans corresponding to whether
|
||||
/// each order in `orders` was successfully filled.
|
||||
function batchBuyERC721s(
|
||||
LibNFTOrder.ERC721Order[] memory sellOrders,
|
||||
LibSignature.Signature[] memory signatures,
|
||||
bytes[] memory callbackData,
|
||||
bool revertIfIncomplete
|
||||
)
|
||||
public
|
||||
override
|
||||
payable
|
||||
returns (bool[] memory successes)
|
||||
{
|
||||
require(
|
||||
sellOrders.length == signatures.length &&
|
||||
sellOrders.length == callbackData.length,
|
||||
"ERC721OrdersFeature::batchBuyERC721s/ARRAY_LENGTH_MISMATCH"
|
||||
);
|
||||
successes = new bool[](sellOrders.length);
|
||||
|
||||
uint256 ethBalanceBefore = address(this).balance
|
||||
.safeSub(msg.value);
|
||||
if (revertIfIncomplete) {
|
||||
for (uint256 i = 0; i < sellOrders.length; i++) {
|
||||
// Will revert if _buyERC721 reverts.
|
||||
_buyERC721(
|
||||
sellOrders[i],
|
||||
signatures[i],
|
||||
address(this).balance.safeSub(ethBalanceBefore),
|
||||
callbackData[i]
|
||||
);
|
||||
successes[i] = true;
|
||||
}
|
||||
} else {
|
||||
for (uint256 i = 0; i < sellOrders.length; i++) {
|
||||
// Delegatecall `_buyERC721` to swallow reverts while
|
||||
// preserving execution context.
|
||||
// Note that `_buyERC721` is a public function but should _not_
|
||||
// be registered in the Exchange Proxy.
|
||||
(successes[i], ) = _implementation.delegatecall(
|
||||
abi.encodeWithSelector(
|
||||
this._buyERC721.selector,
|
||||
sellOrders[i],
|
||||
signatures[i],
|
||||
address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available
|
||||
callbackData[i]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Cannot use pre-existing ETH balance
|
||||
uint256 ethBalanceAfter = address(this).balance;
|
||||
if (ethBalanceAfter < ethBalanceBefore) {
|
||||
LibNFTOrdersRichErrors.OverspentEthError(
|
||||
msg.value + (ethBalanceBefore - ethBalanceAfter),
|
||||
msg.value
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Refund
|
||||
_transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore);
|
||||
}
|
||||
|
||||
/// @dev Matches a pair of complementary orders that have
|
||||
/// a non-negative spread. Each order is filled at
|
||||
/// their respective price, and the matcher receives
|
||||
/// a profit denominated in the ERC20 token.
|
||||
/// @param sellOrder Order selling an ERC721 asset.
|
||||
/// @param buyOrder Order buying an ERC721 asset.
|
||||
/// @param sellOrderSignature Signature for the sell order.
|
||||
/// @param buyOrderSignature Signature for the buy order.
|
||||
/// @return profit The amount of profit earned by the caller
|
||||
/// of this function (denominated in the ERC20 token
|
||||
/// of the matched orders).
|
||||
function matchERC721Orders(
|
||||
LibNFTOrder.ERC721Order memory sellOrder,
|
||||
LibNFTOrder.ERC721Order memory buyOrder,
|
||||
LibSignature.Signature memory sellOrderSignature,
|
||||
LibSignature.Signature memory buyOrderSignature
|
||||
)
|
||||
public
|
||||
override
|
||||
returns (uint256 profit)
|
||||
{
|
||||
// The ERC721 tokens must match
|
||||
if (sellOrder.erc721Token != buyOrder.erc721Token) {
|
||||
LibNFTOrdersRichErrors.ERC721TokenMismatchError(
|
||||
address(sellOrder.erc721Token),
|
||||
address(buyOrder.erc721Token)
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
LibNFTOrder.NFTOrder memory sellNFTOrder = sellOrder.asNFTOrder();
|
||||
LibNFTOrder.NFTOrder memory buyNFTOrder = buyOrder.asNFTOrder();
|
||||
|
||||
{
|
||||
LibNFTOrder.OrderInfo memory sellOrderInfo = _getOrderInfo(sellNFTOrder);
|
||||
LibNFTOrder.OrderInfo memory buyOrderInfo = _getOrderInfo(buyNFTOrder);
|
||||
|
||||
_validateSellOrder(
|
||||
sellNFTOrder,
|
||||
sellOrderSignature,
|
||||
sellOrderInfo,
|
||||
buyOrder.maker
|
||||
);
|
||||
_validateBuyOrder(
|
||||
buyNFTOrder,
|
||||
buyOrderSignature,
|
||||
buyOrderInfo,
|
||||
sellOrder.maker,
|
||||
sellOrder.erc721TokenId
|
||||
);
|
||||
|
||||
// Mark both orders as filled.
|
||||
_updateOrderState(sellNFTOrder, sellOrderInfo.orderHash, 1);
|
||||
_updateOrderState(buyNFTOrder, buyOrderInfo.orderHash, 1);
|
||||
}
|
||||
|
||||
// The buyer must be willing to pay at least the amount that the
|
||||
// seller is asking.
|
||||
if (buyOrder.erc20TokenAmount < sellOrder.erc20TokenAmount) {
|
||||
LibNFTOrdersRichErrors.NegativeSpreadError(
|
||||
sellOrder.erc20TokenAmount,
|
||||
buyOrder.erc20TokenAmount
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// The difference in ERC20 token amounts is the spread.
|
||||
uint256 spread = buyOrder.erc20TokenAmount - sellOrder.erc20TokenAmount;
|
||||
|
||||
// Transfer the ERC721 asset from seller to buyer.
|
||||
_transferERC721AssetFrom(
|
||||
sellOrder.erc721Token,
|
||||
sellOrder.maker,
|
||||
buyOrder.maker,
|
||||
sellOrder.erc721TokenId
|
||||
);
|
||||
|
||||
// Handle the ERC20 side of the order:
|
||||
if (
|
||||
address(sellOrder.erc20Token) == NATIVE_TOKEN_ADDRESS &&
|
||||
buyOrder.erc20Token == WETH
|
||||
) {
|
||||
// The sell order specifies ETH, while the buy order specifies WETH.
|
||||
// The orders are still compatible with one another, but we'll have
|
||||
// to unwrap the WETH on behalf of the buyer.
|
||||
|
||||
// Step 1: Transfer WETH from the buyer to the EP.
|
||||
// Note that we transfer `buyOrder.erc20TokenAmount`, which
|
||||
// is the amount the buyer signaled they are willing to pay
|
||||
// for the ERC721 asset, which may be more than the seller's
|
||||
// ask.
|
||||
_transferERC20TokensFrom(
|
||||
WETH,
|
||||
buyOrder.maker,
|
||||
address(this),
|
||||
buyOrder.erc20TokenAmount
|
||||
);
|
||||
// Step 2: Unwrap the WETH into ETH. We unwrap the entire
|
||||
// `buyOrder.erc20TokenAmount`.
|
||||
// The ETH will be used for three purposes:
|
||||
// - To pay the seller
|
||||
// - To pay fees for the sell order
|
||||
// - Any remaining ETH will be sent to
|
||||
// `msg.sender` as profit.
|
||||
WETH.withdraw(buyOrder.erc20TokenAmount);
|
||||
|
||||
// Step 3: Pay the seller (in ETH).
|
||||
_transferEth(payable(sellOrder.maker), sellOrder.erc20TokenAmount);
|
||||
|
||||
// Step 4: Pay fees for the buy order. Note that these are paid
|
||||
// in _WETH_ by the _buyer_. By signing the buy order, the
|
||||
// buyer signals that they are willing to spend a total
|
||||
// of `erc20TokenAmount` _plus_ fees, all denominated in
|
||||
// the `erc20Token`, which in this case is WETH.
|
||||
_payFees(
|
||||
buyNFTOrder,
|
||||
buyOrder.maker, // payer
|
||||
1, // fillAmount
|
||||
1, // orderAmount
|
||||
false // useNativeToken
|
||||
);
|
||||
|
||||
// Step 5: Pay fees for the sell order. The `erc20Token` of the
|
||||
// sell order is ETH, so the fees are paid out in ETH.
|
||||
// There should be `spread` wei of ETH remaining in the
|
||||
// EP at this point, which we will use ETH to pay the
|
||||
// sell order fees.
|
||||
uint256 sellOrderFees = _payFees(
|
||||
sellNFTOrder,
|
||||
address(this), // payer
|
||||
1, // fillAmount
|
||||
1, // orderAmount
|
||||
true // useNativeToken
|
||||
);
|
||||
|
||||
// Step 6: The spread must be enough to cover the sell order fees.
|
||||
// If not, either `_payFees` will have reverted, or we
|
||||
// have spent ETH that was in the EP before this
|
||||
// `matchERC721Orders` call, which we disallow.
|
||||
if (spread < sellOrderFees) {
|
||||
LibNFTOrdersRichErrors.SellOrderFeesExceedSpreadError(
|
||||
sellOrderFees,
|
||||
spread
|
||||
).rrevert();
|
||||
}
|
||||
// Step 7: The spread less the sell order fees is the amount of ETH
|
||||
// remaining in the EP that can be sent to `msg.sender` as
|
||||
// the profit from matching these two orders.
|
||||
profit = spread - sellOrderFees;
|
||||
if (profit > 0) {
|
||||
_transferEth(msg.sender, profit);
|
||||
}
|
||||
} else {
|
||||
// ERC20 tokens must match
|
||||
if (sellOrder.erc20Token != buyOrder.erc20Token) {
|
||||
LibNFTOrdersRichErrors.ERC20TokenMismatchError(
|
||||
address(sellOrder.erc20Token),
|
||||
address(buyOrder.erc20Token)
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Step 1: Transfer the ERC20 token from the buyer to the seller.
|
||||
// Note that we transfer `sellOrder.erc20TokenAmount`, which
|
||||
// is at most `buyOrder.erc20TokenAmount`.
|
||||
_transferERC20TokensFrom(
|
||||
buyOrder.erc20Token,
|
||||
buyOrder.maker,
|
||||
sellOrder.maker,
|
||||
sellOrder.erc20TokenAmount
|
||||
);
|
||||
|
||||
// Step 2: Pay fees for the buy order. Note that these are paid
|
||||
// by the buyer. By signing the buy order, the buyer signals
|
||||
// that they are willing to spend a total of
|
||||
// `buyOrder.erc20TokenAmount` _plus_ `buyOrder.fees`.
|
||||
_payFees(
|
||||
buyNFTOrder,
|
||||
buyOrder.maker, // payer
|
||||
1, // fillAmount
|
||||
1, // orderAmount
|
||||
false // useNativeToken
|
||||
);
|
||||
|
||||
// Step 3: Pay fees for the sell order. These are paid by the buyer
|
||||
// as well. After paying these fees, we may have taken more
|
||||
// from the buyer than they agreed to in the buy order. If
|
||||
// so, we revert in the following step.
|
||||
uint256 sellOrderFees = _payFees(
|
||||
sellNFTOrder,
|
||||
buyOrder.maker, // payer
|
||||
1, // fillAmount
|
||||
1, // orderAmount
|
||||
false // useNativeToken
|
||||
);
|
||||
|
||||
// Step 4: The spread must be enough to cover the sell order fees.
|
||||
// If not, `_payFees` will have taken more tokens from the
|
||||
// buyer than they had agreed to in the buy order, in which
|
||||
// case we revert here.
|
||||
if (spread < sellOrderFees) {
|
||||
LibNFTOrdersRichErrors.SellOrderFeesExceedSpreadError(
|
||||
sellOrderFees,
|
||||
spread
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Step 5: We calculate the profit as:
|
||||
// profit = buyOrder.erc20TokenAmount - sellOrder.erc20TokenAmount - sellOrderFees
|
||||
// = spread - sellOrderFees
|
||||
// I.e. the buyer would've been willing to pay up to `profit`
|
||||
// more to buy the asset, so instead that amount is sent to
|
||||
// `msg.sender` as the profit from matching these two orders.
|
||||
profit = spread - sellOrderFees;
|
||||
if (profit > 0) {
|
||||
_transferERC20TokensFrom(
|
||||
buyOrder.erc20Token,
|
||||
buyOrder.maker,
|
||||
msg.sender,
|
||||
profit
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
emit ERC721OrderFilled(
|
||||
sellOrder.direction,
|
||||
sellOrder.maker,
|
||||
buyOrder.maker, // taker
|
||||
sellOrder.nonce,
|
||||
sellOrder.erc20Token,
|
||||
sellOrder.erc20TokenAmount,
|
||||
sellOrder.erc721Token,
|
||||
sellOrder.erc721TokenId,
|
||||
msg.sender
|
||||
);
|
||||
|
||||
emit ERC721OrderFilled(
|
||||
buyOrder.direction,
|
||||
buyOrder.maker,
|
||||
sellOrder.maker, // taker
|
||||
buyOrder.nonce,
|
||||
buyOrder.erc20Token,
|
||||
buyOrder.erc20TokenAmount,
|
||||
buyOrder.erc721Token,
|
||||
sellOrder.erc721TokenId,
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Matches pairs of complementary orders that have
|
||||
/// non-negative spreads. Each order is filled at
|
||||
/// their respective price, and the matcher receives
|
||||
/// a profit denominated in the ERC20 token.
|
||||
/// @param sellOrders Orders selling ERC721 assets.
|
||||
/// @param buyOrders Orders buying ERC721 assets.
|
||||
/// @param sellOrderSignatures Signatures for the sell orders.
|
||||
/// @param buyOrderSignatures Signatures for the buy orders.
|
||||
/// @return profits The amount of profit earned by the caller
|
||||
/// of this function for each pair of matched orders
|
||||
/// (denominated in the ERC20 token of the order pair).
|
||||
/// @return successes An array of booleans corresponding to
|
||||
/// whether each pair of orders was successfully matched.
|
||||
function batchMatchERC721Orders(
|
||||
LibNFTOrder.ERC721Order[] memory sellOrders,
|
||||
LibNFTOrder.ERC721Order[] memory buyOrders,
|
||||
LibSignature.Signature[] memory sellOrderSignatures,
|
||||
LibSignature.Signature[] memory buyOrderSignatures
|
||||
)
|
||||
public
|
||||
override
|
||||
returns (uint256[] memory profits, bool[] memory successes)
|
||||
{
|
||||
require(
|
||||
sellOrders.length == buyOrders.length &&
|
||||
sellOrderSignatures.length == buyOrderSignatures.length &&
|
||||
sellOrders.length == sellOrderSignatures.length,
|
||||
"ERC721OrdersFeature::batchMatchERC721Orders/ARRAY_LENGTH_MISMATCH"
|
||||
);
|
||||
profits = new uint256[](sellOrders.length);
|
||||
successes = new bool[](sellOrders.length);
|
||||
|
||||
for (uint256 i = 0; i < sellOrders.length; i++) {
|
||||
bytes memory returnData;
|
||||
// Delegatecall `matchERC721Orders` to catch reverts while
|
||||
// preserving execution context.
|
||||
(successes[i], returnData) = _implementation.delegatecall(
|
||||
abi.encodeWithSelector(
|
||||
this.matchERC721Orders.selector,
|
||||
sellOrders[i],
|
||||
buyOrders[i],
|
||||
sellOrderSignatures[i],
|
||||
buyOrderSignatures[i]
|
||||
)
|
||||
);
|
||||
if (successes[i]) {
|
||||
// If the matching succeeded, record the profit.
|
||||
(uint256 profit) = abi.decode(returnData, (uint256));
|
||||
profits[i] = profit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Callback for the ERC721 `safeTransferFrom` function.
|
||||
/// This callback can be used to sell an ERC721 asset if
|
||||
/// a valid ERC721 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`. This allows takers to sell their
|
||||
/// ERC721 asset without first calling `setApprovalForAll`.
|
||||
/// @param operator The address which called `safeTransferFrom`.
|
||||
/// @param tokenId The ID of the asset being transferred.
|
||||
/// @param data Additional data with no specified format. If a
|
||||
/// valid ERC721 order, signature and `unwrapNativeToken`
|
||||
/// are encoded in `data`, this function will try to fill
|
||||
/// the order using the received asset.
|
||||
/// @return success The selector of this function (0x150b7a02),
|
||||
/// indicating that the callback succeeded.
|
||||
function onERC721Received(
|
||||
address operator,
|
||||
address /* from */,
|
||||
uint256 tokenId,
|
||||
bytes calldata data
|
||||
)
|
||||
external
|
||||
override
|
||||
returns (bytes4 success)
|
||||
{
|
||||
// Decode the order, signature, and `unwrapNativeToken` from
|
||||
// `data`. If `data` does not encode such parameters, this
|
||||
// will throw.
|
||||
(
|
||||
LibNFTOrder.ERC721Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
bool unwrapNativeToken
|
||||
) = abi.decode(
|
||||
data,
|
||||
(LibNFTOrder.ERC721Order, LibSignature.Signature, bool)
|
||||
);
|
||||
|
||||
// `onERC721Received` is called by the ERC721 token contract.
|
||||
// Check that it matches the ERC721 token in the order.
|
||||
if (msg.sender != address(buyOrder.erc721Token)) {
|
||||
LibNFTOrdersRichErrors.ERC721TokenMismatchError(
|
||||
msg.sender,
|
||||
address(buyOrder.erc721Token)
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
_sellERC721(
|
||||
buyOrder,
|
||||
signature,
|
||||
tokenId,
|
||||
unwrapNativeToken,
|
||||
operator, // taker
|
||||
address(this), // owner (we hold the NFT currently)
|
||||
new bytes(0) // No taker callback
|
||||
);
|
||||
|
||||
return ERC721_RECEIVED_MAGIC_BYTES;
|
||||
}
|
||||
|
||||
/// @dev Approves an ERC721 order on-chain. After pre-signing
|
||||
/// the order, the `PRESIGNED` signature type will become
|
||||
/// valid for that order and signer.
|
||||
/// @param order An ERC721 order.
|
||||
function preSignERC721Order(LibNFTOrder.ERC721Order memory order)
|
||||
public
|
||||
override
|
||||
{
|
||||
require(
|
||||
order.maker == msg.sender,
|
||||
"ERC721OrdersFeature::preSignERC721Order/ONLY_MAKER"
|
||||
);
|
||||
bytes32 orderHash = getERC721OrderHash(order);
|
||||
LibERC721OrdersStorage.getStorage().preSigned[orderHash] = true;
|
||||
|
||||
emit ERC721OrderPreSigned(
|
||||
order.direction,
|
||||
order.maker,
|
||||
order.taker,
|
||||
order.expiry,
|
||||
order.nonce,
|
||||
order.erc20Token,
|
||||
order.erc20TokenAmount,
|
||||
order.fees,
|
||||
order.erc721Token,
|
||||
order.erc721TokenId,
|
||||
order.erc721TokenProperties
|
||||
);
|
||||
}
|
||||
|
||||
// Core settlement logic for selling an ERC721 asset.
|
||||
// Used by `sellERC721` and `onERC721Received`.
|
||||
function _sellERC721(
|
||||
LibNFTOrder.ERC721Order memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
uint256 erc721TokenId,
|
||||
bool unwrapNativeToken,
|
||||
address taker,
|
||||
address currentNftOwner,
|
||||
bytes memory takerCallbackData
|
||||
)
|
||||
private
|
||||
{
|
||||
_sellNFT(
|
||||
buyOrder.asNFTOrder(),
|
||||
signature,
|
||||
SellParams(
|
||||
1, // sell amount
|
||||
erc721TokenId,
|
||||
unwrapNativeToken,
|
||||
taker,
|
||||
currentNftOwner,
|
||||
takerCallbackData
|
||||
)
|
||||
);
|
||||
|
||||
emit ERC721OrderFilled(
|
||||
buyOrder.direction,
|
||||
buyOrder.maker,
|
||||
taker,
|
||||
buyOrder.nonce,
|
||||
buyOrder.erc20Token,
|
||||
buyOrder.erc20TokenAmount,
|
||||
buyOrder.erc721Token,
|
||||
erc721TokenId,
|
||||
address(0)
|
||||
);
|
||||
}
|
||||
|
||||
// Core settlement logic for buying an ERC721 asset.
|
||||
// Used by `buyERC721` and `batchBuyERC721s`.
|
||||
function _buyERC721(
|
||||
LibNFTOrder.ERC721Order memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
uint256 ethAvailable,
|
||||
bytes memory takerCallbackData
|
||||
)
|
||||
public
|
||||
payable
|
||||
{
|
||||
_buyNFT(
|
||||
sellOrder.asNFTOrder(),
|
||||
signature,
|
||||
BuyParams(
|
||||
1, // buy amount
|
||||
ethAvailable,
|
||||
takerCallbackData
|
||||
)
|
||||
);
|
||||
|
||||
emit ERC721OrderFilled(
|
||||
sellOrder.direction,
|
||||
sellOrder.maker,
|
||||
msg.sender,
|
||||
sellOrder.nonce,
|
||||
sellOrder.erc20Token,
|
||||
sellOrder.erc20TokenAmount,
|
||||
sellOrder.erc721Token,
|
||||
sellOrder.erc721TokenId,
|
||||
address(0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// @dev Checks whether the given signature is valid for the
|
||||
/// the given ERC721 order. Reverts if not.
|
||||
/// @param order The ERC721 order.
|
||||
/// @param signature The signature to validate.
|
||||
function validateERC721OrderSignature(
|
||||
LibNFTOrder.ERC721Order memory order,
|
||||
LibSignature.Signature memory signature
|
||||
)
|
||||
public
|
||||
override
|
||||
view
|
||||
{
|
||||
bytes32 orderHash = getERC721OrderHash(order);
|
||||
_validateOrderSignature(orderHash, signature, order.maker);
|
||||
}
|
||||
|
||||
/// @dev Validates that the given signature is valid for the
|
||||
/// given maker and order hash. Reverts if the signature
|
||||
/// is not valid.
|
||||
/// @param orderHash The hash of the order that was signed.
|
||||
/// @param signature The signature to check.
|
||||
/// @param maker The maker of the order.
|
||||
function _validateOrderSignature(
|
||||
bytes32 orderHash,
|
||||
LibSignature.Signature memory signature,
|
||||
address maker
|
||||
)
|
||||
internal
|
||||
override
|
||||
view
|
||||
{
|
||||
if (signature.signatureType == LibSignature.SignatureType.PRESIGNED) {
|
||||
// Check if order hash has been pre-signed by the maker.
|
||||
bool isPreSigned = LibERC721OrdersStorage.getStorage().preSigned[orderHash];
|
||||
if (!isPreSigned) {
|
||||
LibNFTOrdersRichErrors.InvalidSignerError(maker, address(0)).rrevert();
|
||||
}
|
||||
} else {
|
||||
address signer = LibSignature.getSignerOfHash(orderHash, signature);
|
||||
if (signer != maker) {
|
||||
LibNFTOrdersRichErrors.InvalidSignerError(maker, signer).rrevert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Transfers an NFT asset.
|
||||
/// @param token The address of the NFT contract.
|
||||
/// @param from The address currently holding the asset.
|
||||
/// @param to The address to transfer the asset to.
|
||||
/// @param tokenId The ID of the asset to transfer.
|
||||
/// @param amount The amount of the asset to transfer. Always
|
||||
/// 1 for ERC721 assets.
|
||||
function _transferNFTAssetFrom(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
override
|
||||
{
|
||||
assert(amount == 1);
|
||||
_transferERC721AssetFrom(IERC721Token(token), from, to, tokenId);
|
||||
}
|
||||
|
||||
/// @dev Updates storage to indicate that the given order
|
||||
/// has been filled by the given amount.
|
||||
/// @param order The order that has been filled.
|
||||
/// @param fillAmount The amount (denominated in the NFT asset)
|
||||
/// that the order has been filled by.
|
||||
function _updateOrderState(
|
||||
LibNFTOrder.NFTOrder memory order,
|
||||
bytes32 /* orderHash */,
|
||||
uint128 fillAmount
|
||||
)
|
||||
internal
|
||||
override
|
||||
{
|
||||
assert(fillAmount == 1);
|
||||
_setOrderStatusBit(order.maker, order.nonce);
|
||||
}
|
||||
|
||||
function _setOrderStatusBit(address maker, uint256 nonce)
|
||||
private
|
||||
{
|
||||
// The bitvector is indexed by the lower 8 bits of the nonce.
|
||||
uint256 flag = 1 << (nonce & 255);
|
||||
// Update order status bit vector to indicate that the given order
|
||||
// has been cancelled/filled by setting the designated bit to 1.
|
||||
LibERC721OrdersStorage.getStorage().orderStatusByMaker
|
||||
[maker][uint248(nonce >> 8)] |= flag;
|
||||
}
|
||||
|
||||
/// @dev If the given order is buying an ERC721 asset, checks
|
||||
/// whether or not the given token ID satisfies the required
|
||||
/// properties specified in the order. If the order does not
|
||||
/// specify any properties, this function instead checks
|
||||
/// whether the given token ID matches the ID in the order.
|
||||
/// Reverts if any checks fail, or if the order is selling
|
||||
/// an ERC721 asset.
|
||||
/// @param order The ERC721 order.
|
||||
/// @param erc721TokenId The ID of the ERC721 asset.
|
||||
function validateERC721OrderProperties(
|
||||
LibNFTOrder.ERC721Order memory order,
|
||||
uint256 erc721TokenId
|
||||
)
|
||||
public
|
||||
override
|
||||
view
|
||||
{
|
||||
_validateOrderProperties(
|
||||
order.asNFTOrder(),
|
||||
erc721TokenId
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Get the current status of an ERC721 order.
|
||||
/// @param order The ERC721 order.
|
||||
/// @return status The status of the order.
|
||||
function getERC721OrderStatus(LibNFTOrder.ERC721Order memory order)
|
||||
public
|
||||
override
|
||||
view
|
||||
returns (LibNFTOrder.OrderStatus status)
|
||||
{
|
||||
// Only buy orders with `erc721TokenId` == 0 can be property
|
||||
// orders.
|
||||
if (order.erc721TokenProperties.length > 0 &&
|
||||
(order.direction != LibNFTOrder.TradeDirection.BUY_NFT ||
|
||||
order.erc721TokenId != 0))
|
||||
{
|
||||
return LibNFTOrder.OrderStatus.INVALID;
|
||||
}
|
||||
|
||||
// Buy orders cannot use ETH as the ERC20 token, since ETH cannot be
|
||||
// transferred from the buyer by a contract.
|
||||
if (order.direction == LibNFTOrder.TradeDirection.BUY_NFT &&
|
||||
address(order.erc20Token) == NATIVE_TOKEN_ADDRESS)
|
||||
{
|
||||
return LibNFTOrder.OrderStatus.INVALID;
|
||||
}
|
||||
|
||||
// Check for expiry.
|
||||
if (order.expiry <= block.timestamp) {
|
||||
return LibNFTOrder.OrderStatus.EXPIRED;
|
||||
}
|
||||
|
||||
// Check `orderStatusByMaker` state variable to see if the order
|
||||
// has been cancelled or previously filled.
|
||||
LibERC721OrdersStorage.Storage storage stor =
|
||||
LibERC721OrdersStorage.getStorage();
|
||||
// `orderStatusByMaker` is indexed by maker and nonce.
|
||||
uint256 orderStatusBitVector =
|
||||
stor.orderStatusByMaker[order.maker][uint248(order.nonce >> 8)];
|
||||
// The bitvector is indexed by the lower 8 bits of the nonce.
|
||||
uint256 flag = 1 << (order.nonce & 255);
|
||||
// If the designated bit is set, the order has been cancelled or
|
||||
// previously filled, so it is now unfillable.
|
||||
if (orderStatusBitVector & flag != 0) {
|
||||
return LibNFTOrder.OrderStatus.UNFILLABLE;
|
||||
}
|
||||
|
||||
// Otherwise, the order is fillable.
|
||||
return LibNFTOrder.OrderStatus.FILLABLE;
|
||||
}
|
||||
|
||||
/// @dev Get the order info for an NFT order.
|
||||
/// @param order The NFT order.
|
||||
/// @return orderInfo Info about the order.
|
||||
function _getOrderInfo(LibNFTOrder.NFTOrder memory order)
|
||||
internal
|
||||
override
|
||||
view
|
||||
returns (LibNFTOrder.OrderInfo memory orderInfo)
|
||||
{
|
||||
LibNFTOrder.ERC721Order memory erc721Order = order.asERC721Order();
|
||||
orderInfo.orderHash = getERC721OrderHash(erc721Order);
|
||||
orderInfo.status = getERC721OrderStatus(erc721Order);
|
||||
orderInfo.orderAmount = 1;
|
||||
orderInfo.remainingAmount = orderInfo.status == LibNFTOrder.OrderStatus.FILLABLE ? 1 : 0;
|
||||
}
|
||||
|
||||
/// @dev Get the EIP-712 hash of an ERC721 order.
|
||||
/// @param order The ERC721 order.
|
||||
/// @return orderHash The order hash.
|
||||
function getERC721OrderHash(LibNFTOrder.ERC721Order memory order)
|
||||
public
|
||||
override
|
||||
view
|
||||
returns (bytes32 orderHash)
|
||||
{
|
||||
return _getEIP712Hash(LibNFTOrder.getERC721OrderStructHash(order));
|
||||
}
|
||||
|
||||
/// @dev Get the order status bit vector for the given
|
||||
/// maker address and nonce range.
|
||||
/// @param maker The maker of the order.
|
||||
/// @param nonceRange Order status bit vectors are indexed
|
||||
/// by maker address and the upper 248 bits of the
|
||||
/// order nonce. We define `nonceRange` to be these
|
||||
/// 248 bits.
|
||||
/// @return bitVector The order status bit vector for the
|
||||
/// given maker and nonce range.
|
||||
function getERC721OrderStatusBitVector(address maker, uint248 nonceRange)
|
||||
external
|
||||
override
|
||||
view
|
||||
returns (uint256 bitVector)
|
||||
{
|
||||
LibERC721OrdersStorage.Storage storage stor =
|
||||
LibERC721OrdersStorage.getStorage();
|
||||
return stor.orderStatusByMaker[maker][nonceRange];
|
||||
}
|
||||
}
|
@@ -0,0 +1,615 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../../errors/LibNFTOrdersRichErrors.sol";
|
||||
import "../../fixins/FixinCommon.sol";
|
||||
import "../../fixins/FixinEIP712.sol";
|
||||
import "../../fixins/FixinTokenSpender.sol";
|
||||
import "../../migrations/LibMigrate.sol";
|
||||
import "../../vendor/IFeeRecipient.sol";
|
||||
import "../../vendor/ITakerCallback.sol";
|
||||
import "../libs/LibSignature.sol";
|
||||
import "../libs/LibNFTOrder.sol";
|
||||
|
||||
|
||||
/// @dev Abstract base contract inherited by ERC721OrdersFeature and NFTOrders
|
||||
abstract contract NFTOrders is
|
||||
FixinCommon,
|
||||
FixinEIP712,
|
||||
FixinTokenSpender
|
||||
{
|
||||
using LibSafeMathV06 for uint256;
|
||||
|
||||
/// @dev Native token pseudo-address.
|
||||
address constant internal NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
/// @dev The WETH token contract.
|
||||
IEtherTokenV06 internal immutable WETH;
|
||||
|
||||
/// @dev The magic return value indicating the success of a `receiveZeroExFeeCallback`.
|
||||
bytes4 private constant FEE_CALLBACK_MAGIC_BYTES = IFeeRecipient.receiveZeroExFeeCallback.selector;
|
||||
/// @dev The magic return value indicating the success of a `zeroExTakerCallback`.
|
||||
bytes4 private constant TAKER_CALLBACK_MAGIC_BYTES = ITakerCallback.zeroExTakerCallback.selector;
|
||||
|
||||
constructor(address zeroExAddress, IEtherTokenV06 weth)
|
||||
public
|
||||
FixinEIP712(zeroExAddress)
|
||||
{
|
||||
WETH = weth;
|
||||
}
|
||||
|
||||
struct SellParams {
|
||||
uint128 sellAmount;
|
||||
uint256 tokenId;
|
||||
bool unwrapNativeToken;
|
||||
address taker;
|
||||
address currentNftOwner;
|
||||
bytes takerCallbackData;
|
||||
}
|
||||
|
||||
struct BuyParams {
|
||||
uint128 buyAmount;
|
||||
uint256 ethAvailable;
|
||||
bytes takerCallbackData;
|
||||
}
|
||||
|
||||
// Core settlement logic for selling an NFT asset.
|
||||
function _sellNFT(
|
||||
LibNFTOrder.NFTOrder memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
SellParams memory params
|
||||
)
|
||||
internal
|
||||
returns (uint256 erc20FillAmount)
|
||||
{
|
||||
LibNFTOrder.OrderInfo memory orderInfo = _getOrderInfo(buyOrder);
|
||||
// Check that the order can be filled.
|
||||
_validateBuyOrder(
|
||||
buyOrder,
|
||||
signature,
|
||||
orderInfo,
|
||||
params.taker,
|
||||
params.tokenId
|
||||
);
|
||||
|
||||
if (params.sellAmount > orderInfo.remainingAmount) {
|
||||
LibNFTOrdersRichErrors.ExceedsRemainingOrderAmount(
|
||||
orderInfo.remainingAmount,
|
||||
params.sellAmount
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
_updateOrderState(buyOrder, orderInfo.orderHash, params.sellAmount);
|
||||
|
||||
if (params.sellAmount == orderInfo.orderAmount) {
|
||||
erc20FillAmount = buyOrder.erc20TokenAmount;
|
||||
} else {
|
||||
// Rounding favors the order maker.
|
||||
erc20FillAmount = LibMathV06.getPartialAmountFloor(
|
||||
params.sellAmount,
|
||||
orderInfo.orderAmount,
|
||||
buyOrder.erc20TokenAmount
|
||||
);
|
||||
}
|
||||
|
||||
if (params.unwrapNativeToken) {
|
||||
// The ERC20 token must be WETH for it to be unwrapped.
|
||||
if (buyOrder.erc20Token != WETH) {
|
||||
LibNFTOrdersRichErrors.ERC20TokenMismatchError(
|
||||
address(buyOrder.erc20Token),
|
||||
address(WETH)
|
||||
).rrevert();
|
||||
}
|
||||
// Transfer the WETH from the maker to the Exchange Proxy
|
||||
// so we can unwrap it before sending it to the seller.
|
||||
// TODO: Probably safe to just use WETH.transferFrom for some
|
||||
// small gas savings
|
||||
_transferERC20TokensFrom(
|
||||
WETH,
|
||||
buyOrder.maker,
|
||||
address(this),
|
||||
erc20FillAmount
|
||||
);
|
||||
// Unwrap WETH into ETH.
|
||||
WETH.withdraw(erc20FillAmount);
|
||||
// Send ETH to the seller.
|
||||
_transferEth(payable(params.taker), erc20FillAmount);
|
||||
} else {
|
||||
// Transfer the ERC20 token from the buyer to the seller.
|
||||
_transferERC20TokensFrom(
|
||||
buyOrder.erc20Token,
|
||||
buyOrder.maker,
|
||||
params.taker,
|
||||
erc20FillAmount
|
||||
);
|
||||
}
|
||||
|
||||
if (params.takerCallbackData.length > 0) {
|
||||
require(
|
||||
params.taker != address(this),
|
||||
"NFTOrders::_sellNFT/CANNOT_CALLBACK_SELF"
|
||||
);
|
||||
// Invoke the callback
|
||||
bytes4 callbackResult = ITakerCallback(params.taker)
|
||||
.zeroExTakerCallback(orderInfo.orderHash, params.takerCallbackData);
|
||||
// Check for the magic success bytes
|
||||
require(
|
||||
callbackResult == TAKER_CALLBACK_MAGIC_BYTES,
|
||||
"NFTOrders::_sellNFT/CALLBACK_FAILED"
|
||||
);
|
||||
}
|
||||
|
||||
// Transfer the NFT asset to the buyer.
|
||||
// If this function is called from the
|
||||
// `onNFTReceived` callback the Exchange Proxy
|
||||
// holds the asset. Otherwise, transfer it from
|
||||
// the seller.
|
||||
_transferNFTAssetFrom(
|
||||
buyOrder.nft,
|
||||
params.currentNftOwner,
|
||||
buyOrder.maker,
|
||||
params.tokenId,
|
||||
params.sellAmount
|
||||
);
|
||||
|
||||
// The buyer pays the order fees.
|
||||
_payFees(
|
||||
buyOrder,
|
||||
buyOrder.maker,
|
||||
params.sellAmount,
|
||||
orderInfo.orderAmount,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// Core settlement logic for buying an NFT asset.
|
||||
function _buyNFT(
|
||||
LibNFTOrder.NFTOrder memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
BuyParams memory params
|
||||
)
|
||||
internal
|
||||
returns (uint256 erc20FillAmount)
|
||||
{
|
||||
LibNFTOrder.OrderInfo memory orderInfo = _getOrderInfo(sellOrder);
|
||||
// Check that the order can be filled.
|
||||
_validateSellOrder(
|
||||
sellOrder,
|
||||
signature,
|
||||
orderInfo,
|
||||
msg.sender
|
||||
);
|
||||
|
||||
if (params.buyAmount > orderInfo.remainingAmount) {
|
||||
LibNFTOrdersRichErrors.ExceedsRemainingOrderAmount(
|
||||
orderInfo.remainingAmount,
|
||||
params.buyAmount
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
_updateOrderState(sellOrder, orderInfo.orderHash, params.buyAmount);
|
||||
|
||||
if (params.buyAmount == orderInfo.orderAmount) {
|
||||
erc20FillAmount = sellOrder.erc20TokenAmount;
|
||||
} else {
|
||||
// Rounding favors the order maker.
|
||||
erc20FillAmount = LibMathV06.getPartialAmountCeil(
|
||||
params.buyAmount,
|
||||
orderInfo.orderAmount,
|
||||
sellOrder.erc20TokenAmount
|
||||
);
|
||||
}
|
||||
|
||||
// Transfer the NFT asset to the buyer (`msg.sender`).
|
||||
_transferNFTAssetFrom(
|
||||
sellOrder.nft,
|
||||
sellOrder.maker,
|
||||
msg.sender,
|
||||
sellOrder.nftId,
|
||||
params.buyAmount
|
||||
);
|
||||
|
||||
uint256 ethAvailable = params.ethAvailable;
|
||||
if (params.takerCallbackData.length > 0) {
|
||||
require(
|
||||
msg.sender != address(this),
|
||||
"NFTOrders::_buyNFT/CANNOT_CALLBACK_SELF"
|
||||
);
|
||||
uint256 ethBalanceBeforeCallback = address(this).balance;
|
||||
// Invoke the callback
|
||||
bytes4 callbackResult = ITakerCallback(msg.sender)
|
||||
.zeroExTakerCallback(orderInfo.orderHash, params.takerCallbackData);
|
||||
// Update `ethAvailable` with amount acquired during
|
||||
// the callback
|
||||
ethAvailable = ethAvailable.safeAdd(
|
||||
address(this).balance.safeSub(ethBalanceBeforeCallback)
|
||||
);
|
||||
// Check for the magic success bytes
|
||||
require(
|
||||
callbackResult == TAKER_CALLBACK_MAGIC_BYTES,
|
||||
"NFTOrders::_buyNFT/CALLBACK_FAILED"
|
||||
);
|
||||
}
|
||||
|
||||
if (address(sellOrder.erc20Token) == NATIVE_TOKEN_ADDRESS) {
|
||||
// Transfer ETH to the seller.
|
||||
_transferEth(payable(sellOrder.maker), erc20FillAmount);
|
||||
// Fees are paid from the EP's current balance of ETH.
|
||||
_payEthFees(
|
||||
sellOrder,
|
||||
params.buyAmount,
|
||||
orderInfo.orderAmount,
|
||||
erc20FillAmount,
|
||||
ethAvailable
|
||||
);
|
||||
} else if (sellOrder.erc20Token == WETH) {
|
||||
// If there is enough ETH available, fill the WETH order
|
||||
// (including fees) using that ETH.
|
||||
// Otherwise, transfer WETH from the taker.
|
||||
if (ethAvailable >= erc20FillAmount) {
|
||||
// Wrap ETH.
|
||||
WETH.deposit{value: erc20FillAmount}();
|
||||
// TODO: Probably safe to just use WETH.transfer for some
|
||||
// small gas savings
|
||||
// Transfer WETH to the seller.
|
||||
_transferERC20Tokens(
|
||||
WETH,
|
||||
sellOrder.maker,
|
||||
erc20FillAmount
|
||||
);
|
||||
// Fees are paid from the EP's current balance of ETH.
|
||||
_payEthFees(
|
||||
sellOrder,
|
||||
params.buyAmount,
|
||||
orderInfo.orderAmount,
|
||||
erc20FillAmount,
|
||||
ethAvailable
|
||||
);
|
||||
} else {
|
||||
// Transfer WETH from the buyer to the seller.
|
||||
_transferERC20TokensFrom(
|
||||
sellOrder.erc20Token,
|
||||
msg.sender,
|
||||
sellOrder.maker,
|
||||
erc20FillAmount
|
||||
);
|
||||
// The buyer pays fees using WETH.
|
||||
_payFees(
|
||||
sellOrder,
|
||||
msg.sender,
|
||||
params.buyAmount,
|
||||
orderInfo.orderAmount,
|
||||
false
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Transfer ERC20 token from the buyer to the seller.
|
||||
_transferERC20TokensFrom(
|
||||
sellOrder.erc20Token,
|
||||
msg.sender,
|
||||
sellOrder.maker,
|
||||
erc20FillAmount
|
||||
);
|
||||
// The buyer pays fees.
|
||||
_payFees(
|
||||
sellOrder,
|
||||
msg.sender,
|
||||
params.buyAmount,
|
||||
orderInfo.orderAmount,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function _validateSellOrder(
|
||||
LibNFTOrder.NFTOrder memory sellOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
LibNFTOrder.OrderInfo memory orderInfo,
|
||||
address taker
|
||||
)
|
||||
internal
|
||||
view
|
||||
{
|
||||
// Order must be selling the NFT asset.
|
||||
require(
|
||||
sellOrder.direction == LibNFTOrder.TradeDirection.SELL_NFT,
|
||||
"NFTOrders::_validateSellOrder/WRONG_TRADE_DIRECTION"
|
||||
);
|
||||
// Taker must match the order taker, if one is specified.
|
||||
if (sellOrder.taker != address(0) && sellOrder.taker != taker) {
|
||||
LibNFTOrdersRichErrors.OnlyTakerError(taker, sellOrder.taker).rrevert();
|
||||
}
|
||||
// Check that the order is valid and has not expired, been cancelled,
|
||||
// or been filled.
|
||||
if (orderInfo.status != LibNFTOrder.OrderStatus.FILLABLE) {
|
||||
LibNFTOrdersRichErrors.OrderNotFillableError(
|
||||
sellOrder.maker,
|
||||
sellOrder.nonce,
|
||||
uint8(orderInfo.status)
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
// Check the signature.
|
||||
_validateOrderSignature(orderInfo.orderHash, signature, sellOrder.maker);
|
||||
}
|
||||
|
||||
function _validateBuyOrder(
|
||||
LibNFTOrder.NFTOrder memory buyOrder,
|
||||
LibSignature.Signature memory signature,
|
||||
LibNFTOrder.OrderInfo memory orderInfo,
|
||||
address taker,
|
||||
uint256 tokenId
|
||||
)
|
||||
internal
|
||||
view
|
||||
{
|
||||
// Order must be buying the NFT asset.
|
||||
require(
|
||||
buyOrder.direction == LibNFTOrder.TradeDirection.BUY_NFT,
|
||||
"NFTOrders::_validateBuyOrder/WRONG_TRADE_DIRECTION"
|
||||
);
|
||||
// The ERC20 token cannot be ETH.
|
||||
require(
|
||||
address(buyOrder.erc20Token) != NATIVE_TOKEN_ADDRESS,
|
||||
"NFTOrders::_validateBuyOrder/NATIVE_TOKEN_NOT_ALLOWED"
|
||||
);
|
||||
// Taker must match the order taker, if one is specified.
|
||||
if (buyOrder.taker != address(0) && buyOrder.taker != taker) {
|
||||
LibNFTOrdersRichErrors.OnlyTakerError(taker, buyOrder.taker).rrevert();
|
||||
}
|
||||
// Check that the order is valid and has not expired, been cancelled,
|
||||
// or been filled.
|
||||
if (orderInfo.status != LibNFTOrder.OrderStatus.FILLABLE) {
|
||||
LibNFTOrdersRichErrors.OrderNotFillableError(
|
||||
buyOrder.maker,
|
||||
buyOrder.nonce,
|
||||
uint8(orderInfo.status)
|
||||
).rrevert();
|
||||
}
|
||||
// Check that the asset with the given token ID satisfies the properties
|
||||
// specified by the order.
|
||||
_validateOrderProperties(buyOrder, tokenId);
|
||||
// Check the signature.
|
||||
_validateOrderSignature(orderInfo.orderHash, signature, buyOrder.maker);
|
||||
}
|
||||
|
||||
function _payEthFees(
|
||||
LibNFTOrder.NFTOrder memory order,
|
||||
uint128 fillAmount,
|
||||
uint128 orderAmount,
|
||||
uint256 ethSpent,
|
||||
uint256 ethAvailable
|
||||
)
|
||||
private
|
||||
{
|
||||
// Pay fees using ETH.
|
||||
uint256 ethFees = _payFees(
|
||||
order,
|
||||
address(this),
|
||||
fillAmount,
|
||||
orderAmount,
|
||||
true
|
||||
);
|
||||
// Update amount of ETH spent.
|
||||
ethSpent = ethSpent.safeAdd(ethFees);
|
||||
if (ethSpent > ethAvailable) {
|
||||
LibNFTOrdersRichErrors.OverspentEthError(
|
||||
ethSpent,
|
||||
ethAvailable
|
||||
).rrevert();
|
||||
}
|
||||
}
|
||||
|
||||
function _payFees(
|
||||
LibNFTOrder.NFTOrder memory order,
|
||||
address payer,
|
||||
uint128 fillAmount,
|
||||
uint128 orderAmount,
|
||||
bool useNativeToken
|
||||
)
|
||||
internal
|
||||
returns (uint256 totalFeesPaid)
|
||||
{
|
||||
// Make assertions about ETH case
|
||||
if (useNativeToken) {
|
||||
assert(payer == address(this));
|
||||
assert(
|
||||
order.erc20Token == WETH ||
|
||||
address(order.erc20Token) == NATIVE_TOKEN_ADDRESS
|
||||
);
|
||||
}
|
||||
|
||||
for (uint256 i = 0; i < order.fees.length; i++) {
|
||||
LibNFTOrder.Fee memory fee = order.fees[i];
|
||||
|
||||
require(
|
||||
fee.recipient != address(this),
|
||||
"NFTOrders::_payFees/RECIPIENT_CANNOT_BE_EXCHANGE_PROXY"
|
||||
);
|
||||
|
||||
uint256 feeFillAmount;
|
||||
if (fillAmount == orderAmount) {
|
||||
feeFillAmount = fee.amount;
|
||||
} else {
|
||||
// Round against the fee recipient
|
||||
feeFillAmount = LibMathV06.getPartialAmountFloor(
|
||||
fillAmount,
|
||||
orderAmount,
|
||||
fee.amount
|
||||
);
|
||||
}
|
||||
if (feeFillAmount == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (useNativeToken) {
|
||||
// Transfer ETH to the fee recipient.
|
||||
_transferEth(payable(fee.recipient), feeFillAmount);
|
||||
} else {
|
||||
// Transfer ERC20 token from payer to recipient.
|
||||
_transferERC20TokensFrom(
|
||||
order.erc20Token,
|
||||
payer,
|
||||
fee.recipient,
|
||||
feeFillAmount
|
||||
);
|
||||
}
|
||||
// Note that the fee callback is _not_ called if zero
|
||||
// `feeData` is provided. If `feeData` is provided, we assume
|
||||
// the fee recipient is a contract that implements the
|
||||
// `IFeeRecipient` interface.
|
||||
if (fee.feeData.length > 0) {
|
||||
// Invoke the callback
|
||||
bytes4 callbackResult = IFeeRecipient(fee.recipient).receiveZeroExFeeCallback(
|
||||
useNativeToken ? NATIVE_TOKEN_ADDRESS : address(order.erc20Token),
|
||||
feeFillAmount,
|
||||
fee.feeData
|
||||
);
|
||||
// Check for the magic success bytes
|
||||
require(
|
||||
callbackResult == FEE_CALLBACK_MAGIC_BYTES,
|
||||
"NFTOrders::_payFees/CALLBACK_FAILED"
|
||||
);
|
||||
}
|
||||
// Sum the fees paid
|
||||
totalFeesPaid = totalFeesPaid.safeAdd(feeFillAmount);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev If the given order is buying an NFT asset, checks
|
||||
/// whether or not the given token ID satisfies the required
|
||||
/// properties specified in the order. If the order does not
|
||||
/// specify any properties, this function instead checks
|
||||
/// whether the given token ID matches the ID in the order.
|
||||
/// Reverts if any checks fail, or if the order is selling
|
||||
/// an NFT asset.
|
||||
/// @param order The NFT order.
|
||||
/// @param tokenId The ID of the NFT asset.
|
||||
function _validateOrderProperties(
|
||||
LibNFTOrder.NFTOrder memory order,
|
||||
uint256 tokenId
|
||||
)
|
||||
internal
|
||||
view
|
||||
{
|
||||
// Order must be buying an NFT asset to have properties.
|
||||
require(
|
||||
order.direction == LibNFTOrder.TradeDirection.BUY_NFT,
|
||||
"NFTOrders::_validateOrderProperties/WRONG_TRADE_DIRECTION"
|
||||
);
|
||||
|
||||
// If no properties are specified, check that the given
|
||||
// `tokenId` matches the one specified in the order.
|
||||
if (order.nftProperties.length == 0) {
|
||||
if (tokenId != order.nftId) {
|
||||
LibNFTOrdersRichErrors.TokenIdMismatchError(
|
||||
tokenId,
|
||||
order.nftId
|
||||
).rrevert();
|
||||
}
|
||||
} else {
|
||||
// Validate each property
|
||||
for (uint256 i = 0; i < order.nftProperties.length; i++) {
|
||||
LibNFTOrder.Property memory property = order.nftProperties[i];
|
||||
// `address(0)` is interpreted as a no-op. Any token ID
|
||||
// will satisfy a property with `propertyValidator == address(0)`.
|
||||
if (address(property.propertyValidator) == address(0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Call the property validator and throw a descriptive error
|
||||
// if the call reverts.
|
||||
try property.propertyValidator.validateProperty(
|
||||
order.nft,
|
||||
tokenId,
|
||||
property.propertyData
|
||||
) {} catch (bytes memory errorData) {
|
||||
LibNFTOrdersRichErrors.PropertyValidationFailedError(
|
||||
address(property.propertyValidator),
|
||||
order.nft,
|
||||
tokenId,
|
||||
property.propertyData,
|
||||
errorData
|
||||
).rrevert();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Validates that the given signature is valid for the
|
||||
/// given maker and order hash. Reverts if the signature
|
||||
/// is not valid.
|
||||
/// @param orderHash The hash of the order that was signed.
|
||||
/// @param signature The signature to check.
|
||||
/// @param maker The maker of the order.
|
||||
function _validateOrderSignature(
|
||||
bytes32 orderHash,
|
||||
LibSignature.Signature memory signature,
|
||||
address maker
|
||||
)
|
||||
internal
|
||||
virtual
|
||||
view;
|
||||
|
||||
/// @dev Transfers an NFT asset.
|
||||
/// @param token The address of the NFT contract.
|
||||
/// @param from The address currently holding the asset.
|
||||
/// @param to The address to transfer the asset to.
|
||||
/// @param tokenId The ID of the asset to transfer.
|
||||
/// @param amount The amount of the asset to transfer. Always
|
||||
/// 1 for ERC721 assets.
|
||||
function _transferNFTAssetFrom(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
virtual;
|
||||
|
||||
/// @dev Updates storage to indicate that the given order
|
||||
/// has been filled by the given amount.
|
||||
/// @param order The order that has been filled.
|
||||
/// @param orderHash The hash of `order`.
|
||||
/// @param fillAmount The amount (denominated in the NFT asset)
|
||||
/// that the order has been filled by.
|
||||
function _updateOrderState(
|
||||
LibNFTOrder.NFTOrder memory order,
|
||||
bytes32 orderHash,
|
||||
uint128 fillAmount
|
||||
)
|
||||
internal
|
||||
virtual;
|
||||
|
||||
/// @dev Get the order info for an NFT order.
|
||||
/// @param order The NFT order.
|
||||
/// @return orderInfo Info about the order.
|
||||
function _getOrderInfo(LibNFTOrder.NFTOrder memory order)
|
||||
internal
|
||||
virtual
|
||||
view
|
||||
returns (LibNFTOrder.OrderInfo memory orderInfo);
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../vendor/IERC1155Token.sol";
|
||||
|
||||
|
||||
/// @dev Helpers for moving ERC1155 assets around.
|
||||
abstract contract FixinERC1155Spender {
|
||||
|
||||
// Mask of the lower 20 bytes of a bytes32.
|
||||
uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
|
||||
|
||||
/// @dev Transfers an ERC1155 asset from `owner` to `to`.
|
||||
/// @param token The address of the ERC1155 token contract.
|
||||
/// @param owner The owner of the asset.
|
||||
/// @param to The recipient of the asset.
|
||||
/// @param tokenId The token ID of the asset to transfer.
|
||||
/// @param amount The amount of the asset to transfer.
|
||||
function _transferERC1155AssetFrom(
|
||||
IERC1155Token token,
|
||||
address owner,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
require(address(token) != address(this), "FixinERC1155Spender/CANNOT_INVOKE_SELF");
|
||||
|
||||
assembly {
|
||||
let ptr := mload(0x40) // free memory pointer
|
||||
|
||||
// selector for safeTransferFrom(address,address,uint256,uint256,bytes)
|
||||
mstore(ptr, 0xf242432a00000000000000000000000000000000000000000000000000000000)
|
||||
mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK))
|
||||
mstore(add(ptr, 0x24), and(to, ADDRESS_MASK))
|
||||
mstore(add(ptr, 0x44), tokenId)
|
||||
mstore(add(ptr, 0x64), amount)
|
||||
mstore(add(ptr, 0x84), 0xa0)
|
||||
mstore(add(ptr, 0xa4), 0)
|
||||
|
||||
let success := call(
|
||||
gas(),
|
||||
and(token, ADDRESS_MASK),
|
||||
0,
|
||||
ptr,
|
||||
0xc4,
|
||||
0,
|
||||
0
|
||||
)
|
||||
|
||||
if iszero(success) {
|
||||
let rdsize := returndatasize()
|
||||
returndatacopy(ptr, 0, rdsize)
|
||||
revert(ptr, rdsize)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../vendor/IERC721Token.sol";
|
||||
|
||||
|
||||
/// @dev Helpers for moving ERC721 assets around.
|
||||
abstract contract FixinERC721Spender {
|
||||
|
||||
// Mask of the lower 20 bytes of a bytes32.
|
||||
uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
|
||||
|
||||
/// @dev Transfers an ERC721 asset from `owner` to `to`.
|
||||
/// @param token The address of the ERC721 token contract.
|
||||
/// @param owner The owner of the asset.
|
||||
/// @param to The recipient of the asset.
|
||||
/// @param tokenId The token ID of the asset to transfer.
|
||||
function _transferERC721AssetFrom(
|
||||
IERC721Token token,
|
||||
address owner,
|
||||
address to,
|
||||
uint256 tokenId
|
||||
)
|
||||
internal
|
||||
{
|
||||
require(address(token) != address(this), "FixinERC721Spender/CANNOT_INVOKE_SELF");
|
||||
|
||||
assembly {
|
||||
let ptr := mload(0x40) // free memory pointer
|
||||
|
||||
// selector for transferFrom(address,address,uint256)
|
||||
mstore(ptr, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
|
||||
mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK))
|
||||
mstore(add(ptr, 0x24), and(to, ADDRESS_MASK))
|
||||
mstore(add(ptr, 0x44), tokenId)
|
||||
|
||||
let success := call(
|
||||
gas(),
|
||||
and(token, ADDRESS_MASK),
|
||||
0,
|
||||
ptr,
|
||||
0x64,
|
||||
0,
|
||||
0
|
||||
)
|
||||
|
||||
if iszero(success) {
|
||||
let rdsize := returndatasize()
|
||||
returndatacopy(ptr, 0, rdsize)
|
||||
revert(ptr, rdsize)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
|
||||
|
||||
@@ -141,6 +141,20 @@ abstract contract FixinTokenSpender {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// @dev Transfers some amount of ETH to the given recipient and
|
||||
/// reverts if the transfer fails.
|
||||
/// @param recipient The recipient of the ETH.
|
||||
/// @param amount The amount of ETH to transfer.
|
||||
function _transferEth(address payable recipient, uint256 amount)
|
||||
internal
|
||||
{
|
||||
if (amount > 0) {
|
||||
(bool success,) = recipient.call{value: amount}("");
|
||||
require(success, "FixinTokenSpender::_transferEth/TRANSFER_FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Gets the maximum amount of an ERC20 token `token` that can be
|
||||
/// pulled from `owner` by this address.
|
||||
/// @param token The token to spend.
|
||||
|
@@ -25,6 +25,7 @@ import "../features/interfaces/IOwnableFeature.sol";
|
||||
import "../features/TransformERC20Feature.sol";
|
||||
import "../features/MetaTransactionsFeature.sol";
|
||||
import "../features/NativeOrdersFeature.sol";
|
||||
import "../features/OtcOrdersFeature.sol";
|
||||
import "./InitialMigration.sol";
|
||||
|
||||
|
||||
@@ -40,6 +41,7 @@ contract FullMigration {
|
||||
TransformERC20Feature transformERC20;
|
||||
MetaTransactionsFeature metaTransactions;
|
||||
NativeOrdersFeature nativeOrders;
|
||||
OtcOrdersFeature otcOrders;
|
||||
}
|
||||
|
||||
/// @dev Parameters needed to initialize features.
|
||||
@@ -173,5 +175,16 @@ contract FullMigration {
|
||||
address(this)
|
||||
);
|
||||
}
|
||||
// OtcOrdersFeature
|
||||
{
|
||||
// Register the feature.
|
||||
ownable.migrate(
|
||||
address(features.otcOrders),
|
||||
abi.encodeWithSelector(
|
||||
OtcOrdersFeature.migrate.selector
|
||||
),
|
||||
address(this)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./LibStorage.sol";
|
||||
|
||||
|
||||
/// @dev Storage helpers for `ERC1155OrdersFeature`.
|
||||
library LibERC1155OrdersStorage {
|
||||
|
||||
struct OrderState {
|
||||
// The amount (denominated in the ERC1155 asset)
|
||||
// that the order has been filled by.
|
||||
uint128 filledAmount;
|
||||
// Whether the order has been pre-signed.
|
||||
bool preSigned;
|
||||
}
|
||||
|
||||
/// @dev Storage bucket for this feature.
|
||||
struct Storage {
|
||||
// Mapping from order hash to order state:
|
||||
mapping(bytes32 => OrderState) orderState;
|
||||
// maker => nonce range => order cancellation bit vector
|
||||
mapping(address => mapping(uint248 => uint256)) orderCancellationByMaker;
|
||||
}
|
||||
|
||||
/// @dev Get the storage bucket for this contract.
|
||||
function getStorage() internal pure returns (Storage storage stor) {
|
||||
uint256 storageSlot = LibStorage.getStorageSlot(
|
||||
LibStorage.StorageId.ERC1155Orders
|
||||
);
|
||||
// Dip into assembly to change the slot pointed to by the local
|
||||
// variable `stor`.
|
||||
// See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries
|
||||
assembly { stor_slot := storageSlot }
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./LibStorage.sol";
|
||||
|
||||
|
||||
/// @dev Storage helpers for `ERC721OrdersFeature`.
|
||||
library LibERC721OrdersStorage {
|
||||
|
||||
/// @dev Storage bucket for this feature.
|
||||
struct Storage {
|
||||
// maker => nonce range => order status bit vector
|
||||
mapping(address => mapping(uint248 => uint256)) orderStatusByMaker;
|
||||
// order hash => isSigned
|
||||
mapping(bytes32 => bool) preSigned;
|
||||
}
|
||||
|
||||
/// @dev Get the storage bucket for this contract.
|
||||
function getStorage() internal pure returns (Storage storage stor) {
|
||||
uint256 storageSlot = LibStorage.getStorageSlot(
|
||||
LibStorage.StorageId.ERC721Orders
|
||||
);
|
||||
// Dip into assembly to change the slot pointed to by the local
|
||||
// variable `stor`.
|
||||
// See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries
|
||||
assembly { stor_slot := storageSlot }
|
||||
}
|
||||
}
|
@@ -17,7 +17,7 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ library LibStorage {
|
||||
MetaTransactions,
|
||||
ReentrancyGuard,
|
||||
NativeOrders,
|
||||
OtcOrders
|
||||
OtcOrders,
|
||||
ERC721Orders,
|
||||
ERC1155Orders
|
||||
}
|
||||
|
||||
/// @dev Get the storage slot given a storage ID. We assign unique, well-spaced
|
||||
|
@@ -313,7 +313,7 @@ contract FillQuoteTransformer is
|
||||
if (success) {
|
||||
results.makerTokenBoughtAmount = abi.decode(resultData, (uint256));
|
||||
results.takerTokenSoldAmount = takerTokenFillAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fill a single limit order.
|
||||
|
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./IBridgeAdapter.sol";
|
||||
|
||||
abstract contract AbstractBridgeAdapter is IBridgeAdapter {
|
||||
|
||||
constructor(
|
||||
uint256 expectedChainId,
|
||||
string memory expectedChainName
|
||||
)
|
||||
public
|
||||
{
|
||||
uint256 chainId;
|
||||
assembly { chainId := chainid() }
|
||||
// Allow testing on Ganache
|
||||
if (chainId != expectedChainId && chainId != 1337) {
|
||||
revert(string(abi.encodePacked(expectedChainName, "BridgeAdapter.constructor: wrong chain ID")));
|
||||
}
|
||||
}
|
||||
|
||||
function isSupportedSource(bytes32 source)
|
||||
external
|
||||
override
|
||||
returns (bool isSupported)
|
||||
{
|
||||
BridgeOrder memory placeholderOrder;
|
||||
placeholderOrder.source = source;
|
||||
IERC20TokenV06 placeholderToken = IERC20TokenV06(address(0));
|
||||
|
||||
(, isSupported) = _trade(
|
||||
placeholderOrder,
|
||||
placeholderToken,
|
||||
placeholderToken,
|
||||
0,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
function trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount
|
||||
)
|
||||
public
|
||||
override
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(boughtAmount, ) = _trade(
|
||||
order,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
virtual
|
||||
returns (uint256 boughtAmount, bool supportedSource);
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
import "./mixins/MixinGMX.sol";
|
||||
import "./mixins/MixinKyberDmm.sol";
|
||||
import "./mixins/MixinAaveV2.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinPlatypus.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract AvalancheBridgeAdapter is
|
||||
AbstractBridgeAdapter(43114, "Avalanche"),
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
MixinGMX,
|
||||
MixinKyberDmm,
|
||||
MixinAaveV2,
|
||||
MixinNerve,
|
||||
MixinPlatypus,
|
||||
MixinUniswapV2,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinCurve(weth)
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CURVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.KYBERDMM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeKyberDmm(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.AAVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeAaveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.GMX) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeGMX(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.PLATYPUS) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradePlatypus(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.WOOFI) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeWOOFi(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,142 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinDodo.sol";
|
||||
import "./mixins/MixinDodoV2.sol";
|
||||
import "./mixins/MixinKyberDmm.sol";
|
||||
import "./mixins/MixinMooniswap.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract BSCBridgeAdapter is
|
||||
AbstractBridgeAdapter(56, "BSC"),
|
||||
MixinCurve,
|
||||
MixinDodo,
|
||||
MixinDodoV2,
|
||||
MixinKyberDmm,
|
||||
MixinMooniswap,
|
||||
MixinNerve,
|
||||
MixinUniswapV2,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinCurve(weth)
|
||||
MixinMooniswap(weth)
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.MOONISWAP) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeMooniswap(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODO) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodo(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODOV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodoV2(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.KYBERDMM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeKyberDmm(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.WOOFI) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeWOOFi(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -27,27 +27,36 @@ library BridgeProtocols {
|
||||
// A incrementally increasing, append-only list of protocol IDs.
|
||||
// We don't use an enum so solidity doesn't throw when we pass in a
|
||||
// new protocol ID that hasn't been rolled up yet.
|
||||
uint128 internal constant UNKNOWN = 0;
|
||||
uint128 internal constant CURVE = 1;
|
||||
uint128 internal constant UNISWAPV2 = 2;
|
||||
uint128 internal constant UNISWAP = 3;
|
||||
uint128 internal constant BALANCER = 4;
|
||||
uint128 internal constant KYBER = 5;
|
||||
uint128 internal constant MOONISWAP = 6;
|
||||
uint128 internal constant MSTABLE = 7;
|
||||
uint128 internal constant OASIS = 8;
|
||||
uint128 internal constant SHELL = 9;
|
||||
uint128 internal constant DODO = 10;
|
||||
uint128 internal constant DODOV2 = 11;
|
||||
uint128 internal constant CRYPTOCOM = 12;
|
||||
uint128 internal constant BANCOR = 13;
|
||||
uint128 internal constant COFIX = 14;
|
||||
uint128 internal constant NERVE = 15;
|
||||
uint128 internal constant MAKERPSM = 16;
|
||||
uint128 internal constant BALANCERV2 = 17;
|
||||
uint128 internal constant UNISWAPV3 = 18;
|
||||
uint128 internal constant KYBERDMM = 19;
|
||||
uint128 internal constant CURVEV2 = 20;
|
||||
uint128 internal constant LIDO = 21;
|
||||
uint128 internal constant CLIPPER = 22;
|
||||
uint128 internal constant UNKNOWN = 0;
|
||||
uint128 internal constant CURVE = 1;
|
||||
uint128 internal constant UNISWAPV2 = 2;
|
||||
uint128 internal constant UNISWAP = 3;
|
||||
uint128 internal constant BALANCER = 4;
|
||||
uint128 internal constant KYBER = 5; // Not used: deprecated.
|
||||
uint128 internal constant MOONISWAP = 6;
|
||||
uint128 internal constant MSTABLE = 7;
|
||||
uint128 internal constant OASIS = 8; // Not used: deprecated.
|
||||
uint128 internal constant SHELL = 9;
|
||||
uint128 internal constant DODO = 10;
|
||||
uint128 internal constant DODOV2 = 11;
|
||||
uint128 internal constant CRYPTOCOM = 12;
|
||||
uint128 internal constant BANCOR = 13;
|
||||
uint128 internal constant COFIX = 14; // Not used: deprecated.
|
||||
uint128 internal constant NERVE = 15;
|
||||
uint128 internal constant MAKERPSM = 16;
|
||||
uint128 internal constant BALANCERV2 = 17;
|
||||
uint128 internal constant UNISWAPV3 = 18;
|
||||
uint128 internal constant KYBERDMM = 19;
|
||||
uint128 internal constant CURVEV2 = 20;
|
||||
uint128 internal constant LIDO = 21;
|
||||
uint128 internal constant CLIPPER = 22; // Not used: Clipper is now using PLP interface
|
||||
uint128 internal constant AAVEV2 = 23;
|
||||
uint128 internal constant COMPOUND = 24;
|
||||
uint128 internal constant BALANCERV2BATCH = 25;
|
||||
uint128 internal constant GMX = 26;
|
||||
uint128 internal constant PLATYPUS = 27;
|
||||
uint128 internal constant BANCORV3 = 28;
|
||||
uint128 internal constant VELODROME = 29;
|
||||
uint128 internal constant SYNTHETIX = 30;
|
||||
uint128 internal constant WOOFI = 31;
|
||||
}
|
||||
|
@@ -0,0 +1,84 @@
|
||||
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract CeloBridgeAdapter is
|
||||
AbstractBridgeAdapter(42220, "Celo"),
|
||||
MixinNerve,
|
||||
MixinUniswapV2,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(address _weth)
|
||||
public
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -20,53 +20,53 @@
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./IBridgeAdapter.sol";
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinAaveV2.sol";
|
||||
import "./mixins/MixinBalancer.sol";
|
||||
import "./mixins/MixinBalancerV2.sol";
|
||||
import "./mixins/MixinBalancerV2Batch.sol";
|
||||
import "./mixins/MixinBancor.sol";
|
||||
import "./mixins/MixinClipper.sol";
|
||||
import "./mixins/MixinCoFiX.sol";
|
||||
import "./mixins/MixinBancorV3.sol";
|
||||
import "./mixins/MixinCompound.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
import "./mixins/MixinCryptoCom.sol";
|
||||
import "./mixins/MixinDodo.sol";
|
||||
import "./mixins/MixinDodoV2.sol";
|
||||
import "./mixins/MixinKyber.sol";
|
||||
import "./mixins/MixinKyberDmm.sol";
|
||||
import "./mixins/MixinLido.sol";
|
||||
import "./mixins/MixinMakerPSM.sol";
|
||||
import "./mixins/MixinMooniswap.sol";
|
||||
import "./mixins/MixinMStable.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinOasis.sol";
|
||||
import "./mixins/MixinShell.sol";
|
||||
import "./mixins/MixinSynthetix.sol";
|
||||
import "./mixins/MixinUniswap.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinUniswapV3.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract BridgeAdapter is
|
||||
IBridgeAdapter,
|
||||
contract EthereumBridgeAdapter is
|
||||
AbstractBridgeAdapter(1, "Ethereum"),
|
||||
MixinAaveV2,
|
||||
MixinBalancer,
|
||||
MixinBalancerV2,
|
||||
MixinBalancerV2Batch,
|
||||
MixinBancor,
|
||||
MixinClipper,
|
||||
MixinCoFiX,
|
||||
MixinBancorV3,
|
||||
MixinCompound,
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
MixinCryptoCom,
|
||||
MixinDodo,
|
||||
MixinDodoV2,
|
||||
MixinKyber,
|
||||
MixinKyberDmm,
|
||||
MixinLido,
|
||||
MixinMakerPSM,
|
||||
MixinMooniswap,
|
||||
MixinMStable,
|
||||
MixinNerve,
|
||||
MixinOasis,
|
||||
MixinShell,
|
||||
MixinSynthetix,
|
||||
MixinUniswap,
|
||||
MixinUniswapV2,
|
||||
MixinUniswapV3,
|
||||
@@ -74,42 +74,28 @@ contract BridgeAdapter is
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinBalancer()
|
||||
MixinBalancerV2()
|
||||
MixinBancor(weth)
|
||||
MixinClipper(weth)
|
||||
MixinCoFiX()
|
||||
MixinBancorV3(weth)
|
||||
MixinCompound(weth)
|
||||
MixinCurve(weth)
|
||||
MixinCurveV2()
|
||||
MixinCryptoCom()
|
||||
MixinDodo()
|
||||
MixinDodoV2()
|
||||
MixinKyber(weth)
|
||||
MixinLido(weth)
|
||||
MixinMakerPSM()
|
||||
MixinMooniswap(weth)
|
||||
MixinMStable()
|
||||
MixinNerve()
|
||||
MixinOasis()
|
||||
MixinShell()
|
||||
MixinUniswap(weth)
|
||||
MixinUniswapV2()
|
||||
MixinUniswapV3()
|
||||
MixinZeroExBridge()
|
||||
{}
|
||||
|
||||
function trade(
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
public
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount)
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
@@ -117,6 +103,7 @@ contract BridgeAdapter is
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CURVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
@@ -124,18 +111,21 @@ contract BridgeAdapter is
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV3(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAP) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswap(
|
||||
sellToken,
|
||||
buyToken,
|
||||
@@ -143,6 +133,7 @@ contract BridgeAdapter is
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BALANCER) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancer(
|
||||
sellToken,
|
||||
buyToken,
|
||||
@@ -150,48 +141,37 @@ contract BridgeAdapter is
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BALANCERV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancerV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.KYBER) {
|
||||
boughtAmount = _tradeKyber(
|
||||
sellToken,
|
||||
buyToken,
|
||||
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancerV2Batch(
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.MAKERPSM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeMakerPsm(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.MOONISWAP) {
|
||||
boughtAmount = _tradeMooniswap(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.MSTABLE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeMStable(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.OASIS) {
|
||||
boughtAmount = _tradeOasis(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.SHELL) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeShell(
|
||||
sellToken,
|
||||
buyToken,
|
||||
@@ -199,63 +179,86 @@ contract BridgeAdapter is
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODO) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodo(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODOV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodoV2(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CRYPTOCOM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCryptoCom(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BANCOR) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBancor(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.COFIX) {
|
||||
boughtAmount = _tradeCoFiX(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.KYBERDMM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeKyberDmm(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.LIDO) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeLido(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CLIPPER) {
|
||||
boughtAmount = _tradeClipper(
|
||||
} else if (protocolId == BridgeProtocols.AAVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeAaveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else {
|
||||
} else if (protocolId == BridgeProtocols.COMPOUND) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCompound(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BANCORV3) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBancorV3(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.SYNTHETIX) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeSynthetix(
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
@@ -0,0 +1,134 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinAaveV2.sol";
|
||||
import "./mixins/MixinBalancerV2.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract FantomBridgeAdapter is
|
||||
AbstractBridgeAdapter(250, "Fantom"),
|
||||
MixinAaveV2,
|
||||
MixinBalancerV2,
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
MixinNerve,
|
||||
MixinUniswapV2,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinCurve(weth)
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CURVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BALANCERV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancerV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.AAVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeAaveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.WOOFI) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeWOOFi(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -50,6 +50,10 @@ interface IBridgeAdapter {
|
||||
uint256 outputTokenAmount
|
||||
);
|
||||
|
||||
function isSupportedSource(bytes32 source)
|
||||
external
|
||||
returns (bool isSupported);
|
||||
|
||||
function trade(
|
||||
BridgeOrder calldata order,
|
||||
IERC20TokenV06 sellToken,
|
||||
|
@@ -0,0 +1,122 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinSynthetix.sol";
|
||||
import "./mixins/MixinUniswapV3.sol";
|
||||
import "./mixins/MixinVelodrome.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract OptimismBridgeAdapter is
|
||||
AbstractBridgeAdapter(10, "Optimism"),
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
MixinNerve,
|
||||
MixinSynthetix,
|
||||
MixinUniswapV3,
|
||||
MixinVelodrome,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinCurve(weth)
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CURVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV3(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.VELODROME) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeVelodrome(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.SYNTHETIX) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeSynthetix(
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./AbstractBridgeAdapter.sol";
|
||||
import "./BridgeProtocols.sol";
|
||||
import "./mixins/MixinAaveV2.sol";
|
||||
import "./mixins/MixinBalancerV2.sol";
|
||||
import "./mixins/MixinBalancerV2Batch.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
import "./mixins/MixinDodo.sol";
|
||||
import "./mixins/MixinDodoV2.sol";
|
||||
import "./mixins/MixinKyberDmm.sol";
|
||||
import "./mixins/MixinMStable.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinUniswapV3.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
contract PolygonBridgeAdapter is
|
||||
AbstractBridgeAdapter(137, "Polygon"),
|
||||
MixinAaveV2,
|
||||
MixinBalancerV2,
|
||||
MixinBalancerV2Batch,
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
MixinDodo,
|
||||
MixinDodoV2,
|
||||
MixinKyberDmm,
|
||||
MixinMStable,
|
||||
MixinNerve,
|
||||
MixinUniswapV2,
|
||||
MixinUniswapV3,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
MixinCurve(weth)
|
||||
{}
|
||||
|
||||
function _trade(
|
||||
BridgeOrder memory order,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bool dryRun
|
||||
)
|
||||
internal
|
||||
override
|
||||
returns (uint256 boughtAmount, bool supportedSource)
|
||||
{
|
||||
uint128 protocolId = uint128(uint256(order.source) >> 128);
|
||||
if (protocolId == BridgeProtocols.CURVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurve(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.CURVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeCurveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV3(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeUniswapV2(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BALANCERV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancerV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeBalancerV2Batch(
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.MSTABLE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeMStable(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODO) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodo(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.DODOV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeDodoV2(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeNerve(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.KYBERDMM) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeKyberDmm(
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.AAVEV2) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeAaveV2(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.WOOFI) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeWOOFi(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) { return (0, true); }
|
||||
boughtAmount = _tradeZeroExBridge(
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
order.bridgeData
|
||||
);
|
||||
}
|
||||
|
||||
emit BridgeFill(
|
||||
order.source,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
boughtAmount
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
|
||||
// Minimal Aave V2 LendingPool interface
|
||||
interface ILendingPool {
|
||||
/**
|
||||
* @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
|
||||
* - E.g. User deposits 100 USDC and gets in return 100 aUSDC
|
||||
* @param asset The address of the underlying asset to deposit
|
||||
* @param amount The amount to be deposited
|
||||
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
|
||||
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
|
||||
* is a different wallet
|
||||
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
|
||||
* 0 if the action is executed directly by the user, without any middle-man
|
||||
**/
|
||||
function deposit(
|
||||
address asset,
|
||||
uint256 amount,
|
||||
address onBehalfOf,
|
||||
uint16 referralCode
|
||||
) external;
|
||||
|
||||
/**
|
||||
* @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
|
||||
* E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
|
||||
* @param asset The address of the underlying asset to withdraw
|
||||
* @param amount The underlying amount to be withdrawn
|
||||
* - Send the value type(uint256).max in order to withdraw the whole aToken balance
|
||||
* @param to Address that will receive the underlying, same as msg.sender if the user
|
||||
* wants to receive it on his own wallet, or a different address if the beneficiary is a
|
||||
* different wallet
|
||||
* @return The final amount withdrawn
|
||||
**/
|
||||
function withdraw(
|
||||
address asset,
|
||||
uint256 amount,
|
||||
address to
|
||||
) external returns (uint256);
|
||||
}
|
||||
|
||||
contract MixinAaveV2 {
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
function _tradeAaveV2(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256)
|
||||
{
|
||||
(ILendingPool lendingPool, address aToken) = abi.decode(bridgeData, (ILendingPool, address));
|
||||
|
||||
sellToken.approveIfBelow(
|
||||
address(lendingPool),
|
||||
sellAmount
|
||||
);
|
||||
|
||||
if (address(buyToken) == aToken) {
|
||||
lendingPool.deposit(address(sellToken), sellAmount, address(this), 0);
|
||||
// 1:1 mapping token -> aToken and have the same number of decimals as the underlying token
|
||||
return sellAmount;
|
||||
} else if (address(sellToken) == aToken) {
|
||||
return lendingPool.withdraw(address(buyToken), sellAmount, address(this));
|
||||
}
|
||||
|
||||
revert("MixinAaveV2/UNSUPPORTED_TOKEN_PAIR");
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
|
||||
|
||||
interface IBalancerV2BatchSwapVault {
|
||||
|
||||
enum SwapKind { GIVEN_IN, GIVEN_OUT }
|
||||
|
||||
struct BatchSwapStep {
|
||||
bytes32 poolId;
|
||||
uint256 assetInIndex;
|
||||
uint256 assetOutIndex;
|
||||
uint256 amount;
|
||||
bytes userData;
|
||||
}
|
||||
|
||||
struct FundManagement {
|
||||
address sender;
|
||||
bool fromInternalBalance;
|
||||
address payable recipient;
|
||||
bool toInternalBalance;
|
||||
}
|
||||
|
||||
function batchSwap(
|
||||
SwapKind kind,
|
||||
BatchSwapStep[] calldata swaps,
|
||||
IERC20TokenV06[] calldata assets,
|
||||
FundManagement calldata funds,
|
||||
int256[] calldata limits,
|
||||
uint256 deadline
|
||||
) external returns (int256[] memory amounts);
|
||||
}
|
||||
|
||||
contract MixinBalancerV2Batch {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
struct BalancerV2BatchBridgeData {
|
||||
IBalancerV2BatchSwapVault vault;
|
||||
IBalancerV2BatchSwapVault.BatchSwapStep[] swapSteps;
|
||||
IERC20TokenV06[] assets;
|
||||
}
|
||||
|
||||
function _tradeBalancerV2Batch(
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
// Decode the bridge data.
|
||||
(
|
||||
IBalancerV2BatchSwapVault vault,
|
||||
IBalancerV2BatchSwapVault.BatchSwapStep[] memory swapSteps,
|
||||
address[] memory assets_
|
||||
) = abi.decode(bridgeData, (IBalancerV2BatchSwapVault, IBalancerV2BatchSwapVault.BatchSwapStep[], address[]));
|
||||
IERC20TokenV06[] memory assets;
|
||||
assembly { assets := assets_ }
|
||||
|
||||
// Grant an allowance to the exchange to spend `fromTokenAddress` token.
|
||||
assets[0].approveIfBelow(address(vault), sellAmount);
|
||||
|
||||
swapSteps[0].amount = sellAmount;
|
||||
int256[] memory limits = new int256[](assets.length);
|
||||
for (uint256 i = 0; i < limits.length; ++i) {
|
||||
limits[i] = type(int256).max;
|
||||
}
|
||||
|
||||
int256[] memory amounts = vault.batchSwap(
|
||||
IBalancerV2BatchSwapVault.SwapKind.GIVEN_IN,
|
||||
swapSteps,
|
||||
assets,
|
||||
IBalancerV2BatchSwapVault.FundManagement({
|
||||
sender: address(this),
|
||||
fromInternalBalance: false,
|
||||
recipient: payable(address(this)),
|
||||
toInternalBalance: false
|
||||
}),
|
||||
limits,
|
||||
block.timestamp + 1
|
||||
);
|
||||
require(amounts[amounts.length - 1] <= 0, 'Unexpected BalancerV2Batch output');
|
||||
return uint256(amounts[amounts.length - 1] * -1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
|
||||
|
||||
/*
|
||||
BancorV3
|
||||
*/
|
||||
interface IBancorV3 {
|
||||
/**
|
||||
* @dev performs a trade by providing the source amount and returns the target amount and the associated fee
|
||||
*
|
||||
* requirements:
|
||||
*
|
||||
* - the caller must be the network contract
|
||||
*/
|
||||
function tradeBySourceAmount(
|
||||
address sourceToken,
|
||||
address targetToken,
|
||||
uint256 sourceAmount,
|
||||
uint256 minReturnAmount,
|
||||
uint256 deadline,
|
||||
address beneficiary
|
||||
) external payable returns (uint256 amount);
|
||||
}
|
||||
|
||||
contract MixinBancorV3 {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
IERC20TokenV06 constant public BANCORV3_ETH_ADDRESS =
|
||||
IERC20TokenV06(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
||||
IEtherTokenV06 private immutable WETH;
|
||||
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
{
|
||||
WETH = weth;
|
||||
}
|
||||
|
||||
function _tradeBancorV3(
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 amountOut)
|
||||
|
||||
{
|
||||
IBancorV3 router;
|
||||
IERC20TokenV06[] memory path;
|
||||
address[] memory _path;
|
||||
uint256 payableAmount = 0;
|
||||
|
||||
{
|
||||
(router, _path) = abi.decode(bridgeData, (IBancorV3, address[]));
|
||||
// To get around `abi.decode()` not supporting interface array types.
|
||||
assembly { path := _path }
|
||||
}
|
||||
|
||||
require(path.length >= 2, "MixinBancorV3/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
|
||||
require(
|
||||
path[path.length - 1] == buyToken,
|
||||
"MixinBancorV3/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
|
||||
);
|
||||
|
||||
//swap WETH->ETH as Bancor only deals in ETH
|
||||
if(_path[0] == address(WETH)) {
|
||||
//withdraw the sell amount of WETH for ETH
|
||||
WETH.withdraw(sellAmount);
|
||||
payableAmount = sellAmount;
|
||||
// set _path[0] to the ETH address if WETH is our buy token
|
||||
_path[0] = address(BANCORV3_ETH_ADDRESS);
|
||||
} else {
|
||||
// Grant the BancorV3 router an allowance to sell the first token.
|
||||
path[0].approveIfBelow(address(router), sellAmount);
|
||||
}
|
||||
|
||||
// if we are buying WETH we need to swap to ETH and deposit into WETH after the swap
|
||||
if(_path[1] == address(WETH)){
|
||||
_path[1] = address(BANCORV3_ETH_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
uint256 amountOut = router.tradeBySourceAmount{value: payableAmount}(
|
||||
_path[0],
|
||||
_path[1],
|
||||
// Sell all tokens we hold.
|
||||
sellAmount,
|
||||
// Minimum buy amount.
|
||||
1,
|
||||
//deadline
|
||||
block.timestamp + 1,
|
||||
// address of the mixin
|
||||
address(this)
|
||||
);
|
||||
|
||||
// if we want to return WETH deposit the ETH amount we sold
|
||||
if(buyToken == WETH){
|
||||
WETH.deposit{value: amountOut}();
|
||||
}
|
||||
|
||||
return amountOut;
|
||||
}
|
||||
}
|
@@ -1,148 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "../IBridgeAdapter.sol";
|
||||
import "../../../vendor/ILiquidityProvider.sol";
|
||||
|
||||
contract MixinClipper {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
/// @dev Mainnet address of the WETH contract.
|
||||
IEtherTokenV06 private immutable WETH;
|
||||
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
{
|
||||
WETH = weth;
|
||||
}
|
||||
|
||||
function _tradeClipper(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
// We can only use ETH with Clipper, no WETH available
|
||||
(ILiquidityProvider clipper, bytes memory auxiliaryData) =
|
||||
abi.decode(bridgeData, (ILiquidityProvider, bytes));
|
||||
|
||||
if (sellToken == WETH) {
|
||||
boughtAmount = _executeSellEthForToken(
|
||||
clipper,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
auxiliaryData
|
||||
);
|
||||
} else if (buyToken == WETH) {
|
||||
boughtAmount = _executeSellTokenForEth(
|
||||
clipper,
|
||||
sellToken,
|
||||
sellAmount,
|
||||
auxiliaryData
|
||||
);
|
||||
} else {
|
||||
boughtAmount = _executeSellTokenForToken(
|
||||
clipper,
|
||||
sellToken,
|
||||
buyToken,
|
||||
sellAmount,
|
||||
auxiliaryData
|
||||
);
|
||||
}
|
||||
|
||||
return boughtAmount;
|
||||
}
|
||||
|
||||
function _executeSellEthForToken(
|
||||
ILiquidityProvider clipper,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory auxiliaryData
|
||||
)
|
||||
private
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
// Clipper requires ETH and doesn't support WETH
|
||||
WETH.withdraw(sellAmount);
|
||||
boughtAmount = clipper.sellEthForToken{ value: sellAmount }(
|
||||
buyToken,
|
||||
address(this),
|
||||
1,
|
||||
auxiliaryData
|
||||
);
|
||||
}
|
||||
|
||||
function _executeSellTokenForEth(
|
||||
ILiquidityProvider clipper,
|
||||
IERC20TokenV06 sellToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory auxiliaryData
|
||||
)
|
||||
private
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
// Optimization: We can transfer the tokens into clipper rather than
|
||||
// have an allowance updated
|
||||
sellToken.compatTransfer(address(clipper), sellAmount);
|
||||
|
||||
boughtAmount = clipper.sellTokenForEth(
|
||||
sellToken,
|
||||
payable(address(this)),
|
||||
1,
|
||||
auxiliaryData
|
||||
);
|
||||
|
||||
// we want WETH for possible future trades
|
||||
WETH.deposit{ value: boughtAmount }();
|
||||
}
|
||||
|
||||
function _executeSellTokenForToken(
|
||||
ILiquidityProvider clipper,
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory auxiliaryData
|
||||
)
|
||||
private
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
// Optimization: We can transfer the tokens into clipper rather than
|
||||
// have an allowance updated
|
||||
sellToken.compatTransfer(address(clipper), sellAmount);
|
||||
|
||||
boughtAmount = clipper.sellTokenForToken(
|
||||
sellToken,
|
||||
buyToken,
|
||||
address(this),
|
||||
1,
|
||||
auxiliaryData
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,92 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
|
||||
|
||||
interface ICoFiXRouter {
|
||||
// msg.value = fee
|
||||
function swapExactTokensForETH(
|
||||
address token,
|
||||
uint amountIn,
|
||||
uint amountOutMin,
|
||||
address to,
|
||||
address rewardTo,
|
||||
uint deadline
|
||||
) external payable returns (uint _amountIn, uint _amountOut);
|
||||
|
||||
// msg.value = amountIn + fee
|
||||
function swapExactETHForTokens(
|
||||
address token,
|
||||
uint amountIn,
|
||||
uint amountOutMin,
|
||||
address to,
|
||||
address rewardTo,
|
||||
uint deadline
|
||||
) external payable returns (uint _amountIn, uint _amountOut);
|
||||
}
|
||||
|
||||
interface ICoFiXPair {
|
||||
|
||||
function swapWithExact(address outToken, address to)
|
||||
external
|
||||
payable
|
||||
returns (
|
||||
uint amountIn,
|
||||
uint amountOut,
|
||||
uint oracleFeeChange,
|
||||
uint256[4] memory tradeInfo
|
||||
);
|
||||
}
|
||||
|
||||
contract MixinCoFiX {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
function _tradeCoFiX(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(uint256 fee, ICoFiXPair pool) = abi.decode(bridgeData, (uint256, ICoFiXPair));
|
||||
// Transfer tokens into the pool
|
||||
LibERC20TokenV06.compatTransfer(
|
||||
sellToken,
|
||||
address(pool),
|
||||
sellAmount
|
||||
);
|
||||
// Call the swap exact with the tokens now in the pool
|
||||
// pay the NEST Oracle fee with ETH
|
||||
(/* In */, boughtAmount, , ) = pool.swapWithExact{value: fee}(
|
||||
address(buyToken),
|
||||
address(this)
|
||||
);
|
||||
|
||||
return boughtAmount;
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
|
||||
|
||||
/// @dev Minimal CToken interface
|
||||
interface ICToken {
|
||||
/// @dev deposits specified amount underlying tokens and mints cToken for the sender
|
||||
/// @param mintAmountInUnderlying amount of underlying tokens to deposit to mint cTokens
|
||||
/// @return status code of whether the mint was successful or not
|
||||
function mint(uint256 mintAmountInUnderlying) external returns (uint256);
|
||||
/// @dev redeems specified amount of cTokens and returns the underlying token to the sender
|
||||
/// @param redeemTokensInCtokens amount of cTokens to redeem for underlying collateral
|
||||
/// @return status code of whether the redemption was successful or not
|
||||
function redeem(uint256 redeemTokensInCtokens) external returns (uint256);
|
||||
}
|
||||
/// @dev Minimal CEther interface
|
||||
interface ICEther {
|
||||
/// @dev deposits the amount of Ether sent as value and return mints cEther for the sender
|
||||
function mint() payable external;
|
||||
/// @dev redeems specified amount of cETH and returns the underlying ether to the sender
|
||||
/// @dev redeemTokensInCEther amount of cETH to redeem for underlying ether
|
||||
/// @return status code of whether the redemption was successful or not
|
||||
function redeem(uint256 redeemTokensInCEther) external returns (uint256);
|
||||
}
|
||||
|
||||
contract MixinCompound {
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
|
||||
IEtherTokenV06 private immutable WETH;
|
||||
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
{
|
||||
WETH = weth;
|
||||
}
|
||||
|
||||
uint256 constant private COMPOUND_SUCCESS_CODE = 0;
|
||||
|
||||
function _tradeCompound(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256)
|
||||
{
|
||||
(address cTokenAddress) = abi.decode(bridgeData, (address));
|
||||
uint256 beforeBalance = buyToken.balanceOf(address(this));
|
||||
|
||||
if (address(buyToken) == cTokenAddress) {
|
||||
if (address(sellToken) == address(WETH)) {
|
||||
// ETH/WETH -> cETH
|
||||
ICEther cETH = ICEther(cTokenAddress);
|
||||
// Compound expects ETH to be sent with mint call
|
||||
WETH.withdraw(sellAmount);
|
||||
// NOTE: cETH mint will revert on failure instead of returning a status code
|
||||
cETH.mint{value: sellAmount}();
|
||||
} else {
|
||||
sellToken.approveIfBelow(
|
||||
cTokenAddress,
|
||||
sellAmount
|
||||
);
|
||||
// Token -> cToken
|
||||
ICToken cToken = ICToken(cTokenAddress);
|
||||
require(cToken.mint(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_MINT_CTOKEN");
|
||||
}
|
||||
} else if (address(sellToken) == cTokenAddress) {
|
||||
if (address(buyToken) == address(WETH)) {
|
||||
// cETH -> ETH/WETH
|
||||
uint256 etherBalanceBefore = address(this).balance;
|
||||
ICEther cETH = ICEther(cTokenAddress);
|
||||
require(cETH.redeem(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_REDEEM_CETHER");
|
||||
uint256 etherBalanceAfter = address(this).balance;
|
||||
uint256 receivedEtherBalance = etherBalanceAfter.safeSub(etherBalanceBefore);
|
||||
WETH.deposit{value: receivedEtherBalance}();
|
||||
} else {
|
||||
ICToken cToken = ICToken(cTokenAddress);
|
||||
require(cToken.redeem(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_REDEEM_CTOKEN");
|
||||
}
|
||||
}
|
||||
|
||||
return buyToken.balanceOf(address(this)).safeSub(beforeBalance);
|
||||
}
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "../IBridgeAdapter.sol";
|
||||
|
||||
/*
|
||||
UniswapV2
|
||||
*/
|
||||
interface IGmxRouter {
|
||||
|
||||
// /// @dev Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path.
|
||||
// /// The first element of path is the input token, the last is the output token, and any intermediate elements represent
|
||||
// /// intermediate pairs to trade through (if, for example, a direct pair does not exist).
|
||||
// /// @param _path An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
|
||||
// /// @param _amountIn The amount of input tokens to send.
|
||||
// /// @param _minOut The minimum amount of output tokens that must be received for the transaction not to revert.
|
||||
// /// @param _reciever Recipient of the output tokens.
|
||||
function swap(
|
||||
address[] calldata _path, uint256 _amountIn, uint256 _minOut, address _receiver
|
||||
) external;
|
||||
}
|
||||
|
||||
contract MixinGMX {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
|
||||
function _tradeGMX(
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
public
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
address _router;
|
||||
address reader;
|
||||
address vault;
|
||||
address[] memory _path;
|
||||
IGmxRouter router;
|
||||
IERC20TokenV06[] memory path;
|
||||
|
||||
{
|
||||
//decode the bridge data
|
||||
(_router, reader, vault, _path) = abi.decode(bridgeData, (address, address, address, address[]));
|
||||
// To get around `abi.decode()` not supporting interface array types.
|
||||
assembly { path := _path }
|
||||
}
|
||||
|
||||
require(path.length >= 2, "MixinGMX/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
|
||||
require(
|
||||
path[path.length - 1] == buyToken,
|
||||
"MixinGMX/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
|
||||
);
|
||||
|
||||
//connect to the GMX router
|
||||
router = IGmxRouter(_router);
|
||||
|
||||
// Grant the GMX router an allowance to sell the first token.
|
||||
path[0].approveIfBelow(address(router), sellAmount);
|
||||
|
||||
//track the balance to know how much we bought
|
||||
uint256 beforeBalance = buyToken.balanceOf(address(this));
|
||||
router.swap(
|
||||
// Convert to `buyToken` along this path.
|
||||
_path,
|
||||
// Sell all tokens we hold.
|
||||
sellAmount,
|
||||
// Minimum buy amount.
|
||||
0,
|
||||
// Recipient is `this`.
|
||||
address(this)
|
||||
);
|
||||
|
||||
//calculate the difference in balance from preswap->postswap to find how many tokens out
|
||||
boughtAmount = buyToken.balanceOf(address(this)).safeSub(beforeBalance);
|
||||
|
||||
return boughtAmount;
|
||||
}
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "../IBridgeAdapter.sol";
|
||||
|
||||
interface IKyberNetworkProxy {
|
||||
|
||||
/// @dev Sells `sellTokenAddress` tokens for `buyTokenAddress` tokens
|
||||
/// using a hint for the reserve.
|
||||
/// @param sellToken Token to sell.
|
||||
/// @param sellAmount Amount of tokens to sell.
|
||||
/// @param buyToken Token to buy.
|
||||
/// @param recipientAddress Address to send bought tokens to.
|
||||
/// @param maxBuyTokenAmount A limit on the amount of tokens to buy.
|
||||
/// @param minConversionRate The minimal conversion rate. If actual rate
|
||||
/// is lower, trade is canceled.
|
||||
/// @param walletId The wallet ID to send part of the fees
|
||||
/// @param hint The hint for the selective inclusion (or exclusion) of reserves
|
||||
/// @return boughtAmount Amount of tokens bought.
|
||||
function tradeWithHint(
|
||||
IERC20TokenV06 sellToken,
|
||||
uint256 sellAmount,
|
||||
IERC20TokenV06 buyToken,
|
||||
address payable recipientAddress,
|
||||
uint256 maxBuyTokenAmount,
|
||||
uint256 minConversionRate,
|
||||
address payable walletId,
|
||||
bytes calldata hint
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (uint256 boughtAmount);
|
||||
}
|
||||
|
||||
contract MixinKyber {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
/// @dev Address indicating the trade is using ETH
|
||||
IERC20TokenV06 private immutable KYBER_ETH_ADDRESS =
|
||||
IERC20TokenV06(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
||||
/// @dev Mainnet address of the WETH contract.
|
||||
IEtherTokenV06 private immutable WETH;
|
||||
|
||||
constructor(IEtherTokenV06 weth)
|
||||
public
|
||||
{
|
||||
WETH = weth;
|
||||
}
|
||||
|
||||
function _tradeKyber(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(IKyberNetworkProxy kyber, bytes memory hint) =
|
||||
abi.decode(bridgeData, (IKyberNetworkProxy, bytes));
|
||||
|
||||
uint256 payableAmount = 0;
|
||||
if (sellToken != WETH) {
|
||||
// If the input token is not WETH, grant an allowance to the exchange
|
||||
// to spend them.
|
||||
sellToken.approveIfBelow(
|
||||
address(kyber),
|
||||
sellAmount
|
||||
);
|
||||
} else {
|
||||
// If the input token is WETH, unwrap it and attach it to the call.
|
||||
payableAmount = sellAmount;
|
||||
WETH.withdraw(payableAmount);
|
||||
}
|
||||
|
||||
// Try to sell all of this contract's input token balance through
|
||||
// `KyberNetworkProxy.trade()`.
|
||||
boughtAmount = kyber.tradeWithHint{ value: payableAmount }(
|
||||
// Input token.
|
||||
sellToken == WETH ? KYBER_ETH_ADDRESS : sellToken,
|
||||
// Sell amount.
|
||||
sellAmount,
|
||||
// Output token.
|
||||
buyToken == WETH ? KYBER_ETH_ADDRESS : buyToken,
|
||||
// Transfer to this contract
|
||||
address(uint160(address(this))),
|
||||
// Buy as much as possible.
|
||||
uint256(-1),
|
||||
// Lowest minimum conversion rate
|
||||
1,
|
||||
// No affiliate address.
|
||||
address(0),
|
||||
hint
|
||||
);
|
||||
// If receving ETH, wrap it to WETH.
|
||||
if (buyToken == WETH) {
|
||||
WETH.deposit{ value: boughtAmount }();
|
||||
}
|
||||
return boughtAmount;
|
||||
}
|
||||
}
|
@@ -26,7 +26,7 @@ import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
|
||||
|
||||
/// @dev Minimal interface for minting StETH
|
||||
interface ILido {
|
||||
interface IStETH {
|
||||
/// @dev Adds eth to the pool
|
||||
/// @param _referral optional address for referrals
|
||||
/// @return StETH Amount of shares generated
|
||||
@@ -37,6 +37,33 @@ interface ILido {
|
||||
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
|
||||
}
|
||||
|
||||
/// @dev Minimal interface for wrapping/unwrapping stETH.
|
||||
interface IWstETH {
|
||||
|
||||
/**
|
||||
* @notice Exchanges stETH to wstETH
|
||||
* @param _stETHAmount amount of stETH to wrap in exchange for wstETH
|
||||
* @dev Requirements:
|
||||
* - `_stETHAmount` must be non-zero
|
||||
* - msg.sender must approve at least `_stETHAmount` stETH to this
|
||||
* contract.
|
||||
* - msg.sender must have at least `_stETHAmount` of stETH.
|
||||
* User should first approve _stETHAmount to the WstETH contract
|
||||
* @return Amount of wstETH user receives after wrap
|
||||
*/
|
||||
function wrap(uint256 _stETHAmount) external returns (uint256);
|
||||
|
||||
/**
|
||||
* @notice Exchanges wstETH to stETH
|
||||
* @param _wstETHAmount amount of wstETH to uwrap in exchange for stETH
|
||||
* @dev Requirements:
|
||||
* - `_wstETHAmount` must be non-zero
|
||||
* - msg.sender must have at least `_wstETHAmount` wstETH.
|
||||
* @return Amount of stETH user receives after unwrap
|
||||
*/
|
||||
function unwrap(uint256 _wstETHAmount) external returns (uint256);
|
||||
}
|
||||
|
||||
|
||||
contract MixinLido {
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
@@ -59,12 +86,43 @@ contract MixinLido {
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(ILido lido) = abi.decode(bridgeData, (ILido));
|
||||
if (address(sellToken) == address(WETH) && address(buyToken) == address(lido)) {
|
||||
if (address(sellToken) == address(WETH)) {
|
||||
return _tradeStETH(buyToken, sellAmount, bridgeData);
|
||||
}
|
||||
|
||||
return _tradeWstETH(sellToken, buyToken, sellAmount, bridgeData);
|
||||
}
|
||||
|
||||
function _tradeStETH(
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
) private returns (uint256 boughtAmount) {
|
||||
(IStETH stETH) = abi.decode(bridgeData, (IStETH));
|
||||
if (address(buyToken) == address(stETH)) {
|
||||
WETH.withdraw(sellAmount);
|
||||
boughtAmount = lido.getPooledEthByShares(lido.submit{ value: sellAmount}(address(0)));
|
||||
} else {
|
||||
revert("MixinLido/UNSUPPORTED_TOKEN_PAIR");
|
||||
return stETH.getPooledEthByShares(stETH.submit{ value: sellAmount}(address(0)));
|
||||
}
|
||||
|
||||
revert("MixinLido/UNSUPPORTED_TOKEN_PAIR");
|
||||
}
|
||||
|
||||
function _tradeWstETH(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
|
||||
) private returns(uint256 boughtAmount){
|
||||
(IEtherTokenV06 stETH, IWstETH wstETH) = abi.decode(bridgeData, (IEtherTokenV06, IWstETH));
|
||||
if (address(sellToken) == address(stETH) && address(buyToken) == address(wstETH) ) {
|
||||
sellToken.approveIfBelow(address(wstETH), sellAmount);
|
||||
return wstETH.wrap(sellAmount);
|
||||
}
|
||||
if (address(sellToken) == address(wstETH) && address(buyToken) == address(stETH) ) {
|
||||
return wstETH.unwrap(sellAmount);
|
||||
}
|
||||
|
||||
revert("MixinLido/UNSUPPORTED_TOKEN_PAIR");
|
||||
}
|
||||
}
|
||||
|
@@ -1,76 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../IBridgeAdapter.sol";
|
||||
|
||||
interface IOasis {
|
||||
|
||||
/// @dev Sell `sellAmount` of `sellToken` token and receive `buyToken` token.
|
||||
/// @param sellToken The token being sold.
|
||||
/// @param sellAmount The amount of `sellToken` token being sold.
|
||||
/// @param buyToken The token being bought.
|
||||
/// @param minBoughtAmount Minimum amount of `buyToken` token to buy.
|
||||
/// @return boughtAmount Amount of `buyToken` bought.
|
||||
function sellAllAmount(
|
||||
IERC20TokenV06 sellToken,
|
||||
uint256 sellAmount,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 minBoughtAmount
|
||||
)
|
||||
external
|
||||
returns (uint256 boughtAmount);
|
||||
}
|
||||
|
||||
contract MixinOasis {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
function _tradeOasis(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
|
||||
(IOasis oasis) = abi.decode(bridgeData, (IOasis));
|
||||
|
||||
// Grant an allowance to the exchange to spend `sellToken` token.
|
||||
sellToken.approveIfBelow(
|
||||
address(oasis),
|
||||
sellAmount
|
||||
);
|
||||
// Try to sell all of this contract's `sellToken` token balance.
|
||||
boughtAmount = oasis.sellAllAmount(
|
||||
sellToken,
|
||||
sellAmount,
|
||||
buyToken,
|
||||
// min fill amount
|
||||
1
|
||||
);
|
||||
return boughtAmount;
|
||||
}
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
|
||||
|
||||
interface IPlatypusRouter {
|
||||
|
||||
function swapTokensForTokens(
|
||||
address[] calldata tokenPath,
|
||||
address[] calldata poolPath,
|
||||
uint256 fromAmount,
|
||||
uint256 minimumToAmount,
|
||||
address to,
|
||||
uint256 deadline
|
||||
) external returns (uint256 amountOut, uint256 haircut);
|
||||
}
|
||||
|
||||
contract MixinPlatypus {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
|
||||
function _tradePlatypus(
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
public
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
IPlatypusRouter router;
|
||||
address _router;
|
||||
address[] memory _pool;
|
||||
IERC20TokenV06[] memory path;
|
||||
address[] memory _path;
|
||||
|
||||
{
|
||||
(_router, _pool, _path) = abi.decode(bridgeData, (address, address[], address[]));
|
||||
|
||||
// To get around `abi.decode()` not supporting interface array types.
|
||||
assembly { path := _path }
|
||||
}
|
||||
|
||||
//connect to the ptp router
|
||||
router = IPlatypusRouter(_router);
|
||||
|
||||
require(path.length >= 2, "MixinPlatypus/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
|
||||
require(
|
||||
path[path.length - 1] == buyToken,
|
||||
"MixinPlatypus/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
|
||||
);
|
||||
// Grant the Platypus router an allowance to sell the first token.
|
||||
path[0].approveIfBelow(address(router), sellAmount);
|
||||
|
||||
//keep track of the previous balance to confirm amount out
|
||||
uint256 beforeBalance = buyToken.balanceOf(address(this));
|
||||
|
||||
router.swapTokensForTokens(
|
||||
// Convert to `buyToken` along this path.
|
||||
_path,
|
||||
// pool to swap on
|
||||
_pool,
|
||||
// Sell all tokens we hold.
|
||||
sellAmount,
|
||||
// Minimum buy amount.
|
||||
0,
|
||||
// Recipient is `this`.
|
||||
address(this),
|
||||
|
||||
block.timestamp + 1
|
||||
);
|
||||
//calculate the buy amount from the tokens we recieved
|
||||
boughtAmount = buyToken.balanceOf(address(this)).safeSub(beforeBalance);
|
||||
return boughtAmount;
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface ISynthetix {
|
||||
// Ethereum Mainnet
|
||||
function exchangeAtomically(
|
||||
bytes32 sourceCurrencyKey,
|
||||
uint256 sourceAmount,
|
||||
bytes32 destinationCurrencyKey,
|
||||
bytes32 trackingCode,
|
||||
uint256 minAmount
|
||||
) external returns (uint256 amountReceived);
|
||||
|
||||
// Optimism
|
||||
function exchangeWithTracking(
|
||||
bytes32 sourceCurrencyKey,
|
||||
uint256 sourceAmount,
|
||||
bytes32 destinationCurrencyKey,
|
||||
address rewardAddress,
|
||||
bytes32 trackingCode
|
||||
) external returns (uint256 amountReceived);
|
||||
}
|
||||
|
||||
contract MixinSynthetix {
|
||||
address private constant rewardAddress =
|
||||
0x5C80239D97E1eB216b5c3D8fBa5DE5Be5d38e4C9;
|
||||
bytes32 constant trackingCode =
|
||||
0x3058000000000000000000000000000000000000000000000000000000000000;
|
||||
|
||||
function _tradeSynthetix(uint256 sellAmount, bytes memory bridgeData)
|
||||
public
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(
|
||||
ISynthetix synthetix,
|
||||
bytes32 sourceCurrencyKey,
|
||||
bytes32 destinationCurrencyKey
|
||||
) = abi.decode(
|
||||
bridgeData,
|
||||
(ISynthetix, bytes32, bytes32)
|
||||
);
|
||||
|
||||
boughtAmount = exchange(
|
||||
synthetix,
|
||||
sourceCurrencyKey,
|
||||
destinationCurrencyKey,
|
||||
sellAmount
|
||||
);
|
||||
}
|
||||
|
||||
function exchange(
|
||||
ISynthetix synthetix,
|
||||
bytes32 sourceCurrencyKey,
|
||||
bytes32 destinationCurrencyKey,
|
||||
uint256 sellAmount
|
||||
) internal returns (uint256 boughtAmount) {
|
||||
uint256 chainId;
|
||||
assembly {
|
||||
chainId := chainid()
|
||||
}
|
||||
|
||||
if (chainId == 1) {
|
||||
boughtAmount = synthetix.exchangeAtomically(
|
||||
sourceCurrencyKey,
|
||||
sellAmount,
|
||||
destinationCurrencyKey,
|
||||
trackingCode,
|
||||
0
|
||||
);
|
||||
} else {
|
||||
boughtAmount = synthetix.exchangeWithTracking(
|
||||
sourceCurrencyKey,
|
||||
sellAmount,
|
||||
destinationCurrencyKey,
|
||||
rewardAddress,
|
||||
trackingCode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
|
||||
interface IVelodromeRouter {
|
||||
function swapExactTokensForTokensSimple(
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin,
|
||||
address tokenFrom,
|
||||
address tokenTo,
|
||||
bool stable,
|
||||
address to,
|
||||
uint256 deadline
|
||||
) external returns (uint256[] memory amounts);
|
||||
}
|
||||
|
||||
contract MixinVelodrome {
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
function _tradeVelodrome(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
internal
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
|
||||
(IVelodromeRouter router, bool stable) = abi.decode(bridgeData, (IVelodromeRouter, bool));
|
||||
sellToken.approveIfBelow(address(router), sellAmount);
|
||||
|
||||
boughtAmount = router.swapExactTokensForTokensSimple(
|
||||
sellAmount,
|
||||
0,
|
||||
address(sellToken),
|
||||
address(buyToken),
|
||||
stable,
|
||||
address(this),
|
||||
block.timestamp + 1
|
||||
)[1];
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
Copyright 2020 ZeroEx Intl.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
||||
import "../IBridgeAdapter.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
|
||||
/// @dev WooFI pool interface.
|
||||
interface IWooPP {
|
||||
function quoteToken() external view returns (address);
|
||||
|
||||
function sellBase(
|
||||
address baseToken,
|
||||
uint256 baseAmount,
|
||||
uint256 minQuoteAmount,
|
||||
address to,
|
||||
address rebateTo
|
||||
) external returns (uint256 quoteAmount);
|
||||
|
||||
function sellQuote(
|
||||
address baseToken,
|
||||
uint256 quoteAmount,
|
||||
uint256 minBaseAmount,
|
||||
address to,
|
||||
address rebateTo
|
||||
) external returns (uint256 baseAmount);
|
||||
|
||||
/// @dev Query the amount for selling the base token amount.
|
||||
/// @param baseToken the base token to sell
|
||||
/// @param baseAmount the amount to sell
|
||||
/// @return quoteAmount the swapped quote amount
|
||||
function querySellBase(
|
||||
address baseToken,
|
||||
uint256 baseAmount
|
||||
) external view returns (uint256 quoteAmount);
|
||||
|
||||
}
|
||||
|
||||
contract MixinWOOFi{
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibERC20TokenV06 for IEtherTokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
|
||||
address constant rebateAddress = 0xBfdcBB4C05843163F491C24f9c0019c510786304;
|
||||
|
||||
// /// @dev Swaps an exact amount of input tokens for as many output tokens as possible.
|
||||
// /// @param _amountIn Amount of input tokens to send
|
||||
// /// @param _minAmountOut The minimum amount of output tokens that must be received for the transaction not to revert.
|
||||
// /// @param _tokenIn Input token
|
||||
// /// @param _tokenOut Output token
|
||||
// /// @param _to recipient of tokens
|
||||
// /// @param pool WOOFi pool where the swap will happen
|
||||
function _tradeWOOFi(
|
||||
IERC20TokenV06 sellToken,
|
||||
IERC20TokenV06 buyToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
)
|
||||
public
|
||||
returns (uint256 boughtAmount)
|
||||
{
|
||||
(IWooPP _pool) = abi.decode(bridgeData, (IWooPP));
|
||||
uint256 beforeBalance = buyToken.balanceOf(address(this));
|
||||
|
||||
sellToken.approveIfBelow(address(_pool), sellAmount);
|
||||
|
||||
_swap(
|
||||
sellAmount,
|
||||
address(sellToken),
|
||||
address(buyToken),
|
||||
_pool
|
||||
);
|
||||
boughtAmount = buyToken.balanceOf(address(this)).safeSub(beforeBalance);
|
||||
}
|
||||
|
||||
function _swap(
|
||||
uint _amountIn,
|
||||
address _tokenIn,
|
||||
address _tokenOut,
|
||||
IWooPP pool
|
||||
) internal {
|
||||
address quoteToken = pool.quoteToken();
|
||||
if (_tokenIn == quoteToken) {
|
||||
pool.sellQuote(
|
||||
_tokenOut,
|
||||
_amountIn,
|
||||
1,
|
||||
address(this),
|
||||
rebateAddress
|
||||
);
|
||||
} else if (_tokenOut == quoteToken) {
|
||||
pool.sellBase(
|
||||
_tokenIn,
|
||||
_amountIn,
|
||||
1,
|
||||
address(this),
|
||||
rebateAddress
|
||||
);
|
||||
} else {
|
||||
uint256 quoteAmount = pool.sellBase(
|
||||
_tokenIn,
|
||||
_amountIn,
|
||||
0,
|
||||
address(this),
|
||||
rebateAddress
|
||||
);
|
||||
IERC20TokenV06(pool.quoteToken()).approveIfBelow(address(pool), quoteAmount);
|
||||
pool.sellQuote(
|
||||
_tokenOut,
|
||||
quoteAmount,
|
||||
1,
|
||||
address(this),
|
||||
rebateAddress
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
151
contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol
vendored
Normal file
151
contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface IERC1155Token {
|
||||
|
||||
/// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred,
|
||||
/// including zero value transfers as well as minting or burning.
|
||||
/// Operator will always be msg.sender.
|
||||
/// Either event from address `0x0` signifies a minting operation.
|
||||
/// An event to address `0x0` signifies a burning or melting operation.
|
||||
/// The total value transferred from address 0x0 minus the total value transferred to 0x0 may
|
||||
/// be used by clients and exchanges to be added to the "circulating supply" for a given token ID.
|
||||
/// To define a token ID with no initial balance, the contract SHOULD emit the TransferSingle event
|
||||
/// from `0x0` to `0x0`, with the token creator as `_operator`.
|
||||
event TransferSingle(
|
||||
address indexed operator,
|
||||
address indexed from,
|
||||
address indexed to,
|
||||
uint256 id,
|
||||
uint256 value
|
||||
);
|
||||
|
||||
/// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred,
|
||||
/// including zero value transfers as well as minting or burning.
|
||||
///Operator will always be msg.sender.
|
||||
/// Either event from address `0x0` signifies a minting operation.
|
||||
/// An event to address `0x0` signifies a burning or melting operation.
|
||||
/// The total value transferred from address 0x0 minus the total value transferred to 0x0 may
|
||||
/// be used by clients and exchanges to be added to the "circulating supply" for a given token ID.
|
||||
/// To define multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event
|
||||
/// from `0x0` to `0x0`, with the token creator as `_operator`.
|
||||
event TransferBatch(
|
||||
address indexed operator,
|
||||
address indexed from,
|
||||
address indexed to,
|
||||
uint256[] ids,
|
||||
uint256[] values
|
||||
);
|
||||
|
||||
/// @dev MUST emit when an approval is updated.
|
||||
event ApprovalForAll(
|
||||
address indexed owner,
|
||||
address indexed operator,
|
||||
bool approved
|
||||
);
|
||||
|
||||
/// @dev MUST emit when the URI is updated for a token ID.
|
||||
/// URIs are defined in RFC 3986.
|
||||
/// The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema".
|
||||
event URI(
|
||||
string value,
|
||||
uint256 indexed id
|
||||
);
|
||||
|
||||
/// @notice Transfers value amount of an _id from the _from address to the _to address specified.
|
||||
/// @dev MUST emit TransferSingle event on success.
|
||||
/// Caller must be approved to manage the _from account's tokens (see isApprovedForAll).
|
||||
/// MUST throw if `_to` is the zero address.
|
||||
/// MUST throw if balance of sender for token `_id` is lower than the `_value` sent.
|
||||
/// MUST throw on any other error.
|
||||
/// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0).
|
||||
/// If so, it MUST call `onERC1155Received` on `_to` and revert if the return value
|
||||
/// is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`.
|
||||
/// @param from Source address
|
||||
/// @param to Target address
|
||||
/// @param id ID of the token type
|
||||
/// @param value Transfer amount
|
||||
/// @param data Additional data with no specified format, sent in call to `_to`
|
||||
function safeTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
)
|
||||
external;
|
||||
|
||||
/// @notice Send multiple types of Tokens from a 3rd party in one transfer (with safety call).
|
||||
/// @dev MUST emit TransferBatch event on success.
|
||||
/// Caller must be approved to manage the _from account's tokens (see isApprovedForAll).
|
||||
/// MUST throw if `_to` is the zero address.
|
||||
/// MUST throw if length of `_ids` is not the same as length of `_values`.
|
||||
/// MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent.
|
||||
/// MUST throw on any other error.
|
||||
/// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0).
|
||||
/// If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value
|
||||
/// is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`.
|
||||
/// @param from Source addresses
|
||||
/// @param to Target addresses
|
||||
/// @param ids IDs of each token type
|
||||
/// @param values Transfer amounts per token type
|
||||
/// @param data Additional data with no specified format, sent in call to `_to`
|
||||
function safeBatchTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256[] calldata ids,
|
||||
uint256[] calldata values,
|
||||
bytes calldata data
|
||||
)
|
||||
external;
|
||||
|
||||
/// @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
|
||||
/// @dev MUST emit the ApprovalForAll event on success.
|
||||
/// @param operator Address to add to the set of authorized operators
|
||||
/// @param approved True if the operator is approved, false to revoke approval
|
||||
function setApprovalForAll(address operator, bool approved) external;
|
||||
|
||||
/// @notice Queries the approval status of an operator for a given owner.
|
||||
/// @param owner The owner of the Tokens
|
||||
/// @param operator Address of authorized operator
|
||||
/// @return isApproved True if the operator is approved, false if not
|
||||
function isApprovedForAll(address owner, address operator) external view returns (bool isApproved);
|
||||
|
||||
/// @notice Get the balance of an account's Tokens.
|
||||
/// @param owner The address of the token holder
|
||||
/// @param id ID of the Token
|
||||
/// @return balance The _owner's balance of the Token type requested
|
||||
function balanceOf(address owner, uint256 id) external view returns (uint256 balance);
|
||||
|
||||
/// @notice Get the balance of multiple account/token pairs
|
||||
/// @param owners The addresses of the token holders
|
||||
/// @param ids ID of the Tokens
|
||||
/// @return balances_ The _owner's balance of the Token types requested
|
||||
function balanceOfBatch(
|
||||
address[] calldata owners,
|
||||
uint256[] calldata ids
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory balances_);
|
||||
}
|
159
contracts/zero-ex/contracts/src/vendor/IERC721Token.sol
vendored
Normal file
159
contracts/zero-ex/contracts/src/vendor/IERC721Token.sol
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
|
||||
|
||||
interface IERC721Token {
|
||||
|
||||
/// @dev This emits when ownership of any NFT changes by any mechanism.
|
||||
/// This event emits when NFTs are created (`from` == 0) and destroyed
|
||||
/// (`to` == 0). Exception: during contract creation, any number of NFTs
|
||||
/// may be created and assigned without emitting Transfer. At the time of
|
||||
/// any transfer, the approved address for that NFT (if any) is reset to none.
|
||||
event Transfer(
|
||||
address indexed _from,
|
||||
address indexed _to,
|
||||
uint256 indexed _tokenId
|
||||
);
|
||||
|
||||
/// @dev This emits when the approved address for an NFT is changed or
|
||||
/// reaffirmed. The zero address indicates there is no approved address.
|
||||
/// When a Transfer event emits, this also indicates that the approved
|
||||
/// address for that NFT (if any) is reset to none.
|
||||
event Approval(
|
||||
address indexed _owner,
|
||||
address indexed _approved,
|
||||
uint256 indexed _tokenId
|
||||
);
|
||||
|
||||
/// @dev This emits when an operator is enabled or disabled for an owner.
|
||||
/// The operator can manage all NFTs of the owner.
|
||||
event ApprovalForAll(
|
||||
address indexed _owner,
|
||||
address indexed _operator,
|
||||
bool _approved
|
||||
);
|
||||
|
||||
/// @notice Transfers the ownership of an NFT from one address to another address
|
||||
/// @dev Throws unless `msg.sender` is the current owner, an authorized
|
||||
/// perator, or the approved address for this NFT. Throws if `_from` is
|
||||
/// not the current owner. Throws if `_to` is the zero address. Throws if
|
||||
/// `_tokenId` is not a valid NFT. When transfer is complete, this function
|
||||
/// checks if `_to` is a smart contract (code size > 0). If so, it calls
|
||||
/// `onERC721Received` on `_to` and throws if the return value is not
|
||||
/// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
|
||||
/// @param _from The current owner of the NFT
|
||||
/// @param _to The new owner
|
||||
/// @param _tokenId The NFT to transfer
|
||||
/// @param _data Additional data with no specified format, sent in call to `_to`
|
||||
function safeTransferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _tokenId,
|
||||
bytes calldata _data
|
||||
)
|
||||
external;
|
||||
|
||||
/// @notice Transfers the ownership of an NFT from one address to another address
|
||||
/// @dev This works identically to the other function with an extra data parameter,
|
||||
/// except this function just sets data to "".
|
||||
/// @param _from The current owner of the NFT
|
||||
/// @param _to The new owner
|
||||
/// @param _tokenId The NFT to transfer
|
||||
function safeTransferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _tokenId
|
||||
)
|
||||
external;
|
||||
|
||||
/// @notice Change or reaffirm the approved address for an NFT
|
||||
/// @dev The zero address indicates there is no approved address.
|
||||
/// Throws unless `msg.sender` is the current NFT owner, or an authorized
|
||||
/// operator of the current owner.
|
||||
/// @param _approved The new approved NFT controller
|
||||
/// @param _tokenId The NFT to approve
|
||||
function approve(address _approved, uint256 _tokenId)
|
||||
external;
|
||||
|
||||
/// @notice Enable or disable approval for a third party ("operator") to manage
|
||||
/// all of `msg.sender`'s assets
|
||||
/// @dev Emits the ApprovalForAll event. The contract MUST allow
|
||||
/// multiple operators per owner.
|
||||
/// @param _operator Address to add to the set of authorized operators
|
||||
/// @param _approved True if the operator is approved, false to revoke approval
|
||||
function setApprovalForAll(address _operator, bool _approved)
|
||||
external;
|
||||
|
||||
/// @notice Count all NFTs assigned to an owner
|
||||
/// @dev NFTs assigned to the zero address are considered invalid, and this
|
||||
/// function throws for queries about the zero address.
|
||||
/// @param _owner An address for whom to query the balance
|
||||
/// @return The number of NFTs owned by `_owner`, possibly zero
|
||||
function balanceOf(address _owner)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
|
||||
/// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
|
||||
/// THEY MAY BE PERMANENTLY LOST
|
||||
/// @dev Throws unless `msg.sender` is the current owner, an authorized
|
||||
/// operator, or the approved address for this NFT. Throws if `_from` is
|
||||
/// not the current owner. Throws if `_to` is the zero address. Throws if
|
||||
/// `_tokenId` is not a valid NFT.
|
||||
/// @param _from The current owner of the NFT
|
||||
/// @param _to The new owner
|
||||
/// @param _tokenId The NFT to transfer
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _tokenId
|
||||
)
|
||||
external;
|
||||
|
||||
/// @notice Find the owner of an NFT
|
||||
/// @dev NFTs assigned to zero address are considered invalid, and queries
|
||||
/// about them do throw.
|
||||
/// @param _tokenId The identifier for an NFT
|
||||
/// @return The address of the owner of the NFT
|
||||
function ownerOf(uint256 _tokenId)
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
|
||||
/// @notice Get the approved address for a single NFT
|
||||
/// @dev Throws if `_tokenId` is not a valid NFT.
|
||||
/// @param _tokenId The NFT to find the approved address for
|
||||
/// @return The approved address for this NFT, or the zero address if there is none
|
||||
function getApproved(uint256 _tokenId)
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
|
||||
/// @notice Query if an address is an authorized operator for another address
|
||||
/// @param _owner The address that owns the NFTs
|
||||
/// @param _operator The address that acts on behalf of the owner
|
||||
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
|
||||
function isApprovedForAll(address _owner, address _operator)
|
||||
external
|
||||
view
|
||||
returns (bool);
|
||||
}
|
44
contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol
vendored
Normal file
44
contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface IFeeRecipient {
|
||||
|
||||
/// @dev A callback function invoked in the ERC721Feature for each ERC721
|
||||
/// order fee that get paid. Integrators can make use of this callback
|
||||
/// to implement arbitrary fee-handling logic, e.g. splitting the fee
|
||||
/// between multiple parties.
|
||||
/// @param tokenAddress The address of the token in which the received fee is
|
||||
/// denominated. `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` indicates
|
||||
/// that the fee was paid in the native token (e.g. ETH).
|
||||
/// @param amount The amount of the given token received.
|
||||
/// @param feeData Arbitrary data encoded in the `Fee` used by this callback.
|
||||
/// @return success The selector of this function (0x0190805e),
|
||||
/// indicating that the callback succeeded.
|
||||
function receiveZeroExFeeCallback(
|
||||
address tokenAddress,
|
||||
uint256 amount,
|
||||
bytes calldata feeData
|
||||
)
|
||||
external
|
||||
returns (bytes4 success);
|
||||
}
|
38
contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol
vendored
Normal file
38
contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface IPropertyValidator {
|
||||
|
||||
/// @dev Checks that the given ERC721/ERC1155 asset satisfies the properties encoded in `propertyData`.
|
||||
/// Should revert if the asset does not satisfy the specified properties.
|
||||
/// @param tokenAddress The ERC721/ERC1155 token contract address.
|
||||
/// @param tokenId The ERC721/ERC1155 tokenId of the asset to check.
|
||||
/// @param propertyData Encoded properties or auxiliary data needed to perform the check.
|
||||
function validateProperty(
|
||||
address tokenAddress,
|
||||
uint256 tokenId,
|
||||
bytes calldata propertyData
|
||||
)
|
||||
external
|
||||
view;
|
||||
}
|
40
contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol
vendored
Normal file
40
contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface ITakerCallback {
|
||||
|
||||
/// @dev A taker callback function invoked in ERC721OrdersFeature and
|
||||
/// ERC1155OrdersFeature between the maker -> taker transfer and
|
||||
/// the taker -> maker transfer.
|
||||
/// @param orderHash The hash of the order being filled when this
|
||||
/// callback is invoked.
|
||||
/// @param callbackData Arbitrary data used by this callback.
|
||||
/// @return success The selector of this function,
|
||||
/// indicating that the callback succeeded.
|
||||
function zeroExTakerCallback(
|
||||
bytes32 orderHash,
|
||||
bytes calldata callbackData
|
||||
)
|
||||
external
|
||||
returns (bytes4 success);
|
||||
}
|
55
contracts/zero-ex/contracts/test/TestFeeRecipient.sol
Normal file
55
contracts/zero-ex/contracts/test/TestFeeRecipient.sol
Normal file
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
contract TestFeeRecipient {
|
||||
bytes4 constant private SUCCESS = this.receiveZeroExFeeCallback.selector;
|
||||
bytes4 constant private FAILURE = 0xdeadbeef;
|
||||
|
||||
uint256 constant private TRIGGER_REVERT = 333;
|
||||
uint256 constant private TRIGGER_FAILURE = 666;
|
||||
|
||||
event FeeReceived(
|
||||
address tokenAddress,
|
||||
uint256 amount
|
||||
);
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
function receiveZeroExFeeCallback(
|
||||
address tokenAddress,
|
||||
uint256 amount,
|
||||
bytes calldata /* feeData */
|
||||
)
|
||||
external
|
||||
returns (bytes4 success)
|
||||
{
|
||||
emit FeeReceived(tokenAddress, amount);
|
||||
if (amount == TRIGGER_REVERT) {
|
||||
revert("TestFeeRecipient::receiveZeroExFeeCallback/REVERT");
|
||||
} else if (amount == TRIGGER_FAILURE) {
|
||||
return FAILURE;
|
||||
} else {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,7 @@ pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol";
|
||||
import "../src/vendor/v3/IERC20Bridge.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "./tokens/TestMintableERC20Token.sol";
|
||||
|
||||
|
||||
contract TestFillQuoteTransformerBridge {
|
||||
|
@@ -23,7 +23,7 @@ pragma experimental ABIEncoderV2;
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "./tokens/TestMintableERC20Token.sol";
|
||||
import "../src/features/libs/LibNativeOrder.sol";
|
||||
import "../src/features/libs/LibSignature.sol";
|
||||
|
||||
|
@@ -21,7 +21,7 @@ pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../src/transformers/IERC20Transformer.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "./tokens/TestMintableERC20Token.sol";
|
||||
import "./TestTransformerHost.sol";
|
||||
|
||||
|
||||
|
@@ -46,6 +46,10 @@ contract TestMetaTransactionsTransformERC20Feature is
|
||||
payable
|
||||
returns (uint256 outputTokenAmount)
|
||||
{
|
||||
if (msg.value == 555) {
|
||||
tx.origin.transfer(1);
|
||||
}
|
||||
|
||||
if (msg.value == 666) {
|
||||
revert('FAIL');
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ pragma experimental ABIEncoderV2;
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../src/transformers/IERC20Transformer.sol";
|
||||
import "../src/transformers/LibERC20Transformer.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "./tokens/TestMintableERC20Token.sol";
|
||||
|
||||
|
||||
contract TestMintTokenERC20Transformer is
|
||||
|
93
contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol
Normal file
93
contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol
Normal file
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "../src/IZeroEx.sol";
|
||||
import "../src/vendor/IERC1155Token.sol";
|
||||
import "../src/vendor/IERC721Token.sol";
|
||||
import "../src/features/libs/LibNFTOrder.sol";
|
||||
|
||||
|
||||
contract TestNFTOrderPresigner {
|
||||
IZeroEx private immutable zeroEx;
|
||||
|
||||
constructor(IZeroEx _zeroEx)
|
||||
public
|
||||
{
|
||||
zeroEx = _zeroEx;
|
||||
}
|
||||
|
||||
function onERC1155Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
)
|
||||
external
|
||||
returns(bytes4 success)
|
||||
{
|
||||
return 0xf23a6e61;
|
||||
}
|
||||
|
||||
function approveERC721(IERC721Token token)
|
||||
external
|
||||
{
|
||||
token.setApprovalForAll(address(zeroEx), true);
|
||||
}
|
||||
|
||||
function approveERC1155(IERC1155Token token)
|
||||
external
|
||||
{
|
||||
token.setApprovalForAll(address(zeroEx), true);
|
||||
}
|
||||
|
||||
function approveERC20(IERC20TokenV06 token)
|
||||
external
|
||||
{
|
||||
token.approve(address(zeroEx), uint256(-1));
|
||||
}
|
||||
|
||||
function preSignERC721Order(LibNFTOrder.ERC721Order calldata order)
|
||||
external
|
||||
{
|
||||
zeroEx.preSignERC721Order(order);
|
||||
}
|
||||
|
||||
function preSignERC1155Order(LibNFTOrder.ERC1155Order calldata order)
|
||||
external
|
||||
{
|
||||
zeroEx.preSignERC1155Order(order);
|
||||
}
|
||||
|
||||
function cancelERC721Order(uint256 orderNonce)
|
||||
external
|
||||
{
|
||||
zeroEx.cancelERC721Order(orderNonce);
|
||||
}
|
||||
|
||||
function cancelERC1155Order(uint256 orderNonce)
|
||||
external
|
||||
{
|
||||
zeroEx.cancelERC1155Order(orderNonce);
|
||||
}
|
||||
}
|
@@ -17,29 +17,23 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface ISmoothy {
|
||||
contract TestPropertyValidator {
|
||||
|
||||
function getBalance (
|
||||
uint256 tid
|
||||
function validateProperty(
|
||||
address tokenAddress,
|
||||
uint256 tokenId,
|
||||
bytes calldata propertyData
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 balance);
|
||||
|
||||
function _yBalances (
|
||||
uint256 tid
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 balance);
|
||||
|
||||
function getTokenStats (
|
||||
uint256 tid
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 softWeight, uint256 hardWeight, uint256 balance, uint256 decimals);
|
||||
{
|
||||
require(
|
||||
propertyData.length > 0,
|
||||
"TestPropertyValidator::validateProperty/REVERT"
|
||||
);
|
||||
}
|
||||
}
|
@@ -21,9 +21,9 @@ pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../src/transformers/IERC20Transformer.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "./tokens/TestMintableERC20Token.sol";
|
||||
import "./TestTransformerHost.sol";
|
||||
import "./TestWeth.sol";
|
||||
import "./tokens/TestWeth.sol";
|
||||
|
||||
|
||||
contract TestWethTransformerHost is
|
||||
|
30
contracts/zero-ex/contracts/test/foundry/ContractTest.sol
Normal file
30
contracts/zero-ex/contracts/test/foundry/ContractTest.sol
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
|
||||
contract ContractTest is Test {
|
||||
function setUp() public {}
|
||||
|
||||
function testExample() public {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ pragma solidity ^0.6.5;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "./TestMintableERC20Token.sol";
|
||||
import "../tokens/TestMintableERC20Token.sol";
|
||||
|
||||
contract TestCurve {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user