Compare commits
740 Commits
@0x/contra
...
@0x/contra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec92cea598 | ||
|
|
0e25f8ba32 | ||
|
|
23602ec6b4 | ||
|
|
f4da2a129d | ||
|
|
ab6938f614 | ||
|
|
09ec6d637b | ||
|
|
703e8e06a3 | ||
|
|
47f30d097a | ||
|
|
5c18b394a4 | ||
|
|
fb5afafbbe | ||
|
|
b3f71af850 | ||
|
|
093fb6e68d | ||
|
|
a8ae2b7355 | ||
|
|
d45f64ab06 | ||
|
|
050343c97a | ||
|
|
64f5aaccd7 | ||
|
|
856472452a | ||
|
|
f06e7a511e | ||
|
|
f6bd8c939c | ||
|
|
d09040d1d3 | ||
|
|
00fcdbd43a | ||
|
|
4dfd91e2df | ||
|
|
50f86dd61b | ||
|
|
9c219159c6 | ||
|
|
e1195a3444 | ||
|
|
7fe4a03683 | ||
|
|
803505cacc | ||
|
|
e05e118bd2 | ||
|
|
c883f5ea41 | ||
|
|
0567b3332b | ||
|
|
cc2833b372 | ||
|
|
0165d67dc1 | ||
|
|
1a4489b96a | ||
|
|
1ecc4a14ca | ||
|
|
9eba6d7146 | ||
|
|
3724ac4b67 | ||
|
|
d912175a7a | ||
|
|
5f23eee6dc | ||
|
|
5fe607557d | ||
|
|
5d6584b0eb | ||
|
|
7bdb77d93f | ||
|
|
2530d47fde | ||
|
|
2b8226a757 | ||
|
|
92d5adaac4 | ||
|
|
0c9daa693e | ||
|
|
89729e828c | ||
|
|
c2113caae1 | ||
|
|
e0adb6624d | ||
|
|
022855add0 | ||
|
|
4dd1c48dc8 | ||
|
|
cdc2393aa6 | ||
|
|
94f94bdda7 | ||
|
|
3264bd223d | ||
|
|
6292c0703c | ||
|
|
9a28079f2a | ||
|
|
c612649f02 | ||
|
|
eda44d1ffb | ||
|
|
4c2f77c014 | ||
|
|
6b8bbd3d5f | ||
|
|
e914e1b7fa | ||
|
|
3d2ce749a8 | ||
|
|
9892d8d6d2 | ||
|
|
218a7ab810 | ||
|
|
6779e52813 | ||
|
|
5d51b40541 | ||
|
|
b12b7069f7 | ||
|
|
10a5d38446 | ||
|
|
e39e7a934e | ||
|
|
b7127d8506 | ||
|
|
a12e07b1a8 | ||
|
|
8ff5c0a603 | ||
|
|
c5c8506cc6 | ||
|
|
dbef531d66 | ||
|
|
4e9c9ca079 | ||
|
|
d7c61fea4c | ||
|
|
08dc5fafa0 | ||
|
|
78493a9d98 | ||
|
|
e274d8994a | ||
|
|
2dee887e6f | ||
|
|
f7eb20a235 | ||
|
|
f3cea0ebd0 | ||
|
|
05e00d278f | ||
|
|
107c7a71f9 | ||
|
|
56698fb09e | ||
|
|
55bb6f89d3 | ||
|
|
47d77cbddd | ||
|
|
2547e0e5b1 | ||
|
|
1a4699ecac | ||
|
|
c825643b67 | ||
|
|
a425d3a234 | ||
|
|
3041e7459e | ||
|
|
1fb9d54174 | ||
|
|
598607f5a3 | ||
|
|
5c5bb20415 | ||
|
|
6199a17791 | ||
|
|
7dd42ad6aa | ||
|
|
c7fd85633d | ||
|
|
b3df71bebf | ||
|
|
88d95ebdbc | ||
|
|
140cf4d378 | ||
|
|
451a19117f | ||
|
|
aa6ab33b93 | ||
|
|
8ec04271f3 | ||
|
|
f583de652f | ||
|
|
96cd9de8a6 | ||
|
|
9a17cb4c92 | ||
|
|
021cba9fad | ||
|
|
47f4321611 | ||
|
|
775a41a789 | ||
|
|
f6c61ed79f | ||
|
|
152e057e08 | ||
|
|
8b84ecc593 | ||
|
|
9c10babefd | ||
|
|
67193d9472 | ||
|
|
7d04dd9520 | ||
|
|
93bda7972c | ||
|
|
92c0e34ed2 | ||
|
|
c0a471b349 | ||
|
|
2543076d16 | ||
|
|
e32bb6fc0f | ||
|
|
7020166473 | ||
|
|
16ae47f2ad | ||
|
|
abf1141ad8 | ||
|
|
3790e0a741 | ||
|
|
9e1966b4fe | ||
|
|
38e06e57a3 | ||
|
|
7f2fc90677 | ||
|
|
1f0ab54fc5 | ||
|
|
7f8c11a74c | ||
|
|
7a4d64d90d | ||
|
|
7217bfa35e | ||
|
|
25077affc8 | ||
|
|
7a80583655 | ||
|
|
c21fe0cb50 | ||
|
|
3d08e79089 | ||
|
|
c43db2d096 | ||
|
|
220856d084 | ||
|
|
a01eafa4e7 | ||
|
|
f9c2d25352 | ||
|
|
d2f77d74e6 | ||
|
|
c3b928c1f5 | ||
|
|
9dfa9c194e | ||
|
|
1a3dc6cefc | ||
|
|
1a73daf82a | ||
|
|
6b20c9a542 | ||
|
|
76c996250d | ||
|
|
52e8de9966 | ||
|
|
81ab84b087 | ||
|
|
e34755a1ef | ||
|
|
6c11b2ad8a | ||
|
|
ede6ecc3aa | ||
|
|
9db69f33e4 | ||
|
|
17d5d4648b | ||
|
|
e203b5593a | ||
|
|
de9aa063c0 | ||
|
|
077d001b42 | ||
|
|
dfd46d68ac | ||
|
|
4dbe137999 | ||
|
|
1ac5cb404f | ||
|
|
43ffa2dd77 | ||
|
|
1efa7935b7 | ||
|
|
b0835b005a | ||
|
|
30946ac110 | ||
|
|
9427858755 | ||
|
|
53864d3817 | ||
|
|
ab283ddd9b | ||
|
|
7efcf9066c | ||
|
|
219e09d157 | ||
|
|
d816551dba | ||
|
|
04c5752b8a | ||
|
|
ed12d8b95f | ||
|
|
f48852742d | ||
|
|
b84d89367a | ||
|
|
d8dab6a070 | ||
|
|
ac2443690c | ||
|
|
5df0f13eb0 | ||
|
|
24d782fb19 | ||
|
|
01a5472318 | ||
|
|
4b7a2e9d49 | ||
|
|
62936e3502 | ||
|
|
d6b3e4fbaa | ||
|
|
a5f011f4a4 | ||
|
|
c6efaab01d | ||
|
|
0f7282d9a9 | ||
|
|
a3b414a986 | ||
|
|
8a6d0b67f1 | ||
|
|
f78ff91975 | ||
|
|
c8e416f3b1 | ||
|
|
d61f67d24a | ||
|
|
258ffdcc94 | ||
|
|
1f93f09864 | ||
|
|
7afddb9309 | ||
|
|
5eb4dbd5d9 | ||
|
|
fc39ddfb71 | ||
|
|
ba04a8bc0c | ||
|
|
02d4a28402 | ||
|
|
ea2bf07ea6 | ||
|
|
b5dc734dc4 | ||
|
|
7dd9b0ba66 | ||
|
|
69a5c8a317 | ||
|
|
b975ac7c31 | ||
|
|
dcede832c8 | ||
|
|
f40bbbc238 | ||
|
|
361f5ca5cc | ||
|
|
a710ebe5b3 | ||
|
|
2becef23ff | ||
|
|
f916d293fa | ||
|
|
f312a260cc | ||
|
|
fd9b51c7db | ||
|
|
1dac6b6157 | ||
|
|
c2ba6b3a0f | ||
|
|
576bd5585f | ||
|
|
ae61a87190 | ||
|
|
2e8f2ae769 | ||
|
|
b507a308e6 | ||
|
|
ad83b17fdf | ||
|
|
e452cfcd59 | ||
|
|
6474a4e08c | ||
|
|
e78288ddfd | ||
|
|
6e2d0ab13d | ||
|
|
bfbc78c95c | ||
|
|
368ae86530 | ||
|
|
d8ccc1694d | ||
|
|
b4e10b1e06 | ||
|
|
05f76958ac | ||
|
|
1183cf5e6b | ||
|
|
bf9eb1413b | ||
|
|
38d48a8f20 | ||
|
|
ca222a470d | ||
|
|
49ca8840ea | ||
|
|
faaeba78bb | ||
|
|
6c37d47f2f | ||
|
|
185e53149f | ||
|
|
4329a252ee | ||
|
|
8d38d69684 | ||
|
|
edb5e50253 | ||
|
|
81ab2e75ca | ||
|
|
e0d8398cf7 | ||
|
|
4fd46d1c95 | ||
|
|
c217764fe0 | ||
|
|
42124274c7 | ||
|
|
562342ac99 | ||
|
|
14b573ebfd | ||
|
|
e3834c2fc0 | ||
|
|
c2f3757de7 | ||
|
|
4b0010be63 | ||
|
|
078af36e0e | ||
|
|
b17d12fe23 | ||
|
|
294c0b449b | ||
|
|
bc3927e973 | ||
|
|
a2cfdd2975 | ||
|
|
53b4f48b2e | ||
|
|
635b80440a | ||
|
|
f2d95477e6 | ||
|
|
1005e4962a | ||
|
|
487bc1a08b | ||
|
|
0cf768185e | ||
|
|
b5558a8cff | ||
|
|
af2b8dfde5 | ||
|
|
2bde5f7034 | ||
|
|
c38f913a84 | ||
|
|
44b4f91208 | ||
|
|
9c4ad6ac32 | ||
|
|
b151c0b701 | ||
|
|
d4b6db773f | ||
|
|
7da71c0955 | ||
|
|
32adb35c2a | ||
|
|
2f197d128a | ||
|
|
5415bc4590 | ||
|
|
f6086b8054 | ||
|
|
c9d77d7fa0 | ||
|
|
ab8c457c51 | ||
|
|
5d91ad3656 | ||
|
|
78ffca06ea | ||
|
|
0d71ec93e7 | ||
|
|
d4c771dc7d | ||
|
|
68004466bb | ||
|
|
4dd2d1afaf | ||
|
|
4947676434 | ||
|
|
ea5e83da03 | ||
|
|
0705276ff9 | ||
|
|
0299abf1b5 | ||
|
|
132394ffbe | ||
|
|
40edcef340 | ||
|
|
bf22eba795 | ||
|
|
e990272db3 | ||
|
|
401a0eadb1 | ||
|
|
5852e0b476 | ||
|
|
401df5f45d | ||
|
|
7da40fd7bc | ||
|
|
89740dc24c | ||
|
|
4d7ba42f8f | ||
|
|
bbd9c4ef67 | ||
|
|
de036ae96a | ||
|
|
e5985d7c3f | ||
|
|
fb54c45d7d | ||
|
|
f1b704a91a | ||
|
|
b99eab6804 | ||
|
|
82acc26f97 | ||
|
|
569a165c87 | ||
|
|
704adcb03d | ||
|
|
197cdee604 | ||
|
|
3dc5de936e | ||
|
|
d88eb6a5c9 | ||
|
|
a168f34538 | ||
|
|
7b150bab73 | ||
|
|
b0e38f79ea | ||
|
|
a68ebc27ed | ||
|
|
25705bd314 | ||
|
|
85c9b7d9c5 | ||
|
|
629c2ecba2 | ||
|
|
be0662a41d | ||
|
|
1985fec892 | ||
|
|
2cbdd76aa3 | ||
|
|
73ae0541d8 | ||
|
|
22621b9f76 | ||
|
|
c9f214504a | ||
|
|
e8a2d1240f | ||
|
|
f2e0fe49f7 | ||
|
|
4ce7bf56e7 | ||
|
|
29be232ae9 | ||
|
|
794c0342ee | ||
|
|
d5a22829ac | ||
|
|
b58d4005d3 | ||
|
|
c16d9d85a2 | ||
|
|
92aeca1f30 | ||
|
|
b81ed67975 | ||
|
|
2bc6582e6b | ||
|
|
b27311da2e | ||
|
|
ab8a0da16a | ||
|
|
800e37ed03 | ||
|
|
950e84fe5c | ||
|
|
fdbc235fd6 | ||
|
|
ffdb5c06f6 | ||
|
|
14f0f89798 | ||
|
|
54b53184b7 | ||
|
|
75b1cdac66 | ||
|
|
d21f394531 | ||
|
|
86d90599ca | ||
|
|
ec24976789 | ||
|
|
00eaa8bd34 | ||
|
|
5c44163d68 | ||
|
|
f73bad5c13 | ||
|
|
a063fa6fe0 | ||
|
|
894ad8af21 | ||
|
|
c01793599f | ||
|
|
63db393b60 | ||
|
|
5846166c85 | ||
|
|
25e941128a | ||
|
|
22964ff913 | ||
|
|
62a58667ba | ||
|
|
c868015989 | ||
|
|
565e5e5770 | ||
|
|
198831d084 | ||
|
|
d3be097436 | ||
|
|
1259de5be4 | ||
|
|
df6be48638 | ||
|
|
4923fdbb73 | ||
|
|
66964a5a2f | ||
|
|
97e24d0e14 | ||
|
|
fe0b75ef26 | ||
|
|
4b76efbc28 | ||
|
|
11cff4d391 | ||
|
|
59211c1c1e | ||
|
|
c0ab2e8127 | ||
|
|
d39e90bfa1 | ||
|
|
16e55457c8 | ||
|
|
ea2a453811 | ||
|
|
7d2a768a0c | ||
|
|
78304c4369 | ||
|
|
85f243e2e0 | ||
|
|
785ca4f5d1 | ||
|
|
730e8ad151 | ||
|
|
b3e6e23508 | ||
|
|
f09d56cdb9 | ||
|
|
b51933c4d9 | ||
|
|
477791a600 | ||
|
|
f0d6476f92 | ||
|
|
fa4accd0c4 | ||
|
|
e64754f554 | ||
|
|
5badb1eb5d | ||
|
|
9c52fd1f2a | ||
|
|
27e01b9249 | ||
|
|
5bf0de5519 | ||
|
|
139a4acb1b | ||
|
|
9d8b2d9e0c | ||
|
|
d16a0f1b56 | ||
|
|
edb63c0f26 | ||
|
|
bd3a80bcde | ||
|
|
9f0da8ec39 | ||
|
|
42ed4e393f | ||
|
|
99ffe6bb2d | ||
|
|
70898be894 | ||
|
|
9f1859575d | ||
|
|
0167689374 | ||
|
|
053c5f0f88 | ||
|
|
fa6516d0be | ||
|
|
7fb0e1b39c | ||
|
|
8ba439c263 | ||
|
|
1a1f24146c | ||
|
|
086fa31d04 | ||
|
|
b5e02d1b74 | ||
|
|
e88aee6ad9 | ||
|
|
fb4ead84f5 | ||
|
|
298967e639 | ||
|
|
903a9947a3 | ||
|
|
72beb59d63 | ||
|
|
75dd1be40e | ||
|
|
6a7c2918bb | ||
|
|
9b9ee2415d | ||
|
|
f1f38fb8b0 | ||
|
|
1e44bcb7c9 | ||
|
|
11e689156e | ||
|
|
6c792e89f9 | ||
|
|
11026fe36a | ||
|
|
3133dde3a3 | ||
|
|
b666ca0271 | ||
|
|
de5c6c1ed0 | ||
|
|
34f4cf133b | ||
|
|
1ba54af4e2 | ||
|
|
42e0d608c8 | ||
|
|
2c35d63976 | ||
|
|
d1ca1e768f | ||
|
|
2255cc2ebc | ||
|
|
6512c12f40 | ||
|
|
fc8d428d1d | ||
|
|
e07613818d | ||
|
|
de59ae11bd | ||
|
|
026690c837 | ||
|
|
c223a72f5b | ||
|
|
c66cf83ef1 | ||
|
|
30cf9ac857 | ||
|
|
b99b9d5435 | ||
|
|
81b9ab2b6e | ||
|
|
78a60a9973 | ||
|
|
fca6f838d5 | ||
|
|
4a39eb7931 | ||
|
|
00ab5f0afb | ||
|
|
34dfd73aab | ||
|
|
9e0e12a468 | ||
|
|
1bdcb4f737 | ||
|
|
5e5ecdcf32 | ||
|
|
b316217394 | ||
|
|
d96e307e2c | ||
|
|
a7944bb3c5 | ||
|
|
2dc3885691 | ||
|
|
027ab98a3e | ||
|
|
1a5736a498 | ||
|
|
73f4c036c6 | ||
|
|
6cbadcf8e9 | ||
|
|
6a38f231b1 | ||
|
|
02d63daba5 | ||
|
|
99074b3c34 | ||
|
|
bb33609164 | ||
|
|
27832741e4 | ||
|
|
0cffdc9868 | ||
|
|
6055d44120 | ||
|
|
984305d483 | ||
|
|
7934624afc | ||
|
|
e7db5aa4f3 | ||
|
|
e922299a55 | ||
|
|
58cbc7a05f | ||
|
|
43648a2382 | ||
|
|
c1abaa3293 | ||
|
|
9f77879198 | ||
|
|
79279e5614 | ||
|
|
d100897b20 | ||
|
|
bfaaefaf0a | ||
|
|
520c6fa426 | ||
|
|
d95b520512 | ||
|
|
10f8637802 | ||
|
|
b327cc0f52 | ||
|
|
88acdaff90 | ||
|
|
d5039809de | ||
|
|
2746b73416 | ||
|
|
fdd1d20c5b | ||
|
|
e2b4670016 | ||
|
|
336adc6974 | ||
|
|
7c72ac52e1 | ||
|
|
d165bb2bb2 | ||
|
|
12dea02fab | ||
|
|
5181ee172b | ||
|
|
def0d9307e | ||
|
|
45e572388b | ||
|
|
4898de8d41 | ||
|
|
1aa2270d97 | ||
|
|
5abc9a8066 | ||
|
|
a8deb6cc74 | ||
|
|
87bcb46f43 | ||
|
|
3d904aac67 | ||
|
|
ace63fe83a | ||
|
|
33320fd758 | ||
|
|
be5b4b7702 | ||
|
|
5c55064c0f | ||
|
|
71ad8dcec0 | ||
|
|
09fd8bc521 | ||
|
|
ace0150fcb | ||
|
|
e627d3ce01 | ||
|
|
a65f981f55 | ||
|
|
dbebb3818d | ||
|
|
2027b74c5f | ||
|
|
5e921fdd08 | ||
|
|
6eda017719 | ||
|
|
9b9960c7b9 | ||
|
|
9df09e2464 | ||
|
|
5dacc58a4e | ||
|
|
fcb18e8d34 | ||
|
|
9af95a9461 | ||
|
|
bef662a6e1 | ||
|
|
04f24f32e2 | ||
|
|
65743882bb | ||
|
|
9e82b51eb5 | ||
|
|
a20c40ca90 | ||
|
|
745bdda1a3 | ||
|
|
3c7e538202 | ||
|
|
786419fee0 | ||
|
|
739651b917 | ||
|
|
e374469818 | ||
|
|
2ecd9672c2 | ||
|
|
68a4ad2e51 | ||
|
|
b2e2c27775 | ||
|
|
8e45d5e137 | ||
|
|
1ded7cd4f1 | ||
|
|
8bd2411a89 | ||
|
|
907fba7d0f | ||
|
|
bb5afc43b9 | ||
|
|
a243c9d685 | ||
|
|
829eeb2374 | ||
|
|
338de4ffa1 | ||
|
|
c7fbd6c64c | ||
|
|
95b7ae3146 | ||
|
|
ded48fd453 | ||
|
|
cbe2cf8a85 | ||
|
|
a12dc5c81b | ||
|
|
db062154d1 | ||
|
|
ac3a6426e8 | ||
|
|
f1f5b57254 | ||
|
|
3403e8af9b | ||
|
|
19286db952 | ||
|
|
40234e5b4a | ||
|
|
a9f046609c | ||
|
|
f2e2672e81 | ||
|
|
784f2674a9 | ||
|
|
93399165e7 | ||
|
|
7422485817 | ||
|
|
2ef19f31db | ||
|
|
8154209eab | ||
|
|
d56fb374a7 | ||
|
|
7bad1d2921 | ||
|
|
37dd494abd | ||
|
|
a9748e1b52 | ||
|
|
cc33101923 | ||
|
|
31fbbb52a8 | ||
|
|
d2c5665a30 | ||
|
|
06744ee7fb | ||
|
|
3e1db453ff | ||
|
|
ec76186c23 | ||
|
|
fcf975a65c | ||
|
|
e6d2c7db88 | ||
|
|
d012268953 | ||
|
|
70b797cb6d | ||
|
|
28d7cf38c8 | ||
|
|
6094fa7b6d | ||
|
|
8f3b7ee522 | ||
|
|
74f6fb7408 | ||
|
|
4ccb735282 | ||
|
|
b94631c84a | ||
|
|
2544e4fd65 | ||
|
|
7454a7a6f3 | ||
|
|
13e262b9cf | ||
|
|
b4db9d8b7d | ||
|
|
14ad5ced78 | ||
|
|
b2e592bb41 | ||
|
|
1a3281a959 | ||
|
|
6701c58a10 | ||
|
|
80fd0db2eb | ||
|
|
7ca8c5c16d | ||
|
|
3ed7cc5cab | ||
|
|
0987ae05a8 | ||
|
|
3154149d37 | ||
|
|
6f46109617 | ||
|
|
b0896408d2 | ||
|
|
243b478b99 | ||
|
|
fabbad2b2c | ||
|
|
1948ffe7bd | ||
|
|
67baee60f8 | ||
|
|
8f4c4715e2 | ||
|
|
3e7cbe6015 | ||
|
|
0053bde668 | ||
|
|
363dd31768 | ||
|
|
f841737adc | ||
|
|
9adaa7972e | ||
|
|
ec387f9bb7 | ||
|
|
aa657776fc | ||
|
|
f12632a1f2 | ||
|
|
4f8164dc43 | ||
|
|
88303d8855 | ||
|
|
4e8ddafa64 | ||
|
|
1ebe9d2bba | ||
|
|
fbae619725 | ||
|
|
8c5f4c3de7 | ||
|
|
154841157f | ||
|
|
6a20d06194 | ||
|
|
245e118016 | ||
|
|
fcc9d6749c | ||
|
|
9e091c5015 | ||
|
|
01247319c3 | ||
|
|
1d3d5f7e32 | ||
|
|
49f2cef5ac | ||
|
|
926d165321 | ||
|
|
86218445cd | ||
|
|
6e0f695699 | ||
|
|
7b9ff7776d | ||
|
|
e0f3f53d42 | ||
|
|
2e911ee709 | ||
|
|
43afed6654 | ||
|
|
0dda8328af | ||
|
|
48052fc3e4 | ||
|
|
5ac5fed513 | ||
|
|
60521e8167 | ||
|
|
510568d4f1 | ||
|
|
3e3ec3134d | ||
|
|
c22374893e | ||
|
|
013eaeeb07 | ||
|
|
b97b6867d8 | ||
|
|
87f31ec532 | ||
|
|
9b12695443 | ||
|
|
cbb40c1c2b | ||
|
|
b0e56fc27b | ||
|
|
d15532227d | ||
|
|
c3f98e95ad | ||
|
|
e92e99d6ea | ||
|
|
f6b67f6c98 | ||
|
|
108861b6ca | ||
|
|
80d93e8d75 | ||
|
|
1634cd53be | ||
|
|
577df3749d | ||
|
|
73c53b3da6 | ||
|
|
9af996a907 | ||
|
|
bd2e4a8076 | ||
|
|
ceaa6a592c | ||
|
|
b503fecccb | ||
|
|
4161055cc7 | ||
|
|
b0c9a3bbe1 | ||
|
|
436bdde461 | ||
|
|
01853064b0 | ||
|
|
c1ccb5af0f | ||
|
|
706f04ee27 | ||
|
|
549e35e972 | ||
|
|
1ed66966a8 | ||
|
|
326539f1f5 | ||
|
|
67322ba39f | ||
|
|
41fcc41bd1 | ||
|
|
7aacff62ca | ||
|
|
4566ddb037 | ||
|
|
957e6b1500 | ||
|
|
5945635d1d | ||
|
|
045fc0914b | ||
|
|
72442871aa | ||
|
|
bbd3c03969 | ||
|
|
a4405c3d39 | ||
|
|
0fe4f587d8 | ||
|
|
d3c714bd17 | ||
|
|
c399b7a7d5 | ||
|
|
b9234e94fb | ||
|
|
417bb87785 | ||
|
|
0233ae3134 | ||
|
|
eed0c5dd59 | ||
|
|
2b3b167095 | ||
|
|
5d91d19808 | ||
|
|
0f374ddee9 | ||
|
|
a65a9913cd | ||
|
|
1ead32c666 | ||
|
|
d1af9fc780 | ||
|
|
0f06737fb6 | ||
|
|
1676231532 | ||
|
|
b1caf697c8 | ||
|
|
51481065fe | ||
|
|
e367da710c | ||
|
|
f493d6524d | ||
|
|
e1b85da2a7 | ||
|
|
22c6548ed1 | ||
|
|
afb32c087d | ||
|
|
bbc1ed1c64 | ||
|
|
3a46f1a27a | ||
|
|
90cd364780 | ||
|
|
6795e6f078 | ||
|
|
cfb3404349 | ||
|
|
0212f3ee78 | ||
|
|
6b2995a4ee | ||
|
|
09e7ac54d4 | ||
|
|
f69009d4a8 | ||
|
|
206802ae33 | ||
|
|
91d4138fb8 | ||
|
|
cb455f951a | ||
|
|
5f25d20cd0 | ||
|
|
1f0e2cd910 | ||
|
|
1749d02701 | ||
|
|
55ace3179c | ||
|
|
7866d9ccb4 | ||
|
|
51f73d07fa | ||
|
|
63d84674ab | ||
|
|
14066997b2 | ||
|
|
28561e765a | ||
|
|
453fbbdc5d | ||
|
|
1e1e5ec10d | ||
|
|
2088b0e459 | ||
|
|
58400d9e01 | ||
|
|
ac9375f1d2 | ||
|
|
db061c9355 | ||
|
|
d5ce6c464b | ||
|
|
b06205bb7f | ||
|
|
f528a3e1de | ||
|
|
bddfdacfad | ||
|
|
d3cdd3f235 | ||
|
|
41ae45ea40 | ||
|
|
657e0895ea | ||
|
|
b2592d1cc2 | ||
|
|
aa3524c3b2 | ||
|
|
39deb1a05f | ||
|
|
302d08e290 | ||
|
|
05489dd7f1 | ||
|
|
55bd076602 | ||
|
|
7a224fe08f | ||
|
|
3bdeb82097 | ||
|
|
f49ab3f919 | ||
|
|
42d5bdd3ab | ||
|
|
7228cbfe92 | ||
|
|
11e2fc5bc4 | ||
|
|
3e88f820b8 | ||
|
|
163750f8c2 | ||
|
|
4aabc5d791 | ||
|
|
c9a7b9dcc1 | ||
|
|
98075b5653 | ||
|
|
57ae5be916 | ||
|
|
8caf62997f | ||
|
|
f8656ad376 | ||
|
|
29c6c2a2ad | ||
|
|
f2db67ef02 | ||
|
|
72b8ef33d9 |
@@ -23,7 +23,7 @@ jobs:
|
|||||||
# command: npm set prefix=/home/circleci/npm && echo 'export PATH=$HOME/circleci/npm/bin:$PATH' >> /home/circleci/.bashrc
|
# command: npm set prefix=/home/circleci/npm && echo 'export PATH=$HOME/circleci/npm/bin:$PATH' >> /home/circleci/.bashrc
|
||||||
- run:
|
- run:
|
||||||
name: install-yarn
|
name: install-yarn
|
||||||
command: npm install --force --global yarn@1.17.0
|
command: npm install --global yarn@1.17.0
|
||||||
- run:
|
- run:
|
||||||
name: yarn
|
name: yarn
|
||||||
command: yarn --frozen-lockfile --ignore-engines install || yarn --frozen-lockfile --ignore-engines install
|
command: yarn --frozen-lockfile --ignore-engines install || yarn --frozen-lockfile --ignore-engines install
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ~/repo/packages/abi-gen/test-cli/output
|
path: ~/repo/packages/abi-gen/test-cli/output
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ~/repo/packages/contract-wrappers/generated_docs
|
path: ~/repo/packages/abi-gen-wrappers/generated_docs
|
||||||
test-contracts-ganache:
|
test-contracts-ganache:
|
||||||
resource_class: medium+
|
resource_class: medium+
|
||||||
docker:
|
docker:
|
||||||
@@ -47,41 +47,19 @@ jobs:
|
|||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-tests @0x/contracts-staking
|
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils
|
||||||
test-exchange-ganache-3.0:
|
test-contracts-geth:
|
||||||
resource_class: medium+
|
|
||||||
docker:
|
docker:
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
||||||
|
- image: 0xorg/devnet
|
||||||
working_directory: ~/repo
|
working_directory: ~/repo
|
||||||
steps:
|
steps:
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: yarn wsrun test:circleci @0x/contracts-exchange
|
# HACK(albrow): we need to sleep 10 seconds to ensure the devnet is
|
||||||
test-integrations-ganache-3.0:
|
# initialized
|
||||||
resource_class: medium+
|
- run: sleep 10 && TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils
|
||||||
docker:
|
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
|
||||||
working_directory: ~/repo
|
|
||||||
steps:
|
|
||||||
- restore_cache:
|
|
||||||
keys:
|
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
|
||||||
- run: yarn wsrun test:circleci @0x/contracts-integrations
|
|
||||||
test-contracts-rest-ganache-3.0:
|
|
||||||
resource_class: medium+
|
|
||||||
docker:
|
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
|
||||||
working_directory: ~/repo
|
|
||||||
steps:
|
|
||||||
- restore_cache:
|
|
||||||
keys:
|
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
|
||||||
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-tests @0x/contracts-staking @0x/contracts-coordinator @0x/contracts-erc20-bridge-sampler
|
|
||||||
# TODO(dorothy-zbornak): Re-enable after updating this package for
|
|
||||||
# 3.0. At that time, also remove exclusion from monorepo
|
|
||||||
# package.json's test script.
|
|
||||||
# - run: yarn wsrun test:circleci @0x/contracts-extensions
|
|
||||||
test-publish:
|
test-publish:
|
||||||
resource_class: medium+
|
resource_class: medium+
|
||||||
docker:
|
docker:
|
||||||
@@ -92,9 +70,7 @@ jobs:
|
|||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run: yarn test:publish:circleci
|
||||||
command: yarn test:publish:circleci
|
|
||||||
no_output_timeout: 1800
|
|
||||||
test-doc-generation:
|
test-doc-generation:
|
||||||
docker:
|
docker:
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
||||||
@@ -103,9 +79,7 @@ jobs:
|
|||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run: yarn test:generate_docs:circleci
|
||||||
command: yarn test:generate_docs:circleci
|
|
||||||
no_output_timeout: 1200
|
|
||||||
test-rest:
|
test-rest:
|
||||||
docker:
|
docker:
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
||||||
@@ -116,16 +90,15 @@ jobs:
|
|||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: yarn wsrun test:circleci @0x/contracts-test-utils
|
- run: yarn wsrun test:circleci @0x/contracts-test-utils
|
||||||
- run: yarn wsrun test:circleci @0x/abi-gen
|
- run: yarn wsrun test:circleci @0x/abi-gen
|
||||||
- run: yarn wsrun test:circleci @0x/asset-swapper
|
- run: yarn wsrun test:circleci @0x/asset-buyer
|
||||||
- run: yarn wsrun test:circleci @0x/contract-artifacts
|
- run: yarn wsrun test:circleci @0x/contract-artifacts
|
||||||
- run: yarn wsrun test:circleci @0x/assert
|
- run: yarn wsrun test:circleci @0x/assert
|
||||||
- run: yarn wsrun test:circleci @0x/base-contract
|
- run: yarn wsrun test:circleci @0x/base-contract
|
||||||
- run: yarn wsrun test:circleci @0x/connect
|
- run: yarn wsrun test:circleci @0x/connect
|
||||||
- run: yarn wsrun test:circleci @0x/contract-wrappers-test
|
- run: yarn wsrun test:circleci @0x/contract-wrappers
|
||||||
- run: yarn wsrun test:circleci @0x/dev-utils
|
- run: yarn wsrun test:circleci @0x/dev-utils
|
||||||
- run: yarn wsrun test:circleci @0x/json-schemas
|
- run: yarn wsrun test:circleci @0x/json-schemas
|
||||||
- run: yarn wsrun test:circleci @0x/order-utils
|
- run: yarn wsrun test:circleci @0x/order-utils
|
||||||
- run: yarn wsrun test:circleci @0x/orderbook
|
|
||||||
- run: yarn wsrun test:circleci @0x/sol-compiler
|
- run: yarn wsrun test:circleci @0x/sol-compiler
|
||||||
- run: yarn wsrun test:circleci @0x/sol-tracing-utils
|
- run: yarn wsrun test:circleci @0x/sol-tracing-utils
|
||||||
- run: yarn wsrun test:circleci @0x/sol-doc
|
- run: yarn wsrun test:circleci @0x/sol-doc
|
||||||
@@ -142,9 +115,9 @@ jobs:
|
|||||||
paths:
|
paths:
|
||||||
- ~/repo/packages/assert/coverage/lcov.info
|
- ~/repo/packages/assert/coverage/lcov.info
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: coverage-asset-swapper-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-asset-buyer-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
- ~/repo/packages/asset-swapper/coverage/lcov.info
|
- ~/repo/packages/asset-buyer/coverage/lcov.info
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: coverage-base-contract-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-base-contract-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
@@ -154,9 +127,9 @@ jobs:
|
|||||||
paths:
|
paths:
|
||||||
- ~/repo/packages/connect/coverage/lcov.info
|
- ~/repo/packages/connect/coverage/lcov.info
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-contract-wrappers-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
- ~/repo/packages/contract-wrappers-test/coverage/lcov.info
|
- ~/repo/packages/contract-wrappers/coverage/lcov.info
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
@@ -193,27 +166,14 @@ jobs:
|
|||||||
working_directory: ~/repo
|
working_directory: ~/repo
|
||||||
docker:
|
docker:
|
||||||
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
- image: nikolaik/python-nodejs:python3.7-nodejs8
|
||||||
- image: 0xorg/ganache-cli:6.0.0
|
- image: 0xorg/ganache-cli:2.2.2
|
||||||
- image: 0xorg/mesh:0xV3
|
- image: 0xorg/launch-kit-backend:74bcc39
|
||||||
environment:
|
environment:
|
||||||
ETHEREUM_RPC_URL: 'http://localhost:8545'
|
RPC_URL: http://localhost:8545
|
||||||
ETHEREUM_CHAIN_ID: '1337'
|
NETWORK_ID: 50
|
||||||
VERBOSITY: 5
|
|
||||||
BLOCK_POLLING_INTERVAL: '50ms'
|
|
||||||
ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC: '1778000'
|
|
||||||
command: |
|
|
||||||
sh -c "waitForGanache () { until printf 'POST /\r\nContent-Length: 26\r\n\r\n{\"method\":\"net_listening\"}' | nc localhost 8545 | grep true; do continue; done }; waitForGanache && ./mesh"
|
|
||||||
- image: 0xorg/launch-kit-backend:v3
|
|
||||||
environment:
|
|
||||||
RPC_URL: 'http://localhost:8545'
|
|
||||||
CHAIN_ID: 1337
|
|
||||||
WHITELIST_ALL_TOKENS: True
|
WHITELIST_ALL_TOKENS: True
|
||||||
FEE_RECIPIENT: '0x0000000000000000000000000000000000000001'
|
|
||||||
MAKER_FEE_UNIT_AMOUNT: 0
|
|
||||||
TAKER_FEE_UNIT_AMOUNT: 0
|
|
||||||
MESH_ENDPOINT: 'ws://localhost:60557'
|
|
||||||
command: |
|
command: |
|
||||||
sh -c "waitForMesh () { sleep 30; }; waitForMesh && node_modules/.bin/forever ts/lib/index.js"
|
sh -c "until printf 'POST /\r\nContent-Length: 26\r\n\r\n{\"method\":\"net_listening\"}' | nc localhost 8545 | grep true; do continue; done; node_modules/.bin/forever ts/lib/index.js"
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
@@ -235,14 +195,8 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
command: |
|
command: |
|
||||||
cd python-packages
|
cd python-packages
|
||||||
./parallel coverage run setup.py test
|
./parallel_without_sra_client coverage run setup.py test
|
||||||
./build_docs
|
./build_docs
|
||||||
- run:
|
|
||||||
command: |
|
|
||||||
# copy generated wrappers into contract_wrappers/build,
|
|
||||||
# JUST so CircleCI will persist them as build artifacts.
|
|
||||||
cd python-packages/contract_wrappers/src/zero_ex
|
|
||||||
for i in contract_wrappers/[^__]*/; do mkdir -p ../../build/$i; cp $i/__init__.py ../../build/$i; done
|
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: coverage-python-contract-addresses-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-python-contract-addresses-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
@@ -267,6 +221,8 @@ jobs:
|
|||||||
key: coverage-python-sra-client-{{ .Environment.CIRCLE_SHA1 }}
|
key: coverage-python-sra-client-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
- ~/repo/python-packages/sra_client/.coverage
|
- ~/repo/python-packages/sra_client/.coverage
|
||||||
|
- store_artifacts:
|
||||||
|
path: ~/repo/python-packages/contract_wrappers/src/zero_ex/contract_wrappers/*/__init__.py
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ~/repo/python-packages/contract_addresses/build
|
path: ~/repo/python-packages/contract_addresses/build
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
@@ -356,7 +312,7 @@ jobs:
|
|||||||
- coverage-assert-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-assert-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- coverage-asset-swapper-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-asset-buyer-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- coverage-base-contract-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-base-contract-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
@@ -365,7 +321,7 @@ jobs:
|
|||||||
- coverage-connect-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-connect-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-contract-wrappers-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
- coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
@@ -417,15 +373,14 @@ workflows:
|
|||||||
main:
|
main:
|
||||||
jobs:
|
jobs:
|
||||||
- build
|
- build
|
||||||
- test-exchange-ganache-3.0:
|
- test-contracts-ganache:
|
||||||
requires:
|
|
||||||
- build
|
|
||||||
- test-integrations-ganache-3.0:
|
|
||||||
requires:
|
|
||||||
- build
|
|
||||||
- test-contracts-rest-ganache-3.0:
|
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
|
# TODO(albrow): Tests always fail on Geth right now because our fork
|
||||||
|
# is outdated. Uncomment once we have updated our Geth fork.
|
||||||
|
# - test-contracts-geth:
|
||||||
|
# requires:
|
||||||
|
# - build
|
||||||
- test-rest:
|
- test-rest:
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
@@ -440,15 +395,13 @@ workflows:
|
|||||||
- build
|
- build
|
||||||
- submit-coverage:
|
- submit-coverage:
|
||||||
requires:
|
requires:
|
||||||
- test-contracts-rest-ganache-3.0
|
|
||||||
- test-exchange-ganache-3.0
|
|
||||||
- test-rest
|
- test-rest
|
||||||
- static-tests
|
- test-python
|
||||||
|
- static-tests-python:
|
||||||
|
requires:
|
||||||
|
- test-python
|
||||||
- test-python:
|
- test-python:
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- static-tests-python:
|
|
||||||
requires:
|
|
||||||
- build
|
|
||||||
# skip python tox run for now, as we don't yet have multiple test environments to support.
|
# skip python tox run for now, as we don't yet have multiple test environments to support.
|
||||||
# - test-rest-python
|
#- test-rest-python
|
||||||
|
|||||||
6
.github/autolabeler.yml
vendored
6
.github/autolabeler.yml
vendored
@@ -19,15 +19,19 @@ contracts: ['contracts']
|
|||||||
@0x/sol-tracing-utils: ['packages/sol-tracing-utils']
|
@0x/sol-tracing-utils: ['packages/sol-tracing-utils']
|
||||||
@0x/utils: ['packages/utils']
|
@0x/utils: ['packages/utils']
|
||||||
@0x/tslint-config: ['packages/tslint-config']
|
@0x/tslint-config: ['packages/tslint-config']
|
||||||
@0x/asset-swapper: ['packages/asset-swapper']
|
@0x/asset-buyer: ['packages/asset-buyer']
|
||||||
@0x/order-utils: ['packages/order-utils']
|
@0x/order-utils: ['packages/order-utils']
|
||||||
@0x/assert: ['packages/assert']
|
@0x/assert: ['packages/assert']
|
||||||
@0x/base-contract: ['packages/base-contract']
|
@0x/base-contract: ['packages/base-contract']
|
||||||
@0x/typescript-typings: ['packages/typescript-typings']
|
@0x/typescript-typings: ['packages/typescript-typings']
|
||||||
0x.js: ['packages/0x.js']
|
0x.js: ['packages/0x.js']
|
||||||
|
@0x/abi-gen-wrappers: ['packages/abi-gen-wrappers']
|
||||||
@0x/contract-artifacts: ['packages/contract-artifacts']
|
@0x/contract-artifacts: ['packages/contract-artifacts']
|
||||||
@0x/dev-utils: ['packages/dev-utils']
|
@0x/dev-utils: ['packages/dev-utils']
|
||||||
@0x/contract-wrappers: ['packages/contract-wrappers']
|
@0x/contract-wrappers: ['packages/contract-wrappers']
|
||||||
@0x/json-schemas: ['packages/json-schemas']
|
@0x/json-schemas: ['packages/json-schemas']
|
||||||
@0x/ethereum-types: ['ethereum-types']
|
@0x/ethereum-types: ['ethereum-types']
|
||||||
@0x/connect: ['packages/connect']
|
@0x/connect: ['packages/connect']
|
||||||
|
@0x/fill-scenarios: ['packages/fill-scenarios']
|
||||||
|
@0x/testnet-faucets: ['packages/testnet-faucets']
|
||||||
|
@0x/monorepo-scripts: ['packages/monorepo-scripts']
|
||||||
|
|||||||
82
.gitignore
vendored
82
.gitignore
vendored
@@ -78,89 +78,59 @@ TODO.md
|
|||||||
# VSCode file
|
# VSCode file
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
# server cli
|
||||||
|
packages/testnet-faucets/server/
|
||||||
|
|
||||||
# generated contract artifacts/
|
# generated contract artifacts/
|
||||||
contracts/erc20-bridge-sampler/generated-artifacts/
|
|
||||||
contracts/erc20-bridge-sampler/test/generated-artifacts/
|
|
||||||
contracts/integrations/generated-artifacts/
|
|
||||||
contracts/integrations/test/generated-artifacts/
|
|
||||||
contracts/staking/generated-artifacts/
|
|
||||||
contracts/staking/test/generated-artifacts/
|
|
||||||
contracts/coordinator/generated-artifacts/
|
contracts/coordinator/generated-artifacts/
|
||||||
contracts/coordinator/test/generated-artifacts/
|
|
||||||
contracts/exchange/generated-artifacts/
|
contracts/exchange/generated-artifacts/
|
||||||
contracts/exchange/test/generated-artifacts/
|
|
||||||
contracts/asset-proxy/generated-artifacts/
|
contracts/asset-proxy/generated-artifacts/
|
||||||
contracts/asset-proxy/test/generated-artifacts/
|
|
||||||
contracts/multisig/generated-artifacts/
|
contracts/multisig/generated-artifacts/
|
||||||
contracts/multisig/test/generated-artifacts/
|
|
||||||
contracts/utils/generated-artifacts/
|
contracts/utils/generated-artifacts/
|
||||||
contracts/utils/test/generated-artifacts/
|
|
||||||
contracts/exchange-libs/generated-artifacts/
|
contracts/exchange-libs/generated-artifacts/
|
||||||
contracts/exchange-libs/test/generated-artifacts/
|
|
||||||
contracts/erc20/generated-artifacts/
|
contracts/erc20/generated-artifacts/
|
||||||
contracts/erc20/test/generated-artifacts/
|
|
||||||
contracts/erc721/generated-artifacts/
|
contracts/erc721/generated-artifacts/
|
||||||
contracts/erc721/test/generated-artifacts/
|
|
||||||
contracts/erc1155/generated-artifacts/
|
contracts/erc1155/generated-artifacts/
|
||||||
contracts/erc1155/test/generated-artifacts/
|
|
||||||
contracts/extensions/generated-artifacts/
|
contracts/extensions/generated-artifacts/
|
||||||
contracts/extensions/test/generated-artifacts/
|
|
||||||
contracts/exchange-forwarder/generated-artifacts/
|
contracts/exchange-forwarder/generated-artifacts/
|
||||||
contracts/exchange-forwarder/test/generated-artifacts/
|
|
||||||
contracts/dev-utils/generated-artifacts/
|
contracts/dev-utils/generated-artifacts/
|
||||||
contracts/dev-utils/test/generated-artifacts/
|
|
||||||
packages/sol-tracing-utils/test/fixtures/artifacts/
|
packages/sol-tracing-utils/test/fixtures/artifacts/
|
||||||
python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/
|
python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/
|
||||||
|
|
||||||
# generated truffle contract artifacts/
|
|
||||||
contracts/erc20-bridge-sampler/build/
|
|
||||||
contracts/staking/build/
|
|
||||||
contracts/coordinator/build/
|
|
||||||
contracts/exchange/build/
|
|
||||||
contracts/asset-proxy/build/
|
|
||||||
contracts/multisig/build/
|
|
||||||
contracts/utils/build/
|
|
||||||
contracts/exchange-libs/build/
|
|
||||||
contracts/erc20/build/
|
|
||||||
contracts/erc721/build/
|
|
||||||
contracts/erc1155/build/
|
|
||||||
contracts/extensions/build/
|
|
||||||
contracts/exchange-forwarder/build/
|
|
||||||
contracts/dev-utils/build/
|
|
||||||
|
|
||||||
# generated contract wrappers
|
# generated contract wrappers
|
||||||
packages/python-contract-wrappers/generated/
|
packages/python-contract-wrappers/generated/
|
||||||
contracts/erc20-bridge-sampler/generated-wrappers/
|
|
||||||
contracts/erc20-bridge-sampler/test/generated-wrappers/
|
|
||||||
contracts/integrations/generated-wrappers/
|
|
||||||
contracts/integrations/test/generated-wrappers/
|
|
||||||
contracts/staking/generated-wrappers/
|
|
||||||
contracts/staking/test/generated-wrappers/
|
|
||||||
contracts/coordinator/generated-wrappers/
|
contracts/coordinator/generated-wrappers/
|
||||||
contracts/coordinator/test/generated-wrappers/
|
|
||||||
contracts/exchange/generated-wrappers/
|
contracts/exchange/generated-wrappers/
|
||||||
contracts/exchange/test/generated-wrappers/
|
|
||||||
contracts/asset-proxy/generated-wrappers/
|
contracts/asset-proxy/generated-wrappers/
|
||||||
contracts/asset-proxy/test/generated-wrappers/
|
|
||||||
contracts/multisig/generated-wrappers/
|
contracts/multisig/generated-wrappers/
|
||||||
contracts/multisig/test/generated-wrappers/
|
|
||||||
contracts/utils/generated-wrappers/
|
contracts/utils/generated-wrappers/
|
||||||
contracts/utils/test/generated-wrappers/
|
|
||||||
contracts/exchange-libs/generated-wrappers/
|
contracts/exchange-libs/generated-wrappers/
|
||||||
contracts/exchange-libs/test/generated-wrappers/
|
|
||||||
contracts/erc20/generated-wrappers/
|
contracts/erc20/generated-wrappers/
|
||||||
contracts/erc20/test/generated-wrappers/
|
|
||||||
contracts/erc721/generated-wrappers/
|
contracts/erc721/generated-wrappers/
|
||||||
contracts/erc721/test/generated-wrappers/
|
|
||||||
contracts/erc1155/generated-wrappers/
|
contracts/erc1155/generated-wrappers/
|
||||||
contracts/erc1155/test/generated-wrappers/
|
|
||||||
contracts/extensions/generated-wrappers/
|
contracts/extensions/generated-wrappers/
|
||||||
contracts/extensions/test/generated-wrappers/
|
|
||||||
contracts/exchange-forwarder/generated-wrappers/
|
contracts/exchange-forwarder/generated-wrappers/
|
||||||
contracts/exchange-forwarder/test/generated-wrappers/
|
|
||||||
contracts/dev-utils/generated-wrappers/
|
contracts/dev-utils/generated-wrappers/
|
||||||
contracts/dev-utils/test/generated-wrappers/
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_token/__init__.py
|
||||||
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/*/__init__.py
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/exchange/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/asset_proxy_owner/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/coordinator/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/coordinator_registry/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dummy_erc20_token/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dummy_erc721_token/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dutch_auction/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_proxy/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_proxy/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_token/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/eth_balance_checker/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/forwarder/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_asset_proxy/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_validator/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_wallet/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/multi_asset_proxy/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/order_validator/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/weth9/__init__.py
|
||||||
|
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/zrx_token/__init__.py
|
||||||
|
|
||||||
# solc-bin in sol-compiler
|
# solc-bin in sol-compiler
|
||||||
packages/sol-compiler/solc_bin/
|
packages/sol-compiler/solc_bin/
|
||||||
@@ -175,14 +145,10 @@ __pycache__
|
|||||||
python-packages/*/src/*.egg-info
|
python-packages/*/src/*.egg-info
|
||||||
python-packages/*/.coverage
|
python-packages/*/.coverage
|
||||||
|
|
||||||
# python keeps package-local copies of json schemas and contract addresses
|
# python keeps package-local copies of json schemas
|
||||||
python-packages/json_schemas/src/zero_ex/json_schemas/schemas
|
python-packages/json_schemas/src/zero_ex/json_schemas/schemas
|
||||||
python-packages/contract_addresses/src/zero_ex/contract_addresses/addresses.json
|
|
||||||
|
|
||||||
# Doc README copy
|
# Doc README copy
|
||||||
packages/*/docs/README.md
|
packages/*/docs/README.md
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# the snapshot that gets built for migrations sure does have a ton of files
|
|
||||||
packages/migrations/0x_ganache_snapshot*
|
|
||||||
|
|||||||
@@ -1,78 +1,29 @@
|
|||||||
lib
|
lib
|
||||||
.nyc_output
|
.nyc_output
|
||||||
/contracts/integrations/generated-wrappers
|
|
||||||
/contracts/integrations/test/generated-wrappers
|
|
||||||
/contracts/integrations/generated-artifacts
|
|
||||||
/contracts/integrations/test/generated-artifacts
|
|
||||||
/contracts/staking/generated-wrappers
|
|
||||||
/contracts/staking/test/generated-wrappers
|
|
||||||
/contracts/staking/generated-artifacts
|
|
||||||
/contracts/staking/test/generated-artifacts
|
|
||||||
/contracts/coordinator/generated-wrappers
|
/contracts/coordinator/generated-wrappers
|
||||||
/contracts/coordinator/test/generated-wrappers
|
|
||||||
/contracts/coordinator/generated-artifacts
|
/contracts/coordinator/generated-artifacts
|
||||||
/contracts/coordinator/test/generated-artifacts
|
|
||||||
/contracts/exchange/generated-wrappers
|
/contracts/exchange/generated-wrappers
|
||||||
/contracts/exchange/test/generated-wrappers
|
|
||||||
/contracts/exchange/generated-artifacts
|
/contracts/exchange/generated-artifacts
|
||||||
/contracts/exchange/test/generated-artifacts
|
|
||||||
/contracts/asset-proxy/generated-wrappers
|
/contracts/asset-proxy/generated-wrappers
|
||||||
/contracts/asset-proxy/test/generated-wrappers
|
|
||||||
/contracts/asset-proxy/generated-artifacts
|
/contracts/asset-proxy/generated-artifacts
|
||||||
/contracts/asset-proxy/test/generated-artifacts
|
|
||||||
/contracts/multisig/generated-wrappers
|
/contracts/multisig/generated-wrappers
|
||||||
/contracts/multisig/test/generated-wrappers
|
|
||||||
/contracts/multisig/generated-artifacts
|
/contracts/multisig/generated-artifacts
|
||||||
/contracts/multisig/test/generated-artifacts
|
|
||||||
/contracts/utils/generated-wrappers
|
/contracts/utils/generated-wrappers
|
||||||
/contracts/utils/test/generated-wrappers
|
|
||||||
/contracts/utils/generated-artifacts
|
/contracts/utils/generated-artifacts
|
||||||
/contracts/utils/test/generated-artifacts
|
|
||||||
/contracts/exchange-libs/generated-wrappers
|
/contracts/exchange-libs/generated-wrappers
|
||||||
/contracts/exchange-libs/test/generated-wrappers
|
|
||||||
/contracts/exchange-libs/generated-artifacts
|
/contracts/exchange-libs/generated-artifacts
|
||||||
/contracts/exchange-libs/test/generated-artifacts
|
|
||||||
/contracts/erc20/generated-wrappers
|
/contracts/erc20/generated-wrappers
|
||||||
/contracts/erc20/test/generated-wrappers
|
|
||||||
/contracts/erc20/generated-artifacts
|
/contracts/erc20/generated-artifacts
|
||||||
/contracts/erc20/test/generated-artifacts
|
|
||||||
/contracts/erc20-bridge-sampler/generated-wrappers
|
|
||||||
/contracts/erc20-bridge-sampler/test/generated-wrappers
|
|
||||||
/contracts/erc20-bridge-sampler/generated-artifacts
|
|
||||||
/contracts/erc20-bridge-sampler/test/generated-artifacts
|
|
||||||
/contracts/erc721/generated-wrappers
|
/contracts/erc721/generated-wrappers
|
||||||
/contracts/erc721/test/generated-wrappers
|
|
||||||
/contracts/erc721/generated-artifacts
|
/contracts/erc721/generated-artifacts
|
||||||
/contracts/erc721/test/generated-artifacts
|
|
||||||
/contracts/erc1155/generated-wrappers
|
/contracts/erc1155/generated-wrappers
|
||||||
/contracts/erc1155/test/generated-wrappers
|
|
||||||
/contracts/erc1155/generated-artifacts
|
/contracts/erc1155/generated-artifacts
|
||||||
/contracts/erc1155/test/generated-artifacts
|
|
||||||
/contracts/extensions/generated-wrappers
|
/contracts/extensions/generated-wrappers
|
||||||
/contracts/extensions/test/generated-wrappers
|
|
||||||
/contracts/extensions/generated-artifacts
|
/contracts/extensions/generated-artifacts
|
||||||
/contracts/extensions/test/generated-artifacts
|
|
||||||
/contracts/exchange-forwarder/generated-wrappers
|
/contracts/exchange-forwarder/generated-wrappers
|
||||||
/contracts/exchange-forwarder/test/generated-wrappers
|
|
||||||
/contracts/exchange-forwarder/generated-artifacts
|
/contracts/exchange-forwarder/generated-artifacts
|
||||||
/contracts/exchange-forwarder/test/generated-artifacts
|
|
||||||
/contracts/dev-utils/generated-wrappers
|
/contracts/dev-utils/generated-wrappers
|
||||||
/contracts/dev-utils/test/generated-wrappers
|
|
||||||
/contracts/dev-utils/generated-artifacts
|
/contracts/dev-utils/generated-artifacts
|
||||||
/contracts/dev-utils/test/generated-artifacts
|
|
||||||
/contracts/staking/build/
|
|
||||||
/contracts/coordinator/build/
|
|
||||||
/contracts/exchange/build/
|
|
||||||
/contracts/asset-proxy/build/
|
|
||||||
/contracts/multisig/build/
|
|
||||||
/contracts/utils/build/
|
|
||||||
/contracts/exchange-libs/build/
|
|
||||||
/contracts/erc20/build/
|
|
||||||
/contracts/erc721/build/
|
|
||||||
/contracts/erc1155/build/
|
|
||||||
/contracts/extensions/build/
|
|
||||||
/contracts/exchange-forwarder/build/
|
|
||||||
/contracts/dev-utils/build/
|
|
||||||
/packages/abi-gen/test-cli/output
|
/packages/abi-gen/test-cli/output
|
||||||
/packages/json-schemas/schemas
|
/packages/json-schemas/schemas
|
||||||
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
|
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"printWidth": 120,
|
|
||||||
"tabWidth": 4,
|
"tabWidth": 4,
|
||||||
"singleQuote": true,
|
"printWidth": 120,
|
||||||
"trailingComma": "all"
|
"trailingComma": all,
|
||||||
|
"singleQuote": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
# https://git-scm.com/docs/gitignore#_pattern_format
|
# https://git-scm.com/docs/gitignore#_pattern_format
|
||||||
|
|
||||||
# Website
|
# Website
|
||||||
packages/asset-swapper/ @BMillman19 @fragosti @dave4506
|
packages/asset-buyer/ @BMillman19 @fragosti @steveklebanoff
|
||||||
packages/instant/ @BMillman19 @fragosti @dave4506
|
packages/instant/ @BMillman19 @fragosti @steveklebanoff
|
||||||
|
|
||||||
# Dev tools & setup
|
# Dev tools & setup
|
||||||
.circleci/ @LogvinovLeon
|
.circleci/ @LogvinovLeon
|
||||||
@@ -14,8 +14,8 @@ packages/abi-gen/ @feuGeneA
|
|||||||
packages/base-contract/ @xianny
|
packages/base-contract/ @xianny
|
||||||
packages/connect/ @fragosti
|
packages/connect/ @fragosti
|
||||||
packages/abi-gen-templates/ @feuGeneA @xianny
|
packages/abi-gen-templates/ @feuGeneA @xianny
|
||||||
packages/contract-addresses/ @abandeali1
|
packages/contract-addresses/ @albrow
|
||||||
packages/contract-artifacts/ @abandeali1
|
packages/contract-artifacts/ @albrow
|
||||||
packages/dev-utils/ @LogvinovLeon @fabioberger
|
packages/dev-utils/ @LogvinovLeon @fabioberger
|
||||||
packages/devnet/ @albrow
|
packages/devnet/ @albrow
|
||||||
packages/ethereum-types/ @LogvinovLeon
|
packages/ethereum-types/ @LogvinovLeon
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -47,7 +47,6 @@ These packages are all under development. See [/contracts/README.md](/contracts/
|
|||||||
| [`@0x/contracts-utils`](/contracts/utils) | [](https://www.npmjs.com/package/@0x/contracts-utils) | Generic libraries and utilities used throughout all of the contracts |
|
| [`@0x/contracts-utils`](/contracts/utils) | [](https://www.npmjs.com/package/@0x/contracts-utils) | Generic libraries and utilities used throughout all of the contracts |
|
||||||
| [`@0x/contracts-coordinator`](/contracts/coordinator) | [](https://www.npmjs.com/package/@0x/contracts-coordinator) | A contract that allows users to execute 0x transactions with permission from a Coordinator |
|
| [`@0x/contracts-coordinator`](/contracts/coordinator) | [](https://www.npmjs.com/package/@0x/contracts-coordinator) | A contract that allows users to execute 0x transactions with permission from a Coordinator |
|
||||||
| [`@0x/contracts-dev-utils`](/contracts/dev-utils) | [](https://www.npmjs.com/package/@0x/contracts-dev-utils) | A contract contains utility functions for developers (such as validating many orders using a single eth_call) |
|
| [`@0x/contracts-dev-utils`](/contracts/dev-utils) | [](https://www.npmjs.com/package/@0x/contracts-dev-utils) | A contract contains utility functions for developers (such as validating many orders using a single eth_call) |
|
||||||
| [`@0x/contracts-staking`](/contracts/staking) | [](https://www.npmjs.com/package/@0x/contracts-staking) | Implements the stake-based liquidity incentives defined by [`ZEIP-31`](https://github.com/0xProject/ZEIPs/issues/31) |
|
|
||||||
|
|
||||||
### TypeScript/Javascript Packages
|
### TypeScript/Javascript Packages
|
||||||
|
|
||||||
@@ -61,9 +60,11 @@ These packages are all under development. See [/contracts/README.md](/contracts/
|
|||||||
| [`@0x/order-utils`](/packages/order-utils) | [](https://www.npmjs.com/package/@0x/order-utils) | A set of utilities for generating, parsing, signing and validating 0x orders |
|
| [`@0x/order-utils`](/packages/order-utils) | [](https://www.npmjs.com/package/@0x/order-utils) | A set of utilities for generating, parsing, signing and validating 0x orders |
|
||||||
| [`@0x/json-schemas`](/packages/json-schemas) | [](https://www.npmjs.com/package/@0x/json-schemas) | 0x-related JSON schemas | |
|
| [`@0x/json-schemas`](/packages/json-schemas) | [](https://www.npmjs.com/package/@0x/json-schemas) | 0x-related JSON schemas | |
|
||||||
| [`@0x/migrations`](/packages/migrations) | [](https://www.npmjs.com/package/@0x/migrations) | Migration tool for deploying 0x smart contracts on private testnets |
|
| [`@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 | |
|
| [`@0x/contract-artifacts`](/packages/contract-artifacts) | [](https://www.npmjs.com/package/@0x/contract-artifacts) | 0x smart contract compilation artifacts |
|
||||||
|
| [`@0x/abi-gen-wrappers`](/packages/abi-gen-wrappers) | [](https://www.npmjs.com/package/@0x/abi-gen-wrappers) | Low-level 0x smart contract wrappers generated using `@0x/abi-gen` |
|
||||||
| [`@0x/sra-spec`](/packages/sra-spec) | [](https://www.npmjs.com/package/@0x/sra-spec) | OpenAPI specification for the Standard Relayer API |
|
| [`@0x/sra-spec`](/packages/sra-spec) | [](https://www.npmjs.com/package/@0x/sra-spec) | OpenAPI specification for the Standard Relayer API |
|
||||||
| [`@0x/connect`](/packages/connect) | [](https://www.npmjs.com/package/@0x/connect) | An HTTP/WS client for interacting with the Standard Relayer API |
|
| [`@0x/connect`](/packages/connect) | [](https://www.npmjs.com/package/@0x/connect) | An HTTP/WS client for interacting with the Standard Relayer API |
|
||||||
|
| [`@0x/asset-buyer`](/packages/asset-buyer) | [](https://www.npmjs.com/package/@0x/asset-buyer) | Convenience package for discovering and buying assets with Ether |
|
||||||
| [`@0x/asset-swapper`](/packages/asset-swapper) | [](https://www.npmjs.com/package/@0x/asset-swapper) | Convenience package for discovering and performing swaps for any ERC20 Assets |
|
| [`@0x/asset-swapper`](/packages/asset-swapper) | [](https://www.npmjs.com/package/@0x/asset-swapper) | Convenience package for discovering and performing swaps for any ERC20 Assets |
|
||||||
|
|
||||||
#### Ethereum tooling
|
#### Ethereum tooling
|
||||||
@@ -91,12 +92,14 @@ These packages are all under development. See [/contracts/README.md](/contracts/
|
|||||||
| [`@0x/assert`](/packages/assert) | [](https://www.npmjs.com/package/@0x/assert) | Type and schema assertions used by our packages |
|
| [`@0x/assert`](/packages/assert) | [](https://www.npmjs.com/package/@0x/assert) | Type and schema assertions used by our packages |
|
||||||
| [`@0x/base-contract`](/packages/base-contract) | [](https://www.npmjs.com/package/@0x/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts |
|
| [`@0x/base-contract`](/packages/base-contract) | [](https://www.npmjs.com/package/@0x/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts |
|
||||||
| [`@0x/dev-utils`](/packages/dev-utils) | [](https://www.npmjs.com/package/@0x/dev-utils) | Dev utils to be shared across 0x packages |
|
| [`@0x/dev-utils`](/packages/dev-utils) | [](https://www.npmjs.com/package/@0x/dev-utils) | Dev utils to be shared across 0x packages |
|
||||||
|
| [`@0x/fill-scenarios`](/packages/fill-scenarios) | [](https://www.npmjs.com/package/@0x/fill-scenarios) | 0x order fill scenario generator |
|
||||||
|
|
||||||
#### Private Packages
|
#### Private Packages
|
||||||
|
|
||||||
| Package | Description |
|
| Package | Description |
|
||||||
| ---------------------------------- | -------------------------------------------------------------------------------- |
|
| -------------------------------------------------- | -------------------------------------------------------------------------------- |
|
||||||
| [`@0x/instant`](/packages/instant) | A free and flexible way to offer simple crypto purchasing in any app or website. |
|
| [`@0x/instant`](/packages/instant) | A free and flexible way to offer simple crypto purchasing in any app or website. |
|
||||||
|
| [`@0x/testnet-faucets`](/packages/testnet-faucets) | A faucet micro-service that dispenses test ERC20 tokens or Ether |
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,4 @@
|
|||||||
|
|
||||||
#### Development
|
#### Development
|
||||||
|
|
||||||
Building solidity files will update the contract artifact in `{package-name}/generated-artifacts/{contract}.json`, but does not automatically update the `contract-artifacts` or `contract-wrappers` packages, which are generated from the artifact JSON. See `contract-artifacts/README.md` for instructions on updating these packages.
|
Building solidity files will update the contract artifact in `{package-name}/generated-artifacts/{contract}.json`, but does not automatically update the `abi-gen-wrappers` package, which are generated from the artifact JSON. To ensure consistency, clean and rebuild `abi-gen-wrappers` after any changes to the artifact JSON.
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# Blacklist all files
|
|
||||||
.*
|
|
||||||
*
|
|
||||||
# Whitelist lib
|
|
||||||
!lib/**/*
|
|
||||||
# Whitelist Solidity contracts
|
|
||||||
!contracts/src/**/*
|
|
||||||
# Blacklist tests in lib
|
|
||||||
/lib/test/*
|
|
||||||
# Package specific ignore
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# solhint can't parse `abi.decode` syntax.
|
|
||||||
contracts/src/ERC1155Proxy.sol
|
|
||||||
@@ -1,180 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"timestamp": 1579682890,
|
|
||||||
"version": "3.1.1",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "3.1.0",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Integration tests for DydxBridge with ERC20BridgeProxy.",
|
|
||||||
"pr": 2401
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Fix `UniswapBridge` token -> token transfer call.",
|
|
||||||
"pr": 2412
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Fix `KyberBridge` incorrect `minConversionRate` calculation.",
|
|
||||||
"pr": 2412
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1578272714
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"timestamp": 1576540892,
|
|
||||||
"version": "3.0.2",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"timestamp": 1575931811,
|
|
||||||
"version": "3.0.1",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "3.0.0",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Implement `KyberBridge`.",
|
|
||||||
"pr": 2352
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
|
||||||
"pr": 2330
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "ERC20Wrapper and ERC1155ProxyWrapper constructors now require an instance of DevUtilsContract",
|
|
||||||
"pr": 2034
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Disallow the zero address from being made an authorized address in MixinAuthorizable, and created an archive directory that includes an old version of Ownable",
|
|
||||||
"pr": 2019
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove `LibAssetProxyIds` contract",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Compile and export all contracts, artifacts, and wrappers by default",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove unused dependency on IAuthorizable in IAssetProxy",
|
|
||||||
"pr": 1910
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `ERC20BridgeProxy`",
|
|
||||||
"pr": 2220
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `Eth2DaiBridge`",
|
|
||||||
"pr": 2221
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `UniswapBridge`",
|
|
||||||
"pr": 2233
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Replaced `SafeMath` with `LibSafeMath`",
|
|
||||||
"pr": 2254
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1575296764
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.3.0-beta.4",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Implement `KyberBridge`.",
|
|
||||||
"pr": 2352
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Implement `DydxBridge`.",
|
|
||||||
"pr": 2365
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1575290197
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.3.0-beta.3",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1574238768
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.3.0-beta.2",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
|
||||||
"pr": 2330
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1574030254
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.3.0-beta.1",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "ERC20Wrapper and ERC1155ProxyWrapper constructors now require an instance of DevUtilsContract",
|
|
||||||
"pr": 2034
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1573159180
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.3.0-beta.0",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Disallow the zero address from being made an authorized address in MixinAuthorizable, and created an archive directory that includes an old version of Ownable",
|
|
||||||
"pr": 2019
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove `LibAssetProxyIds` contract",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Compile and export all contracts, artifacts, and wrappers by default",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove unused dependency on IAuthorizable in IAssetProxy",
|
|
||||||
"pr": 1910
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `ERC20BridgeProxy`",
|
|
||||||
"pr": 2220
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `Eth2DaiBridge`",
|
|
||||||
"pr": 2221
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `UniswapBridge`",
|
|
||||||
"pr": 2233
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Replaced `SafeMath` with `LibSafeMath`",
|
|
||||||
"pr": 2254
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1570135330
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"timestamp": 1568744790,
|
"timestamp": 1568744790,
|
||||||
"version": "2.2.8",
|
"version": "2.2.8",
|
||||||
@@ -299,18 +123,6 @@
|
|||||||
{
|
{
|
||||||
"note": "Update tests to use contract-built-in `awaitTransactionSuccessAsync`",
|
"note": "Update tests to use contract-built-in `awaitTransactionSuccessAsync`",
|
||||||
"pr": 1797
|
"pr": 1797
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Make `ERC721Wrapper.setApprovalForAll()` take an owner address instead of a token ID",
|
|
||||||
"pr": 1819
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Automatically set unlimited proxy allowances in `ERC721.setBalancesAndAllowancesAsync()`",
|
|
||||||
"pr": 1819
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add `setProxyAllowanceForAllAsync()` to `ERC1155ProxyWrapper`.",
|
|
||||||
"pr": 1819
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"timestamp": 1557507213
|
"timestamp": 1557507213
|
||||||
|
|||||||
@@ -5,66 +5,6 @@ Edit the package's CHANGELOG.json file only.
|
|||||||
|
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
|
|
||||||
## v3.1.1 - _January 22, 2020_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.1.0 - _January 6, 2020_
|
|
||||||
|
|
||||||
* Integration tests for DydxBridge with ERC20BridgeProxy. (#2401)
|
|
||||||
* Fix `UniswapBridge` token -> token transfer call. (#2412)
|
|
||||||
* Fix `KyberBridge` incorrect `minConversionRate` calculation. (#2412)
|
|
||||||
|
|
||||||
## v3.0.2 - _December 17, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.1 - _December 9, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.0 - _December 2, 2019_
|
|
||||||
|
|
||||||
* Implement `KyberBridge`. (#2352)
|
|
||||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
|
||||||
* ERC20Wrapper and ERC1155ProxyWrapper constructors now require an instance of DevUtilsContract (#2034)
|
|
||||||
* Disallow the zero address from being made an authorized address in MixinAuthorizable, and created an archive directory that includes an old version of Ownable (#2019)
|
|
||||||
* Remove `LibAssetProxyIds` contract (#2055)
|
|
||||||
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
|
|
||||||
* Remove unused dependency on IAuthorizable in IAssetProxy (#1910)
|
|
||||||
* Add `ERC20BridgeProxy` (#2220)
|
|
||||||
* Add `Eth2DaiBridge` (#2221)
|
|
||||||
* Add `UniswapBridge` (#2233)
|
|
||||||
* Replaced `SafeMath` with `LibSafeMath` (#2254)
|
|
||||||
|
|
||||||
## v2.3.0-beta.4 - _December 2, 2019_
|
|
||||||
|
|
||||||
* Implement `KyberBridge`. (#2352)
|
|
||||||
* Implement `DydxBridge`. (#2365)
|
|
||||||
|
|
||||||
## v2.3.0-beta.3 - _November 20, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v2.3.0-beta.2 - _November 17, 2019_
|
|
||||||
|
|
||||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
|
||||||
|
|
||||||
## v2.3.0-beta.1 - _November 7, 2019_
|
|
||||||
|
|
||||||
* ERC20Wrapper and ERC1155ProxyWrapper constructors now require an instance of DevUtilsContract (#2034)
|
|
||||||
|
|
||||||
## v2.3.0-beta.0 - _October 3, 2019_
|
|
||||||
|
|
||||||
* Disallow the zero address from being made an authorized address in MixinAuthorizable, and created an archive directory that includes an old version of Ownable (#2019)
|
|
||||||
* Remove `LibAssetProxyIds` contract (#2055)
|
|
||||||
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
|
|
||||||
* Remove unused dependency on IAuthorizable in IAssetProxy (#1910)
|
|
||||||
* Add `ERC20BridgeProxy` (#2220)
|
|
||||||
* Add `Eth2DaiBridge` (#2221)
|
|
||||||
* Add `UniswapBridge` (#2233)
|
|
||||||
* Replaced `SafeMath` with `LibSafeMath` (#2254)
|
|
||||||
|
|
||||||
## v2.2.8 - _September 17, 2019_
|
## v2.2.8 - _September 17, 2019_
|
||||||
|
|
||||||
* Dependencies updated
|
* Dependencies updated
|
||||||
@@ -118,9 +58,6 @@ CHANGELOG
|
|||||||
## v2.1.2 - _May 10, 2019_
|
## v2.1.2 - _May 10, 2019_
|
||||||
|
|
||||||
* Update tests to use contract-built-in `awaitTransactionSuccessAsync` (#1797)
|
* Update tests to use contract-built-in `awaitTransactionSuccessAsync` (#1797)
|
||||||
* Make `ERC721Wrapper.setApprovalForAll()` take an owner address instead of a token ID (#1819)
|
|
||||||
* Automatically set unlimited proxy allowances in `ERC721.setBalancesAndAllowancesAsync()` (#1819)
|
|
||||||
* Add `setProxyAllowanceForAllAsync()` to `ERC1155ProxyWrapper`. (#1819)
|
|
||||||
|
|
||||||
## v2.1.1 - _April 11, 2019_
|
## v2.1.1 - _April 11, 2019_
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"artifactsDir": "./test/generated-artifacts",
|
"artifactsDir": "./generated-artifacts",
|
||||||
"contractsDir": "./contracts",
|
"contractsDir": "./contracts",
|
||||||
"useDockerisedSolc": false,
|
"useDockerisedSolc": false,
|
||||||
"isOfflineMode": false,
|
"isOfflineMode": false,
|
||||||
"compilerSettings": {
|
"compilerSettings": {
|
||||||
"evmVersion": "istanbul",
|
"evmVersion": "constantinople",
|
||||||
"optimizer": {
|
"optimizer": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"runs": 1000000,
|
"runs": 1000000,
|
||||||
@@ -22,5 +22,17 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"contracts": [
|
||||||
|
"src/ERC1155Proxy.sol",
|
||||||
|
"src/ERC20Proxy.sol",
|
||||||
|
"src/ERC721Proxy.sol",
|
||||||
|
"src/MixinAuthorizable.sol",
|
||||||
|
"src/MultiAssetProxy.sol",
|
||||||
|
"src/StaticCallProxy.sol",
|
||||||
|
"src/interfaces/IAssetData.sol",
|
||||||
|
"src/interfaces/IAssetProxy.sol",
|
||||||
|
"src/interfaces/IAuthorizable.sol",
|
||||||
|
"test/TestStaticCallTarget.sol"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
pragma solidity ^0.5.9;
|
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/interfaces/IOwnable.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract Ownable is
|
|
||||||
IOwnable
|
|
||||||
{
|
|
||||||
address public owner;
|
|
||||||
|
|
||||||
constructor ()
|
|
||||||
public
|
|
||||||
{
|
|
||||||
owner = msg.sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier onlyOwner() {
|
|
||||||
require(
|
|
||||||
msg.sender == owner,
|
|
||||||
"ONLY_CONTRACT_OWNER"
|
|
||||||
);
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
function transferOwnership(address newOwner)
|
|
||||||
public
|
|
||||||
onlyOwner
|
|
||||||
{
|
|
||||||
if (newOwner != address(0)) {
|
|
||||||
owner = newOwner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -19,18 +19,18 @@
|
|||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.9;
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
|
||||||
import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol";
|
import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol";
|
||||||
import "../archive/MixinAuthorizable.sol";
|
import "./MixinAuthorizable.sol";
|
||||||
import "./interfaces/IAssetProxy.sol";
|
import "./interfaces/IAssetProxy.sol";
|
||||||
|
|
||||||
|
|
||||||
contract ERC1155Proxy is
|
contract ERC1155Proxy is
|
||||||
MixinAuthorizable,
|
MixinAuthorizable,
|
||||||
|
SafeMath,
|
||||||
IAssetProxy
|
IAssetProxy
|
||||||
{
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
using LibSafeMath for uint256;
|
|
||||||
|
|
||||||
// Id of this proxy.
|
// Id of this proxy.
|
||||||
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)"));
|
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)"));
|
||||||
@@ -69,9 +69,9 @@ contract ERC1155Proxy is
|
|||||||
for (uint256 i = 0; i != length; i++) {
|
for (uint256 i = 0; i != length; i++) {
|
||||||
// We write the scaled values to an unused location in memory in order
|
// We write the scaled values to an unused location in memory in order
|
||||||
// to avoid copying over `ids` or `data`. This is possible if they are
|
// to avoid copying over `ids` or `data`. This is possible if they are
|
||||||
// identical to `values` and the offsets for each are pointing to the
|
// identical to `values` and the offsets for each are pointing to the
|
||||||
// same location in the ABI encoded calldata.
|
// same location in the ABI encoded calldata.
|
||||||
scaledValues[i] = values[i].safeMul(amount);
|
scaledValues[i] = safeMul(values[i], amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute `safeBatchTransferFrom` call
|
// Execute `safeBatchTransferFrom` call
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/Authorizable.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "./interfaces/IAssetProxy.sol";
|
|
||||||
import "./interfaces/IERC20Bridge.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract ERC20BridgeProxy is
|
|
||||||
IAssetProxy,
|
|
||||||
Authorizable
|
|
||||||
{
|
|
||||||
using LibBytes for bytes;
|
|
||||||
using LibSafeMath for uint256;
|
|
||||||
|
|
||||||
// @dev Id of this proxy. Also the result of a successful bridge call.
|
|
||||||
// bytes4(keccak256("ERC20Bridge(address,address,bytes)"))
|
|
||||||
bytes4 constant private PROXY_ID = 0xdc1600f3;
|
|
||||||
|
|
||||||
/// @dev Calls a bridge contract to transfer `amount` of ERC20 from `from`
|
|
||||||
/// to `to`. Asserts that the balance of `to` has increased by `amount`.
|
|
||||||
/// @param assetData Abi-encoded data for this asset proxy encoded as:
|
|
||||||
/// abi.encodeWithSelector(
|
|
||||||
/// bytes4 PROXY_ID,
|
|
||||||
/// address tokenAddress,
|
|
||||||
/// address bridgeAddress,
|
|
||||||
/// bytes bridgeData
|
|
||||||
/// )
|
|
||||||
/// @param from Address to transfer asset from.
|
|
||||||
/// @param to Address to transfer asset to.
|
|
||||||
/// @param amount Amount of asset to transfer.
|
|
||||||
function transferFrom(
|
|
||||||
bytes calldata assetData,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
onlyAuthorized
|
|
||||||
{
|
|
||||||
// Extract asset data fields.
|
|
||||||
(
|
|
||||||
address tokenAddress,
|
|
||||||
address bridgeAddress,
|
|
||||||
bytes memory bridgeData
|
|
||||||
) = abi.decode(
|
|
||||||
assetData.sliceDestructive(4, assetData.length),
|
|
||||||
(address, address, bytes)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remember the balance of `to` before calling the bridge.
|
|
||||||
uint256 balanceBefore = balanceOf(tokenAddress, to);
|
|
||||||
// Call the bridge, who should transfer `amount` of `tokenAddress` to
|
|
||||||
// `to`.
|
|
||||||
bytes4 success = IERC20Bridge(bridgeAddress).bridgeTransferFrom(
|
|
||||||
tokenAddress,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
bridgeData
|
|
||||||
);
|
|
||||||
// Bridge must return the proxy ID to indicate success.
|
|
||||||
require(success == PROXY_ID, "BRIDGE_FAILED");
|
|
||||||
// Ensure that the balance of `to` has increased by at least `amount`.
|
|
||||||
require(
|
|
||||||
balanceBefore.safeAdd(amount) <= balanceOf(tokenAddress, to),
|
|
||||||
"BRIDGE_UNDERPAY"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Gets the proxy id associated with this asset proxy.
|
|
||||||
/// @return proxyId The proxy id.
|
|
||||||
function getProxyId()
|
|
||||||
external
|
|
||||||
pure
|
|
||||||
returns (bytes4 proxyId)
|
|
||||||
{
|
|
||||||
return PROXY_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Retrieves the balance of `owner` for this asset.
|
|
||||||
/// @return balance The balance of the ERC20 token being transferred by this
|
|
||||||
/// asset proxy.
|
|
||||||
function balanceOf(bytes calldata assetData, address owner)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256 balance)
|
|
||||||
{
|
|
||||||
(address tokenAddress) = abi.decode(
|
|
||||||
assetData.sliceDestructive(4, assetData.length),
|
|
||||||
(address)
|
|
||||||
);
|
|
||||||
return balanceOf(tokenAddress, owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Retrieves the balance of `owner` given an ERC20 address.
|
|
||||||
/// @return balance The balance of the ERC20 token for `owner`.
|
|
||||||
function balanceOf(address tokenAddress, address owner)
|
|
||||||
private
|
|
||||||
view
|
|
||||||
returns (uint256 balance)
|
|
||||||
{
|
|
||||||
return IERC20Token(tokenAddress).balanceOf(owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../archive/MixinAuthorizable.sol";
|
import "./MixinAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
contract ERC20Proxy is
|
contract ERC20Proxy is
|
||||||
@@ -26,9 +26,9 @@ contract ERC20Proxy is
|
|||||||
{
|
{
|
||||||
// Id of this proxy.
|
// Id of this proxy.
|
||||||
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC20Token(address)"));
|
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC20Token(address)"));
|
||||||
|
|
||||||
// solhint-disable-next-line payable-fallback
|
// solhint-disable-next-line payable-fallback
|
||||||
function ()
|
function ()
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
assembly {
|
assembly {
|
||||||
@@ -117,13 +117,13 @@ contract ERC20Proxy is
|
|||||||
// * The "token address" is offset 32+4=36 bytes into "assetData" (tables 1 & 2).
|
// * The "token address" is offset 32+4=36 bytes into "assetData" (tables 1 & 2).
|
||||||
// [tokenOffset = assetDataOffsetFromHeader + 36 = calldataload(4) + 4 + 36]
|
// [tokenOffset = assetDataOffsetFromHeader + 36 = calldataload(4) + 4 + 36]
|
||||||
let token := calldataload(add(calldataload(4), 40))
|
let token := calldataload(add(calldataload(4), 40))
|
||||||
|
|
||||||
/////// Setup Header Area ///////
|
/////// Setup Header Area ///////
|
||||||
// This area holds the 4-byte `transferFrom` selector.
|
// This area holds the 4-byte `transferFrom` selector.
|
||||||
// Any trailing data in transferFromSelector will be
|
// Any trailing data in transferFromSelector will be
|
||||||
// overwritten in the next `mstore` call.
|
// overwritten in the next `mstore` call.
|
||||||
mstore(0, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
|
mstore(0, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
|
||||||
|
|
||||||
/////// Setup Params Area ///////
|
/////// Setup Params Area ///////
|
||||||
// We copy the fields `from`, `to` and `amount` in bulk
|
// We copy the fields `from`, `to` and `amount` in bulk
|
||||||
// from our own calldata to the new calldata.
|
// from our own calldata to the new calldata.
|
||||||
@@ -147,7 +147,7 @@ contract ERC20Proxy is
|
|||||||
// If the token does return data, we require that it is a single
|
// If the token does return data, we require that it is a single
|
||||||
// nonzero 32 bytes value.
|
// nonzero 32 bytes value.
|
||||||
// So the transfer succeeded if the call succeeded and either
|
// So the transfer succeeded if the call succeeded and either
|
||||||
// returned nothing, or returned a non-zero 32 byte value.
|
// returned nothing, or returned a non-zero 32 byte value.
|
||||||
success := and(success, or(
|
success := and(success, or(
|
||||||
iszero(returndatasize),
|
iszero(returndatasize),
|
||||||
and(
|
and(
|
||||||
@@ -158,7 +158,7 @@ contract ERC20Proxy is
|
|||||||
if success {
|
if success {
|
||||||
return(0, 0)
|
return(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert with `Error("TRANSFER_FAILED")`
|
// Revert with `Error("TRANSFER_FAILED")`
|
||||||
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
||||||
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
|
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../archive/MixinAuthorizable.sol";
|
import "./MixinAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
contract ERC721Proxy is
|
contract ERC721Proxy is
|
||||||
@@ -28,7 +28,7 @@ contract ERC721Proxy is
|
|||||||
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
|
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
|
||||||
|
|
||||||
// solhint-disable-next-line payable-fallback
|
// solhint-disable-next-line payable-fallback
|
||||||
function ()
|
function ()
|
||||||
external
|
external
|
||||||
{
|
{
|
||||||
assembly {
|
assembly {
|
||||||
@@ -93,10 +93,10 @@ contract ERC721Proxy is
|
|||||||
// | Params | | 2 * 32 | function parameters: |
|
// | Params | | 2 * 32 | function parameters: |
|
||||||
// | | 4 | 12 + 20 | 1. token address |
|
// | | 4 | 12 + 20 | 1. token address |
|
||||||
// | | 36 | | 2. tokenId |
|
// | | 36 | | 2. tokenId |
|
||||||
|
|
||||||
// We construct calldata for the `token.transferFrom` ABI.
|
// We construct calldata for the `token.transferFrom` ABI.
|
||||||
// The layout of this calldata is in the table below.
|
// The layout of this calldata is in the table below.
|
||||||
//
|
//
|
||||||
// | Area | Offset | Length | Contents |
|
// | Area | Offset | Length | Contents |
|
||||||
// |----------|--------|---------|-------------------------------------|
|
// |----------|--------|---------|-------------------------------------|
|
||||||
// | Header | 0 | 4 | function selector |
|
// | Header | 0 | 4 | function selector |
|
||||||
@@ -121,7 +121,7 @@ contract ERC721Proxy is
|
|||||||
// Any trailing data in transferFromSelector will be
|
// Any trailing data in transferFromSelector will be
|
||||||
// overwritten in the next `mstore` call.
|
// overwritten in the next `mstore` call.
|
||||||
mstore(0, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
|
mstore(0, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
|
||||||
|
|
||||||
/////// Setup Params Area ///////
|
/////// Setup Params Area ///////
|
||||||
// We copy the fields `from` and `to` in bulk
|
// We copy the fields `from` and `to` in bulk
|
||||||
// from our own calldata to the new calldata.
|
// from our own calldata to the new calldata.
|
||||||
@@ -145,7 +145,7 @@ contract ERC721Proxy is
|
|||||||
if success {
|
if success {
|
||||||
return(0, 0)
|
return(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert with `Error("TRANSFER_FAILED")`
|
// Revert with `Error("TRANSFER_FAILED")`
|
||||||
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
||||||
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
|
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../archive/Ownable.sol";
|
import "@0x/contracts-utils/contracts/src/Ownable.sol";
|
||||||
import "../src/interfaces/IAssetProxy.sol";
|
import "./mixins/MAssetProxyDispatcher.sol";
|
||||||
import "../src/interfaces/IAssetProxyDispatcher.sol";
|
import "./interfaces/IAssetProxy.sol";
|
||||||
|
|
||||||
|
|
||||||
contract MixinAssetProxyDispatcher is
|
contract MixinAssetProxyDispatcher is
|
||||||
Ownable,
|
Ownable,
|
||||||
IAssetProxyDispatcher
|
MAssetProxyDispatcher
|
||||||
{
|
{
|
||||||
// Mapping from Asset Proxy Id's to their respective Asset Proxy
|
// Mapping from Asset Proxy Id's to their respective Asset Proxy
|
||||||
mapping (bytes4 => address) public assetProxies;
|
mapping (bytes4 => address) public assetProxies;
|
||||||
@@ -69,7 +69,7 @@ contract MixinAssetProxyDispatcher is
|
|||||||
/// @param from Address to transfer token from.
|
/// @param from Address to transfer token from.
|
||||||
/// @param to Address to transfer token to.
|
/// @param to Address to transfer token to.
|
||||||
/// @param amount Amount of token to transfer.
|
/// @param amount Amount of token to transfer.
|
||||||
function _dispatchTransferFrom(
|
function dispatchTransferFrom(
|
||||||
bytes memory assetData,
|
bytes memory assetData,
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
@@ -84,7 +84,7 @@ contract MixinAssetProxyDispatcher is
|
|||||||
assetData.length > 3,
|
assetData.length > 3,
|
||||||
"LENGTH_GREATER_THAN_3_REQUIRED"
|
"LENGTH_GREATER_THAN_3_REQUIRED"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Lookup assetProxy. We do not use `LibBytes.readBytes4` for gas efficiency reasons.
|
// Lookup assetProxy. We do not use `LibBytes.readBytes4` for gas efficiency reasons.
|
||||||
bytes4 assetProxyId;
|
bytes4 assetProxyId;
|
||||||
assembly {
|
assembly {
|
||||||
@@ -100,10 +100,10 @@ contract MixinAssetProxyDispatcher is
|
|||||||
assetProxy != address(0),
|
assetProxy != address(0),
|
||||||
"ASSET_PROXY_DOES_NOT_EXIST"
|
"ASSET_PROXY_DOES_NOT_EXIST"
|
||||||
);
|
);
|
||||||
|
|
||||||
// We construct calldata for the `assetProxy.transferFrom` ABI.
|
// We construct calldata for the `assetProxy.transferFrom` ABI.
|
||||||
// The layout of this calldata is in the table below.
|
// The layout of this calldata is in the table below.
|
||||||
//
|
//
|
||||||
// | Area | Offset | Length | Contents |
|
// | Area | Offset | Length | Contents |
|
||||||
// | -------- |--------|---------|-------------------------------------------- |
|
// | -------- |--------|---------|-------------------------------------------- |
|
||||||
// | Header | 0 | 4 | function selector |
|
// | Header | 0 | 4 | function selector |
|
||||||
@@ -127,12 +127,12 @@ contract MixinAssetProxyDispatcher is
|
|||||||
// `cdEnd` is the end of the calldata for `assetProxy.transferFrom`.
|
// `cdEnd` is the end of the calldata for `assetProxy.transferFrom`.
|
||||||
let cdEnd := add(cdStart, add(132, dataAreaLength))
|
let cdEnd := add(cdStart, add(132, dataAreaLength))
|
||||||
|
|
||||||
|
|
||||||
/////// Setup Header Area ///////
|
/////// Setup Header Area ///////
|
||||||
// This area holds the 4-byte `transferFromSelector`.
|
// This area holds the 4-byte `transferFromSelector`.
|
||||||
// bytes4(keccak256("transferFrom(bytes,address,address,uint256)")) = 0xa85e59e4
|
// bytes4(keccak256("transferFrom(bytes,address,address,uint256)")) = 0xa85e59e4
|
||||||
mstore(cdStart, 0xa85e59e400000000000000000000000000000000000000000000000000000000)
|
mstore(cdStart, 0xa85e59e400000000000000000000000000000000000000000000000000000000)
|
||||||
|
|
||||||
/////// Setup Params Area ///////
|
/////// Setup Params Area ///////
|
||||||
// Each parameter is padded to 32-bytes. The entire Params Area is 128 bytes.
|
// Each parameter is padded to 32-bytes. The entire Params Area is 128 bytes.
|
||||||
// Notes:
|
// Notes:
|
||||||
@@ -142,7 +142,7 @@ contract MixinAssetProxyDispatcher is
|
|||||||
mstore(add(cdStart, 36), and(from, 0xffffffffffffffffffffffffffffffffffffffff))
|
mstore(add(cdStart, 36), and(from, 0xffffffffffffffffffffffffffffffffffffffff))
|
||||||
mstore(add(cdStart, 68), and(to, 0xffffffffffffffffffffffffffffffffffffffff))
|
mstore(add(cdStart, 68), and(to, 0xffffffffffffffffffffffffffffffffffffffff))
|
||||||
mstore(add(cdStart, 100), amount)
|
mstore(add(cdStart, 100), amount)
|
||||||
|
|
||||||
/////// Setup Data Area ///////
|
/////// Setup Data Area ///////
|
||||||
// This area holds `assetData`.
|
// This area holds `assetData`.
|
||||||
let dataArea := add(cdStart, 132)
|
let dataArea := add(cdStart, 132)
|
||||||
@@ -159,7 +159,7 @@ contract MixinAssetProxyDispatcher is
|
|||||||
assetProxy, // call address of asset proxy
|
assetProxy, // call address of asset proxy
|
||||||
0, // don't send any ETH
|
0, // don't send any ETH
|
||||||
cdStart, // pointer to start of input
|
cdStart, // pointer to start of input
|
||||||
sub(cdEnd, cdStart), // length of input
|
sub(cdEnd, cdStart), // length of input
|
||||||
cdStart, // write output over input
|
cdStart, // write output over input
|
||||||
512 // reserve 512 bytes for output
|
512 // reserve 512 bytes for output
|
||||||
)
|
)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../archive/Ownable.sol";
|
import "@0x/contracts-utils/contracts/src/Ownable.sol";
|
||||||
import "../src/interfaces/IAuthorizable.sol";
|
import "./mixins/MAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
contract MixinAuthorizable is
|
contract MixinAuthorizable is
|
||||||
Ownable,
|
Ownable,
|
||||||
IAuthorizable
|
MAuthorizable
|
||||||
{
|
{
|
||||||
/// @dev Only authorized addresses can invoke functions with this modifier.
|
/// @dev Only authorized addresses can invoke functions with this modifier.
|
||||||
modifier onlyAuthorized {
|
modifier onlyAuthorized {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../archive/MixinAssetProxyDispatcher.sol";
|
import "./MixinAssetProxyDispatcher.sol";
|
||||||
import "../archive/MixinAuthorizable.sol";
|
import "./MixinAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
contract MultiAssetProxy is
|
contract MultiAssetProxy is
|
||||||
@@ -105,7 +105,7 @@ contract MultiAssetProxy is
|
|||||||
// | | 36 | | 2. offset to nestedAssetData (*) |
|
// | | 36 | | 2. offset to nestedAssetData (*) |
|
||||||
// | Data | | | amounts: |
|
// | Data | | | amounts: |
|
||||||
// | | 68 | 32 | amounts Length |
|
// | | 68 | 32 | amounts Length |
|
||||||
// | | 100 | a | amounts Contents |
|
// | | 100 | a | amounts Contents |
|
||||||
// | | | | nestedAssetData: |
|
// | | | | nestedAssetData: |
|
||||||
// | | 100 + a | 32 | nestedAssetData Length |
|
// | | 100 + a | 32 | nestedAssetData Length |
|
||||||
// | | 132 + a | b | nestedAssetData Contents (offsets) |
|
// | | 132 + a | b | nestedAssetData Contents (offsets) |
|
||||||
@@ -149,8 +149,8 @@ contract MultiAssetProxy is
|
|||||||
// + 32 (amounts offset)
|
// + 32 (amounts offset)
|
||||||
let nestedAssetDataOffset := calldataload(add(assetDataOffset, 68))
|
let nestedAssetDataOffset := calldataload(add(assetDataOffset, 68))
|
||||||
|
|
||||||
// In order to find the start of the `amounts` contents, we must add:
|
// In order to find the start of the `amounts` contents, we must add:
|
||||||
// assetDataOffset
|
// assetDataOffset
|
||||||
// + 32 (assetData len)
|
// + 32 (assetData len)
|
||||||
// + 4 (assetProxyId)
|
// + 4 (assetProxyId)
|
||||||
// + amountsOffset
|
// + amountsOffset
|
||||||
@@ -160,8 +160,8 @@ contract MultiAssetProxy is
|
|||||||
// Load number of elements in `amounts`
|
// Load number of elements in `amounts`
|
||||||
let amountsLen := calldataload(sub(amountsContentsStart, 32))
|
let amountsLen := calldataload(sub(amountsContentsStart, 32))
|
||||||
|
|
||||||
// In order to find the start of the `nestedAssetData` contents, we must add:
|
// In order to find the start of the `nestedAssetData` contents, we must add:
|
||||||
// assetDataOffset
|
// assetDataOffset
|
||||||
// + 32 (assetData len)
|
// + 32 (assetData len)
|
||||||
// + 4 (assetProxyId)
|
// + 4 (assetProxyId)
|
||||||
// + nestedAssetDataOffset
|
// + nestedAssetDataOffset
|
||||||
@@ -190,10 +190,10 @@ contract MultiAssetProxy is
|
|||||||
|
|
||||||
// Overwrite existing offset to `assetData` with our own
|
// Overwrite existing offset to `assetData` with our own
|
||||||
mstore(4, 128)
|
mstore(4, 128)
|
||||||
|
|
||||||
// Load `amount`
|
// Load `amount`
|
||||||
let amount := calldataload(100)
|
let amount := calldataload(100)
|
||||||
|
|
||||||
// Calculate number of bytes in `amounts` contents
|
// Calculate number of bytes in `amounts` contents
|
||||||
let amountsByteLen := mul(amountsLen, 32)
|
let amountsByteLen := mul(amountsLen, 32)
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ contract MultiAssetProxy is
|
|||||||
let amountsElement := calldataload(add(amountsContentsStart, i))
|
let amountsElement := calldataload(add(amountsContentsStart, i))
|
||||||
let totalAmount := mul(amountsElement, amount)
|
let totalAmount := mul(amountsElement, amount)
|
||||||
|
|
||||||
// Revert if `amount` != 0 and multiplication resulted in an overflow
|
// Revert if `amount` != 0 and multiplication resulted in an overflow
|
||||||
if iszero(or(
|
if iszero(or(
|
||||||
iszero(amount),
|
iszero(amount),
|
||||||
eq(div(totalAmount, amount), amountsElement)
|
eq(div(totalAmount, amount), amountsElement)
|
||||||
@@ -228,7 +228,7 @@ contract MultiAssetProxy is
|
|||||||
let nestedAssetDataElementOffset := calldataload(add(nestedAssetDataContentsStart, i))
|
let nestedAssetDataElementOffset := calldataload(add(nestedAssetDataContentsStart, i))
|
||||||
|
|
||||||
// In order to find the start of the `nestedAssetData[i]` contents, we must add:
|
// In order to find the start of the `nestedAssetData[i]` contents, we must add:
|
||||||
// assetDataOffset
|
// assetDataOffset
|
||||||
// + 32 (assetData len)
|
// + 32 (assetData len)
|
||||||
// + 4 (assetProxyId)
|
// + 4 (assetProxyId)
|
||||||
// + nestedAssetDataOffset
|
// + nestedAssetDataOffset
|
||||||
@@ -274,7 +274,7 @@ contract MultiAssetProxy is
|
|||||||
mstore(164, assetProxies_slot)
|
mstore(164, assetProxies_slot)
|
||||||
assetProxy := sload(keccak256(132, 64))
|
assetProxy := sload(keccak256(132, 64))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert if AssetProxy with given id does not exist
|
// Revert if AssetProxy with given id does not exist
|
||||||
if iszero(assetProxy) {
|
if iszero(assetProxy) {
|
||||||
// Revert with `Error("ASSET_PROXY_DOES_NOT_EXIST")`
|
// Revert with `Error("ASSET_PROXY_DOES_NOT_EXIST")`
|
||||||
@@ -284,7 +284,7 @@ contract MultiAssetProxy is
|
|||||||
mstore(96, 0)
|
mstore(96, 0)
|
||||||
revert(0, 100)
|
revert(0, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy `nestedAssetData[i]` from calldata to memory
|
// Copy `nestedAssetData[i]` from calldata to memory
|
||||||
calldatacopy(
|
calldatacopy(
|
||||||
132, // memory slot after `amounts[i]`
|
132, // memory slot after `amounts[i]`
|
||||||
@@ -298,7 +298,7 @@ contract MultiAssetProxy is
|
|||||||
assetProxy, // call address of asset proxy
|
assetProxy, // call address of asset proxy
|
||||||
0, // don't send any ETH
|
0, // don't send any ETH
|
||||||
0, // pointer to start of input
|
0, // pointer to start of input
|
||||||
add(164, nestedAssetDataElementLen), // length of input
|
add(164, nestedAssetDataElementLen), // length of input
|
||||||
0, // write output over memory that won't be reused
|
0, // write output over memory that won't be reused
|
||||||
0 // don't copy output to memory
|
0 // don't copy output to memory
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "../interfaces/IERC20Bridge.sol";
|
|
||||||
import "../interfaces/IChai.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable space-after-comma
|
|
||||||
contract ChaiBridge is
|
|
||||||
IERC20Bridge,
|
|
||||||
DeploymentConstants
|
|
||||||
{
|
|
||||||
/// @dev Withdraws `amount` of `from` address's Dai from the Chai contract.
|
|
||||||
/// Transfers `amount` of Dai to `to` address.
|
|
||||||
/// @param from Address to transfer asset from.
|
|
||||||
/// @param to Address to transfer asset to.
|
|
||||||
/// @param amount Amount of asset to transfer.
|
|
||||||
/// @return success The magic bytes `0x37708e9b` if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address /* tokenAddress */,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata /* bridgeData */
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success)
|
|
||||||
{
|
|
||||||
// Ensure that only the `ERC20BridgeProxy` can call this function.
|
|
||||||
require(
|
|
||||||
msg.sender == _getERC20BridgeProxyAddress(),
|
|
||||||
"ChaiBridge/ONLY_CALLABLE_BY_ERC20_BRIDGE_PROXY"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Withdraw `from` address's Dai.
|
|
||||||
// NOTE: This contract must be approved to spend Chai on behalf of `from`.
|
|
||||||
bytes memory drawCalldata = abi.encodeWithSelector(
|
|
||||||
IChai(address(0)).draw.selector,
|
|
||||||
from,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
|
|
||||||
(bool success,) = _getChaiAddress().call(drawCalldata);
|
|
||||||
require(
|
|
||||||
success,
|
|
||||||
"ChaiBridge/DRAW_DAI_FAILED"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Transfer Dai to `to`
|
|
||||||
// This will never fail if the `draw` call was successful
|
|
||||||
IERC20Token(_getDaiAddress()).transfer(to, amount);
|
|
||||||
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
|
|
||||||
import "../interfaces/IERC20Bridge.sol";
|
|
||||||
import "../interfaces/IDydxBridge.sol";
|
|
||||||
import "../interfaces/IDydx.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract DydxBridge is
|
|
||||||
IERC20Bridge,
|
|
||||||
IDydxBridge,
|
|
||||||
DeploymentConstants
|
|
||||||
{
|
|
||||||
|
|
||||||
using LibSafeMath for uint256;
|
|
||||||
|
|
||||||
/// @dev Callback for `IERC20Bridge`. Deposits or withdraws tokens from a dydx account.
|
|
||||||
/// Notes:
|
|
||||||
/// 1. This bridge must be set as an operator of the input dydx account.
|
|
||||||
/// 2. This function may only be called in the context of the 0x Exchange.
|
|
||||||
/// 3. The maker or taker of the 0x order must be the dydx account owner.
|
|
||||||
/// 4. Deposits into dydx are made from the `from` address.
|
|
||||||
/// 5. Withdrawals from dydx are made to the `to` address.
|
|
||||||
/// 6. Calling this function must always withdraw at least `amount`,
|
|
||||||
/// otherwise the `ERC20Bridge` will revert.
|
|
||||||
/// @param from The sender of the tokens and owner of the dydx account.
|
|
||||||
/// @param to The recipient of the tokens.
|
|
||||||
/// @param amount Minimum amount of `toTokenAddress` tokens to deposit or withdraw.
|
|
||||||
/// @param encodedBridgeData An abi-encoded `BridgeData` struct.
|
|
||||||
/// @return success The magic bytes if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata encodedBridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success)
|
|
||||||
{
|
|
||||||
// Ensure that only the `ERC20BridgeProxy` can call this function.
|
|
||||||
require(
|
|
||||||
msg.sender == _getERC20BridgeProxyAddress(),
|
|
||||||
"DydxBridge/ONLY_CALLABLE_BY_ERC20_BRIDGE_PROXY"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Decode bridge data.
|
|
||||||
(BridgeData memory bridgeData) = abi.decode(encodedBridgeData, (BridgeData));
|
|
||||||
|
|
||||||
// The dydx accounts are owned by the `from` address.
|
|
||||||
IDydx.AccountInfo[] memory accounts = _createAccounts(from, bridgeData);
|
|
||||||
|
|
||||||
// Create dydx actions to run on the dydx accounts.
|
|
||||||
IDydx.ActionArgs[] memory actions = _createActions(
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
bridgeData
|
|
||||||
);
|
|
||||||
|
|
||||||
// Run operation. This will revert on failure.
|
|
||||||
IDydx(_getDydxAddress()).operate(accounts, actions);
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Creates an array of accounts for dydx to operate on.
|
|
||||||
/// All accounts must belong to the same owner.
|
|
||||||
/// @param accountOwner Owner of the dydx account.
|
|
||||||
/// @param bridgeData A `BridgeData` struct.
|
|
||||||
function _createAccounts(
|
|
||||||
address accountOwner,
|
|
||||||
BridgeData memory bridgeData
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
returns (IDydx.AccountInfo[] memory accounts)
|
|
||||||
{
|
|
||||||
uint256[] memory accountNumbers = bridgeData.accountNumbers;
|
|
||||||
uint256 nAccounts = accountNumbers.length;
|
|
||||||
accounts = new IDydx.AccountInfo[](nAccounts);
|
|
||||||
for (uint256 i = 0; i < nAccounts; ++i) {
|
|
||||||
accounts[i] = IDydx.AccountInfo({
|
|
||||||
owner: accountOwner,
|
|
||||||
number: accountNumbers[i]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Creates an array of actions to carry out on dydx.
|
|
||||||
/// @param depositFrom Deposit value from this address (owner of the dydx account).
|
|
||||||
/// @param withdrawTo Withdraw value to this address.
|
|
||||||
/// @param amount The amount of value available to operate on.
|
|
||||||
/// @param bridgeData A `BridgeData` struct.
|
|
||||||
function _createActions(
|
|
||||||
address depositFrom,
|
|
||||||
address withdrawTo,
|
|
||||||
uint256 amount,
|
|
||||||
BridgeData memory bridgeData
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
returns (IDydx.ActionArgs[] memory actions)
|
|
||||||
{
|
|
||||||
BridgeAction[] memory bridgeActions = bridgeData.actions;
|
|
||||||
uint256 nBridgeActions = bridgeActions.length;
|
|
||||||
actions = new IDydx.ActionArgs[](nBridgeActions);
|
|
||||||
for (uint256 i = 0; i < nBridgeActions; ++i) {
|
|
||||||
// Cache current bridge action.
|
|
||||||
BridgeAction memory bridgeAction = bridgeActions[i];
|
|
||||||
|
|
||||||
// Scale amount, if conversion rate is set.
|
|
||||||
uint256 scaledAmount;
|
|
||||||
if (bridgeAction.conversionRateDenominator > 0) {
|
|
||||||
scaledAmount = LibMath.safeGetPartialAmountFloor(
|
|
||||||
bridgeAction.conversionRateNumerator,
|
|
||||||
bridgeAction.conversionRateDenominator,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
scaledAmount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct dydx action.
|
|
||||||
if (bridgeAction.actionType == BridgeActionType.Deposit) {
|
|
||||||
// Deposit tokens from the account owner into their dydx account.
|
|
||||||
actions[i] = _createDepositAction(
|
|
||||||
depositFrom,
|
|
||||||
scaledAmount,
|
|
||||||
bridgeAction
|
|
||||||
);
|
|
||||||
} else if (bridgeAction.actionType == BridgeActionType.Withdraw) {
|
|
||||||
// Withdraw tokens from dydx to the `otherAccount`.
|
|
||||||
actions[i] = _createWithdrawAction(
|
|
||||||
withdrawTo,
|
|
||||||
scaledAmount,
|
|
||||||
bridgeAction
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// If all values in the `Action` enum are handled then this
|
|
||||||
// revert is unreachable: Solidity will revert when casting
|
|
||||||
// from `uint8` to `Action`.
|
|
||||||
revert("DydxBridge/UNRECOGNIZED_BRIDGE_ACTION");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Returns a dydx `DepositAction`.
|
|
||||||
/// @param depositFrom Deposit tokens from this address who is also the account owner.
|
|
||||||
/// @param amount of tokens to deposit.
|
|
||||||
/// @param bridgeAction A `BridgeAction` struct.
|
|
||||||
/// @return depositAction The encoded dydx action.
|
|
||||||
function _createDepositAction(
|
|
||||||
address depositFrom,
|
|
||||||
uint256 amount,
|
|
||||||
BridgeAction memory bridgeAction
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
pure
|
|
||||||
returns (
|
|
||||||
IDydx.ActionArgs memory depositAction
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Create dydx amount.
|
|
||||||
IDydx.AssetAmount memory dydxAmount = IDydx.AssetAmount({
|
|
||||||
sign: true, // true if positive.
|
|
||||||
denomination: IDydx.AssetDenomination.Wei, // Wei => actual token amount held in account.
|
|
||||||
ref: IDydx.AssetReference.Delta, // Delta => a relative amount.
|
|
||||||
value: amount // amount to deposit.
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create dydx deposit action.
|
|
||||||
depositAction = IDydx.ActionArgs({
|
|
||||||
actionType: IDydx.ActionType.Deposit, // deposit tokens.
|
|
||||||
amount: dydxAmount, // amount to deposit.
|
|
||||||
accountId: bridgeAction.accountId, // index in the `accounts` when calling `operate`.
|
|
||||||
primaryMarketId: bridgeAction.marketId, // indicates which token to deposit.
|
|
||||||
otherAddress: depositFrom, // deposit from the account owner.
|
|
||||||
// unused parameters
|
|
||||||
secondaryMarketId: 0,
|
|
||||||
otherAccountId: 0,
|
|
||||||
data: hex''
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Returns a dydx `WithdrawAction`.
|
|
||||||
/// @param withdrawTo Withdraw tokens to this address.
|
|
||||||
/// @param amount of tokens to withdraw.
|
|
||||||
/// @param bridgeAction A `BridgeAction` struct.
|
|
||||||
/// @return withdrawAction The encoded dydx action.
|
|
||||||
function _createWithdrawAction(
|
|
||||||
address withdrawTo,
|
|
||||||
uint256 amount,
|
|
||||||
BridgeAction memory bridgeAction
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
pure
|
|
||||||
returns (
|
|
||||||
IDydx.ActionArgs memory withdrawAction
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Create dydx amount.
|
|
||||||
IDydx.AssetAmount memory amountToWithdraw = IDydx.AssetAmount({
|
|
||||||
sign: false, // false if negative.
|
|
||||||
denomination: IDydx.AssetDenomination.Wei, // Wei => actual token amount held in account.
|
|
||||||
ref: IDydx.AssetReference.Delta, // Delta => a relative amount.
|
|
||||||
value: amount // amount to withdraw.
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create withdraw action.
|
|
||||||
withdrawAction = IDydx.ActionArgs({
|
|
||||||
actionType: IDydx.ActionType.Withdraw, // withdraw tokens.
|
|
||||||
amount: amountToWithdraw, // amount to withdraw.
|
|
||||||
accountId: bridgeAction.accountId, // index in the `accounts` when calling `operate`.
|
|
||||||
primaryMarketId: bridgeAction.marketId, // indicates which token to withdraw.
|
|
||||||
otherAddress: withdrawTo, // withdraw tokens to this address.
|
|
||||||
// unused parameters
|
|
||||||
secondaryMarketId: 0,
|
|
||||||
otherAccountId: 0,
|
|
||||||
data: hex''
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/IWallet.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
|
||||||
import "../interfaces/IERC20Bridge.sol";
|
|
||||||
import "../interfaces/IEth2Dai.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable space-after-comma
|
|
||||||
contract Eth2DaiBridge is
|
|
||||||
IERC20Bridge,
|
|
||||||
IWallet,
|
|
||||||
DeploymentConstants
|
|
||||||
{
|
|
||||||
/// @dev Callback for `IERC20Bridge`. Tries to buy `amount` of
|
|
||||||
/// `toTokenAddress` tokens by selling the entirety of the opposing asset
|
|
||||||
/// (DAI or WETH) to the Eth2Dai contract, then transfers the bought
|
|
||||||
/// tokens to `to`.
|
|
||||||
/// @param toTokenAddress The token to give to `to` (either DAI or WETH).
|
|
||||||
/// @param to The recipient of the bought tokens.
|
|
||||||
/// @param amount Minimum amount of `toTokenAddress` tokens to buy.
|
|
||||||
/// @param bridgeData The abi-encoeded "from" token address.
|
|
||||||
/// @return success The magic bytes if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address toTokenAddress,
|
|
||||||
address /* from */,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success)
|
|
||||||
{
|
|
||||||
// Decode the bridge data to get the `fromTokenAddress`.
|
|
||||||
(address fromTokenAddress) = abi.decode(bridgeData, (address));
|
|
||||||
|
|
||||||
IEth2Dai exchange = IEth2Dai(_getEth2DaiAddress());
|
|
||||||
// Grant an allowance to the exchange to spend `fromTokenAddress` token.
|
|
||||||
LibERC20Token.approve(fromTokenAddress, address(exchange), uint256(-1));
|
|
||||||
|
|
||||||
// Try to sell all of this contract's `fromTokenAddress` token balance.
|
|
||||||
uint256 boughtAmount = exchange.sellAllAmount(
|
|
||||||
fromTokenAddress,
|
|
||||||
IERC20Token(fromTokenAddress).balanceOf(address(this)),
|
|
||||||
toTokenAddress,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
// Transfer the converted `toToken`s to `to`.
|
|
||||||
LibERC20Token.transfer(toTokenAddress, to, boughtAmount);
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `SignatureType.Wallet` callback, so that this bridge can be the maker
|
|
||||||
/// and sign for itself in orders. Always succeeds.
|
|
||||||
/// @return magicValue Magic success bytes, always.
|
|
||||||
function isValidSignature(
|
|
||||||
bytes32,
|
|
||||||
bytes calldata
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes4 magicValue)
|
|
||||||
{
|
|
||||||
return LEGACY_WALLET_MAGIC_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/IWallet.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
|
||||||
import "../interfaces/IERC20Bridge.sol";
|
|
||||||
import "../interfaces/IKyberNetworkProxy.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable space-after-comma
|
|
||||||
contract KyberBridge is
|
|
||||||
IERC20Bridge,
|
|
||||||
IWallet,
|
|
||||||
DeploymentConstants
|
|
||||||
{
|
|
||||||
using LibSafeMath for uint256;
|
|
||||||
|
|
||||||
// @dev Structure used internally to get around stack limits.
|
|
||||||
struct TradeState {
|
|
||||||
IKyberNetworkProxy kyber;
|
|
||||||
IEtherToken weth;
|
|
||||||
address fromTokenAddress;
|
|
||||||
uint256 fromTokenBalance;
|
|
||||||
uint256 payableAmount;
|
|
||||||
uint256 conversionRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Kyber ETH pseudo-address.
|
|
||||||
address constant public KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
|
||||||
/// @dev `bridgeTransferFrom()` failure result.
|
|
||||||
bytes4 constant private BRIDGE_FAILED = 0x0;
|
|
||||||
/// @dev Precision of Kyber rates.
|
|
||||||
uint256 constant private KYBER_RATE_BASE = 10 ** 18;
|
|
||||||
|
|
||||||
// solhint-disable no-empty-blocks
|
|
||||||
/// @dev Payable fallback to receive ETH from Kyber.
|
|
||||||
function ()
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{}
|
|
||||||
|
|
||||||
/// @dev Callback for `IKyberBridge`. Tries to buy `amount` of
|
|
||||||
/// `toTokenAddress` tokens by selling the entirety of the opposing asset
|
|
||||||
/// to the `KyberNetworkProxy` contract, then transfers the bought
|
|
||||||
/// tokens to `to`.
|
|
||||||
/// @param toTokenAddress The token to give to `to`.
|
|
||||||
/// @param to The recipient of the bought tokens.
|
|
||||||
/// @param amount Minimum amount of `toTokenAddress` tokens to buy.
|
|
||||||
/// @param bridgeData The abi-encoeded "from" token address.
|
|
||||||
/// @return success The magic bytes if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address toTokenAddress,
|
|
||||||
address /* from */,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success)
|
|
||||||
{
|
|
||||||
TradeState memory state;
|
|
||||||
state.kyber = IKyberNetworkProxy(_getKyberNetworkProxyAddress());
|
|
||||||
state.weth = IEtherToken(_getWethAddress());
|
|
||||||
// Decode the bridge data to get the `fromTokenAddress`.
|
|
||||||
(state.fromTokenAddress) = abi.decode(bridgeData, (address));
|
|
||||||
// Query the balance of "from" tokens.
|
|
||||||
state.fromTokenBalance = IERC20Token(state.fromTokenAddress).balanceOf(address(this));
|
|
||||||
if (state.fromTokenBalance == 0) {
|
|
||||||
// Return failure if no input tokens.
|
|
||||||
return BRIDGE_FAILED;
|
|
||||||
}
|
|
||||||
// Compute the conversion rate, expressed in 18 decimals.
|
|
||||||
// The sequential notation is to get around stack limits.
|
|
||||||
state.conversionRate = KYBER_RATE_BASE;
|
|
||||||
state.conversionRate = state.conversionRate.safeMul(amount);
|
|
||||||
state.conversionRate = state.conversionRate.safeMul(
|
|
||||||
10 ** uint256(LibERC20Token.decimals(state.fromTokenAddress))
|
|
||||||
);
|
|
||||||
state.conversionRate = state.conversionRate.safeDiv(state.fromTokenBalance);
|
|
||||||
state.conversionRate = state.conversionRate.safeDiv(
|
|
||||||
10 ** uint256(LibERC20Token.decimals(toTokenAddress))
|
|
||||||
);
|
|
||||||
if (state.fromTokenAddress == toTokenAddress) {
|
|
||||||
// Just transfer the tokens if they're the same.
|
|
||||||
LibERC20Token.transfer(state.fromTokenAddress, to, state.fromTokenBalance);
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
} else if (state.fromTokenAddress != address(state.weth)) {
|
|
||||||
// If the input token is not WETH, grant an allowance to the exchange
|
|
||||||
// to spend them.
|
|
||||||
LibERC20Token.approve(state.fromTokenAddress, address(state.kyber), uint256(-1));
|
|
||||||
} else {
|
|
||||||
// If the input token is WETH, unwrap it and attach it to the call.
|
|
||||||
state.fromTokenAddress = KYBER_ETH_ADDRESS;
|
|
||||||
state.payableAmount = state.fromTokenBalance;
|
|
||||||
state.weth.withdraw(state.fromTokenBalance);
|
|
||||||
}
|
|
||||||
bool isToTokenWeth = toTokenAddress == address(state.weth);
|
|
||||||
|
|
||||||
// Try to sell all of this contract's input token balance through
|
|
||||||
// `KyberNetworkProxy.trade()`.
|
|
||||||
uint256 boughtAmount = state.kyber.trade.value(state.payableAmount)(
|
|
||||||
// Input token.
|
|
||||||
state.fromTokenAddress,
|
|
||||||
// Sell amount.
|
|
||||||
state.fromTokenBalance,
|
|
||||||
// Output token.
|
|
||||||
isToTokenWeth ? KYBER_ETH_ADDRESS : toTokenAddress,
|
|
||||||
// Transfer to this contract if converting to ETH, otherwise
|
|
||||||
// transfer directly to the recipient.
|
|
||||||
isToTokenWeth ? address(uint160(address(this))) : address(uint160(to)),
|
|
||||||
// Buy as much as possible.
|
|
||||||
uint256(-1),
|
|
||||||
// Compute the minimum conversion rate, which is expressed in units with
|
|
||||||
// 18 decimal places.
|
|
||||||
state.conversionRate,
|
|
||||||
// No affiliate address.
|
|
||||||
address(0)
|
|
||||||
);
|
|
||||||
// Wrap ETH output and transfer to recipient.
|
|
||||||
if (isToTokenWeth) {
|
|
||||||
state.weth.deposit.value(boughtAmount)();
|
|
||||||
state.weth.transfer(to, boughtAmount);
|
|
||||||
}
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `SignatureType.Wallet` callback, so that this bridge can be the maker
|
|
||||||
/// and sign for itself in orders. Always succeeds.
|
|
||||||
/// @return magicValue Magic success bytes, always.
|
|
||||||
function isValidSignature(
|
|
||||||
bytes32,
|
|
||||||
bytes calldata
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes4 magicValue)
|
|
||||||
{
|
|
||||||
return LEGACY_WALLET_MAGIC_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/IWallet.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
|
||||||
import "../interfaces/IUniswapExchangeFactory.sol";
|
|
||||||
import "../interfaces/IUniswapExchange.sol";
|
|
||||||
import "../interfaces/IERC20Bridge.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable space-after-comma
|
|
||||||
// solhint-disable not-rely-on-time
|
|
||||||
contract UniswapBridge is
|
|
||||||
IERC20Bridge,
|
|
||||||
IWallet,
|
|
||||||
DeploymentConstants
|
|
||||||
{
|
|
||||||
// Struct to hold `bridgeTransferFrom()` local variables in memory and to avoid
|
|
||||||
// stack overflows.
|
|
||||||
struct WithdrawToState {
|
|
||||||
IUniswapExchange exchange;
|
|
||||||
uint256 fromTokenBalance;
|
|
||||||
IEtherToken weth;
|
|
||||||
}
|
|
||||||
|
|
||||||
// solhint-disable no-empty-blocks
|
|
||||||
/// @dev Payable fallback to receive ETH from uniswap.
|
|
||||||
function ()
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{}
|
|
||||||
|
|
||||||
/// @dev Callback for `IERC20Bridge`. Tries to buy `amount` of
|
|
||||||
/// `toTokenAddress` tokens by selling the entirety of the `fromTokenAddress`
|
|
||||||
/// token encoded in the bridge data.
|
|
||||||
/// @param toTokenAddress The token to buy and transfer to `to`.
|
|
||||||
/// @param to The recipient of the bought tokens.
|
|
||||||
/// @param amount Minimum amount of `toTokenAddress` tokens to buy.
|
|
||||||
/// @param bridgeData The abi-encoded "from" token address.
|
|
||||||
/// @return success The magic bytes if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address toTokenAddress,
|
|
||||||
address /* from */,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success)
|
|
||||||
{
|
|
||||||
// State memory object to avoid stack overflows.
|
|
||||||
WithdrawToState memory state;
|
|
||||||
// Decode the bridge data to get the `fromTokenAddress`.
|
|
||||||
(address fromTokenAddress) = abi.decode(bridgeData, (address));
|
|
||||||
|
|
||||||
// Just transfer the tokens if they're the same.
|
|
||||||
if (fromTokenAddress == toTokenAddress) {
|
|
||||||
LibERC20Token.transfer(fromTokenAddress, to, amount);
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the exchange for the token pair.
|
|
||||||
state.exchange = _getUniswapExchangeForTokenPair(
|
|
||||||
fromTokenAddress,
|
|
||||||
toTokenAddress
|
|
||||||
);
|
|
||||||
// Get our balance of `fromTokenAddress` token.
|
|
||||||
state.fromTokenBalance = IERC20Token(fromTokenAddress).balanceOf(address(this));
|
|
||||||
// Get the weth contract.
|
|
||||||
state.weth = IEtherToken(_getWethAddress());
|
|
||||||
|
|
||||||
// Convert from WETH to a token.
|
|
||||||
if (fromTokenAddress == address(state.weth)) {
|
|
||||||
// Unwrap the WETH.
|
|
||||||
state.weth.withdraw(state.fromTokenBalance);
|
|
||||||
// Buy as much of `toTokenAddress` token with ETH as possible and
|
|
||||||
// transfer it to `to`.
|
|
||||||
state.exchange.ethToTokenTransferInput.value(state.fromTokenBalance)(
|
|
||||||
// Minimum buy amount.
|
|
||||||
amount,
|
|
||||||
// Expires after this block.
|
|
||||||
block.timestamp,
|
|
||||||
// Recipient is `to`.
|
|
||||||
to
|
|
||||||
);
|
|
||||||
|
|
||||||
// Convert from a token to WETH.
|
|
||||||
} else if (toTokenAddress == address(state.weth)) {
|
|
||||||
// Grant the exchange an allowance.
|
|
||||||
_grantExchangeAllowance(state.exchange, fromTokenAddress);
|
|
||||||
// Buy as much ETH with `fromTokenAddress` token as possible.
|
|
||||||
uint256 ethBought = state.exchange.tokenToEthSwapInput(
|
|
||||||
// Sell all tokens we hold.
|
|
||||||
state.fromTokenBalance,
|
|
||||||
// Minimum buy amount.
|
|
||||||
amount,
|
|
||||||
// Expires after this block.
|
|
||||||
block.timestamp
|
|
||||||
);
|
|
||||||
// Wrap the ETH.
|
|
||||||
state.weth.deposit.value(ethBought)();
|
|
||||||
// Transfer the WETH to `to`.
|
|
||||||
IEtherToken(toTokenAddress).transfer(to, ethBought);
|
|
||||||
|
|
||||||
// Convert from one token to another.
|
|
||||||
} else {
|
|
||||||
// Grant the exchange an allowance.
|
|
||||||
_grantExchangeAllowance(state.exchange, fromTokenAddress);
|
|
||||||
// Buy as much `toTokenAddress` token with `fromTokenAddress` token
|
|
||||||
// and transfer it to `to`.
|
|
||||||
state.exchange.tokenToTokenTransferInput(
|
|
||||||
// Sell all tokens we hold.
|
|
||||||
state.fromTokenBalance,
|
|
||||||
// Minimum buy amount.
|
|
||||||
amount,
|
|
||||||
// Must buy at least 1 intermediate ETH.
|
|
||||||
1,
|
|
||||||
// Expires after this block.
|
|
||||||
block.timestamp,
|
|
||||||
// Recipient is `to`.
|
|
||||||
to,
|
|
||||||
// Convert to `toTokenAddress`.
|
|
||||||
toTokenAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return BRIDGE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `SignatureType.Wallet` callback, so that this bridge can be the maker
|
|
||||||
/// and sign for itself in orders. Always succeeds.
|
|
||||||
/// @return magicValue Success bytes, always.
|
|
||||||
function isValidSignature(
|
|
||||||
bytes32,
|
|
||||||
bytes calldata
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes4 magicValue)
|
|
||||||
{
|
|
||||||
return LEGACY_WALLET_MAGIC_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Grants an unlimited allowance to the exchange for its token
|
|
||||||
/// on behalf of this contract.
|
|
||||||
/// @param exchange The Uniswap token exchange.
|
|
||||||
/// @param tokenAddress The token address for the exchange.
|
|
||||||
function _grantExchangeAllowance(IUniswapExchange exchange, address tokenAddress)
|
|
||||||
private
|
|
||||||
{
|
|
||||||
LibERC20Token.approve(tokenAddress, address(exchange), uint256(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Retrieves the uniswap exchange for a given token pair.
|
|
||||||
/// In the case of a WETH-token exchange, this will be the non-WETH token.
|
|
||||||
/// In th ecase of a token-token exchange, this will be the first token.
|
|
||||||
/// @param fromTokenAddress The address of the token we are converting from.
|
|
||||||
/// @param toTokenAddress The address of the token we are converting to.
|
|
||||||
/// @return exchange The uniswap exchange.
|
|
||||||
function _getUniswapExchangeForTokenPair(
|
|
||||||
address fromTokenAddress,
|
|
||||||
address toTokenAddress
|
|
||||||
)
|
|
||||||
private
|
|
||||||
view
|
|
||||||
returns (IUniswapExchange exchange)
|
|
||||||
{
|
|
||||||
address exchangeTokenAddress = fromTokenAddress;
|
|
||||||
// Whichever isn't WETH is the exchange token.
|
|
||||||
if (fromTokenAddress == _getWethAddress()) {
|
|
||||||
exchangeTokenAddress = toTokenAddress;
|
|
||||||
}
|
|
||||||
exchange = IUniswapExchange(
|
|
||||||
IUniswapExchangeFactory(_getUniswapExchangeFactoryAddress())
|
|
||||||
.getExchange(exchangeTokenAddress)
|
|
||||||
);
|
|
||||||
require(address(exchange) != address(0), "NO_UNISWAP_EXCHANGE_FOR_TOKEN");
|
|
||||||
return exchange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// solhint-disable
|
// solhint-disable
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,63 +26,33 @@ pragma experimental ABIEncoderV2;
|
|||||||
// This argument is ABI encoded as one of the methods of this interface.
|
// This argument is ABI encoded as one of the methods of this interface.
|
||||||
interface IAssetData {
|
interface IAssetData {
|
||||||
|
|
||||||
/// @dev Function signature for encoding ERC20 assetData.
|
|
||||||
/// @param tokenAddress Address of ERC20Token contract.
|
|
||||||
function ERC20Token(address tokenAddress)
|
function ERC20Token(address tokenAddress)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
/// @dev Function signature for encoding ERC721 assetData.
|
|
||||||
/// @param tokenAddress Address of ERC721 token contract.
|
|
||||||
/// @param tokenId Id of ERC721 token to be transferred.
|
|
||||||
function ERC721Token(
|
function ERC721Token(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256 tokenId
|
uint256 tokenId
|
||||||
)
|
)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
/// @dev Function signature for encoding ERC1155 assetData.
|
|
||||||
/// @param tokenAddress Address of ERC1155 token contract.
|
|
||||||
/// @param tokenIds Array of ids of tokens to be transferred.
|
|
||||||
/// @param values Array of values that correspond to each token id to be transferred.
|
|
||||||
/// Note that each value will be multiplied by the amount being filled in the order before transferring.
|
|
||||||
/// @param callbackData Extra data to be passed to receiver's `onERC1155Received` callback function.
|
|
||||||
function ERC1155Assets(
|
function ERC1155Assets(
|
||||||
address tokenAddress,
|
address tokenAddress,
|
||||||
uint256[] calldata tokenIds,
|
uint256[] calldata tokenIds,
|
||||||
uint256[] calldata values,
|
uint256[] calldata tokenValues,
|
||||||
bytes calldata callbackData
|
bytes calldata callbackData
|
||||||
)
|
)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
/// @dev Function signature for encoding MultiAsset assetData.
|
|
||||||
/// @param values Array of amounts that correspond to each asset to be transferred.
|
|
||||||
/// Note that each value will be multiplied by the amount being filled in the order before transferring.
|
|
||||||
/// @param nestedAssetData Array of assetData fields that will be be dispatched to their correspnding AssetProxy contract.
|
|
||||||
function MultiAsset(
|
function MultiAsset(
|
||||||
uint256[] calldata values,
|
uint256[] calldata amounts,
|
||||||
bytes[] calldata nestedAssetData
|
bytes[] calldata nestedAssetData
|
||||||
)
|
)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
/// @dev Function signature for encoding StaticCall assetData.
|
|
||||||
/// @param staticCallTargetAddress Address that will execute the staticcall.
|
|
||||||
/// @param staticCallData Data that will be executed via staticcall on the staticCallTargetAddress.
|
|
||||||
/// @param expectedReturnDataHash Keccak-256 hash of the expected staticcall return data.
|
|
||||||
function StaticCall(
|
function StaticCall(
|
||||||
address staticCallTargetAddress,
|
address callTarget,
|
||||||
bytes calldata staticCallData,
|
bytes calldata staticCallData,
|
||||||
bytes32 expectedReturnDataHash
|
bytes32 callResultHash
|
||||||
)
|
|
||||||
external;
|
|
||||||
|
|
||||||
/// @dev Function signature for encoding ERC20Bridge assetData.
|
|
||||||
/// @param tokenAddress Address of token to transfer.
|
|
||||||
/// @param bridgeAddress Address of the bridge contract.
|
|
||||||
/// @param bridgeData Arbitrary data to be passed to the bridge contract.
|
|
||||||
function ERC20Bridge(
|
|
||||||
address tokenAddress,
|
|
||||||
address bridgeAddress,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
)
|
||||||
external;
|
external;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
import "./IAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
contract IAssetProxy {
|
contract IAssetProxy {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,17 +16,11 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
|
||||||
contract IAssetProxyDispatcher {
|
contract IAssetProxyDispatcher {
|
||||||
|
|
||||||
// Logs registration of new asset proxy
|
|
||||||
event AssetProxyRegistered(
|
|
||||||
bytes4 id, // Id of new registered AssetProxy.
|
|
||||||
address assetProxy // Address of new registered AssetProxy.
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @dev Registers an asset proxy to its asset proxy id.
|
/// @dev Registers an asset proxy to its asset proxy id.
|
||||||
/// Once an asset proxy is registered, it cannot be unregistered.
|
/// Once an asset proxy is registered, it cannot be unregistered.
|
||||||
/// @param assetProxy Address of new asset proxy to register.
|
/// @param assetProxy Address of new asset proxy to register.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/interfaces/IOwnable.sol";
|
import "@0x/contracts-utils/contracts/src/interfaces/IOwnable.sol";
|
||||||
|
|
||||||
@@ -24,18 +24,6 @@ import "@0x/contracts-utils/contracts/src/interfaces/IOwnable.sol";
|
|||||||
contract IAuthorizable is
|
contract IAuthorizable is
|
||||||
IOwnable
|
IOwnable
|
||||||
{
|
{
|
||||||
// Event logged when a new address is authorized.
|
|
||||||
event AuthorizedAddressAdded(
|
|
||||||
address indexed target,
|
|
||||||
address indexed caller
|
|
||||||
);
|
|
||||||
|
|
||||||
// Event logged when a currently authorized address is unauthorized.
|
|
||||||
event AuthorizedAddressRemoved(
|
|
||||||
address indexed target,
|
|
||||||
address indexed caller
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @dev Authorizes an address.
|
/// @dev Authorizes an address.
|
||||||
/// @param target Address to authorize.
|
/// @param target Address to authorize.
|
||||||
function addAuthorizedAddress(address target)
|
function addAuthorizedAddress(address target)
|
||||||
@@ -54,7 +42,7 @@ contract IAuthorizable is
|
|||||||
uint256 index
|
uint256 index
|
||||||
)
|
)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
/// @dev Gets all authorized addresses.
|
/// @dev Gets all authorized addresses.
|
||||||
/// @return Array of authorized addresses.
|
/// @return Array of authorized addresses.
|
||||||
function getAuthorizedAddresses()
|
function getAuthorizedAddresses()
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract PotLike {
|
|
||||||
function chi() external returns (uint256);
|
|
||||||
function rho() external returns (uint256);
|
|
||||||
function drip() external returns (uint256);
|
|
||||||
function join(uint256) external;
|
|
||||||
function exit(uint256) external;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// The actual Chai contract can be found here: https://github.com/dapphub/chai
|
|
||||||
contract IChai is
|
|
||||||
IERC20Token
|
|
||||||
{
|
|
||||||
/// @dev Withdraws Dai owned by `src`
|
|
||||||
/// @param src Address that owns Dai.
|
|
||||||
/// @param wad Amount of Dai to withdraw.
|
|
||||||
function draw(
|
|
||||||
address src,
|
|
||||||
uint256 wad
|
|
||||||
)
|
|
||||||
external;
|
|
||||||
|
|
||||||
/// @dev Queries Dai balance of Chai holder.
|
|
||||||
/// @param usr Address of Chai holder.
|
|
||||||
/// @return Dai balance.
|
|
||||||
function dai(address usr)
|
|
||||||
external
|
|
||||||
returns (uint256);
|
|
||||||
|
|
||||||
/// @dev Queries the Pot contract used by the Chai contract.
|
|
||||||
function pot()
|
|
||||||
external
|
|
||||||
returns (PotLike);
|
|
||||||
|
|
||||||
/// @dev Deposits Dai in exchange for Chai
|
|
||||||
/// @param dst Address to receive Chai.
|
|
||||||
/// @param wad Amount of Dai to deposit.
|
|
||||||
function join(
|
|
||||||
address dst,
|
|
||||||
uint256 wad
|
|
||||||
)
|
|
||||||
external;
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
|
|
||||||
interface IDydx {
|
|
||||||
|
|
||||||
/// @dev Represents the unique key that specifies an account
|
|
||||||
struct AccountInfo {
|
|
||||||
address owner; // The address that owns the account
|
|
||||||
uint256 number; // A nonce that allows a single address to control many accounts
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ActionType {
|
|
||||||
Deposit, // supply tokens
|
|
||||||
Withdraw, // borrow tokens
|
|
||||||
Transfer, // transfer balance between accounts
|
|
||||||
Buy, // buy an amount of some token (externally)
|
|
||||||
Sell, // sell an amount of some token (externally)
|
|
||||||
Trade, // trade tokens against another account
|
|
||||||
Liquidate, // liquidate an undercollateralized or expiring account
|
|
||||||
Vaporize, // use excess tokens to zero-out a completely negative account
|
|
||||||
Call // send arbitrary data to an address
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Arguments that are passed to Solo in an ordered list as part of a single operation.
|
|
||||||
/// Each ActionArgs has an actionType which specifies which action struct that this data will be
|
|
||||||
/// parsed into before being processed.
|
|
||||||
struct ActionArgs {
|
|
||||||
ActionType actionType;
|
|
||||||
uint256 accountId;
|
|
||||||
AssetAmount amount;
|
|
||||||
uint256 primaryMarketId;
|
|
||||||
uint256 secondaryMarketId;
|
|
||||||
address otherAddress;
|
|
||||||
uint256 otherAccountId;
|
|
||||||
bytes data;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum AssetDenomination {
|
|
||||||
Wei, // the amount is denominated in wei
|
|
||||||
Par // the amount is denominated in par
|
|
||||||
}
|
|
||||||
|
|
||||||
enum AssetReference {
|
|
||||||
Delta, // the amount is given as a delta from the current value
|
|
||||||
Target // the amount is given as an exact number to end up at
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AssetAmount {
|
|
||||||
bool sign; // true if positive
|
|
||||||
AssetDenomination denomination;
|
|
||||||
AssetReference ref;
|
|
||||||
uint256 value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev The main entry-point to Solo that allows users and contracts to manage accounts.
|
|
||||||
/// Take one or more actions on one or more accounts. The msg.sender must be the owner or
|
|
||||||
/// operator of all accounts except for those being liquidated, vaporized, or traded with.
|
|
||||||
/// One call to operate() is considered a singular "operation". Account collateralization is
|
|
||||||
/// ensured only after the completion of the entire operation.
|
|
||||||
/// @param accounts A list of all accounts that will be used in this operation. Cannot contain
|
|
||||||
/// duplicates. In each action, the relevant account will be referred-to by its
|
|
||||||
/// index in the list.
|
|
||||||
/// @param actions An ordered list of all actions that will be taken in this operation. The
|
|
||||||
/// actions will be processed in order.
|
|
||||||
function operate(
|
|
||||||
AccountInfo[] calldata accounts,
|
|
||||||
ActionArgs[] calldata actions
|
|
||||||
)
|
|
||||||
external;
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
interface IDydxBridge {
|
|
||||||
|
|
||||||
/// @dev This is the subset of `IDydx.ActionType` that are supported by the bridge.
|
|
||||||
enum BridgeActionType {
|
|
||||||
Deposit, // Deposit tokens into dydx account.
|
|
||||||
Withdraw // Withdraw tokens from dydx account.
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BridgeAction {
|
|
||||||
BridgeActionType actionType; // Action to run on dydx account.
|
|
||||||
uint256 accountId; // Index in `BridgeData.accountNumbers` for this action.
|
|
||||||
uint256 marketId; // Market to operate on.
|
|
||||||
uint256 conversionRateNumerator; // Optional. If set, transfer amount is scaled by (conversionRateNumerator/conversionRateDenominator).
|
|
||||||
uint256 conversionRateDenominator; // Optional. If set, transfer amount is scaled by (conversionRateNumerator/conversionRateDenominator).
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BridgeData {
|
|
||||||
uint256[] accountNumbers; // Account number used to identify the owner's specific account.
|
|
||||||
BridgeAction[] actions; // Actions to carry out on the owner's accounts.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
contract IERC20Bridge {
|
|
||||||
|
|
||||||
// @dev Result of a successful bridge call.
|
|
||||||
bytes4 constant internal BRIDGE_SUCCESS = 0xdc1600f3;
|
|
||||||
|
|
||||||
/// @dev Transfers `amount` of the ERC20 `tokenAddress` from `from` to `to`.
|
|
||||||
/// @param tokenAddress The address of the ERC20 token to transfer.
|
|
||||||
/// @param from Address to transfer asset from.
|
|
||||||
/// @param to Address to transfer asset to.
|
|
||||||
/// @param amount Amount of asset to transfer.
|
|
||||||
/// @param bridgeData Arbitrary asset data needed by the bridge contract.
|
|
||||||
/// @return success The magic bytes `0x37708e9b` if successful.
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address tokenAddress,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4 success);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
interface IEth2Dai {
|
|
||||||
|
|
||||||
/// @dev Sell `sellAmount` of `fromToken` token and receive `toToken` token.
|
|
||||||
/// @param fromToken The token being sold.
|
|
||||||
/// @param sellAmount The amount of `fromToken` token being sold.
|
|
||||||
/// @param toToken The token being bought.
|
|
||||||
/// @param minFillAmount Minimum amount of `toToken` token to buy.
|
|
||||||
/// @return fillAmount Amount of `toToken` bought.
|
|
||||||
function sellAllAmount(
|
|
||||||
address fromToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
address toToken,
|
|
||||||
uint256 minFillAmount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 fillAmount);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
interface IKyberNetworkProxy {
|
|
||||||
|
|
||||||
/// @dev Sells `sellTokenAddress` tokens for `buyTokenAddress` tokens.
|
|
||||||
/// @param sellTokenAddress Token to sell.
|
|
||||||
/// @param sellAmount Amount of tokens to sell.
|
|
||||||
/// @param buyTokenAddress 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
|
|
||||||
/// @return boughtAmount Amount of tokens bought.
|
|
||||||
function trade(
|
|
||||||
address sellTokenAddress,
|
|
||||||
uint256 sellAmount,
|
|
||||||
address buyTokenAddress,
|
|
||||||
address payable recipientAddress,
|
|
||||||
uint256 maxBuyTokenAmount,
|
|
||||||
uint256 minConversionRate,
|
|
||||||
address walletId
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns(uint256 boughtAmount);
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
interface IUniswapExchange {
|
|
||||||
|
|
||||||
/// @dev Buys at least `minTokensBought` tokens with ETH and transfer them
|
|
||||||
/// to `recipient`.
|
|
||||||
/// @param minTokensBought The minimum number of tokens to buy.
|
|
||||||
/// @param deadline Time when this order expires.
|
|
||||||
/// @param recipient Who to transfer the tokens to.
|
|
||||||
/// @return tokensBought Amount of tokens bought.
|
|
||||||
function ethToTokenTransferInput(
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (uint256 tokensBought);
|
|
||||||
|
|
||||||
/// @dev Buys at least `minEthBought` ETH with tokens.
|
|
||||||
/// @param tokensSold Amount of tokens to sell.
|
|
||||||
/// @param minEthBought The minimum amount of ETH to buy.
|
|
||||||
/// @param deadline Time when this order expires.
|
|
||||||
/// @return ethBought Amount of tokens bought.
|
|
||||||
function tokenToEthSwapInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 ethBought);
|
|
||||||
|
|
||||||
/// @dev Buys at least `minTokensBought` tokens with the exchange token
|
|
||||||
/// and transfer them to `recipient`.
|
|
||||||
/// @param minTokensBought The minimum number of tokens to buy.
|
|
||||||
/// @param minEthBought The minimum amount of intermediate ETH to buy.
|
|
||||||
/// @param deadline Time when this order expires.
|
|
||||||
/// @param recipient Who to transfer the tokens to.
|
|
||||||
/// @param toTokenAddress The token being bought.
|
|
||||||
/// @return tokensBought Amount of tokens bought.
|
|
||||||
function tokenToTokenTransferInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient,
|
|
||||||
address toTokenAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 tokensBought);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
import "./IUniswapExchange.sol";
|
|
||||||
|
|
||||||
|
|
||||||
interface IUniswapExchangeFactory {
|
|
||||||
|
|
||||||
/// @dev Get the exchange for a token.
|
|
||||||
/// @param tokenAddress The address of the token contract.
|
|
||||||
function getExchange(address tokenAddress)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (address);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2019 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.5.5;
|
||||||
|
|
||||||
|
|
||||||
|
contract LibAssetProxyIds {
|
||||||
|
|
||||||
|
// AssetProxy Ids are equiavalent the first 4 bytes of the keccak256 hash of the function signature assigned to each AssetProxy.
|
||||||
|
|
||||||
|
// ERC20Token(address)
|
||||||
|
bytes4 constant public ERC20_PROXY_ID = 0xf47261b0;
|
||||||
|
|
||||||
|
// ERC721Token(address,uint256)
|
||||||
|
bytes4 constant public ERC721_PROXY_ID = 0x02571792;
|
||||||
|
|
||||||
|
// ERC1155Assets(address,uint256[],uint256[],bytes)
|
||||||
|
bytes4 constant public ERC1155_PROXY_ID = 0xa7cb5fb7;
|
||||||
|
|
||||||
|
// MultiAsset(uint256[],bytes[])
|
||||||
|
bytes4 constant public MULTI_ASSET_PROXY_ID = 0x94cfcdd7;
|
||||||
|
|
||||||
|
// StaticCall(address,bytes,bytes32)
|
||||||
|
bytes4 constant public STATIC_CALL_PROXY_ID = 0xc339d10a;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
import "../interfaces/IAssetProxyDispatcher.sol";
|
||||||
|
|
||||||
|
|
||||||
|
contract MAssetProxyDispatcher is
|
||||||
|
IAssetProxyDispatcher
|
||||||
|
{
|
||||||
|
// Logs registration of new asset proxy
|
||||||
|
event AssetProxyRegistered(
|
||||||
|
bytes4 id, // Id of new registered AssetProxy.
|
||||||
|
address assetProxy // Address of new registered AssetProxy.
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws.
|
||||||
|
/// @param assetData Byte array encoded for the asset.
|
||||||
|
/// @param from Address to transfer token from.
|
||||||
|
/// @param to Address to transfer token to.
|
||||||
|
/// @param amount Amount of token to transfer.
|
||||||
|
function dispatchTransferFrom(
|
||||||
|
bytes memory assetData,
|
||||||
|
address from,
|
||||||
|
address to,
|
||||||
|
uint256 amount
|
||||||
|
)
|
||||||
|
internal;
|
||||||
|
}
|
||||||
41
contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol
Normal file
41
contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
import "../interfaces/IAuthorizable.sol";
|
||||||
|
|
||||||
|
|
||||||
|
contract MAuthorizable is
|
||||||
|
IAuthorizable
|
||||||
|
{
|
||||||
|
// Event logged when a new address is authorized.
|
||||||
|
event AuthorizedAddressAdded(
|
||||||
|
address indexed target,
|
||||||
|
address indexed caller
|
||||||
|
);
|
||||||
|
|
||||||
|
// Event logged when a currently authorized address is unauthorized.
|
||||||
|
event AuthorizedAddressRemoved(
|
||||||
|
address indexed target,
|
||||||
|
address indexed caller
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @dev Only authorized addresses can invoke functions with this modifier.
|
||||||
|
modifier onlyAuthorized { revert(); _; }
|
||||||
|
}
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "../src/bridges/ChaiBridge.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/ERC20Token.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract TestChaiDai is
|
|
||||||
ERC20Token
|
|
||||||
{
|
|
||||||
address private constant ALWAYS_REVERT_ADDRESS = address(1);
|
|
||||||
|
|
||||||
function draw(
|
|
||||||
address from,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
if (from == ALWAYS_REVERT_ADDRESS) {
|
|
||||||
revert();
|
|
||||||
}
|
|
||||||
balances[msg.sender] += amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
contract TestChaiBridge is
|
|
||||||
ChaiBridge
|
|
||||||
{
|
|
||||||
address public testChaiDai;
|
|
||||||
address private constant ALWAYS_REVERT_ADDRESS = address(1);
|
|
||||||
|
|
||||||
constructor()
|
|
||||||
public
|
|
||||||
{
|
|
||||||
testChaiDai = address(new TestChaiDai());
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getDaiAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return testChaiDai;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getChaiAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return testChaiDai;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getERC20BridgeProxyAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return msg.sender == ALWAYS_REVERT_ADDRESS ? address(0) : msg.sender;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "../src/bridges/DydxBridge.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract TestDydxBridgeToken {
|
|
||||||
|
|
||||||
uint256 private constant INIT_HOLDER_BALANCE = 10 * 10**18; // 10 tokens
|
|
||||||
mapping (address => uint256) private _balances;
|
|
||||||
|
|
||||||
/// @dev Sets initial balance of token holders.
|
|
||||||
constructor(address[] memory holders)
|
|
||||||
public
|
|
||||||
{
|
|
||||||
for (uint256 i = 0; i != holders.length; ++i) {
|
|
||||||
_balances[holders[i]] = INIT_HOLDER_BALANCE;
|
|
||||||
}
|
|
||||||
_balances[msg.sender] = INIT_HOLDER_BALANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Basic transferFrom implementation.
|
|
||||||
function transferFrom(address from, address to, uint256 amount)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
if (_balances[from] < amount || _balances[to] + amount < _balances[to]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_balances[from] -= amount;
|
|
||||||
_balances[to] += amount;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Returns balance of `holder`.
|
|
||||||
function balanceOf(address holder)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return _balances[holder];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable space-after-comma
|
|
||||||
contract TestDydxBridge is
|
|
||||||
IDydx,
|
|
||||||
DydxBridge
|
|
||||||
{
|
|
||||||
|
|
||||||
address private constant ALWAYS_REVERT_ADDRESS = address(1);
|
|
||||||
address private _testTokenAddress;
|
|
||||||
bool private _shouldRevertOnOperate;
|
|
||||||
|
|
||||||
event OperateAccount(
|
|
||||||
address owner,
|
|
||||||
uint256 number
|
|
||||||
);
|
|
||||||
|
|
||||||
event OperateAction(
|
|
||||||
ActionType actionType,
|
|
||||||
uint256 accountId,
|
|
||||||
bool amountSign,
|
|
||||||
AssetDenomination amountDenomination,
|
|
||||||
AssetReference amountRef,
|
|
||||||
uint256 amountValue,
|
|
||||||
uint256 primaryMarketId,
|
|
||||||
uint256 secondaryMarketId,
|
|
||||||
address otherAddress,
|
|
||||||
uint256 otherAccountId,
|
|
||||||
bytes data
|
|
||||||
);
|
|
||||||
|
|
||||||
constructor(address[] memory holders)
|
|
||||||
public
|
|
||||||
{
|
|
||||||
// Deploy a test token. This represents the asset being deposited/withdrawn from dydx.
|
|
||||||
_testTokenAddress = address(new TestDydxBridgeToken(holders));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Simulates `operate` in dydx contract.
|
|
||||||
/// Emits events so that arguments can be validated client-side.
|
|
||||||
function operate(
|
|
||||||
AccountInfo[] calldata accounts,
|
|
||||||
ActionArgs[] calldata actions
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
if (_shouldRevertOnOperate) {
|
|
||||||
revert("TestDydxBridge/SHOULD_REVERT_ON_OPERATE");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint i = 0; i < accounts.length; ++i) {
|
|
||||||
emit OperateAccount(
|
|
||||||
accounts[i].owner,
|
|
||||||
accounts[i].number
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint i = 0; i < actions.length; ++i) {
|
|
||||||
emit OperateAction(
|
|
||||||
actions[i].actionType,
|
|
||||||
actions[i].accountId,
|
|
||||||
actions[i].amount.sign,
|
|
||||||
actions[i].amount.denomination,
|
|
||||||
actions[i].amount.ref,
|
|
||||||
actions[i].amount.value,
|
|
||||||
actions[i].primaryMarketId,
|
|
||||||
actions[i].secondaryMarketId,
|
|
||||||
actions[i].otherAddress,
|
|
||||||
actions[i].otherAccountId,
|
|
||||||
actions[i].data
|
|
||||||
);
|
|
||||||
|
|
||||||
if (actions[i].actionType == IDydx.ActionType.Withdraw) {
|
|
||||||
require(
|
|
||||||
IERC20Token(_testTokenAddress).transferFrom(
|
|
||||||
address(this),
|
|
||||||
actions[i].otherAddress,
|
|
||||||
actions[i].amount.value
|
|
||||||
),
|
|
||||||
"TestDydxBridge/WITHDRAW_FAILED"
|
|
||||||
);
|
|
||||||
} else if (actions[i].actionType == IDydx.ActionType.Deposit) {
|
|
||||||
require(
|
|
||||||
IERC20Token(_testTokenAddress).transferFrom(
|
|
||||||
actions[i].otherAddress,
|
|
||||||
address(this),
|
|
||||||
actions[i].amount.value
|
|
||||||
),
|
|
||||||
"TestDydxBridge/DEPOSIT_FAILED"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
revert("TestDydxBridge/UNSUPPORTED_ACTION");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev If `true` then subsequent calls to `operate` will revert.
|
|
||||||
function setRevertOnOperate(bool shouldRevert)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
_shouldRevertOnOperate = shouldRevert;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Returns test token.
|
|
||||||
function getTestToken()
|
|
||||||
external
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return _testTokenAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev overrides `_getDydxAddress()` from `DeploymentConstants` to return this address.
|
|
||||||
function _getDydxAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev overrides `_getERC20BridgeProxyAddress()` from `DeploymentConstants` for testing.
|
|
||||||
function _getERC20BridgeProxyAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return msg.sender == ALWAYS_REVERT_ADDRESS ? address(0) : msg.sender;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "../src/interfaces/IERC20Bridge.sol";
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev Test bridge token
|
|
||||||
contract TestERC20BridgeToken {
|
|
||||||
mapping (address => uint256) private _balances;
|
|
||||||
|
|
||||||
function addBalance(address owner, int256 amount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
setBalance(owner, uint256(int256(balanceOf(owner)) + amount));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBalance(address owner, uint256 balance)
|
|
||||||
public
|
|
||||||
{
|
|
||||||
_balances[owner] = balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
function balanceOf(address owner)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return _balances[owner];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev Test bridge contract.
|
|
||||||
contract TestERC20Bridge is
|
|
||||||
IERC20Bridge
|
|
||||||
{
|
|
||||||
TestERC20BridgeToken public testToken;
|
|
||||||
|
|
||||||
event BridgeWithdrawTo(
|
|
||||||
address tokenAddress,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes bridgeData
|
|
||||||
);
|
|
||||||
|
|
||||||
constructor() public {
|
|
||||||
testToken = new TestERC20BridgeToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTestTokenBalance(address owner, uint256 balance)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
testToken.setBalance(owner, balance);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bridgeTransferFrom(
|
|
||||||
address tokenAddress,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount,
|
|
||||||
bytes calldata bridgeData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bytes4)
|
|
||||||
{
|
|
||||||
emit BridgeWithdrawTo(
|
|
||||||
tokenAddress,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
bridgeData
|
|
||||||
);
|
|
||||||
// Unpack the bridgeData.
|
|
||||||
(
|
|
||||||
int256 transferAmount,
|
|
||||||
bytes memory revertData,
|
|
||||||
bytes memory returnData
|
|
||||||
) = abi.decode(bridgeData, (int256, bytes, bytes));
|
|
||||||
|
|
||||||
// If `revertData` is set, revert.
|
|
||||||
if (revertData.length != 0) {
|
|
||||||
assembly { revert(add(revertData, 0x20), mload(revertData)) }
|
|
||||||
}
|
|
||||||
// Increase `to`'s balance by `transferAmount`.
|
|
||||||
TestERC20BridgeToken(tokenAddress).addBalance(to, transferAmount);
|
|
||||||
// Return `returnData`.
|
|
||||||
assembly { return(add(returnData, 0x20), mload(returnData)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "../src/bridges/Eth2DaiBridge.sol";
|
|
||||||
import "../src/interfaces/IEth2Dai.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable no-simple-event-func-name
|
|
||||||
contract TestEvents {
|
|
||||||
|
|
||||||
event TokenTransfer(
|
|
||||||
address token,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event TokenApprove(
|
|
||||||
address token,
|
|
||||||
address spender,
|
|
||||||
uint256 allowance
|
|
||||||
);
|
|
||||||
|
|
||||||
function raiseTokenTransfer(
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenTransfer(
|
|
||||||
msg.sender,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseTokenApprove(address spender, uint256 allowance)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenApprove(msg.sender, spender, allowance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev A minimalist ERC20 token.
|
|
||||||
contract TestToken {
|
|
||||||
|
|
||||||
mapping (address => uint256) public balances;
|
|
||||||
string private _nextTransferRevertReason;
|
|
||||||
bytes private _nextTransferReturnData;
|
|
||||||
|
|
||||||
/// @dev Just calls `raiseTokenTransfer()` on the caller.
|
|
||||||
function transfer(address to, uint256 amount)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
TestEvents(msg.sender).raiseTokenTransfer(msg.sender, to, amount);
|
|
||||||
if (bytes(_nextTransferRevertReason).length != 0) {
|
|
||||||
revert(_nextTransferRevertReason);
|
|
||||||
}
|
|
||||||
bytes memory returnData = _nextTransferReturnData;
|
|
||||||
assembly { return(add(returnData, 0x20), mload(returnData)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Set the balance for `owner`.
|
|
||||||
function setBalance(address owner, uint256 balance)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
balances[owner] = balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Set the behavior of the `transfer()` call.
|
|
||||||
function setTransferBehavior(
|
|
||||||
string calldata revertReason,
|
|
||||||
bytes calldata returnData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
_nextTransferRevertReason = revertReason;
|
|
||||||
_nextTransferReturnData = returnData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Just calls `raiseTokenApprove()` on the caller.
|
|
||||||
function approve(address spender, uint256 allowance)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
TestEvents(msg.sender).raiseTokenApprove(spender, allowance);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Retrieve the balance for `owner`.
|
|
||||||
function balanceOf(address owner)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return balances[owner];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev Eth2DaiBridge overridden to mock tokens and
|
|
||||||
/// implement IEth2Dai.
|
|
||||||
contract TestEth2DaiBridge is
|
|
||||||
TestEvents,
|
|
||||||
IEth2Dai,
|
|
||||||
Eth2DaiBridge
|
|
||||||
{
|
|
||||||
event SellAllAmount(
|
|
||||||
address sellToken,
|
|
||||||
uint256 sellTokenAmount,
|
|
||||||
address buyToken,
|
|
||||||
uint256 minimumFillAmount
|
|
||||||
);
|
|
||||||
|
|
||||||
mapping (address => TestToken) public testTokens;
|
|
||||||
string private _nextRevertReason;
|
|
||||||
uint256 private _nextFillAmount;
|
|
||||||
|
|
||||||
/// @dev Create a token and set this contract's balance.
|
|
||||||
function createToken(uint256 balance)
|
|
||||||
external
|
|
||||||
returns (address tokenAddress)
|
|
||||||
{
|
|
||||||
TestToken token = new TestToken();
|
|
||||||
testTokens[address(token)] = token;
|
|
||||||
token.setBalance(address(this), balance);
|
|
||||||
return address(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Set the behavior for `IEth2Dai.sellAllAmount()`.
|
|
||||||
function setFillBehavior(string calldata revertReason, uint256 fillAmount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
_nextRevertReason = revertReason;
|
|
||||||
_nextFillAmount = fillAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Set the behavior of a token's `transfer()`.
|
|
||||||
function setTransferBehavior(
|
|
||||||
address tokenAddress,
|
|
||||||
string calldata revertReason,
|
|
||||||
bytes calldata returnData
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
testTokens[tokenAddress].setTransferBehavior(revertReason, returnData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Implementation of `IEth2Dai.sellAllAmount()`
|
|
||||||
function sellAllAmount(
|
|
||||||
address sellTokenAddress,
|
|
||||||
uint256 sellTokenAmount,
|
|
||||||
address buyTokenAddress,
|
|
||||||
uint256 minimumFillAmount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 fillAmount)
|
|
||||||
{
|
|
||||||
emit SellAllAmount(
|
|
||||||
sellTokenAddress,
|
|
||||||
sellTokenAmount,
|
|
||||||
buyTokenAddress,
|
|
||||||
minimumFillAmount
|
|
||||||
);
|
|
||||||
if (bytes(_nextRevertReason).length != 0) {
|
|
||||||
revert(_nextRevertReason);
|
|
||||||
}
|
|
||||||
return _nextFillAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @dev This contract will double as the Eth2Dai contract.
|
|
||||||
function _getEth2DaiAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,324 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "../src/bridges/KyberBridge.sol";
|
|
||||||
import "../src/interfaces/IKyberNetworkProxy.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable no-simple-event-func-name
|
|
||||||
interface ITestContract {
|
|
||||||
|
|
||||||
function wethWithdraw(
|
|
||||||
address payable ownerAddress,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external;
|
|
||||||
|
|
||||||
function wethDeposit(
|
|
||||||
address ownerAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable;
|
|
||||||
|
|
||||||
function tokenTransfer(
|
|
||||||
address ownerAddress,
|
|
||||||
address recipientAddress,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bool success);
|
|
||||||
|
|
||||||
function tokenApprove(
|
|
||||||
address ownerAddress,
|
|
||||||
address spenderAddress,
|
|
||||||
uint256 allowance
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bool success);
|
|
||||||
|
|
||||||
function tokenBalanceOf(
|
|
||||||
address ownerAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256 balance);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev A minimalist ERC20/WETH token.
|
|
||||||
contract TestToken {
|
|
||||||
|
|
||||||
uint8 public decimals;
|
|
||||||
ITestContract private _testContract;
|
|
||||||
|
|
||||||
constructor(uint8 decimals_) public {
|
|
||||||
decimals = decimals_;
|
|
||||||
_testContract = ITestContract(msg.sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
function approve(address spender, uint256 allowance)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
return _testContract.tokenApprove(
|
|
||||||
msg.sender,
|
|
||||||
spender,
|
|
||||||
allowance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function transfer(address recipient, uint256 amount)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
return _testContract.tokenTransfer(
|
|
||||||
msg.sender,
|
|
||||||
recipient,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function withdraw(uint256 amount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
return _testContract.wethWithdraw(msg.sender, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
function deposit()
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
return _testContract.wethDeposit.value(msg.value)(msg.sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
function balanceOf(address owner)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return _testContract.tokenBalanceOf(owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev KyberBridge overridden to mock tokens and implement IKyberBridge.
|
|
||||||
contract TestKyberBridge is
|
|
||||||
KyberBridge,
|
|
||||||
ITestContract,
|
|
||||||
IKyberNetworkProxy
|
|
||||||
{
|
|
||||||
event KyberBridgeTrade(
|
|
||||||
uint256 msgValue,
|
|
||||||
address sellTokenAddress,
|
|
||||||
uint256 sellAmount,
|
|
||||||
address buyTokenAddress,
|
|
||||||
address payable recipientAddress,
|
|
||||||
uint256 maxBuyTokenAmount,
|
|
||||||
uint256 minConversionRate,
|
|
||||||
address walletId
|
|
||||||
);
|
|
||||||
|
|
||||||
event KyberBridgeWethWithdraw(
|
|
||||||
address ownerAddress,
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event KyberBridgeWethDeposit(
|
|
||||||
uint256 msgValue,
|
|
||||||
address ownerAddress,
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event KyberBridgeTokenApprove(
|
|
||||||
address tokenAddress,
|
|
||||||
address ownerAddress,
|
|
||||||
address spenderAddress,
|
|
||||||
uint256 allowance
|
|
||||||
);
|
|
||||||
|
|
||||||
event KyberBridgeTokenTransfer(
|
|
||||||
address tokenAddress,
|
|
||||||
address ownerAddress,
|
|
||||||
address recipientAddress,
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
IEtherToken public weth;
|
|
||||||
mapping (address => mapping (address => uint256)) private _tokenBalances;
|
|
||||||
uint256 private _nextFillAmount;
|
|
||||||
|
|
||||||
constructor() public {
|
|
||||||
weth = IEtherToken(address(new TestToken(18)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Implementation of `IKyberNetworkProxy.trade()`
|
|
||||||
function trade(
|
|
||||||
address sellTokenAddress,
|
|
||||||
uint256 sellAmount,
|
|
||||||
address buyTokenAddress,
|
|
||||||
address payable recipientAddress,
|
|
||||||
uint256 maxBuyTokenAmount,
|
|
||||||
uint256 minConversionRate,
|
|
||||||
address walletId
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns(uint256 boughtAmount)
|
|
||||||
{
|
|
||||||
emit KyberBridgeTrade(
|
|
||||||
msg.value,
|
|
||||||
sellTokenAddress,
|
|
||||||
sellAmount,
|
|
||||||
buyTokenAddress,
|
|
||||||
recipientAddress,
|
|
||||||
maxBuyTokenAmount,
|
|
||||||
minConversionRate,
|
|
||||||
walletId
|
|
||||||
);
|
|
||||||
return _nextFillAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createToken(uint8 decimals)
|
|
||||||
external
|
|
||||||
returns (address tokenAddress)
|
|
||||||
{
|
|
||||||
return address(new TestToken(decimals));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setNextFillAmount(uint256 amount)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
if (msg.value != 0) {
|
|
||||||
require(amount == msg.value, "VALUE_AMOUNT_MISMATCH");
|
|
||||||
grantTokensTo(address(weth), address(this), msg.value);
|
|
||||||
}
|
|
||||||
_nextFillAmount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
function wethDeposit(
|
|
||||||
address ownerAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
require(msg.sender == address(weth), "ONLY_WETH");
|
|
||||||
grantTokensTo(address(weth), ownerAddress, msg.value);
|
|
||||||
emit KyberBridgeWethDeposit(
|
|
||||||
msg.value,
|
|
||||||
ownerAddress,
|
|
||||||
msg.value
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wethWithdraw(
|
|
||||||
address payable ownerAddress,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
require(msg.sender == address(weth), "ONLY_WETH");
|
|
||||||
_tokenBalances[address(weth)][ownerAddress] -= amount;
|
|
||||||
ownerAddress.transfer(amount);
|
|
||||||
emit KyberBridgeWethWithdraw(
|
|
||||||
ownerAddress,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenApprove(
|
|
||||||
address ownerAddress,
|
|
||||||
address spenderAddress,
|
|
||||||
uint256 allowance
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bool success)
|
|
||||||
{
|
|
||||||
emit KyberBridgeTokenApprove(
|
|
||||||
msg.sender,
|
|
||||||
ownerAddress,
|
|
||||||
spenderAddress,
|
|
||||||
allowance
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenTransfer(
|
|
||||||
address ownerAddress,
|
|
||||||
address recipientAddress,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (bool success)
|
|
||||||
{
|
|
||||||
_tokenBalances[msg.sender][ownerAddress] -= amount;
|
|
||||||
_tokenBalances[msg.sender][recipientAddress] += amount;
|
|
||||||
emit KyberBridgeTokenTransfer(
|
|
||||||
msg.sender,
|
|
||||||
ownerAddress,
|
|
||||||
recipientAddress,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenBalanceOf(
|
|
||||||
address ownerAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256 balance)
|
|
||||||
{
|
|
||||||
return _tokenBalances[msg.sender][ownerAddress];
|
|
||||||
}
|
|
||||||
|
|
||||||
function grantTokensTo(address tokenAddress, address ownerAddress, uint256 amount)
|
|
||||||
public
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
_tokenBalances[tokenAddress][ownerAddress] += amount;
|
|
||||||
if (tokenAddress != address(weth)) {
|
|
||||||
// Send back ether if not WETH.
|
|
||||||
msg.sender.transfer(msg.value);
|
|
||||||
} else {
|
|
||||||
require(msg.value == amount, "VALUE_AMOUNT_MISMATCH");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @dev overridden to point to this contract.
|
|
||||||
function _getKyberNetworkProxyAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @dev overridden to point to test WETH.
|
|
||||||
function _getWethAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(weth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,432 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
|
||||||
import "../src/bridges/UniswapBridge.sol";
|
|
||||||
import "../src/interfaces/IUniswapExchangeFactory.sol";
|
|
||||||
import "../src/interfaces/IUniswapExchange.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable no-simple-event-func-name
|
|
||||||
contract TestEventsRaiser {
|
|
||||||
|
|
||||||
event TokenTransfer(
|
|
||||||
address token,
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event TokenApprove(
|
|
||||||
address spender,
|
|
||||||
uint256 allowance
|
|
||||||
);
|
|
||||||
|
|
||||||
event WethDeposit(
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event WethWithdraw(
|
|
||||||
uint256 amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event EthToTokenTransferInput(
|
|
||||||
address exchange,
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient
|
|
||||||
);
|
|
||||||
|
|
||||||
event TokenToEthSwapInput(
|
|
||||||
address exchange,
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline
|
|
||||||
);
|
|
||||||
|
|
||||||
event TokenToTokenTransferInput(
|
|
||||||
address exchange,
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient,
|
|
||||||
address toTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
function raiseEthToTokenTransferInput(
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit EthToTokenTransferInput(
|
|
||||||
msg.sender,
|
|
||||||
minTokensBought,
|
|
||||||
deadline,
|
|
||||||
recipient
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseTokenToEthSwapInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenToEthSwapInput(
|
|
||||||
msg.sender,
|
|
||||||
tokensSold,
|
|
||||||
minEthBought,
|
|
||||||
deadline
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseTokenToTokenTransferInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient,
|
|
||||||
address toTokenAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenToTokenTransferInput(
|
|
||||||
msg.sender,
|
|
||||||
tokensSold,
|
|
||||||
minTokensBought,
|
|
||||||
minEthBought,
|
|
||||||
deadline,
|
|
||||||
recipient,
|
|
||||||
toTokenAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseTokenTransfer(
|
|
||||||
address from,
|
|
||||||
address to,
|
|
||||||
uint256 amount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenTransfer(
|
|
||||||
msg.sender,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseTokenApprove(address spender, uint256 allowance)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit TokenApprove(spender, allowance);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseWethDeposit(uint256 amount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit WethDeposit(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
function raiseWethWithdraw(uint256 amount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
emit WethWithdraw(amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev A minimalist ERC20/WETH token.
|
|
||||||
contract TestToken {
|
|
||||||
|
|
||||||
using LibSafeMath for uint256;
|
|
||||||
|
|
||||||
mapping (address => uint256) public balances;
|
|
||||||
string private _nextRevertReason;
|
|
||||||
|
|
||||||
/// @dev Set the balance for `owner`.
|
|
||||||
function setBalance(address owner)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
balances[owner] = msg.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Set the revert reason for `transfer()`,
|
|
||||||
/// `deposit()`, and `withdraw()`.
|
|
||||||
function setRevertReason(string calldata reason)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
_nextRevertReason = reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Just calls `raiseTokenTransfer()` on the caller.
|
|
||||||
function transfer(address to, uint256 amount)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
_revertIfReasonExists();
|
|
||||||
TestEventsRaiser(msg.sender).raiseTokenTransfer(msg.sender, to, amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Just calls `raiseTokenApprove()` on the caller.
|
|
||||||
function approve(address spender, uint256 allowance)
|
|
||||||
external
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
TestEventsRaiser(msg.sender).raiseTokenApprove(spender, allowance);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `IWETH.deposit()` that increases balances and calls
|
|
||||||
/// `raiseWethDeposit()` on the caller.
|
|
||||||
function deposit()
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
_revertIfReasonExists();
|
|
||||||
balances[msg.sender] += balances[msg.sender].safeAdd(msg.value);
|
|
||||||
TestEventsRaiser(msg.sender).raiseWethDeposit(msg.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `IWETH.withdraw()` that just reduces balances and calls
|
|
||||||
/// `raiseWethWithdraw()` on the caller.
|
|
||||||
function withdraw(uint256 amount)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
_revertIfReasonExists();
|
|
||||||
balances[msg.sender] = balances[msg.sender].safeSub(amount);
|
|
||||||
msg.sender.transfer(amount);
|
|
||||||
TestEventsRaiser(msg.sender).raiseWethWithdraw(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Retrieve the balance for `owner`.
|
|
||||||
function balanceOf(address owner)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return balances[owner];
|
|
||||||
}
|
|
||||||
|
|
||||||
function _revertIfReasonExists()
|
|
||||||
private
|
|
||||||
view
|
|
||||||
{
|
|
||||||
if (bytes(_nextRevertReason).length != 0) {
|
|
||||||
revert(_nextRevertReason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
contract TestExchange is
|
|
||||||
IUniswapExchange
|
|
||||||
{
|
|
||||||
address public tokenAddress;
|
|
||||||
string private _nextRevertReason;
|
|
||||||
|
|
||||||
constructor(address _tokenAddress) public {
|
|
||||||
tokenAddress = _tokenAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setFillBehavior(
|
|
||||||
string calldata revertReason
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
_nextRevertReason = revertReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ethToTokenTransferInput(
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (uint256 tokensBought)
|
|
||||||
{
|
|
||||||
TestEventsRaiser(msg.sender).raiseEthToTokenTransferInput(
|
|
||||||
minTokensBought,
|
|
||||||
deadline,
|
|
||||||
recipient
|
|
||||||
);
|
|
||||||
_revertIfReasonExists();
|
|
||||||
return address(this).balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenToEthSwapInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 ethBought)
|
|
||||||
{
|
|
||||||
TestEventsRaiser(msg.sender).raiseTokenToEthSwapInput(
|
|
||||||
tokensSold,
|
|
||||||
minEthBought,
|
|
||||||
deadline
|
|
||||||
);
|
|
||||||
_revertIfReasonExists();
|
|
||||||
uint256 fillAmount = address(this).balance;
|
|
||||||
msg.sender.transfer(fillAmount);
|
|
||||||
return fillAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tokenToTokenTransferInput(
|
|
||||||
uint256 tokensSold,
|
|
||||||
uint256 minTokensBought,
|
|
||||||
uint256 minEthBought,
|
|
||||||
uint256 deadline,
|
|
||||||
address recipient,
|
|
||||||
address toTokenAddress
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 tokensBought)
|
|
||||||
{
|
|
||||||
TestEventsRaiser(msg.sender).raiseTokenToTokenTransferInput(
|
|
||||||
tokensSold,
|
|
||||||
minTokensBought,
|
|
||||||
minEthBought,
|
|
||||||
deadline,
|
|
||||||
recipient,
|
|
||||||
toTokenAddress
|
|
||||||
);
|
|
||||||
_revertIfReasonExists();
|
|
||||||
return address(this).balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toTokenAddress()
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (address _tokenAddress)
|
|
||||||
{
|
|
||||||
return tokenAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _revertIfReasonExists()
|
|
||||||
private
|
|
||||||
view
|
|
||||||
{
|
|
||||||
if (bytes(_nextRevertReason).length != 0) {
|
|
||||||
revert(_nextRevertReason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// @dev UniswapBridge overridden to mock tokens and implement IUniswapExchangeFactory.
|
|
||||||
contract TestUniswapBridge is
|
|
||||||
IUniswapExchangeFactory,
|
|
||||||
TestEventsRaiser,
|
|
||||||
UniswapBridge
|
|
||||||
{
|
|
||||||
TestToken public wethToken;
|
|
||||||
// Token address to TestToken instance.
|
|
||||||
mapping (address => TestToken) private _testTokens;
|
|
||||||
// Token address to TestExchange instance.
|
|
||||||
mapping (address => TestExchange) private _testExchanges;
|
|
||||||
|
|
||||||
constructor() public {
|
|
||||||
wethToken = new TestToken();
|
|
||||||
_testTokens[address(wethToken)] = wethToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Sets the balance of this contract for an existing token.
|
|
||||||
/// The wei attached will be the balance.
|
|
||||||
function setTokenBalance(address tokenAddress)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
TestToken token = _testTokens[tokenAddress];
|
|
||||||
token.deposit.value(msg.value)();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Sets the revert reason for an existing token.
|
|
||||||
function setTokenRevertReason(address tokenAddress, string calldata revertReason)
|
|
||||||
external
|
|
||||||
{
|
|
||||||
TestToken token = _testTokens[tokenAddress];
|
|
||||||
token.setRevertReason(revertReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Create a token and exchange (if they don't exist) for a new token
|
|
||||||
/// and sets the exchange revert and fill behavior. The wei attached
|
|
||||||
/// will be the fill amount for the exchange.
|
|
||||||
/// @param tokenAddress The token address. If zero, one will be created.
|
|
||||||
/// @param revertReason The revert reason for exchange operations.
|
|
||||||
function createTokenAndExchange(
|
|
||||||
address tokenAddress,
|
|
||||||
string calldata revertReason
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (TestToken token, TestExchange exchange)
|
|
||||||
{
|
|
||||||
token = TestToken(tokenAddress);
|
|
||||||
if (tokenAddress == address(0)) {
|
|
||||||
token = new TestToken();
|
|
||||||
}
|
|
||||||
_testTokens[address(token)] = token;
|
|
||||||
exchange = _testExchanges[address(token)];
|
|
||||||
if (address(exchange) == address(0)) {
|
|
||||||
_testExchanges[address(token)] = exchange = new TestExchange(address(token));
|
|
||||||
}
|
|
||||||
exchange.setFillBehavior.value(msg.value)(revertReason);
|
|
||||||
return (token, exchange);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `IUniswapExchangeFactory.getExchange`
|
|
||||||
function getExchange(address tokenAddress)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(_testExchanges[tokenAddress]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @dev Use `wethToken`.
|
|
||||||
function _getWethAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(wethToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @dev This contract will double as the Uniswap contract.
|
|
||||||
function _getUniswapExchangeFactoryAddress()
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (address)
|
|
||||||
{
|
|
||||||
return address(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@0x/contracts-asset-proxy",
|
"name": "@0x/contracts-asset-proxy",
|
||||||
"version": "3.1.1",
|
"version": "2.2.8",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.12"
|
"node": ">=6.12"
|
||||||
},
|
},
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn pre_build && tsc -b",
|
"build": "yarn pre_build && tsc -b",
|
||||||
"build:ci": "yarn build",
|
"build:ci": "yarn build",
|
||||||
"pre_build": "run-s compile contracts:gen generate_contract_wrappers contracts:copy",
|
"pre_build": "run-s compile generate_contract_wrappers",
|
||||||
"test": "yarn run_mocha",
|
"test": "yarn run_mocha",
|
||||||
"rebuild_and_test": "run-s build test",
|
"rebuild_and_test": "run-s build test",
|
||||||
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
|
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
|
||||||
@@ -21,24 +21,20 @@
|
|||||||
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
|
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
|
||||||
"compile": "sol-compiler",
|
"compile": "sol-compiler",
|
||||||
"watch": "sol-compiler -w",
|
"watch": "sol-compiler -w",
|
||||||
"clean": "shx rm -rf lib test/generated-artifacts test/generated-wrappers generated-artifacts generated-wrappers",
|
"clean": "shx rm -rf lib generated-artifacts generated-wrappers",
|
||||||
"generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output test/generated-wrappers --backend ethers",
|
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers",
|
||||||
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
||||||
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
||||||
"coverage:report:text": "istanbul report text",
|
"coverage:report:text": "istanbul report text",
|
||||||
"coverage:report:html": "istanbul report html && open coverage/index.html",
|
"coverage:report:html": "istanbul report html && open coverage/index.html",
|
||||||
"profiler:report:html": "istanbul report html && open coverage/index.html",
|
"profiler:report:html": "istanbul report html && open coverage/index.html",
|
||||||
"coverage:report:lcov": "istanbul report lcov",
|
"coverage:report:lcov": "istanbul report lcov",
|
||||||
"test:circleci": "yarn test",
|
"test:circleci": "yarn test",
|
||||||
"contracts:gen": "contracts-gen generate",
|
"contracts:gen": "contracts-gen",
|
||||||
"contracts:copy": "contracts-gen copy",
|
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol",
|
|
||||||
"compile:truffle": "truffle compile",
|
|
||||||
"docs:md": "ts-doc-gen --sourceDir='$PROJECT_FILES' --output=$MD_FILE_DIR --fileExtension=mdx --tsconfig=./typedoc-tsconfig.json",
|
|
||||||
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
|
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"abis": "./test/generated-artifacts/@(ChaiBridge|DydxBridge|ERC1155Proxy|ERC20BridgeProxy|ERC20Proxy|ERC721Proxy|Eth2DaiBridge|IAssetData|IAssetProxy|IAssetProxyDispatcher|IAuthorizable|IChai|IDydx|IDydxBridge|IERC20Bridge|IEth2Dai|IKyberNetworkProxy|IUniswapExchange|IUniswapExchangeFactory|KyberBridge|MixinAssetProxyDispatcher|MixinAuthorizable|MultiAssetProxy|Ownable|StaticCallProxy|TestChaiBridge|TestDydxBridge|TestERC20Bridge|TestEth2DaiBridge|TestKyberBridge|TestStaticCallTarget|TestUniswapBridge|UniswapBridge).json",
|
"abis": "./generated-artifacts/@(ERC1155Proxy|ERC20Proxy|ERC721Proxy|IAssetData|IAssetProxy|IAuthorizable|MixinAuthorizable|MultiAssetProxy|StaticCallProxy|TestStaticCallTarget).json",
|
||||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -51,15 +47,12 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md",
|
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@0x/abi-gen": "^5.1.0",
|
"@0x/abi-gen": "^4.2.1",
|
||||||
"@0x/contracts-gen": "^2.0.4",
|
"@0x/contracts-gen": "^1.0.15",
|
||||||
"@0x/contracts-test-utils": "^5.1.1",
|
"@0x/contracts-test-utils": "^3.1.16",
|
||||||
"@0x/contracts-utils": "^4.1.0",
|
"@0x/dev-utils": "^2.3.3",
|
||||||
"@0x/dev-utils": "^3.1.1",
|
"@0x/sol-compiler": "^3.1.15",
|
||||||
"@0x/sol-compiler": "^4.0.4",
|
"@0x/tslint-config": "^3.0.1",
|
||||||
"@0x/ts-doc-gen": "^0.0.22",
|
|
||||||
"@0x/tslint-config": "^4.0.0",
|
|
||||||
"@0x/types": "^3.1.1",
|
|
||||||
"@types/lodash": "4.14.104",
|
"@types/lodash": "4.14.104",
|
||||||
"@types/mocha": "^5.2.7",
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
@@ -67,29 +60,27 @@
|
|||||||
"chai-as-promised": "^7.1.0",
|
"chai-as-promised": "^7.1.0",
|
||||||
"chai-bignumber": "^3.0.0",
|
"chai-bignumber": "^3.0.0",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"ethereumjs-util": "^5.1.1",
|
|
||||||
"make-promises-safe": "^1.1.0",
|
"make-promises-safe": "^1.1.0",
|
||||||
"mocha": "^6.2.0",
|
"mocha": "^6.2.0",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
"shx": "^0.2.2",
|
"shx": "^0.2.2",
|
||||||
"solhint": "^1.4.1",
|
"solhint": "^1.4.1",
|
||||||
"truffle": "^5.0.32",
|
|
||||||
"tslint": "5.11.0",
|
"tslint": "5.11.0",
|
||||||
"typedoc": "^0.15.0",
|
|
||||||
"typescript": "3.0.1"
|
"typescript": "3.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@0x/base-contract": "^6.1.0",
|
"@0x/base-contract": "^5.4.0",
|
||||||
"@0x/contracts-dev-utils": "^1.0.4",
|
"@0x/contracts-erc1155": "^1.1.15",
|
||||||
"@0x/contracts-erc1155": "^2.0.4",
|
"@0x/contracts-erc20": "^2.2.14",
|
||||||
"@0x/contracts-erc20": "^3.0.4",
|
"@0x/contracts-erc721": "^2.1.15",
|
||||||
"@0x/contracts-erc721": "^3.0.4",
|
"@0x/contracts-utils": "^3.2.4",
|
||||||
"@0x/contracts-exchange-libs": "^4.1.0",
|
"@0x/order-utils": "^8.4.0",
|
||||||
"@0x/order-utils": "^10.1.1",
|
"@0x/types": "^2.4.3",
|
||||||
"@0x/typescript-typings": "^5.0.1",
|
"@0x/typescript-typings": "^4.3.0",
|
||||||
"@0x/utils": "^5.2.0",
|
"@0x/utils": "^4.5.2",
|
||||||
"@0x/web3-wrapper": "^7.0.4",
|
"@0x/web3-wrapper": "^6.0.13",
|
||||||
"ethereum-types": "^3.0.0",
|
"ethereum-types": "^2.1.6",
|
||||||
|
"ethereumjs-util": "^5.1.1",
|
||||||
"lodash": "^4.17.11"
|
"lodash": "^4.17.11"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|||||||
@@ -5,71 +5,25 @@
|
|||||||
*/
|
*/
|
||||||
import { ContractArtifact } from 'ethereum-types';
|
import { ContractArtifact } from 'ethereum-types';
|
||||||
|
|
||||||
import * as ChaiBridge from '../generated-artifacts/ChaiBridge.json';
|
|
||||||
import * as DydxBridge from '../generated-artifacts/DydxBridge.json';
|
|
||||||
import * as ERC1155Proxy from '../generated-artifacts/ERC1155Proxy.json';
|
import * as ERC1155Proxy from '../generated-artifacts/ERC1155Proxy.json';
|
||||||
import * as ERC20BridgeProxy from '../generated-artifacts/ERC20BridgeProxy.json';
|
|
||||||
import * as ERC20Proxy from '../generated-artifacts/ERC20Proxy.json';
|
import * as ERC20Proxy from '../generated-artifacts/ERC20Proxy.json';
|
||||||
import * as ERC721Proxy from '../generated-artifacts/ERC721Proxy.json';
|
import * as ERC721Proxy from '../generated-artifacts/ERC721Proxy.json';
|
||||||
import * as Eth2DaiBridge from '../generated-artifacts/Eth2DaiBridge.json';
|
|
||||||
import * as IAssetData from '../generated-artifacts/IAssetData.json';
|
import * as IAssetData from '../generated-artifacts/IAssetData.json';
|
||||||
import * as IAssetProxy from '../generated-artifacts/IAssetProxy.json';
|
import * as IAssetProxy from '../generated-artifacts/IAssetProxy.json';
|
||||||
import * as IAssetProxyDispatcher from '../generated-artifacts/IAssetProxyDispatcher.json';
|
|
||||||
import * as IAuthorizable from '../generated-artifacts/IAuthorizable.json';
|
import * as IAuthorizable from '../generated-artifacts/IAuthorizable.json';
|
||||||
import * as IChai from '../generated-artifacts/IChai.json';
|
|
||||||
import * as IDydx from '../generated-artifacts/IDydx.json';
|
|
||||||
import * as IDydxBridge from '../generated-artifacts/IDydxBridge.json';
|
|
||||||
import * as IERC20Bridge from '../generated-artifacts/IERC20Bridge.json';
|
|
||||||
import * as IEth2Dai from '../generated-artifacts/IEth2Dai.json';
|
|
||||||
import * as IKyberNetworkProxy from '../generated-artifacts/IKyberNetworkProxy.json';
|
|
||||||
import * as IUniswapExchange from '../generated-artifacts/IUniswapExchange.json';
|
|
||||||
import * as IUniswapExchangeFactory from '../generated-artifacts/IUniswapExchangeFactory.json';
|
|
||||||
import * as KyberBridge from '../generated-artifacts/KyberBridge.json';
|
|
||||||
import * as MixinAssetProxyDispatcher from '../generated-artifacts/MixinAssetProxyDispatcher.json';
|
|
||||||
import * as MixinAuthorizable from '../generated-artifacts/MixinAuthorizable.json';
|
import * as MixinAuthorizable from '../generated-artifacts/MixinAuthorizable.json';
|
||||||
import * as MultiAssetProxy from '../generated-artifacts/MultiAssetProxy.json';
|
import * as MultiAssetProxy from '../generated-artifacts/MultiAssetProxy.json';
|
||||||
import * as Ownable from '../generated-artifacts/Ownable.json';
|
|
||||||
import * as StaticCallProxy from '../generated-artifacts/StaticCallProxy.json';
|
import * as StaticCallProxy from '../generated-artifacts/StaticCallProxy.json';
|
||||||
import * as TestChaiBridge from '../generated-artifacts/TestChaiBridge.json';
|
|
||||||
import * as TestDydxBridge from '../generated-artifacts/TestDydxBridge.json';
|
|
||||||
import * as TestERC20Bridge from '../generated-artifacts/TestERC20Bridge.json';
|
|
||||||
import * as TestEth2DaiBridge from '../generated-artifacts/TestEth2DaiBridge.json';
|
|
||||||
import * as TestKyberBridge from '../generated-artifacts/TestKyberBridge.json';
|
|
||||||
import * as TestStaticCallTarget from '../generated-artifacts/TestStaticCallTarget.json';
|
import * as TestStaticCallTarget from '../generated-artifacts/TestStaticCallTarget.json';
|
||||||
import * as TestUniswapBridge from '../generated-artifacts/TestUniswapBridge.json';
|
|
||||||
import * as UniswapBridge from '../generated-artifacts/UniswapBridge.json';
|
|
||||||
export const artifacts = {
|
export const artifacts = {
|
||||||
MixinAssetProxyDispatcher: MixinAssetProxyDispatcher as ContractArtifact,
|
|
||||||
MixinAuthorizable: MixinAuthorizable as ContractArtifact,
|
|
||||||
Ownable: Ownable as ContractArtifact,
|
|
||||||
ERC1155Proxy: ERC1155Proxy as ContractArtifact,
|
ERC1155Proxy: ERC1155Proxy as ContractArtifact,
|
||||||
ERC20BridgeProxy: ERC20BridgeProxy as ContractArtifact,
|
|
||||||
ERC20Proxy: ERC20Proxy as ContractArtifact,
|
ERC20Proxy: ERC20Proxy as ContractArtifact,
|
||||||
ERC721Proxy: ERC721Proxy as ContractArtifact,
|
ERC721Proxy: ERC721Proxy as ContractArtifact,
|
||||||
|
MixinAuthorizable: MixinAuthorizable as ContractArtifact,
|
||||||
MultiAssetProxy: MultiAssetProxy as ContractArtifact,
|
MultiAssetProxy: MultiAssetProxy as ContractArtifact,
|
||||||
StaticCallProxy: StaticCallProxy as ContractArtifact,
|
StaticCallProxy: StaticCallProxy as ContractArtifact,
|
||||||
ChaiBridge: ChaiBridge as ContractArtifact,
|
|
||||||
DydxBridge: DydxBridge as ContractArtifact,
|
|
||||||
Eth2DaiBridge: Eth2DaiBridge as ContractArtifact,
|
|
||||||
KyberBridge: KyberBridge as ContractArtifact,
|
|
||||||
UniswapBridge: UniswapBridge as ContractArtifact,
|
|
||||||
IAssetData: IAssetData as ContractArtifact,
|
IAssetData: IAssetData as ContractArtifact,
|
||||||
IAssetProxy: IAssetProxy as ContractArtifact,
|
IAssetProxy: IAssetProxy as ContractArtifact,
|
||||||
IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact,
|
|
||||||
IAuthorizable: IAuthorizable as ContractArtifact,
|
IAuthorizable: IAuthorizable as ContractArtifact,
|
||||||
IChai: IChai as ContractArtifact,
|
|
||||||
IDydx: IDydx as ContractArtifact,
|
|
||||||
IDydxBridge: IDydxBridge as ContractArtifact,
|
|
||||||
IERC20Bridge: IERC20Bridge as ContractArtifact,
|
|
||||||
IEth2Dai: IEth2Dai as ContractArtifact,
|
|
||||||
IKyberNetworkProxy: IKyberNetworkProxy as ContractArtifact,
|
|
||||||
IUniswapExchange: IUniswapExchange as ContractArtifact,
|
|
||||||
IUniswapExchangeFactory: IUniswapExchangeFactory as ContractArtifact,
|
|
||||||
TestChaiBridge: TestChaiBridge as ContractArtifact,
|
|
||||||
TestDydxBridge: TestDydxBridge as ContractArtifact,
|
|
||||||
TestERC20Bridge: TestERC20Bridge as ContractArtifact,
|
|
||||||
TestEth2DaiBridge: TestEth2DaiBridge as ContractArtifact,
|
|
||||||
TestKyberBridge: TestKyberBridge as ContractArtifact,
|
|
||||||
TestStaticCallTarget: TestStaticCallTarget as ContractArtifact,
|
TestStaticCallTarget: TestStaticCallTarget as ContractArtifact,
|
||||||
TestUniswapBridge: TestUniswapBridge as ContractArtifact,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
|
||||||
|
|
||||||
export enum DydxBridgeActionType {
|
|
||||||
Deposit,
|
|
||||||
Withdraw,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DydxBrigeAction {
|
|
||||||
actionType: DydxBridgeActionType;
|
|
||||||
accountId: BigNumber;
|
|
||||||
marketId: BigNumber;
|
|
||||||
conversionRateNumerator: BigNumber;
|
|
||||||
conversionRateDenominator: BigNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DydxBridgeData {
|
|
||||||
accountNumbers: BigNumber[];
|
|
||||||
actions: DydxBrigeAction[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const dydxBridgeDataEncoder = AbiEncoder.create([
|
|
||||||
{
|
|
||||||
name: 'bridgeData',
|
|
||||||
type: 'tuple',
|
|
||||||
components: [
|
|
||||||
{ name: 'accountNumbers', type: 'uint256[]' },
|
|
||||||
{
|
|
||||||
name: 'actions',
|
|
||||||
type: 'tuple[]',
|
|
||||||
components: [
|
|
||||||
{ name: 'actionType', type: 'uint8' },
|
|
||||||
{ name: 'accountId', type: 'uint256' },
|
|
||||||
{ name: 'marketId', type: 'uint256' },
|
|
||||||
{ name: 'conversionRateNumerator', type: 'uint256' },
|
|
||||||
{ name: 'conversionRateDenominator', type: 'uint256' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
@@ -1,70 +1,3 @@
|
|||||||
export { artifacts } from './artifacts';
|
export * from './artifacts';
|
||||||
export {
|
export * from './wrappers';
|
||||||
ERC1155ProxyContract,
|
export * from '../test/utils';
|
||||||
ERC20BridgeProxyContract,
|
|
||||||
ERC20ProxyContract,
|
|
||||||
ERC721ProxyContract,
|
|
||||||
Eth2DaiBridgeContract,
|
|
||||||
DydxBridgeContract,
|
|
||||||
TestDydxBridgeContract,
|
|
||||||
IAssetDataContract,
|
|
||||||
IAssetProxyContract,
|
|
||||||
MultiAssetProxyContract,
|
|
||||||
StaticCallProxyContract,
|
|
||||||
TestStaticCallTargetContract,
|
|
||||||
UniswapBridgeContract,
|
|
||||||
KyberBridgeContract,
|
|
||||||
ChaiBridgeContract,
|
|
||||||
IChaiContract,
|
|
||||||
} from './wrappers';
|
|
||||||
|
|
||||||
export { ERC20Wrapper } from './erc20_wrapper';
|
|
||||||
export { ERC721Wrapper } from './erc721_wrapper';
|
|
||||||
export { ERC1155ProxyWrapper } from './erc1155_proxy_wrapper';
|
|
||||||
export { ERC1155MintableContract, Erc1155Wrapper } from '@0x/contracts-erc1155';
|
|
||||||
export { DummyERC20TokenContract } from '@0x/contracts-erc20';
|
|
||||||
export { DummyERC721TokenContract } from '@0x/contracts-erc721';
|
|
||||||
export {
|
|
||||||
ERC1155HoldingsByOwner,
|
|
||||||
ERC20BalancesByOwner,
|
|
||||||
ERC721TokenIdsByOwner,
|
|
||||||
ERC1155FungibleHoldingsByOwner,
|
|
||||||
ERC1155NonFungibleHoldingsByOwner,
|
|
||||||
} from '@0x/contracts-test-utils';
|
|
||||||
export {
|
|
||||||
TransactionReceiptWithDecodedLogs,
|
|
||||||
Provider,
|
|
||||||
ZeroExProvider,
|
|
||||||
JSONRPCRequestPayload,
|
|
||||||
JSONRPCErrorCallback,
|
|
||||||
TransactionReceiptStatus,
|
|
||||||
JSONRPCResponsePayload,
|
|
||||||
JSONRPCResponseError,
|
|
||||||
ContractArtifact,
|
|
||||||
ContractChains,
|
|
||||||
CompilerOpts,
|
|
||||||
StandardContractOutput,
|
|
||||||
CompilerSettings,
|
|
||||||
ContractChainData,
|
|
||||||
ContractAbi,
|
|
||||||
DevdocOutput,
|
|
||||||
EvmOutput,
|
|
||||||
CompilerSettingsMetadata,
|
|
||||||
OptimizerSettings,
|
|
||||||
OutputField,
|
|
||||||
ParamDescription,
|
|
||||||
EvmBytecodeOutput,
|
|
||||||
AbiDefinition,
|
|
||||||
FunctionAbi,
|
|
||||||
EventAbi,
|
|
||||||
RevertErrorAbi,
|
|
||||||
EventParameter,
|
|
||||||
DataItem,
|
|
||||||
MethodAbi,
|
|
||||||
ConstructorAbi,
|
|
||||||
FallbackAbi,
|
|
||||||
ConstructorStateMutability,
|
|
||||||
TupleDataItem,
|
|
||||||
StateMutability,
|
|
||||||
} from 'ethereum-types';
|
|
||||||
export * from './dydx_bridge_encoder';
|
|
||||||
|
|||||||
@@ -3,36 +3,13 @@
|
|||||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
export * from '../generated-wrappers/chai_bridge';
|
|
||||||
export * from '../generated-wrappers/dydx_bridge';
|
|
||||||
export * from '../generated-wrappers/erc1155_proxy';
|
export * from '../generated-wrappers/erc1155_proxy';
|
||||||
export * from '../generated-wrappers/erc20_bridge_proxy';
|
|
||||||
export * from '../generated-wrappers/erc20_proxy';
|
export * from '../generated-wrappers/erc20_proxy';
|
||||||
export * from '../generated-wrappers/erc721_proxy';
|
export * from '../generated-wrappers/erc721_proxy';
|
||||||
export * from '../generated-wrappers/eth2_dai_bridge';
|
|
||||||
export * from '../generated-wrappers/i_asset_data';
|
export * from '../generated-wrappers/i_asset_data';
|
||||||
export * from '../generated-wrappers/i_asset_proxy';
|
export * from '../generated-wrappers/i_asset_proxy';
|
||||||
export * from '../generated-wrappers/i_asset_proxy_dispatcher';
|
|
||||||
export * from '../generated-wrappers/i_authorizable';
|
export * from '../generated-wrappers/i_authorizable';
|
||||||
export * from '../generated-wrappers/i_chai';
|
|
||||||
export * from '../generated-wrappers/i_dydx';
|
|
||||||
export * from '../generated-wrappers/i_dydx_bridge';
|
|
||||||
export * from '../generated-wrappers/i_erc20_bridge';
|
|
||||||
export * from '../generated-wrappers/i_eth2_dai';
|
|
||||||
export * from '../generated-wrappers/i_kyber_network_proxy';
|
|
||||||
export * from '../generated-wrappers/i_uniswap_exchange';
|
|
||||||
export * from '../generated-wrappers/i_uniswap_exchange_factory';
|
|
||||||
export * from '../generated-wrappers/kyber_bridge';
|
|
||||||
export * from '../generated-wrappers/mixin_asset_proxy_dispatcher';
|
|
||||||
export * from '../generated-wrappers/mixin_authorizable';
|
export * from '../generated-wrappers/mixin_authorizable';
|
||||||
export * from '../generated-wrappers/multi_asset_proxy';
|
export * from '../generated-wrappers/multi_asset_proxy';
|
||||||
export * from '../generated-wrappers/ownable';
|
|
||||||
export * from '../generated-wrappers/static_call_proxy';
|
export * from '../generated-wrappers/static_call_proxy';
|
||||||
export * from '../generated-wrappers/test_chai_bridge';
|
|
||||||
export * from '../generated-wrappers/test_dydx_bridge';
|
|
||||||
export * from '../generated-wrappers/test_erc20_bridge';
|
|
||||||
export * from '../generated-wrappers/test_eth2_dai_bridge';
|
|
||||||
export * from '../generated-wrappers/test_kyber_bridge';
|
|
||||||
export * from '../generated-wrappers/test_static_call_target';
|
export * from '../generated-wrappers/test_static_call_target';
|
||||||
export * from '../generated-wrappers/test_uniswap_bridge';
|
|
||||||
export * from '../generated-wrappers/uniswap_bridge';
|
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
import { ContractArtifact } from 'ethereum-types';
|
|
||||||
|
|
||||||
import * as ChaiBridge from '../test/generated-artifacts/ChaiBridge.json';
|
|
||||||
import * as DydxBridge from '../test/generated-artifacts/DydxBridge.json';
|
|
||||||
import * as ERC1155Proxy from '../test/generated-artifacts/ERC1155Proxy.json';
|
|
||||||
import * as ERC20BridgeProxy from '../test/generated-artifacts/ERC20BridgeProxy.json';
|
|
||||||
import * as ERC20Proxy from '../test/generated-artifacts/ERC20Proxy.json';
|
|
||||||
import * as ERC721Proxy from '../test/generated-artifacts/ERC721Proxy.json';
|
|
||||||
import * as Eth2DaiBridge from '../test/generated-artifacts/Eth2DaiBridge.json';
|
|
||||||
import * as IAssetData from '../test/generated-artifacts/IAssetData.json';
|
|
||||||
import * as IAssetProxy from '../test/generated-artifacts/IAssetProxy.json';
|
|
||||||
import * as IAssetProxyDispatcher from '../test/generated-artifacts/IAssetProxyDispatcher.json';
|
|
||||||
import * as IAuthorizable from '../test/generated-artifacts/IAuthorizable.json';
|
|
||||||
import * as IChai from '../test/generated-artifacts/IChai.json';
|
|
||||||
import * as IDydx from '../test/generated-artifacts/IDydx.json';
|
|
||||||
import * as IDydxBridge from '../test/generated-artifacts/IDydxBridge.json';
|
|
||||||
import * as IERC20Bridge from '../test/generated-artifacts/IERC20Bridge.json';
|
|
||||||
import * as IEth2Dai from '../test/generated-artifacts/IEth2Dai.json';
|
|
||||||
import * as IKyberNetworkProxy from '../test/generated-artifacts/IKyberNetworkProxy.json';
|
|
||||||
import * as IUniswapExchange from '../test/generated-artifacts/IUniswapExchange.json';
|
|
||||||
import * as IUniswapExchangeFactory from '../test/generated-artifacts/IUniswapExchangeFactory.json';
|
|
||||||
import * as KyberBridge from '../test/generated-artifacts/KyberBridge.json';
|
|
||||||
import * as MixinAssetProxyDispatcher from '../test/generated-artifacts/MixinAssetProxyDispatcher.json';
|
|
||||||
import * as MixinAuthorizable from '../test/generated-artifacts/MixinAuthorizable.json';
|
|
||||||
import * as MultiAssetProxy from '../test/generated-artifacts/MultiAssetProxy.json';
|
|
||||||
import * as Ownable from '../test/generated-artifacts/Ownable.json';
|
|
||||||
import * as StaticCallProxy from '../test/generated-artifacts/StaticCallProxy.json';
|
|
||||||
import * as TestChaiBridge from '../test/generated-artifacts/TestChaiBridge.json';
|
|
||||||
import * as TestDydxBridge from '../test/generated-artifacts/TestDydxBridge.json';
|
|
||||||
import * as TestERC20Bridge from '../test/generated-artifacts/TestERC20Bridge.json';
|
|
||||||
import * as TestEth2DaiBridge from '../test/generated-artifacts/TestEth2DaiBridge.json';
|
|
||||||
import * as TestKyberBridge from '../test/generated-artifacts/TestKyberBridge.json';
|
|
||||||
import * as TestStaticCallTarget from '../test/generated-artifacts/TestStaticCallTarget.json';
|
|
||||||
import * as TestUniswapBridge from '../test/generated-artifacts/TestUniswapBridge.json';
|
|
||||||
import * as UniswapBridge from '../test/generated-artifacts/UniswapBridge.json';
|
|
||||||
export const artifacts = {
|
|
||||||
MixinAssetProxyDispatcher: MixinAssetProxyDispatcher as ContractArtifact,
|
|
||||||
MixinAuthorizable: MixinAuthorizable as ContractArtifact,
|
|
||||||
Ownable: Ownable as ContractArtifact,
|
|
||||||
ERC1155Proxy: ERC1155Proxy as ContractArtifact,
|
|
||||||
ERC20BridgeProxy: ERC20BridgeProxy as ContractArtifact,
|
|
||||||
ERC20Proxy: ERC20Proxy as ContractArtifact,
|
|
||||||
ERC721Proxy: ERC721Proxy as ContractArtifact,
|
|
||||||
MultiAssetProxy: MultiAssetProxy as ContractArtifact,
|
|
||||||
StaticCallProxy: StaticCallProxy as ContractArtifact,
|
|
||||||
ChaiBridge: ChaiBridge as ContractArtifact,
|
|
||||||
DydxBridge: DydxBridge as ContractArtifact,
|
|
||||||
Eth2DaiBridge: Eth2DaiBridge as ContractArtifact,
|
|
||||||
KyberBridge: KyberBridge as ContractArtifact,
|
|
||||||
UniswapBridge: UniswapBridge as ContractArtifact,
|
|
||||||
IAssetData: IAssetData as ContractArtifact,
|
|
||||||
IAssetProxy: IAssetProxy as ContractArtifact,
|
|
||||||
IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact,
|
|
||||||
IAuthorizable: IAuthorizable as ContractArtifact,
|
|
||||||
IChai: IChai as ContractArtifact,
|
|
||||||
IDydx: IDydx as ContractArtifact,
|
|
||||||
IDydxBridge: IDydxBridge as ContractArtifact,
|
|
||||||
IERC20Bridge: IERC20Bridge as ContractArtifact,
|
|
||||||
IEth2Dai: IEth2Dai as ContractArtifact,
|
|
||||||
IKyberNetworkProxy: IKyberNetworkProxy as ContractArtifact,
|
|
||||||
IUniswapExchange: IUniswapExchange as ContractArtifact,
|
|
||||||
IUniswapExchangeFactory: IUniswapExchangeFactory as ContractArtifact,
|
|
||||||
TestChaiBridge: TestChaiBridge as ContractArtifact,
|
|
||||||
TestDydxBridge: TestDydxBridge as ContractArtifact,
|
|
||||||
TestERC20Bridge: TestERC20Bridge as ContractArtifact,
|
|
||||||
TestEth2DaiBridge: TestEth2DaiBridge as ContractArtifact,
|
|
||||||
TestKyberBridge: TestKyberBridge as ContractArtifact,
|
|
||||||
TestStaticCallTarget: TestStaticCallTarget as ContractArtifact,
|
|
||||||
TestUniswapBridge: TestUniswapBridge as ContractArtifact,
|
|
||||||
};
|
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
import { chaiSetup, expectTransactionFailedAsync, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
|
import {
|
||||||
|
chaiSetup,
|
||||||
|
constants,
|
||||||
|
expectTransactionFailedAsync,
|
||||||
|
provider,
|
||||||
|
txDefaults,
|
||||||
|
web3Wrapper,
|
||||||
|
} from '@0x/contracts-test-utils';
|
||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
import { RevertReason } from '@0x/types';
|
import { RevertReason } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts, MixinAuthorizableContract } from '../src';
|
||||||
|
|
||||||
import { MixinAuthorizableContract } from './wrappers';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -22,11 +27,9 @@ describe('Authorizable', () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
await blockchainLifecycle.revertAsync();
|
await blockchainLifecycle.revertAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
[owner, address, notOwner] = _.slice(accounts, 0, 3);
|
[owner, address, notOwner] = _.slice(accounts, 0, 3);
|
||||||
@@ -37,57 +40,74 @@ describe('Authorizable', () => {
|
|||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await blockchainLifecycle.revertAsync();
|
await blockchainLifecycle.revertAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('addAuthorizedAddress', () => {
|
describe('addAuthorizedAddress', () => {
|
||||||
it('should revert if not called by owner', async () => {
|
it('should throw if not called by owner', async () => {
|
||||||
await expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.addAuthorizedAddress(notOwner).sendTransactionAsync({ from: notOwner }),
|
authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
|
||||||
RevertReason.OnlyContractOwner,
|
RevertReason.OnlyContractOwner,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow owner to add an authorized address', async () => {
|
it('should allow owner to add an authorized address', async () => {
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||||
expect(isAuthorized).to.be.true();
|
expect(isAuthorized).to.be.true();
|
||||||
});
|
});
|
||||||
|
it('should throw if owner attempts to authorize a duplicate address', async () => {
|
||||||
it('should revert if owner attempts to authorize a duplicate address', async () => {
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.addAuthorizedAddress(address).sendTransactionAsync({ from: owner }),
|
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
|
||||||
RevertReason.TargetAlreadyAuthorized,
|
RevertReason.TargetAlreadyAuthorized,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeAuthorizedAddress', () => {
|
describe('removeAuthorizedAddress', () => {
|
||||||
it('should revert if not called by owner', async () => {
|
it('should throw if not called by owner', async () => {
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await expectTransactionFailedAsync(
|
address,
|
||||||
authorizable.removeAuthorizedAddress(address).sendTransactionAsync({ from: notOwner }),
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
return expectTransactionFailedAsync(
|
||||||
|
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
|
||||||
|
from: notOwner,
|
||||||
|
}),
|
||||||
RevertReason.OnlyContractOwner,
|
RevertReason.OnlyContractOwner,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow owner to remove an authorized address', async () => {
|
it('should allow owner to remove an authorized address', async () => {
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
address,
|
||||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||||
expect(isAuthorized).to.be.false();
|
expect(isAuthorized).to.be.false();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should revert if owner attempts to remove an address that is not authorized', async () => {
|
it('should throw if owner attempts to remove an address that is not authorized', async () => {
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.removeAuthorizedAddress(address).sendTransactionAsync({
|
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
|
||||||
from: owner,
|
from: owner,
|
||||||
}),
|
}),
|
||||||
RevertReason.TargetNotAuthorized,
|
RevertReason.TargetNotAuthorized,
|
||||||
@@ -96,73 +116,100 @@ describe('Authorizable', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('removeAuthorizedAddressAtIndex', () => {
|
describe('removeAuthorizedAddressAtIndex', () => {
|
||||||
it('should revert if not called by owner', async () => {
|
it('should throw if not called by owner', async () => {
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
const index = new BigNumber(0);
|
const index = new BigNumber(0);
|
||||||
await expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||||
from: notOwner,
|
from: notOwner,
|
||||||
}),
|
}),
|
||||||
RevertReason.OnlyContractOwner,
|
RevertReason.OnlyContractOwner,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should throw if index is >= authorities.length', async () => {
|
||||||
it('should revert if index is >= authorities.length', async () => {
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
const index = new BigNumber(1);
|
const index = new BigNumber(1);
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||||
from: owner,
|
from: owner,
|
||||||
}),
|
}),
|
||||||
RevertReason.IndexOutOfBounds,
|
RevertReason.IndexOutOfBounds,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should throw if owner attempts to remove an address that is not authorized', async () => {
|
||||||
it('should revert if owner attempts to remove an address that is not authorized', async () => {
|
|
||||||
const index = new BigNumber(0);
|
const index = new BigNumber(0);
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||||
from: owner,
|
from: owner,
|
||||||
}),
|
}),
|
||||||
RevertReason.TargetNotAuthorized,
|
RevertReason.TargetNotAuthorized,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should throw if address at index does not match target', async () => {
|
||||||
it('should revert if address at index does not match target', async () => {
|
|
||||||
const address1 = address;
|
const address1 = address;
|
||||||
const address2 = notOwner;
|
const address2 = notOwner;
|
||||||
await authorizable.addAuthorizedAddress(address1).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await authorizable.addAuthorizedAddress(address2).awaitTransactionSuccessAsync({ from: owner });
|
address1,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
|
address2,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
const address1Index = new BigNumber(0);
|
const address1Index = new BigNumber(0);
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
authorizable.removeAuthorizedAddressAtIndex(address2, address1Index).sendTransactionAsync({
|
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, {
|
||||||
from: owner,
|
from: owner,
|
||||||
}),
|
}),
|
||||||
RevertReason.AuthorizedAddressMismatch,
|
RevertReason.AuthorizedAddressMismatch,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow owner to remove an authorized address', async () => {
|
it('should allow owner to remove an authorized address', async () => {
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
const index = new BigNumber(0);
|
const index = new BigNumber(0);
|
||||||
await authorizable.removeAuthorizedAddressAtIndex(address, index).awaitTransactionSuccessAsync({
|
await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(
|
||||||
from: owner,
|
address,
|
||||||
});
|
index,
|
||||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||||
expect(isAuthorized).to.be.false();
|
expect(isAuthorized).to.be.false();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAuthorizedAddresses', () => {
|
describe('getAuthorizedAddresses', () => {
|
||||||
it('should return all authorized addresses', async () => {
|
it('should return all authorized addresses', async () => {
|
||||||
const initial = await authorizable.getAuthorizedAddresses().callAsync();
|
const initial = await authorizable.getAuthorizedAddresses.callAsync();
|
||||||
expect(initial).to.have.length(0);
|
expect(initial).to.have.length(0);
|
||||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
const afterAdd = await authorizable.getAuthorizedAddresses().callAsync();
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
|
||||||
expect(afterAdd).to.have.length(1);
|
expect(afterAdd).to.have.length(1);
|
||||||
expect(afterAdd).to.include(address);
|
expect(afterAdd).to.include(address);
|
||||||
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
const afterRemove = await authorizable.getAuthorizedAddresses().callAsync();
|
address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
|
||||||
expect(afterRemove).to.have.length(0);
|
expect(afterRemove).to.have.length(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
import { ERC20TokenContract } from '@0x/contracts-erc20';
|
|
||||||
import { blockchainTests, constants, expect, randomAddress } from '@0x/contracts-test-utils';
|
|
||||||
import { AssetProxyId, RevertReason } from '@0x/types';
|
|
||||||
import { BigNumber } from '@0x/utils';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
import { TestChaiBridgeContract } from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('ChaiBridge unit tests', env => {
|
|
||||||
let chaiBridgeContract: TestChaiBridgeContract;
|
|
||||||
let testDaiContract: ERC20TokenContract;
|
|
||||||
let fromAddress: string;
|
|
||||||
let toAddress: string;
|
|
||||||
|
|
||||||
const alwaysRevertAddress = '0x0000000000000000000000000000000000000001';
|
|
||||||
const amount = new BigNumber(1);
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
[fromAddress, toAddress] = await env.getAccountAddressesAsync();
|
|
||||||
chaiBridgeContract = await TestChaiBridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestChaiBridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
const testChaiDaiAddress = await chaiBridgeContract.testChaiDai().callAsync();
|
|
||||||
testDaiContract = new ERC20TokenContract(testChaiDaiAddress, env.provider, env.txDefaults);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('bridgeTransferFrom()', () => {
|
|
||||||
it('fails if not called by ERC20BridgeProxy', async () => {
|
|
||||||
return expect(
|
|
||||||
chaiBridgeContract
|
|
||||||
.bridgeTransferFrom(randomAddress(), fromAddress, toAddress, amount, constants.NULL_BYTES)
|
|
||||||
.awaitTransactionSuccessAsync({ from: alwaysRevertAddress }),
|
|
||||||
).to.revertWith(RevertReason.ChaiBridgeOnlyCallableByErc20BridgeProxy);
|
|
||||||
});
|
|
||||||
it('returns magic bytes upon success', async () => {
|
|
||||||
const magicBytes = await chaiBridgeContract
|
|
||||||
.bridgeTransferFrom(randomAddress(), fromAddress, toAddress, amount, constants.NULL_BYTES)
|
|
||||||
.callAsync();
|
|
||||||
expect(magicBytes).to.eq(AssetProxyId.ERC20Bridge);
|
|
||||||
});
|
|
||||||
it('should increase the Dai balance of `toAddress` by `amount` if successful', async () => {
|
|
||||||
const initialBalance = await testDaiContract.balanceOf(toAddress).callAsync();
|
|
||||||
await chaiBridgeContract
|
|
||||||
.bridgeTransferFrom(randomAddress(), fromAddress, toAddress, amount, constants.NULL_BYTES)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
const endBalance = await testDaiContract.balanceOf(toAddress).callAsync();
|
|
||||||
expect(endBalance).to.bignumber.eq(initialBalance.plus(amount));
|
|
||||||
});
|
|
||||||
it('fails if the `chai.draw` call fails', async () => {
|
|
||||||
return expect(
|
|
||||||
chaiBridgeContract
|
|
||||||
.bridgeTransferFrom(randomAddress(), alwaysRevertAddress, toAddress, amount, constants.NULL_BYTES)
|
|
||||||
.awaitTransactionSuccessAsync(),
|
|
||||||
).to.revertWith(RevertReason.ChaiBridgeDrawDaiFailed);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,399 +0,0 @@
|
|||||||
import { LibMathRevertErrors } from '@0x/contracts-exchange-libs';
|
|
||||||
import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils';
|
|
||||||
import { AssetProxyId, RevertReason } from '@0x/types';
|
|
||||||
import { BigNumber } from '@0x/utils';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { DydxBridgeActionType, DydxBridgeData, dydxBridgeDataEncoder } from '../src/dydx_bridge_encoder';
|
|
||||||
import { ERC20BridgeProxyContract, IAssetDataContract } from '../src/wrappers';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
import { TestDydxBridgeContract, TestDydxBridgeEvents } from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('DydxBridge unit tests', env => {
|
|
||||||
const defaultAccountNumber = new BigNumber(1);
|
|
||||||
const marketId = new BigNumber(2);
|
|
||||||
const defaultAmount = new BigNumber(4);
|
|
||||||
const notAuthorized = '0x0000000000000000000000000000000000000001';
|
|
||||||
const defaultDepositAction = {
|
|
||||||
actionType: DydxBridgeActionType.Deposit,
|
|
||||||
accountId: constants.ZERO_AMOUNT,
|
|
||||||
marketId,
|
|
||||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
|
||||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
|
||||||
};
|
|
||||||
const defaultWithdrawAction = {
|
|
||||||
actionType: DydxBridgeActionType.Withdraw,
|
|
||||||
accountId: constants.ZERO_AMOUNT,
|
|
||||||
marketId,
|
|
||||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
|
||||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
|
||||||
};
|
|
||||||
let testContract: TestDydxBridgeContract;
|
|
||||||
let testProxyContract: ERC20BridgeProxyContract;
|
|
||||||
let assetDataEncoder: IAssetDataContract;
|
|
||||||
let owner: string;
|
|
||||||
let authorized: string;
|
|
||||||
let accountOwner: string;
|
|
||||||
let receiver: string;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
// Get accounts
|
|
||||||
const accounts = await env.web3Wrapper.getAvailableAddressesAsync();
|
|
||||||
[owner, authorized, accountOwner, receiver] = accounts;
|
|
||||||
|
|
||||||
// Deploy dydx bridge
|
|
||||||
testContract = await TestDydxBridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestDydxBridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
[accountOwner, receiver],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Deploy test erc20 bridge proxy
|
|
||||||
testProxyContract = await ERC20BridgeProxyContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.ERC20BridgeProxy,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
await testProxyContract.addAuthorizedAddress(authorized).awaitTransactionSuccessAsync({ from: owner });
|
|
||||||
|
|
||||||
// Setup asset data encoder
|
|
||||||
assetDataEncoder = new IAssetDataContract(constants.NULL_ADDRESS, env.provider);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('bridgeTransferFrom()', () => {
|
|
||||||
const callBridgeTransferFrom = async (
|
|
||||||
from: string,
|
|
||||||
to: string,
|
|
||||||
amount: BigNumber,
|
|
||||||
bridgeData: DydxBridgeData,
|
|
||||||
sender: string,
|
|
||||||
): Promise<string> => {
|
|
||||||
const returnValue = await testContract
|
|
||||||
.bridgeTransferFrom(
|
|
||||||
constants.NULL_ADDRESS,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
dydxBridgeDataEncoder.encode({ bridgeData }),
|
|
||||||
)
|
|
||||||
.callAsync({ from: sender });
|
|
||||||
return returnValue;
|
|
||||||
};
|
|
||||||
const executeBridgeTransferFromAndVerifyEvents = async (
|
|
||||||
from: string,
|
|
||||||
to: string,
|
|
||||||
amount: BigNumber,
|
|
||||||
bridgeData: DydxBridgeData,
|
|
||||||
sender: string,
|
|
||||||
): Promise<void> => {
|
|
||||||
// Execute transaction.
|
|
||||||
const txReceipt = await testContract
|
|
||||||
.bridgeTransferFrom(
|
|
||||||
constants.NULL_ADDRESS,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
dydxBridgeDataEncoder.encode({ bridgeData }),
|
|
||||||
)
|
|
||||||
.awaitTransactionSuccessAsync({ from: sender });
|
|
||||||
|
|
||||||
// Verify `OperateAccount` event.
|
|
||||||
const expectedOperateAccountEvents = [];
|
|
||||||
for (const accountNumber of bridgeData.accountNumbers) {
|
|
||||||
expectedOperateAccountEvents.push({
|
|
||||||
owner: accountOwner,
|
|
||||||
number: accountNumber,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
verifyEventsFromLogs(txReceipt.logs, expectedOperateAccountEvents, TestDydxBridgeEvents.OperateAccount);
|
|
||||||
|
|
||||||
// Verify `OperateAction` event.
|
|
||||||
const weiDenomination = 0;
|
|
||||||
const deltaAmountRef = 0;
|
|
||||||
const expectedOperateActionEvents = [];
|
|
||||||
for (const action of bridgeData.actions) {
|
|
||||||
expectedOperateActionEvents.push({
|
|
||||||
actionType: action.actionType as number,
|
|
||||||
accountId: action.accountId,
|
|
||||||
amountSign: action.actionType === DydxBridgeActionType.Deposit ? true : false,
|
|
||||||
amountDenomination: weiDenomination,
|
|
||||||
amountRef: deltaAmountRef,
|
|
||||||
amountValue: action.conversionRateDenominator.gt(0)
|
|
||||||
? amount
|
|
||||||
.times(action.conversionRateNumerator)
|
|
||||||
.dividedToIntegerBy(action.conversionRateDenominator)
|
|
||||||
: amount,
|
|
||||||
primaryMarketId: marketId,
|
|
||||||
secondaryMarketId: constants.ZERO_AMOUNT,
|
|
||||||
otherAddress: action.actionType === DydxBridgeActionType.Deposit ? from : to,
|
|
||||||
otherAccountId: constants.ZERO_AMOUNT,
|
|
||||||
data: '0x',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
verifyEventsFromLogs(txReceipt.logs, expectedOperateActionEvents, TestDydxBridgeEvents.OperateAction);
|
|
||||||
};
|
|
||||||
it('succeeds when calling with zero amount', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
constants.ZERO_AMOUNT,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling with no accounts', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling with no actions', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with the `deposit` action and a single account', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with the `deposit` action and multiple accounts', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber, defaultAccountNumber.plus(1)],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with the `withdraw` action and a single account', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultWithdrawAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with the `withdraw` action and multiple accounts', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber, defaultAccountNumber.plus(1)],
|
|
||||||
actions: [defaultWithdrawAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with the `deposit` action and multiple accounts', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber, defaultAccountNumber.plus(1)],
|
|
||||||
actions: [defaultWithdrawAction, defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when calling `operate` with multiple actions under a single account', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultWithdrawAction, defaultDepositAction],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when scaling the `amount` to deposit', async () => {
|
|
||||||
const conversionRateNumerator = new BigNumber(1);
|
|
||||||
const conversionRateDenominator = new BigNumber(2);
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [
|
|
||||||
defaultWithdrawAction,
|
|
||||||
{
|
|
||||||
...defaultDepositAction,
|
|
||||||
conversionRateNumerator,
|
|
||||||
conversionRateDenominator,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('succeeds when scaling the `amount` to withdraw', async () => {
|
|
||||||
const conversionRateNumerator = new BigNumber(1);
|
|
||||||
const conversionRateDenominator = new BigNumber(2);
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [
|
|
||||||
defaultDepositAction,
|
|
||||||
{
|
|
||||||
...defaultWithdrawAction,
|
|
||||||
conversionRateNumerator,
|
|
||||||
conversionRateDenominator,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
await executeBridgeTransferFromAndVerifyEvents(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('reverts if not called by the ERC20 Bridge Proxy', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
const callBridgeTransferFromPromise = callBridgeTransferFrom(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
notAuthorized,
|
|
||||||
);
|
|
||||||
const expectedError = RevertReason.DydxBridgeOnlyCallableByErc20BridgeProxy;
|
|
||||||
return expect(callBridgeTransferFromPromise).to.revertWith(expectedError);
|
|
||||||
});
|
|
||||||
it('should return magic bytes if call succeeds', async () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
const returnValue = await callBridgeTransferFrom(
|
|
||||||
accountOwner,
|
|
||||||
receiver,
|
|
||||||
defaultAmount,
|
|
||||||
bridgeData,
|
|
||||||
authorized,
|
|
||||||
);
|
|
||||||
expect(returnValue).to.equal(AssetProxyId.ERC20Bridge);
|
|
||||||
});
|
|
||||||
it('should revert when `Operate` reverts', async () => {
|
|
||||||
// Set revert flag.
|
|
||||||
await testContract.setRevertOnOperate(true).awaitTransactionSuccessAsync();
|
|
||||||
|
|
||||||
// Execute transfer.
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultDepositAction],
|
|
||||||
};
|
|
||||||
const tx = callBridgeTransferFrom(accountOwner, receiver, defaultAmount, bridgeData, authorized);
|
|
||||||
const expectedError = 'TestDydxBridge/SHOULD_REVERT_ON_OPERATE';
|
|
||||||
return expect(tx).to.revertWith(expectedError);
|
|
||||||
});
|
|
||||||
it('should revert when there is a rounding error', async () => {
|
|
||||||
// Setup a rounding error
|
|
||||||
const conversionRateNumerator = new BigNumber(5318);
|
|
||||||
const conversionRateDenominator = new BigNumber(47958);
|
|
||||||
const amount = new BigNumber(9000);
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [
|
|
||||||
defaultDepositAction,
|
|
||||||
{
|
|
||||||
...defaultWithdrawAction,
|
|
||||||
conversionRateNumerator,
|
|
||||||
conversionRateDenominator,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Execute transfer and assert error.
|
|
||||||
const tx = callBridgeTransferFrom(accountOwner, receiver, amount, bridgeData, authorized);
|
|
||||||
const expectedError = new LibMathRevertErrors.RoundingError(
|
|
||||||
conversionRateNumerator,
|
|
||||||
conversionRateDenominator,
|
|
||||||
amount,
|
|
||||||
);
|
|
||||||
return expect(tx).to.revertWith(expectedError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ERC20BridgeProxy.transferFrom()', () => {
|
|
||||||
const bridgeData = {
|
|
||||||
accountNumbers: [defaultAccountNumber],
|
|
||||||
actions: [defaultWithdrawAction],
|
|
||||||
};
|
|
||||||
let assetData: string;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
const testTokenAddress = await testContract.getTestToken().callAsync();
|
|
||||||
assetData = assetDataEncoder
|
|
||||||
.ERC20Bridge(testTokenAddress, testContract.address, dydxBridgeDataEncoder.encode({ bridgeData }))
|
|
||||||
.getABIEncodedTransactionData();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should succeed if `bridgeTransferFrom` succeeds', async () => {
|
|
||||||
await testProxyContract
|
|
||||||
.transferFrom(assetData, accountOwner, receiver, defaultAmount)
|
|
||||||
.awaitTransactionSuccessAsync({ from: authorized });
|
|
||||||
});
|
|
||||||
it('should revert if `bridgeTransferFrom` reverts', async () => {
|
|
||||||
// Set revert flag.
|
|
||||||
await testContract.setRevertOnOperate(true).awaitTransactionSuccessAsync();
|
|
||||||
const tx = testProxyContract
|
|
||||||
.transferFrom(assetData, accountOwner, receiver, defaultAmount)
|
|
||||||
.awaitTransactionSuccessAsync({ from: authorized });
|
|
||||||
const expectedError = 'TestDydxBridge/SHOULD_REVERT_ON_OPERATE';
|
|
||||||
return expect(tx).to.revertWith(expectedError);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { DevUtilsContract } from '@0x/contracts-dev-utils';
|
|
||||||
import {
|
import {
|
||||||
artifacts as erc1155Artifacts,
|
artifacts as erc1155Artifacts,
|
||||||
DummyERC1155ReceiverBatchTokenReceivedEventArgs,
|
DummyERC1155ReceiverBatchTokenReceivedEventArgs,
|
||||||
@@ -15,8 +14,8 @@ import {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
web3Wrapper,
|
web3Wrapper,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
import { SafeMathRevertErrors } from '@0x/contracts-utils';
|
|
||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
|
import { assetDataUtils } from '@0x/order-utils';
|
||||||
import { AssetProxyId, RevertReason } from '@0x/types';
|
import { AssetProxyId, RevertReason } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@@ -24,10 +23,7 @@ import { LogWithDecodedArgs } from 'ethereum-types';
|
|||||||
import * as ethUtil from 'ethereumjs-util';
|
import * as ethUtil from 'ethereumjs-util';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { ERC1155ProxyWrapper } from '../src/erc1155_proxy_wrapper';
|
import { artifacts, ERC1155ProxyContract, ERC1155ProxyWrapper } from '../src';
|
||||||
import { ERC1155ProxyContract, IAssetDataContract } from '../src/wrappers';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -63,8 +59,6 @@ describe('ERC1155Proxy', () => {
|
|||||||
// tokens
|
// tokens
|
||||||
let fungibleTokens: BigNumber[];
|
let fungibleTokens: BigNumber[];
|
||||||
let nonFungibleTokensOwnedBySpender: BigNumber[];
|
let nonFungibleTokensOwnedBySpender: BigNumber[];
|
||||||
// devUtils for encoding and decoding assetData
|
|
||||||
let devUtils: DevUtilsContract;
|
|
||||||
// tests
|
// tests
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
@@ -78,8 +72,16 @@ describe('ERC1155Proxy', () => {
|
|||||||
const usedAddresses = ([owner, notAuthorized, authorized, spender, receiver] = _.slice(accounts, 0, 5));
|
const usedAddresses = ([owner, notAuthorized, authorized, spender, receiver] = _.slice(accounts, 0, 5));
|
||||||
erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner);
|
erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner);
|
||||||
erc1155Proxy = await erc1155ProxyWrapper.deployProxyAsync();
|
erc1155Proxy = await erc1155ProxyWrapper.deployProxyAsync();
|
||||||
await erc1155Proxy.addAuthorizedAddress(authorized).awaitTransactionSuccessAsync({ from: owner });
|
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
await erc1155Proxy.addAuthorizedAddress(erc1155Proxy.address).awaitTransactionSuccessAsync({ from: owner });
|
authorized,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(
|
||||||
|
erc1155Proxy.address,
|
||||||
|
{ from: owner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
// deploy & configure ERC1155 tokens and receiver
|
// deploy & configure ERC1155 tokens and receiver
|
||||||
[erc1155Wrapper] = await erc1155ProxyWrapper.deployDummyContractsAsync();
|
[erc1155Wrapper] = await erc1155ProxyWrapper.deployDummyContractsAsync();
|
||||||
erc1155Contract = erc1155Wrapper.getContract();
|
erc1155Contract = erc1155Wrapper.getContract();
|
||||||
@@ -101,8 +103,6 @@ describe('ERC1155Proxy', () => {
|
|||||||
tokenBalances.nonFungible[spender][erc1155Contract.address][nonFungibleTokenAsString][0];
|
tokenBalances.nonFungible[spender][erc1155Contract.address][nonFungibleTokenAsString][0];
|
||||||
nonFungibleTokensOwnedBySpender.push(nonFungibleTokenHeldBySpender);
|
nonFungibleTokensOwnedBySpender.push(nonFungibleTokenHeldBySpender);
|
||||||
});
|
});
|
||||||
// set up devUtils
|
|
||||||
devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider, { from: owner });
|
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
@@ -123,7 +123,7 @@ describe('ERC1155Proxy', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should have an id of 0xa7cb5fb7', async () => {
|
it('should have an id of 0xa7cb5fb7', async () => {
|
||||||
const proxyId = await erc1155Proxy.getProxyId().callAsync();
|
const proxyId = await erc1155Proxy.getProxyId.callAsync();
|
||||||
const expectedProxyId = AssetProxyId.ERC1155;
|
const expectedProxyId = AssetProxyId.ERC1155;
|
||||||
expect(proxyId).to.equal(expectedProxyId);
|
expect(proxyId).to.equal(expectedProxyId);
|
||||||
});
|
});
|
||||||
@@ -638,14 +638,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
return value.times(valueMultiplier);
|
return value.times(valueMultiplier);
|
||||||
});
|
});
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
const extraData = '0102030405060708091001020304050607080910010203040506070809100102';
|
const extraData = '0102030405060708091001020304050607080910010203040506070809100102';
|
||||||
const assetDataWithExtraData = `${assetData}${extraData}`;
|
const assetDataWithExtraData = `${assetData}${extraData}`;
|
||||||
// check balances before transfer
|
// check balances before transfer
|
||||||
@@ -698,20 +696,25 @@ describe('ERC1155Proxy', () => {
|
|||||||
const tokenUri = '';
|
const tokenUri = '';
|
||||||
for (const tokenToCreate of tokensToCreate) {
|
for (const tokenToCreate of tokensToCreate) {
|
||||||
// create token
|
// create token
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.createWithType(tokenToCreate, tokenUri)
|
tokenUri,
|
||||||
.awaitTransactionSuccessAsync({
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
|
||||||
// mint balance for spender
|
// mint balance for spender
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.mintFungible(tokenToCreate, [spender], [spenderInitialBalance])
|
[spender],
|
||||||
.awaitTransactionSuccessAsync({
|
[spenderInitialBalance],
|
||||||
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
///// Step 2/5 /////
|
///// Step 2/5 /////
|
||||||
// Check balances before transfer
|
// Check balances before transfer
|
||||||
@@ -744,16 +747,18 @@ describe('ERC1155Proxy', () => {
|
|||||||
const tokensToTransfer = [new BigNumber(1), new BigNumber(2)];
|
const tokensToTransfer = [new BigNumber(1), new BigNumber(2)];
|
||||||
const valuesToTransfer = tokensToTransfer;
|
const valuesToTransfer = tokensToTransfer;
|
||||||
const valueMultiplier = new BigNumber(2);
|
const valueMultiplier = new BigNumber(2);
|
||||||
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
// hand encode optimized assetData because our tooling (based on LibAssetData.sol/encodeERC1155AssetData) does not use optimized encoding
|
erc1155ContractAddress,
|
||||||
const assetDataContract = new IAssetDataContract(constants.NULL_ADDRESS, provider);
|
tokensToTransfer,
|
||||||
const selector = assetDataContract.getSelector('ERC1155Assets');
|
valuesToTransfer,
|
||||||
const assetDataWithoutContractAddress =
|
receiverCallbackData,
|
||||||
|
);
|
||||||
|
// remove the function selector and contract address from check, as these change on each test
|
||||||
|
const offsetToTokenIds = 74;
|
||||||
|
const assetDataWithoutContractAddress = assetData.substr(offsetToTokenIds);
|
||||||
|
const expectedAssetDataWithoutContractAddress =
|
||||||
'0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040102030400000000000000000000000000000000000000000000000000000000';
|
'0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040102030400000000000000000000000000000000000000000000000000000000';
|
||||||
const assetData = `${selector}000000000000000000000000${erc1155ContractAddress.substr(
|
expect(assetDataWithoutContractAddress).to.be.equal(expectedAssetDataWithoutContractAddress);
|
||||||
2,
|
|
||||||
)}${assetDataWithoutContractAddress}`;
|
|
||||||
|
|
||||||
///// Step 4/5 /////
|
///// Step 4/5 /////
|
||||||
// Transfer token IDs [1, 2] and amounts [1, 2] with a multiplier of 2;
|
// Transfer token IDs [1, 2] and amounts [1, 2] with a multiplier of 2;
|
||||||
// the expected trade will be token IDs [1, 2] and amounts [2, 4]
|
// the expected trade will be token IDs [1, 2] and amounts [2, 4]
|
||||||
@@ -800,20 +805,25 @@ describe('ERC1155Proxy', () => {
|
|||||||
const tokenUri = '';
|
const tokenUri = '';
|
||||||
for (const tokenToCreate of tokensToCreate) {
|
for (const tokenToCreate of tokensToCreate) {
|
||||||
// create token
|
// create token
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.createWithType(tokenToCreate, tokenUri)
|
tokenUri,
|
||||||
.awaitTransactionSuccessAsync({
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
|
||||||
// mint balance for spender
|
// mint balance for spender
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.mintFungible(tokenToCreate, [spender], [spenderInitialBalance])
|
[spender],
|
||||||
.awaitTransactionSuccessAsync({
|
[spenderInitialBalance],
|
||||||
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
///// Step 2/5 /////
|
///// Step 2/5 /////
|
||||||
// Check balances before transfer
|
// Check balances before transfer
|
||||||
@@ -857,14 +867,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [new BigNumber(2), new BigNumber(2)];
|
const valuesToTransfer = [new BigNumber(2), new BigNumber(2)];
|
||||||
const valueMultiplier = new BigNumber(2);
|
const valueMultiplier = new BigNumber(2);
|
||||||
// create callback data that is the encoded version of `valuesToTransfer`
|
// create callback data that is the encoded version of `valuesToTransfer`
|
||||||
const generatedAssetData = await devUtils
|
const generatedAssetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// remove the function selector and contract address from check, as these change on each test
|
// remove the function selector and contract address from check, as these change on each test
|
||||||
const offsetToTokenIds = 74;
|
const offsetToTokenIds = 74;
|
||||||
const assetDataSelectorAndContractAddress = generatedAssetData.substr(0, offsetToTokenIds);
|
const assetDataSelectorAndContractAddress = generatedAssetData.substr(0, offsetToTokenIds);
|
||||||
@@ -929,20 +937,25 @@ describe('ERC1155Proxy', () => {
|
|||||||
const tokenUri = '';
|
const tokenUri = '';
|
||||||
for (const tokenToCreate of tokensToCreate) {
|
for (const tokenToCreate of tokensToCreate) {
|
||||||
// create token
|
// create token
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.createWithType(tokenToCreate, tokenUri)
|
tokenUri,
|
||||||
.awaitTransactionSuccessAsync({
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
|
|
||||||
// mint balance for spender
|
// mint balance for spender
|
||||||
await erc1155Wrapper
|
await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync(
|
||||||
.getContract()
|
tokenToCreate,
|
||||||
.mintFungible(tokenToCreate, [spender], [spenderInitialBalance])
|
[spender],
|
||||||
.awaitTransactionSuccessAsync({
|
[spenderInitialBalance],
|
||||||
|
{
|
||||||
from: owner,
|
from: owner,
|
||||||
});
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
///// Step 2/5 /////
|
///// Step 2/5 /////
|
||||||
// Check balances before transfer
|
// Check balances before transfer
|
||||||
@@ -983,14 +996,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [new BigNumber(1), new BigNumber(2)];
|
const valuesToTransfer = [new BigNumber(1), new BigNumber(2)];
|
||||||
const valueMultiplier = new BigNumber(2);
|
const valueMultiplier = new BigNumber(2);
|
||||||
// create callback data that is the encoded version of `valuesToTransfer`
|
// create callback data that is the encoded version of `valuesToTransfer`
|
||||||
const generatedAssetData = await devUtils
|
const generatedAssetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// remove the function selector and contract address from check, as these change on each test
|
// remove the function selector and contract address from check, as these change on each test
|
||||||
const offsetToTokenIds = 74;
|
const offsetToTokenIds = 74;
|
||||||
const assetDataSelectorAndContractAddress = generatedAssetData.substr(0, offsetToTokenIds);
|
const assetDataSelectorAndContractAddress = generatedAssetData.substr(0, offsetToTokenIds);
|
||||||
@@ -1048,14 +1059,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1097,14 +1106,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1150,14 +1157,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1203,14 +1208,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1256,14 +1259,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1310,14 +1311,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1359,14 +1358,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1412,14 +1409,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1461,14 +1456,12 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
|
||||||
.callAsync();
|
|
||||||
// The asset data we just generated will look like this:
|
// The asset data we just generated will look like this:
|
||||||
// a7cb5fb7
|
// a7cb5fb7
|
||||||
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
// 0x 0000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082
|
||||||
@@ -1514,15 +1507,13 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
const txData = erc1155ProxyWrapper.getTransferFromAbiEncodedTxData(
|
||||||
.callAsync();
|
|
||||||
const txData = await erc1155ProxyWrapper.getTransferFromAbiEncodedTxDataAsync(
|
|
||||||
spender,
|
spender,
|
||||||
receiverContract,
|
receiverContract,
|
||||||
erc1155Contract.address,
|
erc1155Contract.address,
|
||||||
@@ -1547,15 +1538,13 @@ describe('ERC1155Proxy', () => {
|
|||||||
const valuesToTransfer = [fungibleValueToTransferLarge];
|
const valuesToTransfer = [fungibleValueToTransferLarge];
|
||||||
const valueMultiplier = valueMultiplierSmall;
|
const valueMultiplier = valueMultiplierSmall;
|
||||||
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
const erc1155ContractAddress = erc1155Wrapper.getContract().address;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(
|
erc1155ContractAddress,
|
||||||
erc1155ContractAddress,
|
tokensToTransfer,
|
||||||
tokensToTransfer,
|
valuesToTransfer,
|
||||||
valuesToTransfer,
|
receiverCallbackData,
|
||||||
receiverCallbackData,
|
);
|
||||||
)
|
const txData = erc1155ProxyWrapper.getTransferFromAbiEncodedTxData(
|
||||||
.callAsync();
|
|
||||||
const txData = await erc1155ProxyWrapper.getTransferFromAbiEncodedTxDataAsync(
|
|
||||||
spender,
|
spender,
|
||||||
receiverContract,
|
receiverContract,
|
||||||
erc1155Contract.address,
|
erc1155Contract.address,
|
||||||
@@ -1678,9 +1667,13 @@ describe('ERC1155Proxy', () => {
|
|||||||
it('should propagate revert reason from erc1155 contract failure', async () => {
|
it('should propagate revert reason from erc1155 contract failure', async () => {
|
||||||
// disable transfers
|
// disable transfers
|
||||||
const shouldRejectTransfer = true;
|
const shouldRejectTransfer = true;
|
||||||
await erc1155Receiver.setRejectTransferFlag(shouldRejectTransfer).awaitTransactionSuccessAsync({
|
await erc1155Receiver.setRejectTransferFlag.awaitTransactionSuccessAsync(
|
||||||
from: owner,
|
shouldRejectTransfer,
|
||||||
});
|
{
|
||||||
|
from: owner,
|
||||||
|
},
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
// setup test parameters
|
// setup test parameters
|
||||||
const tokenHolders = [spender, receiverContract];
|
const tokenHolders = [spender, receiverContract];
|
||||||
const tokensToTransfer = fungibleTokens.slice(0, 1);
|
const tokensToTransfer = fungibleTokens.slice(0, 1);
|
||||||
@@ -1755,14 +1748,9 @@ describe('ERC1155Proxy', () => {
|
|||||||
nftNotOwnerBalance,
|
nftNotOwnerBalance,
|
||||||
];
|
];
|
||||||
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
|
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
|
||||||
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
|
|
||||||
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
|
|
||||||
maxUintValue,
|
|
||||||
valueMultiplier,
|
|
||||||
);
|
|
||||||
// execute transfer
|
// execute transfer
|
||||||
// note - this will overflow because we are trying to transfer `maxUintValue * 2` of the 2nd token
|
// note - this will overflow because we are trying to transfer `maxUintValue * 2` of the 2nd token
|
||||||
await expect(
|
await expectTransactionFailedAsync(
|
||||||
erc1155ProxyWrapper.transferFromAsync(
|
erc1155ProxyWrapper.transferFromAsync(
|
||||||
spender,
|
spender,
|
||||||
receiver,
|
receiver,
|
||||||
@@ -1773,7 +1761,8 @@ describe('ERC1155Proxy', () => {
|
|||||||
receiverCallbackData,
|
receiverCallbackData,
|
||||||
authorized,
|
authorized,
|
||||||
),
|
),
|
||||||
).to.revertWith(expectedError);
|
RevertReason.Uint256Overflow,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
it('should revert if transferring > 1 instances of a non-fungible token (valueMultiplier field >1)', async () => {
|
it('should revert if transferring > 1 instances of a non-fungible token (valueMultiplier field >1)', async () => {
|
||||||
// setup test parameters
|
// setup test parameters
|
||||||
@@ -1843,23 +1832,20 @@ describe('ERC1155Proxy', () => {
|
|||||||
// check balances before transfer
|
// check balances before transfer
|
||||||
const expectedInitialBalances = [spenderInitialFungibleBalance, receiverInitialFungibleBalance];
|
const expectedInitialBalances = [spenderInitialFungibleBalance, receiverInitialFungibleBalance];
|
||||||
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
|
await erc1155Wrapper.assertBalancesAsync(tokenHolders, tokensToTransfer, expectedInitialBalances);
|
||||||
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
|
|
||||||
SafeMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
|
|
||||||
spenderInitialFungibleBalance,
|
|
||||||
valuesToTransfer[0].times(valueMultiplier),
|
|
||||||
);
|
|
||||||
// execute transfer
|
// execute transfer
|
||||||
const tx = erc1155ProxyWrapper.transferFromAsync(
|
await expectTransactionFailedAsync(
|
||||||
spender,
|
erc1155ProxyWrapper.transferFromAsync(
|
||||||
receiver,
|
spender,
|
||||||
erc1155Contract.address,
|
receiver,
|
||||||
tokensToTransfer,
|
erc1155Contract.address,
|
||||||
valuesToTransfer,
|
tokensToTransfer,
|
||||||
valueMultiplier,
|
valuesToTransfer,
|
||||||
receiverCallbackData,
|
valueMultiplier,
|
||||||
authorized,
|
receiverCallbackData,
|
||||||
|
authorized,
|
||||||
|
),
|
||||||
|
RevertReason.Uint256Underflow,
|
||||||
);
|
);
|
||||||
return expect(tx).to.revertWith(expectedError);
|
|
||||||
});
|
});
|
||||||
it('should revert if sender allowance is insufficient', async () => {
|
it('should revert if sender allowance is insufficient', async () => {
|
||||||
// dremove allowance for ERC1155 proxy
|
// dremove allowance for ERC1155 proxy
|
||||||
|
|||||||
@@ -1,287 +0,0 @@
|
|||||||
import {
|
|
||||||
blockchainTests,
|
|
||||||
constants,
|
|
||||||
expect,
|
|
||||||
getRandomInteger,
|
|
||||||
Numberish,
|
|
||||||
randomAddress,
|
|
||||||
} from '@0x/contracts-test-utils';
|
|
||||||
import { AuthorizableRevertErrors } from '@0x/contracts-utils';
|
|
||||||
import { AssetProxyId } from '@0x/types';
|
|
||||||
import { AbiEncoder, BigNumber, hexUtils, StringRevertError } from '@0x/utils';
|
|
||||||
import { DecodedLogs } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
|
|
||||||
import { ERC20BridgeProxyContract, TestERC20BridgeContract } from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('ERC20BridgeProxy unit tests', env => {
|
|
||||||
const PROXY_ID = AssetProxyId.ERC20Bridge;
|
|
||||||
const BRIDGE_SUCCESS_RETURN_DATA = hexUtils.rightPad(PROXY_ID);
|
|
||||||
let owner: string;
|
|
||||||
let badCaller: string;
|
|
||||||
let assetProxy: ERC20BridgeProxyContract;
|
|
||||||
let bridgeContract: TestERC20BridgeContract;
|
|
||||||
let testTokenAddress: string;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
[owner, badCaller] = await env.getAccountAddressesAsync();
|
|
||||||
assetProxy = await ERC20BridgeProxyContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.ERC20BridgeProxy,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
bridgeContract = await TestERC20BridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestERC20Bridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
testTokenAddress = await bridgeContract.testToken().callAsync();
|
|
||||||
await assetProxy.addAuthorizedAddress(owner).awaitTransactionSuccessAsync();
|
|
||||||
});
|
|
||||||
|
|
||||||
interface AssetDataOpts {
|
|
||||||
tokenAddress: string;
|
|
||||||
bridgeAddress: string;
|
|
||||||
bridgeData: BridgeDataOpts;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BridgeDataOpts {
|
|
||||||
transferAmount: Numberish;
|
|
||||||
revertError?: string;
|
|
||||||
returnData: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createAssetData(opts?: Partial<AssetDataOpts>): AssetDataOpts {
|
|
||||||
return _.merge(
|
|
||||||
{
|
|
||||||
tokenAddress: testTokenAddress,
|
|
||||||
bridgeAddress: bridgeContract.address,
|
|
||||||
bridgeData: createBridgeData(),
|
|
||||||
},
|
|
||||||
opts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createBridgeData(opts?: Partial<BridgeDataOpts>): BridgeDataOpts {
|
|
||||||
return _.merge(
|
|
||||||
{
|
|
||||||
transferAmount: constants.ZERO_AMOUNT,
|
|
||||||
returnData: BRIDGE_SUCCESS_RETURN_DATA,
|
|
||||||
},
|
|
||||||
opts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeAssetData(opts: AssetDataOpts): string {
|
|
||||||
const encoder = AbiEncoder.createMethod('ERC20BridgeProxy', [
|
|
||||||
{ name: 'tokenAddress', type: 'address' },
|
|
||||||
{ name: 'bridgeAddress', type: 'address' },
|
|
||||||
{ name: 'bridgeData', type: 'bytes' },
|
|
||||||
]);
|
|
||||||
return encoder.encode([opts.tokenAddress, opts.bridgeAddress, encodeBridgeData(opts.bridgeData)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeBridgeData(opts: BridgeDataOpts): string {
|
|
||||||
const encoder = AbiEncoder.create([
|
|
||||||
{ name: 'transferAmount', type: 'int256' },
|
|
||||||
{ name: 'revertData', type: 'bytes' },
|
|
||||||
{ name: 'returnData', type: 'bytes' },
|
|
||||||
]);
|
|
||||||
const revertErrorBytes =
|
|
||||||
opts.revertError !== undefined ? new StringRevertError(opts.revertError).encode() : '0x';
|
|
||||||
return encoder.encode([new BigNumber(opts.transferAmount), revertErrorBytes, opts.returnData]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setTestTokenBalanceAsync(_owner: string, balance: Numberish): Promise<void> {
|
|
||||||
await bridgeContract.setTestTokenBalance(_owner, new BigNumber(balance)).awaitTransactionSuccessAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('transferFrom()', () => {
|
|
||||||
interface TransferFromOpts {
|
|
||||||
assetData: AssetDataOpts;
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
amount: Numberish;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTransferFromOpts(opts?: Partial<TransferFromOpts>): TransferFromOpts {
|
|
||||||
const transferAmount = _.get(opts, ['amount'], getRandomInteger(1, 100e18)) as BigNumber;
|
|
||||||
return _.merge(
|
|
||||||
{
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
transferAmount,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
from: randomAddress(),
|
|
||||||
to: randomAddress(),
|
|
||||||
amount: transferAmount,
|
|
||||||
},
|
|
||||||
opts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function transferFromAsync(opts?: Partial<TransferFromOpts>, caller?: string): Promise<DecodedLogs> {
|
|
||||||
const _opts = createTransferFromOpts(opts);
|
|
||||||
const { logs } = await assetProxy
|
|
||||||
.transferFrom(encodeAssetData(_opts.assetData), _opts.from, _opts.to, new BigNumber(_opts.amount))
|
|
||||||
.awaitTransactionSuccessAsync({ from: caller });
|
|
||||||
return (logs as any) as DecodedLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
it('succeeds if the bridge succeeds and balance increases by `amount`', async () => {
|
|
||||||
const tx = transferFromAsync();
|
|
||||||
return expect(tx).to.be.fulfilled('');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('succeeds if balance increases more than `amount`', async () => {
|
|
||||||
const amount = getRandomInteger(1, 100e18);
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
amount,
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
transferAmount: amount.plus(1),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return expect(tx).to.be.fulfilled('');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('passes the correct arguments to the bridge contract', async () => {
|
|
||||||
const opts = createTransferFromOpts();
|
|
||||||
const logs = await transferFromAsync(opts);
|
|
||||||
expect(logs.length).to.eq(1);
|
|
||||||
const args = logs[0].args;
|
|
||||||
expect(args.tokenAddress).to.eq(opts.assetData.tokenAddress);
|
|
||||||
expect(args.from).to.eq(opts.from);
|
|
||||||
expect(args.to).to.eq(opts.to);
|
|
||||||
expect(args.amount).to.bignumber.eq(opts.amount);
|
|
||||||
expect(args.bridgeData).to.eq(encodeBridgeData(opts.assetData.bridgeData));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if not called by an authorized address', async () => {
|
|
||||||
const tx = transferFromAsync({}, badCaller);
|
|
||||||
return expect(tx).to.revertWith(new AuthorizableRevertErrors.SenderNotAuthorizedError(badCaller));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if asset data is truncated', async () => {
|
|
||||||
const opts = createTransferFromOpts();
|
|
||||||
const truncatedAssetData = hexUtils.slice(encodeAssetData(opts.assetData), 0, -1);
|
|
||||||
const tx = assetProxy
|
|
||||||
.transferFrom(truncatedAssetData, opts.from, opts.to, new BigNumber(opts.amount))
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
return expect(tx).to.be.rejected();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if bridge returns nothing', async () => {
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
returnData: '0x',
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
// This will actually revert when the AP tries to decode the return
|
|
||||||
// value.
|
|
||||||
return expect(tx).to.be.rejected();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if bridge returns true', async () => {
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
returnData: hexUtils.leftPad('0x1'),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
// This will actually revert when the AP tries to decode the return
|
|
||||||
// value.
|
|
||||||
return expect(tx).to.be.rejected();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if bridge returns 0x1', async () => {
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
returnData: hexUtils.rightPad('0x1'),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return expect(tx).to.revertWith('BRIDGE_FAILED');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if bridge is an EOA', async () => {
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeAddress: randomAddress(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
// This will actually revert when the AP tries to decode the return
|
|
||||||
// value.
|
|
||||||
return expect(tx).to.be.rejected();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if bridge reverts', async () => {
|
|
||||||
const revertError = 'FOOBAR';
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
revertError,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return expect(tx).to.revertWith(revertError);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if balance of `to` increases by less than `amount`', async () => {
|
|
||||||
const amount = getRandomInteger(1, 100e18);
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
amount,
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
transferAmount: amount.minus(1),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return expect(tx).to.revertWith('BRIDGE_UNDERPAY');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if balance of `to` decreases', async () => {
|
|
||||||
const toAddress = randomAddress();
|
|
||||||
await setTestTokenBalanceAsync(toAddress, 1e18);
|
|
||||||
const tx = transferFromAsync({
|
|
||||||
to: toAddress,
|
|
||||||
assetData: createAssetData({
|
|
||||||
bridgeData: createBridgeData({
|
|
||||||
transferAmount: -1,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return expect(tx).to.revertWith('BRIDGE_UNDERPAY');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('balanceOf()', () => {
|
|
||||||
it('retrieves the balance of the encoded token', async () => {
|
|
||||||
const _owner = randomAddress();
|
|
||||||
const balance = getRandomInteger(1, 100e18);
|
|
||||||
await bridgeContract.setTestTokenBalance(_owner, balance).awaitTransactionSuccessAsync();
|
|
||||||
const assetData = createAssetData({
|
|
||||||
tokenAddress: testTokenAddress,
|
|
||||||
});
|
|
||||||
const actualBalance = await assetProxy.balanceOf(encodeAssetData(assetData), _owner).callAsync();
|
|
||||||
expect(actualBalance).to.bignumber.eq(balance);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getProxyId()', () => {
|
|
||||||
it('returns the correct proxy ID', async () => {
|
|
||||||
const proxyId = await assetProxy.getProxyId().callAsync();
|
|
||||||
expect(proxyId).to.eq(PROXY_ID);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
import {
|
|
||||||
blockchainTests,
|
|
||||||
constants,
|
|
||||||
expect,
|
|
||||||
filterLogsToArguments,
|
|
||||||
getRandomInteger,
|
|
||||||
Numberish,
|
|
||||||
randomAddress,
|
|
||||||
} from '@0x/contracts-test-utils';
|
|
||||||
import { AssetProxyId } from '@0x/types';
|
|
||||||
import { BigNumber, hexUtils, RawRevertError } from '@0x/utils';
|
|
||||||
import { DecodedLogs } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
|
|
||||||
import {
|
|
||||||
TestEth2DaiBridgeContract,
|
|
||||||
TestEth2DaiBridgeEvents,
|
|
||||||
TestEth2DaiBridgeSellAllAmountEventArgs,
|
|
||||||
TestEth2DaiBridgeTokenApproveEventArgs,
|
|
||||||
TestEth2DaiBridgeTokenTransferEventArgs,
|
|
||||||
} from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('Eth2DaiBridge unit tests', env => {
|
|
||||||
let testContract: TestEth2DaiBridgeContract;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
testContract = await TestEth2DaiBridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestEth2DaiBridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isValidSignature()', () => {
|
|
||||||
it('returns success bytes', async () => {
|
|
||||||
const LEGACY_WALLET_MAGIC_VALUE = '0xb0671381';
|
|
||||||
const result = await testContract
|
|
||||||
.isValidSignature(hexUtils.random(), hexUtils.random(_.random(0, 32)))
|
|
||||||
.callAsync();
|
|
||||||
expect(result).to.eq(LEGACY_WALLET_MAGIC_VALUE);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('bridgeTransferFrom()', () => {
|
|
||||||
interface WithdrawToOpts {
|
|
||||||
toTokenAddress?: string;
|
|
||||||
fromTokenAddress?: string;
|
|
||||||
toAddress: string;
|
|
||||||
amount: Numberish;
|
|
||||||
fromTokenBalance: Numberish;
|
|
||||||
revertReason: string;
|
|
||||||
fillAmount: Numberish;
|
|
||||||
toTokentransferRevertReason: string;
|
|
||||||
toTokenTransferReturnData: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WithdrawToResult {
|
|
||||||
opts: WithdrawToOpts;
|
|
||||||
result: string;
|
|
||||||
logs: DecodedLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createWithdrawToOpts(opts?: Partial<WithdrawToOpts>): WithdrawToOpts {
|
|
||||||
return {
|
|
||||||
toAddress: randomAddress(),
|
|
||||||
amount: getRandomInteger(1, 100e18),
|
|
||||||
revertReason: '',
|
|
||||||
fillAmount: getRandomInteger(1, 100e18),
|
|
||||||
fromTokenBalance: getRandomInteger(1, 100e18),
|
|
||||||
toTokentransferRevertReason: '',
|
|
||||||
toTokenTransferReturnData: hexUtils.leftPad(1),
|
|
||||||
...opts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withdrawToAsync(opts?: Partial<WithdrawToOpts>): Promise<WithdrawToResult> {
|
|
||||||
const _opts = createWithdrawToOpts(opts);
|
|
||||||
// Set the fill behavior.
|
|
||||||
await testContract
|
|
||||||
.setFillBehavior(_opts.revertReason, new BigNumber(_opts.fillAmount))
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
// Create tokens and balances.
|
|
||||||
if (_opts.fromTokenAddress === undefined) {
|
|
||||||
const createTokenFn = testContract.createToken(new BigNumber(_opts.fromTokenBalance));
|
|
||||||
_opts.fromTokenAddress = await createTokenFn.callAsync();
|
|
||||||
await createTokenFn.awaitTransactionSuccessAsync();
|
|
||||||
}
|
|
||||||
if (_opts.toTokenAddress === undefined) {
|
|
||||||
const createTokenFn = testContract.createToken(constants.ZERO_AMOUNT);
|
|
||||||
_opts.toTokenAddress = await createTokenFn.callAsync();
|
|
||||||
await createTokenFn.awaitTransactionSuccessAsync();
|
|
||||||
}
|
|
||||||
// Set the transfer behavior of `toTokenAddress`.
|
|
||||||
await testContract
|
|
||||||
.setTransferBehavior(
|
|
||||||
_opts.toTokenAddress,
|
|
||||||
_opts.toTokentransferRevertReason,
|
|
||||||
_opts.toTokenTransferReturnData,
|
|
||||||
)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
// Call bridgeTransferFrom().
|
|
||||||
const bridgeTransferFromFn = testContract.bridgeTransferFrom(
|
|
||||||
// "to" token address
|
|
||||||
_opts.toTokenAddress,
|
|
||||||
// Random from address.
|
|
||||||
randomAddress(),
|
|
||||||
// To address.
|
|
||||||
_opts.toAddress,
|
|
||||||
new BigNumber(_opts.amount),
|
|
||||||
// ABI-encode the "from" token address as the bridge data.
|
|
||||||
hexUtils.leftPad(_opts.fromTokenAddress as string),
|
|
||||||
);
|
|
||||||
const result = await bridgeTransferFromFn.callAsync();
|
|
||||||
const { logs } = await bridgeTransferFromFn.awaitTransactionSuccessAsync();
|
|
||||||
return {
|
|
||||||
opts: _opts,
|
|
||||||
result,
|
|
||||||
logs: (logs as any) as DecodedLogs,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
it('returns magic bytes on success', async () => {
|
|
||||||
const BRIDGE_SUCCESS_RETURN_DATA = AssetProxyId.ERC20Bridge;
|
|
||||||
const { result } = await withdrawToAsync();
|
|
||||||
expect(result).to.eq(BRIDGE_SUCCESS_RETURN_DATA);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls `Eth2Dai.sellAllAmount()`', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
const transfers = filterLogsToArguments<TestEth2DaiBridgeSellAllAmountEventArgs>(
|
|
||||||
logs,
|
|
||||||
TestEth2DaiBridgeEvents.SellAllAmount,
|
|
||||||
);
|
|
||||||
expect(transfers.length).to.eq(1);
|
|
||||||
expect(transfers[0].sellToken).to.eq(opts.fromTokenAddress);
|
|
||||||
expect(transfers[0].buyToken).to.eq(opts.toTokenAddress);
|
|
||||||
expect(transfers[0].sellTokenAmount).to.bignumber.eq(opts.fromTokenBalance);
|
|
||||||
expect(transfers[0].minimumFillAmount).to.bignumber.eq(opts.amount);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets an unlimited allowance on the `fromTokenAddress` token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
const approvals = filterLogsToArguments<TestEth2DaiBridgeTokenApproveEventArgs>(
|
|
||||||
logs,
|
|
||||||
TestEth2DaiBridgeEvents.TokenApprove,
|
|
||||||
);
|
|
||||||
expect(approvals.length).to.eq(1);
|
|
||||||
expect(approvals[0].token).to.eq(opts.fromTokenAddress);
|
|
||||||
expect(approvals[0].spender).to.eq(testContract.address);
|
|
||||||
expect(approvals[0].allowance).to.bignumber.eq(constants.MAX_UINT256);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('transfers filled amount to `to`', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
const transfers = filterLogsToArguments<TestEth2DaiBridgeTokenTransferEventArgs>(
|
|
||||||
logs,
|
|
||||||
TestEth2DaiBridgeEvents.TokenTransfer,
|
|
||||||
);
|
|
||||||
expect(transfers.length).to.eq(1);
|
|
||||||
expect(transfers[0].token).to.eq(opts.toTokenAddress);
|
|
||||||
expect(transfers[0].from).to.eq(testContract.address);
|
|
||||||
expect(transfers[0].to).to.eq(opts.toAddress);
|
|
||||||
expect(transfers[0].amount).to.bignumber.eq(opts.fillAmount);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if `Eth2Dai.sellAllAmount()` reverts', async () => {
|
|
||||||
const opts = createWithdrawToOpts({ revertReason: 'FOOBAR' });
|
|
||||||
const tx = withdrawToAsync(opts);
|
|
||||||
return expect(tx).to.revertWith(opts.revertReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if `toTokenAddress.transfer()` reverts', async () => {
|
|
||||||
const opts = createWithdrawToOpts({ toTokentransferRevertReason: 'FOOBAR' });
|
|
||||||
const tx = withdrawToAsync(opts);
|
|
||||||
return expect(tx).to.revertWith(opts.toTokentransferRevertReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if `toTokenAddress.transfer()` returns false', async () => {
|
|
||||||
const opts = createWithdrawToOpts({ toTokenTransferReturnData: hexUtils.leftPad(0) });
|
|
||||||
const tx = withdrawToAsync(opts);
|
|
||||||
return expect(tx).to.revertWith(new RawRevertError(hexUtils.leftPad(0)));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('succeeds if `toTokenAddress.transfer()` returns true', async () => {
|
|
||||||
await withdrawToAsync({ toTokenTransferReturnData: hexUtils.leftPad(1) });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,283 +0,0 @@
|
|||||||
import {
|
|
||||||
blockchainTests,
|
|
||||||
constants,
|
|
||||||
expect,
|
|
||||||
getRandomInteger,
|
|
||||||
getRandomPortion,
|
|
||||||
randomAddress,
|
|
||||||
verifyEventsFromLogs,
|
|
||||||
} from '@0x/contracts-test-utils';
|
|
||||||
import { AssetProxyId } from '@0x/types';
|
|
||||||
import { BigNumber, hexUtils } from '@0x/utils';
|
|
||||||
import { DecodedLogs } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
|
|
||||||
import { TestKyberBridgeContract, TestKyberBridgeEvents } from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('KyberBridge unit tests', env => {
|
|
||||||
const KYBER_ETH_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
||||||
const FROM_TOKEN_DECIMALS = 6;
|
|
||||||
const TO_TOKEN_DECIMALS = 18;
|
|
||||||
const FROM_TOKEN_BASE = new BigNumber(10).pow(FROM_TOKEN_DECIMALS);
|
|
||||||
const TO_TOKEN_BASE = new BigNumber(10).pow(TO_TOKEN_DECIMALS);
|
|
||||||
const WETH_BASE = new BigNumber(10).pow(18);
|
|
||||||
const KYBER_RATE_BASE = WETH_BASE;
|
|
||||||
let testContract: TestKyberBridgeContract;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
testContract = await TestKyberBridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestKyberBridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isValidSignature()', () => {
|
|
||||||
it('returns success bytes', async () => {
|
|
||||||
const LEGACY_WALLET_MAGIC_VALUE = '0xb0671381';
|
|
||||||
const result = await testContract
|
|
||||||
.isValidSignature(hexUtils.random(), hexUtils.random(_.random(0, 32)))
|
|
||||||
.callAsync();
|
|
||||||
expect(result).to.eq(LEGACY_WALLET_MAGIC_VALUE);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('bridgeTransferFrom()', () => {
|
|
||||||
let fromTokenAddress: string;
|
|
||||||
let toTokenAddress: string;
|
|
||||||
let wethAddress: string;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
wethAddress = await testContract.weth().callAsync();
|
|
||||||
fromTokenAddress = await testContract.createToken(FROM_TOKEN_DECIMALS).callAsync();
|
|
||||||
await testContract.createToken(FROM_TOKEN_DECIMALS).awaitTransactionSuccessAsync();
|
|
||||||
toTokenAddress = await testContract.createToken(TO_TOKEN_DECIMALS).callAsync();
|
|
||||||
await testContract.createToken(TO_TOKEN_DECIMALS).awaitTransactionSuccessAsync();
|
|
||||||
});
|
|
||||||
|
|
||||||
const STATIC_KYBER_TRADE_ARGS = {
|
|
||||||
maxBuyTokenAmount: constants.MAX_UINT256,
|
|
||||||
walletId: constants.NULL_ADDRESS,
|
|
||||||
};
|
|
||||||
|
|
||||||
interface TransferFromOpts {
|
|
||||||
toTokenAddress: string;
|
|
||||||
fromTokenAddress: string;
|
|
||||||
toAddress: string;
|
|
||||||
// Amount to pass into `bridgeTransferFrom()`
|
|
||||||
amount: BigNumber;
|
|
||||||
// Amount to convert in `trade()`.
|
|
||||||
fillAmount: BigNumber;
|
|
||||||
// Token balance of the bridge.
|
|
||||||
fromTokenBalance: BigNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TransferFromResult {
|
|
||||||
opts: TransferFromOpts;
|
|
||||||
result: string;
|
|
||||||
logs: DecodedLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTransferFromOpts(opts?: Partial<TransferFromOpts>): TransferFromOpts {
|
|
||||||
const amount = getRandomInteger(1, TO_TOKEN_BASE.times(100));
|
|
||||||
return {
|
|
||||||
fromTokenAddress,
|
|
||||||
toTokenAddress,
|
|
||||||
amount,
|
|
||||||
toAddress: randomAddress(),
|
|
||||||
fillAmount: getRandomPortion(amount),
|
|
||||||
fromTokenBalance: getRandomInteger(1, FROM_TOKEN_BASE.times(100)),
|
|
||||||
...opts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withdrawToAsync(opts?: Partial<TransferFromOpts>): Promise<TransferFromResult> {
|
|
||||||
const _opts = createTransferFromOpts(opts);
|
|
||||||
// Fund the contract with input tokens.
|
|
||||||
await testContract
|
|
||||||
.grantTokensTo(_opts.fromTokenAddress, testContract.address, _opts.fromTokenBalance)
|
|
||||||
.awaitTransactionSuccessAsync({ value: _opts.fromTokenBalance });
|
|
||||||
// Fund the contract with output tokens.
|
|
||||||
await testContract.setNextFillAmount(_opts.fillAmount).awaitTransactionSuccessAsync({
|
|
||||||
value: _opts.toTokenAddress === wethAddress ? _opts.fillAmount : constants.ZERO_AMOUNT,
|
|
||||||
});
|
|
||||||
// Call bridgeTransferFrom().
|
|
||||||
const bridgeTransferFromFn = testContract.bridgeTransferFrom(
|
|
||||||
// Output token
|
|
||||||
_opts.toTokenAddress,
|
|
||||||
// Random maker address.
|
|
||||||
randomAddress(),
|
|
||||||
// Recipient address.
|
|
||||||
_opts.toAddress,
|
|
||||||
// Transfer amount.
|
|
||||||
_opts.amount,
|
|
||||||
// ABI-encode the input token address as the bridge data.
|
|
||||||
hexUtils.leftPad(_opts.fromTokenAddress),
|
|
||||||
);
|
|
||||||
const result = await bridgeTransferFromFn.callAsync();
|
|
||||||
const { logs } = await bridgeTransferFromFn.awaitTransactionSuccessAsync();
|
|
||||||
return {
|
|
||||||
opts: _opts,
|
|
||||||
result,
|
|
||||||
logs: (logs as any) as DecodedLogs,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMinimumConversionRate(opts: TransferFromOpts): BigNumber {
|
|
||||||
const fromBase = opts.fromTokenAddress === wethAddress ? WETH_BASE : FROM_TOKEN_BASE;
|
|
||||||
const toBase = opts.toTokenAddress === wethAddress ? WETH_BASE : TO_TOKEN_BASE;
|
|
||||||
return opts.amount
|
|
||||||
.div(toBase)
|
|
||||||
.div(opts.fromTokenBalance.div(fromBase))
|
|
||||||
.times(KYBER_RATE_BASE)
|
|
||||||
.integerValue(BigNumber.ROUND_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
it('returns magic bytes on success', async () => {
|
|
||||||
const BRIDGE_SUCCESS_RETURN_DATA = AssetProxyId.ERC20Bridge;
|
|
||||||
const { result } = await withdrawToAsync();
|
|
||||||
expect(result).to.eq(BRIDGE_SUCCESS_RETURN_DATA);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can trade token -> token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
verifyEventsFromLogs(
|
|
||||||
logs,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
sellTokenAddress: opts.fromTokenAddress,
|
|
||||||
buyTokenAddress: opts.toTokenAddress,
|
|
||||||
sellAmount: opts.fromTokenBalance,
|
|
||||||
recipientAddress: opts.toAddress,
|
|
||||||
minConversionRate: getMinimumConversionRate(opts),
|
|
||||||
msgValue: constants.ZERO_AMOUNT,
|
|
||||||
...STATIC_KYBER_TRADE_ARGS,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
TestKyberBridgeEvents.KyberBridgeTrade,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can trade token -> ETH', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
toTokenAddress: wethAddress,
|
|
||||||
});
|
|
||||||
verifyEventsFromLogs(
|
|
||||||
logs,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
sellTokenAddress: opts.fromTokenAddress,
|
|
||||||
buyTokenAddress: KYBER_ETH_ADDRESS,
|
|
||||||
sellAmount: opts.fromTokenBalance,
|
|
||||||
recipientAddress: testContract.address,
|
|
||||||
minConversionRate: getMinimumConversionRate(opts),
|
|
||||||
msgValue: constants.ZERO_AMOUNT,
|
|
||||||
...STATIC_KYBER_TRADE_ARGS,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
TestKyberBridgeEvents.KyberBridgeTrade,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can trade ETH -> token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: wethAddress,
|
|
||||||
});
|
|
||||||
verifyEventsFromLogs(
|
|
||||||
logs,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
sellTokenAddress: KYBER_ETH_ADDRESS,
|
|
||||||
buyTokenAddress: opts.toTokenAddress,
|
|
||||||
sellAmount: opts.fromTokenBalance,
|
|
||||||
recipientAddress: opts.toAddress,
|
|
||||||
minConversionRate: getMinimumConversionRate(opts),
|
|
||||||
msgValue: opts.fromTokenBalance,
|
|
||||||
...STATIC_KYBER_TRADE_ARGS,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
TestKyberBridgeEvents.KyberBridgeTrade,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does nothing if bridge has no token balance', async () => {
|
|
||||||
const { logs } = await withdrawToAsync({
|
|
||||||
fromTokenBalance: constants.ZERO_AMOUNT,
|
|
||||||
});
|
|
||||||
expect(logs).to.be.length(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('only transfers the token if trading the same token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
toTokenAddress: fromTokenAddress,
|
|
||||||
});
|
|
||||||
verifyEventsFromLogs(
|
|
||||||
logs,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
tokenAddress: fromTokenAddress,
|
|
||||||
ownerAddress: testContract.address,
|
|
||||||
recipientAddress: opts.toAddress,
|
|
||||||
amount: opts.fromTokenBalance,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
TestKyberBridgeEvents.KyberBridgeTokenTransfer,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grants Kyber an allowance when selling non-WETH', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
verifyEventsFromLogs(
|
|
||||||
logs,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
tokenAddress: opts.fromTokenAddress,
|
|
||||||
ownerAddress: testContract.address,
|
|
||||||
spenderAddress: testContract.address,
|
|
||||||
allowance: constants.MAX_UINT256,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
TestKyberBridgeEvents.KyberBridgeTokenApprove,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not grant Kyber an allowance when selling WETH', async () => {
|
|
||||||
const { logs } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: wethAddress,
|
|
||||||
});
|
|
||||||
verifyEventsFromLogs(logs, [], TestKyberBridgeEvents.KyberBridgeTokenApprove);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('withdraws WETH and passes it to Kyber when selling WETH', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: wethAddress,
|
|
||||||
});
|
|
||||||
expect(logs[0].event).to.eq(TestKyberBridgeEvents.KyberBridgeWethWithdraw);
|
|
||||||
expect(logs[0].args).to.deep.eq({
|
|
||||||
ownerAddress: testContract.address,
|
|
||||||
amount: opts.fromTokenBalance,
|
|
||||||
});
|
|
||||||
expect(logs[1].event).to.eq(TestKyberBridgeEvents.KyberBridgeTrade);
|
|
||||||
expect(logs[1].args.msgValue).to.bignumber.eq(opts.fromTokenBalance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('wraps WETH and transfers it to the recipient when buyng WETH', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
toTokenAddress: wethAddress,
|
|
||||||
});
|
|
||||||
expect(logs[0].event).to.eq(TestKyberBridgeEvents.KyberBridgeTokenApprove);
|
|
||||||
expect(logs[0].args.tokenAddress).to.eq(opts.fromTokenAddress);
|
|
||||||
expect(logs[1].event).to.eq(TestKyberBridgeEvents.KyberBridgeTrade);
|
|
||||||
expect(logs[1].args.recipientAddress).to.eq(testContract.address);
|
|
||||||
expect(logs[2].event).to.eq(TestKyberBridgeEvents.KyberBridgeWethDeposit);
|
|
||||||
expect(logs[2].args).to.deep.eq({
|
|
||||||
msgValue: opts.fillAmount,
|
|
||||||
ownerAddress: testContract.address,
|
|
||||||
amount: opts.fillAmount,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
|||||||
import { DevUtilsContract } from '@0x/contracts-dev-utils';
|
|
||||||
import {
|
import {
|
||||||
chaiSetup,
|
chaiSetup,
|
||||||
constants,
|
constants,
|
||||||
@@ -9,14 +8,13 @@ import {
|
|||||||
web3Wrapper,
|
web3Wrapper,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
|
import { assetDataUtils } from '@0x/order-utils';
|
||||||
import { AssetProxyId, RevertReason } from '@0x/types';
|
import { AssetProxyId, RevertReason } from '@0x/types';
|
||||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as ethUtil from 'ethereumjs-util';
|
import * as ethUtil from 'ethereumjs-util';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts, IAssetProxyContract, StaticCallProxyContract, TestStaticCallTargetContract } from '../src';
|
||||||
|
|
||||||
import { IAssetProxyContract, StaticCallProxyContract, TestStaticCallTargetContract } from './wrappers';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -27,7 +25,6 @@ describe('StaticCallProxy', () => {
|
|||||||
let fromAddress: string;
|
let fromAddress: string;
|
||||||
let toAddress: string;
|
let toAddress: string;
|
||||||
|
|
||||||
let devUtils: DevUtilsContract;
|
|
||||||
let staticCallProxy: IAssetProxyContract;
|
let staticCallProxy: IAssetProxyContract;
|
||||||
let staticCallTarget: TestStaticCallTargetContract;
|
let staticCallTarget: TestStaticCallTargetContract;
|
||||||
|
|
||||||
@@ -46,14 +43,7 @@ describe('StaticCallProxy', () => {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
|
staticCallProxy = new IAssetProxyContract(staticCallProxyWithoutTransferFrom.address, provider, txDefaults);
|
||||||
staticCallProxy = new IAssetProxyContract(
|
|
||||||
staticCallProxyWithoutTransferFrom.address,
|
|
||||||
provider,
|
|
||||||
txDefaults,
|
|
||||||
{},
|
|
||||||
StaticCallProxyContract.deployedBytecode,
|
|
||||||
);
|
|
||||||
staticCallTarget = await TestStaticCallTargetContract.deployFrom0xArtifactAsync(
|
staticCallTarget = await TestStaticCallTargetContract.deployFrom0xArtifactAsync(
|
||||||
artifacts.TestStaticCallTarget,
|
artifacts.TestStaticCallTarget,
|
||||||
provider,
|
provider,
|
||||||
@@ -81,21 +71,26 @@ describe('StaticCallProxy', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should have an id of 0xc339d10a', async () => {
|
it('should have an id of 0xc339d10a', async () => {
|
||||||
const proxyId = await staticCallProxy.getProxyId().callAsync();
|
const proxyId = await staticCallProxy.getProxyId.callAsync();
|
||||||
const expectedProxyId = AssetProxyId.StaticCall;
|
const expectedProxyId = AssetProxyId.StaticCall;
|
||||||
expect(proxyId).to.equal(expectedProxyId);
|
expect(proxyId).to.equal(expectedProxyId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('transferFrom', () => {
|
describe('transferFrom', () => {
|
||||||
it('should revert if assetData lies outside the bounds of calldata', async () => {
|
it('should revert if assetData lies outside the bounds of calldata', async () => {
|
||||||
const staticCallData = staticCallTarget.noInputFunction().getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.noInputFunction.getABIEncodedTransactionData();
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
const txData = staticCallProxy
|
expectedResultHash,
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
);
|
||||||
.getABIEncodedTransactionData();
|
const txData = staticCallProxy.transferFrom.getABIEncodedTransactionData(
|
||||||
|
assetData,
|
||||||
|
fromAddress,
|
||||||
|
toAddress,
|
||||||
|
amount,
|
||||||
|
);
|
||||||
const offsetToAssetData = '0000000000000000000000000000000000000000000000000000000000000080';
|
const offsetToAssetData = '0000000000000000000000000000000000000000000000000000000000000080';
|
||||||
const txDataEndBuffer = ethUtil.toBuffer((txData.length - 2) / 2 - 4);
|
const txDataEndBuffer = ethUtil.toBuffer((txData.length - 2) / 2 - 4);
|
||||||
const paddedTxDataEndBuffer = ethUtil.setLengthLeft(txDataEndBuffer, 32);
|
const paddedTxDataEndBuffer = ethUtil.setLengthLeft(txDataEndBuffer, 32);
|
||||||
@@ -113,21 +108,23 @@ describe('StaticCallProxy', () => {
|
|||||||
it('should revert if the length of assetData is less than 100 bytes', async () => {
|
it('should revert if the length of assetData is less than 100 bytes', async () => {
|
||||||
const staticCallData = constants.NULL_BYTES;
|
const staticCallData = constants.NULL_BYTES;
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = (await devUtils
|
const assetData = assetDataUtils
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
||||||
.callAsync()).slice(0, -128);
|
.slice(0, -128);
|
||||||
const assetDataByteLen = (assetData.length - 2) / 2;
|
const assetDataByteLen = (assetData.length - 2) / 2;
|
||||||
expect((assetDataByteLen - 4) % 32).to.equal(0);
|
expect((assetDataByteLen - 4) % 32).to.equal(0);
|
||||||
await expectTransactionFailedWithoutReasonAsync(
|
await expectTransactionFailedWithoutReasonAsync(
|
||||||
staticCallProxy.transferFrom(assetData, fromAddress, toAddress, amount).sendTransactionAsync(),
|
staticCallProxy.transferFrom.sendTransactionAsync(assetData, fromAddress, toAddress, amount),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should revert if the offset to `staticCallData` points to outside of assetData', async () => {
|
it('should revert if the offset to `staticCallData` points to outside of assetData', async () => {
|
||||||
const staticCallData = staticCallTarget.noInputFunction().getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.noInputFunction.getABIEncodedTransactionData();
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
|
expectedResultHash,
|
||||||
|
);
|
||||||
const offsetToStaticCallData = '0000000000000000000000000000000000000000000000000000000000000060';
|
const offsetToStaticCallData = '0000000000000000000000000000000000000000000000000000000000000060';
|
||||||
const assetDataEndBuffer = ethUtil.toBuffer((assetData.length - 2) / 2 - 4);
|
const assetDataEndBuffer = ethUtil.toBuffer((assetData.length - 2) / 2 - 4);
|
||||||
const paddedAssetDataEndBuffer = ethUtil.setLengthLeft(assetDataEndBuffer, 32);
|
const paddedAssetDataEndBuffer = ethUtil.setLengthLeft(assetDataEndBuffer, 32);
|
||||||
@@ -138,88 +135,90 @@ describe('StaticCallProxy', () => {
|
|||||||
invalidOffsetToStaticCallData,
|
invalidOffsetToStaticCallData,
|
||||||
)}${newStaticCallData}`;
|
)}${newStaticCallData}`;
|
||||||
await expectTransactionFailedWithoutReasonAsync(
|
await expectTransactionFailedWithoutReasonAsync(
|
||||||
staticCallProxy.transferFrom(badAssetData, fromAddress, toAddress, amount).sendTransactionAsync(),
|
staticCallProxy.transferFrom.sendTransactionAsync(badAssetData, fromAddress, toAddress, amount),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should revert if the callTarget attempts to write to state', async () => {
|
it('should revert if the callTarget attempts to write to state', async () => {
|
||||||
const staticCallData = staticCallTarget.updateState().getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.updateState.getABIEncodedTransactionData();
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
|
expectedResultHash,
|
||||||
|
);
|
||||||
await expectTransactionFailedWithoutReasonAsync(
|
await expectTransactionFailedWithoutReasonAsync(
|
||||||
staticCallProxy.transferFrom(assetData, fromAddress, toAddress, amount).sendTransactionAsync(),
|
staticCallProxy.transferFrom.sendTransactionAsync(assetData, fromAddress, toAddress, amount),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should revert with data provided by the callTarget if the staticcall reverts', async () => {
|
it('should revert with data provided by the callTarget if the staticcall reverts', async () => {
|
||||||
const staticCallData = staticCallTarget.assertEvenNumber(new BigNumber(1)).getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(new BigNumber(1));
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
|
expectedResultHash,
|
||||||
|
);
|
||||||
await expectTransactionFailedAsync(
|
await expectTransactionFailedAsync(
|
||||||
staticCallProxy.transferFrom(assetData, fromAddress, toAddress, amount).sendTransactionAsync(),
|
staticCallProxy.transferFrom.sendTransactionAsync(assetData, fromAddress, toAddress, amount),
|
||||||
RevertReason.TargetNotEven,
|
RevertReason.TargetNotEven,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should revert if the hash of the output is different than expected expected', async () => {
|
it('should revert if the hash of the output is different than expected expected', async () => {
|
||||||
const staticCallData = staticCallTarget.isOddNumber(new BigNumber(0)).getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.isOddNumber.getABIEncodedTransactionData(new BigNumber(0));
|
||||||
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
|
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
|
||||||
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
|
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
|
expectedResultHash,
|
||||||
|
);
|
||||||
await expectTransactionFailedAsync(
|
await expectTransactionFailedAsync(
|
||||||
staticCallProxy.transferFrom(assetData, fromAddress, toAddress, amount).sendTransactionAsync(),
|
staticCallProxy.transferFrom.sendTransactionAsync(assetData, fromAddress, toAddress, amount),
|
||||||
RevertReason.UnexpectedStaticCallResult,
|
RevertReason.UnexpectedStaticCallResult,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should be successful if a function call with no inputs and no outputs is successful', async () => {
|
it('should be successful if a function call with no inputs and no outputs is successful', async () => {
|
||||||
const staticCallData = staticCallTarget.noInputFunction().getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.noInputFunction.getABIEncodedTransactionData();
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
await staticCallProxy
|
expectedResultHash,
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
);
|
||||||
.awaitTransactionSuccessAsync();
|
await staticCallProxy.transferFrom.awaitTransactionSuccessAsync(assetData, fromAddress, toAddress, amount);
|
||||||
});
|
});
|
||||||
it('should be successful if the staticCallTarget is not a contract and no return value is expected', async () => {
|
it('should be successful if the staticCallTarget is not a contract and no return value is expected', async () => {
|
||||||
const staticCallData = '0x0102030405060708';
|
const staticCallData = '0x0102030405060708';
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(toAddress, staticCallData, expectedResultHash);
|
||||||
.encodeStaticCallAssetData(toAddress, staticCallData, expectedResultHash)
|
await staticCallProxy.transferFrom.awaitTransactionSuccessAsync(assetData, fromAddress, toAddress, amount);
|
||||||
.callAsync();
|
|
||||||
await staticCallProxy
|
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
});
|
});
|
||||||
it('should be successful if a function call with one static input returns the correct value', async () => {
|
it('should be successful if a function call with one static input returns the correct value', async () => {
|
||||||
const staticCallData = staticCallTarget.isOddNumber(new BigNumber(1)).getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.isOddNumber.getABIEncodedTransactionData(new BigNumber(1));
|
||||||
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
|
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
|
||||||
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
|
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
await staticCallProxy
|
expectedResultHash,
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
);
|
||||||
.awaitTransactionSuccessAsync();
|
await staticCallProxy.transferFrom.awaitTransactionSuccessAsync(assetData, fromAddress, toAddress, amount);
|
||||||
});
|
});
|
||||||
it('should be successful if a function with one dynamic input is successful', async () => {
|
it('should be successful if a function with one dynamic input is successful', async () => {
|
||||||
const dynamicInput = '0x0102030405060708';
|
const dynamicInput = '0x0102030405060708';
|
||||||
const staticCallData = staticCallTarget.dynamicInputFunction(dynamicInput).getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.dynamicInputFunction.getABIEncodedTransactionData(dynamicInput);
|
||||||
const expectedResultHash = constants.KECCAK256_NULL;
|
const expectedResultHash = constants.KECCAK256_NULL;
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
await staticCallProxy
|
expectedResultHash,
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
);
|
||||||
.awaitTransactionSuccessAsync();
|
await staticCallProxy.transferFrom.awaitTransactionSuccessAsync(assetData, fromAddress, toAddress, amount);
|
||||||
});
|
});
|
||||||
it('should be successful if a function call returns a complex type', async () => {
|
it('should be successful if a function call returns a complex type', async () => {
|
||||||
const a = new BigNumber(1);
|
const a = new BigNumber(1);
|
||||||
const b = new BigNumber(2);
|
const b = new BigNumber(2);
|
||||||
const staticCallData = staticCallTarget.returnComplexType(a, b).getABIEncodedTransactionData();
|
const staticCallData = staticCallTarget.returnComplexType.getABIEncodedTransactionData(a, b);
|
||||||
const abiEncoder = new AbiEncoder.DynamicBytes({
|
const abiEncoder = new AbiEncoder.DynamicBytes({
|
||||||
name: '',
|
name: '',
|
||||||
type: 'bytes',
|
type: 'bytes',
|
||||||
@@ -232,12 +231,12 @@ describe('StaticCallProxy', () => {
|
|||||||
const expectedResultHash = ethUtil.bufferToHex(
|
const expectedResultHash = ethUtil.bufferToHex(
|
||||||
ethUtil.sha3(ethUtil.toBuffer(encodedExpectedResultWithOffset)),
|
ethUtil.sha3(ethUtil.toBuffer(encodedExpectedResultWithOffset)),
|
||||||
);
|
);
|
||||||
const assetData = await devUtils
|
const assetData = assetDataUtils.encodeStaticCallAssetData(
|
||||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
|
staticCallTarget.address,
|
||||||
.callAsync();
|
staticCallData,
|
||||||
await staticCallProxy
|
expectedResultHash,
|
||||||
.transferFrom(assetData, fromAddress, toAddress, amount)
|
);
|
||||||
.awaitTransactionSuccessAsync();
|
await staticCallProxy.transferFrom.awaitTransactionSuccessAsync(assetData, fromAddress, toAddress, amount);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,370 +0,0 @@
|
|||||||
import {
|
|
||||||
blockchainTests,
|
|
||||||
constants,
|
|
||||||
expect,
|
|
||||||
filterLogs,
|
|
||||||
filterLogsToArguments,
|
|
||||||
getRandomInteger,
|
|
||||||
Numberish,
|
|
||||||
randomAddress,
|
|
||||||
} from '@0x/contracts-test-utils';
|
|
||||||
import { AssetProxyId } from '@0x/types';
|
|
||||||
import { BigNumber, hexUtils } from '@0x/utils';
|
|
||||||
import { DecodedLogs } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
|
||||||
|
|
||||||
import {
|
|
||||||
TestUniswapBridgeContract,
|
|
||||||
TestUniswapBridgeEthToTokenTransferInputEventArgs as EthToTokenTransferInputArgs,
|
|
||||||
TestUniswapBridgeEvents as ContractEvents,
|
|
||||||
TestUniswapBridgeTokenApproveEventArgs as TokenApproveArgs,
|
|
||||||
TestUniswapBridgeTokenToEthSwapInputEventArgs as TokenToEthSwapInputArgs,
|
|
||||||
TestUniswapBridgeTokenToTokenTransferInputEventArgs as TokenToTokenTransferInputArgs,
|
|
||||||
TestUniswapBridgeTokenTransferEventArgs as TokenTransferArgs,
|
|
||||||
TestUniswapBridgeWethDepositEventArgs as WethDepositArgs,
|
|
||||||
TestUniswapBridgeWethWithdrawEventArgs as WethWithdrawArgs,
|
|
||||||
} from './wrappers';
|
|
||||||
|
|
||||||
blockchainTests.resets('UniswapBridge unit tests', env => {
|
|
||||||
let testContract: TestUniswapBridgeContract;
|
|
||||||
let wethTokenAddress: string;
|
|
||||||
|
|
||||||
before(async () => {
|
|
||||||
testContract = await TestUniswapBridgeContract.deployFrom0xArtifactAsync(
|
|
||||||
artifacts.TestUniswapBridge,
|
|
||||||
env.provider,
|
|
||||||
env.txDefaults,
|
|
||||||
artifacts,
|
|
||||||
);
|
|
||||||
wethTokenAddress = await testContract.wethToken().callAsync();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isValidSignature()', () => {
|
|
||||||
it('returns success bytes', async () => {
|
|
||||||
const LEGACY_WALLET_MAGIC_VALUE = '0xb0671381';
|
|
||||||
const result = await testContract
|
|
||||||
.isValidSignature(hexUtils.random(), hexUtils.random(_.random(0, 32)))
|
|
||||||
.callAsync();
|
|
||||||
expect(result).to.eq(LEGACY_WALLET_MAGIC_VALUE);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('bridgeTransferFrom()', () => {
|
|
||||||
interface WithdrawToOpts {
|
|
||||||
fromTokenAddress: string;
|
|
||||||
toTokenAddress: string;
|
|
||||||
fromTokenBalance: Numberish;
|
|
||||||
toAddress: string;
|
|
||||||
amount: Numberish;
|
|
||||||
exchangeRevertReason: string;
|
|
||||||
exchangeFillAmount: Numberish;
|
|
||||||
toTokenRevertReason: string;
|
|
||||||
fromTokenRevertReason: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createWithdrawToOpts(opts?: Partial<WithdrawToOpts>): WithdrawToOpts {
|
|
||||||
return {
|
|
||||||
fromTokenAddress: constants.NULL_ADDRESS,
|
|
||||||
toTokenAddress: constants.NULL_ADDRESS,
|
|
||||||
fromTokenBalance: getRandomInteger(1, 1e18),
|
|
||||||
toAddress: randomAddress(),
|
|
||||||
amount: getRandomInteger(1, 1e18),
|
|
||||||
exchangeRevertReason: '',
|
|
||||||
exchangeFillAmount: getRandomInteger(1, 1e18),
|
|
||||||
toTokenRevertReason: '',
|
|
||||||
fromTokenRevertReason: '',
|
|
||||||
...opts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WithdrawToResult {
|
|
||||||
opts: WithdrawToOpts;
|
|
||||||
result: string;
|
|
||||||
logs: DecodedLogs;
|
|
||||||
blockTime: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withdrawToAsync(opts?: Partial<WithdrawToOpts>): Promise<WithdrawToResult> {
|
|
||||||
const _opts = createWithdrawToOpts(opts);
|
|
||||||
const callData = { value: new BigNumber(_opts.exchangeFillAmount) };
|
|
||||||
// Create the "from" token and exchange.
|
|
||||||
const createFromTokenFn = testContract.createTokenAndExchange(
|
|
||||||
_opts.fromTokenAddress,
|
|
||||||
_opts.exchangeRevertReason,
|
|
||||||
);
|
|
||||||
[_opts.fromTokenAddress] = await createFromTokenFn.callAsync(callData);
|
|
||||||
await createFromTokenFn.awaitTransactionSuccessAsync(callData);
|
|
||||||
|
|
||||||
// Create the "to" token and exchange.
|
|
||||||
const createToTokenFn = testContract.createTokenAndExchange(
|
|
||||||
_opts.toTokenAddress,
|
|
||||||
_opts.exchangeRevertReason,
|
|
||||||
);
|
|
||||||
[_opts.toTokenAddress] = await createToTokenFn.callAsync(callData);
|
|
||||||
await createToTokenFn.awaitTransactionSuccessAsync(callData);
|
|
||||||
|
|
||||||
await testContract
|
|
||||||
.setTokenRevertReason(_opts.toTokenAddress, _opts.toTokenRevertReason)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
await testContract
|
|
||||||
.setTokenRevertReason(_opts.fromTokenAddress, _opts.fromTokenRevertReason)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
// Set the token balance for the token we're converting from.
|
|
||||||
await testContract.setTokenBalance(_opts.fromTokenAddress).awaitTransactionSuccessAsync({
|
|
||||||
value: new BigNumber(_opts.fromTokenBalance),
|
|
||||||
});
|
|
||||||
// Call bridgeTransferFrom().
|
|
||||||
const bridgeTransferFromFn = testContract.bridgeTransferFrom(
|
|
||||||
// The "to" token address.
|
|
||||||
_opts.toTokenAddress,
|
|
||||||
// The "from" address.
|
|
||||||
randomAddress(),
|
|
||||||
// The "to" address.
|
|
||||||
_opts.toAddress,
|
|
||||||
// The amount to transfer to "to"
|
|
||||||
new BigNumber(_opts.amount),
|
|
||||||
// ABI-encoded "from" token address.
|
|
||||||
hexUtils.leftPad(_opts.fromTokenAddress),
|
|
||||||
);
|
|
||||||
const result = await bridgeTransferFromFn.callAsync();
|
|
||||||
const receipt = await bridgeTransferFromFn.awaitTransactionSuccessAsync();
|
|
||||||
return {
|
|
||||||
opts: _opts,
|
|
||||||
result,
|
|
||||||
logs: (receipt.logs as any) as DecodedLogs,
|
|
||||||
blockTime: await env.web3Wrapper.getBlockTimestampAsync(receipt.blockNumber),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getExchangeForTokenAsync(tokenAddress: string): Promise<string> {
|
|
||||||
return testContract.getExchange(tokenAddress).callAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
it('returns magic bytes on success', async () => {
|
|
||||||
const { result } = await withdrawToAsync();
|
|
||||||
expect(result).to.eq(AssetProxyId.ERC20Bridge);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('just transfers tokens to `to` if the same tokens are in play', async () => {
|
|
||||||
const createTokenFn = await testContract.createTokenAndExchange(constants.NULL_ADDRESS, '');
|
|
||||||
const [tokenAddress] = await createTokenFn.callAsync();
|
|
||||||
await createTokenFn.awaitTransactionSuccessAsync();
|
|
||||||
const { opts, result, logs } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: tokenAddress,
|
|
||||||
toTokenAddress: tokenAddress,
|
|
||||||
});
|
|
||||||
expect(result).to.eq(AssetProxyId.ERC20Bridge);
|
|
||||||
const transfers = filterLogsToArguments<TokenTransferArgs>(logs, ContractEvents.TokenTransfer);
|
|
||||||
expect(transfers.length).to.eq(1);
|
|
||||||
expect(transfers[0].token).to.eq(tokenAddress);
|
|
||||||
expect(transfers[0].from).to.eq(testContract.address);
|
|
||||||
expect(transfers[0].to).to.eq(opts.toAddress);
|
|
||||||
expect(transfers[0].amount).to.bignumber.eq(opts.amount);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('token -> token', () => {
|
|
||||||
it('calls `IUniswapExchange.tokenToTokenTransferInput()', async () => {
|
|
||||||
const { opts, logs, blockTime } = await withdrawToAsync();
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
const calls = filterLogsToArguments<TokenToTokenTransferInputArgs>(
|
|
||||||
logs,
|
|
||||||
ContractEvents.TokenToTokenTransferInput,
|
|
||||||
);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].exchange).to.eq(exchangeAddress);
|
|
||||||
expect(calls[0].tokensSold).to.bignumber.eq(opts.fromTokenBalance);
|
|
||||||
expect(calls[0].minTokensBought).to.bignumber.eq(opts.amount);
|
|
||||||
expect(calls[0].minEthBought).to.bignumber.eq(1);
|
|
||||||
expect(calls[0].deadline).to.bignumber.eq(blockTime);
|
|
||||||
expect(calls[0].recipient).to.eq(opts.toAddress);
|
|
||||||
expect(calls[0].toTokenAddress).to.eq(opts.toTokenAddress);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets allowance for "from" token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync();
|
|
||||||
const approvals = filterLogsToArguments<TokenApproveArgs>(logs, ContractEvents.TokenApprove);
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
expect(approvals.length).to.eq(1);
|
|
||||||
expect(approvals[0].spender).to.eq(exchangeAddress);
|
|
||||||
expect(approvals[0].allowance).to.bignumber.eq(constants.MAX_UINT256);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets allowance for "from" token on subsequent calls', async () => {
|
|
||||||
const { opts } = await withdrawToAsync();
|
|
||||||
const { logs } = await withdrawToAsync(opts);
|
|
||||||
const approvals = filterLogsToArguments<TokenApproveArgs>(logs, ContractEvents.TokenApprove);
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
expect(approvals.length).to.eq(1);
|
|
||||||
expect(approvals[0].spender).to.eq(exchangeAddress);
|
|
||||||
expect(approvals[0].allowance).to.bignumber.eq(constants.MAX_UINT256);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if "from" token does not exist', async () => {
|
|
||||||
const tx = testContract
|
|
||||||
.bridgeTransferFrom(
|
|
||||||
randomAddress(),
|
|
||||||
randomAddress(),
|
|
||||||
randomAddress(),
|
|
||||||
getRandomInteger(1, 1e18),
|
|
||||||
hexUtils.leftPad(randomAddress()),
|
|
||||||
)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith('NO_UNISWAP_EXCHANGE_FOR_TOKEN');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if the exchange fails', async () => {
|
|
||||||
const revertReason = 'FOOBAR';
|
|
||||||
const tx = withdrawToAsync({
|
|
||||||
exchangeRevertReason: revertReason,
|
|
||||||
});
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith(revertReason);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('token -> ETH', () => {
|
|
||||||
it('calls `IUniswapExchange.tokenToEthSwapInput()`, `WETH.deposit()`, then `transfer()`', async () => {
|
|
||||||
const { opts, logs, blockTime } = await withdrawToAsync({
|
|
||||||
toTokenAddress: wethTokenAddress,
|
|
||||||
});
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
let calls: any = filterLogs<TokenToEthSwapInputArgs>(logs, ContractEvents.TokenToEthSwapInput);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].args.exchange).to.eq(exchangeAddress);
|
|
||||||
expect(calls[0].args.tokensSold).to.bignumber.eq(opts.fromTokenBalance);
|
|
||||||
expect(calls[0].args.minEthBought).to.bignumber.eq(opts.amount);
|
|
||||||
expect(calls[0].args.deadline).to.bignumber.eq(blockTime);
|
|
||||||
calls = filterLogs<WethDepositArgs>(
|
|
||||||
logs.slice(calls[0].logIndex as number),
|
|
||||||
ContractEvents.WethDeposit,
|
|
||||||
);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].args.amount).to.bignumber.eq(opts.exchangeFillAmount);
|
|
||||||
calls = filterLogs<TokenTransferArgs>(
|
|
||||||
logs.slice(calls[0].logIndex as number),
|
|
||||||
ContractEvents.TokenTransfer,
|
|
||||||
);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].args.token).to.eq(opts.toTokenAddress);
|
|
||||||
expect(calls[0].args.from).to.eq(testContract.address);
|
|
||||||
expect(calls[0].args.to).to.eq(opts.toAddress);
|
|
||||||
expect(calls[0].args.amount).to.bignumber.eq(opts.exchangeFillAmount);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets allowance for "from" token', async () => {
|
|
||||||
const { opts, logs } = await withdrawToAsync({
|
|
||||||
toTokenAddress: wethTokenAddress,
|
|
||||||
});
|
|
||||||
const transfers = filterLogsToArguments<TokenApproveArgs>(logs, ContractEvents.TokenApprove);
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
expect(transfers.length).to.eq(1);
|
|
||||||
expect(transfers[0].spender).to.eq(exchangeAddress);
|
|
||||||
expect(transfers[0].allowance).to.bignumber.eq(constants.MAX_UINT256);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets allowance for "from" token on subsequent calls', async () => {
|
|
||||||
const { opts } = await withdrawToAsync({
|
|
||||||
toTokenAddress: wethTokenAddress,
|
|
||||||
});
|
|
||||||
const { logs } = await withdrawToAsync(opts);
|
|
||||||
const approvals = filterLogsToArguments<TokenApproveArgs>(logs, ContractEvents.TokenApprove);
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.fromTokenAddress);
|
|
||||||
expect(approvals.length).to.eq(1);
|
|
||||||
expect(approvals[0].spender).to.eq(exchangeAddress);
|
|
||||||
expect(approvals[0].allowance).to.bignumber.eq(constants.MAX_UINT256);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if "from" token does not exist', async () => {
|
|
||||||
const tx = testContract
|
|
||||||
.bridgeTransferFrom(
|
|
||||||
randomAddress(),
|
|
||||||
randomAddress(),
|
|
||||||
randomAddress(),
|
|
||||||
getRandomInteger(1, 1e18),
|
|
||||||
hexUtils.leftPad(wethTokenAddress),
|
|
||||||
)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith('NO_UNISWAP_EXCHANGE_FOR_TOKEN');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if `WETH.deposit()` fails', async () => {
|
|
||||||
const revertReason = 'FOOBAR';
|
|
||||||
const tx = withdrawToAsync({
|
|
||||||
toTokenAddress: wethTokenAddress,
|
|
||||||
toTokenRevertReason: revertReason,
|
|
||||||
});
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith(revertReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if the exchange fails', async () => {
|
|
||||||
const revertReason = 'FOOBAR';
|
|
||||||
const tx = withdrawToAsync({
|
|
||||||
toTokenAddress: wethTokenAddress,
|
|
||||||
exchangeRevertReason: revertReason,
|
|
||||||
});
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith(revertReason);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ETH -> token', () => {
|
|
||||||
it('calls `WETH.withdraw()`, then `IUniswapExchange.ethToTokenTransferInput()`', async () => {
|
|
||||||
const { opts, logs, blockTime } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: wethTokenAddress,
|
|
||||||
});
|
|
||||||
const exchangeAddress = await getExchangeForTokenAsync(opts.toTokenAddress);
|
|
||||||
let calls: any = filterLogs<WethWithdrawArgs>(logs, ContractEvents.WethWithdraw);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].args.amount).to.bignumber.eq(opts.fromTokenBalance);
|
|
||||||
calls = filterLogs<EthToTokenTransferInputArgs>(
|
|
||||||
logs.slice(calls[0].logIndex as number),
|
|
||||||
ContractEvents.EthToTokenTransferInput,
|
|
||||||
);
|
|
||||||
expect(calls.length).to.eq(1);
|
|
||||||
expect(calls[0].args.exchange).to.eq(exchangeAddress);
|
|
||||||
expect(calls[0].args.minTokensBought).to.bignumber.eq(opts.amount);
|
|
||||||
expect(calls[0].args.deadline).to.bignumber.eq(blockTime);
|
|
||||||
expect(calls[0].args.recipient).to.eq(opts.toAddress);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not set any allowance', async () => {
|
|
||||||
const { logs } = await withdrawToAsync({
|
|
||||||
fromTokenAddress: wethTokenAddress,
|
|
||||||
});
|
|
||||||
const approvals = filterLogsToArguments<TokenApproveArgs>(logs, ContractEvents.TokenApprove);
|
|
||||||
expect(approvals).to.be.empty('');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if "to" token does not exist', async () => {
|
|
||||||
const tx = testContract
|
|
||||||
.bridgeTransferFrom(
|
|
||||||
wethTokenAddress,
|
|
||||||
randomAddress(),
|
|
||||||
randomAddress(),
|
|
||||||
getRandomInteger(1, 1e18),
|
|
||||||
hexUtils.leftPad(randomAddress()),
|
|
||||||
)
|
|
||||||
.awaitTransactionSuccessAsync();
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith('NO_UNISWAP_EXCHANGE_FOR_TOKEN');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if the `WETH.withdraw()` fails', async () => {
|
|
||||||
const revertReason = 'FOOBAR';
|
|
||||||
const tx = withdrawToAsync({
|
|
||||||
fromTokenAddress: wethTokenAddress,
|
|
||||||
fromTokenRevertReason: revertReason,
|
|
||||||
});
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith(revertReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails if the exchange fails', async () => {
|
|
||||||
const revertReason = 'FOOBAR';
|
|
||||||
const tx = withdrawToAsync({
|
|
||||||
fromTokenAddress: wethTokenAddress,
|
|
||||||
exchangeRevertReason: revertReason,
|
|
||||||
});
|
|
||||||
return expect(tx).to.eventually.be.rejectedWith(revertReason);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { DevUtilsContract } from '@0x/contracts-dev-utils';
|
|
||||||
import { artifacts as erc1155Artifacts, ERC1155MintableContract, Erc1155Wrapper } from '@0x/contracts-erc1155';
|
import { artifacts as erc1155Artifacts, ERC1155MintableContract, Erc1155Wrapper } from '@0x/contracts-erc1155';
|
||||||
import {
|
import {
|
||||||
constants,
|
constants,
|
||||||
@@ -8,14 +7,13 @@ import {
|
|||||||
LogDecoder,
|
LogDecoder,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
|
import { assetDataUtils } from '@0x/order-utils';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||||
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts, ERC1155ProxyContract, IAssetProxyContract } from '../../src';
|
||||||
|
|
||||||
import { ERC1155ProxyContract, IAssetProxyContract } from './wrappers';
|
|
||||||
|
|
||||||
export class ERC1155ProxyWrapper {
|
export class ERC1155ProxyWrapper {
|
||||||
private readonly _tokenOwnerAddresses: string[];
|
private readonly _tokenOwnerAddresses: string[];
|
||||||
@@ -28,7 +26,6 @@ export class ERC1155ProxyWrapper {
|
|||||||
private readonly _logDecoder: LogDecoder;
|
private readonly _logDecoder: LogDecoder;
|
||||||
private readonly _dummyTokenWrappers: Erc1155Wrapper[];
|
private readonly _dummyTokenWrappers: Erc1155Wrapper[];
|
||||||
private readonly _assetProxyInterface: IAssetProxyContract;
|
private readonly _assetProxyInterface: IAssetProxyContract;
|
||||||
private readonly _devUtils: DevUtilsContract;
|
|
||||||
private _proxyContract?: ERC1155ProxyContract;
|
private _proxyContract?: ERC1155ProxyContract;
|
||||||
private _proxyIdIfExists?: string;
|
private _proxyIdIfExists?: string;
|
||||||
private _initialTokenIdsByOwner: ERC1155HoldingsByOwner = { fungible: {}, nonFungible: {} };
|
private _initialTokenIdsByOwner: ERC1155HoldingsByOwner = { fungible: {}, nonFungible: {} };
|
||||||
@@ -40,7 +37,6 @@ export class ERC1155ProxyWrapper {
|
|||||||
this._logDecoder = new LogDecoder(this._web3Wrapper, allArtifacts);
|
this._logDecoder = new LogDecoder(this._web3Wrapper, allArtifacts);
|
||||||
this._dummyTokenWrappers = [];
|
this._dummyTokenWrappers = [];
|
||||||
this._assetProxyInterface = new IAssetProxyContract(constants.NULL_ADDRESS, provider);
|
this._assetProxyInterface = new IAssetProxyContract(constants.NULL_ADDRESS, provider);
|
||||||
this._devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
|
|
||||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||||
this._contractOwnerAddress = contractOwnerAddress;
|
this._contractOwnerAddress = contractOwnerAddress;
|
||||||
this._fungibleTokenIds = [];
|
this._fungibleTokenIds = [];
|
||||||
@@ -60,7 +56,7 @@ export class ERC1155ProxyWrapper {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
const erc1155Wrapper = new Erc1155Wrapper(erc1155Contract, this._contractOwnerAddress);
|
const erc1155Wrapper = new Erc1155Wrapper(erc1155Contract, this._provider, this._contractOwnerAddress);
|
||||||
this._dummyTokenWrappers.push(erc1155Wrapper);
|
this._dummyTokenWrappers.push(erc1155Wrapper);
|
||||||
}
|
}
|
||||||
return this._dummyTokenWrappers;
|
return this._dummyTokenWrappers;
|
||||||
@@ -76,7 +72,7 @@ export class ERC1155ProxyWrapper {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
this._proxyIdIfExists = await this._proxyContract.getProxyId().callAsync();
|
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
|
||||||
return this._proxyContract;
|
return this._proxyContract;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +95,7 @@ export class ERC1155ProxyWrapper {
|
|||||||
* @param extraData extra data to append to `transferFrom` transaction. Optional.
|
* @param extraData extra data to append to `transferFrom` transaction. Optional.
|
||||||
* @return abi encoded tx data.
|
* @return abi encoded tx data.
|
||||||
*/
|
*/
|
||||||
public async getTransferFromAbiEncodedTxDataAsync(
|
public getTransferFromAbiEncodedTxData(
|
||||||
from: string,
|
from: string,
|
||||||
to: string,
|
to: string,
|
||||||
contractAddress: string,
|
contractAddress: string,
|
||||||
@@ -109,17 +105,23 @@ export class ERC1155ProxyWrapper {
|
|||||||
receiverCallbackData: string,
|
receiverCallbackData: string,
|
||||||
authorizedSender: string,
|
authorizedSender: string,
|
||||||
assetData_?: string,
|
assetData_?: string,
|
||||||
): Promise<string> {
|
): string {
|
||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
const assetData =
|
const assetData =
|
||||||
assetData_ === undefined
|
assetData_ === undefined
|
||||||
? await this._devUtils
|
? assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(contractAddress, tokensToTransfer, valuesToTransfer, receiverCallbackData)
|
contractAddress,
|
||||||
.callAsync()
|
tokensToTransfer,
|
||||||
|
valuesToTransfer,
|
||||||
|
receiverCallbackData,
|
||||||
|
)
|
||||||
: assetData_;
|
: assetData_;
|
||||||
const data = this._assetProxyInterface
|
const data = this._assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||||
.transferFrom(assetData, from, to, valueMultiplier)
|
assetData,
|
||||||
.getABIEncodedTransactionData();
|
from,
|
||||||
|
to,
|
||||||
|
valueMultiplier,
|
||||||
|
);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -167,13 +169,19 @@ export class ERC1155ProxyWrapper {
|
|||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
const assetData =
|
const assetData =
|
||||||
assetData_ === undefined
|
assetData_ === undefined
|
||||||
? await this._devUtils
|
? assetDataUtils.encodeERC1155AssetData(
|
||||||
.encodeERC1155AssetData(contractAddress, tokensToTransfer, valuesToTransfer, receiverCallbackData)
|
contractAddress,
|
||||||
.callAsync()
|
tokensToTransfer,
|
||||||
|
valuesToTransfer,
|
||||||
|
receiverCallbackData,
|
||||||
|
)
|
||||||
: assetData_;
|
: assetData_;
|
||||||
const data = this._assetProxyInterface
|
const data = this._assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||||
.transferFrom(assetData, from, to, valueMultiplier)
|
assetData,
|
||||||
.getABIEncodedTransactionData();
|
from,
|
||||||
|
to,
|
||||||
|
valueMultiplier,
|
||||||
|
);
|
||||||
const txHash = await this._web3Wrapper.sendTransactionAsync({
|
const txHash = await this._web3Wrapper.sendTransactionAsync({
|
||||||
to: (this._proxyContract as ERC1155ProxyContract).address,
|
to: (this._proxyContract as ERC1155ProxyContract).address,
|
||||||
data,
|
data,
|
||||||
@@ -328,22 +336,6 @@ export class ERC1155ProxyWrapper {
|
|||||||
};
|
};
|
||||||
return holdingsByOwner;
|
return holdingsByOwner;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @dev Set the approval for the proxy on behalf of `userAddress` .
|
|
||||||
* @param userAddress owner of ERC1155 tokens.
|
|
||||||
* @param contractAddress address of ERC1155 contract.
|
|
||||||
* @param isApproved Whether to approve the proxy for all or not.
|
|
||||||
*/
|
|
||||||
public async setProxyAllowanceForAllAsync(
|
|
||||||
userAddress: string,
|
|
||||||
contractAddress: string,
|
|
||||||
isApproved: boolean,
|
|
||||||
): Promise<void> {
|
|
||||||
this._validateProxyContractExistsOrThrow();
|
|
||||||
const tokenWrapper = this.getContractWrapper(contractAddress);
|
|
||||||
const operator = (this._proxyContract as ERC1155ProxyContract).address;
|
|
||||||
await tokenWrapper.setApprovalForAllAsync(userAddress, operator, isApproved);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @dev Checks if proxy is approved to transfer tokens on behalf of `userAddress`.
|
* @dev Checks if proxy is approved to transfer tokens on behalf of `userAddress`.
|
||||||
* @param userAddress owner of ERC1155 tokens.
|
* @param userAddress owner of ERC1155 tokens.
|
||||||
@@ -354,7 +346,7 @@ export class ERC1155ProxyWrapper {
|
|||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
const tokenContract = this._getContractFromAddress(contractAddress);
|
const tokenContract = this._getContractFromAddress(contractAddress);
|
||||||
const operator = (this._proxyContract as ERC1155ProxyContract).address;
|
const operator = (this._proxyContract as ERC1155ProxyContract).address;
|
||||||
const didApproveAll = await tokenContract.isApprovedForAll(userAddress, operator).callAsync();
|
const didApproveAll = await tokenContract.isApprovedForAll.callAsync(userAddress, operator);
|
||||||
return didApproveAll;
|
return didApproveAll;
|
||||||
}
|
}
|
||||||
public getFungibleTokenIds(): BigNumber[] {
|
public getFungibleTokenIds(): BigNumber[] {
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
import { DevUtilsContract } from '@0x/contracts-dev-utils';
|
|
||||||
import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20';
|
import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20';
|
||||||
import { constants, ERC20BalancesByOwner, txDefaults } from '@0x/contracts-test-utils';
|
import { constants, ERC20BalancesByOwner, txDefaults } from '@0x/contracts-test-utils';
|
||||||
|
import { assetDataUtils } from '@0x/order-utils';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { ZeroExProvider } from 'ethereum-types';
|
import { ZeroExProvider } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts, ERC20ProxyContract } from '../../src';
|
||||||
|
|
||||||
import { ERC20ProxyContract } from './wrappers';
|
|
||||||
|
|
||||||
export class ERC20Wrapper {
|
export class ERC20Wrapper {
|
||||||
private readonly _tokenOwnerAddresses: string[];
|
private readonly _tokenOwnerAddresses: string[];
|
||||||
private readonly _contractOwnerAddress: string;
|
private readonly _contractOwnerAddress: string;
|
||||||
private readonly _provider: ZeroExProvider;
|
private readonly _provider: ZeroExProvider;
|
||||||
private readonly _dummyTokenContracts: DummyERC20TokenContract[];
|
private readonly _dummyTokenContracts: DummyERC20TokenContract[];
|
||||||
private readonly _devUtils: DevUtilsContract;
|
|
||||||
private _proxyContract?: ERC20ProxyContract;
|
private _proxyContract?: ERC20ProxyContract;
|
||||||
private _proxyIdIfExists?: string;
|
private _proxyIdIfExists?: string;
|
||||||
/**
|
/**
|
||||||
@@ -29,7 +26,6 @@ export class ERC20Wrapper {
|
|||||||
this._provider = provider;
|
this._provider = provider;
|
||||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||||
this._contractOwnerAddress = contractOwnerAddress;
|
this._contractOwnerAddress = contractOwnerAddress;
|
||||||
this._devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
|
|
||||||
}
|
}
|
||||||
public async deployDummyTokensAsync(
|
public async deployDummyTokensAsync(
|
||||||
numberToDeploy: number,
|
numberToDeploy: number,
|
||||||
@@ -58,7 +54,7 @@ export class ERC20Wrapper {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
this._proxyIdIfExists = await this._proxyContract.getProxyId().callAsync();
|
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
|
||||||
return this._proxyContract;
|
return this._proxyContract;
|
||||||
}
|
}
|
||||||
public getProxyId(): string {
|
public getProxyId(): string {
|
||||||
@@ -70,39 +66,50 @@ export class ERC20Wrapper {
|
|||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
for (const dummyTokenContract of this._dummyTokenContracts) {
|
for (const dummyTokenContract of this._dummyTokenContracts) {
|
||||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||||
await dummyTokenContract
|
await dummyTokenContract.setBalance.awaitTransactionSuccessAsync(
|
||||||
.setBalance(tokenOwnerAddress, constants.INITIAL_ERC20_BALANCE)
|
tokenOwnerAddress,
|
||||||
.awaitTransactionSuccessAsync({ from: this._contractOwnerAddress });
|
constants.INITIAL_ERC20_BALANCE,
|
||||||
await dummyTokenContract
|
{ from: this._contractOwnerAddress },
|
||||||
.approve((this._proxyContract as ERC20ProxyContract).address, constants.INITIAL_ERC20_ALLOWANCE)
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
.awaitTransactionSuccessAsync({ from: tokenOwnerAddress });
|
);
|
||||||
|
await dummyTokenContract.approve.awaitTransactionSuccessAsync(
|
||||||
|
(this._proxyContract as ERC20ProxyContract).address,
|
||||||
|
constants.INITIAL_ERC20_ALLOWANCE,
|
||||||
|
{ from: tokenOwnerAddress },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||||
const tokenContract = await this._getTokenContractFromAssetDataAsync(assetData);
|
const tokenContract = this._getTokenContractFromAssetData(assetData);
|
||||||
const balance = new BigNumber(await tokenContract.balanceOf(userAddress).callAsync());
|
const balance = new BigNumber(await tokenContract.balanceOf.callAsync(userAddress));
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
public async setBalanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise<void> {
|
public async setBalanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise<void> {
|
||||||
const tokenContract = await this._getTokenContractFromAssetDataAsync(assetData);
|
const tokenContract = this._getTokenContractFromAssetData(assetData);
|
||||||
await tokenContract
|
await tokenContract.setBalance.awaitTransactionSuccessAsync(
|
||||||
.setBalance(userAddress, amount)
|
userAddress,
|
||||||
.awaitTransactionSuccessAsync(
|
amount,
|
||||||
{ from: this._contractOwnerAddress },
|
{ from: this._contractOwnerAddress },
|
||||||
{ pollingIntervalMs: constants.AWAIT_TRANSACTION_MINED_MS },
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||||
const tokenContract = await this._getTokenContractFromAssetDataAsync(assetData);
|
const tokenContract = this._getTokenContractFromAssetData(assetData);
|
||||||
const proxyAddress = (this._proxyContract as ERC20ProxyContract).address;
|
const proxyAddress = (this._proxyContract as ERC20ProxyContract).address;
|
||||||
const allowance = new BigNumber(await tokenContract.allowance(userAddress, proxyAddress).callAsync());
|
const allowance = new BigNumber(await tokenContract.allowance.callAsync(userAddress, proxyAddress));
|
||||||
return allowance;
|
return allowance;
|
||||||
}
|
}
|
||||||
public async setAllowanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise<void> {
|
public async setAllowanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise<void> {
|
||||||
const tokenContract = await this._getTokenContractFromAssetDataAsync(assetData);
|
const tokenContract = this._getTokenContractFromAssetData(assetData);
|
||||||
const proxyAddress = (this._proxyContract as ERC20ProxyContract).address;
|
const proxyAddress = (this._proxyContract as ERC20ProxyContract).address;
|
||||||
await tokenContract.approve(proxyAddress, amount).awaitTransactionSuccessAsync({ from: userAddress });
|
await tokenContract.approve.awaitTransactionSuccessAsync(
|
||||||
|
proxyAddress,
|
||||||
|
amount,
|
||||||
|
{ from: userAddress },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
|
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
|
||||||
this._validateDummyTokenContractsExistOrThrow();
|
this._validateDummyTokenContractsExistOrThrow();
|
||||||
@@ -111,7 +118,7 @@ export class ERC20Wrapper {
|
|||||||
const balanceInfo: Array<{ tokenOwnerAddress: string; tokenAddress: string }> = [];
|
const balanceInfo: Array<{ tokenOwnerAddress: string; tokenAddress: string }> = [];
|
||||||
for (const dummyTokenContract of this._dummyTokenContracts) {
|
for (const dummyTokenContract of this._dummyTokenContracts) {
|
||||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||||
balances.push(await dummyTokenContract.balanceOf(tokenOwnerAddress).callAsync());
|
balances.push(await dummyTokenContract.balanceOf.callAsync(tokenOwnerAddress));
|
||||||
balanceInfo.push({
|
balanceInfo.push({
|
||||||
tokenOwnerAddress,
|
tokenOwnerAddress,
|
||||||
tokenAddress: dummyTokenContract.address,
|
tokenAddress: dummyTokenContract.address,
|
||||||
@@ -144,8 +151,9 @@ export class ERC20Wrapper {
|
|||||||
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
|
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
|
||||||
return tokenAddresses;
|
return tokenAddresses;
|
||||||
}
|
}
|
||||||
private async _getTokenContractFromAssetDataAsync(assetData: string): Promise<DummyERC20TokenContract> {
|
private _getTokenContractFromAssetData(assetData: string): DummyERC20TokenContract {
|
||||||
const [proxyId, tokenAddress] = await this._devUtils.decodeERC20AssetData(assetData).callAsync(); // tslint:disable-line:no-unused-variable
|
const erc20ProxyData = assetDataUtils.decodeERC20AssetData(assetData);
|
||||||
|
const tokenAddress = erc20ProxyData.tokenAddress;
|
||||||
const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === tokenAddress);
|
const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === tokenAddress);
|
||||||
if (tokenContractIfExists === undefined) {
|
if (tokenContractIfExists === undefined) {
|
||||||
throw new Error(`Token: ${tokenAddress} was not deployed through ERC20Wrapper`);
|
throw new Error(`Token: ${tokenAddress} was not deployed through ERC20Wrapper`);
|
||||||
@@ -5,9 +5,7 @@ import { BigNumber } from '@0x/utils';
|
|||||||
import { ZeroExProvider } from 'ethereum-types';
|
import { ZeroExProvider } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts, ERC721ProxyContract } from '../../src';
|
||||||
|
|
||||||
import { ERC721ProxyContract } from './wrappers';
|
|
||||||
|
|
||||||
export class ERC721Wrapper {
|
export class ERC721Wrapper {
|
||||||
private readonly _tokenOwnerAddresses: string[];
|
private readonly _tokenOwnerAddresses: string[];
|
||||||
@@ -46,7 +44,7 @@ export class ERC721Wrapper {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
artifacts,
|
artifacts,
|
||||||
);
|
);
|
||||||
this._proxyIdIfExists = await this._proxyContract.getProxyId().callAsync();
|
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
|
||||||
return this._proxyContract;
|
return this._proxyContract;
|
||||||
}
|
}
|
||||||
public getProxyId(): string {
|
public getProxyId(): string {
|
||||||
@@ -73,14 +71,14 @@ export class ERC721Wrapper {
|
|||||||
}
|
}
|
||||||
this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address].push(tokenId);
|
this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address].push(tokenId);
|
||||||
|
|
||||||
await this.approveProxyForAllAsync(dummyTokenContract.address, tokenOwnerAddress, true);
|
await this.approveProxyAsync(dummyTokenContract.address, tokenId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async doesTokenExistAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
public async doesTokenExistAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const owner = await tokenContract.ownerOf(tokenId).callAsync();
|
const owner = await tokenContract.ownerOf.callAsync(tokenId);
|
||||||
const doesExist = owner !== constants.NULL_ADDRESS;
|
const doesExist = owner !== constants.NULL_ADDRESS;
|
||||||
return doesExist;
|
return doesExist;
|
||||||
}
|
}
|
||||||
@@ -88,21 +86,26 @@ export class ERC721Wrapper {
|
|||||||
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
||||||
await this.approveAsync(proxyAddress, tokenAddress, tokenId);
|
await this.approveAsync(proxyAddress, tokenAddress, tokenId);
|
||||||
}
|
}
|
||||||
public async approveProxyForAllAsync(
|
public async approveProxyForAllAsync(tokenAddress: string, tokenId: BigNumber, isApproved: boolean): Promise<void> {
|
||||||
tokenAddress: string,
|
|
||||||
ownerAddress: string,
|
|
||||||
isApproved: boolean,
|
|
||||||
): Promise<void> {
|
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
|
const tokenOwner = await this.ownerOfAsync(tokenAddress, tokenId);
|
||||||
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
||||||
await tokenContract.setApprovalForAll(proxyAddress, isApproved).awaitTransactionSuccessAsync({
|
await tokenContract.setApprovalForAll.awaitTransactionSuccessAsync(
|
||||||
from: ownerAddress,
|
proxyAddress,
|
||||||
});
|
isApproved,
|
||||||
|
{ from: tokenOwner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async approveAsync(to: string, tokenAddress: string, tokenId: BigNumber): Promise<void> {
|
public async approveAsync(to: string, tokenAddress: string, tokenId: BigNumber): Promise<void> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const tokenOwner = await this.ownerOfAsync(tokenAddress, tokenId);
|
const tokenOwner = await this.ownerOfAsync(tokenAddress, tokenId);
|
||||||
await tokenContract.approve(to, tokenId).awaitTransactionSuccessAsync({ from: tokenOwner });
|
await tokenContract.approve.awaitTransactionSuccessAsync(
|
||||||
|
to,
|
||||||
|
tokenId,
|
||||||
|
{ from: tokenOwner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async transferFromAsync(
|
public async transferFromAsync(
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
@@ -111,28 +114,40 @@ export class ERC721Wrapper {
|
|||||||
userAddress: string,
|
userAddress: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
await tokenContract.transferFrom(currentOwner, userAddress, tokenId).awaitTransactionSuccessAsync({
|
await tokenContract.transferFrom.awaitTransactionSuccessAsync(
|
||||||
from: currentOwner,
|
currentOwner,
|
||||||
});
|
userAddress,
|
||||||
|
tokenId,
|
||||||
|
{ from: currentOwner },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async mintAsync(tokenAddress: string, tokenId: BigNumber, userAddress: string): Promise<void> {
|
public async mintAsync(tokenAddress: string, tokenId: BigNumber, userAddress: string): Promise<void> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
await tokenContract.mint(userAddress, tokenId).awaitTransactionSuccessAsync({
|
await tokenContract.mint.awaitTransactionSuccessAsync(
|
||||||
from: this._contractOwnerAddress,
|
userAddress,
|
||||||
});
|
tokenId,
|
||||||
|
{ from: this._contractOwnerAddress },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async burnAsync(tokenAddress: string, tokenId: BigNumber, owner: string): Promise<void> {
|
public async burnAsync(tokenAddress: string, tokenId: BigNumber, owner: string): Promise<void> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
await tokenContract.burn(owner, tokenId).awaitTransactionSuccessAsync({ from: this._contractOwnerAddress });
|
await tokenContract.burn.awaitTransactionSuccessAsync(
|
||||||
|
owner,
|
||||||
|
tokenId,
|
||||||
|
{ from: this._contractOwnerAddress },
|
||||||
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
public async ownerOfAsync(tokenAddress: string, tokenId: BigNumber): Promise<string> {
|
public async ownerOfAsync(tokenAddress: string, tokenId: BigNumber): Promise<string> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const owner = await tokenContract.ownerOf(tokenId).callAsync();
|
const owner = await tokenContract.ownerOf.callAsync(tokenId);
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
public async isOwnerAsync(userAddress: string, tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
public async isOwnerAsync(userAddress: string, tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const tokenOwner = await tokenContract.ownerOf(tokenId).callAsync();
|
const tokenOwner = await tokenContract.ownerOf.callAsync(tokenId);
|
||||||
const isOwner = tokenOwner === userAddress;
|
const isOwner = tokenOwner === userAddress;
|
||||||
return isOwner;
|
return isOwner;
|
||||||
}
|
}
|
||||||
@@ -140,13 +155,13 @@ export class ERC721Wrapper {
|
|||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const operator = (this._proxyContract as ERC721ProxyContract).address;
|
const operator = (this._proxyContract as ERC721ProxyContract).address;
|
||||||
const didApproveAll = await tokenContract.isApprovedForAll(userAddress, operator).callAsync();
|
const didApproveAll = await tokenContract.isApprovedForAll.callAsync(userAddress, operator);
|
||||||
return didApproveAll;
|
return didApproveAll;
|
||||||
}
|
}
|
||||||
public async isProxyApprovedAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
public async isProxyApprovedAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
||||||
this._validateProxyContractExistsOrThrow();
|
this._validateProxyContractExistsOrThrow();
|
||||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||||
const approvedAddress = await tokenContract.getApproved(tokenId).callAsync();
|
const approvedAddress = await tokenContract.getApproved.callAsync(tokenId);
|
||||||
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
const proxyAddress = (this._proxyContract as ERC721ProxyContract).address;
|
||||||
const isProxyAnApprovedOperator = approvedAddress === proxyAddress;
|
const isProxyAnApprovedOperator = approvedAddress === proxyAddress;
|
||||||
return isProxyAnApprovedOperator;
|
return isProxyAnApprovedOperator;
|
||||||
@@ -163,7 +178,7 @@ export class ERC721Wrapper {
|
|||||||
dummyTokenContract.address
|
dummyTokenContract.address
|
||||||
];
|
];
|
||||||
for (const tokenId of initialTokenOwnerIds) {
|
for (const tokenId of initialTokenOwnerIds) {
|
||||||
tokenOwnerAddresses.push(await dummyTokenContract.ownerOf(tokenId).callAsync());
|
tokenOwnerAddresses.push(await dummyTokenContract.ownerOf.callAsync(tokenId));
|
||||||
tokenInfo.push({
|
tokenInfo.push({
|
||||||
tokenId,
|
tokenId,
|
||||||
tokenAddress: dummyTokenContract.address,
|
tokenAddress: dummyTokenContract.address,
|
||||||
3
contracts/asset-proxy/test/utils/index.ts
Normal file
3
contracts/asset-proxy/test/utils/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export * from './erc20_wrapper';
|
||||||
|
export * from './erc721_wrapper';
|
||||||
|
export * from './erc1155_proxy_wrapper';
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
export * from '../test/generated-wrappers/chai_bridge';
|
|
||||||
export * from '../test/generated-wrappers/dydx_bridge';
|
|
||||||
export * from '../test/generated-wrappers/erc1155_proxy';
|
|
||||||
export * from '../test/generated-wrappers/erc20_bridge_proxy';
|
|
||||||
export * from '../test/generated-wrappers/erc20_proxy';
|
|
||||||
export * from '../test/generated-wrappers/erc721_proxy';
|
|
||||||
export * from '../test/generated-wrappers/eth2_dai_bridge';
|
|
||||||
export * from '../test/generated-wrappers/i_asset_data';
|
|
||||||
export * from '../test/generated-wrappers/i_asset_proxy';
|
|
||||||
export * from '../test/generated-wrappers/i_asset_proxy_dispatcher';
|
|
||||||
export * from '../test/generated-wrappers/i_authorizable';
|
|
||||||
export * from '../test/generated-wrappers/i_chai';
|
|
||||||
export * from '../test/generated-wrappers/i_dydx';
|
|
||||||
export * from '../test/generated-wrappers/i_dydx_bridge';
|
|
||||||
export * from '../test/generated-wrappers/i_erc20_bridge';
|
|
||||||
export * from '../test/generated-wrappers/i_eth2_dai';
|
|
||||||
export * from '../test/generated-wrappers/i_kyber_network_proxy';
|
|
||||||
export * from '../test/generated-wrappers/i_uniswap_exchange';
|
|
||||||
export * from '../test/generated-wrappers/i_uniswap_exchange_factory';
|
|
||||||
export * from '../test/generated-wrappers/kyber_bridge';
|
|
||||||
export * from '../test/generated-wrappers/mixin_asset_proxy_dispatcher';
|
|
||||||
export * from '../test/generated-wrappers/mixin_authorizable';
|
|
||||||
export * from '../test/generated-wrappers/multi_asset_proxy';
|
|
||||||
export * from '../test/generated-wrappers/ownable';
|
|
||||||
export * from '../test/generated-wrappers/static_call_proxy';
|
|
||||||
export * from '../test/generated-wrappers/test_chai_bridge';
|
|
||||||
export * from '../test/generated-wrappers/test_dydx_bridge';
|
|
||||||
export * from '../test/generated-wrappers/test_erc20_bridge';
|
|
||||||
export * from '../test/generated-wrappers/test_eth2_dai_bridge';
|
|
||||||
export * from '../test/generated-wrappers/test_kyber_bridge';
|
|
||||||
export * from '../test/generated-wrappers/test_static_call_target';
|
|
||||||
export * from '../test/generated-wrappers/test_uniswap_bridge';
|
|
||||||
export * from '../test/generated-wrappers/uniswap_bridge';
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/**
|
|
||||||
* Use this file to configure your truffle project. It's seeded with some
|
|
||||||
* common settings for different networks and features like migrations,
|
|
||||||
* compilation and testing. Uncomment the ones you need or modify
|
|
||||||
* them to suit your project as necessary.
|
|
||||||
*
|
|
||||||
* More information about configuration can be found at:
|
|
||||||
*
|
|
||||||
* truffleframework.com/docs/advanced/configuration
|
|
||||||
*
|
|
||||||
* To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider)
|
|
||||||
* to sign your transactions before they're sent to a remote public node. Infura accounts
|
|
||||||
* are available for free at: infura.io/register.
|
|
||||||
*
|
|
||||||
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
|
|
||||||
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
|
|
||||||
* phrase from a file you've .gitignored so it doesn't accidentally become public.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// const HDWalletProvider = require('truffle-hdwallet-provider');
|
|
||||||
// const infuraKey = "fj4jll3k.....";
|
|
||||||
//
|
|
||||||
// const fs = require('fs');
|
|
||||||
// const mnemonic = fs.readFileSync(".secret").toString().trim();
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* Networks define how you connect to your ethereum client and let you set the
|
|
||||||
* defaults web3 uses to send transactions. If you don't specify one truffle
|
|
||||||
* will spin up a development blockchain for you on port 9545 when you
|
|
||||||
* run `develop` or `test`. You can ask a truffle command to use a specific
|
|
||||||
* network from the command line, e.g
|
|
||||||
*
|
|
||||||
* $ truffle test --network <network-name>
|
|
||||||
*/
|
|
||||||
|
|
||||||
networks: {
|
|
||||||
// Useful for testing. The `development` name is special - truffle uses it by default
|
|
||||||
// if it's defined here and no other network is specified at the command line.
|
|
||||||
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
|
|
||||||
// tab if you use this network and you must also set the `host`, `port` and `network_id`
|
|
||||||
// options below to some value.
|
|
||||||
//
|
|
||||||
// development: {
|
|
||||||
// host: "127.0.0.1", // Localhost (default: none)
|
|
||||||
// port: 8545, // Standard Ethereum port (default: none)
|
|
||||||
// network_id: "*", // Any network (default: none)
|
|
||||||
// },
|
|
||||||
// Another network with more advanced options...
|
|
||||||
// advanced: {
|
|
||||||
// port: 8777, // Custom port
|
|
||||||
// network_id: 1342, // Custom network
|
|
||||||
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
|
|
||||||
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
|
|
||||||
// from: <address>, // Account to send txs from (default: accounts[0])
|
|
||||||
// websockets: true // Enable EventEmitter interface for web3 (default: false)
|
|
||||||
// },
|
|
||||||
// Useful for deploying to a public network.
|
|
||||||
// NB: It's important to wrap the provider as a function.
|
|
||||||
// ropsten: {
|
|
||||||
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
|
|
||||||
// network_id: 3, // Ropsten's id
|
|
||||||
// gas: 5500000, // Ropsten has a lower block limit than mainnet
|
|
||||||
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
|
|
||||||
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
|
|
||||||
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
|
|
||||||
// },
|
|
||||||
// Useful for private networks
|
|
||||||
// private: {
|
|
||||||
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
|
|
||||||
// network_id: 2111, // This network is yours, in the cloud.
|
|
||||||
// production: true // Treats this network as if it was a public net. (default: false)
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
|
|
||||||
// Set default mocha options here, use special reporters etc.
|
|
||||||
mocha: {
|
|
||||||
// timeout: 100000
|
|
||||||
},
|
|
||||||
|
|
||||||
// Configure your compilers
|
|
||||||
compilers: {
|
|
||||||
solc: {
|
|
||||||
version: '0.5.9',
|
|
||||||
settings: {
|
|
||||||
evmVersion: 'istanbul',
|
|
||||||
optimizer: {
|
|
||||||
enabled: true,
|
|
||||||
runs: 1000000,
|
|
||||||
details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -3,72 +3,16 @@
|
|||||||
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
|
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
|
||||||
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
||||||
"files": [
|
"files": [
|
||||||
"generated-artifacts/ChaiBridge.json",
|
|
||||||
"generated-artifacts/DydxBridge.json",
|
|
||||||
"generated-artifacts/ERC1155Proxy.json",
|
"generated-artifacts/ERC1155Proxy.json",
|
||||||
"generated-artifacts/ERC20BridgeProxy.json",
|
|
||||||
"generated-artifacts/ERC20Proxy.json",
|
"generated-artifacts/ERC20Proxy.json",
|
||||||
"generated-artifacts/ERC721Proxy.json",
|
"generated-artifacts/ERC721Proxy.json",
|
||||||
"generated-artifacts/Eth2DaiBridge.json",
|
|
||||||
"generated-artifacts/IAssetData.json",
|
"generated-artifacts/IAssetData.json",
|
||||||
"generated-artifacts/IAssetProxy.json",
|
"generated-artifacts/IAssetProxy.json",
|
||||||
"generated-artifacts/IAssetProxyDispatcher.json",
|
|
||||||
"generated-artifacts/IAuthorizable.json",
|
"generated-artifacts/IAuthorizable.json",
|
||||||
"generated-artifacts/IChai.json",
|
|
||||||
"generated-artifacts/IDydx.json",
|
|
||||||
"generated-artifacts/IDydxBridge.json",
|
|
||||||
"generated-artifacts/IERC20Bridge.json",
|
|
||||||
"generated-artifacts/IEth2Dai.json",
|
|
||||||
"generated-artifacts/IKyberNetworkProxy.json",
|
|
||||||
"generated-artifacts/IUniswapExchange.json",
|
|
||||||
"generated-artifacts/IUniswapExchangeFactory.json",
|
|
||||||
"generated-artifacts/KyberBridge.json",
|
|
||||||
"generated-artifacts/MixinAssetProxyDispatcher.json",
|
|
||||||
"generated-artifacts/MixinAuthorizable.json",
|
"generated-artifacts/MixinAuthorizable.json",
|
||||||
"generated-artifacts/MultiAssetProxy.json",
|
"generated-artifacts/MultiAssetProxy.json",
|
||||||
"generated-artifacts/Ownable.json",
|
|
||||||
"generated-artifacts/StaticCallProxy.json",
|
"generated-artifacts/StaticCallProxy.json",
|
||||||
"generated-artifacts/TestChaiBridge.json",
|
"generated-artifacts/TestStaticCallTarget.json"
|
||||||
"generated-artifacts/TestDydxBridge.json",
|
|
||||||
"generated-artifacts/TestERC20Bridge.json",
|
|
||||||
"generated-artifacts/TestEth2DaiBridge.json",
|
|
||||||
"generated-artifacts/TestKyberBridge.json",
|
|
||||||
"generated-artifacts/TestStaticCallTarget.json",
|
|
||||||
"generated-artifacts/TestUniswapBridge.json",
|
|
||||||
"generated-artifacts/UniswapBridge.json",
|
|
||||||
"test/generated-artifacts/ChaiBridge.json",
|
|
||||||
"test/generated-artifacts/DydxBridge.json",
|
|
||||||
"test/generated-artifacts/ERC1155Proxy.json",
|
|
||||||
"test/generated-artifacts/ERC20BridgeProxy.json",
|
|
||||||
"test/generated-artifacts/ERC20Proxy.json",
|
|
||||||
"test/generated-artifacts/ERC721Proxy.json",
|
|
||||||
"test/generated-artifacts/Eth2DaiBridge.json",
|
|
||||||
"test/generated-artifacts/IAssetData.json",
|
|
||||||
"test/generated-artifacts/IAssetProxy.json",
|
|
||||||
"test/generated-artifacts/IAssetProxyDispatcher.json",
|
|
||||||
"test/generated-artifacts/IAuthorizable.json",
|
|
||||||
"test/generated-artifacts/IChai.json",
|
|
||||||
"test/generated-artifacts/IDydx.json",
|
|
||||||
"test/generated-artifacts/IDydxBridge.json",
|
|
||||||
"test/generated-artifacts/IERC20Bridge.json",
|
|
||||||
"test/generated-artifacts/IEth2Dai.json",
|
|
||||||
"test/generated-artifacts/IKyberNetworkProxy.json",
|
|
||||||
"test/generated-artifacts/IUniswapExchange.json",
|
|
||||||
"test/generated-artifacts/IUniswapExchangeFactory.json",
|
|
||||||
"test/generated-artifacts/KyberBridge.json",
|
|
||||||
"test/generated-artifacts/MixinAssetProxyDispatcher.json",
|
|
||||||
"test/generated-artifacts/MixinAuthorizable.json",
|
|
||||||
"test/generated-artifacts/MultiAssetProxy.json",
|
|
||||||
"test/generated-artifacts/Ownable.json",
|
|
||||||
"test/generated-artifacts/StaticCallProxy.json",
|
|
||||||
"test/generated-artifacts/TestChaiBridge.json",
|
|
||||||
"test/generated-artifacts/TestDydxBridge.json",
|
|
||||||
"test/generated-artifacts/TestERC20Bridge.json",
|
|
||||||
"test/generated-artifacts/TestEth2DaiBridge.json",
|
|
||||||
"test/generated-artifacts/TestKyberBridge.json",
|
|
||||||
"test/generated-artifacts/TestStaticCallTarget.json",
|
|
||||||
"test/generated-artifacts/TestUniswapBridge.json",
|
|
||||||
"test/generated-artifacts/UniswapBridge.json"
|
|
||||||
],
|
],
|
||||||
"exclude": ["./deploy/solc/solc_bin"]
|
"exclude": ["./deploy/solc/solc_bin"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# Blacklist all files
|
|
||||||
.*
|
|
||||||
*
|
|
||||||
# Whitelist lib
|
|
||||||
!lib/**/*
|
|
||||||
# Whitelist Solidity contracts
|
|
||||||
!contracts/src/**/*
|
|
||||||
# Blacklist tests in lib
|
|
||||||
/lib/test/*
|
|
||||||
# Package specific ignore
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# solhint can't parse `abi.decode` syntax.
|
|
||||||
contracts/src/MixinCoordinatorApprovalVerifier.sol
|
|
||||||
@@ -1,189 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"timestamp": 1579682890,
|
|
||||||
"version": "3.0.4",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"timestamp": 1578272714,
|
|
||||||
"version": "3.0.3",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"timestamp": 1576540892,
|
|
||||||
"version": "3.0.2",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"timestamp": 1575931811,
|
|
||||||
"version": "3.0.1",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "3.0.0",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
|
||||||
"pr": 2330
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Introduced new export CoordinatorRevertErrors",
|
|
||||||
"pr": 2321
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Added dependency on @0x/contracts-utils",
|
|
||||||
"pr": 2321
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add chainId to domain separator",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Inherit Exchange domain constants from `exchange-libs` to reduce code duplication",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update domain separator",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Refactor contract to use new ITransactions interface",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add verifyingContractIfExists arg to LibEIP712CoordinatorDomain constructor",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove LibZeroExTransaction contract",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update tests for arbitrary fee tokens (ZEIP-28).",
|
|
||||||
"pr": 1819
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update for new `marketXOrders` consolidation.",
|
|
||||||
"pr": 2042
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Use built in selectors instead of hard coded constants",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Compile and export all contracts, artifacts, and wrappers by default",
|
|
||||||
"pr": 2055
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1575296764
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.1.0-beta.4",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1575290197
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.1.0-beta.3",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1574238768
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.1.0-beta.2",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
|
||||||
"pr": 2330
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Introduced new export CoordinatorRevertErrors",
|
|
||||||
"pr": 2321
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Added dependency on @0x/contracts-utils",
|
|
||||||
"pr": 2321
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1574030254
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.1.0-beta.1",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Dependencies updated"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1573159180
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"version": "2.1.0-beta.0",
|
|
||||||
"changes": [
|
|
||||||
{
|
|
||||||
"note": "Add chainId to domain separator",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Inherit Exchange domain constants from `exchange-libs` to reduce code duplication",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update domain separator",
|
|
||||||
"pr": 1742
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Refactor contract to use new ITransactions interface",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Add verifyingContractIfExists arg to LibEIP712CoordinatorDomain constructor",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Remove LibZeroExTransaction contract",
|
|
||||||
"pr": 1753
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update tests for arbitrary fee tokens (ZEIP-28).",
|
|
||||||
"pr": 1819
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Update for new `marketXOrders` consolidation.",
|
|
||||||
"pr": 2042
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Use built in selectors instead of hard coded constants",
|
|
||||||
"pr": 2055
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"note": "Compile and export all contracts, artifacts, and wrappers by default",
|
|
||||||
"pr": 2055
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"timestamp": 1570135330
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"timestamp": 1568744790,
|
"timestamp": 1568744790,
|
||||||
"version": "2.0.13",
|
"version": "2.0.13",
|
||||||
|
|||||||
@@ -5,69 +5,6 @@ Edit the package's CHANGELOG.json file only.
|
|||||||
|
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
|
|
||||||
## v3.0.4 - _January 22, 2020_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.3 - _January 6, 2020_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.2 - _December 17, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.1 - _December 9, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v3.0.0 - _December 2, 2019_
|
|
||||||
|
|
||||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
|
||||||
* Introduced new export CoordinatorRevertErrors (#2321)
|
|
||||||
* Added dependency on @0x/contracts-utils (#2321)
|
|
||||||
* Add chainId to domain separator (#1742)
|
|
||||||
* Inherit Exchange domain constants from `exchange-libs` to reduce code duplication (#1742)
|
|
||||||
* Update domain separator (#1742)
|
|
||||||
* Refactor contract to use new ITransactions interface (#1753)
|
|
||||||
* Add verifyingContractIfExists arg to LibEIP712CoordinatorDomain constructor (#1753)
|
|
||||||
* Remove LibZeroExTransaction contract (#1753)
|
|
||||||
* Update tests for arbitrary fee tokens (ZEIP-28). (#1819)
|
|
||||||
* Update for new `marketXOrders` consolidation. (#2042)
|
|
||||||
* Use built in selectors instead of hard coded constants (#2055)
|
|
||||||
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
|
|
||||||
|
|
||||||
## v2.1.0-beta.4 - _December 2, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v2.1.0-beta.3 - _November 20, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v2.1.0-beta.2 - _November 17, 2019_
|
|
||||||
|
|
||||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
|
||||||
* Introduced new export CoordinatorRevertErrors (#2321)
|
|
||||||
* Added dependency on @0x/contracts-utils (#2321)
|
|
||||||
|
|
||||||
## v2.1.0-beta.1 - _November 7, 2019_
|
|
||||||
|
|
||||||
* Dependencies updated
|
|
||||||
|
|
||||||
## v2.1.0-beta.0 - _October 3, 2019_
|
|
||||||
|
|
||||||
* Add chainId to domain separator (#1742)
|
|
||||||
* Inherit Exchange domain constants from `exchange-libs` to reduce code duplication (#1742)
|
|
||||||
* Update domain separator (#1742)
|
|
||||||
* Refactor contract to use new ITransactions interface (#1753)
|
|
||||||
* Add verifyingContractIfExists arg to LibEIP712CoordinatorDomain constructor (#1753)
|
|
||||||
* Remove LibZeroExTransaction contract (#1753)
|
|
||||||
* Update tests for arbitrary fee tokens (ZEIP-28). (#1819)
|
|
||||||
* Update for new `marketXOrders` consolidation. (#2042)
|
|
||||||
* Use built in selectors instead of hard coded constants (#2055)
|
|
||||||
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
|
|
||||||
|
|
||||||
## v2.0.13 - _September 17, 2019_
|
## v2.0.13 - _September 17, 2019_
|
||||||
|
|
||||||
* Dependencies updated
|
* Dependencies updated
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"artifactsDir": "./test/generated-artifacts",
|
"artifactsDir": "./generated-artifacts",
|
||||||
"contractsDir": "./contracts",
|
"contractsDir": "./contracts",
|
||||||
"useDockerisedSolc": false,
|
"useDockerisedSolc": false,
|
||||||
"compilerSettings": {
|
"compilerSettings": {
|
||||||
"evmVersion": "istanbul",
|
"evmVersion": "constantinople",
|
||||||
"optimizer": {
|
"optimizer": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"runs": 1000000,
|
"runs": 1000000,
|
||||||
@@ -21,5 +21,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"contracts": ["src/Coordinator.sol", "src/registry/CoordinatorRegistry.sol"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,12 +16,10 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
|
||||||
import "./libs/LibConstants.sol";
|
import "./libs/LibConstants.sol";
|
||||||
import "./libs/LibEIP712CoordinatorDomain.sol";
|
|
||||||
import "./MixinSignatureValidator.sol";
|
import "./MixinSignatureValidator.sol";
|
||||||
import "./MixinCoordinatorApprovalVerifier.sol";
|
import "./MixinCoordinatorApprovalVerifier.sol";
|
||||||
import "./MixinCoordinatorCore.sol";
|
import "./MixinCoordinatorCore.sol";
|
||||||
@@ -34,12 +32,8 @@ contract Coordinator is
|
|||||||
MixinCoordinatorApprovalVerifier,
|
MixinCoordinatorApprovalVerifier,
|
||||||
MixinCoordinatorCore
|
MixinCoordinatorCore
|
||||||
{
|
{
|
||||||
/// @param exchange Address of the 0x Exchange contract.
|
constructor (address _exchange)
|
||||||
/// @param chainId Chain ID of the network this contract is deployed on.
|
|
||||||
constructor (address exchange, uint256 chainId)
|
|
||||||
public
|
public
|
||||||
LibConstants(exchange)
|
LibConstants(_exchange)
|
||||||
LibEIP712CoordinatorDomain(chainId, address(0))
|
|
||||||
LibEIP712ExchangeDomain(chainId, exchange)
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,28 +16,26 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol";
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibAddressArray.sol";
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
import "@0x/contracts-utils/contracts/src/LibAddressArray.sol";
|
||||||
import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol";
|
|
||||||
import "./libs/LibCoordinatorApproval.sol";
|
import "./libs/LibCoordinatorApproval.sol";
|
||||||
import "./libs/LibCoordinatorRichErrors.sol";
|
import "./libs/LibZeroExTransaction.sol";
|
||||||
import "./interfaces/ICoordinatorSignatureValidator.sol";
|
import "./mixins/MSignatureValidator.sol";
|
||||||
import "./interfaces/ICoordinatorApprovalVerifier.sol";
|
import "./mixins/MCoordinatorApprovalVerifier.sol";
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable avoid-tx-origin
|
// solhint-disable avoid-tx-origin
|
||||||
contract MixinCoordinatorApprovalVerifier is
|
contract MixinCoordinatorApprovalVerifier is
|
||||||
|
LibExchangeSelectors,
|
||||||
LibCoordinatorApproval,
|
LibCoordinatorApproval,
|
||||||
LibEIP712ExchangeDomain,
|
LibZeroExTransaction,
|
||||||
ICoordinatorSignatureValidator,
|
MSignatureValidator,
|
||||||
ICoordinatorApprovalVerifier
|
MCoordinatorApprovalVerifier
|
||||||
{
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
using LibAddressArray for address[];
|
using LibAddressArray for address[];
|
||||||
@@ -47,12 +45,13 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
/// order in the transaction's Exchange calldata.
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata.
|
||||||
function assertValidCoordinatorApprovals(
|
function assertValidCoordinatorApprovals(
|
||||||
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
address txOrigin,
|
address txOrigin,
|
||||||
bytes memory transactionSignature,
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
bytes[] memory approvalSignatures
|
bytes[] memory approvalSignatures
|
||||||
)
|
)
|
||||||
public
|
public
|
||||||
@@ -64,11 +63,12 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
// No approval is required for non-fill methods
|
// No approval is required for non-fill methods
|
||||||
if (orders.length > 0) {
|
if (orders.length > 0) {
|
||||||
// Revert if approval is invalid for transaction orders
|
// Revert if approval is invalid for transaction orders
|
||||||
_assertValidTransactionOrdersApproval(
|
assertValidTransactionOrdersApproval(
|
||||||
transaction,
|
transaction,
|
||||||
orders,
|
orders,
|
||||||
txOrigin,
|
txOrigin,
|
||||||
transactionSignature,
|
transactionSignature,
|
||||||
|
approvalExpirationTimeSeconds,
|
||||||
approvalSignatures
|
approvalSignatures
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
|
|
||||||
/// @dev Decodes the orders from Exchange calldata representing any fill method.
|
/// @dev Decodes the orders from Exchange calldata representing any fill method.
|
||||||
/// @param data Exchange calldata representing a fill method.
|
/// @param data Exchange calldata representing a fill method.
|
||||||
/// @return orders The orders from the Exchange calldata.
|
/// @return The orders from the Exchange calldata.
|
||||||
function decodeOrdersFromFillData(bytes memory data)
|
function decodeOrdersFromFillData(bytes memory data)
|
||||||
public
|
public
|
||||||
pure
|
pure
|
||||||
@@ -84,8 +84,9 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
{
|
{
|
||||||
bytes4 selector = data.readBytes4(0);
|
bytes4 selector = data.readBytes4(0);
|
||||||
if (
|
if (
|
||||||
selector == IExchange(address(0)).fillOrder.selector ||
|
selector == FILL_ORDER_SELECTOR ||
|
||||||
selector == IExchange(address(0)).fillOrKillOrder.selector
|
selector == FILL_ORDER_NO_THROW_SELECTOR ||
|
||||||
|
selector == FILL_OR_KILL_ORDER_SELECTOR
|
||||||
) {
|
) {
|
||||||
// Decode single order
|
// Decode single order
|
||||||
(LibOrder.Order memory order) = abi.decode(
|
(LibOrder.Order memory order) = abi.decode(
|
||||||
@@ -95,13 +96,13 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
orders = new LibOrder.Order[](1);
|
orders = new LibOrder.Order[](1);
|
||||||
orders[0] = order;
|
orders[0] = order;
|
||||||
} else if (
|
} else if (
|
||||||
selector == IExchange(address(0)).batchFillOrders.selector ||
|
selector == BATCH_FILL_ORDERS_SELECTOR ||
|
||||||
selector == IExchange(address(0)).batchFillOrdersNoThrow.selector ||
|
selector == BATCH_FILL_ORDERS_NO_THROW_SELECTOR ||
|
||||||
selector == IExchange(address(0)).batchFillOrKillOrders.selector ||
|
selector == BATCH_FILL_OR_KILL_ORDERS_SELECTOR ||
|
||||||
selector == IExchange(address(0)).marketBuyOrdersNoThrow.selector ||
|
selector == MARKET_BUY_ORDERS_SELECTOR ||
|
||||||
selector == IExchange(address(0)).marketBuyOrdersFillOrKill.selector ||
|
selector == MARKET_BUY_ORDERS_NO_THROW_SELECTOR ||
|
||||||
selector == IExchange(address(0)).marketSellOrdersNoThrow.selector ||
|
selector == MARKET_SELL_ORDERS_SELECTOR ||
|
||||||
selector == IExchange(address(0)).marketSellOrdersFillOrKill.selector
|
selector == MARKET_SELL_ORDERS_NO_THROW_SELECTOR
|
||||||
) {
|
) {
|
||||||
// Decode all orders
|
// Decode all orders
|
||||||
// solhint-disable indent
|
// solhint-disable indent
|
||||||
@@ -109,10 +110,7 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
data.slice(4, data.length),
|
data.slice(4, data.length),
|
||||||
(LibOrder.Order[])
|
(LibOrder.Order[])
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (selector == MATCH_ORDERS_SELECTOR) {
|
||||||
selector == IExchange(address(0)).matchOrders.selector ||
|
|
||||||
selector == IExchange(address(0)).matchOrdersWithMaximalFill.selector
|
|
||||||
) {
|
|
||||||
// Decode left and right orders
|
// Decode left and right orders
|
||||||
(LibOrder.Order memory leftOrder, LibOrder.Order memory rightOrder) = abi.decode(
|
(LibOrder.Order memory leftOrder, LibOrder.Order memory rightOrder) = abi.decode(
|
||||||
data.slice(4, data.length),
|
data.slice(4, data.length),
|
||||||
@@ -132,24 +130,27 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
/// @param orders Array of order structs containing order specifications.
|
/// @param orders Array of order structs containing order specifications.
|
||||||
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order.
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order.
|
||||||
function _assertValidTransactionOrdersApproval(
|
function assertValidTransactionOrdersApproval(
|
||||||
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
LibOrder.Order[] memory orders,
|
LibOrder.Order[] memory orders,
|
||||||
address txOrigin,
|
address txOrigin,
|
||||||
bytes memory transactionSignature,
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
bytes[] memory approvalSignatures
|
bytes[] memory approvalSignatures
|
||||||
)
|
)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
{
|
{
|
||||||
// Verify that Ethereum tx signer is the same as the approved txOrigin
|
// Verify that Ethereum tx signer is the same as the approved txOrigin
|
||||||
if (tx.origin != txOrigin) {
|
require(
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.InvalidOriginError(txOrigin));
|
tx.origin == txOrigin,
|
||||||
}
|
"INVALID_ORIGIN"
|
||||||
|
);
|
||||||
|
|
||||||
// Hash 0x transaction
|
// Hash 0x transaction
|
||||||
bytes32 transactionHash = LibZeroExTransaction.getTypedDataHash(transaction, EIP712_EXCHANGE_DOMAIN_HASH);
|
bytes32 transactionHash = getTransactionHash(transaction);
|
||||||
|
|
||||||
// Create empty list of approval signers
|
// Create empty list of approval signers
|
||||||
address[] memory approvalSignerAddresses = new address[](0);
|
address[] memory approvalSignerAddresses = new address[](0);
|
||||||
@@ -157,12 +158,21 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
uint256 signaturesLength = approvalSignatures.length;
|
uint256 signaturesLength = approvalSignatures.length;
|
||||||
for (uint256 i = 0; i != signaturesLength; i++) {
|
for (uint256 i = 0; i != signaturesLength; i++) {
|
||||||
// Create approval message
|
// Create approval message
|
||||||
|
uint256 currentApprovalExpirationTimeSeconds = approvalExpirationTimeSeconds[i];
|
||||||
CoordinatorApproval memory approval = CoordinatorApproval({
|
CoordinatorApproval memory approval = CoordinatorApproval({
|
||||||
txOrigin: txOrigin,
|
txOrigin: txOrigin,
|
||||||
transactionHash: transactionHash,
|
transactionHash: transactionHash,
|
||||||
transactionSignature: transactionSignature
|
transactionSignature: transactionSignature,
|
||||||
|
approvalExpirationTimeSeconds: currentApprovalExpirationTimeSeconds
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Ensure approval has not expired
|
||||||
|
require(
|
||||||
|
// solhint-disable-next-line not-rely-on-time
|
||||||
|
currentApprovalExpirationTimeSeconds > block.timestamp,
|
||||||
|
"APPROVAL_EXPIRED"
|
||||||
|
);
|
||||||
|
|
||||||
// Hash approval message and recover signer address
|
// Hash approval message and recover signer address
|
||||||
bytes32 approvalHash = getCoordinatorApprovalHash(approval);
|
bytes32 approvalHash = getCoordinatorApprovalHash(approval);
|
||||||
address approvalSignerAddress = getSignerAddress(approvalHash, approvalSignatures[i]);
|
address approvalSignerAddress = getSignerAddress(approvalHash, approvalSignatures[i]);
|
||||||
@@ -184,12 +194,10 @@ contract MixinCoordinatorApprovalVerifier is
|
|||||||
// Ensure feeRecipient of order has approved this 0x transaction
|
// Ensure feeRecipient of order has approved this 0x transaction
|
||||||
address approverAddress = orders[i].feeRecipientAddress;
|
address approverAddress = orders[i].feeRecipientAddress;
|
||||||
bool isOrderApproved = approvalSignerAddresses.contains(approverAddress);
|
bool isOrderApproved = approvalSignerAddresses.contains(approverAddress);
|
||||||
if (!isOrderApproved) {
|
require(
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.InvalidApprovalSignatureError(
|
isOrderApproved,
|
||||||
transactionHash,
|
"INVALID_APPROVAL_SIGNATURE"
|
||||||
approverAddress
|
);
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,57 +16,50 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
import "./libs/LibZeroExTransaction.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/Refundable.sol";
|
|
||||||
import "./libs/LibConstants.sol";
|
import "./libs/LibConstants.sol";
|
||||||
|
import "./mixins/MCoordinatorApprovalVerifier.sol";
|
||||||
import "./interfaces/ICoordinatorCore.sol";
|
import "./interfaces/ICoordinatorCore.sol";
|
||||||
import "./interfaces/ICoordinatorApprovalVerifier.sol";
|
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable no-empty-blocks
|
|
||||||
contract MixinCoordinatorCore is
|
contract MixinCoordinatorCore is
|
||||||
Refundable,
|
|
||||||
LibConstants,
|
LibConstants,
|
||||||
ICoordinatorApprovalVerifier,
|
MCoordinatorApprovalVerifier,
|
||||||
ICoordinatorCore
|
ICoordinatorCore
|
||||||
{
|
{
|
||||||
|
/// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata.
|
||||||
/// @dev A payable fallback function that makes this contract "payable". This is necessary to allow
|
|
||||||
/// this contract to gracefully handle refunds from the Exchange.
|
|
||||||
function ()
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
{}
|
|
||||||
|
|
||||||
/// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to
|
|
||||||
/// each order in the transaction's Exchange calldata.
|
|
||||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
/// order in the transaction's Exchange calldata.
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata.
|
||||||
function executeTransaction(
|
function executeTransaction(
|
||||||
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
address txOrigin,
|
address txOrigin,
|
||||||
bytes memory transactionSignature,
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
bytes[] memory approvalSignatures
|
bytes[] memory approvalSignatures
|
||||||
)
|
)
|
||||||
public
|
public
|
||||||
payable
|
|
||||||
refundFinalBalance
|
|
||||||
{
|
{
|
||||||
// Validate that the 0x transaction has been approves by each feeRecipient
|
// Validate that the 0x transaction has been approves by each feeRecipient
|
||||||
assertValidCoordinatorApprovals(
|
assertValidCoordinatorApprovals(
|
||||||
transaction,
|
transaction,
|
||||||
txOrigin,
|
txOrigin,
|
||||||
transactionSignature,
|
transactionSignature,
|
||||||
|
approvalExpirationTimeSeconds,
|
||||||
approvalSignatures
|
approvalSignatures
|
||||||
);
|
);
|
||||||
|
|
||||||
// Execute the transaction
|
// Execute the transaction
|
||||||
EXCHANGE.executeTransaction.value(msg.value)(transaction, transactionSignature);
|
EXCHANGE.executeTransaction(
|
||||||
|
transaction.salt,
|
||||||
|
transaction.signerAddress,
|
||||||
|
transaction.data,
|
||||||
|
transactionSignature
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,48 +16,38 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
import "./mixins/MSignatureValidator.sol";
|
||||||
import "./interfaces/ICoordinatorSignatureValidator.sol";
|
|
||||||
import "./libs/LibCoordinatorRichErrors.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract MixinSignatureValidator is
|
contract MixinSignatureValidator is
|
||||||
ICoordinatorSignatureValidator
|
MSignatureValidator
|
||||||
{
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
|
|
||||||
/// @dev Recovers the address of a signer given a hash and signature.
|
/// @dev Recovers the address of a signer given a hash and signature.
|
||||||
/// @param hash Any 32 byte hash.
|
/// @param hash Any 32 byte hash.
|
||||||
/// @param signature Proof that the hash has been signed by signer.
|
/// @param signature Proof that the hash has been signed by signer.
|
||||||
/// @return signerAddress Address of the signer.
|
|
||||||
function getSignerAddress(bytes32 hash, bytes memory signature)
|
function getSignerAddress(bytes32 hash, bytes memory signature)
|
||||||
public
|
public
|
||||||
pure
|
pure
|
||||||
returns (address signerAddress)
|
returns (address signerAddress)
|
||||||
{
|
{
|
||||||
uint256 signatureLength = signature.length;
|
require(
|
||||||
if (signatureLength == 0) {
|
signature.length > 0,
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
"LENGTH_GREATER_THAN_0_REQUIRED"
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.INVALID_LENGTH,
|
);
|
||||||
hash,
|
|
||||||
signature
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pop last byte off of signature byte array.
|
// Pop last byte off of signature byte array.
|
||||||
uint8 signatureTypeRaw = uint8(signature[signature.length - 1]);
|
uint8 signatureTypeRaw = uint8(signature.popLastByte());
|
||||||
|
|
||||||
// Ensure signature is supported
|
// Ensure signature is supported
|
||||||
if (signatureTypeRaw >= uint8(SignatureType.NSignatureTypes)) {
|
require(
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
signatureTypeRaw < uint8(SignatureType.NSignatureTypes),
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.UNSUPPORTED,
|
"SIGNATURE_UNSUPPORTED"
|
||||||
hash,
|
);
|
||||||
signature
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
SignatureType signatureType = SignatureType(signatureTypeRaw);
|
SignatureType signatureType = SignatureType(signatureTypeRaw);
|
||||||
|
|
||||||
@@ -67,32 +57,25 @@ contract MixinSignatureValidator is
|
|||||||
// it an explicit option. This aids testing and analysis. It is
|
// it an explicit option. This aids testing and analysis. It is
|
||||||
// also the initialization value for the enum type.
|
// also the initialization value for the enum type.
|
||||||
if (signatureType == SignatureType.Illegal) {
|
if (signatureType == SignatureType.Illegal) {
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
revert("SIGNATURE_ILLEGAL");
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.ILLEGAL,
|
|
||||||
hash,
|
|
||||||
signature
|
|
||||||
));
|
|
||||||
|
|
||||||
// Always invalid signature.
|
// Always invalid signature.
|
||||||
// Like Illegal, this is always implicitly available and therefore
|
// Like Illegal, this is always implicitly available and therefore
|
||||||
// offered explicitly. It can be implicitly created by providing
|
// offered explicitly. It can be implicitly created by providing
|
||||||
// a correctly formatted but incorrect signature.
|
// a correctly formatted but incorrect signature.
|
||||||
} else if (signatureType == SignatureType.Invalid) {
|
} else if (signatureType == SignatureType.Invalid) {
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
require(
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.INVALID,
|
signature.length == 0,
|
||||||
hash,
|
"LENGTH_0_REQUIRED"
|
||||||
signature
|
);
|
||||||
));
|
revert("SIGNATURE_INVALID");
|
||||||
|
|
||||||
// Signature using EIP712
|
// Signature using EIP712
|
||||||
} else if (signatureType == SignatureType.EIP712) {
|
} else if (signatureType == SignatureType.EIP712) {
|
||||||
if (signatureLength != 66) {
|
require(
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
signature.length == 65,
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.INVALID_LENGTH,
|
"LENGTH_65_REQUIRED"
|
||||||
hash,
|
);
|
||||||
signature
|
|
||||||
));
|
|
||||||
}
|
|
||||||
uint8 v = uint8(signature[0]);
|
uint8 v = uint8(signature[0]);
|
||||||
bytes32 r = signature.readBytes32(1);
|
bytes32 r = signature.readBytes32(1);
|
||||||
bytes32 s = signature.readBytes32(33);
|
bytes32 s = signature.readBytes32(33);
|
||||||
@@ -106,13 +89,10 @@ contract MixinSignatureValidator is
|
|||||||
|
|
||||||
// Signed using web3.eth_sign
|
// Signed using web3.eth_sign
|
||||||
} else if (signatureType == SignatureType.EthSign) {
|
} else if (signatureType == SignatureType.EthSign) {
|
||||||
if (signatureLength != 66) {
|
require(
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
signature.length == 65,
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.INVALID_LENGTH,
|
"LENGTH_65_REQUIRED"
|
||||||
hash,
|
);
|
||||||
signature
|
|
||||||
));
|
|
||||||
}
|
|
||||||
uint8 v = uint8(signature[0]);
|
uint8 v = uint8(signature[0]);
|
||||||
bytes32 r = signature.readBytes32(1);
|
bytes32 r = signature.readBytes32(1);
|
||||||
bytes32 s = signature.readBytes32(33);
|
bytes32 s = signature.readBytes32(33);
|
||||||
@@ -133,10 +113,6 @@ contract MixinSignatureValidator is
|
|||||||
// that we currently support. In this case returning false
|
// that we currently support. In this case returning false
|
||||||
// may lead the caller to incorrectly believe that the
|
// may lead the caller to incorrectly believe that the
|
||||||
// signature was invalid.)
|
// signature was invalid.)
|
||||||
LibRichErrors.rrevert(LibCoordinatorRichErrors.SignatureError(
|
revert("SIGNATURE_UNSUPPORTED");
|
||||||
LibCoordinatorRichErrors.SignatureErrorCodes.UNSUPPORTED,
|
|
||||||
hash,
|
|
||||||
signature
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
import "../libs/LibZeroExTransaction.sol";
|
||||||
|
|
||||||
|
|
||||||
contract ICoordinatorApprovalVerifier {
|
contract ICoordinatorApprovalVerifier {
|
||||||
@@ -30,12 +30,13 @@ contract ICoordinatorApprovalVerifier {
|
|||||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
/// order in the transaction's Exchange calldata.
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata.
|
||||||
function assertValidCoordinatorApprovals(
|
function assertValidCoordinatorApprovals(
|
||||||
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
address txOrigin,
|
address txOrigin,
|
||||||
bytes memory transactionSignature,
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
bytes[] memory approvalSignatures
|
bytes[] memory approvalSignatures
|
||||||
)
|
)
|
||||||
public
|
public
|
||||||
@@ -43,7 +44,7 @@ contract ICoordinatorApprovalVerifier {
|
|||||||
|
|
||||||
/// @dev Decodes the orders from Exchange calldata representing any fill method.
|
/// @dev Decodes the orders from Exchange calldata representing any fill method.
|
||||||
/// @param data Exchange calldata representing a fill method.
|
/// @param data Exchange calldata representing a fill method.
|
||||||
/// @return orders The orders from the Exchange calldata.
|
/// @return The orders from the Exchange calldata.
|
||||||
function decodeOrdersFromFillData(bytes memory data)
|
function decodeOrdersFromFillData(bytes memory data)
|
||||||
public
|
public
|
||||||
pure
|
pure
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,27 +16,26 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
import "../libs/LibZeroExTransaction.sol";
|
||||||
|
|
||||||
|
|
||||||
contract ICoordinatorCore {
|
contract ICoordinatorCore {
|
||||||
|
|
||||||
/// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to
|
/// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata.
|
||||||
/// each order in the transaction's Exchange calldata.
|
|
||||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
/// order in the transaction's Exchange calldata.
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata.
|
||||||
function executeTransaction(
|
function executeTransaction(
|
||||||
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
address txOrigin,
|
address txOrigin,
|
||||||
bytes memory transactionSignature,
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
bytes[] memory approvalSignatures
|
bytes[] memory approvalSignatures
|
||||||
)
|
)
|
||||||
public
|
public;
|
||||||
payable;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
contract ICoordinatorSignatureValidator {
|
|
||||||
|
|
||||||
// Allowed signature types.
|
|
||||||
enum SignatureType {
|
|
||||||
Illegal, // 0x00, default value
|
|
||||||
Invalid, // 0x01
|
|
||||||
EIP712, // 0x02
|
|
||||||
EthSign, // 0x03
|
|
||||||
Wallet, // 0x04
|
|
||||||
Validator, // 0x05
|
|
||||||
PreSigned, // 0x06
|
|
||||||
EIP1271Wallet, // 0x07
|
|
||||||
NSignatureTypes // 0x08, number of signature types. Always leave at end.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Recovers the address of a signer given a hash and signature.
|
|
||||||
/// @param hash Any 32 byte hash.
|
|
||||||
/// @param signature Proof that the hash has been signed by signer.
|
|
||||||
/// @return signerAddress Address of the signer.
|
|
||||||
function getSignerAddress(bytes32 hash, bytes memory signature)
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (address signerAddress);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -18,10 +18,14 @@
|
|||||||
|
|
||||||
pragma solidity ^0.5.5;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "../src/libs/LibExchangeRichErrorDecoder.sol";
|
|
||||||
|
|
||||||
|
contract ISignatureValidator {
|
||||||
|
|
||||||
// solhint-disable no-empty-blocks
|
/// @dev Recovers the address of a signer given a hash and signature.
|
||||||
contract TestLibExchangeRichErrorDecoder is
|
/// @param hash Any 32 byte hash.
|
||||||
LibExchangeRichErrorDecoder
|
/// @param signature Proof that the hash has been signed by signer.
|
||||||
{}
|
function getSignerAddress(bytes32 hash, bytes memory signature)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (address signerAddress);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,24 +15,21 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
pragma solidity ^0.5.9;
|
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract IEIP1271Wallet is
|
contract ITransactions {
|
||||||
LibEIP1271
|
|
||||||
{
|
/// @dev Executes an exchange method call in the context of signer.
|
||||||
/// @dev Verifies that a signature is valid.
|
/// @param salt Arbitrary number to ensure uniqueness of transaction hash.
|
||||||
/// @param data Arbitrary signed data.
|
/// @param signerAddress Address of transaction signer.
|
||||||
/// @param signature Proof that data has been signed.
|
/// @param data AbiV2 encoded calldata.
|
||||||
/// @return magicValue bytes4(0x20c13b0b) if the signature check succeeds.
|
/// @param signature Proof of signer transaction by signer.
|
||||||
function isValidSignature(
|
function executeTransaction(
|
||||||
|
uint256 salt,
|
||||||
|
address signerAddress,
|
||||||
bytes calldata data,
|
bytes calldata data,
|
||||||
bytes calldata signature
|
bytes calldata signature
|
||||||
)
|
)
|
||||||
external
|
external;
|
||||||
view
|
|
||||||
returns (bytes4 magicValue);
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,21 +16,19 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "@0x/contracts-exchange/contracts/src/interfaces/ITransactions.sol";
|
import "../interfaces/ITransactions.sol";
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable var-name-mixedcase
|
|
||||||
contract LibConstants {
|
contract LibConstants {
|
||||||
|
|
||||||
// The 0x Exchange contract.
|
// solhint-disable-next-line var-name-mixedcase
|
||||||
ITransactions internal EXCHANGE;
|
ITransactions internal EXCHANGE;
|
||||||
|
|
||||||
/// @param exchange Address of the 0x Exchange contract.
|
constructor (address _exchange)
|
||||||
constructor (address exchange)
|
|
||||||
public
|
public
|
||||||
{
|
{
|
||||||
EXCHANGE = ITransactions(exchange);
|
EXCHANGE = ITransactions(_exchange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,52 +16,49 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
import "./LibEIP712CoordinatorDomain.sol";
|
import "./LibEIP712Domain.sol";
|
||||||
|
|
||||||
|
|
||||||
contract LibCoordinatorApproval is
|
contract LibCoordinatorApproval is
|
||||||
LibEIP712CoordinatorDomain
|
LibEIP712Domain
|
||||||
{
|
{
|
||||||
// Hash for the EIP712 Coordinator approval message
|
// Hash for the EIP712 Coordinator approval message
|
||||||
// keccak256(abi.encodePacked(
|
// keccak256(abi.encodePacked(
|
||||||
// "CoordinatorApproval(",
|
// "CoordinatorApproval(",
|
||||||
// "address txOrigin,",
|
// "address txOrigin,",
|
||||||
// "bytes32 transactionHash,",
|
// "bytes32 transactionHash,",
|
||||||
// "bytes transactionSignature",
|
// "bytes transactionSignature,",
|
||||||
|
// "uint256 approvalExpirationTimeSeconds",
|
||||||
// ")"
|
// ")"
|
||||||
// ));
|
// ));
|
||||||
bytes32 constant public EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH =
|
bytes32 constant internal EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH = 0x2fbcdbaa76bc7589916958ae919dfbef04d23f6bbf26de6ff317b32c6cc01e05;
|
||||||
0xa6511c04ca44625d50986f8c36bedc09366207a17b96e347094053a9f8507168;
|
|
||||||
|
|
||||||
struct CoordinatorApproval {
|
struct CoordinatorApproval {
|
||||||
address txOrigin; // Required signer of Ethereum transaction that is submitting approval.
|
address txOrigin; // Required signer of Ethereum transaction that is submitting approval.
|
||||||
bytes32 transactionHash; // EIP712 hash of the transaction.
|
bytes32 transactionHash; // EIP712 hash of the transaction.
|
||||||
bytes transactionSignature; // Signature of the 0x transaction.
|
bytes transactionSignature; // Signature of the 0x transaction.
|
||||||
|
uint256 approvalExpirationTimeSeconds; // Timestamp in seconds for which the approval expires.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Calculates the EIP712 hash of the Coordinator approval mesasage using the domain
|
/// @dev Calculated the EIP712 hash of the Coordinator approval mesasage using the domain separator of this contract.
|
||||||
/// separator of this contract.
|
/// @param approval Coordinator approval message containing the transaction hash, transaction signature, and expiration of the approval.
|
||||||
/// @param approval Coordinator approval message containing the transaction hash, and transaction
|
/// @return EIP712 hash of the Coordinator approval message with the domain separator of this contract.
|
||||||
/// signature.
|
|
||||||
/// @return approvalHash EIP712 hash of the Coordinator approval message with the domain
|
|
||||||
/// separator of this contract.
|
|
||||||
function getCoordinatorApprovalHash(CoordinatorApproval memory approval)
|
function getCoordinatorApprovalHash(CoordinatorApproval memory approval)
|
||||||
public
|
public
|
||||||
view
|
view
|
||||||
returns (bytes32 approvalHash)
|
returns (bytes32 approvalHash)
|
||||||
{
|
{
|
||||||
approvalHash = _hashEIP712CoordinatorMessage(_hashCoordinatorApproval(approval));
|
approvalHash = hashEIP712CoordinatorMessage(hashCoordinatorApproval(approval));
|
||||||
return approvalHash;
|
return approvalHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Calculates the EIP712 hash of the Coordinator approval mesasage with no domain separator.
|
/// @dev Calculated the EIP712 hash of the Coordinator approval mesasage with no domain separator.
|
||||||
/// @param approval Coordinator approval message containing the transaction hash, and transaction
|
/// @param approval Coordinator approval message containing the transaction hash, transaction signature, and expiration of the approval.
|
||||||
// signature.
|
/// @return EIP712 hash of the Coordinator approval message with no domain separator.
|
||||||
/// @return result EIP712 hash of the Coordinator approval message with no domain separator.
|
function hashCoordinatorApproval(CoordinatorApproval memory approval)
|
||||||
function _hashCoordinatorApproval(CoordinatorApproval memory approval)
|
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (bytes32 result)
|
returns (bytes32 result)
|
||||||
@@ -70,6 +67,7 @@ contract LibCoordinatorApproval is
|
|||||||
bytes memory transactionSignature = approval.transactionSignature;
|
bytes memory transactionSignature = approval.transactionSignature;
|
||||||
address txOrigin = approval.txOrigin;
|
address txOrigin = approval.txOrigin;
|
||||||
bytes32 transactionHash = approval.transactionHash;
|
bytes32 transactionHash = approval.transactionHash;
|
||||||
|
uint256 approvalExpirationTimeSeconds = approval.approvalExpirationTimeSeconds;
|
||||||
|
|
||||||
// Assembly for more efficiently computing:
|
// Assembly for more efficiently computing:
|
||||||
// keccak256(abi.encodePacked(
|
// keccak256(abi.encodePacked(
|
||||||
@@ -77,6 +75,7 @@ contract LibCoordinatorApproval is
|
|||||||
// approval.txOrigin,
|
// approval.txOrigin,
|
||||||
// approval.transactionHash,
|
// approval.transactionHash,
|
||||||
// keccak256(approval.transactionSignature)
|
// keccak256(approval.transactionSignature)
|
||||||
|
// approval.approvalExpirationTimeSeconds,
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
assembly {
|
assembly {
|
||||||
@@ -90,8 +89,9 @@ contract LibCoordinatorApproval is
|
|||||||
mstore(add(memPtr, 32), txOrigin) // txOrigin
|
mstore(add(memPtr, 32), txOrigin) // txOrigin
|
||||||
mstore(add(memPtr, 64), transactionHash) // transactionHash
|
mstore(add(memPtr, 64), transactionHash) // transactionHash
|
||||||
mstore(add(memPtr, 96), transactionSignatureHash) // transactionSignatureHash
|
mstore(add(memPtr, 96), transactionSignatureHash) // transactionSignatureHash
|
||||||
|
mstore(add(memPtr, 128), approvalExpirationTimeSeconds) // approvalExpirationTimeSeconds
|
||||||
// Compute hash
|
// Compute hash
|
||||||
result := keccak256(memPtr, 128)
|
result := keccak256(memPtr, 160)
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
|
|
||||||
library LibCoordinatorRichErrors {
|
|
||||||
enum SignatureErrorCodes {
|
|
||||||
INVALID_LENGTH,
|
|
||||||
UNSUPPORTED,
|
|
||||||
ILLEGAL,
|
|
||||||
INVALID
|
|
||||||
}
|
|
||||||
|
|
||||||
// bytes4(keccak256("SignatureError(uint8,bytes32,bytes)"))
|
|
||||||
bytes4 internal constant SIGNATURE_ERROR_SELECTOR =
|
|
||||||
0x779c5223;
|
|
||||||
|
|
||||||
// bytes4(keccak256("InvalidOriginError(address)"))
|
|
||||||
bytes4 internal constant INVALID_ORIGIN_ERROR_SELECTOR =
|
|
||||||
0xa458d7ff;
|
|
||||||
|
|
||||||
// bytes4(keccak256("InvalidApprovalSignatureError(bytes32,address)"))
|
|
||||||
bytes4 internal constant INVALID_APPROVAL_SIGNATURE_ERROR_SELECTOR =
|
|
||||||
0xd789b640;
|
|
||||||
|
|
||||||
// solhint-disable func-name-mixedcase
|
|
||||||
function SignatureError(
|
|
||||||
SignatureErrorCodes errorCode,
|
|
||||||
bytes32 hash,
|
|
||||||
bytes memory signature
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
pure
|
|
||||||
returns (bytes memory)
|
|
||||||
{
|
|
||||||
return abi.encodeWithSelector(
|
|
||||||
SIGNATURE_ERROR_SELECTOR,
|
|
||||||
errorCode,
|
|
||||||
hash,
|
|
||||||
signature
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function InvalidOriginError(
|
|
||||||
address expectedOrigin
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
pure
|
|
||||||
returns (bytes memory)
|
|
||||||
{
|
|
||||||
return abi.encodeWithSelector(
|
|
||||||
INVALID_ORIGIN_ERROR_SELECTOR,
|
|
||||||
expectedOrigin
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function InvalidApprovalSignatureError(
|
|
||||||
bytes32 transactionHash,
|
|
||||||
address approverAddress
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
pure
|
|
||||||
returns (bytes memory)
|
|
||||||
{
|
|
||||||
return abi.encodeWithSelector(
|
|
||||||
INVALID_APPROVAL_SIGNATURE_ERROR_SELECTOR,
|
|
||||||
transactionHash,
|
|
||||||
approverAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Copyright 2019 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.5.9;
|
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibEIP712.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract LibEIP712CoordinatorDomain {
|
|
||||||
|
|
||||||
// EIP712 Domain Name value for the Coordinator
|
|
||||||
string constant public EIP712_COORDINATOR_DOMAIN_NAME = "0x Protocol Coordinator";
|
|
||||||
|
|
||||||
// EIP712 Domain Version value for the Coordinator
|
|
||||||
string constant public EIP712_COORDINATOR_DOMAIN_VERSION = "3.0.0";
|
|
||||||
|
|
||||||
// Hash of the EIP712 Domain Separator data for the Coordinator
|
|
||||||
// solhint-disable-next-line var-name-mixedcase
|
|
||||||
bytes32 public EIP712_COORDINATOR_DOMAIN_HASH;
|
|
||||||
|
|
||||||
/// @param chainId Chain ID of the network this contract is deployed on.
|
|
||||||
/// @param verifyingContractAddressIfExists Address of the verifying contract (null if the address of this contract)
|
|
||||||
constructor (
|
|
||||||
uint256 chainId,
|
|
||||||
address verifyingContractAddressIfExists
|
|
||||||
)
|
|
||||||
public
|
|
||||||
{
|
|
||||||
address verifyingContractAddress = verifyingContractAddressIfExists == address(0)
|
|
||||||
? address(this)
|
|
||||||
: verifyingContractAddressIfExists;
|
|
||||||
EIP712_COORDINATOR_DOMAIN_HASH = LibEIP712.hashEIP712Domain(
|
|
||||||
EIP712_COORDINATOR_DOMAIN_NAME,
|
|
||||||
EIP712_COORDINATOR_DOMAIN_VERSION,
|
|
||||||
chainId,
|
|
||||||
verifyingContractAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain
|
|
||||||
/// of this contract.
|
|
||||||
/// @param hashStruct The EIP712 hash struct.
|
|
||||||
/// @return result EIP712 hash applied to this EIP712 Domain.
|
|
||||||
function _hashEIP712CoordinatorMessage(bytes32 hashStruct)
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (bytes32 result)
|
|
||||||
{
|
|
||||||
return LibEIP712.hashEIP712Message(EIP712_COORDINATOR_DOMAIN_HASH, hashStruct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
131
contracts/coordinator/contracts/src/libs/LibEIP712Domain.sol
Normal file
131
contracts/coordinator/contracts/src/libs/LibEIP712Domain.sol
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
import "./LibConstants.sol";
|
||||||
|
|
||||||
|
|
||||||
|
contract LibEIP712Domain is
|
||||||
|
LibConstants
|
||||||
|
{
|
||||||
|
|
||||||
|
// EIP191 header for EIP712 prefix
|
||||||
|
string constant internal EIP191_HEADER = "\x19\x01";
|
||||||
|
|
||||||
|
// EIP712 Domain Name value for the Coordinator
|
||||||
|
string constant internal EIP712_COORDINATOR_DOMAIN_NAME = "0x Protocol Coordinator";
|
||||||
|
|
||||||
|
// EIP712 Domain Version value for the Coordinator
|
||||||
|
string constant internal EIP712_COORDINATOR_DOMAIN_VERSION = "1.0.0";
|
||||||
|
|
||||||
|
// EIP712 Domain Name value for the Exchange
|
||||||
|
string constant internal EIP712_EXCHANGE_DOMAIN_NAME = "0x Protocol";
|
||||||
|
|
||||||
|
// EIP712 Domain Version value for the Exchange
|
||||||
|
string constant internal EIP712_EXCHANGE_DOMAIN_VERSION = "2";
|
||||||
|
|
||||||
|
// Hash of the EIP712 Domain Separator Schema
|
||||||
|
bytes32 constant internal EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked(
|
||||||
|
"EIP712Domain(",
|
||||||
|
"string name,",
|
||||||
|
"string version,",
|
||||||
|
"address verifyingContract",
|
||||||
|
")"
|
||||||
|
));
|
||||||
|
|
||||||
|
// Hash of the EIP712 Domain Separator data for the Coordinator
|
||||||
|
// solhint-disable-next-line var-name-mixedcase
|
||||||
|
bytes32 public EIP712_COORDINATOR_DOMAIN_HASH;
|
||||||
|
|
||||||
|
// Hash of the EIP712 Domain Separator data for the Exchange
|
||||||
|
// solhint-disable-next-line var-name-mixedcase
|
||||||
|
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
|
||||||
|
|
||||||
|
constructor ()
|
||||||
|
public
|
||||||
|
{
|
||||||
|
EIP712_COORDINATOR_DOMAIN_HASH = keccak256(abi.encodePacked(
|
||||||
|
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
|
||||||
|
keccak256(bytes(EIP712_COORDINATOR_DOMAIN_NAME)),
|
||||||
|
keccak256(bytes(EIP712_COORDINATOR_DOMAIN_VERSION)),
|
||||||
|
uint256(address(this))
|
||||||
|
));
|
||||||
|
|
||||||
|
EIP712_EXCHANGE_DOMAIN_HASH = keccak256(abi.encodePacked(
|
||||||
|
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
|
||||||
|
keccak256(bytes(EIP712_EXCHANGE_DOMAIN_NAME)),
|
||||||
|
keccak256(bytes(EIP712_EXCHANGE_DOMAIN_VERSION)),
|
||||||
|
uint256(address(EXCHANGE))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain
|
||||||
|
/// of this contract.
|
||||||
|
/// @param hashStruct The EIP712 hash struct.
|
||||||
|
/// @return EIP712 hash applied to this EIP712 Domain.
|
||||||
|
function hashEIP712CoordinatorMessage(bytes32 hashStruct)
|
||||||
|
internal
|
||||||
|
view
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
return hashEIP712Message(EIP712_COORDINATOR_DOMAIN_HASH, hashStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain
|
||||||
|
/// of the Exchange contract.
|
||||||
|
/// @param hashStruct The EIP712 hash struct.
|
||||||
|
/// @return EIP712 hash applied to the Exchange EIP712 Domain.
|
||||||
|
function hashEIP712ExchangeMessage(bytes32 hashStruct)
|
||||||
|
internal
|
||||||
|
view
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
return hashEIP712Message(EIP712_EXCHANGE_DOMAIN_HASH, hashStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Calculates EIP712 encoding for a hash struct with a given domain hash.
|
||||||
|
/// @param eip712DomainHash Hash of the domain domain separator data.
|
||||||
|
/// @param hashStruct The EIP712 hash struct.
|
||||||
|
/// @return EIP712 hash applied to the Exchange EIP712 Domain.
|
||||||
|
function hashEIP712Message(bytes32 eip712DomainHash, bytes32 hashStruct)
|
||||||
|
internal
|
||||||
|
pure
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
// Assembly for more efficient computing:
|
||||||
|
// keccak256(abi.encodePacked(
|
||||||
|
// EIP191_HEADER,
|
||||||
|
// EIP712_DOMAIN_HASH,
|
||||||
|
// hashStruct
|
||||||
|
// ));
|
||||||
|
|
||||||
|
assembly {
|
||||||
|
// Load free memory pointer
|
||||||
|
let memPtr := mload(64)
|
||||||
|
|
||||||
|
mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000) // EIP191 header
|
||||||
|
mstore(add(memPtr, 2), eip712DomainHash) // EIP712 domain hash
|
||||||
|
mstore(add(memPtr, 34), hashStruct) // Hash of struct
|
||||||
|
|
||||||
|
// Compute hash
|
||||||
|
result := keccak256(memPtr, 66)
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
|
import "./LibEIP712Domain.sol";
|
||||||
|
|
||||||
|
|
||||||
|
contract LibZeroExTransaction is
|
||||||
|
LibEIP712Domain
|
||||||
|
{
|
||||||
|
// Hash for the EIP712 0x transaction schema
|
||||||
|
// keccak256(abi.encodePacked(
|
||||||
|
// "ZeroExTransaction(",
|
||||||
|
// "uint256 salt,",
|
||||||
|
// "address signerAddress,",
|
||||||
|
// "bytes data",
|
||||||
|
// ")"
|
||||||
|
// ));
|
||||||
|
bytes32 constant internal EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0x213c6f636f3ea94e701c0adf9b2624aa45a6c694f9a292c094f9a81c24b5df4c;
|
||||||
|
|
||||||
|
struct ZeroExTransaction {
|
||||||
|
uint256 salt; // Arbitrary number to ensure uniqueness of transaction hash.
|
||||||
|
address signerAddress; // Address of transaction signer.
|
||||||
|
bytes data; // AbiV2 encoded calldata.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Calculates the EIP712 hash of a 0x transaction using the domain separator of the Exchange contract.
|
||||||
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
|
/// @return EIP712 hash of the transaction with the domain separator of this contract.
|
||||||
|
function getTransactionHash(ZeroExTransaction memory transaction)
|
||||||
|
public
|
||||||
|
view
|
||||||
|
returns (bytes32 transactionHash)
|
||||||
|
{
|
||||||
|
// Hash the transaction with the domain separator of the Exchange contract.
|
||||||
|
transactionHash = hashEIP712ExchangeMessage(hashZeroExTransaction(transaction));
|
||||||
|
return transactionHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Calculates EIP712 hash of the 0x transaction with no domain separator.
|
||||||
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
|
/// @return EIP712 hash of the transaction with no domain separator.
|
||||||
|
function hashZeroExTransaction(ZeroExTransaction memory transaction)
|
||||||
|
internal
|
||||||
|
pure
|
||||||
|
returns (bytes32 result)
|
||||||
|
{
|
||||||
|
bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
|
||||||
|
bytes memory data = transaction.data;
|
||||||
|
uint256 salt = transaction.salt;
|
||||||
|
address signerAddress = transaction.signerAddress;
|
||||||
|
|
||||||
|
// Assembly for more efficiently computing:
|
||||||
|
// keccak256(abi.encodePacked(
|
||||||
|
// EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH,
|
||||||
|
// transaction.salt,
|
||||||
|
// uint256(transaction.signerAddress),
|
||||||
|
// keccak256(transaction.data)
|
||||||
|
// ));
|
||||||
|
|
||||||
|
assembly {
|
||||||
|
// Compute hash of data
|
||||||
|
let dataHash := keccak256(add(data, 32), mload(data))
|
||||||
|
|
||||||
|
// Load free memory pointer
|
||||||
|
let memPtr := mload(64)
|
||||||
|
|
||||||
|
mstore(memPtr, schemaHash) // hash of schema
|
||||||
|
mstore(add(memPtr, 32), salt) // salt
|
||||||
|
mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) // signerAddress
|
||||||
|
mstore(add(memPtr, 96), dataHash) // hash of data
|
||||||
|
|
||||||
|
// Compute hash
|
||||||
|
result := keccak256(memPtr, 128)
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
pragma experimental "ABIEncoderV2";
|
||||||
|
|
||||||
|
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||||
|
import "../interfaces/ICoordinatorApprovalVerifier.sol";
|
||||||
|
|
||||||
|
|
||||||
|
contract MCoordinatorApprovalVerifier is
|
||||||
|
ICoordinatorApprovalVerifier
|
||||||
|
{
|
||||||
|
/// @dev Validates that the feeRecipients of a batch of order have approved a 0x transaction.
|
||||||
|
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||||
|
/// @param orders Array of order structs containing order specifications.
|
||||||
|
/// @param txOrigin Required signer of Ethereum transaction calling this function.
|
||||||
|
/// @param transactionSignature Proof that the transaction has been signed by the signer.
|
||||||
|
/// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires.
|
||||||
|
/// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order.
|
||||||
|
function assertValidTransactionOrdersApproval(
|
||||||
|
LibZeroExTransaction.ZeroExTransaction memory transaction,
|
||||||
|
LibOrder.Order[] memory orders,
|
||||||
|
address txOrigin,
|
||||||
|
bytes memory transactionSignature,
|
||||||
|
uint256[] memory approvalExpirationTimeSeconds,
|
||||||
|
bytes[] memory approvalSignatures
|
||||||
|
)
|
||||||
|
internal
|
||||||
|
view;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,27 +16,20 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "../src/Staking.sol";
|
import "../interfaces/ISignatureValidator.sol";
|
||||||
|
|
||||||
|
|
||||||
contract TestExchangeManager is
|
contract MSignatureValidator is
|
||||||
Staking
|
ISignatureValidator
|
||||||
{
|
{
|
||||||
function setValidExchange(address exchange)
|
// Allowed signature types.
|
||||||
external
|
enum SignatureType {
|
||||||
{
|
Illegal, // 0x00, default value
|
||||||
validExchanges[exchange] = true;
|
Invalid, // 0x01
|
||||||
}
|
EIP712, // 0x02
|
||||||
|
EthSign, // 0x03
|
||||||
function onlyExchangeFunction()
|
NSignatureTypes // 0x04, number of signature types. Always leave at end.
|
||||||
external
|
|
||||||
view
|
|
||||||
onlyExchange
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "./MixinCoordinatorRegistryCore.sol";
|
import "./MixinCoordinatorRegistryCore.sol";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "./interfaces/ICoordinatorRegistryCore.sol";
|
import "./interfaces/ICoordinatorRegistryCore.sol";
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ contract MixinCoordinatorRegistryCore is
|
|||||||
mapping (address => string) internal coordinatorEndpoints;
|
mapping (address => string) internal coordinatorEndpoints;
|
||||||
|
|
||||||
/// @dev Called by a Coordinator operator to set the endpoint of their Coordinator.
|
/// @dev Called by a Coordinator operator to set the endpoint of their Coordinator.
|
||||||
/// @param coordinatorEndpoint Endpoint of the Coordinator as a string.
|
/// @param coordinatorEndpoint endpoint of the Coordinator.
|
||||||
function setCoordinatorEndpoint(string calldata coordinatorEndpoint) external {
|
function setCoordinatorEndpoint(string calldata coordinatorEndpoint) external {
|
||||||
address coordinatorOperator = msg.sender;
|
address coordinatorOperator = msg.sender;
|
||||||
coordinatorEndpoints[coordinatorOperator] = coordinatorEndpoint;
|
coordinatorEndpoints[coordinatorOperator] = coordinatorEndpoint;
|
||||||
@@ -37,8 +37,7 @@ contract MixinCoordinatorRegistryCore is
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Gets the endpoint for a Coordinator.
|
/// @dev Gets the endpoint for a Coordinator.
|
||||||
/// @param coordinatorOperator Operator of the Coordinator endpoint.
|
/// @param coordinatorOperator operator of the Coordinator endpoint.
|
||||||
/// @return coordinatorEndpoint Endpoint of the Coordinator as a string.
|
|
||||||
function getCoordinatorEndpoint(address coordinatorOperator)
|
function getCoordinatorEndpoint(address coordinatorOperator)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2019 ZeroEx Intl.
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
|
||||||
// solhint-disable no-empty-blocks
|
// solhint-disable no-empty-blocks
|
||||||
@@ -29,12 +29,11 @@ contract ICoordinatorRegistryCore
|
|||||||
);
|
);
|
||||||
|
|
||||||
/// @dev Called by a Coordinator operator to set the endpoint of their Coordinator.
|
/// @dev Called by a Coordinator operator to set the endpoint of their Coordinator.
|
||||||
/// @param coordinatorEndpoint Endpoint of the Coordinator as a string.
|
/// @param coordinatorEndpoint endpoint of the Coordinator.
|
||||||
function setCoordinatorEndpoint(string calldata coordinatorEndpoint) external;
|
function setCoordinatorEndpoint(string calldata coordinatorEndpoint) external;
|
||||||
|
|
||||||
/// @dev Gets the endpoint for a Coordinator.
|
/// @dev Gets the endpoint for a Coordinator.
|
||||||
/// @param coordinatorOperator Operator of the Coordinator endpoint.
|
/// @param coordinatorOperator operator of the Coordinator endpoint.
|
||||||
/// @return coordinatorEndpoint Endpoint of the Coordinator as a string.
|
|
||||||
function getCoordinatorEndpoint(address coordinatorOperator)
|
function getCoordinatorEndpoint(address coordinatorOperator)
|
||||||
external
|
external
|
||||||
view
|
view
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@0x/contracts-coordinator",
|
"name": "@0x/contracts-coordinator",
|
||||||
"version": "3.0.4",
|
"version": "2.0.13",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.12"
|
"node": ">=6.12"
|
||||||
},
|
},
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn pre_build && tsc -b",
|
"build": "yarn pre_build && tsc -b",
|
||||||
"build:ci": "yarn build",
|
"build:ci": "yarn build",
|
||||||
"pre_build": "run-s compile contracts:gen generate_contract_wrappers contracts:copy",
|
"pre_build": "run-s compile generate_contract_wrappers",
|
||||||
"test": "yarn run_mocha",
|
"test": "yarn run_mocha",
|
||||||
"rebuild_and_test": "run-s build test",
|
"rebuild_and_test": "run-s build test",
|
||||||
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
|
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
|
||||||
@@ -21,25 +21,20 @@
|
|||||||
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
|
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
|
||||||
"compile": "sol-compiler",
|
"compile": "sol-compiler",
|
||||||
"watch": "sol-compiler -w",
|
"watch": "sol-compiler -w",
|
||||||
"clean": "shx rm -rf lib test/generated-artifacts test/generated-wrappers generated-artifacts generated-wrappers",
|
"clean": "shx rm -rf lib generated-artifacts generated-wrappers",
|
||||||
"generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output test/generated-wrappers --backend ethers",
|
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers",
|
||||||
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
||||||
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
|
||||||
"coverage:report:text": "istanbul report text",
|
"coverage:report:text": "istanbul report text",
|
||||||
"coverage:report:html": "istanbul report html && open coverage/index.html",
|
"coverage:report:html": "istanbul report html && open coverage/index.html",
|
||||||
"profiler:report:html": "istanbul report html && open coverage/index.html",
|
"profiler:report:html": "istanbul report html && open coverage/index.html",
|
||||||
"coverage:report:lcov": "istanbul report lcov",
|
"coverage:report:lcov": "istanbul report lcov",
|
||||||
"test:circleci": "yarn test",
|
"test:circleci": "yarn test",
|
||||||
"contracts:gen": "contracts-gen generate",
|
"contracts:gen": "contracts-gen",
|
||||||
"contracts:copy": "contracts-gen copy",
|
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol",
|
|
||||||
"compile:truffle": "truffle compile",
|
|
||||||
"docs:md": "ts-doc-gen --sourceDir='$PROJECT_FILES' --output=$MD_FILE_DIR --fileExtension=mdx --tsconfig=./typedoc-tsconfig.json",
|
|
||||||
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
|
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"publicInterfaceContracts": "Coordinator,CoordinatorRegistry,LibCoordinatorApproval,LibCoordinatorRichErrors,LibEIP712CoordinatorDomain,LibConstants",
|
"abis": "./generated-artifacts/@(Coordinator|CoordinatorRegistry).json",
|
||||||
"abis": "./test/generated-artifacts/@(Coordinator|CoordinatorRegistry|ICoordinatorApprovalVerifier|ICoordinatorCore|ICoordinatorRegistryCore|ICoordinatorSignatureValidator|LibConstants|LibCoordinatorApproval|LibCoordinatorRichErrors|LibEIP712CoordinatorDomain|MixinCoordinatorApprovalVerifier|MixinCoordinatorCore|MixinCoordinatorRegistryCore|MixinSignatureValidator).json",
|
|
||||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -52,19 +47,12 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@0x/abi-gen": "^5.1.0",
|
"@0x/abi-gen": "^4.2.1",
|
||||||
"@0x/contracts-asset-proxy": "^3.1.1",
|
"@0x/contracts-gen": "^1.0.15",
|
||||||
"@0x/contracts-dev-utils": "^1.0.4",
|
"@0x/contracts-test-utils": "^3.1.16",
|
||||||
"@0x/contracts-erc20": "^3.0.4",
|
"@0x/dev-utils": "^2.3.3",
|
||||||
"@0x/contracts-exchange": "^3.1.0",
|
"@0x/sol-compiler": "^3.1.15",
|
||||||
"@0x/contracts-gen": "^2.0.4",
|
"@0x/tslint-config": "^3.0.1",
|
||||||
"@0x/contracts-test-utils": "^5.1.1",
|
|
||||||
"@0x/dev-utils": "^3.1.1",
|
|
||||||
"@0x/order-utils": "^10.1.1",
|
|
||||||
"@0x/sol-compiler": "^4.0.4",
|
|
||||||
"@0x/ts-doc-gen": "^0.0.22",
|
|
||||||
"@0x/tslint-config": "^4.0.0",
|
|
||||||
"@0x/web3-wrapper": "^7.0.4",
|
|
||||||
"@types/lodash": "4.14.104",
|
"@types/lodash": "4.14.104",
|
||||||
"@types/mocha": "^5.2.7",
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
@@ -72,28 +60,29 @@
|
|||||||
"chai-as-promised": "^7.1.0",
|
"chai-as-promised": "^7.1.0",
|
||||||
"chai-bignumber": "^3.0.0",
|
"chai-bignumber": "^3.0.0",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"lodash": "^4.17.11",
|
|
||||||
"make-promises-safe": "^1.1.0",
|
"make-promises-safe": "^1.1.0",
|
||||||
"mocha": "^6.2.0",
|
"mocha": "^6.2.0",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
"shx": "^0.2.2",
|
"shx": "^0.2.2",
|
||||||
"solhint": "^1.4.1",
|
"solhint": "^1.4.1",
|
||||||
"truffle": "^5.0.32",
|
|
||||||
"tslint": "5.11.0",
|
"tslint": "5.11.0",
|
||||||
"typedoc": "^0.15.0",
|
|
||||||
"typescript": "3.0.1"
|
"typescript": "3.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@0x/assert": "^3.0.4",
|
"@0x/base-contract": "^5.4.0",
|
||||||
"@0x/base-contract": "^6.1.0",
|
"@0x/contracts-asset-proxy": "^2.2.8",
|
||||||
"@0x/contract-addresses": "^4.3.0",
|
"@0x/contracts-erc20": "^2.2.14",
|
||||||
"@0x/contracts-utils": "^4.1.0",
|
"@0x/contracts-exchange": "^2.1.14",
|
||||||
"@0x/json-schemas": "^5.0.4",
|
"@0x/contracts-exchange-libs": "^3.0.8",
|
||||||
"@0x/types": "^3.1.1",
|
"@0x/contracts-utils": "^3.2.4",
|
||||||
"@0x/typescript-typings": "^5.0.1",
|
"@0x/order-utils": "^8.4.0",
|
||||||
"@0x/utils": "^5.2.0",
|
"@0x/types": "^2.4.3",
|
||||||
"ethereum-types": "^3.0.0",
|
"@0x/typescript-typings": "^4.3.0",
|
||||||
"http-status-codes": "^1.3.2"
|
"@0x/utils": "^4.5.2",
|
||||||
|
"@0x/web3-wrapper": "^6.0.13",
|
||||||
|
"ethereum-types": "^2.1.6",
|
||||||
|
"ethereumjs-util": "^5.1.1",
|
||||||
|
"lodash": "^4.17.11"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|||||||
@@ -7,15 +7,7 @@ import { ContractArtifact } from 'ethereum-types';
|
|||||||
|
|
||||||
import * as Coordinator from '../generated-artifacts/Coordinator.json';
|
import * as Coordinator from '../generated-artifacts/Coordinator.json';
|
||||||
import * as CoordinatorRegistry from '../generated-artifacts/CoordinatorRegistry.json';
|
import * as CoordinatorRegistry from '../generated-artifacts/CoordinatorRegistry.json';
|
||||||
import * as LibConstants from '../generated-artifacts/LibConstants.json';
|
|
||||||
import * as LibCoordinatorApproval from '../generated-artifacts/LibCoordinatorApproval.json';
|
|
||||||
import * as LibCoordinatorRichErrors from '../generated-artifacts/LibCoordinatorRichErrors.json';
|
|
||||||
import * as LibEIP712CoordinatorDomain from '../generated-artifacts/LibEIP712CoordinatorDomain.json';
|
|
||||||
export const artifacts = {
|
export const artifacts = {
|
||||||
Coordinator: Coordinator as ContractArtifact,
|
Coordinator: Coordinator as ContractArtifact,
|
||||||
CoordinatorRegistry: CoordinatorRegistry as ContractArtifact,
|
CoordinatorRegistry: CoordinatorRegistry as ContractArtifact,
|
||||||
LibCoordinatorApproval: LibCoordinatorApproval as ContractArtifact,
|
|
||||||
LibCoordinatorRichErrors: LibCoordinatorRichErrors as ContractArtifact,
|
|
||||||
LibEIP712CoordinatorDomain: LibEIP712CoordinatorDomain as ContractArtifact,
|
|
||||||
LibConstants: LibConstants as ContractArtifact,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,820 +0,0 @@
|
|||||||
import { SendTransactionOpts } from '@0x/base-contract';
|
|
||||||
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
|
|
||||||
import { ExchangeContract } from '@0x/contracts-exchange';
|
|
||||||
import { ExchangeFunctionName } from '@0x/contracts-test-utils';
|
|
||||||
import { devConstants } from '@0x/dev-utils';
|
|
||||||
import { schemas } from '@0x/json-schemas';
|
|
||||||
import { generatePseudoRandomSalt, signatureUtils } from '@0x/order-utils';
|
|
||||||
import { Order, SignedOrder, SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
|
|
||||||
import { BigNumber, fetchAsync } from '@0x/utils';
|
|
||||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
|
||||||
import { CallData, ContractAbi, SupportedProvider, TxData } from 'ethereum-types';
|
|
||||||
import * as HttpStatus from 'http-status-codes';
|
|
||||||
import { flatten } from 'lodash';
|
|
||||||
|
|
||||||
import { artifacts } from '../artifacts';
|
|
||||||
import { CoordinatorContract, CoordinatorRegistryContract } from '../wrappers';
|
|
||||||
|
|
||||||
import { assert } from './utils/assert';
|
|
||||||
import {
|
|
||||||
CoordinatorServerApprovalResponse,
|
|
||||||
CoordinatorServerCancellationResponse,
|
|
||||||
CoordinatorServerError,
|
|
||||||
CoordinatorServerErrorMsg,
|
|
||||||
CoordinatorServerResponse,
|
|
||||||
} from './utils/coordinator_server_types';
|
|
||||||
|
|
||||||
import { decorators } from './utils/decorators';
|
|
||||||
|
|
||||||
export { CoordinatorServerErrorMsg, CoordinatorServerCancellationResponse };
|
|
||||||
|
|
||||||
const DEFAULT_TX_DATA = {
|
|
||||||
gas: devConstants.GAS_LIMIT,
|
|
||||||
gasPrice: new BigNumber(1),
|
|
||||||
value: new BigNumber(150000), // DEFAULT_PROTOCOL_FEE_MULTIPLIER
|
|
||||||
};
|
|
||||||
|
|
||||||
// tx expiration time will be set to (now + default_approval - time_buffer)
|
|
||||||
const DEFAULT_APPROVAL_EXPIRATION_TIME_SECONDS = 90;
|
|
||||||
const DEFAULT_EXPIRATION_TIME_BUFFER_SECONDS = 30;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class includes all the functionality related to filling or cancelling orders through
|
|
||||||
* the 0x V2 Coordinator extension contract.
|
|
||||||
*/
|
|
||||||
export class CoordinatorClient {
|
|
||||||
public abi: ContractAbi = artifacts.Coordinator.compilerOutput.abi;
|
|
||||||
public chainId: number;
|
|
||||||
public address: string;
|
|
||||||
public exchangeAddress: string;
|
|
||||||
public registryAddress: string;
|
|
||||||
|
|
||||||
private readonly _web3Wrapper: Web3Wrapper;
|
|
||||||
private readonly _contractInstance: CoordinatorContract;
|
|
||||||
private readonly _registryInstance: CoordinatorRegistryContract;
|
|
||||||
private readonly _exchangeInstance: ExchangeContract;
|
|
||||||
private readonly _feeRecipientToEndpoint: { [feeRecipient: string]: string } = {};
|
|
||||||
private readonly _txDefaults: CallData = DEFAULT_TX_DATA;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates that the 0x transaction has been approved by all of the feeRecipients that correspond to each order in the transaction's Exchange calldata.
|
|
||||||
* Throws an error if the transaction approvals are not valid. Will not detect failures that would occur when the transaction is executed on the Exchange contract.
|
|
||||||
* @param transaction 0x transaction containing salt, signerAddress, and data.
|
|
||||||
* @param txOrigin Required signer of Ethereum transaction calling this function.
|
|
||||||
* @param transactionSignature Proof that the transaction has been signed by the signer.
|
|
||||||
* @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async assertValidCoordinatorApprovalsOrThrowAsync(
|
|
||||||
transaction: ZeroExTransaction,
|
|
||||||
txOrigin: string,
|
|
||||||
transactionSignature: string,
|
|
||||||
approvalSignatures: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
assert.doesConformToSchema('transaction', transaction, schemas.zeroExTransactionSchema);
|
|
||||||
assert.isETHAddressHex('txOrigin', txOrigin);
|
|
||||||
assert.isHexString('transactionSignature', transactionSignature);
|
|
||||||
for (const approvalSignature of approvalSignatures) {
|
|
||||||
assert.isHexString('approvalSignature', approvalSignature);
|
|
||||||
}
|
|
||||||
return this._contractInstance
|
|
||||||
.assertValidCoordinatorApprovals(transaction, txOrigin, transactionSignature, approvalSignatures)
|
|
||||||
.callAsync();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Instantiate CoordinatorClient
|
|
||||||
* @param web3Wrapper Web3Wrapper instance to use.
|
|
||||||
* @param chainId Desired chainId.
|
|
||||||
* @param address The address of the Coordinator contract. If undefined, will
|
|
||||||
* default to the known address corresponding to the chainId.
|
|
||||||
* @param exchangeAddress The address of the Exchange contract. If undefined, will
|
|
||||||
* default to the known address corresponding to the chainId.
|
|
||||||
* @param registryAddress The address of the CoordinatorRegistry contract. If undefined, will
|
|
||||||
* default to the known address corresponding to the chainId.
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
address: string,
|
|
||||||
provider: SupportedProvider,
|
|
||||||
chainId: number,
|
|
||||||
txDefaults?: Partial<TxData>,
|
|
||||||
exchangeAddress?: string,
|
|
||||||
registryAddress?: string,
|
|
||||||
) {
|
|
||||||
this.chainId = chainId;
|
|
||||||
const contractAddresses = getContractAddressesForChainOrThrow(this.chainId);
|
|
||||||
this.address = address === undefined ? contractAddresses.coordinator : address;
|
|
||||||
this.exchangeAddress = exchangeAddress === undefined ? contractAddresses.exchange : exchangeAddress;
|
|
||||||
this.registryAddress = registryAddress === undefined ? contractAddresses.coordinatorRegistry : registryAddress;
|
|
||||||
this._web3Wrapper = new Web3Wrapper(provider);
|
|
||||||
this._txDefaults = { ...txDefaults, ...DEFAULT_TX_DATA };
|
|
||||||
this._contractInstance = new CoordinatorContract(
|
|
||||||
this.address,
|
|
||||||
this._web3Wrapper.getProvider(),
|
|
||||||
this._web3Wrapper.getContractDefaults(),
|
|
||||||
);
|
|
||||||
this._registryInstance = new CoordinatorRegistryContract(
|
|
||||||
this.registryAddress,
|
|
||||||
this._web3Wrapper.getProvider(),
|
|
||||||
this._web3Wrapper.getContractDefaults(),
|
|
||||||
);
|
|
||||||
this._exchangeInstance = new ExchangeContract(
|
|
||||||
this.exchangeAddress,
|
|
||||||
this._web3Wrapper.getProvider(),
|
|
||||||
this._web3Wrapper.getContractDefaults(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fills a signed order with an amount denominated in baseUnits of the taker asset. Under-the-hood, this
|
|
||||||
* method uses the `feeRecipientAddress` of the order to look up the coordinator server endpoint registered in the
|
|
||||||
* coordinator registry contract. It requests an approval from that coordinator server before
|
|
||||||
* submitting the order and approval as a 0x transaction to the coordinator extension contract. The coordinator extension
|
|
||||||
* contract validates approvals and then fills the order via the Exchange contract.
|
|
||||||
* @param order An object that conforms to the Order interface.
|
|
||||||
* @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
|
|
||||||
* @param signature Signature corresponding to the order.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async fillOrderAsync(
|
|
||||||
order: Order,
|
|
||||||
takerAssetFillAmount: BigNumber,
|
|
||||||
signature: string,
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: Partial<SendTransactionOpts> = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('order', order, schemas.orderSchema);
|
|
||||||
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
ExchangeFunctionName.FillOrder,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
[order],
|
|
||||||
order,
|
|
||||||
takerAssetFillAmount,
|
|
||||||
signature,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to fill a specific amount of an order. If the entire amount specified cannot be filled,
|
|
||||||
* the fill order is abandoned.
|
|
||||||
* @param order An object that conforms to the Order interface.
|
|
||||||
* @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
|
|
||||||
* @param signature Signature corresponding to the order.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async fillOrKillOrderAsync(
|
|
||||||
order: Order,
|
|
||||||
takerAssetFillAmount: BigNumber,
|
|
||||||
signature: string,
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: Partial<SendTransactionOpts> = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('order', order, schemas.orderSchema);
|
|
||||||
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
ExchangeFunctionName.FillOrKillOrder,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
[order],
|
|
||||||
order,
|
|
||||||
takerAssetFillAmount,
|
|
||||||
signature,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Batch version of fillOrderAsync. Executes multiple fills atomically in a single transaction.
|
|
||||||
* If any `feeRecipientAddress` in the batch is not registered to a coordinator server through the CoordinatorRegistryContract, the whole batch fails.
|
|
||||||
* @param orders An array of orders to fill.
|
|
||||||
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
|
|
||||||
* @param signatures Signatures corresponding to the orders.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async batchFillOrdersAsync(
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmounts: BigNumber[],
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts?: Partial<SendTransactionOpts>,
|
|
||||||
): Promise<string> {
|
|
||||||
return this._batchFillAsync(
|
|
||||||
ExchangeFunctionName.BatchFillOrders,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmounts,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* No throw version of batchFillOrdersAsync
|
|
||||||
* @param orders An array of orders to fill.
|
|
||||||
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
|
|
||||||
* @param signatures Signatures corresponding to the orders.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public async batchFillOrdersNoThrowAsync(
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmounts: BigNumber[],
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts?: Partial<SendTransactionOpts>,
|
|
||||||
): Promise<string> {
|
|
||||||
return this._batchFillAsync(
|
|
||||||
ExchangeFunctionName.BatchFillOrdersNoThrow,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmounts,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Batch version of fillOrKillOrderAsync. Executes multiple fills atomically in a single transaction.
|
|
||||||
* @param orders An array of orders to fill.
|
|
||||||
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
|
|
||||||
* @param signatures Signatures corresponding to the orders.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async batchFillOrKillOrdersAsync(
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmounts: BigNumber[],
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts?: Partial<SendTransactionOpts>,
|
|
||||||
): Promise<string> {
|
|
||||||
return this._batchFillAsync(
|
|
||||||
ExchangeFunctionName.BatchFillOrKillOrders,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmounts,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes multiple calls of fillOrder until total amount of makerAsset is bought by taker.
|
|
||||||
* If any fill reverts, the error is caught and ignored. Finally, reverts if < makerAssetFillAmount has been bought.
|
|
||||||
* NOTE: This function does not enforce that the makerAsset is the same for each order.
|
|
||||||
* @param orders Array of order specifications.
|
|
||||||
* @param makerAssetFillAmount Desired amount of makerAsset to buy.
|
|
||||||
* @param signatures Proofs that orders have been signed by makers.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async marketBuyOrdersFillOrKillAsync(
|
|
||||||
orders: Order[],
|
|
||||||
makerAssetFillAmount: BigNumber,
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
return this._marketBuySellOrdersAsync(
|
|
||||||
ExchangeFunctionName.MarketBuyOrdersFillOrKill,
|
|
||||||
orders,
|
|
||||||
makerAssetFillAmount,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No throw version of marketBuyOrdersFillOrKillAsync
|
|
||||||
* @param orders An array of orders to fill.
|
|
||||||
* @param makerAssetFillAmount Maker asset fill amount.
|
|
||||||
* @param signatures Signatures corresponding to the orders.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async marketBuyOrdersNoThrowAsync(
|
|
||||||
orders: Order[],
|
|
||||||
makerAssetFillAmount: BigNumber,
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
return this._marketBuySellOrdersAsync(
|
|
||||||
ExchangeFunctionName.MarketBuyOrdersNoThrow,
|
|
||||||
orders,
|
|
||||||
makerAssetFillAmount,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Executes multiple calls of fillOrder until total amount of takerAsset is sold by taker.
|
|
||||||
* If any fill reverts, the error is caught and ignored. Finally, reverts if < takerAssetFillAmount has been sold.
|
|
||||||
* NOTE: This function does not enforce that the takerAsset is the same for each order.
|
|
||||||
* @param orders Array of order specifications.
|
|
||||||
* @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
|
||||||
* @param signatures Proofs that orders have been signed by makers.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async marketSellOrdersFillOrKillAsync(
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmount: BigNumber,
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
return this._marketBuySellOrdersAsync(
|
|
||||||
ExchangeFunctionName.MarketSellOrdersFillOrKill,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmount,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No throw version of marketSellOrdersAsync
|
|
||||||
* @param orders An array of orders to fill.
|
|
||||||
* @param takerAssetFillAmount Taker asset fill amount.
|
|
||||||
* @param signatures Signatures corresponding to the orders.
|
|
||||||
* @param txData Transaction data. The `from` field should be the user Ethereum address who would like
|
|
||||||
* to fill these orders. Must be available via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async marketSellOrdersNoThrowAsync(
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmount: BigNumber,
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
return this._marketBuySellOrdersAsync(
|
|
||||||
ExchangeFunctionName.MarketSellOrdersNoThrow,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmount,
|
|
||||||
signatures,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels an order on-chain by submitting an Ethereum transaction.
|
|
||||||
* @param order An object that conforms to the Order interface. The order you would like to cancel.
|
|
||||||
* @param txData Transaction data. The `from` field should be the maker's Ethereum address. Must be available
|
|
||||||
* via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async hardCancelOrderAsync(
|
|
||||||
order: Order,
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('order', order, schemas.orderSchema);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
ExchangeFunctionName.CancelOrder,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
[order],
|
|
||||||
order,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Batch version of hardCancelOrderAsync. Cancels orders on-chain by submitting an Ethereum transaction.
|
|
||||||
* Executes multiple cancels atomically in a single transaction.
|
|
||||||
* @param orders An array of orders to cancel.
|
|
||||||
* @param txData Transaction data. The `from` field should be the maker's Ethereum address. Must be available
|
|
||||||
* via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async batchHardCancelOrdersAsync(
|
|
||||||
orders: Order[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
ExchangeFunctionName.BatchCancelOrders,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
orders,
|
|
||||||
orders,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels orders on-chain by submitting an Ethereum transaction.
|
|
||||||
* Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
|
|
||||||
* and senderAddress equal to coordinator extension contract address.
|
|
||||||
* @param targetOrderEpoch Target order epoch.
|
|
||||||
* @param txData Transaction data. The `from` field should be the maker's Ethereum address. Must be available
|
|
||||||
* via the Provider supplied at instantiation.
|
|
||||||
* @param sendTxOpts Optional arguments for sending the transaction.
|
|
||||||
* @return Transaction hash.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async hardCancelOrdersUpToAsync(
|
|
||||||
targetOrderEpoch: BigNumber,
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.isBigNumber('targetOrderEpoch', targetOrderEpoch);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
ExchangeFunctionName.CancelOrdersUpTo,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
[],
|
|
||||||
targetOrderEpoch,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Soft cancel a given order.
|
|
||||||
* Soft cancels are recorded only on coordinator operator servers and do not involve an Ethereum transaction.
|
|
||||||
* See [soft cancels](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/coordinator-specification.md#soft-cancels).
|
|
||||||
* @param order An object that conforms to the Order or SignedOrder interface. The order you would like to cancel.
|
|
||||||
* @return CoordinatorServerCancellationResponse. See [Cancellation Response](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/coordinator-specification.md#response).
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async softCancelAsync(order: Order): Promise<CoordinatorServerCancellationResponse> {
|
|
||||||
assert.doesConformToSchema('order', order, schemas.orderSchema);
|
|
||||||
assert.isETHAddressHex('feeRecipientAddress', order.feeRecipientAddress);
|
|
||||||
assert.isSenderAddressAsync('makerAddress', order.makerAddress, this._web3Wrapper);
|
|
||||||
|
|
||||||
const data = this._exchangeInstance.cancelOrder(order).getABIEncodedTransactionData();
|
|
||||||
const transaction = await this._generateSignedZeroExTransactionAsync(data, order.makerAddress);
|
|
||||||
const endpoint = await this._getServerEndpointOrThrowAsync(order);
|
|
||||||
|
|
||||||
const response = await this._executeServerRequestAsync(transaction, order.makerAddress, endpoint);
|
|
||||||
if (response.isError) {
|
|
||||||
const approvedOrders = new Array();
|
|
||||||
const cancellations = new Array();
|
|
||||||
const errors = [
|
|
||||||
{
|
|
||||||
...response,
|
|
||||||
orders: [order],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
throw new CoordinatorServerError(
|
|
||||||
CoordinatorServerErrorMsg.CancellationFailed,
|
|
||||||
approvedOrders,
|
|
||||||
cancellations,
|
|
||||||
errors,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return response.body as CoordinatorServerCancellationResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Batch version of softCancelOrderAsync. Requests multiple soft cancels
|
|
||||||
* @param orders An array of orders to cancel.
|
|
||||||
* @return CoordinatorServerCancellationResponse. See [Cancellation Response](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/coordinator-specification.md#response).
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async batchSoftCancelAsync(orders: SignedOrder[]): Promise<CoordinatorServerCancellationResponse[]> {
|
|
||||||
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
|
|
||||||
const makerAddress = getMakerAddressOrThrow(orders);
|
|
||||||
assert.isSenderAddressAsync('makerAddress', makerAddress, this._web3Wrapper);
|
|
||||||
const data = this._exchangeInstance.batchCancelOrders(orders).getABIEncodedTransactionData();
|
|
||||||
const transaction = await this._generateSignedZeroExTransactionAsync(data, makerAddress);
|
|
||||||
|
|
||||||
// make server requests
|
|
||||||
const errorResponses: CoordinatorServerResponse[] = [];
|
|
||||||
const successResponses: CoordinatorServerCancellationResponse[] = [];
|
|
||||||
const serverEndpointsToOrders = await this._mapServerEndpointsToOrdersAsync(orders);
|
|
||||||
for (const endpoint of Object.keys(serverEndpointsToOrders)) {
|
|
||||||
const response = await this._executeServerRequestAsync(transaction, makerAddress, endpoint);
|
|
||||||
if (response.isError) {
|
|
||||||
errorResponses.push(response);
|
|
||||||
} else {
|
|
||||||
successResponses.push(response.body as CoordinatorServerCancellationResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no errors
|
|
||||||
if (errorResponses.length === 0) {
|
|
||||||
return successResponses;
|
|
||||||
} else {
|
|
||||||
// lookup orders with errors
|
|
||||||
const errorsWithOrders = errorResponses.map(resp => {
|
|
||||||
const endpoint = resp.coordinatorOperator;
|
|
||||||
const _orders = serverEndpointsToOrders[endpoint];
|
|
||||||
return {
|
|
||||||
...resp,
|
|
||||||
orders: _orders,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const approvedOrders = new Array();
|
|
||||||
const cancellations = successResponses;
|
|
||||||
// return errors and approvals
|
|
||||||
throw new CoordinatorServerError(
|
|
||||||
CoordinatorServerErrorMsg.CancellationFailed,
|
|
||||||
approvedOrders,
|
|
||||||
cancellations,
|
|
||||||
errorsWithOrders,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recovers the address of a signer given a hash and signature.
|
|
||||||
* @param hash Any 32 byte hash.
|
|
||||||
* @param signature Proof that the hash has been signed by signer.
|
|
||||||
* @returns Signer address.
|
|
||||||
*/
|
|
||||||
@decorators.asyncZeroExErrorHandler
|
|
||||||
public async getSignerAddressAsync(hash: string, signature: string): Promise<string> {
|
|
||||||
assert.isHexString('hash', hash);
|
|
||||||
assert.isHexString('signature', signature);
|
|
||||||
const signerAddress = await this._contractInstance.getSignerAddress(hash, signature).callAsync();
|
|
||||||
return signerAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _marketBuySellOrdersAsync(
|
|
||||||
exchangeFn: ExchangeFunctionName,
|
|
||||||
orders: Order[],
|
|
||||||
assetFillAmount: BigNumber,
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
|
|
||||||
assert.isBigNumber('assetFillAmount', assetFillAmount);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
exchangeFn,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
orders,
|
|
||||||
orders,
|
|
||||||
assetFillAmount,
|
|
||||||
signatures,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _batchFillAsync(
|
|
||||||
exchangeFn: ExchangeFunctionName,
|
|
||||||
orders: Order[],
|
|
||||||
takerAssetFillAmounts: BigNumber[],
|
|
||||||
signatures: string[],
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
|
|
||||||
): Promise<string> {
|
|
||||||
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
|
|
||||||
takerAssetFillAmounts.forEach(takerAssetFillAmount =>
|
|
||||||
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount),
|
|
||||||
);
|
|
||||||
return this._executeTxThroughCoordinatorAsync(
|
|
||||||
exchangeFn,
|
|
||||||
txData,
|
|
||||||
sendTxOpts,
|
|
||||||
orders,
|
|
||||||
orders,
|
|
||||||
takerAssetFillAmounts,
|
|
||||||
signatures,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _executeTxThroughCoordinatorAsync(
|
|
||||||
exchangeFn: ExchangeFunctionName,
|
|
||||||
txData: TxData,
|
|
||||||
sendTxOpts: Partial<SendTransactionOpts>,
|
|
||||||
ordersNeedingApprovals: Order[],
|
|
||||||
...args: any[] // tslint:disable-line:trailing-comma
|
|
||||||
): Promise<string> {
|
|
||||||
assert.isETHAddressHex('takerAddress', txData.from);
|
|
||||||
await assert.isSenderAddressAsync('takerAddress', txData.from, this._web3Wrapper);
|
|
||||||
|
|
||||||
// get ABI encoded transaction data for the desired exchange method
|
|
||||||
const data = (this._exchangeInstance as any)[exchangeFn](...args).getABIEncodedTransactionData();
|
|
||||||
|
|
||||||
// generate and sign a ZeroExTransaction
|
|
||||||
const signedZrxTx = await this._generateSignedZeroExTransactionAsync(data, txData.from, txData.gasPrice);
|
|
||||||
|
|
||||||
// get approval signatures from registered coordinator operators
|
|
||||||
const approvalSignatures = await this._getApprovalsAsync(signedZrxTx, ordersNeedingApprovals, txData.from);
|
|
||||||
|
|
||||||
// execute the transaction through the Coordinator Contract
|
|
||||||
const txDataWithDefaults = {
|
|
||||||
...this._txDefaults,
|
|
||||||
...txData, // override defaults
|
|
||||||
};
|
|
||||||
const txHash = this._contractInstance
|
|
||||||
.executeTransaction(signedZrxTx, txData.from, signedZrxTx.signature, approvalSignatures)
|
|
||||||
.sendTransactionAsync(txDataWithDefaults, sendTxOpts);
|
|
||||||
return txHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _generateSignedZeroExTransactionAsync(
|
|
||||||
data: string,
|
|
||||||
signerAddress: string,
|
|
||||||
gasPrice?: BigNumber | string | number,
|
|
||||||
): Promise<SignedZeroExTransaction> {
|
|
||||||
const transaction: ZeroExTransaction = {
|
|
||||||
salt: generatePseudoRandomSalt(),
|
|
||||||
signerAddress,
|
|
||||||
data,
|
|
||||||
domain: {
|
|
||||||
verifyingContract: this.exchangeAddress,
|
|
||||||
chainId: await this._web3Wrapper.getChainIdAsync(),
|
|
||||||
},
|
|
||||||
expirationTimeSeconds: new BigNumber(
|
|
||||||
Math.floor(Date.now() / 1000) +
|
|
||||||
DEFAULT_APPROVAL_EXPIRATION_TIME_SECONDS -
|
|
||||||
DEFAULT_EXPIRATION_TIME_BUFFER_SECONDS,
|
|
||||||
),
|
|
||||||
gasPrice: gasPrice ? new BigNumber(gasPrice) : new BigNumber(1),
|
|
||||||
};
|
|
||||||
const signedZrxTx = await signatureUtils.ecSignTransactionAsync(
|
|
||||||
this._web3Wrapper.getProvider(),
|
|
||||||
transaction,
|
|
||||||
transaction.signerAddress,
|
|
||||||
);
|
|
||||||
return signedZrxTx;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _getApprovalsAsync(
|
|
||||||
transaction: SignedZeroExTransaction,
|
|
||||||
orders: Order[],
|
|
||||||
txOrigin: string,
|
|
||||||
): Promise<string[]> {
|
|
||||||
const coordinatorOrders = orders.filter(o => o.senderAddress === this.address);
|
|
||||||
if (coordinatorOrders.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const serverEndpointsToOrders = await this._mapServerEndpointsToOrdersAsync(coordinatorOrders);
|
|
||||||
|
|
||||||
// make server requests
|
|
||||||
const errorResponses: CoordinatorServerResponse[] = [];
|
|
||||||
const approvalResponses: CoordinatorServerResponse[] = [];
|
|
||||||
for (const endpoint of Object.keys(serverEndpointsToOrders)) {
|
|
||||||
const response = await this._executeServerRequestAsync(transaction, txOrigin, endpoint);
|
|
||||||
if (response.isError) {
|
|
||||||
errorResponses.push(response);
|
|
||||||
} else {
|
|
||||||
approvalResponses.push(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no errors
|
|
||||||
if (errorResponses.length === 0) {
|
|
||||||
// concatenate all approval responses
|
|
||||||
return approvalResponses.reduce(
|
|
||||||
(accumulator, response) =>
|
|
||||||
accumulator.concat((response.body as CoordinatorServerApprovalResponse).signatures),
|
|
||||||
[] as string[],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// format errors and approvals
|
|
||||||
// concatenate approvals
|
|
||||||
const notCoordinatorOrders = orders.filter(o => o.senderAddress !== this.address);
|
|
||||||
const approvedOrdersNested = approvalResponses.map(resp => {
|
|
||||||
const endpoint = resp.coordinatorOperator;
|
|
||||||
return serverEndpointsToOrders[endpoint];
|
|
||||||
});
|
|
||||||
const approvedOrders = flatten(approvedOrdersNested.concat(notCoordinatorOrders));
|
|
||||||
|
|
||||||
// lookup orders with errors
|
|
||||||
const errorsWithOrders = errorResponses.map(resp => {
|
|
||||||
const endpoint = resp.coordinatorOperator;
|
|
||||||
return {
|
|
||||||
...resp,
|
|
||||||
orders: serverEndpointsToOrders[endpoint],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// throw informative error
|
|
||||||
const cancellations = new Array();
|
|
||||||
throw new CoordinatorServerError(
|
|
||||||
CoordinatorServerErrorMsg.FillFailed,
|
|
||||||
approvedOrders,
|
|
||||||
cancellations,
|
|
||||||
errorsWithOrders,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _getServerEndpointOrThrowAsync(order: Order): Promise<string> {
|
|
||||||
const cached = this._feeRecipientToEndpoint[order.feeRecipientAddress];
|
|
||||||
const endpoint =
|
|
||||||
cached !== undefined
|
|
||||||
? cached
|
|
||||||
: await _fetchServerEndpointOrThrowAsync(order.feeRecipientAddress, this._registryInstance);
|
|
||||||
return endpoint;
|
|
||||||
|
|
||||||
async function _fetchServerEndpointOrThrowAsync(
|
|
||||||
feeRecipient: string,
|
|
||||||
registryInstance: CoordinatorRegistryContract,
|
|
||||||
): Promise<string> {
|
|
||||||
const coordinatorOperatorEndpoint = await registryInstance.getCoordinatorEndpoint(feeRecipient).callAsync();
|
|
||||||
if (coordinatorOperatorEndpoint === '' || coordinatorOperatorEndpoint === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`No Coordinator server endpoint found in Coordinator Registry for feeRecipientAddress: ${feeRecipient}. Registry contract address: [${
|
|
||||||
registryInstance.address
|
|
||||||
}] Order: [${JSON.stringify(order)}]`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return coordinatorOperatorEndpoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _executeServerRequestAsync(
|
|
||||||
signedTransaction: SignedZeroExTransaction,
|
|
||||||
txOrigin: string,
|
|
||||||
endpoint: string,
|
|
||||||
): Promise<CoordinatorServerResponse> {
|
|
||||||
const requestPayload = {
|
|
||||||
signedTransaction,
|
|
||||||
txOrigin,
|
|
||||||
};
|
|
||||||
const response = await fetchAsync(`${endpoint}/v2/request_transaction?chainId=${this.chainId}`, {
|
|
||||||
body: JSON.stringify(requestPayload),
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isError = response.status !== HttpStatus.OK;
|
|
||||||
const isValidationError = response.status === HttpStatus.BAD_REQUEST;
|
|
||||||
const json = isError && !isValidationError ? undefined : await response.json();
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
isError,
|
|
||||||
status: response.status,
|
|
||||||
body: isError ? undefined : json,
|
|
||||||
error: isError ? json : undefined,
|
|
||||||
request: requestPayload,
|
|
||||||
coordinatorOperator: endpoint,
|
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _mapServerEndpointsToOrdersAsync(
|
|
||||||
coordinatorOrders: Order[],
|
|
||||||
): Promise<{ [endpoint: string]: Order[] }> {
|
|
||||||
const groupByFeeRecipient: { [feeRecipient: string]: Order[] } = {};
|
|
||||||
for (const order of coordinatorOrders) {
|
|
||||||
const feeRecipient = order.feeRecipientAddress;
|
|
||||||
if (groupByFeeRecipient[feeRecipient] === undefined) {
|
|
||||||
groupByFeeRecipient[feeRecipient] = [] as Order[];
|
|
||||||
}
|
|
||||||
groupByFeeRecipient[feeRecipient].push(order);
|
|
||||||
}
|
|
||||||
const serverEndpointsToOrders: { [endpoint: string]: Order[] } = {};
|
|
||||||
for (const orders of Object.values(groupByFeeRecipient)) {
|
|
||||||
const endpoint = await this._getServerEndpointOrThrowAsync(orders[0]);
|
|
||||||
if (serverEndpointsToOrders[endpoint] === undefined) {
|
|
||||||
serverEndpointsToOrders[endpoint] = [];
|
|
||||||
}
|
|
||||||
serverEndpointsToOrders[endpoint] = serverEndpointsToOrders[endpoint].concat(orders);
|
|
||||||
}
|
|
||||||
return serverEndpointsToOrders;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMakerAddressOrThrow(orders: Array<Order | SignedOrder>): string {
|
|
||||||
const uniqueMakerAddresses = new Set(orders.map(o => o.makerAddress));
|
|
||||||
if (uniqueMakerAddresses.size > 1) {
|
|
||||||
throw new Error(`All orders in a batch must have the same makerAddress`);
|
|
||||||
}
|
|
||||||
return orders[0].makerAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
// tslint:disable:max-file-line-count
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user