Compare commits

..

115 Commits

Author SHA1 Message Date
Github Actions
85bcf87af8 Publish
- @0x/asset-swapper@16.49.5
2022-02-14 13:12:38 +00:00
Github Actions
a0fe1c610f Updated CHANGELOGS & MD docs 2022-02-14 13:12:35 +00:00
Kim Persson
5d21af1a0a fix: 1 base unit output amount being scale down, rounding to 0 output (#422)
* fix: 1 base unit output amount being scale down, rounding to 0 output

* chore: add asset-swapper changelog entry

* fix: round scaled output to base units before clamping
2022-02-14 13:54:53 +01:00
Jacob Evans
f6edbd210c Update protocol docs (#421)
* Update protocol docs

* Added functions

* fix table

* eligbility section?

* Trader.xyz shoutout

* Up to
2022-02-11 22:53:49 +10:00
Github Actions
e084807a8f Publish
- @0x/asset-swapper@16.49.4
2022-02-10 15:34:41 +00:00
Github Actions
1c7d512829 Updated CHANGELOGS & MD docs 2022-02-10 15:34:38 +00:00
Kim Persson
df0e0866e4 fix: Revert Improve Uniswap V3 gas schedule (#397) (#419)
* Revert "feat: Improve Uniswap V3 gas schedule (#397)"

This reverts commit 84e4819e6e.

* chore: Add changelog entry
2022-02-10 16:15:54 +01:00
Github Actions
9e6efc3676 Publish
- @0x/asset-swapper@16.49.3
2022-02-10 12:12:08 +00:00
Github Actions
3aef29dace Updated CHANGELOGS & MD docs 2022-02-10 12:12:05 +00:00
Kim Persson
9a16e00577 fix: router RFQ underutilization (#413)
* fix: pass EP overhead to Path & use path comparison all & vip routes

* chore: add changelog entry for asset-swapper
2022-02-10 12:55:30 +01:00
Kim Persson
84e4819e6e feat: Improve Uniswap V3 gas schedule (#397)
* feat: UniswapV3Sampler use QuoterV2 for sells WIP

* feat: UniswapV3Sampler for QuoterV2 buys WIP

* refactor: separate logic to remove stack too deep issue

* feat: Use initializedTicksCrossed from Uniswap QuoterV2 for gas est.

* fix: use Quoter gasUsed instead of estimating gas from pools + ticks

* refactor: clean up UniswapV3Sampler & remove old Quoter interface

* refactor: unify code for buys and sells while handling stack too deep

* fix: use mean gas price from all sample estimating UniV3 gas schedule

* fix: fallback to legacy Uniswap V3 gas estimate if we can't get gasUsed

* refactor: use named function instead of fat arrow

* chore: add asset-swapper changelog entry
2022-02-10 11:16:24 +01:00
Kim Persson
25dd6bc79a fix: incorrect output scaling when input is less than desired amount (#401)
* fix: incorrect output scaling when input is less than desired amount

* chore: bump fast-abi

* chore: add changelog entry for asset-swapper
2022-02-10 10:43:44 +01:00
Jacob Evans
5d2cdb00c2 fix: slippage inconsistency when recalculated in exchange proxy quote consumer (#412)
* fix: Pass slippage down rather than recalculate due to accuracy

* CHANGELOG
2022-02-04 10:37:38 +10:00
Github Actions
0f701f42d3 Publish
- @0x/asset-swapper@16.49.2
2022-01-31 18:24:47 +00:00
Github Actions
3e3e82d3f7 Updated CHANGELOGS & MD docs 2022-01-31 18:24:44 +00:00
Lawrence Forman
c57bf86273 Fix ABI encoding error with two hop buys due to applying slippage to uint(-1) values (#410)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-01-31 12:51:17 -05:00
Github Actions
f470d282ee Publish
- @0x/asset-swapper@16.49.1
2022-01-31 07:20:03 +00:00
Github Actions
b8a2526da5 Updated CHANGELOGS & MD docs 2022-01-31 07:19:59 +00:00
Jacob Evans
97575bbde9 fix: worstCaseQuoteInfo calculating buys incorrectly [TKR-296] (#402)
* fix: WorstCaseQuoteInfo buy encoding

* CHANGELOG
2022-01-31 17:01:17 +10:00
Github Actions
e5ed8b2c81 Publish
- @0x/asset-swapper@16.49.0
2022-01-28 22:11:46 +00:00
Github Actions
61fbae3ae2 Updated CHANGELOGS & MD docs 2022-01-28 22:11:42 +00:00
Shawn
5c2255c841 feat: add curve pools (#409)
* feat: Additional Curve pools

* more pools

* fix the format

* changlog

* lowercase address

Co-authored-by: Jacob Evans <jacob@dekz.net>
2022-01-28 12:08:28 -08:00
Github Actions
e036dee6c5 Publish
- @0x/asset-swapper@16.48.0
2022-01-25 22:00:25 +00:00
Github Actions
8583aab241 Updated CHANGELOGS & MD docs 2022-01-25 22:00:21 +00:00
Jacob Evans
5d05b62821 chore: Use MIM on Fantom as an intermediary asset (#405) 2022-01-26 07:42:29 +10:00
Github Actions
0063e8178f Publish
- @0x/asset-swapper@16.47.0
2022-01-25 18:51:07 +00:00
Github Actions
ec6e5dd517 Updated CHANGELOGS & MD docs 2022-01-25 18:51:04 +00:00
Noah Khamliche
9d08fefa1c Feat/synapse (#400)
* added synapse support
2022-01-25 13:21:07 -05:00
Github Actions
2fdca24d4e Publish
- @0x/asset-swapper@16.46.0
2022-01-11 01:10:02 +00:00
Github Actions
42ec0b144e Updated CHANGELOGS & MD docs 2022-01-11 01:09:58 +00:00
Jacob Evans
3f6ce78b46 chore: Enable Curve ETH/CVX (#394)
* chore: Enable Curve ETH/CVX

* pr number
2022-01-11 09:32:07 +10:00
Github Actions
c1300c1068 Publish
- @0x/asset-swapper@16.45.2
2022-01-10 15:09:26 +00:00
Github Actions
9a641cfab6 Updated CHANGELOGS & MD docs 2022-01-10 15:09:23 +00:00
Kim Persson
60345d4465 fix: don't create fills for 0 output samples and negative adjusted rate orders (#387)
* fix: don't try to create fills for 0 output samples

* fix: negative adjusted output native orders causing undefined fills

* fix: make sure to use the same sourcePathId for fills from same source

* fix: should be same sourcePathId within the same DexSample[]

* fix: split native orders into 13 samples to align with interpolation

* chore: add changelog entry for asset-swapper
2022-01-10 14:55:03 +01:00
Github Actions
11dfea47a6 Publish
- @0x/asset-swapper@16.45.1
2022-01-05 05:08:43 +00:00
Github Actions
55e9dd39a2 Updated CHANGELOGS & MD docs 2022-01-05 05:08:41 +00:00
Jacob Evans
1993929bed chore: Celo Update certain tokens since Optics v2 (#390)
* chore: Celo Update certain tokens since Optics v2

* Changelog
2022-01-05 14:44:29 +10:00
Oskar Paolini
e1d81de517 fixes axios object dumping in logs (#345) 2022-01-05 09:46:01 +10:00
Github Actions
a6b3a21635 Publish
- @0x/asset-swapper@16.45.0
2022-01-04 15:00:16 +00:00
Github Actions
fd59cdc2db Updated CHANGELOGS & MD docs 2022-01-04 15:00:13 +00:00
Jacob Evans
98e11b5189 feat: Capture Routing timing metrics (#388) 2022-01-04 15:42:14 +01:00
Github Actions
3bebc7cd62 Publish
- @0x/asset-swapper@16.44.0
2021-12-29 11:45:33 +00:00
Github Actions
56dab6ae8c Updated CHANGELOGS & MD docs 2021-12-29 11:45:30 +00:00
Kim Persson
285f98e9e9 feat: Udate neon-router and use router estimated output amount (#354)
* feat: use Rust router estimated output amount when possible

* fix: use strings for sample ids, and increase samples in the rust router

* fix: remove unnecessary interpolation of out of range values

* fix: don't recalculate sampled dist sum in a loop

* fix: use 14 samples for rust router to work around interpolation issues

* fix: unintentional logic change

* fix: remove local dev plotting param from route fn call

* feat: make neon-router number of samples configurable

* chore: bump to newly published neon-router version

* fix: handle insufficient liquidity at all requested sources

* chore: update asset-swapper changelog
2021-12-29 12:08:24 +01:00
Github Actions
8ae9f59f20 Publish
- @0x/contracts-erc20@3.3.25
 - @0x/contracts-test-utils@5.4.16
 - @0x/contracts-treasury@1.4.8
 - @0x/contracts-utils@4.8.6
 - @0x/contracts-zero-ex@0.30.1
 - @0x/asset-swapper@16.43.0
 - @0x/contract-addresses@6.11.0
 - @0x/contract-wrappers@13.18.5
 - @0x/migrations@8.1.14
 - @0x/protocol-utils@1.10.1
2021-12-24 16:45:24 +00:00
Github Actions
4c341c5ca3 Updated CHANGELOGS & MD docs 2021-12-24 16:45:21 +00:00
Shawn
a3c912c2af feat/optimism [TKR-280] (#385)
* rebase and remove WIP Clipper new weth router test

* remove clipper test

* restore from clipper test

* add uniswapV3 on optimism

* modify token addresses and add EP-related addresses on optimism

* prettier

* modify CHANGLOG.json

* convert addresses to lowercase

* remove testnet addresses

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
2021-12-24 08:28:06 -08:00
Github Actions
5e72eb9af9 Publish
- @0x/asset-swapper@16.42.0
2021-12-21 22:02:45 +00:00
Github Actions
9b08b73c06 Updated CHANGELOGS & MD docs 2021-12-21 22:02:41 +00:00
Jacob Evans
76c7eb7c3e fix: Beethovenx graphql endpoint (#383) 2021-12-22 07:44:25 +10:00
Jacob Evans
9b2e5a3adb fix: PR number in CHANGELOG 2021-12-22 08:11:28 +11:00
Jacob Evans
813d703d12 feat: UniswapV3 on Polygon (#382) 2021-12-22 07:10:21 +10:00
Github Actions
83005d0f3d Publish
- @0x/asset-swapper@16.41.0
2021-12-06 21:48:27 +00:00
Github Actions
d07ffd2688 Updated CHANGELOGS & MD docs 2021-12-06 21:48:24 +00:00
Noah Khamliche
4170f970d0 Sushi router celo fix (#376)
* Updated Sushiswap router on CELO 

Sushi address in the docs was incorrect, this is the correct address `0x1421bDe4B10e8dd459b3BCb598810B1337D56842`.

* address to lowercase

* Update CHANGELOG.json

* fixed sushi router address, replaced celo ref with wcelo, fixed mcusd address

* celo->wcelo

* Update packages/asset-swapper/CHANGELOG.json

Co-authored-by: Jacob Evans <jacob@dekz.net>

* changelog

* version bump

Co-authored-by: Jacob Evans <jacob@dekz.net>
2021-12-06 13:31:45 -08:00
Github Actions
dcde12dd70 Publish
- @0x/contracts-erc20@3.3.24
 - @0x/contracts-test-utils@5.4.15
 - @0x/contracts-treasury@1.4.7
 - @0x/contracts-utils@4.8.5
 - @0x/contracts-zero-ex@0.30.0
 - @0x/asset-swapper@16.40.0
 - @0x/contract-addresses@6.10.0
 - @0x/contract-wrappers@13.18.4
 - @0x/migrations@8.1.13
 - @0x/protocol-utils@1.10.0
2021-12-01 20:22:43 +00:00
Github Actions
84a60ec982 Updated CHANGELOGS & MD docs 2021-12-01 20:22:39 +00:00
Kim Persson
9615570dc6 feat: deploy interest tokens (#321)
* feat: Aave aToken deposit/withdrawal [TKR-111] (#293)

* feat: AaveV2 deposit/withdrawal integration WIP

* feat: add basic Aave Reserves cache with data from subgraphs WIP

* feat: hook up Aave Reserves integration

* fix: set allowance before trade & use ERC20 token interface

* refactor: pass aToken to mixin to avoid lookup

* fix: migrate from swap/revert to normal sampling

* fix: Aave gas estimate & refactor to clean up code

* feat: Create a sampler no operation type and make AaveV2Sampler a no-op

* fix: Clipper merge conflict resolution issues

* fix: don't fetch unnecessary Aave pool data & clean up code

* chore: Add changelog entries

* feat: cToken deposit/withdrawal [TKR-222] (#294)

* feat: first stab at a CompoundSampler implementation

* feat: MixinCompound implementation WIP

* feat: Compound integration with cache WIP

* fix: decimals scaling in CompoundSampler

* feat: handle minting and redeeming of cETH

* fix: adjust Compound gas schedule

* refactor: clean up code and add comments in cToken cache

* fix: MixinCompound check allowance on WETH withdrawal & fix indentation

* fix: address review comments and clean up code

* chore: add changelog entries

* feat: enable AaveV2 on Avalanche

* chore: add freshly deployed FQT on Polygon, Avalanche

* fix: temporarily disable on Ethereum mainnet until we redeploy EP

* fix: address PR comments and update changelogs

* fix: correct contract-addresses changelog note
2021-12-01 17:10:22 +01:00
Jacob Evans
880a9c3da0 chore: Curve added ETH/CRV pool (#378) 2021-12-01 14:51:47 +10:00
Jacob Evans
c44bd9d42d Revert "chore: Curve added ETH/CRV pool"
This reverts commit 90b441330b.
2021-12-01 14:19:49 +10:00
Jacob Evans
90b441330b chore: Curve added ETH/CRV pool 2021-12-01 14:17:40 +10:00
Github Actions
e12ed1eddf Publish
- @0x/asset-swapper@16.38.0
2021-11-29 23:23:57 +00:00
Github Actions
ac94023ab3 Updated CHANGELOGS & MD docs 2021-11-29 23:23:54 +00:00
Jacob Evans
281e6acca5 chore: Add ability to capture sampler metrics (#374)
* chore: Add ability to capture sampler metrics

* Added block number metrics
2021-11-30 09:06:05 +10:00
Github Actions
2f1b520409 Publish
- @0x/asset-swapper@16.37.0
2021-11-19 19:15:43 +00:00
Github Actions
21b4eb3d26 Updated CHANGELOGS & MD docs 2021-11-19 19:15:40 +00:00
Noah Khamliche
644f6c7d28 removed comma 2021-11-19 13:46:57 -05:00
Noah Khamliche
0647b9e4f8 Update CHANGELOG.json 2021-11-19 13:46:57 -05:00
Noah Khamliche
82d42eeede address to lowercase 2021-11-19 13:46:57 -05:00
Noah Khamliche
6ef4d95043 Updated Sushiswap router on CELO
Sushi address in the docs was incorrect, this is the correct address `0x1421bDe4B10e8dd459b3BCb598810B1337D56842`.
2021-11-19 13:46:57 -05:00
Github Actions
6044140f86 Publish
- @0x/asset-swapper@16.36.0
2021-11-19 02:59:33 +00:00
Github Actions
4da1ef0f56 Updated CHANGELOGS & MD docs 2021-11-19 02:59:30 +00:00
Jacob Evans
8c668a3918 feat: Specify FEI/TRIBE liquid pool (#371)
* feat: Specify FEI/TRIBE liquid pool

* CHANGELOG

* FXS/FRAX and OHM/FRAX
2021-11-18 15:39:07 +10:00
Github Actions
f1ff1cde39 Publish
- @0x/asset-swapper@16.35.0
2021-11-18 03:31:36 +00:00
Github Actions
1668a24e31 Updated CHANGELOGS & MD docs 2021-11-18 03:31:32 +00:00
Shawn
4b7c376d96 feat: Add Beethoven X, MorpheusSwap and JetSwap on Fantom (#370)
* Rebase to development branch

* add support for MorpheusSwap and JetSwap on Fantom

* fix lint

* modify changelog.json for asset-swapper

* fix the comments

* prettier

* Use BalancerV2PoolsCache for BeethovenX

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
2021-11-17 19:14:01 -08:00
Github Actions
bb4a9c656c Publish
- @0x/contracts-erc20@3.3.23
 - @0x/contracts-test-utils@5.4.14
 - @0x/contracts-treasury@1.4.6
 - @0x/contracts-utils@4.8.4
 - @0x/contracts-zero-ex@0.29.5
 - @0x/asset-swapper@16.34.0
 - @0x/contract-addresses@6.9.0
 - @0x/contract-wrappers@13.18.3
 - @0x/migrations@8.1.12
 - @0x/protocol-utils@1.9.5
2021-11-16 22:49:46 +00:00
Github Actions
6ab07b6304 Updated CHANGELOGS & MD docs 2021-11-16 22:49:43 +00:00
Noah Khamliche
8903f1ab01 Update packages/contract-addresses/CHANGELOG.json
Co-authored-by: Lawrence Forman <lawrence@0xproject.com>
2021-11-16 16:55:57 -05:00
Noah Khamliche
415535612a removed duplicate celo code 2021-11-16 16:55:57 -05:00
Noah Khamliche
5248a135c3 upped versions in changelog 2021-11-16 16:55:57 -05:00
Lawrence Forman
602290925c fix celo rebase 2021-11-16 16:55:57 -05:00
Github Actions
01813746e8 Publish
- @0x/contracts-zero-ex@0.29.4
 - @0x/asset-swapper@16.33.0
 - @0x/migrations@8.1.11
2021-11-16 12:27:06 +00:00
Github Actions
7d668d8801 Updated CHANGELOGS & MD docs 2021-11-16 12:27:02 +00:00
Jacob Evans
797a00a33a feat: Uniswap V3 1bps pools [TKR-263] (#366)
* feat: Uniswap V3 1bps pools

* Update CHANGELOG
2021-11-16 08:15:24 +10:00
Lawrence Forman
4b3d98f43c @0x/contracts-zero-ex: Prevent EP ETH balance from reducing when executin mtxs (#365)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2021-11-09 22:11:36 -05:00
Github Actions
9ff77c1cd5 Publish
- @0x/asset-swapper@16.32.0
2021-11-09 19:36:14 +00:00
Github Actions
18a8351671 Updated CHANGELOGS & MD docs 2021-11-09 19:36:10 +00:00
Jorge Pérez
9a994dfcd3 fix: Extended Quote Report Changelog typo 2021-11-09 13:17:14 -06:00
Jorge Pérez
b7adc5a889 feat: Extended Quote Report
* Extended Quote report for indicative quote

* feat: Only save 'full' quotes on quote report

* Unify extended quote report
2021-11-09 13:05:01 -06:00
Github Actions
10b0d7f363 Publish
- @0x/asset-swapper@16.31.0
2021-11-04 06:52:28 +00:00
Github Actions
e2c905a15f Updated CHANGELOGS & MD docs 2021-11-04 06:52:25 +00:00
Jacob Evans
8589ba728c feat: [Avalanche] Add Curve, CurveV2 and KyberDMM (#363)
* feat: [Avalanche] Add Curve, CurveV2 and KyberDMM

* CHANGELOG

* fix missing file

* lint
2021-11-04 16:34:48 +10:00
Github Actions
43512fd07a Publish
- @0x/contracts-erc20@3.3.22
 - @0x/contracts-test-utils@5.4.13
 - @0x/contracts-treasury@1.4.5
 - @0x/contracts-utils@4.8.3
 - @0x/contracts-zero-ex@0.29.3
 - @0x/asset-swapper@16.30.1
 - @0x/contract-addresses@6.8.1
 - @0x/contract-wrappers@13.18.2
 - @0x/migrations@8.1.10
 - @0x/protocol-utils@1.9.4
2021-11-03 01:40:34 +00:00
Github Actions
c090608d99 Updated CHANGELOGS & MD docs 2021-11-03 01:40:30 +00:00
phil-ociraptor
89817428ed chore: add OtcOrder feature to fullMigrateAsync (#350) 2021-11-02 20:19:27 -05:00
Lawrence Forman
fce3664258 @0x/contracts-zero-ex: Register transformERC20() and remove transformERC20Staging() (#355)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2021-10-25 20:08:58 -04:00
Github Actions
aa522fe49b Publish
- @0x/contracts-erc20@3.3.21
 - @0x/contracts-test-utils@5.4.12
 - @0x/contracts-treasury@1.4.4
 - @0x/contracts-utils@4.8.2
 - @0x/contracts-zero-ex@0.29.2
 - @0x/asset-swapper@16.30.0
 - @0x/contract-addresses@6.8.0
 - @0x/contract-wrappers@13.18.1
 - @0x/migrations@8.1.9
 - @0x/protocol-utils@1.9.3
2021-10-19 18:27:29 +00:00
Github Actions
c03653ebd7 Updated CHANGELOGS & MD docs 2021-10-19 18:27:25 +00:00
Shawn
ae08f77381 Feat/ftm (#347)
* ftm deployment

* add Fantom Curve

* add support for ftm

* add more Fantom liquidity sources

* clean up codes

* lint

* prettier codes

* modify CHANGLOG

* undo some changes

* use lowercase addresses

* Update EP FlashWallet

* Update addresses and remove timestamps

Co-authored-by: Jacob Evans <jacob@dekz.net>

* Cleanup

* cleanup json

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
Co-authored-by: Jacob Evans <jacob@dekz.net>
2021-10-19 09:51:07 -07:00
Github Actions
73a07e512d Publish
- @0x/asset-swapper@16.29.3
2021-10-18 10:36:39 +00:00
Github Actions
7cff09f40a Updated CHANGELOGS & MD docs 2021-10-18 10:36:36 +00:00
Kim Persson
a6d690f10a chore: update to new router version and address breaking changes (#344)
* chore: update to new router version and address breaking changes

* chore: add changelog entry
2021-10-18 11:15:31 +01:00
Github Actions
d7cff52e75 Publish
- @0x/contracts-treasury@1.4.3
 - @0x/asset-swapper@16.29.2
2021-10-13 17:44:45 +00:00
Github Actions
cf1f29a37d Updated CHANGELOGS & MD docs 2021-10-13 17:44:41 +00:00
mzhu25
9af22110b4 Chore: go back to using transformERC20 in AS (#343)
* go back to using transformERC20

* Update changelog
2021-10-12 22:47:29 -07:00
mzhu25
2c187c7e85 Add Proposal 2 and test (#339) 2021-10-08 13:04:09 -07:00
Phạm Minh Đức
d46756ae2e fix(asset-swapper): Check MAX_IN_RATIO in sampleBuysFromBalancer (#338)
* fix: for swapExactAmountIn

* chore: update change log

* Update packages/asset-swapper/CHANGELOG.json

Co-authored-by: Lawrence Forman <lawrence@0xproject.com>
2021-10-05 16:25:02 -04:00
Github Actions
d9a16ed1f9 Publish
- @0x/contracts-treasury@1.4.2
 - @0x/contracts-zero-ex@0.29.1
 - @0x/asset-swapper@16.29.1
 - @0x/migrations@8.1.8
 - @0x/protocol-utils@1.9.2
2021-10-04 19:01:10 +00:00
Github Actions
57a1120997 Updated CHANGELOGS & MD docs 2021-10-04 19:01:06 +00:00
Romain Butteaud
0945d4cef2 fix: removing Clipper custom integration (to add it later as a real PLP) (#335)
* fix: removing Clipper custom integration (to add it later as a real PLP)

* fix: update CHHANGELOG

* fix: keep Clipper as BridgeProtocols so we dont have to redeploy and comment this is not used

* fix: prettier
2021-10-04 11:39:07 -07:00
Github Actions
8f6f7ad453 Publish
- @0x/asset-swapper@16.29.0
2021-10-04 12:21:46 +00:00
Github Actions
bb4fad37fa Updated CHANGELOGS & MD docs 2021-10-04 12:21:43 +00:00
Kim Persson
d06daf2957 feat: initial integration of new router (#295)
* feat: integrate Rust router with asset-swapper WIP

* fix: produce outputFees in the format the Rust router expects

* fix: correct output fee calc and only use the rust router for sells

* fix: make sure numbers sent to the rust router are integers

* hack: try to debug why rust router output is being overestimated WIP

* refactor: clean up router debugging code

* fix: don't use negative output fees for sells

* feat: try VIP sources in isolation and compare with routing all sources

* fix: adjust for FQT overhead when choosing between VIP, all sources WIP

* fix: pass gasPrice to path_optimizer for EP overhead calculations

* feat: buy support with the Rust Router WIP

* chore: WIP commit trying to get buys working

* refactor: use samples instead of fills for the Rust router

* feat: add vip handling hack to sample based routing

* fix: revert to 200 samplings for rust router when using pure samples

* refactor: remove old hacky Path based Rust code, add back feature toggle

* fix: scale both fill output and adjustedOutput my same factor as input

* feat: initial plumbing for supporting RFQ/Limit orders

* fix: incorrect bump of input amount by one base unit before routing

* fix: add fake samples for rfq/limit orders to fulfill the 3 sample req

* fix pass rfq orders in the correct format to the rust router

* chore: remove debugging logs and clean up code & comments

* fix: use published version of @0x/neon-router

* hack: scale routed amounts to account for precision loss of number/f64

* refactor: clean up code and address initial review comments

* fix: only remove trailing 0 output samples before passing to the router

* refactor: consolidate eth to output token calc into ethToOutputAmount fn

* fix: interpolate input between samples on output amount instead of price

* fix: return no path when we have no samples, add sanity asserts

* refactor: fix interpolation comment wording

* fix: remove double adjusted source route input amount

* chore: update changelog for asset-swapper
2021-10-04 12:09:54 +02:00
Megan
34314960ef Updated docs for zero protocol fees (#337) 2021-10-01 13:04:25 +02:00
104 changed files with 5359 additions and 839 deletions

View File

@@ -1,4 +1,49 @@
[
{
"timestamp": 1640364306,
"version": "3.3.25",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "3.3.24",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "3.3.23",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "3.3.22",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "3.3.21",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1631710679,
"version": "3.3.20",

View File

@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v3.3.25 - _December 24, 2021_
* Dependencies updated
## v3.3.24 - _December 1, 2021_
* Dependencies updated
## v3.3.23 - _November 16, 2021_
* Dependencies updated
## v3.3.22 - _November 3, 2021_
* Dependencies updated
## v3.3.21 - _October 19, 2021_
* Dependencies updated
## v3.3.20 - _September 15, 2021_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-erc20",
"version": "3.3.20",
"version": "3.3.25",
"engines": {
"node": ">=6.12"
},
@@ -53,8 +53,8 @@
"devDependencies": {
"@0x/abi-gen": "^5.6.2",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-utils": "^4.8.1",
"@0x/contracts-test-utils": "^5.4.16",
"@0x/contracts-utils": "^4.8.6",
"@0x/dev-utils": "^4.2.9",
"@0x/sol-compiler": "^4.7.5",
"@0x/ts-doc-gen": "^0.0.28",

View File

@@ -1,4 +1,49 @@
[
{
"timestamp": 1640364306,
"version": "5.4.16",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "5.4.15",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "5.4.14",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "5.4.13",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "5.4.12",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1631710679,
"version": "5.4.11",

View File

@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v5.4.16 - _December 24, 2021_
* Dependencies updated
## v5.4.15 - _December 1, 2021_
* Dependencies updated
## v5.4.14 - _November 16, 2021_
* Dependencies updated
## v5.4.13 - _November 3, 2021_
* Dependencies updated
## v5.4.12 - _October 19, 2021_
* Dependencies updated
## v5.4.11 - _September 15, 2021_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-test-utils",
"version": "5.4.11",
"version": "5.4.16",
"engines": {
"node": ">=6.12"
},
@@ -44,7 +44,7 @@
"dependencies": {
"@0x/assert": "^3.0.29",
"@0x/base-contract": "^6.4.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contract-addresses": "^6.11.0",
"@0x/dev-utils": "^4.2.9",
"@0x/json-schemas": "^6.3.0",
"@0x/order-utils": "^10.4.28",

View File

@@ -1,4 +1,67 @@
[
{
"timestamp": 1640364306,
"version": "1.4.8",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "1.4.7",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "1.4.6",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "1.4.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "1.4.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634147078,
"version": "1.4.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1633374058,
"version": "1.4.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1632957537,
"version": "1.4.1",

View File

@@ -5,6 +5,34 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.4.8 - _December 24, 2021_
* Dependencies updated
## v1.4.7 - _December 1, 2021_
* Dependencies updated
## v1.4.6 - _November 16, 2021_
* Dependencies updated
## v1.4.5 - _November 3, 2021_
* Dependencies updated
## v1.4.4 - _October 19, 2021_
* Dependencies updated
## v1.4.3 - _October 13, 2021_
* Dependencies updated
## v1.4.2 - _October 4, 2021_
* Dependencies updated
## v1.4.1 - _September 29, 2021_
* Dependencies updated

View File

@@ -0,0 +1,60 @@
pragma solidity ^0.6.12;
/**
* @title ISablier
* @author Sablier
*/
interface ISablier {
/**
* @notice Emits when a stream is successfully created.
*/
event CreateStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
uint256 deposit,
address tokenAddress,
uint256 startTime,
uint256 stopTime
);
/**
* @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream.
*/
event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount);
/**
* @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis.
*/
event CancelStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
uint256 senderBalance,
uint256 recipientBalance
);
function balanceOf(uint256 streamId, address who) external view returns (uint256 balance);
function getStream(uint256 streamId)
external
view
returns (
address sender,
address recipient,
uint256 deposit,
address token,
uint256 startTime,
uint256 stopTime,
uint256 remainingBalance,
uint256 ratePerSecond
);
function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
external
returns (uint256 streamId);
function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool);
function cancelStream(uint256 streamId) external returns (bool);
}

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-treasury",
"version": "1.4.1",
"version": "1.4.8",
"engines": {
"node": ">=6.12"
},
@@ -32,9 +32,9 @@
"publish:private": "yarn build && gitpkg publish"
},
"config": {
"publicInterfaceContracts": "ZrxTreasury,DefaultPoolOperator",
"publicInterfaceContracts": "ZrxTreasury,DefaultPoolOperator,ISablier",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./test/generated-artifacts/@(DefaultPoolOperator|IStaking|IZrxTreasury|ZrxTreasury).json"
"abis": "./test/generated-artifacts/@(DefaultPoolOperator|ISablier|IStaking|IZrxTreasury|ZrxTreasury).json"
},
"repository": {
"type": "git",
@@ -47,12 +47,12 @@
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/treasury",
"devDependencies": {
"@0x/abi-gen": "^5.6.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contract-addresses": "^6.11.0",
"@0x/contracts-asset-proxy": "^3.7.19",
"@0x/contracts-erc20": "^3.3.20",
"@0x/contracts-erc20": "^3.3.25",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-staking": "^2.0.45",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-test-utils": "^5.4.16",
"@0x/sol-compiler": "^4.7.5",
"@0x/ts-doc-gen": "^0.0.28",
"@0x/tslint-config": "^4.1.4",
@@ -73,7 +73,7 @@
},
"dependencies": {
"@0x/base-contract": "^6.4.2",
"@0x/protocol-utils": "^1.9.1",
"@0x/protocol-utils": "^1.10.1",
"@0x/subproviders": "^6.6.0",
"@0x/types": "^3.3.4",
"@0x/typescript-typings": "^5.2.1",

View File

@@ -6,8 +6,10 @@
import { ContractArtifact } from 'ethereum-types';
import * as DefaultPoolOperator from '../generated-artifacts/DefaultPoolOperator.json';
import * as ISablier from '../generated-artifacts/ISablier.json';
import * as ZrxTreasury from '../generated-artifacts/ZrxTreasury.json';
export const artifacts = {
ZrxTreasury: ZrxTreasury as ContractArtifact,
DefaultPoolOperator: DefaultPoolOperator as ContractArtifact,
ISablier: ISablier as ContractArtifact,
};

View File

@@ -3,6 +3,8 @@ import { ERC20TokenContract } from '@0x/contracts-erc20';
import { Web3ProviderEngine } from '@0x/subproviders';
import { BigNumber } from '@0x/utils';
import { ISablierContract } from './wrappers';
interface ProposedAction {
target: string;
data: string;
@@ -17,8 +19,14 @@ interface Proposal {
const { zrxToken } = getContractAddressesForChainOrThrow(1);
const zrx = new ERC20TokenContract(zrxToken, new Web3ProviderEngine());
const maticToken = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0';
const matic = new ERC20TokenContract(maticToken, new Web3ProviderEngine());
const maticToken = new ERC20TokenContract('0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', new Web3ProviderEngine());
const sablier = new ISablierContract('0xcd18eaa163733da39c232722cbc4e8940b1d8888', new Web3ProviderEngine());
const ONE_YEAR_IN_SECONDS = new BigNumber('31536000');
const PROPOSAL_2_ZRX_AMOUNT = new BigNumber('485392999999999970448000');
const PROPOSAL_2_MATIC_AMOUNT = new BigNumber('378035999999999992944000');
const PROPOSAL_2_STREAM_START_TIME = new BigNumber('1635188400');
const PROPOSAL_2_RECIPIENT = '0x976378445d31d81b15576811450a7b9797206807';
export const proposals: Proposal[] = [
{
@@ -44,8 +52,8 @@ export const proposals: Proposal[] = [
value: new BigNumber(0),
},
{
target: maticToken,
data: matic
target: maticToken.address,
data: maticToken
.transfer('0xab66cc8fd10457ebc9d13b9760c835f0a4cbc487', new BigNumber('420000e18'))
.getABIEncodedTransactionData(),
value: new BigNumber(0),
@@ -54,4 +62,46 @@ export const proposals: Proposal[] = [
description:
'# Z-2 0x/Polygon Grant Budget for 0xEVE\n\n## Summary\n\nWe propose to transfer 10% of the new Treasury allocation from the recently announced 0x/Polygon initiative to the 0x Ecosystem Value Experiment (0xEVE). The purpose is not so much to increase the budget as it is to enable access to the MATIC that was allocated to the Treasury after 0xEVE was established and to expand the original goals to include use cases on the Polygon Network. A snapshot vote was held to gauge community sentiment with 100% in favor https://snapshot.org/#/0xgov.eth/proposal/QmdcZAAcmNgM3R6CVY586G4sSoPwm6T3CS39DCQ4gPDPB4.\n\n## Background\n\nA proposal to establish the 0x Ecosystem Value Experiment (0xEVE) was passed in early June with a budget of 400K ZRX, which was then transferred to the 0xEVE multisig to fund operations. Shortly afterwards, 0xLabs and 0xPolygon allocated 3.3M ZRX and 4.2M MATIC to the 0xDAO Treasury with the shared goal of bringing 1M new users to the Polygon Network via 0x-powered applications.<br/><br/>\nSince that time, 0xEVE has established a grant program and published a framework for projects seeking support from the 0xDAO. However, because 0xEVE has no access to these new funds, it will be extremely difficult given the current market conditions (and the commensurate devaluation of our operating budget in USD terms) for us to incorporate this new goal into the grant program in any meaningful way, particularly because we are not able to spend any of the MATIC in the Treasury.\n\n## Request for Approval\n\nIn keeping with the original structure of the budget where ~10% of the Treasury was allocated to 0xEVE to fund opportunities such as grants, we propose that 10% of the new funding (ZRX and MATIC) be allocated to 0xEVE to fund activities associated with this new initiative. A separate multisig has been set up to manage and track these expenditures.<br/><br/>\nCompensation will remain as authorized in the original budget, and the new funding will be allocated 100% to grants and other operational activities specific to Polygon. In accordance with the grant program framework, this will enable 0xEVE to fast track grants under $50k using its own budget, while larger grants will require an onchain community vote and will be awarded from Treasury funds.<br/><br/>\nAdditionally, as 0x protocol deploys to additional chains, for any future allocations from similar joint initiatives, we recommend that they be structured the same way (90/10 split between the Treasury and 0xEVE) so that 0xEVE can actively participate in evaluating, distributing, and managing grants and other associated efforts designed to accelerate adoption and ecosystem value capture on those networks.<br/><br/>\nAs stipulated in Z-1, 0xEVE is a limited-duration experiment (26 weeks) and any funds not used will be returned to the Treasury when the experiment concludes.\n\n## Action Required\n\nTransfer 330,813 ZRX and 420,000 MATIC to 0xEVE gnosis safe multisig 0xAB66CC8FD10457ebC9D13B9760C835F0a4CbC487',
},
{
actions: [
{
target: zrxToken,
data: zrx.approve(sablier.address, PROPOSAL_2_ZRX_AMOUNT).getABIEncodedTransactionData(),
value: new BigNumber(0),
},
{
target: maticToken.address,
data: maticToken.approve(sablier.address, PROPOSAL_2_MATIC_AMOUNT).getABIEncodedTransactionData(),
value: new BigNumber(0),
},
{
target: sablier.address,
data: sablier
.createStream(
PROPOSAL_2_RECIPIENT,
PROPOSAL_2_ZRX_AMOUNT,
zrxToken,
PROPOSAL_2_STREAM_START_TIME,
PROPOSAL_2_STREAM_START_TIME.plus(ONE_YEAR_IN_SECONDS),
)
.getABIEncodedTransactionData(),
value: new BigNumber(0),
},
{
target: sablier.address,
data: sablier
.createStream(
PROPOSAL_2_RECIPIENT,
PROPOSAL_2_MATIC_AMOUNT,
maticToken.address,
PROPOSAL_2_STREAM_START_TIME,
PROPOSAL_2_STREAM_START_TIME.plus(ONE_YEAR_IN_SECONDS),
)
.getABIEncodedTransactionData(),
value: new BigNumber(0),
},
],
description:
'# Z-3 Trader.xyz Grant\n\n## Summary\n\nThis proposal seeks authorization of a $950k grant from the treasury to trader.xyz. The community has discussed the merits of the proposal in the governance forum and signaled strong support for moving forward in a snapshot poll:\n\n1. https://gov.0x.org/t/grant-proposal-trader-xyz/1005/\n2. https://snapshot.org/#/0xgov.eth/proposal/Qmcf2C3KmQ1W1XBGownLWsA8yX9hpzY6peLUGKNJnPzN9y\n\n## Grant Details\n\n### What category best describes your grant request?\n\n1. 0x orderbook\n2. 0x protocol feature development\n\n### Grant amount requested\n\n**Amount**: $950k split 50/50 between $ZRX and $MATIC (note: an upfront payment of $50k in $ZRX and $MATIC is being made from the 0xEVE grant budget)\n\n**Price reference**:\n1. [https://www.tradingview.com/symbols/ZRXUSD/technicals/](https://www.tradingview.com/symbols/ZRXUSD/technicals/) ($ZRX 30-day EMA as of 10/4/2021 = 0.97859)\n2. [https://www.tradingview.com/symbols/MATICUSD/technicals/](https://www.tradingview.com/symbols/MATICUSD/technicals/) ($MATIC 30-day EMA as of 10/4/2021 = 1.2564959)\n\n**Payment details**: $950k streamed from Sablier over 365 days (485,393 ZRX + 378,036 MATIC)\n\n**Receiving address**: 0x976378445D31D81b15576811450A7b9797206807 (Gnosis Safe)\n\n### Team background\n\nCore team is comprised of two former 0x core team members (Patryk Adas - former Matcha lead designer, and John Johnson - former Matcha lead engineer)\n\n### Project background\n\nTrader.xyz is a dapp that provides a user-focused trading experience with the goal of becoming the flagship, 0x-powered application for discovering and trading NFTs\n\n### Description of work to be funded\n\nSee detailed explanation at https://gov.0x.org/t/grant-proposal-trader-xyz/1005\n\n### Budget breakdown\n\nSee detailed explanation at https://gov.0x.org/t/grant-proposal-trader-xyz/1005\n\n### Benefit to 0x ecosystem\n\n1. Become the gold standard for exchanging NFTs with 0x protocol\n2. Enable 0xDAO to build organic development capabilities\n3. Improve protocol documentation and developer resources\n4. Add OSS API protocol features\n\n### Risk/Reward factors\n\nRisks include competition, mindshare, flywheel of liquidity, etc. We believe our product and team have the potential to mitigate these risks and bring to market several features and capabilities that will be market-leading.\n\n### Additional info\n\nOur team has a track record of delivering high quality projects, and in order for us to continue our work, we need capital and support. We prefer not to go the venture capital route and instead work directly with the 0xDAO for the best synergies and to align value with 0x. We proved out an initial brand, design, and engineering concept via OTC orders, and it is already the highest quality OTC swap on the market. We would like to work with 0xDAO directly to make sure 0x has a foothold in the NFT market as it continues to evolve and develop. We want to do what Matcha did for DEX ERC20 trading.\n\n## Action Required\n\nStream 485,393 ZRX and 378,036 MATIC to Gnosis Safe 0x976378445D31D81b15576811450A7b9797206807 over 365 days',
},
];

View File

@@ -4,4 +4,5 @@
* -----------------------------------------------------------------------------
*/
export * from '../generated-wrappers/default_pool_operator';
export * from '../generated-wrappers/i_sablier';
export * from '../generated-wrappers/zrx_treasury';

View File

@@ -6,10 +6,12 @@
import { ContractArtifact } from 'ethereum-types';
import * as DefaultPoolOperator from '../test/generated-artifacts/DefaultPoolOperator.json';
import * as ISablier from '../test/generated-artifacts/ISablier.json';
import * as IStaking from '../test/generated-artifacts/IStaking.json';
import * as IZrxTreasury from '../test/generated-artifacts/IZrxTreasury.json';
import * as ZrxTreasury from '../test/generated-artifacts/ZrxTreasury.json';
export const artifacts = {
ISablier: ISablier as ContractArtifact,
DefaultPoolOperator: DefaultPoolOperator as ContractArtifact,
IStaking: IStaking as ContractArtifact,
IZrxTreasury: IZrxTreasury as ContractArtifact,

View File

@@ -7,7 +7,7 @@ import * as _ from 'lodash';
import { proposals } from '../src/proposals';
import { artifacts } from './artifacts';
import { ZrxTreasuryContract, ZrxTreasuryEvents } from './wrappers';
import { ISablierEvents, ZrxTreasuryContract, ZrxTreasuryEvents } from './wrappers';
const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/mzhu25/zeroex-staking';
const STAKING_PROXY_ADDRESS = '0xa26e80e7dea86279c6d778d702cc413e6cffa777';
@@ -15,9 +15,11 @@ const TREASURY_ADDRESS = '0x0bb1810061c2f5b2088054ee184e6c79e1591101';
const PROPOSER = process.env.PROPOSER || constants.NULL_ADDRESS;
const VOTER = '0xba4f44e774158408e2dc6c5cb65bc995f0a89180';
const VOTER_OPERATED_POOLS = ['0x0000000000000000000000000000000000000000000000000000000000000017'];
const VOTER_2 = '0x9a4eb1101c0c053505bd71d2ffa27ed902dead85';
const VOTER_2_OPERATED_POOLS = ['0x0000000000000000000000000000000000000000000000000000000000000029'];
blockchainTests.configure({
fork: {
unlockedAccounts: [PROPOSER, VOTER],
unlockedAccounts: [PROPOSER, VOTER, VOTER_2],
},
});
@@ -219,4 +221,80 @@ blockchainTests.fork.skip('Treasury proposal mainnet fork tests', env => {
);
});
});
describe('Proposal 2', () => {
it('works', async () => {
const proposal = proposals[2];
let executionEpoch: BigNumber;
if (proposal.executionEpoch) {
executionEpoch = proposal.executionEpoch;
} else {
const currentEpoch = await staking.currentEpoch().callAsync();
executionEpoch = currentEpoch.plus(2);
}
const pools = await querySubgraphAsync(PROPOSER);
const proposeTx = treasury.propose(proposal.actions, executionEpoch, proposal.description, pools);
const calldata = proposeTx.getABIEncodedTransactionData();
logUtils.log('ZrxTreasury.propose calldata:');
logUtils.log(calldata);
const proposalId = await proposeTx.callAsync({ from: PROPOSER });
const receipt = await proposeTx.awaitTransactionSuccessAsync({ from: PROPOSER });
verifyEventsFromLogs(
receipt.logs,
[
{
...proposal,
proposalId,
executionEpoch,
proposer: PROPOSER,
operatedPoolIds: pools,
},
],
ZrxTreasuryEvents.ProposalCreated,
);
await fastForwardToNextEpochAsync();
await fastForwardToNextEpochAsync();
await treasury
.castVote(proposalId, true, VOTER_OPERATED_POOLS)
.awaitTransactionSuccessAsync({ from: VOTER });
await treasury
.castVote(proposalId, true, VOTER_2_OPERATED_POOLS)
.awaitTransactionSuccessAsync({ from: VOTER_2 });
await env.web3Wrapper.increaseTimeAsync(votingPeriod.plus(1).toNumber());
await env.web3Wrapper.mineBlockAsync();
const executeTx = await treasury.execute(proposalId, proposal.actions).awaitTransactionSuccessAsync();
verifyEventsFromLogs(
executeTx.logs,
[
{
proposalId,
},
],
ZrxTreasuryEvents.ProposalExecuted,
);
verifyEventsFromLogs(
executeTx.logs,
[
{
recipient: '0x976378445D31D81b15576811450A7b9797206807',
deposit: new BigNumber('485392999999999970448000'),
tokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498',
startTime: new BigNumber(1635188400),
stopTime: new BigNumber(1666724400),
},
{
recipient: '0x976378445D31D81b15576811450A7b9797206807',
deposit: new BigNumber('378035999999999992944000'),
tokenAddress: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
startTime: new BigNumber(1635188400),
stopTime: new BigNumber(1666724400),
},
],
ISablierEvents.CreateStream,
);
});
});
});

View File

@@ -4,6 +4,7 @@
* -----------------------------------------------------------------------------
*/
export * from '../test/generated-wrappers/default_pool_operator';
export * from '../test/generated-wrappers/i_sablier';
export * from '../test/generated-wrappers/i_staking';
export * from '../test/generated-wrappers/i_zrx_treasury';
export * from '../test/generated-wrappers/zrx_treasury';

View File

@@ -4,8 +4,10 @@
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
"files": [
"generated-artifacts/DefaultPoolOperator.json",
"generated-artifacts/ISablier.json",
"generated-artifacts/ZrxTreasury.json",
"test/generated-artifacts/DefaultPoolOperator.json",
"test/generated-artifacts/ISablier.json",
"test/generated-artifacts/IStaking.json",
"test/generated-artifacts/IZrxTreasury.json",
"test/generated-artifacts/ZrxTreasury.json"

View File

@@ -1,4 +1,49 @@
[
{
"timestamp": 1640364306,
"version": "4.8.6",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "4.8.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "4.8.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "4.8.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "4.8.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1631710679,
"version": "4.8.1",

View File

@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v4.8.6 - _December 24, 2021_
* Dependencies updated
## v4.8.5 - _December 1, 2021_
* Dependencies updated
## v4.8.4 - _November 16, 2021_
* Dependencies updated
## v4.8.3 - _November 3, 2021_
* Dependencies updated
## v4.8.2 - _October 19, 2021_
* Dependencies updated
## v4.8.1 - _September 15, 2021_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-utils",
"version": "4.8.1",
"version": "4.8.6",
"engines": {
"node": ">=6.12"
},
@@ -52,7 +52,7 @@
"devDependencies": {
"@0x/abi-gen": "^5.6.2",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-test-utils": "^5.4.16",
"@0x/dev-utils": "^4.2.9",
"@0x/order-utils": "^10.4.28",
"@0x/sol-compiler": "^4.7.5",

View File

@@ -1,4 +1,74 @@
[
{
"timestamp": 1640364306,
"version": "0.30.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "0.30.0",
"changes": [
{
"note": "Add `AaveV2` and `Compound` deposit/withdrawal liquidity source",
"pr": 321
}
],
"timestamp": 1638390144
},
{
"timestamp": 1637102971,
"version": "0.29.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "0.29.4",
"changes": [
{
"note": "Prevent EP ETH balance from reducing when executin mtxs",
"pr": 365
}
],
"timestamp": 1637065617
},
{
"version": "0.29.3",
"changes": [
{
"note": "Register transformERC20() and remove transformERC20Staging()",
"pr": 355
},
{
"note": "Add OtcOrders to FullMigration",
"pr": 350
}
],
"timestamp": 1635903615
},
{
"timestamp": 1634668033,
"version": "0.29.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1633374058,
"version": "0.29.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "0.29.0",
"changes": [

View File

@@ -5,6 +5,35 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v0.30.1 - _December 24, 2021_
* Dependencies updated
## v0.30.0 - _December 1, 2021_
* Add `AaveV2` and `Compound` deposit/withdrawal liquidity source (#321)
## v0.29.5 - _November 16, 2021_
* Dependencies updated
## v0.29.4 - _November 16, 2021_
* Prevent EP ETH balance from reducing when executin mtxs (#365)
## v0.29.3 - _November 3, 2021_
* Register transformERC20() and remove transformERC20Staging() (#355)
* Add OtcOrders to FullMigration (#350)
## v0.29.2 - _October 19, 2021_
* Dependencies updated
## v0.29.1 - _October 4, 2021_
* Dependencies updated
## v0.29.0 - _September 29, 2021_
* Export TransformERC20FeatureContract (#282)

View File

@@ -78,7 +78,7 @@ contract MetaTransactionsFeature is
/// @dev Name of this feature.
string public constant override FEATURE_NAME = "MetaTransactions";
/// @dev Version of this feature.
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 0);
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 1);
/// @dev EIP712 typehash of the `MetaTransactionData` struct.
bytes32 public immutable MTX_EIP712_TYPEHASH = keccak256(
"MetaTransactionData("
@@ -105,6 +105,17 @@ contract MetaTransactionsFeature is
}
}
/// @dev Ensures that the ETH balance of `this` does not go below the
/// initial ETH balance before the call (excluding ETH attached to the call).
modifier doesNotReduceEthBalance() {
uint256 initialBalance = address(this).balance - msg.value;
_;
require(
initialBalance <= address(this).balance,
"MetaTransactionsFeature/ETH_LEAK"
);
}
constructor(address zeroExAddress)
public
FixinCommon()
@@ -140,6 +151,7 @@ contract MetaTransactionsFeature is
payable
override
nonReentrant(REENTRANCY_MTX)
doesNotReduceEthBalance
refundsAttachedEth
returns (bytes memory returnResult)
{
@@ -164,6 +176,7 @@ contract MetaTransactionsFeature is
payable
override
nonReentrant(REENTRANCY_MTX)
doesNotReduceEthBalance
refundsAttachedEth
returns (bytes[] memory returnResults)
{

View File

@@ -75,7 +75,7 @@ contract TransformERC20Feature is
_registerFeatureFunction(this.setTransformerDeployer.selector);
_registerFeatureFunction(this.setQuoteSigner.selector);
_registerFeatureFunction(this.getQuoteSigner.selector);
_registerFeatureFunction(this.transformERC20Staging.selector);
_registerFeatureFunction(this.transformERC20.selector);
_registerFeatureFunction(this._transformERC20.selector);
if (this.getTransformWallet() == IFlashWallet(address(0))) {
// Create the transform wallet if it doesn't exist.
@@ -145,44 +145,6 @@ contract TransformERC20Feature is
LibTransformERC20Storage.getStorage().wallet = wallet;
}
/// @dev Wrapper for `transformERC20`. This selector will be temporarily
/// registered to the Exchange Proxy so that we can migrate 0x API
/// with no downtime. Once 0x API has been updated to point to this
/// function, we can safely re-register `transformERC20`, point
/// 0x API back to `transformERC20`, and deregister this function.
/// @param inputToken The token being provided by the sender.
/// If `0xeee...`, ETH is implied and should be provided with the call.`
/// @param outputToken The token to be acquired by the sender.
/// `0xeee...` implies ETH.
/// @param inputTokenAmount The amount of `inputToken` to take from the sender.
/// If set to `uint256(-1)`, the entire spendable balance of the taker
/// will be solt.
/// @param minOutputTokenAmount The minimum amount of `outputToken` the sender
/// must receive for the entire transformation to succeed. If set to zero,
/// the minimum output token transfer will not be asserted.
/// @param transformations The transformations to execute on the token balance(s)
/// in sequence.
/// @return outputTokenAmount The amount of `outputToken` received by the sender.
function transformERC20Staging(
IERC20TokenV06 inputToken,
IERC20TokenV06 outputToken,
uint256 inputTokenAmount,
uint256 minOutputTokenAmount,
Transformation[] memory transformations
)
public
payable
returns (uint256 outputTokenAmount)
{
return transformERC20(
inputToken,
outputToken,
inputTokenAmount,
minOutputTokenAmount,
transformations
);
}
/// @dev Executes a series of transformations to convert an ERC20 `inputToken`
/// to an ERC20 `outputToken`.
/// @param inputToken The token being provided by the sender.
@@ -283,8 +245,8 @@ contract TransformERC20Feature is
}
// Transfer output tokens from wallet to recipient
outputTokenAmount = _executeOutputTokenTransfer(
args.outputToken,
state.wallet,
args.outputToken,
state.wallet,
args.recipient
);
}

View File

@@ -25,6 +25,7 @@ import "../features/interfaces/IOwnableFeature.sol";
import "../features/TransformERC20Feature.sol";
import "../features/MetaTransactionsFeature.sol";
import "../features/NativeOrdersFeature.sol";
import "../features/OtcOrdersFeature.sol";
import "./InitialMigration.sol";
@@ -40,6 +41,7 @@ contract FullMigration {
TransformERC20Feature transformERC20;
MetaTransactionsFeature metaTransactions;
NativeOrdersFeature nativeOrders;
OtcOrdersFeature otcOrders;
}
/// @dev Parameters needed to initialize features.
@@ -173,5 +175,16 @@ contract FullMigration {
address(this)
);
}
// OtcOrdersFeature
{
// Register the feature.
ownable.migrate(
address(features.otcOrders),
abi.encodeWithSelector(
OtcOrdersFeature.migrate.selector
),
address(this)
);
}
}
}

View File

@@ -22,11 +22,12 @@ pragma experimental ABIEncoderV2;
import "./IBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinBalancer.sol";
import "./mixins/MixinBalancerV2.sol";
import "./mixins/MixinBancor.sol";
import "./mixins/MixinClipper.sol";
import "./mixins/MixinCoFiX.sol";
import "./mixins/MixinCompound.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinCryptoCom.sol";
@@ -48,11 +49,12 @@ import "./mixins/MixinZeroExBridge.sol";
contract BridgeAdapter is
IBridgeAdapter,
MixinAaveV2,
MixinBalancer,
MixinBalancerV2,
MixinBancor,
MixinClipper,
MixinCoFiX,
MixinCompound,
MixinCurve,
MixinCurveV2,
MixinCryptoCom,
@@ -74,11 +76,12 @@ contract BridgeAdapter is
{
constructor(IEtherTokenV06 weth)
public
MixinAaveV2()
MixinBalancer()
MixinBalancerV2()
MixinBancor(weth)
MixinClipper(weth)
MixinCoFiX()
MixinCompound(weth)
MixinCurve(weth)
MixinCurveV2()
MixinCryptoCom()
@@ -248,8 +251,15 @@ contract BridgeAdapter is
sellAmount,
order.bridgeData
);
} else if (protocolId == BridgeProtocols.CLIPPER) {
boughtAmount = _tradeClipper(
} else if (protocolId == BridgeProtocols.AAVEV2) {
boughtAmount = _tradeAaveV2(
sellToken,
buyToken,
sellAmount,
order.bridgeData
);
} else if (protocolId == BridgeProtocols.COMPOUND) {
boughtAmount = _tradeCompound(
sellToken,
buyToken,
sellAmount,

View File

@@ -49,5 +49,7 @@ library BridgeProtocols {
uint128 internal constant KYBERDMM = 19;
uint128 internal constant CURVEV2 = 20;
uint128 internal constant LIDO = 21;
uint128 internal constant CLIPPER = 22;
uint128 internal constant CLIPPER = 22; // Not used: Clipper is now using PLP interface
uint128 internal constant AAVEV2 = 23;
uint128 internal constant COMPOUND = 24;
}

View File

@@ -0,0 +1,93 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
// Minimal Aave V2 LendingPool interface
interface ILendingPool {
/**
* @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
* - E.g. User deposits 100 USDC and gets in return 100 aUSDC
* @param asset The address of the underlying asset to deposit
* @param amount The amount to be deposited
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
**/
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
* E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
* @param asset The address of the underlying asset to withdraw
* @param amount The underlying amount to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole aToken balance
* @param to Address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
**/
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
}
contract MixinAaveV2 {
using LibERC20TokenV06 for IERC20TokenV06;
function _tradeAaveV2(
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bytes memory bridgeData
)
internal
returns (uint256)
{
(ILendingPool lendingPool, address aToken) = abi.decode(bridgeData, (ILendingPool, address));
sellToken.approveIfBelow(
address(lendingPool),
sellAmount
);
if (address(buyToken) == aToken) {
lendingPool.deposit(address(sellToken), sellAmount, address(this), 0);
// 1:1 mapping token -> aToken and have the same number of decimals as the underlying token
return sellAmount;
} else if (address(sellToken) == aToken) {
return lendingPool.withdraw(address(buyToken), sellAmount, address(this));
}
revert("MixinAaveV2/UNSUPPORTED_TOKEN_PAIR");
}
}

View File

@@ -1,148 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
import "../IBridgeAdapter.sol";
import "../../../vendor/ILiquidityProvider.sol";
contract MixinClipper {
using LibERC20TokenV06 for IERC20TokenV06;
/// @dev Mainnet address of the WETH contract.
IEtherTokenV06 private immutable WETH;
constructor(IEtherTokenV06 weth)
public
{
WETH = weth;
}
function _tradeClipper(
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bytes memory bridgeData
)
internal
returns (uint256 boughtAmount)
{
// We can only use ETH with Clipper, no WETH available
(ILiquidityProvider clipper, bytes memory auxiliaryData) =
abi.decode(bridgeData, (ILiquidityProvider, bytes));
if (sellToken == WETH) {
boughtAmount = _executeSellEthForToken(
clipper,
buyToken,
sellAmount,
auxiliaryData
);
} else if (buyToken == WETH) {
boughtAmount = _executeSellTokenForEth(
clipper,
sellToken,
sellAmount,
auxiliaryData
);
} else {
boughtAmount = _executeSellTokenForToken(
clipper,
sellToken,
buyToken,
sellAmount,
auxiliaryData
);
}
return boughtAmount;
}
function _executeSellEthForToken(
ILiquidityProvider clipper,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bytes memory auxiliaryData
)
private
returns (uint256 boughtAmount)
{
// Clipper requires ETH and doesn't support WETH
WETH.withdraw(sellAmount);
boughtAmount = clipper.sellEthForToken{ value: sellAmount }(
buyToken,
address(this),
1,
auxiliaryData
);
}
function _executeSellTokenForEth(
ILiquidityProvider clipper,
IERC20TokenV06 sellToken,
uint256 sellAmount,
bytes memory auxiliaryData
)
private
returns (uint256 boughtAmount)
{
// Optimization: We can transfer the tokens into clipper rather than
// have an allowance updated
sellToken.compatTransfer(address(clipper), sellAmount);
boughtAmount = clipper.sellTokenForEth(
sellToken,
payable(address(this)),
1,
auxiliaryData
);
// we want WETH for possible future trades
WETH.deposit{ value: boughtAmount }();
}
function _executeSellTokenForToken(
ILiquidityProvider clipper,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bytes memory auxiliaryData
)
private
returns (uint256 boughtAmount)
{
// Optimization: We can transfer the tokens into clipper rather than
// have an allowance updated
sellToken.compatTransfer(address(clipper), sellAmount);
boughtAmount = clipper.sellTokenForToken(
sellToken,
buyToken,
address(this),
1,
auxiliaryData
);
}
}

View File

@@ -0,0 +1,110 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
/// @dev Minimal CToken interface
interface ICToken {
/// @dev deposits specified amount underlying tokens and mints cToken for the sender
/// @param mintAmountInUnderlying amount of underlying tokens to deposit to mint cTokens
/// @return status code of whether the mint was successful or not
function mint(uint256 mintAmountInUnderlying) external returns (uint256);
/// @dev redeems specified amount of cTokens and returns the underlying token to the sender
/// @param redeemTokensInCtokens amount of cTokens to redeem for underlying collateral
/// @return status code of whether the redemption was successful or not
function redeem(uint256 redeemTokensInCtokens) external returns (uint256);
}
/// @dev Minimal CEther interface
interface ICEther {
/// @dev deposits the amount of Ether sent as value and return mints cEther for the sender
function mint() payable external;
/// @dev redeems specified amount of cETH and returns the underlying ether to the sender
/// @dev redeemTokensInCEther amount of cETH to redeem for underlying ether
/// @return status code of whether the redemption was successful or not
function redeem(uint256 redeemTokensInCEther) external returns (uint256);
}
contract MixinCompound {
using LibERC20TokenV06 for IERC20TokenV06;
using LibSafeMathV06 for uint256;
IEtherTokenV06 private immutable WETH;
constructor(IEtherTokenV06 weth)
public
{
WETH = weth;
}
uint256 constant private COMPOUND_SUCCESS_CODE = 0;
function _tradeCompound(
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bytes memory bridgeData
)
internal
returns (uint256)
{
(address cTokenAddress) = abi.decode(bridgeData, (address));
uint256 beforeBalance = buyToken.balanceOf(address(this));
if (address(buyToken) == cTokenAddress) {
if (address(sellToken) == address(WETH)) {
// ETH/WETH -> cETH
ICEther cETH = ICEther(cTokenAddress);
// Compound expects ETH to be sent with mint call
WETH.withdraw(sellAmount);
// NOTE: cETH mint will revert on failure instead of returning a status code
cETH.mint{value: sellAmount}();
} else {
sellToken.approveIfBelow(
cTokenAddress,
sellAmount
);
// Token -> cToken
ICToken cToken = ICToken(cTokenAddress);
require(cToken.mint(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_MINT_CTOKEN");
}
} else if (address(sellToken) == cTokenAddress) {
if (address(buyToken) == address(WETH)) {
// cETH -> ETH/WETH
uint256 etherBalanceBefore = address(this).balance;
ICEther cETH = ICEther(cTokenAddress);
require(cETH.redeem(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_REDEEM_CETHER");
uint256 etherBalanceAfter = address(this).balance;
uint256 receivedEtherBalance = etherBalanceAfter.safeSub(etherBalanceBefore);
WETH.deposit{value: receivedEtherBalance}();
} else {
ICToken cToken = ICToken(cTokenAddress);
require(cToken.redeem(sellAmount) == COMPOUND_SUCCESS_CODE, "MixinCompound/FAILED_TO_REDEEM_CTOKEN");
}
}
return buyToken.balanceOf(address(this)).safeSub(beforeBalance);
}
}

View File

@@ -46,6 +46,10 @@ contract TestMetaTransactionsTransformERC20Feature is
payable
returns (uint256 outputTokenAmount)
{
if (msg.value == 555) {
tx.origin.transfer(1);
}
if (msg.value == 666) {
revert('FAIL');
}

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-zero-ex",
"version": "0.29.0",
"version": "0.30.1",
"engines": {
"node": ">=6.12"
},
@@ -43,7 +43,7 @@
"config": {
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,BridgeAdapter,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC20Bridge|IERC20Transformer|IFeature|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|ISimpleFunctionRegistryFeature|IStaking|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinBalancer|MixinBalancerV2|MixinBancor|MixinClipper|MixinCoFiX|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestMooniswap|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC20Bridge|IERC20Transformer|IFeature|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|ISimpleFunctionRegistryFeature|IStaking|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBancor|MixinCoFiX|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestMooniswap|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
},
"repository": {
"type": "git",
@@ -56,10 +56,10 @@
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/zero-ex",
"devDependencies": {
"@0x/abi-gen": "^5.6.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contracts-erc20": "^3.3.20",
"@0x/contract-addresses": "^6.11.0",
"@0x/contracts-erc20": "^3.3.25",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-test-utils": "^5.4.16",
"@0x/dev-utils": "^4.2.9",
"@0x/order-utils": "^10.4.28",
"@0x/sol-compiler": "^4.7.5",
@@ -83,7 +83,7 @@
},
"dependencies": {
"@0x/base-contract": "^6.4.2",
"@0x/protocol-utils": "^1.9.1",
"@0x/protocol-utils": "^1.10.1",
"@0x/subproviders": "^6.6.0",
"@0x/types": "^3.3.4",
"@0x/typescript-typings": "^5.2.1",

View File

@@ -12,6 +12,7 @@ import {
IZeroExContract,
MetaTransactionsFeatureContract,
NativeOrdersFeatureContract,
OtcOrdersFeatureContract,
OwnableFeatureContract,
SimpleFunctionRegistryFeatureContract,
TransformERC20FeatureContract,
@@ -113,6 +114,7 @@ export interface FullFeatures extends BootstrapFeatures {
transformERC20: string;
metaTransactions: string;
nativeOrders: string;
otcOrders: string;
}
/**
@@ -123,6 +125,7 @@ export interface FullFeatureArtifacts extends BootstrapFeatureArtifacts {
metaTransactions: SimpleContractArtifact;
nativeOrders: SimpleContractArtifact;
feeCollectorController: SimpleContractArtifact;
otcOrders: SimpleContractArtifact;
}
/**
@@ -155,6 +158,7 @@ const DEFAULT_FULL_FEATURES_ARTIFACTS = {
metaTransactions: artifacts.MetaTransactionsFeature,
nativeOrders: artifacts.NativeOrdersFeature,
feeCollectorController: artifacts.FeeCollectorController,
otcOrders: artifacts.OtcOrdersFeature,
};
/**
@@ -222,6 +226,18 @@ export async function deployFullFeaturesAsync(
_config.protocolFeeMultiplier,
)
).address,
otcOrders:
features.otcOrders ||
(
await OtcOrdersFeatureContract.deployFrom0xArtifactAsync(
_featureArtifacts.otcOrders,
provider,
txDefaults,
artifacts,
_config.zeroExAddress,
_config.wethAddress,
)
).address,
};
}

View File

@@ -81,11 +81,12 @@ import * as LiquidityProviderFeature from '../test/generated-artifacts/Liquidity
import * as LiquidityProviderSandbox from '../test/generated-artifacts/LiquidityProviderSandbox.json';
import * as LogMetadataTransformer from '../test/generated-artifacts/LogMetadataTransformer.json';
import * as MetaTransactionsFeature from '../test/generated-artifacts/MetaTransactionsFeature.json';
import * as MixinAaveV2 from '../test/generated-artifacts/MixinAaveV2.json';
import * as MixinBalancer from '../test/generated-artifacts/MixinBalancer.json';
import * as MixinBalancerV2 from '../test/generated-artifacts/MixinBalancerV2.json';
import * as MixinBancor from '../test/generated-artifacts/MixinBancor.json';
import * as MixinClipper from '../test/generated-artifacts/MixinClipper.json';
import * as MixinCoFiX from '../test/generated-artifacts/MixinCoFiX.json';
import * as MixinCompound from '../test/generated-artifacts/MixinCompound.json';
import * as MixinCryptoCom from '../test/generated-artifacts/MixinCryptoCom.json';
import * as MixinCurve from '../test/generated-artifacts/MixinCurve.json';
import * as MixinCurveV2 from '../test/generated-artifacts/MixinCurveV2.json';
@@ -273,11 +274,12 @@ export const artifacts = {
BridgeAdapter: BridgeAdapter as ContractArtifact,
BridgeProtocols: BridgeProtocols as ContractArtifact,
IBridgeAdapter: IBridgeAdapter as ContractArtifact,
MixinAaveV2: MixinAaveV2 as ContractArtifact,
MixinBalancer: MixinBalancer as ContractArtifact,
MixinBalancerV2: MixinBalancerV2 as ContractArtifact,
MixinBancor: MixinBancor as ContractArtifact,
MixinClipper: MixinClipper as ContractArtifact,
MixinCoFiX: MixinCoFiX as ContractArtifact,
MixinCompound: MixinCompound as ContractArtifact,
MixinCryptoCom: MixinCryptoCom as ContractArtifact,
MixinCurve: MixinCurve as ContractArtifact,
MixinCurveV2: MixinCurveV2 as ContractArtifact,

View File

@@ -38,6 +38,7 @@ blockchainTests.resets('MetaTransactions feature', env => {
let nativeOrdersFeature: TestMetaTransactionsNativeOrdersFeatureContract;
const MAX_FEE_AMOUNT = new BigNumber('1e18');
const TRANSFORM_ERC20_ONE_WEI_VALUE = new BigNumber(555);
const TRANSFORM_ERC20_FAILING_VALUE = new BigNumber(666);
const TRANSFORM_ERC20_REENTER_VALUE = new BigNumber(777);
const TRANSFORM_ERC20_BATCH_REENTER_VALUE = new BigNumber(888);
@@ -597,7 +598,7 @@ blockchainTests.resets('MetaTransactions feature', env => {
);
});
it('cannot reenter `executeMetaTransaction()`', async () => {
it('cannot reduce initial ETH balance', async () => {
const args = getRandomTransformERC20Args();
const mtx = getRandomMetaTransaction({
callData: transformERC20Feature
@@ -609,58 +610,23 @@ blockchainTests.resets('MetaTransactions feature', env => {
args.transformations,
)
.getABIEncodedTransactionData(),
value: TRANSFORM_ERC20_REENTER_VALUE,
value: TRANSFORM_ERC20_ONE_WEI_VALUE,
});
const mtxHash = mtx.getHash();
const signature = await mtx.getSignatureWithProviderAsync(env.provider);
const callOpts = {
gasPrice: mtx.maxGasPrice,
value: mtx.value,
};
const tx = feature.executeMetaTransaction(mtx, signature).awaitTransactionSuccessAsync(callOpts);
return expect(tx).to.revertWith(
new ZeroExRevertErrors.MetaTransactions.MetaTransactionCallFailedError(
mtxHash,
undefined,
new ZeroExRevertErrors.Common.IllegalReentrancyError(
feature.getSelector('executeMetaTransaction'),
REENTRANCY_FLAG_MTX,
).encode(),
),
// Send pre-existing ETH to the EP.
await env.web3Wrapper.awaitTransactionSuccessAsync(
await env.web3Wrapper.sendTransactionAsync({
from: owner,
to: zeroEx.address,
value: new BigNumber(1),
}),
);
});
it('cannot reenter `batchExecuteMetaTransactions()`', async () => {
const args = getRandomTransformERC20Args();
const mtx = getRandomMetaTransaction({
callData: transformERC20Feature
.transformERC20(
args.inputToken,
args.outputToken,
args.inputTokenAmount,
args.minOutputTokenAmount,
args.transformations,
)
.getABIEncodedTransactionData(),
value: TRANSFORM_ERC20_BATCH_REENTER_VALUE,
});
const mtxHash = mtx.getHash();
const signature = await mtx.getSignatureWithProviderAsync(env.provider);
const callOpts = {
gasPrice: mtx.maxGasPrice,
value: mtx.value,
};
const tx = feature.executeMetaTransaction(mtx, signature).awaitTransactionSuccessAsync(callOpts);
return expect(tx).to.revertWith(
new ZeroExRevertErrors.MetaTransactions.MetaTransactionCallFailedError(
mtxHash,
undefined,
new ZeroExRevertErrors.Common.IllegalReentrancyError(
feature.getSelector('batchExecuteMetaTransactions'),
REENTRANCY_FLAG_MTX,
).encode(),
),
);
return expect(tx).to.revertWith('MetaTransactionsFeature/ETH_LEAK');
});
});
@@ -817,6 +783,37 @@ blockchainTests.resets('MetaTransactions feature', env => {
),
);
});
it('cannot reduce initial ETH balance', async () => {
const args = getRandomTransformERC20Args();
const mtx = getRandomMetaTransaction({
callData: transformERC20Feature
.transformERC20(
args.inputToken,
args.outputToken,
args.inputTokenAmount,
args.minOutputTokenAmount,
args.transformations,
)
.getABIEncodedTransactionData(),
value: TRANSFORM_ERC20_ONE_WEI_VALUE,
});
const signature = await mtx.getSignatureWithProviderAsync(env.provider);
const callOpts = {
gasPrice: mtx.maxGasPrice,
value: mtx.value,
};
// Send pre-existing ETH to the EP.
await env.web3Wrapper.awaitTransactionSuccessAsync(
await env.web3Wrapper.sendTransactionAsync({
from: owner,
to: zeroEx.address,
value: new BigNumber(1),
}),
);
const tx = feature.batchExecuteMetaTransactions([mtx], [signature]).awaitTransactionSuccessAsync(callOpts);
return expect(tx).to.revertWith('MetaTransactionsFeature/ETH_LEAK');
});
});
describe('getMetaTransactionExecutedBlock()', () => {

View File

@@ -79,11 +79,12 @@ export * from '../test/generated-wrappers/liquidity_provider_feature';
export * from '../test/generated-wrappers/liquidity_provider_sandbox';
export * from '../test/generated-wrappers/log_metadata_transformer';
export * from '../test/generated-wrappers/meta_transactions_feature';
export * from '../test/generated-wrappers/mixin_aave_v2';
export * from '../test/generated-wrappers/mixin_balancer';
export * from '../test/generated-wrappers/mixin_balancer_v2';
export * from '../test/generated-wrappers/mixin_bancor';
export * from '../test/generated-wrappers/mixin_clipper';
export * from '../test/generated-wrappers/mixin_co_fi_x';
export * from '../test/generated-wrappers/mixin_compound';
export * from '../test/generated-wrappers/mixin_crypto_com';
export * from '../test/generated-wrappers/mixin_curve';
export * from '../test/generated-wrappers/mixin_curve_v2';

View File

@@ -112,11 +112,12 @@
"test/generated-artifacts/LiquidityProviderSandbox.json",
"test/generated-artifacts/LogMetadataTransformer.json",
"test/generated-artifacts/MetaTransactionsFeature.json",
"test/generated-artifacts/MixinAaveV2.json",
"test/generated-artifacts/MixinBalancer.json",
"test/generated-artifacts/MixinBalancerV2.json",
"test/generated-artifacts/MixinBancor.json",
"test/generated-artifacts/MixinClipper.json",
"test/generated-artifacts/MixinCoFiX.json",
"test/generated-artifacts/MixinCompound.json",
"test/generated-artifacts/MixinCryptoCom.json",
"test/generated-artifacts/MixinCurve.json",
"test/generated-artifacts/MixinCurveV2.json",

View File

@@ -2,47 +2,15 @@
Bounties
###############################
We run an ongoing bug bounty for the 0x Protocol smart contracts! The program is open to anyone and
rewards up to **$100,000 for critical exploits**. The scope and disclosure instructions are below.
Rewards
-------
The severity of reported vulnerabilities will be graded according to the `CVSS <https://www.first.org/cvss/>`_ (Common Vulnerability Scoring Standard).
The following table will serve as a guideline for reward decisions:
The bug bounties on this page apply only to the *0x smart contracts* on Ethereum mainnet, Binance Smart Chain, Polygon, Avalanche, Fantom, Celo, Optimism and future deployments in other EVM-compatible networks announced through our official communication channels.
+----------------------------+---------------------+
| **Exploit Score** | **Reward** |
+----------------------------+---------------------+
| Critical (CVSS 9.0 - 10.0) | $10,000 - $100,000 |
+----------------------------+---------------------+
| High (CVSS 7.0 - 8.9) | $2,500 - $10,000 |
+----------------------------+---------------------+
| Medium (CVSS 4.0 - 6.9) | $1,000 - $2,500 |
+----------------------------+---------------------+
| Low (CVSS 0.0 - 3.9) | $0 - $1,000 |
+----------------------------+---------------------+
Bug reports pertaining to 0x API and 0x web interfaces (e.g. Matcha, 0x.org), both in terms of UI/UX or servers/infrastructure, are not eligible. Only the first reporter of a given contract vulnerability will be rewarded, and findings already discovered as part of a formal audit are ineligible.
Please note that any rewards will ultimately be awarded at the discretion of ZeroEx Intl. All rewards will be paid out in ZRX.
Overview
--------
Areas of Interest
-----------------
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Area** | **Examples** |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Loss of funds | * A user loses funds in a way that they did not explicitly authorize (e.g an account is able to gain access to an ``AssetProxy`` and drain user funds). |
| | * A user authorized a transaction or trade but spends more assets than normally expected (e.g an order is allowed to be over-filled). |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Unintended contract state | * A user is able to update the state of a contract such that it is no longer useable (e.g permanently lock a mutex). |
| | * Any assets get unexpectedly "stuck" in a contract with regular use of the contract's public methods. |
| | * An action taken in the staking contracts is applied to an incorrect epoch. |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Bypassing time locks | * The ``ZeroExGovernor`` is allowed to bypass the timelock for transactions where it is not explicitly allowed to do so. |
| | * A user is allowed to bypass the ``ZeroExGovernor``. |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Incorrect math | * Overflows or underflow result in unexpected behavior. |
| | * The staking reward payouts are incorrect. |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
0x has completed smart contract audits with Consensys Diligence, Trail of Bits and ABDK. We run a continuous bug bounty program for the V4 release of the 0x core contracts.
Scope
-----
@@ -51,14 +19,14 @@ The following contracts are in scope of the bug bounty. Please note that any bug
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| **Release** | **Contracts** | **Commit Hash** |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V4 | * Documentation at `https://0xprotocol.readthedocs.io/en/latest/ <https://0xprotocol.readthedocs.io/en/latest/>`__ | `72a74e7c66 <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src>`__ |
| | * `ZeroEx.sol <https://github.com/0xProject/protocol/blob/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/ZeroEx.sol>`__ | |
| | * `ZeroExOptimized.sol <https://github.com/0xProject/protocol/blob/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/ZeroExOptimized.sol>`__ | |
| | * `external/*.sol <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/external>`__ | |
| | * `features/**.sol <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/features>`__ | |
| | * `fixins/*.sol <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/fixins>`__ | |
| | * `migrations/*.sol <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/migrations>`__ | |
| | * `storage/*.sol <https://github.com/0xProject/protocol/tree/72a74e7c66e27da02dd9f4ce604ad057c740c304/contracts/zero-ex/contracts/src/storage>`__ | |
| Exchange V4 | * Documentation at `https://protocol.0x.org/en/latest/ <https://protocol.0x.org/en/latest/>`__ | `2cbeb9c <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src>`__ |
| | * `ZeroEx.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/ZeroEx.sol>`__ | |
| | * `ZeroExOptimized.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/ZeroExOptimized.sol>`__ | |
| | * `external/*.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/external>`__ | |
| | * `features/**.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/features>`__ | |
| | * `fixins/*.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/fixins>`__ | |
| | * `migrations/*.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/migrations>`__ | |
| | * `storage/*.sol <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src/storage>`__ | |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V3 | * `ERC20BridgeProxy.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/asset-proxy/contracts/src/ERC20BridgeProxy.sol>`_ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/asset-proxy/erc20-bridge-proxy.md>`__) | `fb8360edfd <https://github.com/0xProject/0x-monorepo/tree/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts>`__ |
| | * `Exchange.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/exchange/contracts/src/Exchange.sol>`__ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md>`__) | |
@@ -67,7 +35,7 @@ The following contracts are in scope of the bug bounty. Please note that any bug
| | * `StakingProxy.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/staking/contracts/src/StakingProxy.sol>`_ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/staking/staking-specification.md>`__) | |
| | * `ZrxVault.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/staking/contracts/src/ZrxVault.sol>`_ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/staking/staking-specification.md>`__) | |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V2.1 | * `src/2.0.0/protocol <https://github.com/0xProject/0x-monorepo/tree/ff70c5ecfe28eff14e1a372c5e493b8f5363e1d0/packages/contracts/src/2.0.0/protocol>`_ | `ff70c5ecfe <https://github.com/0xProject/0x-monorepo/tree/ff70c5ecfe28eff14e1a372c5e493b8f5363e1d0/contracts>`_ |
| Exchange V2.1 | * `src/2.0.0/protocol <https://github.com/0xProject/0x-monorepo/tree/ff70c5ecfe28eff14e1a372c5e493b8f5363e1d0/packages/contracts/src/2.0.0/protocol>`_ | `ff70c5ecfe <https://github.com/0xProject/0x-monorepo/tree/ff70c5ecfe28eff14e1a372c5e493b8f5363e1d0/packages/contracts/src/2.0.0>`_ |
| | * `src/2.0.0/utils <https://github.com/0xProject/0x-monorepo/tree/ff70c5ecfe28eff14e1a372c5e493b8f5363e1d0/packages/contracts/src/2.0.0/utils>`_ | |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| MultiAssetProxy | * `MultiAssetProxy.sol <https://github.com/0xProject/0x-monorepo/blob/c4d9ef9f83508154fe9db35796b6b86aeb0f2240/contracts/asset-proxy/contracts/src/MultiAssetProxy.sol>`_ | `c4d9ef9f83 <https://github.com/0xProject/0x-monorepo/tree/c4d9ef9f83508154fe9db35796b6b86aeb0f2240/contracts>`_ |
@@ -78,9 +46,37 @@ The following contracts are in scope of the bug bounty. Please note that any bug
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ERC20BridgeProxy | * `ERC20BridgeProxy.sol <https://github.com/0xProject/0x-monorepo/blob/281658ba349a2c5088b40b503998bea5020284a6/contracts/asset-proxy/contracts/src/ERC20BridgeProxy.sol>`__ | `281658ba34 <https://github.com/0xProject/0x-monorepo/tree/281658ba349a2c5088b40b503998bea5020284a6/contracts>`_ |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ExchangeProxy | * `contracts/src <https://github.com/0xProject/0x-monorepo/tree/7967a8416c76e34ff5a0a4eb80e7b33ff8c0e297/contracts/zero-ex>`__ | `7967a8416c <https://github.com/0xProject/0x-monorepo/tree/7967a8416c76e34ff5a0a4eb80e7b33ff8c0e297/contracts>`_ |
| ExchangeProxy | * `contracts/src <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src>`__ | `2cbeb9c <https://github.com/0xProject/protocol/tree/audit/nft-orders-address-findings/contracts/zero-ex/contracts/src>`_ |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
Bounties
--------
The bounty program will pay out rewards according to the severity of a vulnerability. The severity of reported vulnerabilities will be graded according to the `CVSS <https://www.first.org/cvss/>`__ (Common Vulnerability Scoring Standard).
The final reward amount is at the sole discretion of 0x Labs and will be paid in the specified sum in either USD or ETH.
+----------------------------+---------------------+
| **Exploit Score** | **Reward** |
+----------------------------+---------------------+
| Critical (CVSS 9.0 - 10.0) | up to $1,000,000 |
+----------------------------+---------------------+
| High (CVSS 7.0 - 8.9) | up to $350,000 |
+----------------------------+---------------------+
| Medium (CVSS 4.0 - 6.9) | up to $35,000 |
+----------------------------+---------------------+
| Low (CVSS 0.0 - 3.9) | up to $5,000 |
+----------------------------+---------------------+
Recent Inclusions
-----------------
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Change** | **** |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| NFT feature | * Trade ERC721 and ERC1155 assets. See `ZEIP-93 <https://github.com/0xProject/ZEIPs/issues/93>`__ for more details |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
Disclosures
-----------
Please e-mail all submissions to security@0x.org with the subject "BUG BOUNTY". Your submission

View File

@@ -17,3 +17,10 @@ Known tokens:
- LINK
- sUSD
- USDT
Tokens with Fees on Transfer
----------------------------
These tokens do not follow the ERC20 specification. As such the protocol expects the transfer to transfer
the specified amount, or revert. Since tokens with transfer fees do not meet this criteria, the behaviour
of the protocol with these tokens is unspecified. In most cases it will result in an overall transaction failure
due to various slippage protections.

View File

@@ -17,10 +17,12 @@ This page outlines upcoming releases and expected changes.
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| **Name** | **Overview** | **Est Release Date** | **Status** | **Additional** |
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| `Amaretto`_ | Protocol 4.1: Efficiency + Batch Fills | 03/15/21 | Development | |
| `Nifty`_ | ERC721 and ERC1155 support | 02/14/22 | Vote | |
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| *The following releases have been deployed* | | | | |
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| `Amaretto`_ | Protocol 4.1: Efficiency + Batch Fills | 03/15/21 | Deployed | |
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| `Babooshka`_ | Connect Exchange Proxy to Staking | 02/08/21 | Deployed | `Release Notes <https://github.com/0xProject/0x-migrations/blob/main/src/exchange-proxy/migrations/log/9_babooshka.md>`__ |
+---------------------------------------------+---------------------------------------------------------------+----------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------+
| `Squire`_ | Aggregation for `V4 Orders <../basics/orders.html>`_ | 02/04/21 | Deployed | N/A |
@@ -45,6 +47,19 @@ This page outlines upcoming releases and expected changes.
Upcoming
========
Nifty
--------
- ERC721 and ERC1155 order types
- Batch fills for NFT orders
- Property based orders
- Ability to receive ETH in NFT orders
Past
=====
Amaretto
--------
@@ -53,10 +68,6 @@ Amaretto
- Mooniswap VIP
- Curve / Swerve VIP (via PLP Sandbox)
Past
=====
Babooshka
----------

View File

@@ -57,18 +57,22 @@ Liquidity Aggregation
Liquidity can be pulled from other Decentralized Exchanges (DEX) to supplement native liquidity (0x orders). This is currently used by 0x API to provide the aggregate the best prices across the entire DEX Ecosystem. Check out `https://matcha.xyz <https://matcha.xyz>`_ to see this in action!
Supported DEX's:
Below are just a few of the Supported DEX's on Ethereum:
* Balancer
* Balancer v1/v2
* Bancor v1/v2
* Curve
* DoDo
* Dodo v1/v2
* Kyber
* MakerPSM
* MStable
* Mooniswap
* Oasis
* Shell
* Sushiswap
* Uniswap v1/v2
* Shibaswap
* Smoothy
* Uniswap v1/v2/v3
This transformation is implemented by the `FillQuoteTransformer <../architecture/transformers.html>`_. Abi-Encode the following struct to get the ``data``:

View File

@@ -6,16 +6,17 @@ Addresses
.. note::
This page is auto-generated. See the `contract-addresses <https://github.com/0xProject/protocol/blob/development/packages/contract-addresses/addresses.json>`_ package for an exhaustive list of contracts across all networks.
The Exchange Proxy may have different addresses on various networks, see the `Exchange Proxy Addresses <./addresses.html#exchange-proxy-addresses>`__ table for an exhaustive list.
Exchange V4
===================
.. csv-table::
exchangeProxy, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://etherscan.io/address//0xdef1c0ded9bec7f1a1670819833240f027b25eff>`_
exchangeProxyAllowanceTarget, `0xf740b67da229f2f10bcbd38a7979992fcc71b8eb <https://etherscan.io/address//0xf740b67da229f2f10bcbd38a7979992fcc71b8eb>`_
exchangeProxyFlashWallet, `0x22f9dcf4647084d6c31b2765f6910cd85c178c18 <https://etherscan.io/address//0x22f9dcf4647084d6c31b2765f6910cd85c178c18>`_
exchangeProxyGovernor, `0x618f9c67ce7bf1a50afa1e7e0238422601b0ff6e <https://etherscan.io/address//0x618f9c67ce7bf1a50afa1e7e0238422601b0ff6e>`_
exchangeProxyLiquidityProviderSandbox, `0x407b4128e9ecad8769b2332312a9f655cb9f5f3a <https://etherscan.io/address//0x407b4128e9ecad8769b2332312a9f655cb9f5f3a>`_
exchangeProxyTransformerDeployer, `0x39dce47a67ad34344eab877eae3ef1fa2a1d50bb <https://etherscan.io/address//0x39dce47a67ad34344eab877eae3ef1fa2a1d50bb>`_
exchangeProxy, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://etherscan.io/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__
exchangeProxyFlashWallet, `0x22f9dcf4647084d6c31b2765f6910cd85c178c18 <https://etherscan.io/address/0x22f9dcf4647084d6c31b2765f6910cd85c178c18>`__
exchangeProxyGovernor, `0x618f9c67ce7bf1a50afa1e7e0238422601b0ff6e <https://etherscan.io/address/0x618f9c67ce7bf1a50afa1e7e0238422601b0ff6e>`__
exchangeProxyLiquidityProviderSandbox, `0x407b4128e9ecad8769b2332312a9f655cb9f5f3a <https://etherscan.io/address/0x407b4128e9ecad8769b2332312a9f655cb9f5f3a>`__
exchangeProxyTransformerDeployer, `0x39dce47a67ad34344eab877eae3ef1fa2a1d50bb <https://etherscan.io/address/0x39dce47a67ad34344eab877eae3ef1fa2a1d50bb>`__
@@ -23,10 +24,11 @@ Transformers
===================
.. csv-table::
wethTransformer, `0xb2bc06a4efb20fc6553a69dbfa49b7be938034a7 <https://etherscan.io/address//0xb2bc06a4efb20fc6553a69dbfa49b7be938034a7>`_
payTakerTransformer, `0x4638a7ebe75b911b995d0ec73a81e4f85f41f24e <https://etherscan.io/address//0x4638a7ebe75b911b995d0ec73a81e4f85f41f24e>`_
fillQuoteTransformer, `0x5ce5174d7442061135ea849970ffc7763920e0fd <https://etherscan.io/address//0x5ce5174d7442061135ea849970ffc7763920e0fd>`_
affiliateFeeTransformer, `0xda6d9fc5998f550a094585cf9171f0e8ee3ac59f <https://etherscan.io/address//0xda6d9fc5998f550a094585cf9171f0e8ee3ac59f>`_
wethTransformer, `0xb2bc06a4efb20fc6553a69dbfa49b7be938034a7 <https://etherscan.io/address/0xb2bc06a4efb20fc6553a69dbfa49b7be938034a7>`__
payTakerTransformer, `0x4638a7ebe75b911b995d0ec73a81e4f85f41f24e <https://etherscan.io/address/0x4638a7ebe75b911b995d0ec73a81e4f85f41f24e>`__
affiliateFeeTransformer, `0xda6d9fc5998f550a094585cf9171f0e8ee3ac59f <https://etherscan.io/address/0xda6d9fc5998f550a094585cf9171f0e8ee3ac59f>`__
fillQuoteTransformer, `0xb4fa284689c9784a60d840eb136bb16c5246191f <https://etherscan.io/address/0xb4fa284689c9784a60d840eb136bb16c5246191f>`__
positiveSlippageFeeTransformer, `0xa9416ce1dbde8d331210c07b5c253d94ee4cc3fd <https://etherscan.io/address/0xa9416ce1dbde8d331210c07b5c253d94ee4cc3fd>`__
@@ -34,10 +36,10 @@ ZRX / Staking
===================
.. csv-table::
staking, `0x2a17c35ff147b32f13f19f2e311446eeb02503f3 <https://etherscan.io/address//0x2a17c35ff147b32f13f19f2e311446eeb02503f3>`_
stakingProxy, `0xa26e80e7dea86279c6d778d702cc413e6cffa777 <https://etherscan.io/address//0xa26e80e7dea86279c6d778d702cc413e6cffa777>`_
zrxToken, `0xe41d2489571d322189246dafa5ebde1f4699f498 <https://etherscan.io/address//0xe41d2489571d322189246dafa5ebde1f4699f498>`_
zrxVault, `0xba7f8b5fb1b19c1211c5d49550fcd149177a5eaf <https://etherscan.io/address//0xba7f8b5fb1b19c1211c5d49550fcd149177a5eaf>`_
staking, `0x2a17c35ff147b32f13f19f2e311446eeb02503f3 <https://etherscan.io/address/0x2a17c35ff147b32f13f19f2e311446eeb02503f3>`__
stakingProxy, `0xa26e80e7dea86279c6d778d702cc413e6cffa777 <https://etherscan.io/address/0xa26e80e7dea86279c6d778d702cc413e6cffa777>`__
zrxToken, `0xe41d2489571d322189246dafa5ebde1f4699f498 <https://etherscan.io/address/0xe41d2489571d322189246dafa5ebde1f4699f498>`__
zrxVault, `0xba7f8b5fb1b19c1211c5d49550fcd149177a5eaf <https://etherscan.io/address/0xba7f8b5fb1b19c1211c5d49550fcd149177a5eaf>`__
@@ -45,9 +47,22 @@ Miscellaneous
===================
.. csv-table::
devUtils, `0x74134cf88b21383713e096a5ecf59e297dc7f547 <https://etherscan.io/address//0x74134cf88b21383713e096a5ecf59e297dc7f547>`_
etherToken, `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 <https://etherscan.io/address//0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2>`_
erc20BridgeSampler, `0xd8c38704c9937ea3312de29f824b4ad3450a5e61 <https://etherscan.io/address//0xd8c38704c9937ea3312de29f824b4ad3450a5e61>`_
devUtils, `0x74134cf88b21383713e096a5ecf59e297dc7f547 <https://etherscan.io/address/0x74134cf88b21383713e096a5ecf59e297dc7f547>`__
etherToken, `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 <https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2>`__
erc20BridgeSampler, `0xd8c38704c9937ea3312de29f824b4ad3450a5e61 <https://etherscan.io/address/0xd8c38704c9937ea3312de29f824b4ad3450a5e61>`__
Exchange Proxy Addresses
=========================
Note: Some addresses have changed across various networks
.. csv-table::
Ethereum, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://etherscan.io/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__
Optimism, `0xdef1abe32c034e558cdd535791643c58a13acc10 <https://optimistic.etherscan.io/address/0xdef1abe32c034e558cdd535791643c58a13acc10>`__
Binance Smart Chain, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://bscscan.com/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__
Polygon, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://polygonscan.com/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__
Avalanche, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://snowtrace.io/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__
Fantom, `0xdef189deaef76e379df891899eb5a00a94cbc250 <https://ftmscan.com/address/0xdef189deaef76e379df891899eb5a00a94cbc250>`__
Celo, `0xdef1c0ded9bec7f1a1670819833240f027b25eff <https://explorer.celo.org/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff>`__

View File

@@ -2,6 +2,4 @@
Allowances
###############################
Both maker and taker allowance should be be set directly on the `Exchange Proxy contract <./addresses.html#exchange-v4>`_.
For takers, legacy allowances set on the `Allowance Target <./addresses.html#exchange-v4>`_ will continue to work during this transition period but will suffer a gas penalty. It's highly encouraged to migrate allowances over to the Exchange Proxy as soon as possible to avoid interruption.
Both maker and taker allowance should be be set directly on the `Exchange Proxy contract <./addresses.html#exchange-proxy-addresses>`_.

View File

@@ -61,6 +61,18 @@ illustrates how events are emitted when trading through the Exchange Proxy.
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `TransformerMetadata`_ | A general, customizable event emitted that can be emitted by transformers as-needed. | FlashWallet |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC1155OrderFilled`_ | Emitted when a `V4 ERC1155 Order <./orders.html#erc1155-orders>`_ is filled. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC721OrderFilled`_ | Emitted when a `V4 ERC721 Order <./orders.html#erc721-orders>`_ is filled. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC1155OrderCancelled`_ | Emitted when a `V4 ERC1155 Order <./orders.html#erc1155-orders>`_ is cancelled. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC721OrderCancelled`_ | Emitted when a `V4 ERC721 Order <./orders.html#erc721-orders>`_ is cancelled. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC1155OrderPreSigned`_ | Emitted when a `V4 ERC1155 Order <./orders.html#erc1155-orders>`_ is signed on-chain. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
| `ERC721OrderPreSigned`_ | Emitted when a `V4 ERC721 Order <./orders.html#erc721-orders>`_ is signed on-chain. | ExchangeProxy |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+
Deployed
@@ -374,6 +386,143 @@ TransformerMetadata
);
ERC721OrderFilled
-------------------
.. code-block:: solidity
/// @dev Emitted whenever an `ERC721Order` is filled.
/// @param direction Whether the order is selling or
/// buying the ERC721 token.
/// @param maker The maker of the order.
/// @param taker The taker of the order.
/// @param nonce The unique maker nonce in the order.
/// @param erc20Token The address of the ERC20 token.
/// @param erc20TokenAmount The amount of ERC20 token
/// to sell or buy.
/// @param erc721Token The address of the ERC721 token.
/// @param erc721TokenId The ID of the ERC721 asset.
/// @param matcher If this order was matched with another using `matchERC721Orders()`,
/// this will be the address of the caller. If not, this will be `address(0)`.
event ERC721OrderFilled(
LibNFTOrder.TradeDirection direction,
address maker,
address taker,
uint256 nonce,
IERC20TokenV06 erc20Token,
uint256 erc20TokenAmount,
IERC721Token erc721Token,
uint256 erc721TokenId,
address matcher
);
ERC721OrderCancelled
---------------------
.. code-block:: solidity
/// @dev Emitted whenever an `ERC721Order` is cancelled.
/// @param maker The maker of the order.
/// @param nonce The nonce of the order that was cancelled.
event ERC721OrderCancelled(
address maker,
uint256 nonce
);
ERC721OrderPreSigned
---------------------
.. code-block:: solidity
/// @dev Emitted when an `ERC721Order` is pre-signed.
/// Contains all the fields of the order.
event ERC721OrderPreSigned(
LibNFTOrder.TradeDirection direction,
address maker,
address taker,
uint256 expiry,
uint256 nonce,
IERC20TokenV06 erc20Token,
uint256 erc20TokenAmount,
LibNFTOrder.Fee[] fees,
IERC721Token erc721Token,
uint256 erc721TokenId,
LibNFTOrder.Property[] erc721TokenProperties
);
ERC1155OrderFilled
-------------------
.. code-block:: solidity
/// @dev Emitted whenever an `ERC1155Order` is filled.
/// @param direction Whether the order is selling or
/// buying the ERC1155 token.
/// @param maker The maker of the order.
/// @param taker The taker of the order.
/// @param nonce The unique maker nonce in the order.
/// @param erc20Token The address of the ERC20 token.
/// @param erc20FillAmount The amount of ERC20 token filled.
/// @param erc1155Token The address of the ERC1155 token.
/// @param erc1155TokenId The ID of the ERC1155 asset.
/// @param erc1155FillAmount The amount of ERC1155 asset filled.
/// @param matcher Currently unused.
event ERC1155OrderFilled(
LibNFTOrder.TradeDirection direction,
address maker,
address taker,
uint256 nonce,
IERC20TokenV06 erc20Token,
uint256 erc20FillAmount,
IERC1155Token erc1155Token,
uint256 erc1155TokenId,
uint128 erc1155FillAmount,
address matcher
);
ERC1155OrderCancelled
---------------------
.. code-block:: solidity
/// @dev Emitted whenever an `ERC1155Order` is cancelled.
/// @param orderHash The hash the order.
/// @param maker The maker of the order.
event ERC1155OrderCancelled(
bytes32 orderHash,
address maker
);
ERC1155OrderPreSigned
---------------------
.. code-block:: solidity
/// @dev Emitted when an `ERC1155Order` is pre-signed.
/// Contains all the fields of the order.
event ERC1155OrderPreSigned(
LibNFTOrder.TradeDirection direction,
address maker,
address taker,
uint256 expiry,
uint256 nonce,
IERC20TokenV06 erc20Token,
uint256 erc20TokenAmount,
LibNFTOrder.Fee[] fees,
IERC1155Token erc1155Token,
uint256 erc1155TokenId,
LibNFTOrder.Property[] erc1155TokenProperties,
uint128 erc1155TokenAmount
);

View File

@@ -67,6 +67,46 @@ Below is a catalog of basic Exchange functionality. For more advanced usage, lik
| `transferProtocolFeesForPools`_ | Transfers protocol fees from escrow to the 0x Staking System. |
| | This should be called near the end of each epoch. |
+-----------------------------------------+--------------------------------------------------------------------------+
| **NFT Orders** | **Overview** |
+-----------------------------------------+--------------------------------------------------------------------------+
| `sellERC721`_ | These are specialised orders for NFT trading |
+-----------------------------------------+ |
| `buyERC721`_ | |
+-----------------------------------------+ |
| `batchBuyERC721s`_ | |
+-----------------------------------------+ |
| `matchERC721Orders`_ | |
+-----------------------------------------+ |
| `batchMatchERC721Orders`_ | |
+-----------------------------------------+ |
| `preSignERC721Order`_ | |
+-----------------------------------------+ |
| `validateERC721OrderSignature`_ | |
+-----------------------------------------+ |
| `validateERC721OrderProperties`_ | |
+-----------------------------------------+ |
| `getERC721OrderStatus`_ | |
+-----------------------------------------+ |
| `getERC721OrderHash`_ | |
+-----------------------------------------+ +
| `sellERC1155`_ | |
+-----------------------------------------+ +
| `buyERC1155`_ | |
+-----------------------------------------+ +
| `batchCancelERC1155Orders`_ | |
+-----------------------------------------+ +
| `batchBuyERC1155s`_ | |
+-----------------------------------------+ +
| `preSignERC1155Order`_ | |
+-----------------------------------------+ +
| `validateERC1155OrderSignature`_ | |
+-----------------------------------------+ +
| `validateERC1155OrderProperties`_ | |
+-----------------------------------------+ +
| `getERC1155OrderInfo`_ | |
+-----------------------------------------+ +
| `getERC1155OrderHash`_ | |
+-----------------------------------------+--------------------------------------------------------------------------+
Limit Orders
@@ -733,3 +773,490 @@ This function transfers protocol fees from `Fee Collectors <../architecture/fee_
/// @param poolIds Staking pool IDs
function transferProtocolFeesForPools(bytes32[] calldata poolIds)
external;
NFT Orders
==========
sellERC721
----------------------------
This function sells an ERC721 token given a buy order.
.. code-block:: solidity
/// @dev Sells an ERC721 asset to fill the given order.
/// @param buyOrder The ERC721 buy order.
/// @param signature The order signature from the maker.
/// @param erc721TokenId The ID of the ERC721 asset being
/// sold. If the given order specifies properties,
/// the asset must satisfy those properties. Otherwise,
/// it must equal the tokenId in the order.
/// @param unwrapNativeToken If this parameter is true and the
/// ERC20 token of the order is e.g. WETH, unwraps the
/// token before transferring it to the taker.
/// @param callbackData If this parameter is non-zero, invokes
/// `zeroExERC721OrderCallback` on `msg.sender` after
/// the ERC20 tokens have been transferred to `msg.sender`
/// but before transferring the ERC721 asset to the buyer.
function sellERC721(
LibNFTOrder.ERC721Order _calldata_ buyOrder,
LibSignature.Signature _calldata_ signature,
uint256 erc721TokenId,
bool unwrapNativeToken,
bytes _calldata_ callbackData
)
_external_;
buyERC721
----------------------------
This function buys an ERC721 token given a sell order.
.. code-block:: solidity
/// @dev Buys an ERC721 asset by filling the given order.
/// @param sellOrder The ERC721 sell order.
/// @param signature The order signature.
/// @param callbackData If this parameter is non-zero, invokes
/// `zeroExERC721OrderCallback` on `msg.sender` after
/// the ERC721 asset has been transferred to `msg.sender`
/// but before transferring the ERC20 tokens to the seller.
/// Native tokens acquired during the callback can be used
/// to fill the order.
function buyERC721(
LibNFTOrder.ERC721Order _calldata_ sellOrder,
LibSignature.Signature _calldata_ signature,
bytes _calldata_ callbackData
)
_external_
_payable_;
cancelERC721Order
----------------------------
This function cancels an ERC721 order using the order `nonce` field.
.. code-block:: solidity
/// @dev Cancel a single ERC721 order by its nonce. The caller
/// should be the maker of the order. Silently succeeds if
/// an order with the same nonce has already been filled or
/// cancelled.
/// @param orderNonce The order nonce.
function cancelERC721Order(uint256 orderNonce)
_external_;
batchCancelERC721Orders
----------------------------
This function cancels an number of ERC721 order using the order `nonce` field.
.. code-block:: solidity
/// @dev Cancel multiple ERC721 orders by their nonces. The caller
/// should be the maker of the orders. Silently succeeds if
/// an order with the same nonce has already been filled or
/// cancelled.
/// @param orderNonces The order nonces.
function batchCancelERC721Orders(uint256[] _calldata_ orderNonces)
_external_;
batchBuyERC721s
----------------------------
This function buys a number of ERC721's. If you wish the transaction to revert unless ALL NFT's are purchased, set `revertIfIncomplete` to true.
.. code-block:: solidity
/// @dev Buys multiple ERC721 assets by filling the
/// given orders.
/// @param sellOrders The ERC721 sell orders.
/// @param signatures The order signatures.
/// @param revertIfIncomplete If true, reverts if this
/// function fails to fill any individual order.
/// @return successes An array of booleans corresponding to whether
/// each order in `orders` was successfully filled.
function batchBuyERC721s(
LibNFTOrder.ERC721Order[] _calldata_ sellOrders,
LibSignature.Signature[] _calldata_ signatures,
bool revertIfIncomplete
)
_external_
_payable_
returns (bool[] _memory_ successes);
matchERC721Orders
----------------------------
This function matches a buy order and a sell order together. The matcher receives any spread in price.
.. code-block:: solidity
/// @dev Matches a pair of complementary orders that have
/// a non-negative spread. Each order is filled at
/// their respective price, and the matcher receives
/// a profit denominated in the ERC20 token.
/// @param sellOrder Order selling an ERC721 asset.
/// @param buyOrder Order buying an ERC721 asset.
/// @param sellOrderSignature Signature for the sell order.
/// @param buyOrderSignature Signature for the buy order.
/// @return profit The amount of profit earned by the caller
/// of this function (denominated in the ERC20 token
/// of the matched orders).
function matchERC721Orders(
LibNFTOrder.ERC721Order _calldata_ sellOrder,
LibNFTOrder.ERC721Order _calldata_ buyOrder,
LibSignature.Signature _calldata_ sellOrderSignature,
LibSignature.Signature _calldata_ buyOrderSignature
)
_external_
returns (uint256 profit);
batchMatchERC721Orders
----------------------------
This function matches a buy orders and a sell orders together. The matcher receives any spread in price.
.. code-block:: solidity
/// @dev Matches pairs of complementary orders that have
/// non-negative spreads. Each order is filled at
/// their respective price, and the matcher receives
/// a profit denominated in the ERC20 token.
/// @param sellOrders Orders selling ERC721 assets.
/// @param buyOrders Orders buying ERC721 assets.
/// @param sellOrderSignatures Signatures for the sell orders.
/// @param buyOrderSignatures Signatures for the buy orders.
/// @return profits The amount of profit earned by the caller
/// of this function for each pair of matched orders
/// (denominated in the ERC20 token of the order pair).
/// @return successes An array of booleans corresponding to
/// whether each pair of orders was successfully matched.
function batchMatchERC721Orders(
LibNFTOrder.ERC721Order[] _calldata_ sellOrders,
LibNFTOrder.ERC721Order[] _calldata_ buyOrders,
LibSignature.Signature[] _calldata_ sellOrderSignatures,
LibSignature.Signature[] _calldata_ buyOrderSignatures
)
_external_
returns (uint256[] _memory_ profits, bool[] _memory_ successes);
preSignERC721Order
----------------------------
This function pre-signs an order. Useful for contracts that wish to buy or sell an NFT.
.. code-block:: solidity
/// @dev Approves an ERC721 order on-chain. After pre-signing
/// the order, the `PRESIGNED` signature type will become
/// valid for that order and signer.
/// @param order An ERC721 order.
function preSignERC721Order(LibNFTOrder.ERC721Order _calldata_ order)
_external_;
validateERC721OrderSignature
----------------------------
A read function to validate an ERC721 order signature.
.. code-block:: solidity
/// @dev Checks whether the given signature is valid for the
/// the given ERC721 order. Reverts if not.
/// @param order The ERC721 order.
/// @param signature The signature to validate.
function validateERC721OrderSignature(
LibNFTOrder.ERC721Order _calldata_ order,
LibSignature.Signature _calldata_ signature
)
_external_
_view_;
validateERC721OrderProperties
---------------------------------
A read function to validate a property based order with a particular token id.
.. code-block:: solidity
/// @dev If the given order is buying an ERC721 asset, checks
/// whether or not the given token ID satisfies the required
/// properties specified in the order. If the order does not
/// specify any properties, this function instead checks
/// whether the given token ID matches the ID in the order.
/// Reverts if any checks fail, or if the order is selling
/// an ERC721 asset.
/// @param order The ERC721 order.
/// @param erc721TokenId The ID of the ERC721 asset.
function validateERC721OrderProperties(
LibNFTOrder.ERC721Order _calldata_ order,
uint256 erc721TokenId
)
_external_
_view_;
getERC721OrderStatus
----------------------------
A read function to return the order status. E.g whether it is filled, cancelled or expired.
.. code-block:: solidity
/// @dev Get the current status of an ERC721 order.
/// @param order The ERC721 order.
/// @return status The status of the order.
function getERC721OrderStatus(LibNFTOrder.ERC721Order _calldata_ order)
_external_
_view_
returns (LibNFTOrder.OrderStatus status);
getERC721OrderHash
----------------------------
A read function to return the uniquie order hash.
.. code-block:: solidity
/// @dev Get the canonical hash of an ERC721 order.
/// @param order The ERC721 order.
/// @return orderHash The order hash.
function getERC721OrderHash(LibNFTOrder.ERC721Order _calldata_ order)
_external_
_view_
returns (bytes32 orderHash);
getERC721OrderStatusBitVector
---------------------------------
.. code-block:: solidity
/// @dev Get the order status bit vector for the given
/// maker address and nonce range.
/// @param maker The maker of the order.
/// @param nonceRange Order status bit vectors are indexed
/// by maker address and the upper 248 bits of the
/// order nonce. We define `nonceRange` to be these
/// 248 bits.
/// @return bitVector The order status bit vector for the
/// given maker and nonce range.
function getERC721OrderStatusBitVector(address maker, uint248 nonceRange)
_external_
_view_
returns (uint256 bitVector);
sellERC1155
----------------------------
Sells an ERC115 token given a buy order.
.. code-block:: solidity
/// @dev Sells an ERC1155 asset to fill the given order.
/// @param buyOrder The ERC1155 buy order.
/// @param signature The order signature from the maker.
/// @param erc1155TokenId The ID of the ERC1155 asset being
/// sold. If the given order specifies properties,
/// the asset must satisfy those properties. Otherwise,
/// it must equal the tokenId in the order.
/// @param erc1155SellAmount The amount of the ERC1155 asset
/// to sell.
/// @param unwrapNativeToken If this parameter is true and the
/// ERC20 token of the order is e.g. WETH, unwraps the
/// token before transferring it to the taker.
/// @param callbackData If this parameter is non-zero, invokes
/// `zeroExERC1155OrderCallback` on `msg.sender` after
/// the ERC20 tokens have been transferred to `msg.sender`
/// but before transferring the ERC1155 asset to the buyer.
function sellERC1155(
LibNFTOrder.ERC1155Order _calldata_ buyOrder,
LibSignature.Signature _calldata_ signature,
uint256 erc1155TokenId,
uint128 erc1155SellAmount,
bool unwrapNativeToken,
bytes _calldata_ callbackData
)
_external_;
buyERC1155
----------------------------
Buys an ERC115 token given a sell order.
.. code-block:: solidity
/// @dev Buys an ERC1155 asset by filling the given order.
/// @param sellOrder The ERC1155 sell order.
/// @param signature The order signature.
/// @param erc1155BuyAmount The amount of the ERC1155 asset
/// to buy.
/// @param callbackData If this parameter is non-zero, invokes
/// `zeroExERC1155OrderCallback` on `msg.sender` after
/// the ERC1155 asset has been transferred to `msg.sender`
/// but before transferring the ERC20 tokens to the seller.
/// Native tokens acquired during the callback can be used
/// to fill the order.
function buyERC1155(
LibNFTOrder.ERC1155Order _calldata_ sellOrder,
LibSignature.Signature _calldata_ signature,
uint128 erc1155BuyAmount,
bytes _calldata_ callbackData
)
_external_
_payable_;
cancelERC1155Order
----------------------------
Cancels an ERC115 order given the order struct.
.. code-block:: solidity
/// @dev Cancel a single ERC1155 order. The caller should be the
/// maker of the order. Silently succeeds if the order has
/// already been filled or cancelled.
/// @param order The order to cancel.
function cancelERC1155Order(LibNFTOrder.ERC1155Order _calldata_ order)
_external_;
batchCancelERC1155Orders
----------------------------
Cancels a number of ERC115 orders.
.. code-block:: solidity
/// @dev Cancel multiple ERC1155 orders. The caller should be the
/// maker of the orders. Silently succeeds if an order has
/// already been filled or cancelled.
/// @param orders The orders to cancel.
function batchCancelERC1155Orders(LibNFTOrder.ERC1155Order[] _calldata_ orders)
_external_;
batchBuyERC1155s
----------------------------
Buys multiple ERC1155 assets given the sell orders.
.. code-block:: solidity
/// @dev Buys multiple ERC1155 assets by filling the
/// given orders.
/// @param sellOrders The ERC1155 sell orders.
/// @param signatures The order signatures.
/// @param erc1155TokenAmounts The amounts of the ERC1155 assets
/// to buy for each order.
/// @param revertIfIncomplete If true, reverts if this
/// function fails to fill any individual order.
/// @return successes An array of booleans corresponding to whether
/// each order in `orders` was successfully filled.
function batchBuyERC1155s(
LibNFTOrder.ERC1155Order[] _calldata_ sellOrders,
LibSignature.Signature[] _calldata_ signatures,
uint128[] _calldata_ erc1155TokenAmounts,
bool revertIfIncomplete
)
_external_
_payable_
returns (bool[] _memory_ successes);
preSignERC1155Order
----------------------------
Pre-signs the order on-chain. This is useful for smart contracts.
.. code-block:: solidity
/// @dev Approves an ERC1155 order on-chain. After pre-signing
/// the order, the `PRESIGNED` signature type will become
/// valid for that order and signer.
/// @param order An ERC1155 order.
function preSignERC1155Order(LibNFTOrder.ERC1155Order _calldata_ order)
_external_;
validateERC1155OrderSignature
---------------------------------
A read function to validate the ERC1155 order signatures.
.. code-block:: solidity
/// @dev Checks whether the given signature is valid for the
/// the given ERC1155 order. Reverts if not.
/// @param order The ERC1155 order.
/// @param signature The signature to validate.
function validateERC1155OrderSignature(
LibNFTOrder.ERC1155Order calldata order,
LibSignature.Signature calldata signature
)
external
view;
validateERC1155OrderProperties
---------------------------------
A read function to validate the specific ERC1155 asset against a property based order.
.. code-block:: solidity
/// @dev If the given order is buying an ERC1155 asset, checks
/// whether or not the given token ID satisfies the required
/// properties specified in the order. If the order does not
/// specify any properties, this function instead checks
/// whether the given token ID matches the ID in the order.
/// Reverts if any checks fail, or if the order is selling
/// an ERC1155 asset.
/// @param order The ERC1155 order.
/// @param erc1155TokenId The ID of the ERC1155 asset.
function validateERC1155OrderProperties(
LibNFTOrder.ERC1155Order calldata order,
uint256 erc1155TokenId
)
external
view;
getERC1155OrderInfo
----------------------------
A read function to get the ERC1155 order info. Such as whether it has been cancelled, expired or filled.
.. code-block:: solidity
/// @dev Get the order info for an ERC1155 order.
/// @param order The ERC1155 order.
/// @return orderInfo Infor about the order.
function getERC1155OrderInfo(LibNFTOrder.ERC1155Order calldata order)
external
view
returns (LibNFTOrder.OrderInfo memory orderInfo);
getERC1155OrderHash
----------------------------
A read function to calculate the unique order hash.
.. code-block:: solidity
/// @dev Get the canonical hash of an ERC1155 order.
/// @param order The ERC1155 order.
/// @return orderHash The order hash.
function getERC1155OrderHash(LibNFTOrder.ERC1155Order calldata order)
external
view
returns (bytes32 orderHash);

View File

@@ -89,10 +89,160 @@ The ``RFQOrder`` struct has the following fields:
+-----------------+-------------+----------------------------------------------------------------------------------------------------------------------------+
NFT Orders
===========
NFT orders in 0x V4 are optimized for this specific use case. They are up to 54% cheaper than alternatives currently on Ethereum.
Unlike 0x Limit orders, there is a `direction` of the trade, either buy or sell. ERC20's can be exchanged for either ERC721 or ERC1155.
Property based orders can also be created by specifying the properties field in the respective order.
A number of fees can be embedded in the order.
`NFT Swap SDK <https://docs.swapsdk.xyz/0x-v4>`__ is a friendly library that will help you easily create and consume NFT orders in 0x V4. You can find their `documentation here <https://docs.swapsdk.xyz/0x-v4>`__.
ERC721 Orders
*************
The ``ERC721Order`` struct has the following fields:
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| Field | Type | Description |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``direction`` | ``enum`` | The trade direction, either sell the NFT or buy the NFT |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``maker`` | ``address`` | The address of the maker, and signer, of this order. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``taker`` | ``address`` | Allowed taker address. Set to zero to allow any taker. [optional; default 0] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``expiry`` | ``uint256`` | The Unix timestamp in seconds when this order expires. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``nonce`` | ``uint256`` | Number used to uniquiely represent this order. Used for cancellations. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc20Token`` | ``address`` | The ERC20 token used to pay for the ERC721 token. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc20TokenAmount`` | ``uint256`` | The amount of erc20Token being sold. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``fees`` | ``Fees[]`` | An array of structs containing the fee data [optional] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc721Token`` | ``address`` | The ERC721 token. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc721TokenId`` | ``uint256`` | The ERC721 token id. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc721TokenProperties`` | ``Property[]`` | Properties to validate for a property based order. [optional] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
ERC1155 Orders
***************
The ``ERC1155Order`` struct has the following fields:
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| Field | Type | Description |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``direction`` | ``enum`` | The trade direction, either sell the NFT or buy the NFT |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``maker`` | ``address`` | The address of the maker, and signer, of this order. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``taker`` | ``address`` | Allowed taker address. Set to zero to allow any taker. [optional; default 0] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``expiry`` | ``uint256`` | The Unix timestamp in seconds when this order expires. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``nonce`` | ``uint256`` | Number used to uniquiely represent this order. Used for cancellations. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc20Token`` | ``address`` | The ERC20 token used to pay for the ERC721 token. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc20TokenAmount`` | ``uint256`` | The amount of erc20Token being sold. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``fees`` | ``Fees[]`` | An array of structs containing the fee data [optional] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc1155Token`` | ``address`` | The ERC1155 token. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc1155TokenId`` | ``uint256`` | The ERC1155 token id. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc1155TokenProperties`` | ``Property[]`` | Properties to validate for a property based order. [optional] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``erc1155TokenAmount`` | ``uin128`` | The ERC1155 amount. [required] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
NFT Order Property
******************
For Property based NFT orders, the properties have the following fields:
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| Field | Type | Description |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``propertyValidator`` | ``address`` | The address of the contract which implements `IPropertyValidator`. |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``propertyData`` | ``bytes`` | The address of the maker, and signer, of this order. |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
The property validator contract must implement the following interface when Property based orders are used.
.. code-block:: solidity
/// @dev Checks that the given ERC721/ERC1155 asset satisfies the properties encoded in `propertyData`.
/// Should revert if the asset does not satisfy the specified properties.
/// @param tokenAddress The ERC721/ERC1155 token contract address.
/// @param tokenId The ERC721/ERC1155 tokenId of the asset to check.
/// @param propertyData Encoded properties or auxiliary data needed to perform the check.
function validateProperty(
address tokenAddress,
uint256 tokenId,
bytes calldata propertyData
)
external
view;
NFT Order Fee
**************
For NFT orders with fees, the fees have the following fields:
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| Field | Type | Description |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``receipient`` | ``address`` | The receipient of the fees. |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``amount`` | ``uint256`` | The amount of fee to be paid to recipient. |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
| ``feeData`` | ``bytes`` | If provided the recipient (contract) will be called with this feeData [optional] |
+----------------------------+-----------------+------------------------------------------------------------------------------------------+
The contract must implement the following interface when the `feeData` is present.
.. code-block:: solidity
interface IFeeRecipient {
/// @dev A callback function invoked in the ERC721Feature for each ERC721
/// order fee that get paid. Integrators can make use of this callback
/// to implement arbitrary fee-handling logic, e.g. splitting the fee
/// between multiple parties.
/// @param tokenAddress The address of the token in which the received fee is
/// denominated. `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` indicates
/// that the fee was paid in the native token (e.g. ETH).
/// @param amount The amount of the given token received.
/// @param feeData Arbitrary data encoded in the `Fee` used by this callback.
/// @return success The selector of this function (0x0190805e),
/// indicating that the callback succeeded.
function receiveFeeCallback(
address tokenAddress,
uint256 amount,
bytes calldata feeData
)
external
returns (bytes4 success);
}
How To Sign
==============
Both Limit & RFQ orders must be signed by the `maker` or a registered order signer (`registerAllowedOrderSigner <./functions.html#registerallowedrfqorigins>`_). This signature is needed to fill an order, see `Basic Functionality <./functions.html>`_.
Orders must be signed by the `maker` or a registered order signer (`registerAllowedOrderSigner <./functions.html#registerallowedrfqorigins>`_). This signature is needed to fill an order, see `Basic Functionality <./functions.html>`_.
The protocol accepts signatures defined by the following struct:

View File

@@ -3,10 +3,14 @@ Protocol Fees
###############################
An ETH protocol fee is paid by the Taker each time a `Limit Order <./orders.html#limit-orders>`_ is `filled <./functions.html>`_.
The fee is proportional to the gas cost of filling an order and scales linearly with gas price. The cost is currently ``70k * tx.gasprice``.
The fee is proportional to the gas cost of filling an order and scales linearly with gas price. The cost is currently ``0 * tx.gasprice``.
At the end of every Staking Epoch, these fees are aggregated and distributed to the makers as a liquidity reward: the reward is proportional to the maker's collected fees and staked ZRX relative to other makers.
To learn more about protocol fees and liquidity incentives, see the `Official Spec <https://github.com/0xProject/0x-protocol-specification/blob/master/staking/staking-specification.md>`_.
.. note::
As of September 29, 2021, protocol fees have been removed for all order types in both Exchange V4 and V3 in accordance with `ZEIP-91 <https://0x.org/zrx/vote/zeip-91>`_.
.. note::
`RFQ Orders <./orders.html#rfq-orders>`_ are introduced in Exchange V4, and there is currently no protocol fee for filling this type of order.

View File

@@ -60,9 +60,9 @@ copyright = u'2016, ZeroEx Inc'
# built documents.
#
# The short X.Y version.
version = '4.0'
version = '4.1'
# The full version, including alpha/beta/rc tags.
release = '4.0'
release = '4.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@@ -12,7 +12,6 @@ sections = [
"name": "Exchange V4",
"contracts": [
'exchangeProxy',
'exchangeProxyAllowanceTarget',
'exchangeProxyFlashWallet',
'exchangeProxyGovernor',
'exchangeProxyLiquidityProviderSandbox',
@@ -50,18 +49,43 @@ sections = [
}
]
def printRow(contract, address):
etherscanLink = "%s/%s"%("https://etherscan.io/address/", address)
print(" %s, `%s <%s>`_"%(contract, address, etherscanLink))
networks = {
'1': 'Ethereum',
'10': 'Optimism',
'56': 'Binance Smart Chain',
'137': 'Polygon',
'43114': 'Avalanche',
'250': 'Fantom',
'42220': 'Celo',
}
def printTable(contracts, addresses):
etherscanByNetwork = {
'1': 'https://etherscan.io/address',
'10': 'https://optimistic.etherscan.io/address',
'56': 'https://bscscan.com/address',
'137': 'https://polygonscan.com/address',
'43114': 'https://snowtrace.io/address',
'250': 'https://ftmscan.com/address',
'42220': 'https://explorer.celo.org/address',
}
def getLinkableAddress(address, network):
etherscanLink = "%s/%s"%(etherscanByNetwork[network], address)
return "`%s <%s>`__"%(address, etherscanLink)
def printRow(contract, address, network):
etherscanLink = "%s/%s"%(etherscanByNetwork[network], address)
print(" %s, %s"%(contract, getLinkableAddress(address, network)))
def printTable(contracts, addresses, network):
print(".. csv-table::\n")
for contract in contracts:
if isinstance(addresses[contract], unicode):
printRow(contract, addresses[contract])
if isinstance(addresses[contract], str):
printRow(contract, addresses[contract], network)
else:
for contract,address in addresses[contract].items():
printRow(contract, address)
printRow(contract, address, network)
print(
@@ -72,6 +96,8 @@ Addresses
.. note::
This page is auto-generated. See the `contract-addresses <https://github.com/0xProject/protocol/blob/development/packages/contract-addresses/addresses.json>`_ package for an exhaustive list of contracts across all networks.
The Exchange Proxy may have different addresses on various networks, see the `Exchange Proxy Addresses <./addresses.html#exchange-proxy-addresses>`__ table for an exhaustive list.
'''
)
@@ -79,6 +105,13 @@ with open('../packages/contract-addresses/addresses.json') as f:
addresses = json.load(f)
for section in sections:
print("%s\n==================="%(section["name"]))
printTable(section["contracts"], addresses["1"])
printTable(section["contracts"], addresses["1"], "1")
print("\n\n")
print("Exchange Proxy Addresses \n=========================")
print("Note: Some addresses have changed across various networks\n")
print(".. csv-table::\n")
for network in networks:
# etherscanLink = "%s/%s"%("https://etherscan.io/address/", address)
# print(" %s, `%s <%s>`_"%(contract, address, etherscanLink))
print(" %s, %s"%(networks[network], getLinkableAddress(addresses[network]["exchangeProxy"], network)))

View File

@@ -1,4 +1,342 @@
[
{
"version": "16.49.5",
"changes": [
{
"note": "Fix scaling 1 base unit to 0, round output to base units",
"pr": 422
}
],
"timestamp": 1644844353
},
{
"version": "16.49.4",
"changes": [
{
"note": "Reverts 'Improve Uniswap V3 gas schedule' due to issue with buys",
"pr": 419
}
],
"timestamp": 1644507275
},
{
"version": "16.49.3",
"changes": [
{
"note": "Fix `slippage` inconsistency when recalculated in exchange proxy quote consumer",
"pr": 412
},
{
"note": "Fix incorrect output scaling when input is less than desired amount, update fast-abi",
"pr": 401
},
{
"note": "Improve Uniswap V3 gas schedule",
"pr": 397
},
{
"note": "Fix add Native as VIP and use Path to compare all sources vs vip only",
"pr": 413
}
],
"timestamp": 1644495123
},
{
"version": "16.49.2",
"changes": [
{
"note": "Fix ABI encoding error with two hop buys due to applying slippage to uint(-1) values",
"pr": 410
}
],
"timestamp": 1643653482
},
{
"version": "16.49.1",
"changes": [
{
"note": "Fix WorstCaseQuoteInfo encoding bug",
"pr": 402
}
],
"timestamp": 1643613597
},
{
"version": "16.49.0",
"changes": [
{
"note": "Add more curve pools",
"pr": 409
}
],
"timestamp": 1643407900
},
{
"version": "16.48.0",
"changes": [
{
"note": "Use `MIM` as an intermediate asset on `Fantom`",
"pr": 405
}
],
"timestamp": 1643148019
},
{
"version": "16.47.0",
"changes": [
{
"note": "Adding support for Synapse on all networks",
"pr": 400
}
],
"timestamp": 1643136662
},
{
"version": "16.46.0",
"changes": [
{
"note": "Enable `Curve` ETH/CVX pool",
"pr": 394
}
],
"timestamp": 1641863395
},
{
"version": "16.45.2",
"changes": [
{
"note": "Handle 0 output samples and negative adjusted rate native orders in routing",
"pr": 387
}
],
"timestamp": 1641827361
},
{
"version": "16.45.1",
"changes": [
{
"note": "Update `Celo` intermediate tokens",
"pr": 390
}
],
"timestamp": 1641359319
},
{
"version": "16.45.0",
"changes": [
{
"note": "Capture router timings",
"pr": 388
}
],
"timestamp": 1641308410
},
{
"version": "16.44.0",
"changes": [
{
"note": "Update neon-router and use router estimated output amount",
"pr": 354
}
],
"timestamp": 1640778328
},
{
"version": "16.43.0",
"changes": [
{
"note": "`UniswapV3` support for `Optimism`",
"pr": 385
}
],
"timestamp": 1640364306
},
{
"version": "16.42.0",
"changes": [
{
"note": "`UniswapV3` support for `Polygon`",
"pr": 382
},
{
"note": "Update `Beethoven` Graphql url",
"pr": 383
}
],
"timestamp": 1640124159
},
{
"version": "16.41.0",
"changes": [
{
"note": "Update mcusd contract address, and made celo native asset",
"pr": 376
}
],
"timestamp": 1638827302
},
{
"version": "16.40.0",
"changes": [
{
"note": "Add `AaveV2` and `Compound` deposit/withdrawal liquidity source",
"pr": 321
}
],
"timestamp": 1638390144
},
{
"version": "16.39.0",
"changes": [
{
"note": "Curve ETH/CRV pool",
"pr": 378
}
]
},
{
"version": "16.38.0",
"changes": [
{
"note": "Capture sampler metrics",
"pr": 374
}
],
"timestamp": 1638228231
},
{
"version": "16.37.0",
"changes": [
{
"note": "Changed Sushiswap router address",
"pr": 373
}
],
"timestamp": 1637349338
},
{
"version": "16.36.0",
"changes": [
{
"note": "Specify liquid routes for FEI/TRIBE FXS/FRAX and OHM/FRAX",
"pr": 371
}
],
"timestamp": 1637290768
},
{
"version": "16.35.0",
"changes": [
{
"note": "Add Beethoven X, MorpheusSwap and JetSwap to Fantom",
"pr": 370
}
],
"timestamp": 1637206290
},
{
"version": "16.34.0",
"changes": [
{
"note": "Add support Celo",
"pr": 367
}
],
"timestamp": 1637102971
},
{
"version": "16.33.0",
"changes": [
{
"note": "Add support for Uniswap V3 1 bps pools",
"pr": 366
}
],
"timestamp": 1637065617
},
{
"version": "16.32.0",
"changes": [
{
"note": "Extended Quote Report",
"pr": 361
}
],
"timestamp": 1636480845
},
{
"timestamp": 1635903615,
"version": "16.31.0",
"changes": [
{
"note": "Added `Curve`, `Curve_V2` and `KyberDmm` to Avalanche",
"pr": 363
}
]
},
{
"timestamp": 1635903615,
"version": "16.30.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "16.30.0",
"changes": [
{
"note": "Fantom deployment",
"pr": 347
}
],
"timestamp": 1634668033
},
{
"version": "16.29.3",
"changes": [
{
"note": "Update neon-router version and address breaking changes",
"pr": 344
}
],
"timestamp": 1634553393
},
{
"version": "16.29.2",
"changes": [
{
"note": "Check MAX_IN_RATIO in sampleBuysFromBalancer",
"pr": 338
},
{
"note": "Go back to using transformERC20 (instead of transformERC20Staging)",
"pr": 343
}
],
"timestamp": 1634147078
},
{
"version": "16.29.1",
"changes": [
{
"note": "Remove `Clipper` as a custom liquidity source",
"pr": 335
}
],
"timestamp": 1633374058
},
{
"version": "16.29.0",
"changes": [
{
"note": "Initial integration of neon-router (behind feature flag)",
"pr": 295
}
],
"timestamp": 1633350101
},
{
"version": "16.28.0",
"changes": [

View File

@@ -5,6 +5,139 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v16.49.5 - _February 14, 2022_
* Fix scaling 1 base unit to 0, round output to base units (#422)
## v16.49.4 - _February 10, 2022_
* Reverts 'Improve Uniswap V3 gas schedule' due to issue with buys (#419)
## v16.49.3 - _February 10, 2022_
* Fix `slippage` inconsistency when recalculated in exchange proxy quote consumer (#412)
* Fix incorrect output scaling when input is less than desired amount, update fast-abi (#401)
* Improve Uniswap V3 gas schedule (#397)
* Fix add Native as VIP and use Path to compare all sources vs vip only (#413)
## v16.49.2 - _January 31, 2022_
* Fix ABI encoding error with two hop buys due to applying slippage to uint(-1) values (#410)
## v16.49.1 - _January 31, 2022_
* Fix WorstCaseQuoteInfo encoding bug (#402)
## v16.49.0 - _January 28, 2022_
* Add more curve pools (#409)
## v16.48.0 - _January 25, 2022_
* Use `MIM` as an intermediate asset on `Fantom` (#405)
## v16.47.0 - _January 25, 2022_
* Adding support for Synapse on all networks (#400)
## v16.46.0 - _January 11, 2022_
* Enable `Curve` ETH/CVX pool (#394)
## v16.45.2 - _January 10, 2022_
* Handle 0 output samples and negative adjusted rate native orders in routing (#387)
## v16.45.1 - _January 5, 2022_
* Update `Celo` intermediate tokens (#390)
## v16.45.0 - _January 4, 2022_
* Capture router timings (#388)
## v16.44.0 - _December 29, 2021_
* Update neon-router and use router estimated output amount (#354)
## v16.43.0 - _December 24, 2021_
* `UniswapV3` support for `Optimism` (#385)
## v16.42.0 - _December 21, 2021_
* `UniswapV3` support for `Polygon` (#382)
* Update `Beethoven` Graphql url (#383)
## v16.41.0 - _December 6, 2021_
* Update mcusd contract address, and made celo native asset (#376)
## v16.40.0 - _December 1, 2021_
* Add `AaveV2` and `Compound` deposit/withdrawal liquidity source (#321)
## v16.39.0 - _Invalid date_
* Curve ETH/CRV pool (#378)
## v16.38.0 - _November 29, 2021_
* Capture sampler metrics (#374)
## v16.37.0 - _November 19, 2021_
* Changed Sushiswap router address (#373)
## v16.36.0 - _November 19, 2021_
* Specify liquid routes for FEI/TRIBE FXS/FRAX and OHM/FRAX (#371)
## v16.35.0 - _November 18, 2021_
* Add Beethoven X, MorpheusSwap and JetSwap to Fantom (#370)
## v16.34.0 - _November 16, 2021_
* Add support Celo (#367)
## v16.33.0 - _November 16, 2021_
* Add support for Uniswap V3 1 bps pools (#366)
## v16.32.0 - _November 9, 2021_
* Extended Quote Report (#361)
## v16.31.0 - _November 3, 2021_
* Added `Curve`, `Curve_V2` and `KyberDmm` to Avalanche (#363)
## v16.30.1 - _November 3, 2021_
* Dependencies updated
## v16.30.0 - _October 19, 2021_
* Fantom deployment (#347)
## v16.29.3 - _October 18, 2021_
* Update neon-router version and address breaking changes (#344)
## v16.29.2 - _October 13, 2021_
* Check MAX_IN_RATIO in sampleBuysFromBalancer (#338)
* Go back to using transformERC20 (instead of transformERC20Staging) (#343)
## v16.29.1 - _October 4, 2021_
* Remove `Clipper` as a custom liquidity source (#335)
## v16.29.0 - _October 4, 2021_
* Initial integration of neon-router (behind feature flag) (#295)
## v16.28.0 - _September 29, 2021_
* Update ExchangeProxySwapQuoteConsumer for Multiplex V2 and friends (#282)

View File

@@ -154,6 +154,12 @@ contract BalancerSampler {
)
returns (uint256 amount)
{
// Handles this revert scenario:
// https://github.com/balancer-labs/balancer-core/blob/master/contracts/BPool.sol#L443
if (amount > _bmul(poolState.takerTokenBalance, MAX_IN_RATIO)) {
break;
}
takerTokenAmounts[i] = amount;
// Break early if there are 0 amounts
if (takerTokenAmounts[i] == 0) {

View File

@@ -0,0 +1,96 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6;
pragma experimental ABIEncoderV2;
import "./SamplerUtils.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
// Minimal CToken interface
interface ICToken {
function mint(uint mintAmount) external returns (uint);
function redeem(uint redeemTokens) external returns (uint);
function redeemUnderlying(uint redeemAmount) external returns (uint);
function exchangeRateStored() external view returns (uint);
function decimals() external view returns (uint8);
}
contract CompoundSampler is SamplerUtils {
uint256 constant private EXCHANGE_RATE_SCALE = 1e10;
function sampleSellsFromCompound(
ICToken cToken,
IERC20TokenV06 takerToken,
IERC20TokenV06 makerToken,
uint256[] memory takerTokenAmounts
)
public
view
returns (uint256[] memory makerTokenAmounts)
{
uint256 numSamples = takerTokenAmounts.length;
makerTokenAmounts = new uint256[](numSamples);
// Exchange rate is scaled by 1 * 10^(18 - 8 + Underlying Token Decimals
uint256 exchangeRate = cToken.exchangeRateStored();
uint256 cTokenDecimals = uint256(cToken.decimals());
if (address(makerToken) == address(cToken)) {
// mint
for (uint256 i = 0; i < numSamples; i++) {
makerTokenAmounts[i] = (takerTokenAmounts[i] * EXCHANGE_RATE_SCALE * 10 ** cTokenDecimals) / exchangeRate;
}
} else if (address(takerToken) == address(cToken)) {
// redeem
for (uint256 i = 0; i < numSamples; i++) {
makerTokenAmounts[i] = (takerTokenAmounts[i] * exchangeRate) / (EXCHANGE_RATE_SCALE * 10 ** cTokenDecimals);
}
}
}
function sampleBuysFromCompound(
ICToken cToken,
IERC20TokenV06 takerToken,
IERC20TokenV06 makerToken,
uint256[] memory makerTokenAmounts
)
public
view
returns (uint256[] memory takerTokenAmounts)
{
uint256 numSamples = makerTokenAmounts.length;
takerTokenAmounts = new uint256[](numSamples);
// Exchange rate is scaled by 1 * 10^(18 - 8 + Underlying Token Decimals
uint256 exchangeRate = cToken.exchangeRateStored();
uint256 cTokenDecimals = uint256(cToken.decimals());
if (address(makerToken) == address(cToken)) {
// mint
for (uint256 i = 0; i < numSamples; i++) {
takerTokenAmounts[i] = makerTokenAmounts[i] * exchangeRate / (EXCHANGE_RATE_SCALE * 10 ** cTokenDecimals);
}
} else if (address(takerToken) == address(cToken)) {
// redeem
for (uint256 i = 0; i < numSamples; i++) {
takerTokenAmounts[i] = (makerTokenAmounts[i] * EXCHANGE_RATE_SCALE * 10 ** cTokenDecimals)/exchangeRate;
}
}
}
}

View File

@@ -23,6 +23,7 @@ pragma experimental ABIEncoderV2;
import "./BalancerSampler.sol";
import "./BalancerV2Sampler.sol";
import "./BancorSampler.sol";
import "./CompoundSampler.sol";
import "./CurveSampler.sol";
import "./DODOSampler.sol";
import "./DODOV2Sampler.sol";
@@ -48,6 +49,7 @@ contract ERC20BridgeSampler is
BalancerSampler,
BalancerV2Sampler,
BancorSampler,
CompoundSampler,
CurveSampler,
DODOSampler,
DODOV2Sampler,

View File

@@ -159,8 +159,11 @@ contract KyberDmmSampler
(path[i], path[i + 1])
returns (address[] memory allPools)
{
if (allPools.length == 0) {
return new address[](0);
}
uint256 maxSupply = 0;
require(allPools.length >= 1, "KyberDMMSampler/NO_POOLS_FOUND");
for (uint256 j = 0; j < allPools.length; j++) {
uint256 totalSupply = IKyberDmmPool(allPools[j]).totalSupply();
if (totalSupply > maxSupply) {

View File

@@ -51,7 +51,7 @@ interface IUniswapV3Pool {
contract UniswapV3Sampler
{
/// @dev Gas limit for UniswapV3 calls. This is 100% a guess.
uint256 constant private QUOTE_GAS = 300e3;
uint256 constant private QUOTE_GAS = 600e3;
/// @dev Sample sell quotes from UniswapV3.
/// @param quoter UniswapV3 Quoter contract.
@@ -174,8 +174,9 @@ contract UniswapV3Sampler
tokenPath.length - startIndex >= 2,
"UniswapV3Sampler/tokenPath too short"
);
uint24[3] memory validPoolFees = [
uint24[4] memory validPoolFees = [
// The launch pool fees. Could get hairier if they add more.
uint24(0.0001e6),
uint24(0.0005e6),
uint24(0.003e6),
uint24(0.01e6)

View File

@@ -77,4 +77,19 @@ contract UtilitySampler {
assembly { size := extcodesize(account) }
return size > 0;
}
function getGasLeft()
public
returns (uint256)
{
return gasleft();
}
function getBlockNumber()
public
view
returns (uint256)
{
return block.number;
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/asset-swapper",
"version": "16.28.0",
"version": "16.49.5",
"engines": {
"node": ">=6.12"
},
@@ -39,7 +39,7 @@
"config": {
"publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker,FakeTaker",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2Sampler|BancorSampler|CurveSampler|DODOSampler|DODOV2Sampler|DummyLiquidityProvider|ERC20BridgeSampler|FakeTaker|IBalancer|IBancor|ICurve|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|KyberSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|MultiBridgeSampler|NativeOrderSampler|SamplerUtils|ShellSampler|SmoothySampler|TestERC20BridgeSampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json",
"abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2Sampler|BancorSampler|CompoundSampler|CurveSampler|DODOSampler|DODOV2Sampler|DummyLiquidityProvider|ERC20BridgeSampler|FakeTaker|IBalancer|IBancor|ICurve|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|KyberSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|MultiBridgeSampler|NativeOrderSampler|SamplerUtils|ShellSampler|SmoothySampler|TestERC20BridgeSampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json",
"postpublish": {
"assets": []
}
@@ -60,13 +60,14 @@
"dependencies": {
"@0x/assert": "^3.0.29",
"@0x/base-contract": "^6.4.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contract-wrappers": "^13.18.0",
"@0x/contracts-erc20": "^3.3.20",
"@0x/contracts-zero-ex": "^0.29.0",
"@0x/contract-addresses": "^6.11.0",
"@0x/contract-wrappers": "^13.18.5",
"@0x/contracts-erc20": "^3.3.25",
"@0x/contracts-zero-ex": "^0.30.1",
"@0x/dev-utils": "^4.2.9",
"@0x/json-schemas": "^6.3.0",
"@0x/protocol-utils": "^1.9.1",
"@0x/neon-router": "^0.3.1",
"@0x/protocol-utils": "^1.10.1",
"@0x/quote-server": "^6.0.6",
"@0x/types": "^3.3.4",
"@0x/typescript-typings": "^5.2.1",
@@ -85,7 +86,7 @@
"decimal.js": "^10.2.0",
"ethereum-types": "^3.6.0",
"ethereumjs-util": "^7.0.10",
"fast-abi": "^0.0.2",
"fast-abi": "^0.0.4",
"graphql": "^15.4.0",
"graphql-request": "^3.4.0",
"heartbeats": "^5.0.1",
@@ -97,10 +98,10 @@
"@0x/contracts-exchange": "^3.2.38",
"@0x/contracts-exchange-libs": "^4.3.37",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-utils": "^4.8.1",
"@0x/contracts-test-utils": "^5.4.16",
"@0x/contracts-utils": "^4.8.6",
"@0x/mesh-rpc-client": "^9.4.2",
"@0x/migrations": "^8.1.7",
"@0x/migrations": "^8.1.14",
"@0x/sol-compiler": "^4.7.5",
"@0x/subproviders": "^6.6.0",
"@0x/ts-doc-gen": "^0.0.28",

View File

@@ -28,7 +28,6 @@ const ONE_SECOND_MS = 1000;
const ONE_MINUTE_SECS = 60;
const ONE_MINUTE_MS = ONE_SECOND_MS * ONE_MINUTE_SECS;
const DEFAULT_PER_PAGE = 1000;
const ZERO_AMOUNT = new BigNumber(0);
const ALT_MM_IMPUTED_INDICATIVE_EXPIRY_SECONDS = 180;
const DEFAULT_ORDER_PRUNER_OPTS: OrderPrunerOpts = {
@@ -43,6 +42,7 @@ const PROTOCOL_FEE_MULTIPLIER = new BigNumber(0);
// default 50% buffer for selecting native orders to be aggregated with other sources
const MARKET_UTILS_AMOUNT_BUFFER_PERCENTAGE = 0.5;
export const ZERO_AMOUNT = new BigNumber(0);
const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
chainId: ChainId.Mainnet,
orderRefreshIntervalMs: 10000, // 10 seconds

View File

@@ -113,6 +113,7 @@ export {
SwapQuoterError,
SwapQuoterOpts,
SwapQuoterRfqOpts,
SamplerMetrics,
} from './types';
export { affiliateFeeUtils } from './utils/affiliate_fee_utils';
export {
@@ -162,14 +163,20 @@ export {
export { ProtocolFeeUtils } from './utils/protocol_fee_utils';
export {
BridgeQuoteReportEntry,
jsonifyFillData,
MultiHopQuoteReportEntry,
NativeLimitOrderQuoteReportEntry,
NativeRfqOrderQuoteReportEntry,
QuoteReport,
QuoteReportEntry,
ExtendedQuoteReport,
ExtendedQuoteReportSources,
ExtendedQuoteReportEntry,
ExtendedQuoteReportIndexedEntry,
ExtendedQuoteReportIndexedEntryOutbound,
PriceComparisonsReport,
} from './utils/quote_report_generator';
export { QuoteRequestor } from './utils/quote_requestor';
export { QuoteRequestor, V4RFQIndicativeQuoteMM } from './utils/quote_requestor';
export { ERC20BridgeSamplerContract, BalanceCheckerContract, FakeTakerContract } from './wrappers';
import { ERC20BridgeSource } from './utils/market_operation_utils/types';
export type Native = ERC20BridgeSource.Native;

View File

@@ -0,0 +1,57 @@
import { BigNumber } from '@0x/utils';
import { ZERO_AMOUNT } from '../constants';
export interface AaveInfo {
lendingPool: string;
aToken: string;
underlyingToken: string;
}
// tslint:disable-next-line:no-unnecessary-class
export class AaveV2Sampler {
public static sampleSellsFromAaveV2(
aaveInfo: AaveInfo,
takerToken: string,
makerToken: string,
takerTokenAmounts: BigNumber[],
): BigNumber[] {
// Deposit/Withdrawal underlying <-> aToken is always 1:1
if (
(takerToken.toLowerCase() === aaveInfo.aToken.toLowerCase() &&
makerToken.toLowerCase() === aaveInfo.underlyingToken.toLowerCase()) ||
(takerToken.toLowerCase() === aaveInfo.underlyingToken.toLowerCase() &&
makerToken.toLowerCase() === aaveInfo.aToken.toLowerCase())
) {
return takerTokenAmounts;
}
// Not matching the reserve return 0 results
const numSamples = takerTokenAmounts.length;
const makerTokenAmounts = new Array(numSamples);
makerTokenAmounts.fill(ZERO_AMOUNT);
return makerTokenAmounts;
}
public static sampleBuysFromAaveV2(
aaveInfo: AaveInfo,
takerToken: string,
makerToken: string,
makerTokenAmounts: BigNumber[],
): BigNumber[] {
// Deposit/Withdrawal underlying <-> aToken is always 1:1
if (
(takerToken.toLowerCase() === aaveInfo.aToken.toLowerCase() &&
makerToken.toLowerCase() === aaveInfo.underlyingToken.toLowerCase()) ||
(takerToken.toLowerCase() === aaveInfo.underlyingToken.toLowerCase() &&
makerToken.toLowerCase() === aaveInfo.aToken.toLowerCase())
) {
return makerTokenAmounts;
}
// Not matching the reserve return 0 results
const numSamples = makerTokenAmounts.length;
const takerTokenAmounts = new Array(numSamples);
takerTokenAmounts.fill(ZERO_AMOUNT);
return takerTokenAmounts;
}
}

View File

@@ -1,6 +1,5 @@
import { ChainId, ContractAddresses } from '@0x/contract-addresses';
import { IZeroExContract } from '@0x/contract-wrappers';
import { TransformERC20FeatureContract } from '@0x/contracts-zero-ex';
import {
encodeAffiliateFeeTransformerData,
encodeCurveLiquidityProviderData,
@@ -95,7 +94,6 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
};
private readonly _exchangeProxy: IZeroExContract;
private readonly _transformERC20Feature: TransformERC20FeatureContract;
constructor(public readonly contractAddresses: ContractAddresses, options: Partial<SwapQuoteConsumerOpts> = {}) {
const { chainId } = _.merge({}, constants.DEFAULT_SWAP_QUOTER_OPTS, options);
@@ -103,7 +101,6 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
this.chainId = chainId;
this.contractAddresses = contractAddresses;
this._exchangeProxy = new IZeroExContract(contractAddresses.exchangeProxy, FAKE_PROVIDER);
this._transformERC20Feature = new TransformERC20FeatureContract(contractAddresses.exchangeProxy, FAKE_PROVIDER);
this.transformerNonces = {
wethTransformer: findTransformerNonce(
contractAddresses.transformers.wethTransformer,
@@ -363,8 +360,9 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
// Build up the transforms.
const transforms = [];
if (isFromETH) {
// Create a WETH wrapper if coming from ETH.
// Create a WETH wrapper if coming from ETH.
// Dont add the wethTransformer to CELO. There is no wrap/unwrap logic for CELO.
if (isFromETH && this.chainId !== ChainId.Celo) {
transforms.push({
deploymentNonce: this.transformerNonces.wethTransformer,
data: encodeWethTransformerData({
@@ -416,9 +414,9 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
}),
});
}
if (isToETH) {
// Create a WETH unwrapper if going to ETH.
// Create a WETH unwrapper if going to ETH.
// Dont add the wethTransformer on CELO. There is no wrap/unwrap logic for CELO.
if (isToETH && this.chainId !== ChainId.Celo) {
transforms.push({
deploymentNonce: this.transformerNonces.wethTransformer,
data: encodeWethTransformerData({
@@ -495,10 +493,11 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
amounts: [],
}),
});
const calldataHexString = this._transformERC20Feature
.transformERC20Staging(
const TO_ETH_ADDRESS = this.chainId === ChainId.Celo ? this.contractAddresses.etherToken : ETH_TOKEN_ADDRESS;
const calldataHexString = this._exchangeProxy
.transformERC20(
isFromETH ? ETH_TOKEN_ADDRESS : sellToken,
isToETH ? ETH_TOKEN_ADDRESS : buyToken,
isToETH ? TO_ETH_ADDRESS : buyToken,
shouldSellEntireBalance ? MAX_UINT256 : sellAmount,
minBuyAmount,
transforms,
@@ -692,7 +691,7 @@ export class ExchangeProxySwapQuoteConsumer implements SwapQuoteConsumerBase {
function slipNonNativeOrders(quote: MarketSellSwapQuote | MarketBuySwapQuote): OptimizedMarketOrder[] {
const slippage = getMaxQuoteSlippageRate(quote);
if (!slippage) {
if (slippage === 0) {
return quote.orders;
}
return quote.orders.map(o => {
@@ -702,25 +701,20 @@ function slipNonNativeOrders(quote: MarketSellSwapQuote | MarketBuySwapQuote): O
return {
...o,
...(quote.type === MarketOperation.Sell
? { makerAmount: o.makerAmount.times(1 - slippage).integerValue(BigNumber.ROUND_DOWN) }
: { takerAmount: o.takerAmount.times(1 + slippage).integerValue(BigNumber.ROUND_UP) }),
? {
makerAmount: o.makerAmount.eq(MAX_UINT256)
? MAX_UINT256
: o.makerAmount.times(1 - slippage).integerValue(BigNumber.ROUND_DOWN),
}
: {
takerAmount: o.takerAmount.eq(MAX_UINT256)
? MAX_UINT256
: o.takerAmount.times(1 + slippage).integerValue(BigNumber.ROUND_UP),
}),
};
});
}
function getMaxQuoteSlippageRate(quote: MarketBuySwapQuote | MarketSellSwapQuote): number {
if (quote.type === MarketOperation.Buy) {
// (worstCaseTaker - bestCaseTaker) / bestCaseTaker
// where worstCaseTaker >= bestCaseTaker
return quote.worstCaseQuoteInfo.takerAmount
.minus(quote.bestCaseQuoteInfo.takerAmount)
.div(quote.bestCaseQuoteInfo.takerAmount)
.toNumber();
}
// (bestCaseMaker - worstCaseMaker) / bestCaseMaker
// where bestCaseMaker >= worstCaseMaker
return quote.bestCaseQuoteInfo.makerAmount
.minus(quote.worstCaseQuoteInfo.makerAmount)
.div(quote.bestCaseQuoteInfo.makerAmount)
.toNumber();
return quote.worstCaseQuoteInfo.slippage;
}

View File

@@ -363,6 +363,7 @@ export class SwapQuoter {
const cloneOpts = _.omit(opts, 'gasPrice') as GetMarketOrdersOpts;
const calcOpts: GetMarketOrdersOpts = {
...cloneOpts,
gasPrice,
feeSchedule: _.mapValues(opts.feeSchedule, gasCost => (fillData: FillData) =>
gasCost === undefined ? 0 : gasPrice.times(gasCost(fillData)),
),
@@ -504,6 +505,7 @@ function createSwapQuote(
const {
optimizedOrders,
quoteReport,
extendedQuoteReportSources,
sourceFlags,
takerAmountPerEth,
makerAmountPerEth,
@@ -531,6 +533,7 @@ function createSwapQuote(
takerAmountPerEth,
makerAmountPerEth,
quoteReport,
extendedQuoteReportSources,
isTwoHop,
priceComparisonsReport,
};
@@ -575,8 +578,8 @@ function calculateQuoteInfo(
});
return {
bestCaseQuoteInfo: fillResultsToQuoteInfo(bestCaseFillResult),
worstCaseQuoteInfo: fillResultsToQuoteInfo(worstCaseFillResult),
bestCaseQuoteInfo: fillResultsToQuoteInfo(bestCaseFillResult, 0),
worstCaseQuoteInfo: fillResultsToQuoteInfo(worstCaseFillResult, slippage),
sourceBreakdown: getSwapQuoteOrdersBreakdown(bestCaseFillResult.fillAmountBySource),
};
}
@@ -596,29 +599,33 @@ function calculateTwoHopQuoteInfo(
secondHopSource: _.pick(secondHopFill, 'source', 'fillData'),
}),
).toNumber();
const isSell = operation === MarketOperation.Sell;
return {
bestCaseQuoteInfo: {
makerAmount: operation === MarketOperation.Sell ? secondHopFill.output : secondHopFill.input,
takerAmount: operation === MarketOperation.Sell ? firstHopFill.input : firstHopFill.output,
totalTakerAmount: operation === MarketOperation.Sell ? firstHopFill.input : firstHopFill.output,
makerAmount: isSell ? secondHopFill.output : secondHopFill.input,
takerAmount: isSell ? firstHopFill.input : firstHopFill.output,
totalTakerAmount: isSell ? firstHopFill.input : firstHopFill.output,
feeTakerTokenAmount: constants.ZERO_AMOUNT,
protocolFeeInWeiAmount: constants.ZERO_AMOUNT,
gas,
slippage: 0,
},
// TODO jacob consolidate this with quote simulation worstCase
worstCaseQuoteInfo: {
makerAmount: MarketOperation.Sell
makerAmount: isSell
? secondHopOrder.makerAmount.times(1 - slippage).integerValue()
: secondHopOrder.makerAmount,
takerAmount: MarketOperation.Sell
takerAmount: isSell
? firstHopOrder.takerAmount
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(),
totalTakerAmount: MarketOperation.Sell
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(BigNumber.ROUND_UP),
totalTakerAmount: isSell
? firstHopOrder.takerAmount
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(),
: firstHopOrder.takerAmount.times(1 + slippage).integerValue(BigNumber.ROUND_UP),
feeTakerTokenAmount: constants.ZERO_AMOUNT,
protocolFeeInWeiAmount: constants.ZERO_AMOUNT,
gas,
slippage,
},
sourceBreakdown: {
[ERC20BridgeSource.MultiHop]: {
@@ -644,7 +651,7 @@ function getSwapQuoteOrdersBreakdown(fillAmountBySource: { [source: string]: Big
return breakdown;
}
function fillResultsToQuoteInfo(fr: QuoteFillResult): SwapQuoteInfo {
function fillResultsToQuoteInfo(fr: QuoteFillResult, slippage: number): SwapQuoteInfo {
return {
makerAmount: fr.totalMakerAssetAmount,
takerAmount: fr.takerAssetAmount,
@@ -652,6 +659,7 @@ function fillResultsToQuoteInfo(fr: QuoteFillResult): SwapQuoteInfo {
feeTakerTokenAmount: fr.takerFeeTakerAssetAmount,
protocolFeeInWeiAmount: fr.protocolFeeAmount,
gas: fr.gas,
slippage,
};
}

View File

@@ -19,7 +19,8 @@ import {
OptimizedMarketOrder,
TokenAdjacencyGraph,
} from './utils/market_operation_utils/types';
import { PriceComparisonsReport, QuoteReport } from './utils/quote_report_generator';
export { SamplerMetrics } from './utils/market_operation_utils/types';
import { ExtendedQuoteReportSources, PriceComparisonsReport, QuoteReport } from './utils/quote_report_generator';
import { MetricsProxy } from './utils/quote_requestor';
/**
@@ -171,6 +172,7 @@ export interface SwapQuoteBase {
worstCaseQuoteInfo: SwapQuoteInfo;
sourceBreakdown: SwapQuoteOrdersBreakdown;
quoteReport?: QuoteReport;
extendedQuoteReportSources?: ExtendedQuoteReportSources;
priceComparisonsReport?: PriceComparisonsReport;
isTwoHop: boolean;
makerTokenDecimals: number;
@@ -206,6 +208,7 @@ export type SwapQuote = MarketBuySwapQuote | MarketSellSwapQuote;
* makerTokenAmount: The amount of makerAsset that will be acquired through the swap.
* protocolFeeInWeiAmount: The amount of ETH to pay (in WEI) as protocol fee to perform the swap for desired asset.
* gas: Amount of estimated gas needed to fill the quote.
* slippage: Amount of slippage to allow for.
*/
export interface SwapQuoteInfo {
feeTakerTokenAmount: BigNumber;
@@ -214,6 +217,7 @@ export interface SwapQuoteInfo {
makerAmount: BigNumber;
protocolFeeInWeiAmount: BigNumber;
gas: number;
slippage: number;
}
/**
@@ -256,7 +260,7 @@ export interface RfqRequestOpts {
/**
* gasPrice: gas price to determine protocolFee amount, default to ethGasStation fast amount
*/
export interface SwapQuoteRequestOpts extends GetMarketOrdersOpts {
export interface SwapQuoteRequestOpts extends Omit<GetMarketOrdersOpts, 'gasPrice'> {
gasPrice?: BigNumber;
rfqt?: RfqRequestOpts;
}

View File

@@ -223,7 +223,17 @@ export async function returnQuoteFromAltMMAsync<ResponseT>(
cancelToken,
})
.catch(err => {
warningLogger(err, `Alt RFQ MM request failed`);
if (err.response) {
// request was made and market maker responded
warningLogger(
{ data: err.response.data, status: err.response.status, headers: err.response.headers },
`Alt RFQ MM request failed`,
);
} else if (err.request) {
warningLogger({}, 'Alt RFQ MM no response received');
} else {
warningLogger({ err: err.message }, 'Failed to construct Alt RFQ MM request');
}
throw new Error(`Alt RFQ MM request failed`);
});

View File

@@ -0,0 +1,106 @@
import { logUtils } from '@0x/utils';
import { gql, request } from 'graphql-request';
import { constants } from '../../constants';
const RESERVES_GQL_QUERY = gql`
{
reserves(
first: 300
where: { isActive: true, isFrozen: false }
orderBy: totalLiquidity
orderDirection: desc
) {
id
underlyingAsset
aToken {
id
}
pool {
id
lendingPool
}
}
}
`;
export interface AaveReserve {
id: string;
underlyingAsset: string;
aToken: {
id: string;
};
pool: {
id: string;
lendingPool: string;
};
}
interface Cache {
[key: string]: AaveReserve[];
}
// tslint:disable-next-line:custom-no-magic-numbers
const RESERVES_REFRESH_INTERVAL_MS = 30 * constants.ONE_MINUTE_MS;
/**
* Fetches Aave V2 reserve information from the official subgraph(s).
* The reserve information is updated every 30 minutes and cached
* so that it can be accessed with the underlying token's address
*/
export class AaveV2ReservesCache {
private _cache: Cache = {};
constructor(private readonly _subgraphUrl: string) {
const resfreshReserves = async () => this.fetchAndUpdateReservesAsync();
// tslint:disable-next-line:no-floating-promises
resfreshReserves();
setInterval(resfreshReserves, RESERVES_REFRESH_INTERVAL_MS);
}
/**
* Fetches Aave V2 reserves from the subgraph and updates the cache
*/
public async fetchAndUpdateReservesAsync(): Promise<void> {
try {
const { reserves } = await request<{ reserves: AaveReserve[] }>(this._subgraphUrl, RESERVES_GQL_QUERY);
const newCache = reserves.reduce<Cache>((memo, reserve) => {
const underlyingAsset = reserve.underlyingAsset.toLowerCase();
if (!memo[underlyingAsset]) {
memo[underlyingAsset] = [];
}
memo[underlyingAsset].push(reserve);
return memo;
}, {});
this._cache = newCache;
} catch (err) {
logUtils.warn(`Failed to update Aave V2 reserves cache: ${err.message}`);
// Empty cache just to be safe
this._cache = {};
}
}
public get(takerToken: string, makerToken: string): AaveReserve | undefined {
// Deposit takerToken into reserve
if (this._cache[takerToken.toLowerCase()]) {
const matchingReserve = this._cache[takerToken.toLowerCase()].find(
r => r.aToken.id === makerToken.toLowerCase(),
);
if (matchingReserve) {
return matchingReserve;
}
}
// Withdraw makerToken from reserve
if (this._cache[makerToken.toLowerCase()]) {
const matchingReserve = this._cache[makerToken.toLowerCase()].find(
r => r.aToken.id === takerToken.toLowerCase(),
);
if (matchingReserve) {
return matchingReserve;
}
}
// No match
return undefined;
}
}

View File

@@ -11,8 +11,13 @@ import {
COMETHSWAP_ROUTER_BY_CHAIN_ID,
COMPONENT_POOLS_BY_CHAIN_ID,
CRYPTO_COM_ROUTER_BY_CHAIN_ID,
CURVE_AVALANCHE_INFOS,
CURVE_FANTOM_INFOS,
CURVE_MAINNET_INFOS,
CURVE_OPTIMISM_INFOS,
CURVE_POLYGON_INFOS,
CURVE_V2_AVALANCHE_INFOS,
CURVE_V2_FANTOM_INFOS,
CURVE_V2_MAINNET_INFOS,
CURVE_V2_POLYGON_INFOS,
DFYN_ROUTER_BY_CHAIN_ID,
@@ -26,6 +31,7 @@ import {
KYBER_BRIDGED_LIQUIDITY_PREFIX,
MAX_DODOV2_POOLS_QUERIED,
MAX_KYBER_RESERVES_QUERIED,
MORPHEUSSWAP_ROUTER_BY_CHAIN_ID,
MSTABLE_POOLS_BY_CHAIN_ID,
NERVE_BSC_INFOS,
NULL_ADDRESS,
@@ -40,9 +46,18 @@ import {
SMOOTHY_BSC_INFOS,
SMOOTHY_MAINNET_INFOS,
SNOWSWAP_MAINNET_INFOS,
SPIRITSWAP_ROUTER_BY_CHAIN_ID,
SPOOKYSWAP_ROUTER_BY_CHAIN_ID,
SUSHISWAP_ROUTER_BY_CHAIN_ID,
SWERVE_MAINNET_INFOS,
SYNAPSE_AVALANCHE_INFOS,
SYNAPSE_BSC_INFOS,
SYNAPSE_FANTOM_INFOS,
SYNAPSE_MAINNET_INFOS,
SYNAPSE_OPTIMISM_INFOS,
SYNAPSE_POLYGON_INFOS,
TRADER_JOE_ROUTER_BY_CHAIN_ID,
UBESWAP_ROUTER_BY_CHAIN_ID,
UNISWAPV2_ROUTER_BY_CHAIN_ID,
WAULTSWAP_ROUTER_BY_CHAIN_ID,
XSIGMA_MAINNET_INFOS,
@@ -133,6 +148,33 @@ export function getCurveInfosForPair(chainId: ChainId, takerToken: string, maker
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Fantom:
return Object.values(CURVE_FANTOM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Avalanche:
return Object.values(CURVE_AVALANCHE_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Optimism:
return Object.values(CURVE_OPTIMISM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
default:
return [];
}
@@ -159,6 +201,24 @@ export function getCurveV2InfosForPair(chainId: ChainId, takerToken: string, mak
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Fantom:
return Object.values(CURVE_V2_FANTOM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Avalanche:
return Object.values(CURVE_V2_AVALANCHE_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
default:
return [];
}
@@ -203,6 +263,67 @@ export function getNerveInfosForPair(chainId: ChainId, takerToken: string, maker
);
}
export function getSynapseInfosForPair(chainId: ChainId, takerToken: string, makerToken: string): CurveInfo[] {
switch (chainId) {
case ChainId.Mainnet:
return Object.values(SYNAPSE_MAINNET_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Optimism:
return Object.values(SYNAPSE_OPTIMISM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.BSC:
return Object.values(SYNAPSE_BSC_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Polygon:
return Object.values(SYNAPSE_POLYGON_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Fantom:
return Object.values(SYNAPSE_FANTOM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Avalanche:
return Object.values(SYNAPSE_AVALANCHE_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
default:
return [];
}
}
export function getFirebirdOneSwapInfosForPair(chainId: ChainId, takerToken: string, makerToken: string): CurveInfo[] {
if (chainId === ChainId.BSC) {
return Object.values(FIREBIRDONESWAP_BSC_INFOS).filter(c =>
@@ -362,6 +483,7 @@ export function getCurveLikeInfosForPair(
| ERC20BridgeSource.Swerve
| ERC20BridgeSource.SnowSwap
| ERC20BridgeSource.Nerve
| ERC20BridgeSource.Synapse
| ERC20BridgeSource.Belt
| ERC20BridgeSource.Ellipsis
| ERC20BridgeSource.Smoothy
@@ -388,6 +510,9 @@ export function getCurveLikeInfosForPair(
case ERC20BridgeSource.Nerve:
pools = getNerveInfosForPair(chainId, takerToken, makerToken);
break;
case ERC20BridgeSource.Synapse:
pools = getSynapseInfosForPair(chainId, takerToken, makerToken);
break;
case ERC20BridgeSource.Belt:
pools = getBeltInfosForPair(chainId, takerToken, makerToken);
break;
@@ -443,7 +568,11 @@ export function uniswapV2LikeRouterAddress(
| ERC20BridgeSource.ShibaSwap
| ERC20BridgeSource.JetSwap
| ERC20BridgeSource.TraderJoe
| ERC20BridgeSource.Pangolin,
| ERC20BridgeSource.Pangolin
| ERC20BridgeSource.UbeSwap
| ERC20BridgeSource.MorpheusSwap
| ERC20BridgeSource.SpookySwap
| ERC20BridgeSource.SpiritSwap,
): string {
switch (source) {
case ERC20BridgeSource.UniswapV2:
@@ -484,6 +613,14 @@ export function uniswapV2LikeRouterAddress(
return PANGOLIN_ROUTER_BY_CHAIN_ID[chainId];
case ERC20BridgeSource.TraderJoe:
return TRADER_JOE_ROUTER_BY_CHAIN_ID[chainId];
case ERC20BridgeSource.UbeSwap:
return UBESWAP_ROUTER_BY_CHAIN_ID[chainId];
case ERC20BridgeSource.MorpheusSwap:
return MORPHEUSSWAP_ROUTER_BY_CHAIN_ID[chainId];
case ERC20BridgeSource.SpookySwap:
return SPOOKYSWAP_ROUTER_BY_CHAIN_ID[chainId];
case ERC20BridgeSource.SpiritSwap:
return SPIRITSWAP_ROUTER_BY_CHAIN_ID[chainId];
default:
throw new Error(`Unknown UniswapV2 like source ${source}`);
}

View File

@@ -0,0 +1,78 @@
import { logUtils } from '@0x/utils';
import axios from 'axios';
import { constants } from '../../constants';
export interface CToken {
tokenAddress: string;
underlyingAddress: string;
}
interface CTokenApiResponse {
cToken: Array<{
token_address: string;
underlying_address: string;
}>;
}
interface Cache {
[key: string]: CToken;
}
// tslint:disable-next-line:custom-no-magic-numbers
const CTOKEN_REFRESH_INTERVAL_MS = 30 * constants.ONE_MINUTE_MS;
/**
* Fetches a list of CTokens from Compound's official API.
* The token information is updated every 30 minutes and cached
* so that it can be accessed with the underlying token's address.
*/
export class CompoundCTokenCache {
private _cache: Cache = {};
constructor(private readonly _apiUrl: string, private readonly _wethAddress: string) {
const refreshCTokenCache = async () => this.fetchAndUpdateCTokensAsync();
// tslint:disable-next-line:no-floating-promises
refreshCTokenCache();
setInterval(refreshCTokenCache, CTOKEN_REFRESH_INTERVAL_MS);
}
public async fetchAndUpdateCTokensAsync(): Promise<void> {
try {
const { data } = await axios.get<CTokenApiResponse>(`${this._apiUrl}/ctoken`);
const newCache = data?.cToken.reduce<Cache>((memo, cToken) => {
// NOTE: Re-map cETH with null underlying token address to WETH address (we only handle WETH internally)
const underlyingAddressClean = cToken.underlying_address
? cToken.underlying_address.toLowerCase()
: this._wethAddress;
const tokenData: CToken = {
tokenAddress: cToken.token_address.toLowerCase(),
underlyingAddress: underlyingAddressClean,
};
memo[underlyingAddressClean] = tokenData;
return memo;
}, {});
this._cache = newCache;
} catch (err) {
logUtils.warn(`Failed to update Compound cToken cache: ${err.message}`);
// NOTE: Safe to keep already cached data as tokens should only be added to the list
}
}
public get(takerToken: string, makerToken: string): CToken | undefined {
// mint cToken
let cToken = this._cache[takerToken.toLowerCase()];
if (cToken && makerToken.toLowerCase() === cToken.tokenAddress.toLowerCase()) {
return cToken;
}
// redeem cToken
cToken = this._cache[makerToken.toLowerCase()];
if (cToken && takerToken.toLowerCase() === cToken.tokenAddress.toLowerCase()) {
return cToken;
}
// No match
return undefined;
}
}

View File

@@ -7,7 +7,9 @@ import { TokenAdjacencyGraphBuilder } from '../token_adjacency_graph_builder';
import { SourceFilters } from './source_filters';
import {
AaveV2FillData,
BancorFillData,
CompoundFillData,
CurveFillData,
CurveFunctionSelectors,
CurveInfo,
@@ -57,6 +59,9 @@ function valueByChainId<T>(rest: Partial<{ [key in ChainId]: T }>, defaultValue:
[ChainId.Polygon]: defaultValue,
[ChainId.PolygonMumbai]: defaultValue,
[ChainId.Avalanche]: defaultValue,
[ChainId.Fantom]: defaultValue,
[ChainId.Celo]: defaultValue,
[ChainId.Optimism]: defaultValue,
...(rest || {}),
};
}
@@ -99,7 +104,10 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.ShibaSwap,
ERC20BridgeSource.Clipper,
ERC20BridgeSource.Synapse,
// TODO: enable after FQT has been redeployed on Ethereum mainnet
// ERC20BridgeSource.AaveV2,
// ERC20BridgeSource.Compound,
]),
[ChainId.Ropsten]: new SourceFilters([
ERC20BridgeSource.Kyber,
@@ -123,6 +131,7 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.Mooniswap,
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Nerve,
ERC20BridgeSource.Synapse,
ERC20BridgeSource.PancakeSwap,
ERC20BridgeSource.PancakeSwapV2,
ERC20BridgeSource.SushiSwap,
@@ -136,6 +145,7 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.FirebirdOneSwap,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.ACryptos,
ERC20BridgeSource.KyberDmm,
]),
[ChainId.Polygon]: new SourceFilters([
ERC20BridgeSource.SushiSwap,
@@ -157,12 +167,44 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.IronSwap,
ERC20BridgeSource.AaveV2,
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
]),
[ChainId.Avalanche]: new SourceFilters([
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Pangolin,
ERC20BridgeSource.TraderJoe,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.KyberDmm,
ERC20BridgeSource.AaveV2,
ERC20BridgeSource.Synapse,
]),
[ChainId.Fantom]: new SourceFilters([
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Beethovenx,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.MorpheusSwap,
ERC20BridgeSource.SpiritSwap,
ERC20BridgeSource.SpookySwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.Synapse,
]),
[ChainId.Celo]: new SourceFilters([
ERC20BridgeSource.UbeSwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.MultiHop,
]),
[ChainId.Optimism]: new SourceFilters([
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.MultiHop,
]),
},
new SourceFilters([]),
@@ -206,7 +248,10 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.ShibaSwap,
ERC20BridgeSource.Clipper,
ERC20BridgeSource.Synapse,
// TODO: enable after FQT has been redeployed on Ethereum mainnet
// ERC20BridgeSource.AaveV2,
// ERC20BridgeSource.Compound,
]),
[ChainId.Ropsten]: new SourceFilters([
ERC20BridgeSource.Kyber,
@@ -243,6 +288,8 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.FirebirdOneSwap,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.ACryptos,
ERC20BridgeSource.KyberDmm,
ERC20BridgeSource.Synapse,
]),
[ChainId.Polygon]: new SourceFilters([
ERC20BridgeSource.SushiSwap,
@@ -264,12 +311,44 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.IronSwap,
ERC20BridgeSource.AaveV2,
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
]),
[ChainId.Avalanche]: new SourceFilters([
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Pangolin,
ERC20BridgeSource.TraderJoe,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.KyberDmm,
ERC20BridgeSource.AaveV2,
ERC20BridgeSource.Synapse,
]),
[ChainId.Fantom]: new SourceFilters([
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Beethovenx,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.JetSwap,
ERC20BridgeSource.MorpheusSwap,
ERC20BridgeSource.SpiritSwap,
ERC20BridgeSource.SpookySwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.Synapse,
]),
[ChainId.Celo]: new SourceFilters([
ERC20BridgeSource.UbeSwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.MultiHop,
]),
[ChainId.Optimism]: new SourceFilters([
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.MultiHop,
]),
},
new SourceFilters([]),
@@ -288,8 +367,11 @@ export const FEE_QUOTE_SOURCES_BY_CHAIN_ID = valueByChainId<ERC20BridgeSource[]>
[ChainId.Mainnet]: [ERC20BridgeSource.UniswapV2, ERC20BridgeSource.SushiSwap, ERC20BridgeSource.UniswapV3],
[ChainId.BSC]: [ERC20BridgeSource.PancakeSwap, ERC20BridgeSource.Mooniswap, ERC20BridgeSource.SushiSwap],
[ChainId.Ropsten]: [ERC20BridgeSource.UniswapV2, ERC20BridgeSource.SushiSwap],
[ChainId.Polygon]: [ERC20BridgeSource.QuickSwap, ERC20BridgeSource.SushiSwap],
[ChainId.Polygon]: [ERC20BridgeSource.QuickSwap, ERC20BridgeSource.SushiSwap, ERC20BridgeSource.UniswapV3],
[ChainId.Avalanche]: [ERC20BridgeSource.Pangolin, ERC20BridgeSource.TraderJoe, ERC20BridgeSource.SushiSwap],
[ChainId.Fantom]: [ERC20BridgeSource.SpiritSwap, ERC20BridgeSource.SpookySwap, ERC20BridgeSource.SushiSwap],
[ChainId.Celo]: [ERC20BridgeSource.UbeSwap, ERC20BridgeSource.SushiSwap],
[ChainId.Optimism]: [ERC20BridgeSource.UniswapV3],
},
[],
);
@@ -386,15 +468,31 @@ export const MAINNET_TOKENS = {
// StableSwap "open pools" (crv.finance)
STABLEx: '0xcd91538b91b4ba7797d39a2f66e63810b50a33d0',
alUSD: '0xbc6da0fe9ad5f3b0d58160288917aa56653660e9',
// Frax ecosystem
FRAX: '0x853d955acef822db058eb8505911ed77f175b99e',
FXS: '0x3432b6a60d23ca0dfca7761b7ab56459d9c964d0',
OHM: '0x383518188c0c6d7730d91b2c03a03c837814a899',
//
LUSD: '0x5f98805a4e8be255a32880fdec7f6728c6568ba0',
// Fei Ecosystem
FEI: '0x956f47f50a910163d8bf957cf5846d573e7f87ca',
TRIBE: '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b',
//
DSU: '0x605d26fbd5be761089281d5cec2ce86eea667109',
ESS: '0x24ae124c4cc33d6791f8e8b63520ed7107ac8b3e',
cvxCRV: '0x62b9c7356a2dc64a1969e19c23e4f579f9810aa7',
CRV: '0xd533a949740bb3306d119cc777fa900ba034cd52',
MIM: '0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3',
EURT: '0xc581b735a1688071a1746c968e0798d642ede491',
// Synapse ecosystem
nUSD: '0x1b84765de8b7566e4ceaf4d0fd3c5af52d3dde4f',
CVX: '0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b',
UST_WORMHOLE: '0xa693b19d2931d498c5b318df961919bb4aee87a5',
RAI: '0x03ab458634910aad20ef5f1c8ee96f1d6ac54919',
DOLA: '0x865377367054516e17014ccded1e7d814edc9ce4',
OUSD: '0x2a8e1e676ec238d8a992307b495b45b3feaa5e86',
agEUR: '0x1a7e4e63778b4f12a199c062f3efdd288afcbce8',
ibEUR: '0x96e61422b6a9ba0e068b6c5add4ffabc6a4aae27',
};
export const BSC_TOKENS = {
@@ -411,6 +509,7 @@ export const BSC_TOKENS = {
BTCB: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
renBTC: '0xfce146bf3146100cfe5db4129cf6c82b0ef4ad8c',
pBTC: '0xed28a457a5a76596ac48d87c0f577020f6ea1c4c',
nUSD: '0x23b891e5c62e0955ae2bd185990103928ab817b3',
};
export const POLYGON_TOKENS = {
@@ -428,13 +527,73 @@ export const POLYGON_TOKENS = {
DFYN: '0xc168e40227e4ebd8c1cae80f7a55a4f0e6d66c97',
BANANA: '0x5d47baba0d66083c52009271faf3f50dcc01023c',
WEXPOLY: '0x4c4bf319237d98a30a929a96112effa8da3510eb',
nUSD: '0xb6c473756050de474286bed418b77aeac39b02af',
};
export const AVALANCHE_TOKENS = {
WAVAX: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
WETH: '0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab',
USDT: '0xc7198437980c041c805a1edcba50c1ce5db95118',
WBTC: '0x50b7545627a5162f82a992c33b87adc75187b218',
DAI: '0xd586e7f844cea2f87f50152665bcbc2c279d8d70',
// bridged USDC
USDC: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
// native USDC on Avalanche
nUSDC: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
USDT: '0xc7198437980c041c805a1edcba50c1ce5db95118',
aDAI: '0x47afa96cdc9fab46904a55a6ad4bf6660b53c38a',
aUSDC: '0x46a51127c3ce23fb7ab1de06226147f446e4a857',
aUSDT: '0x532e6537fea298397212f09a61e03311686f548e',
nETH: '0x19e1ae0ee35c0404f835521146206595d37981ae',
nUSD: '0xcfc37a6ab183dd4aed08c204d1c2773c0b1bdf46',
aWETH: '0x53f7c5869a859f0aec3d334ee8b4cf01e3492f21',
MIM: '0x130966628846bfd36ff31a822705796e8cb8c18d',
};
export const CELO_TOKENS = {
WCELO: '0x471ece3750da237f93b8e339c536989b8978a438',
// Some of these tokens are Optics bridge? tokens which
// had an issue and migrated from v1 to v2
WETHv1: '0xe919f65739c26a42616b7b8eedc6b5524d1e3ac4',
WETH: '0x122013fd7df1c6f636a5bb8f03108e876548b455',
WBTC: '0xbaab46e28388d2779e6e31fd00cf0e5ad95e327b',
cUSD: '0x765de816845861e75a25fca122bb6898b8b1282a',
// ??
WBTCv1: '0xd629eb00deced2a080b7ec630ef6ac117e614f1b',
cETH: '0x2def4285787d58a2f811af24755a8150622f4361',
UBE: '0x00be915b9dcf56a3cbe739d9b9c202ca692409ec',
// Moolah
mCELO: '0x7d00cd74ff385c955ea3d79e47bf06bd7386387d',
mCUSD: '0x918146359264c492bd6934071c6bd31c854edbc3',
mCEUR: '0xe273ad7ee11dcfaa87383ad5977ee1504ac07568',
amCUSD: '0x64defa3544c695db8c535d289d843a189aa26b98',
MOO: '0x17700282592d6917f6a73d0bf8accf4d578c131e',
};
export const FANTOM_TOKENS = {
WFTM: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83',
WETH: '0x74b23882a30290451a17c44f4f05243b6b58c76d',
USDC: '0x04068da6c83afcfa0e13ba15a6696662335d5b75',
DAI: '0x8d11ec38a3eb5e956b052f67da8bdc9bef8abf3e',
fUSDT: '0x049d68029688eabf473097a2fc38ef61633a3c7a',
WBTC: '0x321162cd933e2be498cd2267a90534a804051b11',
renBTC: '0xdbf31df14b66535af65aac99c32e9ea844e14501',
MIM: '0x82f0b8b456c1a451378467398982d4834b6829c1',
nUSD: '0xed2a7edd7413021d440b09d654f3b87712abab66',
nETH: '0x67c10c397dd0ba417329543c1a40eb48aaa7cd00',
gfUSDT: '0x940f41f0ec9ba1a34cf001cc03347ac092f5f6b5',
gUSDC: '0xe578c856933d8e1082740bf7661e379aa2a30b26',
gDAI: '0x07e6332dd090d287d3489245038daf987955dcfb',
FRAX: '0xdc301622e621166bd8e82f2ca0a26c13ad0be355',
};
export const OPTIMISM_TOKENS = {
WETH: '0x4200000000000000000000000000000000000006',
USDC: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
USDT: '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58',
DAI: '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
WBTC: '0x68f180fcce6836688e9084f035309e29bf0a2095',
nETH: '0x809dc529f07651bd43a172e8db6f4a7a0d771036',
sWETH: '0x121ab82b49b2bc4c7901ca46b8277962b4350204',
};
export const CURVE_POOLS = {
@@ -481,6 +640,17 @@ export const CURVE_POOLS = {
cvxcrv: '0x9d0464996170c6b9e75eed71c68b99ddedf279e8',
mim: '0x5a6a4d54456819380173272a5e8e9b9904bdf41b',
eurt: '0xfd5db7463a3ab53fd211b4af195c5bccc1a03890',
ethcrv: '0x8301ae4fc9c624d1d396cbdaa1ed877821d7c511',
ethcvx: '0xb576491f1e6e5e62f1d8f26062ee822b40b0e0d4',
mimust: '0x55a8a39bc9694714e2874c1ce77aa1e599461e18',
usttri_wormhole: '0xceaf7747579696a2f0bb206a14210e3c9e6fb269',
fei_tri: '0x06cb22615ba53e60d67bf6c341a0fd5e718e1655',
rai_tri: '0x618788357d0ebd8a37e763adab3bc575d54c2c7d',
DOLA_tri: '0xaa5a67c256e27a5d80712c51971408db3370927d',
OUSD_tri: '0x87650d7bbfc3a9f10587d7778206671719d9910d',
d3pool: '0xbaaa1f5dba42c3389bdbc2c9d2de134f5cd0dc89',
triEURpool: '0xb9446c4ef5ebe66268da6700d26f96273de3d571',
ibEURsEUR: '0x19b080fe1ffa0553469d20ca36219f17fcf03859',
};
export const CURVE_V2_POOLS = {
@@ -494,10 +664,36 @@ export const CURVE_POLYGON_POOLS = {
};
export const CURVE_V2_POLYGON_POOLS = {
atricrypto: '0x3fcd5de6a9fc8a99995c406c77dda3ed7e406f81',
atricrypto3: '0x1d8b86e3d88cdb2d34688e87e72f388cb541b7c8',
};
export const CURVE_AVALANCHE_POOLS = {
aave: '0x7f90122bf0700f9e7e1f688fe926940e8839f353',
mim: '0xaea2e71b631fa93683bcf256a8689dfa0e094fcd',
USDC: '0x3a43a5851a3e3e0e25a3c1089670269786be1577',
};
export const CURVE_V2_AVALANCHE_POOLS = {
atricrypto: '0x58e57ca18b7a47112b877e31929798cd3d703b0f',
};
export const CURVE_FANTOM_POOLS = {
fUSDT: '0x92d5ebf3593a92888c25c0abef126583d4b5312e',
twoPool: '0x27e611fd27b276acbd5ffd632e5eaebec9761e40',
ren: '0x3ef6a01a0f81d6046290f3e2a8c5b843e738e604',
tri_v2: '0x2dd7c9371965472e5a5fd28fbe165007c61439e1',
geist: '0x0fa949783947bf6c1b171db13aeacbb488845b3f',
FRAX_twoPool: '0x7a656b342e14f745e2b164890e88017e27ae7320',
};
export const CURVE_V2_FANTOM_POOLS = {
tricrypto: '0x3a1659ddcf2339be3aea159ca010979fb49155ff',
};
export const CURVE_OPTIMISM_POOLS = {
tri: '0x1337bedc9d22ecbe766df105c9623922a27963ec',
};
export const SWERVE_POOLS = {
y: '0x329239599afb305da0a2ec69c58f8a6697f9f88d',
};
@@ -532,6 +728,37 @@ export const NERVE_POOLS = {
threePool: '0x1b3771a66ee31180906972580ade9b81afc5fcdc',
};
export const SYNAPSE_MAINNET_POOLS = {
nUSDLP: '0x1116898dda4015ed8ddefb84b6e8bc24528af2d8',
};
export const SYNAPSE_OPTIMISM_POOLS = {
nETHLP: '0xe27bff97ce92c3e1ff7aa9f86781fdd6d48f5ee9',
};
export const SYNAPSE_BSC_POOLS = {
nUSDLP: '0x28ec0b36f0819ecb5005cab836f4ed5a2eca4d13',
};
export const SYNAPSE_POLYGON_POOLS = {
nUSDLP: '0x85fcd7dd0a1e1a9fcd5fd886ed522de8221c3ee5',
};
export const SYNAPSE_FANTOM_POOLS = {
nUSDLP: '0x2913e812cf0dcca30fb28e6cac3d2dcff4497688',
nETHLP: '0x8d9ba570d6cb60c7e3e0f31343efe75ab8e65fb1',
};
export const SYNAPSE_AVALANCHE_POOLS = {
nUSDLP: '0xed2a7edd7413021d440b09d654f3b87712abab66',
nETHLP: '0x77a7e60555bc18b4be44c181b2575eee46212d44',
};
export const SYNAPSE_ARBITRUM_POOLS = {
nUSDLP: '0x0db3fe3b770c95a0b99d1ed6f2627933466c0dd8',
nETHLP: '0xd70a52248e546a3b260849386410c7170c7bd1e9',
};
export const BELT_POOLS = {
vPool: '0xf16d312d119c13dd27fd0dc814b0bcdcaaa62dfd',
};
@@ -589,12 +816,35 @@ export const DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID = valueByChainId<string[]>(
POLYGON_TOKENS.DAI,
POLYGON_TOKENS.USDT,
POLYGON_TOKENS.WBTC,
POLYGON_TOKENS.nUSD,
],
[ChainId.Avalanche]: [
AVALANCHE_TOKENS.WAVAX,
AVALANCHE_TOKENS.WETH,
AVALANCHE_TOKENS.DAI,
AVALANCHE_TOKENS.USDT,
AVALANCHE_TOKENS.USDC,
AVALANCHE_TOKENS.nUSD,
AVALANCHE_TOKENS.nETH,
AVALANCHE_TOKENS.aWETH,
],
[ChainId.Fantom]: [
FANTOM_TOKENS.WFTM,
FANTOM_TOKENS.WETH,
FANTOM_TOKENS.DAI,
FANTOM_TOKENS.USDC,
FANTOM_TOKENS.nUSD,
FANTOM_TOKENS.nETH,
FANTOM_TOKENS.MIM,
],
[ChainId.Celo]: [CELO_TOKENS.WCELO, CELO_TOKENS.mCUSD, CELO_TOKENS.WETH, CELO_TOKENS.amCUSD, CELO_TOKENS.WBTC],
[ChainId.Optimism]: [
OPTIMISM_TOKENS.WETH,
OPTIMISM_TOKENS.DAI,
OPTIMISM_TOKENS.USDC,
OPTIMISM_TOKENS.USDT,
OPTIMISM_TOKENS.nETH,
OPTIMISM_TOKENS.sWETH,
],
},
[],
@@ -612,6 +862,11 @@ export const DEFAULT_TOKEN_ADJACENCY_GRAPH_BY_CHAIN_ID = valueByChainId<TokenAdj
builder.add(MAINNET_TOKENS.MIR, MAINNET_TOKENS.UST);
// Convex and Curve
builder.add(MAINNET_TOKENS.cvxCRV, MAINNET_TOKENS.CRV).add(MAINNET_TOKENS.CRV, MAINNET_TOKENS.cvxCRV);
// FEI TRIBE liquid in UniV2
builder.add(MAINNET_TOKENS.FEI, MAINNET_TOKENS.TRIBE).add(MAINNET_TOKENS.TRIBE, MAINNET_TOKENS.FEI);
// FRAX ecosystem
builder.add(MAINNET_TOKENS.FRAX, MAINNET_TOKENS.FXS).add(MAINNET_TOKENS.FXS, MAINNET_TOKENS.FRAX);
builder.add(MAINNET_TOKENS.FRAX, MAINNET_TOKENS.OHM).add(MAINNET_TOKENS.OHM, MAINNET_TOKENS.FRAX);
})
// Build
.build(),
@@ -623,6 +878,22 @@ export const DEFAULT_TOKEN_ADJACENCY_GRAPH_BY_CHAIN_ID = valueByChainId<TokenAdj
}).build(),
[ChainId.Avalanche]: new TokenAdjacencyGraphBuilder({
default: DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID[ChainId.Avalanche],
})
.tap(builder => {
// Synape nETH/aWETH pool
builder
.add(AVALANCHE_TOKENS.aWETH, AVALANCHE_TOKENS.nETH)
.add(AVALANCHE_TOKENS.nETH, AVALANCHE_TOKENS.aWETH);
})
.build(),
[ChainId.Fantom]: new TokenAdjacencyGraphBuilder({
default: DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID[ChainId.Fantom],
}).build(),
[ChainId.Celo]: new TokenAdjacencyGraphBuilder({
default: DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID[ChainId.Celo],
}).build(),
[ChainId.Optimism]: new TokenAdjacencyGraphBuilder({
default: DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID[ChainId.Optimism],
}).build(),
},
new TokenAdjacencyGraphBuilder({ default: [] }).build(),
@@ -638,6 +909,9 @@ export const NATIVE_FEE_TOKEN_BY_CHAIN_ID = valueByChainId<string>(
[ChainId.Kovan]: getContractAddressesForChainOrThrow(ChainId.Kovan).etherToken,
[ChainId.Polygon]: getContractAddressesForChainOrThrow(ChainId.Polygon).etherToken,
[ChainId.Avalanche]: getContractAddressesForChainOrThrow(ChainId.Avalanche).etherToken,
[ChainId.Fantom]: getContractAddressesForChainOrThrow(ChainId.Fantom).etherToken,
[ChainId.Celo]: getContractAddressesForChainOrThrow(ChainId.Celo).etherToken,
[ChainId.Optimism]: getContractAddressesForChainOrThrow(ChainId.Optimism).etherToken,
},
NULL_ADDRESS,
);
@@ -652,6 +926,7 @@ const CURVE_TRI_POOL_MAINNET_TOKENS = [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC,
const CURVE_TRI_BTC_POOL_TOKEN = [MAINNET_TOKENS.RenBTC, MAINNET_TOKENS.WBTC, MAINNET_TOKENS.sBTC];
const CURVE_POLYGON_ATRICRYPTO_UNDERLYING_TOKENS = [POLYGON_TOKENS.DAI, POLYGON_TOKENS.USDC, POLYGON_TOKENS.USDT];
const CURVE_POLYGON_ATRICRYPTO_TOKENS = [POLYGON_TOKENS.amDAI, POLYGON_TOKENS.amUSDC, POLYGON_TOKENS.amUSDT];
const CURVE_FANTOM_TWO_POOL_TOKENS = [FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC];
const createCurveExchangePool = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange,
@@ -693,6 +968,16 @@ const createCurveMetaTriBtcPool = (info: { tokens: string[]; pool: string; gasSc
gasSchedule: info.gasSchedule,
});
const createCurveMetaTwoPoolFantom = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_underlying,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
tokens: [...info.tokens, ...CURVE_FANTOM_TWO_POOL_TOKENS],
metaTokens: info.tokens,
poolAddress: info.pool,
gasSchedule: info.gasSchedule,
});
const createCurveExchangeV2Pool = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange_v2,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_v2,
@@ -912,6 +1197,73 @@ export const CURVE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
pool: CURVE_POOLS.cvxcrv,
gasSchedule: 105e3,
}),
[CURVE_POOLS.ethcrv]: {
...createCurveExchangePool({
// This pool uses ETH
tokens: [MAINNET_TOKENS.WETH, MAINNET_TOKENS.CRV],
pool: CURVE_POOLS.ethcrv,
gasSchedule: 350e3,
}),
// This pool has a custom get_dy and exchange selector with uint256
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_uint256,
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying_uint256,
},
[CURVE_POOLS.ethcvx]: {
...createCurveExchangePool({
// This pool uses ETH
tokens: [MAINNET_TOKENS.WETH, MAINNET_TOKENS.CVX],
pool: CURVE_POOLS.ethcvx,
gasSchedule: 350e3,
}),
// This pool has a custom get_dy and exchange selector with uint256
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_uint256,
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying_uint256,
},
[CURVE_POOLS.mimust]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.MIM, MAINNET_TOKENS.UST],
pool: CURVE_POOLS.mimust,
gasSchedule: 105e3,
}),
[CURVE_POOLS.usttri_wormhole]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.UST_WORMHOLE],
pool: CURVE_POOLS.usttri_wormhole,
gasSchedule: 340e3,
}),
[CURVE_POOLS.fei_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.FEI],
pool: CURVE_POOLS.fei_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.rai_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.RAI],
pool: CURVE_POOLS.rai_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.DOLA_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.DOLA],
pool: CURVE_POOLS.DOLA_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.OUSD_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.OUSD],
pool: CURVE_POOLS.OUSD_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.d3pool]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.FRAX, MAINNET_TOKENS.FEI, MAINNET_TOKENS.alUSD],
pool: CURVE_POOLS.d3pool,
gasSchedule: 176e3,
}),
[CURVE_POOLS.triEURpool]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.agEUR, MAINNET_TOKENS.EURT, MAINNET_TOKENS.EURS],
pool: CURVE_POOLS.triEURpool,
gasSchedule: 176e3,
}),
[CURVE_POOLS.ibEURsEUR]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.ibEUR, MAINNET_TOKENS.sEUR],
pool: CURVE_POOLS.ibEURsEUR,
gasSchedule: 176e3,
}),
};
export const CURVE_V2_MAINNET_INFOS: { [name: string]: CurveInfo } = {
@@ -946,11 +1298,6 @@ export const CURVE_POLYGON_INFOS: { [name: string]: CurveInfo } = {
};
export const CURVE_V2_POLYGON_INFOS: { [name: string]: CurveInfo } = {
[CURVE_V2_POLYGON_POOLS.atricrypto]: createCurveV2MetaTriPool({
tokens: [POLYGON_TOKENS.WBTC, POLYGON_TOKENS.WETH],
pool: CURVE_V2_POLYGON_POOLS.atricrypto,
gasSchedule: 300e3,
}),
[CURVE_V2_POLYGON_POOLS.atricrypto3]: createCurveV2MetaTriPool({
tokens: [POLYGON_TOKENS.WBTC, POLYGON_TOKENS.WETH],
pool: CURVE_V2_POLYGON_POOLS.atricrypto3,
@@ -958,6 +1305,102 @@ export const CURVE_V2_POLYGON_INFOS: { [name: string]: CurveInfo } = {
}),
};
export const CURVE_AVALANCHE_INFOS: { [name: string]: CurveInfo } = {
['aave_exchangeunderlying']: createCurveExchangeUnderlyingPool({
tokens: [AVALANCHE_TOKENS.DAI, AVALANCHE_TOKENS.USDC, AVALANCHE_TOKENS.USDT],
pool: CURVE_AVALANCHE_POOLS.aave,
gasSchedule: 850e3,
}),
['aave_exchange']: createCurveExchangePool({
tokens: [AVALANCHE_TOKENS.aDAI, AVALANCHE_TOKENS.aUSDC, AVALANCHE_TOKENS.aUSDT],
pool: CURVE_AVALANCHE_POOLS.aave,
gasSchedule: 150e3,
}),
[CURVE_AVALANCHE_POOLS.mim]: createCurveExchangePool({
tokens: [AVALANCHE_TOKENS.MIM, AVALANCHE_TOKENS.USDT, AVALANCHE_TOKENS.USDC],
pool: CURVE_AVALANCHE_POOLS.mim,
gasSchedule: 150e3,
}),
[CURVE_AVALANCHE_POOLS.USDC]: createCurveExchangePool({
tokens: [AVALANCHE_TOKENS.USDC, AVALANCHE_TOKENS.nUSDC],
pool: CURVE_AVALANCHE_POOLS.USDC,
gasSchedule: 150e3,
}),
};
export const CURVE_V2_AVALANCHE_INFOS: { [name: string]: CurveInfo } = {
[CURVE_V2_AVALANCHE_POOLS.atricrypto]: {
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying_v2,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_underlying_v2,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
tokens: [
AVALANCHE_TOKENS.DAI,
AVALANCHE_TOKENS.USDC,
AVALANCHE_TOKENS.USDT,
AVALANCHE_TOKENS.WBTC,
AVALANCHE_TOKENS.WETH,
],
metaTokens: undefined,
poolAddress: CURVE_V2_AVALANCHE_POOLS.atricrypto,
gasSchedule: 1300e3,
},
};
// TODO: modify gasSchedule
export const CURVE_FANTOM_INFOS: { [name: string]: CurveInfo } = {
[CURVE_FANTOM_POOLS.ren]: createCurveExchangePool({
tokens: [FANTOM_TOKENS.WBTC, FANTOM_TOKENS.renBTC],
pool: CURVE_FANTOM_POOLS.ren,
gasSchedule: 171e3,
}),
[CURVE_FANTOM_POOLS.twoPool]: createCurveExchangePool({
tokens: [FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC],
pool: CURVE_FANTOM_POOLS.twoPool,
gasSchedule: 176e3,
}),
[CURVE_FANTOM_POOLS.fUSDT]: createCurveExchangeUnderlyingPool({
tokens: [FANTOM_TOKENS.fUSDT, FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC],
pool: CURVE_FANTOM_POOLS.fUSDT,
gasSchedule: 587e3,
}),
[CURVE_FANTOM_POOLS.tri_v2]: createCurveExchangePool({
tokens: [FANTOM_TOKENS.MIM, FANTOM_TOKENS.fUSDT, FANTOM_TOKENS.USDC],
pool: CURVE_FANTOM_POOLS.tri_v2,
gasSchedule: 176e3,
}),
['geist_exchangeunderlying']: createCurveExchangeUnderlyingPool({
tokens: [FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC, FANTOM_TOKENS.fUSDT],
pool: CURVE_FANTOM_POOLS.geist,
gasSchedule: 850e3,
}),
['geist_exchange']: createCurveExchangePool({
tokens: [FANTOM_TOKENS.gDAI, FANTOM_TOKENS.gUSDC, FANTOM_TOKENS.gfUSDT],
pool: CURVE_FANTOM_POOLS.geist,
gasSchedule: 150e3,
}),
[CURVE_FANTOM_POOLS.FRAX_twoPool]: createCurveMetaTwoPoolFantom({
tokens: [FANTOM_TOKENS.FRAX],
pool: CURVE_FANTOM_POOLS.FRAX_twoPool,
gasSchedule: 411e3,
}),
};
export const CURVE_V2_FANTOM_INFOS: { [name: string]: CurveInfo } = {
[CURVE_V2_FANTOM_POOLS.tricrypto]: createCurveExchangeV2Pool({
tokens: [FANTOM_TOKENS.fUSDT, FANTOM_TOKENS.WBTC, FANTOM_TOKENS.WETH],
pool: CURVE_V2_FANTOM_POOLS.tricrypto,
gasSchedule: 300e3,
}),
};
export const CURVE_OPTIMISM_INFOS: { [name: string]: CurveInfo } = {
[CURVE_OPTIMISM_POOLS.tri]: createCurveExchangePool({
tokens: [OPTIMISM_TOKENS.DAI, OPTIMISM_TOKENS.USDC, OPTIMISM_TOKENS.USDT],
pool: CURVE_OPTIMISM_POOLS.tri,
gasSchedule: 150e3,
}),
};
export const SWERVE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
[SWERVE_POOLS.y]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC, MAINNET_TOKENS.USDT, MAINNET_TOKENS.TUSD],
@@ -1111,6 +1554,87 @@ export const NERVE_BSC_INFOS: { [name: string]: CurveInfo } = {
},
};
export const SYNAPSE_BSC_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_BSC_POOLS.nUSDLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_BSC_POOLS.nUSDLP,
tokens: [BSC_TOKENS.nUSD, BSC_TOKENS.BUSD, BSC_TOKENS.USDC, BSC_TOKENS.USDT],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const SYNAPSE_FANTOM_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_FANTOM_POOLS.nUSDLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_FANTOM_POOLS.nUSDLP,
tokens: [FANTOM_TOKENS.nUSD, FANTOM_TOKENS.MIM, FANTOM_TOKENS.USDC, FANTOM_TOKENS.fUSDT],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const SYNAPSE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_MAINNET_POOLS.nUSDLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_MAINNET_POOLS.nUSDLP,
tokens: [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC, MAINNET_TOKENS.USDT],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const SYNAPSE_OPTIMISM_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_OPTIMISM_POOLS.nETHLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_OPTIMISM_POOLS.nETHLP,
tokens: [OPTIMISM_TOKENS.nETH, OPTIMISM_TOKENS.sWETH],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const SYNAPSE_POLYGON_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_POLYGON_POOLS.nUSDLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_POLYGON_POOLS.nUSDLP,
tokens: [POLYGON_TOKENS.nUSD, POLYGON_TOKENS.DAI, POLYGON_TOKENS.USDC, POLYGON_TOKENS.USDT],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const SYNAPSE_AVALANCHE_INFOS: { [name: string]: CurveInfo } = {
[SYNAPSE_AVALANCHE_POOLS.nUSDLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_AVALANCHE_POOLS.nUSDLP,
tokens: [AVALANCHE_TOKENS.nUSD, AVALANCHE_TOKENS.DAI, AVALANCHE_TOKENS.USDC, AVALANCHE_TOKENS.USDT],
metaTokens: undefined,
gasSchedule: 140e3,
},
[SYNAPSE_AVALANCHE_POOLS.nETHLP]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
sellQuoteFunctionSelector: CurveFunctionSelectors.calculateSwap,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
poolAddress: SYNAPSE_AVALANCHE_POOLS.nETHLP,
tokens: [AVALANCHE_TOKENS.nETH, AVALANCHE_TOKENS.aWETH],
metaTokens: undefined,
gasSchedule: 140e3,
},
};
export const FIREBIRDONESWAP_BSC_INFOS: { [name: string]: CurveInfo } = {
[FIREBIRDONESWAP_BSC_POOLS.oneswap]: {
exchangeFunctionSelector: CurveFunctionSelectors.swap,
@@ -1251,6 +1775,8 @@ export const SUSHISWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
[ChainId.Ropsten]: '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506',
[ChainId.Polygon]: '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506',
[ChainId.Avalanche]: '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506',
[ChainId.Fantom]: '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506',
[ChainId.Celo]: '0x1421bde4b10e8dd459b3bcb598810b1337d56842',
},
NULL_ADDRESS,
);
@@ -1320,6 +1846,9 @@ export const KYBER_DMM_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.Mainnet]: '0x1c87257f5e8609940bc751a07bb085bb7f8cdbe6',
[ChainId.Polygon]: '0x546c79662e028b661dfb4767664d0273184e4dd1',
[ChainId.BSC]: '0x78df70615ffc8066cc0887917f2cd72092c86409',
[ChainId.Avalanche]: '0x8efa5a9ad6d594cf76830267077b78ce0bc5a5f8',
[ChainId.Fantom]: '0x5d5a5a0a465129848c2549669e12cdc2f8de039a',
},
NULL_ADDRESS,
);
@@ -1469,6 +1998,13 @@ export const BALANCER_V2_VAULT_ADDRESS_BY_CHAIN = valueByChainId<string>(
NULL_ADDRESS,
);
export const BEETHOVEN_X_VAULT_ADDRESS_BY_CHAIN = valueByChainId<string>(
{
[ChainId.Fantom]: '0x20dd72ed959b6147912c2e529f0a0c651c33c9ce',
},
NULL_ADDRESS,
);
export const LIDO_INFO_BY_CHAIN = valueByChainId<LidoInfo>(
{
[ChainId.Mainnet]: {
@@ -1482,22 +2018,6 @@ export const LIDO_INFO_BY_CHAIN = valueByChainId<LidoInfo>(
},
);
export const CLIPPER_INFO_BY_CHAIN = valueByChainId(
{
[ChainId.Mainnet]: {
poolAddress: '0xe82906b6b1b04f631d126c974af57a3a7b6a99d9',
tokens: [
MAINNET_TOKENS.WETH, // technically ETH but our sampler and mixin handle this
MAINNET_TOKENS.WBTC,
MAINNET_TOKENS.USDC,
MAINNET_TOKENS.USDT,
MAINNET_TOKENS.DAI,
],
},
},
{ poolAddress: NULL_ADDRESS, tokens: [] },
);
export const BALANCER_SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer';
export const BALANCER_TOP_POOLS_FETCHED = 250;
export const BALANCER_MAX_POOLS_FETCHED = 3;
@@ -1509,6 +2029,13 @@ export const BALANCER_V2_SUBGRAPH_URL_BY_CHAIN = valueByChainId<string>(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2',
);
export const BEETHOVEN_X_SUBGRAPH_URL_BY_CHAIN = valueByChainId<string>(
{
[ChainId.Fantom]: 'https://graph-node.beets-ftm-node.com/subgraphs/name/beethovenx',
},
'https://graph-node.beets-ftm-node.com/subgraphs/name/beethovenx',
);
export const UNISWAPV3_CONFIG_BY_CHAIN_ID = valueByChainId(
{
[ChainId.Mainnet]: {
@@ -1519,10 +2046,36 @@ export const UNISWAPV3_CONFIG_BY_CHAIN_ID = valueByChainId(
quoter: '0x2f9e608fd881861b8916257b76613cb22ee0652c',
router: '0x03782388516e94fcd4c18666303601a12aa729ea',
},
[ChainId.Polygon]: {
quoter: '0xb27308f9f90d607463bb33ea1bebb41c27ce5ab6',
router: '0xe592427a0aece92de3edee1f18e0157c05861564',
},
[ChainId.Optimism]: {
quoter: '0xb27308f9f90d607463bb33ea1bebb41c27ce5ab6',
router: '0xe592427a0aece92de3edee1f18e0157c05861564',
},
},
{ quoter: NULL_ADDRESS, router: NULL_ADDRESS },
);
export const AAVE_V2_SUBGRAPH_URL_BY_CHAIN_ID = valueByChainId(
{
// TODO: enable after FQT has been redeployed on Ethereum mainnet
// [ChainId.Mainnet]: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v2',
[ChainId.Polygon]: 'https://api.thegraph.com/subgraphs/name/aave/aave-v2-matic',
[ChainId.Avalanche]: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v2-avalanche',
},
null,
);
export const COMPOUND_API_URL_BY_CHAIN_ID = valueByChainId(
{
// TODO: enable after FQT has been redeployed on Ethereum mainnet
// [ChainId.Mainnet]: 'https://api.compound.finance/api/v2',
},
null,
);
//
// BSC
//
@@ -1619,6 +2172,7 @@ export const JETSWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.BSC]: '0xbe65b8f75b9f20f4c522e0067a3887fada714800',
[ChainId.Polygon]: '0x5c6ec38fb0e2609672bdf628b1fd605a523e5923',
[ChainId.Fantom]: '0x845e76a8691423fbc4ecb8dd77556cb61c09ee25',
},
NULL_ADDRESS,
);
@@ -1637,6 +2191,60 @@ export const TRADER_JOE_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
NULL_ADDRESS,
);
export const UBESWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.Celo]: '0x7d28570135a2b1930f331c507f65039d4937f66c',
},
NULL_ADDRESS,
);
export const MORPHEUSSWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.Fantom]: '0x8ac868293d97761a1fed6d4a01e9ff17c5594aa3',
},
NULL_ADDRESS,
);
export const SPIRITSWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.Fantom]: '0x16327e3fbdaca3bcf7e38f5af2599d2ddc33ae52',
},
NULL_ADDRESS,
);
export const SPOOKYSWAP_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
{
[ChainId.Fantom]: '0xf491e7b69e4244ad4002bc14e878a34207e38c29',
},
NULL_ADDRESS,
);
export const VIP_ERC20_BRIDGE_SOURCES_BY_CHAIN_ID = valueByChainId<ERC20BridgeSource[]>(
{
[ChainId.Mainnet]: [
ERC20BridgeSource.UniswapV2,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Curve,
ERC20BridgeSource.LiquidityProvider,
ERC20BridgeSource.Native,
],
[ChainId.BSC]: [
ERC20BridgeSource.PancakeSwap,
ERC20BridgeSource.PancakeSwapV2,
ERC20BridgeSource.BakerySwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.ApeSwap,
ERC20BridgeSource.CafeSwap,
ERC20BridgeSource.CheeseSwap,
ERC20BridgeSource.JulSwap,
ERC20BridgeSource.LiquidityProvider,
ERC20BridgeSource.Native,
],
},
[],
);
const uniswapV2CloneGasSchedule = (fillData?: FillData) => {
// TODO: Different base cost if to/from ETH.
let gas = 90e3;
@@ -1675,6 +2283,7 @@ export const DEFAULT_GAS_SCHEDULE: Required<FeeSchedule> = {
[ERC20BridgeSource.Swerve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.SnowSwap]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Nerve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Synapse]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Belt]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Ellipsis]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Smoothy]: fillData => (fillData as CurveFillData).pool.gasSchedule,
@@ -1742,7 +2351,21 @@ export const DEFAULT_GAS_SCHEDULE: Required<FeeSchedule> = {
return gas;
},
[ERC20BridgeSource.Lido]: () => 226e3,
[ERC20BridgeSource.Clipper]: () => 170e3,
[ERC20BridgeSource.AaveV2]: (fillData?: FillData) => {
const aaveFillData = fillData as AaveV2FillData;
// NOTE: The Aave deposit method is more expensive than the withdraw
return aaveFillData.takerToken === aaveFillData.underlyingToken ? 400e3 : 300e3;
},
[ERC20BridgeSource.Compound]: (fillData?: FillData) => {
// NOTE: cETH is handled differently than other cTokens
const wethAddress = NATIVE_FEE_TOKEN_BY_CHAIN_ID[ChainId.Mainnet];
const compoundFillData = fillData as CompoundFillData;
if (compoundFillData.takerToken === compoundFillData.cToken) {
return compoundFillData.makerToken === wethAddress ? 120e3 : 150e3;
} else {
return compoundFillData.takerToken === wethAddress ? 210e3 : 250e3;
}
},
//
// BSC
@@ -1771,6 +2394,19 @@ export const DEFAULT_GAS_SCHEDULE: Required<FeeSchedule> = {
//
[ERC20BridgeSource.Pangolin]: uniswapV2CloneGasSchedule,
[ERC20BridgeSource.TraderJoe]: uniswapV2CloneGasSchedule,
//
// Celo
//
[ERC20BridgeSource.UbeSwap]: uniswapV2CloneGasSchedule,
//
// Fantom
//
[ERC20BridgeSource.MorpheusSwap]: uniswapV2CloneGasSchedule,
[ERC20BridgeSource.SpiritSwap]: uniswapV2CloneGasSchedule,
[ERC20BridgeSource.SpookySwap]: uniswapV2CloneGasSchedule,
[ERC20BridgeSource.Beethovenx]: () => 100e3,
};
export const DEFAULT_FEE_SCHEDULE: Required<FeeSchedule> = { ...DEFAULT_GAS_SCHEDULE };
@@ -1779,7 +2415,7 @@ export const POSITIVE_SLIPPAGE_FEE_TRANSFORMER_GAS = new BigNumber(20000);
// tslint:enable:custom-no-magic-numbers
export const DEFAULT_GET_MARKET_ORDERS_OPTS: GetMarketOrdersOpts = {
export const DEFAULT_GET_MARKET_ORDERS_OPTS: Omit<GetMarketOrdersOpts, 'gasPrice'> = {
// tslint:disable-next-line: custom-no-magic-numbers
runLimit: 2 ** 15,
excludedSources: [],
@@ -1796,4 +2432,5 @@ export const DEFAULT_GET_MARKET_ORDERS_OPTS: GetMarketOrdersOpts = {
shouldGenerateQuoteReport: true,
shouldIncludePriceComparisonsReport: false,
tokenAdjacencyGraph: { default: [] },
neonRouterNumSamples: 14,
};

View File

@@ -71,7 +71,25 @@ function hasLiquidity(fills: Fill[]): boolean {
return true;
}
function nativeOrdersToFills(
export function ethToOutputAmount({
input,
output,
ethAmount,
inputAmountPerEth,
outputAmountPerEth,
}: {
input: BigNumber;
output: BigNumber;
inputAmountPerEth: BigNumber;
outputAmountPerEth: BigNumber;
ethAmount: BigNumber | number;
}): BigNumber {
return !outputAmountPerEth.isZero()
? outputAmountPerEth.times(ethAmount)
: inputAmountPerEth.times(ethAmount).times(output.dividedToIntegerBy(input));
}
export function nativeOrdersToFills(
side: MarketOperation,
orders: NativeOrderWithFillableAmounts[],
targetInput: BigNumber = POSITIVE_INF,
@@ -89,9 +107,13 @@ function nativeOrdersToFills(
const input = side === MarketOperation.Sell ? takerAmount : makerAmount;
const output = side === MarketOperation.Sell ? makerAmount : takerAmount;
const fee = fees[ERC20BridgeSource.Native] === undefined ? 0 : fees[ERC20BridgeSource.Native]!(o);
const outputPenalty = !outputAmountPerEth.isZero()
? outputAmountPerEth.times(fee)
: inputAmountPerEth.times(fee).times(output.dividedToIntegerBy(input));
const outputPenalty = ethToOutputAmount({
input,
output,
inputAmountPerEth,
outputAmountPerEth,
ethAmount: fee,
});
// targetInput can be less than the order size
// whilst the penalty is constant, it affects the adjusted output
// only up until the target has been exhausted.
@@ -132,7 +154,7 @@ function nativeOrdersToFills(
return fills;
}
function dexSamplesToFills(
export function dexSamplesToFills(
side: MarketOperation,
samples: DexSample[],
outputAmountPerEth: BigNumber,
@@ -156,9 +178,13 @@ function dexSamplesToFills(
let penalty = ZERO_AMOUNT;
if (i === 0) {
// Only the first fill in a DEX path incurs a penalty.
penalty = !outputAmountPerEth.isZero()
? outputAmountPerEth.times(fee)
: inputAmountPerEth.times(fee).times(output.dividedToIntegerBy(input));
penalty = ethToOutputAmount({
input,
output,
inputAmountPerEth,
outputAmountPerEth,
ethAmount: fee,
});
}
const adjustedOutput = side === MarketOperation.Sell ? output.minus(penalty) : output.plus(penalty);

View File

@@ -18,12 +18,15 @@ import {
import {
dexSampleToReportSource,
ExtendedQuoteReportSources,
generateExtendedQuoteReportSources,
generateQuoteReport,
multiHopSampleToReportSource,
nativeOrderToReportEntry,
PriceComparisonsReport,
QuoteReport,
} from './../quote_report_generator';
import { getComparisonPrices } from './comparison_price';
import {
BUY_SOURCE_FILTER_BY_CHAIN_ID,
@@ -39,7 +42,7 @@ import { createFills } from './fills';
import { getBestTwoHopQuote } from './multihop_utils';
import { createOrdersFromTwoHopSample } from './orders';
import { Path, PathPenaltyOpts } from './path';
import { fillsToSortedPaths, findOptimalPathAsync } from './path_optimizer';
import { fillsToSortedPaths, findOptimalPathJSAsync, findOptimalRustPathFromSamples } from './path_optimizer';
import { DexOrderSampler, getSampleAmounts } from './sampler';
import { SourceFilters } from './source_filters';
import {
@@ -48,7 +51,6 @@ import {
DexSample,
ERC20BridgeSource,
Fill,
FillData,
GenerateOptimizedOrdersOpts,
GetMarketOrdersOpts,
MarketSideLiquidity,
@@ -57,6 +59,8 @@ import {
OrderDomain,
} from './types';
const SHOULD_USE_RUST_ROUTER = process.env.RUST_ROUTER === 'true';
// tslint:disable:boolean-naming
export class MarketOperationUtils {
@@ -77,6 +81,25 @@ export class MarketOperationUtils {
return generateQuoteReport(side, quotes.nativeOrders, liquidityDelivered, comparisonPrice, quoteRequestor);
}
private static _computeExtendedQuoteReportSources(
quoteRequestor: QuoteRequestor | undefined,
marketSideLiquidity: MarketSideLiquidity,
amount: BigNumber,
optimizerResult: OptimizerResult,
comparisonPrice?: BigNumber | undefined,
): ExtendedQuoteReportSources {
const { side, quotes } = marketSideLiquidity;
const { liquidityDelivered } = optimizerResult;
return generateExtendedQuoteReportSources(
side,
quotes,
liquidityDelivered,
amount,
comparisonPrice,
quoteRequestor,
);
}
private static _computePriceComparisonsReport(
quoteRequestor: QuoteRequestor | undefined,
marketSideLiquidity: MarketSideLiquidity,
@@ -135,6 +158,8 @@ export class MarketOperationUtils {
// Call the sampler contract.
const samplerPromise = this._sampler.executeAsync(
this._sampler.getBlockNumber(),
this._sampler.getGasLeft(),
this._sampler.getTokenDecimals([makerToken, takerToken]),
// Get native order fillable amounts.
this._sampler.getLimitOrderFillableTakerAmounts(nativeOrders, this.contractAddresses.exchangeProxy),
@@ -161,6 +186,7 @@ export class MarketOperationUtils {
takerAmount,
),
this._sampler.isAddressContract(txOrigin),
this._sampler.getGasLeft(),
);
// Refresh the cached pools asynchronously if required
@@ -168,6 +194,8 @@ export class MarketOperationUtils {
const [
[
blockNumber,
gasBefore,
tokenDecimals,
orderFillableTakerAmounts,
outputAmountPerEth,
@@ -175,9 +203,14 @@ export class MarketOperationUtils {
dexQuotes,
rawTwoHopQuotes,
isTxOriginContract,
gasAfter,
],
] = await Promise.all([samplerPromise]);
// Log the gas metrics
_opts.samplerMetrics?.logGasDetails({ gasBefore, gasAfter });
_opts.samplerMetrics?.logBlockNumber(blockNumber);
// Filter out any invalid two hop quotes where we couldn't find a route
const twoHopQuotes = rawTwoHopQuotes.filter(
q => q && q.fillData && q.fillData.firstHopSource && q.fillData.secondHopSource,
@@ -326,12 +359,12 @@ export class MarketOperationUtils {
public async getBatchMarketBuyOrdersAsync(
batchNativeOrders: SignedNativeOrder[][],
makerAmounts: BigNumber[],
opts?: Partial<GetMarketOrdersOpts>,
opts: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber },
): Promise<Array<OptimizerResult | undefined>> {
if (batchNativeOrders.length === 0) {
throw new Error(AggregationError.EmptyOrders);
}
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const _opts: GetMarketOrdersOpts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const requestFilters = new SourceFilters().exclude(_opts.excludedSources).include(_opts.includedSources);
const quoteSourceFilters = this._buySources.merge(requestFilters);
@@ -409,6 +442,8 @@ export class MarketOperationUtils {
excludedSources: _opts.excludedSources,
feeSchedule: _opts.feeSchedule,
allowFallback: _opts.allowFallback,
gasPrice: _opts.gasPrice,
neonRouterNumSamples: _opts.neonRouterNumSamples,
},
);
return optimizerResult;
@@ -475,6 +510,7 @@ export class MarketOperationUtils {
outputAmountPerEth,
inputAmountPerEth,
exchangeProxyOverhead: opts.exchangeProxyOverhead || (() => ZERO_AMOUNT),
gasPrice: opts.gasPrice,
};
// NOTE: For sell quotes input is the taker asset and for buy quotes input is the maker asset
@@ -485,8 +521,31 @@ export class MarketOperationUtils {
const _unoptimizedPath = fillsToSortedPaths(fills, side, inputAmount, penaltyOpts)[0];
const unoptimizedPath = _unoptimizedPath ? _unoptimizedPath.collapse(orderOpts) : undefined;
// Find the optimal path
const optimalPath = await findOptimalPathAsync(side, fills, inputAmount, opts.runLimit, penaltyOpts);
// Find the optimal path using Rust router if enabled, otherwise fallback to JS Router
let optimalPath: Path | undefined;
if (SHOULD_USE_RUST_ROUTER) {
optimalPath = findOptimalRustPathFromSamples(
side,
dexQuotes,
[...nativeOrders, ...augmentedRfqtIndicativeQuotes],
inputAmount,
penaltyOpts,
opts.feeSchedule,
this._sampler.chainId,
opts.neonRouterNumSamples,
opts.samplerMetrics,
);
} else {
optimalPath = await findOptimalPathJSAsync(
side,
fills,
inputAmount,
opts.runLimit,
opts.samplerMetrics,
penaltyOpts,
);
}
const optimalPathRate = optimalPath ? optimalPath.adjustedRate() : ZERO_AMOUNT;
const { adjustedRate: bestTwoHopRate, quote: bestTwoHopQuote } = getBestTwoHopQuote(
@@ -514,7 +573,7 @@ export class MarketOperationUtils {
}
// Generate a fallback path if required
await this._addOptionalFallbackAsync(side, inputAmount, optimalPath, fills, opts, penaltyOpts);
await this._addOptionalFallbackAsync(side, inputAmount, optimalPath, dexQuotes, fills, opts, penaltyOpts);
const collapsedPath = optimalPath.collapse(orderOpts);
return {
@@ -536,9 +595,9 @@ export class MarketOperationUtils {
nativeOrders: SignedNativeOrder[],
amount: BigNumber,
side: MarketOperation,
opts?: Partial<GetMarketOrdersOpts>,
opts: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber },
): Promise<OptimizerResultWithReport> {
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const _opts: GetMarketOrdersOpts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const optimizerOpts: GenerateOptimizedOrdersOpts = {
bridgeSlippage: _opts.bridgeSlippage,
maxFallbackSlippage: _opts.maxFallbackSlippage,
@@ -546,6 +605,9 @@ export class MarketOperationUtils {
feeSchedule: _opts.feeSchedule,
allowFallback: _opts.allowFallback,
exchangeProxyOverhead: _opts.exchangeProxyOverhead,
gasPrice: _opts.gasPrice,
neonRouterNumSamples: _opts.neonRouterNumSamples,
samplerMetrics: _opts.samplerMetrics,
};
if (nativeOrders.length === 0) {
@@ -684,6 +746,16 @@ export class MarketOperationUtils {
);
}
// Always compute the Extended Quote Report
let extendedQuoteReportSources: ExtendedQuoteReportSources | undefined;
extendedQuoteReportSources = MarketOperationUtils._computeExtendedQuoteReportSources(
_opts.rfqt ? _opts.rfqt.quoteRequestor : undefined,
marketSideLiquidity,
amount,
optimizerResult,
wholeOrderPrice,
);
let priceComparisonsReport: PriceComparisonsReport | undefined;
if (_opts.shouldIncludePriceComparisonsReport) {
priceComparisonsReport = MarketOperationUtils._computePriceComparisonsReport(
@@ -692,7 +764,7 @@ export class MarketOperationUtils {
wholeOrderPrice,
);
}
return { ...optimizerResult, quoteReport, priceComparisonsReport };
return { ...optimizerResult, quoteReport, extendedQuoteReportSources, priceComparisonsReport };
}
private async _refreshPoolCacheIfRequiredAsync(takerToken: string, makerToken: string): Promise<void> {
@@ -711,7 +783,8 @@ export class MarketOperationUtils {
side: MarketOperation,
inputAmount: BigNumber,
optimalPath: Path,
fills: Array<Array<Fill<FillData>>>,
dexQuotes: DexSample[][],
fills: Fill[][],
opts: GenerateOptimizedOrdersOpts,
penaltyOpts: PathPenaltyOpts,
): Promise<void> {
@@ -725,13 +798,40 @@ export class MarketOperationUtils {
if (opts.allowFallback && fragileFills.length !== 0) {
// We create a fallback path that is exclusive of Native liquidity
// This is the optimal on-chain path for the entire input amount
const sturdyFills = fills.filter(p => p.length > 0 && !fragileSources.includes(p[0].source));
const sturdyOptimalPath = await findOptimalPathAsync(side, sturdyFills, inputAmount, opts.runLimit, {
const sturdyPenaltyOpts = {
...penaltyOpts,
exchangeProxyOverhead: (sourceFlags: bigint) =>
// tslint:disable-next-line: no-bitwise
penaltyOpts.exchangeProxyOverhead(sourceFlags | optimalPath.sourceFlags),
});
};
let sturdyOptimalPath: Path | undefined;
if (SHOULD_USE_RUST_ROUTER) {
const sturdySamples = dexQuotes.filter(
samples => samples.length > 0 && !fragileSources.includes(samples[0].source),
);
sturdyOptimalPath = findOptimalRustPathFromSamples(
side,
sturdySamples,
[],
inputAmount,
sturdyPenaltyOpts,
opts.feeSchedule,
this._sampler.chainId,
opts.neonRouterNumSamples,
undefined, // hack: set sampler metrics to undefined to avoid fallback timings
);
} else {
const sturdyFills = fills.filter(p => p.length > 0 && !fragileSources.includes(p[0].source));
sturdyOptimalPath = await findOptimalPathJSAsync(
side,
sturdyFills,
inputAmount,
opts.runLimit,
undefined, // hack: set sampler metrics to undefined to avoid fallback timings
sturdyPenaltyOpts,
);
}
// Calculate the slippage of on-chain sources compared to the most optimal path
// if within an acceptable threshold we enable a fallback to prevent reverts
if (

View File

@@ -3,13 +3,15 @@ import { AbiEncoder, BigNumber } from '@0x/utils';
import { AssetSwapperContractAddresses, MarketOperation } from '../../types';
import { MAX_UINT256, NULL_BYTES, ZERO_AMOUNT } from './constants';
import { MAX_UINT256, ZERO_AMOUNT } from './constants';
import {
AaveV2FillData,
AggregationError,
BalancerFillData,
BalancerV2FillData,
BancorFillData,
CollapsedFill,
CompoundFillData,
CurveFillData,
DexSample,
DODOFillData,
@@ -132,6 +134,8 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'BakerySwap');
case ERC20BridgeSource.Nerve:
return encodeBridgeSourceId(BridgeProtocol.Nerve, 'Nerve');
case ERC20BridgeSource.Synapse:
return encodeBridgeSourceId(BridgeProtocol.Nerve, 'Synapse');
case ERC20BridgeSource.Belt:
return encodeBridgeSourceId(BridgeProtocol.Curve, 'Belt');
case ERC20BridgeSource.Ellipsis:
@@ -180,12 +184,24 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
return encodeBridgeSourceId(BridgeProtocol.Nerve, 'IronSwap');
case ERC20BridgeSource.ACryptos:
return encodeBridgeSourceId(BridgeProtocol.Curve, 'ACryptoS');
case ERC20BridgeSource.Clipper:
return encodeBridgeSourceId(BridgeProtocol.Clipper, 'Clipper');
case ERC20BridgeSource.Pangolin:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'Pangolin');
case ERC20BridgeSource.TraderJoe:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'TraderJoe');
case ERC20BridgeSource.UbeSwap:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'UbeSwap');
case ERC20BridgeSource.Beethovenx:
return encodeBridgeSourceId(BridgeProtocol.BalancerV2, 'Beethovenx');
case ERC20BridgeSource.SpiritSwap:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'SpiritSwap');
case ERC20BridgeSource.SpookySwap:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'SpookySwap');
case ERC20BridgeSource.MorpheusSwap:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'MorpheusSwap');
case ERC20BridgeSource.AaveV2:
return encodeBridgeSourceId(BridgeProtocol.AaveV2, 'AaveV2');
case ERC20BridgeSource.Compound:
return encodeBridgeSourceId(BridgeProtocol.Compound, 'Compound');
default:
throw new Error(AggregationError.NoBridgeForSource);
}
@@ -212,6 +228,7 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
case ERC20BridgeSource.Swerve:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
case ERC20BridgeSource.Ellipsis:
case ERC20BridgeSource.Smoothy:
@@ -234,6 +251,7 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
bridgeData = encoder.encode([balancerFillData.poolAddress]);
break;
case ERC20BridgeSource.BalancerV2:
case ERC20BridgeSource.Beethovenx:
const balancerV2FillData = (order as OptimizedMarketBridgeOrder<BalancerV2FillData>).fillData;
const { vault, poolId } = balancerV2FillData;
bridgeData = encoder.encode([vault, poolId]);
@@ -262,6 +280,10 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
case ERC20BridgeSource.JetSwap:
case ERC20BridgeSource.Pangolin:
case ERC20BridgeSource.TraderJoe:
case ERC20BridgeSource.UbeSwap:
case ERC20BridgeSource.SpiritSwap:
case ERC20BridgeSource.SpookySwap:
case ERC20BridgeSource.MorpheusSwap:
const uniswapV2FillData = (order as OptimizedMarketBridgeOrder<UniswapV2FillData>).fillData;
bridgeData = encoder.encode([uniswapV2FillData.router, uniswapV2FillData.tokenAddressPath]);
break;
@@ -326,10 +348,15 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
const lidoFillData = (order as OptimizedMarketBridgeOrder<LidoFillData>).fillData;
bridgeData = encoder.encode([lidoFillData.stEthTokenAddress]);
break;
case ERC20BridgeSource.Clipper:
const clipperFillData = (order as OptimizedMarketBridgeOrder<LiquidityProviderFillData>).fillData;
bridgeData = encoder.encode([clipperFillData.poolAddress, NULL_BYTES]);
case ERC20BridgeSource.AaveV2:
const aaveFillData = (order as OptimizedMarketBridgeOrder<AaveV2FillData>).fillData;
bridgeData = encoder.encode([aaveFillData.lendingPool, aaveFillData.aToken]);
break;
case ERC20BridgeSource.Compound:
const compoundFillData = (order as OptimizedMarketBridgeOrder<CompoundFillData>).fillData;
bridgeData = encoder.encode([compoundFillData.cToken]);
break;
default:
throw new Error(AggregationError.NoBridgeForSource);
}
@@ -439,6 +466,7 @@ export const BRIDGE_ENCODERS: {
[ERC20BridgeSource.Swerve]: curveEncoder,
[ERC20BridgeSource.SnowSwap]: curveEncoder,
[ERC20BridgeSource.Nerve]: curveEncoder,
[ERC20BridgeSource.Synapse]: curveEncoder,
[ERC20BridgeSource.Belt]: curveEncoder,
[ERC20BridgeSource.Ellipsis]: curveEncoder,
[ERC20BridgeSource.Smoothy]: curveEncoder,
@@ -456,6 +484,11 @@ export const BRIDGE_ENCODERS: {
[ERC20BridgeSource.ShibaSwap]: routerAddressPathEncoder,
[ERC20BridgeSource.Pangolin]: routerAddressPathEncoder,
[ERC20BridgeSource.TraderJoe]: routerAddressPathEncoder,
[ERC20BridgeSource.SpiritSwap]: routerAddressPathEncoder,
[ERC20BridgeSource.SpookySwap]: routerAddressPathEncoder,
[ERC20BridgeSource.MorpheusSwap]: routerAddressPathEncoder,
// Celo
[ERC20BridgeSource.UbeSwap]: routerAddressPathEncoder,
// BSC
[ERC20BridgeSource.PancakeSwap]: routerAddressPathEncoder,
[ERC20BridgeSource.PancakeSwapV2]: routerAddressPathEncoder,
@@ -483,16 +516,15 @@ export const BRIDGE_ENCODERS: {
// Custom integrations
[ERC20BridgeSource.MakerPsm]: makerPsmEncoder,
[ERC20BridgeSource.BalancerV2]: balancerV2Encoder,
[ERC20BridgeSource.Beethovenx]: balancerV2Encoder,
[ERC20BridgeSource.UniswapV3]: AbiEncoder.create([
{ name: 'router', type: 'address' },
{ name: 'path', type: 'bytes' },
]),
[ERC20BridgeSource.KyberDmm]: AbiEncoder.create('(address,address[],address[])'),
[ERC20BridgeSource.Lido]: AbiEncoder.create('(address)'),
[ERC20BridgeSource.Clipper]: AbiEncoder.create([
{ name: 'provider', type: 'address' },
{ name: 'data', type: 'bytes' },
]),
[ERC20BridgeSource.AaveV2]: AbiEncoder.create('(address,address)'),
[ERC20BridgeSource.Compound]: AbiEncoder.create('(address)'),
};
function getFillTokenAmounts(fill: CollapsedFill, side: MarketOperation): [BigNumber, BigNumber] {

View File

@@ -3,6 +3,7 @@ import { BigNumber } from '@0x/utils';
import { MarketOperation } from '../../types';
import { POSITIVE_INF, ZERO_AMOUNT } from './constants';
import { ethToOutputAmount } from './fills';
import { createBridgeOrder, createNativeOptimizedOrder, CreateOrderFromPathOpts, getMakerTakerTokens } from './orders';
import { getCompleteRate, getRate } from './rate_utils';
import {
@@ -25,12 +26,14 @@ export interface PathPenaltyOpts {
outputAmountPerEth: BigNumber;
inputAmountPerEth: BigNumber;
exchangeProxyOverhead: ExchangeProxyOverhead;
gasPrice: BigNumber;
}
export const DEFAULT_PATH_PENALTY_OPTS: PathPenaltyOpts = {
outputAmountPerEth: ZERO_AMOUNT,
inputAmountPerEth: ZERO_AMOUNT,
exchangeProxyOverhead: () => ZERO_AMOUNT,
gasPrice: ZERO_AMOUNT,
};
export class Path {
@@ -143,9 +146,13 @@ export class Path {
const { input, output } = this._adjustedSize;
const { exchangeProxyOverhead, outputAmountPerEth, inputAmountPerEth } = this.pathPenaltyOpts;
const gasOverhead = exchangeProxyOverhead(this.sourceFlags);
const pathPenalty = !outputAmountPerEth.isZero()
? outputAmountPerEth.times(gasOverhead)
: inputAmountPerEth.times(gasOverhead).times(output.dividedToIntegerBy(input));
const pathPenalty = ethToOutputAmount({
input,
output,
inputAmountPerEth,
outputAmountPerEth,
ethAmount: gasOverhead,
});
return {
input,
output: this.side === MarketOperation.Sell ? output.minus(pathPenalty) : output.plus(pathPenalty),

View File

@@ -1,26 +1,402 @@
import { BigNumber } from '@0x/utils';
import { assert } from '@0x/assert';
import { ChainId } from '@0x/contract-addresses';
import { OptimizerCapture, route, SerializedPath } from '@0x/neon-router';
import { BigNumber, hexUtils } from '@0x/utils';
import * as _ from 'lodash';
import { performance } from 'perf_hooks';
import { MarketOperation } from '../../types';
import { MarketOperation, NativeOrderWithFillableAmounts } from '../../types';
import { VIP_ERC20_BRIDGE_SOURCES_BY_CHAIN_ID, ZERO_AMOUNT } from '../market_operation_utils/constants';
import { dexSamplesToFills, ethToOutputAmount, nativeOrdersToFills } from './fills';
import { DEFAULT_PATH_PENALTY_OPTS, Path, PathPenaltyOpts } from './path';
import { ERC20BridgeSource, Fill } from './types';
import { DexSample, ERC20BridgeSource, FeeSchedule, Fill, FillData, SamplerMetrics } from './types';
// tslint:disable: prefer-for-of custom-no-magic-numbers completed-docs no-bitwise
const RUN_LIMIT_DECAY_FACTOR = 0.5;
// NOTE: The Rust router will panic with less than 3 samples
const MIN_NUM_SAMPLE_INPUTS = 3;
const isDexSample = (obj: DexSample | NativeOrderWithFillableAmounts): obj is DexSample => !!(obj as DexSample).source;
function nativeOrderToNormalizedAmounts(
side: MarketOperation,
nativeOrder: NativeOrderWithFillableAmounts,
): { input: BigNumber; output: BigNumber } {
const { fillableTakerAmount, fillableTakerFeeAmount, fillableMakerAmount } = nativeOrder;
const makerAmount = fillableMakerAmount;
const takerAmount = fillableTakerAmount.plus(fillableTakerFeeAmount);
const input = side === MarketOperation.Sell ? takerAmount : makerAmount;
const output = side === MarketOperation.Sell ? makerAmount : takerAmount;
return { input, output };
}
function calculateOuputFee(
side: MarketOperation,
sampleOrNativeOrder: DexSample | NativeOrderWithFillableAmounts,
outputAmountPerEth: BigNumber,
inputAmountPerEth: BigNumber,
fees: FeeSchedule,
): BigNumber {
if (isDexSample(sampleOrNativeOrder)) {
const { input, output, source, fillData } = sampleOrNativeOrder;
const fee = fees[source]?.(fillData) || 0;
const outputFee = ethToOutputAmount({
input,
output,
inputAmountPerEth,
outputAmountPerEth,
ethAmount: fee,
});
return outputFee;
} else {
const { input, output } = nativeOrderToNormalizedAmounts(side, sampleOrNativeOrder);
const fee = fees[ERC20BridgeSource.Native]?.(sampleOrNativeOrder) || 0;
const outputFee = ethToOutputAmount({
input,
output,
inputAmountPerEth,
outputAmountPerEth,
ethAmount: fee,
});
return outputFee;
}
}
function findRoutesAndCreateOptimalPath(
side: MarketOperation,
samples: DexSample[][],
nativeOrders: NativeOrderWithFillableAmounts[],
input: BigNumber,
opts: PathPenaltyOpts,
fees: FeeSchedule,
neonRouterNumSamples: number,
): Path | undefined {
const createFill = (sample: DexSample): Fill | undefined => {
const fills = dexSamplesToFills(side, [sample], opts.outputAmountPerEth, opts.inputAmountPerEth, fees);
// NOTE: If the sample has 0 output dexSamplesToFills will return [] because no fill can be created
if (fills.length === 0) {
return undefined;
}
return fills[0];
};
const samplesAndNativeOrdersWithResults: Array<DexSample[] | NativeOrderWithFillableAmounts[]> = [];
const serializedPaths: SerializedPath[] = [];
const sampleSourcePathIds: string[] = [];
for (const singleSourceSamples of samples) {
if (singleSourceSamples.length === 0) {
continue;
}
const sourcePathId = hexUtils.random();
const singleSourceSamplesWithOutput = [...singleSourceSamples];
for (let i = singleSourceSamples.length - 1; i >= 0; i--) {
if (singleSourceSamples[i].output.isZero()) {
// Remove trailing 0 output samples
singleSourceSamplesWithOutput.pop();
} else {
break;
}
}
if (singleSourceSamplesWithOutput.length < MIN_NUM_SAMPLE_INPUTS) {
continue;
}
// TODO(kimpers): Do we need to handle 0 entries, from eg Kyber?
const serializedPath = singleSourceSamplesWithOutput.reduce<SerializedPath>(
(memo, sample, sampleIdx) => {
memo.ids.push(`${sample.source}-${serializedPaths.length}-${sampleIdx}`);
memo.inputs.push(sample.input.integerValue().toNumber());
memo.outputs.push(sample.output.integerValue().toNumber());
memo.outputFees.push(
calculateOuputFee(side, sample, opts.outputAmountPerEth, opts.inputAmountPerEth, fees)
.integerValue()
.toNumber(),
);
return memo;
},
{
ids: [],
inputs: [],
outputs: [],
outputFees: [],
},
);
samplesAndNativeOrdersWithResults.push(singleSourceSamplesWithOutput);
serializedPaths.push(serializedPath);
sampleSourcePathIds.push(sourcePathId);
}
const nativeOrdersourcePathId = hexUtils.random();
for (const [idx, nativeOrder] of nativeOrders.entries()) {
const { input: normalizedOrderInput, output: normalizedOrderOutput } = nativeOrderToNormalizedAmounts(
side,
nativeOrder,
);
// NOTE: skip dummy order created in swap_quoter
// TODO: remove dummy order and this logic once we don't need the JS router
if (normalizedOrderInput.isLessThanOrEqualTo(0) || normalizedOrderOutput.isLessThanOrEqualTo(0)) {
continue;
}
const fee = calculateOuputFee(side, nativeOrder, opts.outputAmountPerEth, opts.inputAmountPerEth, fees)
.integerValue()
.toNumber();
// HACK: due to an issue with the Rust router interpolation we need to create exactly 13 samples from the native order
const ids = [];
const inputs = [];
const outputs = [];
const outputFees = [];
for (let i = 1; i <= 13; i++) {
const fraction = i / 13;
const currentInput = BigNumber.min(normalizedOrderInput.times(fraction), normalizedOrderInput);
const currentOutput = BigNumber.min(normalizedOrderOutput.times(fraction), normalizedOrderOutput);
const id = `${ERC20BridgeSource.Native}-${serializedPaths.length}-${idx}-${i}`;
inputs.push(currentInput.integerValue().toNumber());
outputs.push(currentOutput.integerValue().toNumber());
outputFees.push(fee);
ids.push(id);
}
const serializedPath: SerializedPath = {
ids,
inputs,
outputs,
outputFees,
};
samplesAndNativeOrdersWithResults.push([nativeOrder]);
serializedPaths.push(serializedPath);
sampleSourcePathIds.push(nativeOrdersourcePathId);
}
if (serializedPaths.length === 0) {
return undefined;
}
const rustArgs: OptimizerCapture = {
side,
targetInput: input.toNumber(),
pathsIn: serializedPaths,
};
const allSourcesRustRoute = new Float64Array(rustArgs.pathsIn.length);
const strategySourcesOutputAmounts = new Float64Array(rustArgs.pathsIn.length);
route(rustArgs, allSourcesRustRoute, strategySourcesOutputAmounts, neonRouterNumSamples);
assert.assert(
rustArgs.pathsIn.length === allSourcesRustRoute.length,
'different number of sources in the Router output than the input',
);
assert.assert(
rustArgs.pathsIn.length === strategySourcesOutputAmounts.length,
'different number of sources in the Router output amounts results than the input',
);
const routesAndSamplesAndOutputs = _.zip(
allSourcesRustRoute,
samplesAndNativeOrdersWithResults,
strategySourcesOutputAmounts,
sampleSourcePathIds,
);
const adjustedFills: Fill[] = [];
const totalRoutedAmount = BigNumber.sum(...allSourcesRustRoute);
const scale = input.dividedBy(totalRoutedAmount);
for (const [routeInput, routeSamplesAndNativeOrders, outputAmount, sourcePathId] of routesAndSamplesAndOutputs) {
if (!routeInput || !routeSamplesAndNativeOrders || !outputAmount || !Number.isFinite(outputAmount)) {
continue;
}
// TODO(kimpers): [TKR-241] amounts are sometimes clipped in the router due to precision loss for number/f64
// we can work around it by scaling it and rounding up. However now we end up with a total amount of a couple base units too much
const rustInputAdjusted = BigNumber.min(
new BigNumber(routeInput).multipliedBy(scale).integerValue(BigNumber.ROUND_CEIL),
input,
);
const current = routeSamplesAndNativeOrders[routeSamplesAndNativeOrders.length - 1];
if (!isDexSample(current)) {
const nativeFill = nativeOrdersToFills(
side,
[current],
rustInputAdjusted,
opts.outputAmountPerEth,
opts.inputAmountPerEth,
fees,
)[0] as Fill | undefined;
// Note: If the order has an adjusted rate of less than or equal to 0 it will be skipped
// and nativeFill will be `undefined`
if (nativeFill) {
// NOTE: For Limit/RFQ orders we are done here. No need to scale output
adjustedFills.push({ ...nativeFill, sourcePathId: sourcePathId ?? hexUtils.random() });
}
continue;
}
// NOTE: For DexSamples only
let fill = createFill(current);
if (!fill) {
continue;
}
const routeSamples = routeSamplesAndNativeOrders as Array<DexSample<FillData>>;
// Descend to approach a closer fill for fillData which may not be consistent
// throughout the path (UniswapV3) and for a closer guesstimate at
// gas used
assert.assert(routeSamples.length >= 1, 'Found no sample to use for source');
for (let k = routeSamples.length - 1; k >= 0; k--) {
if (k === 0) {
fill = createFill(routeSamples[0]) ?? fill;
}
if (rustInputAdjusted.isGreaterThan(routeSamples[k].input)) {
const left = routeSamples[k];
const right = routeSamples[k + 1];
if (left && right) {
fill =
createFill({
...right, // default to the greater (for gas used)
input: rustInputAdjusted,
output: new BigNumber(outputAmount),
}) ?? fill;
} else {
assert.assert(Boolean(left || right), 'No valid sample to use');
fill = createFill(left || right) ?? fill;
}
break;
}
}
// TODO(kimpers): remove once we have solved the rounding/precision loss issues in the Rust router
const maxSampledOutput = BigNumber.max(...routeSamples.map(s => s.output));
// Scale output by scale factor but never go above the largest sample (unknown liquidity) or below 1 base unit (unfillable)
const scaleOutput = (output: BigNumber) => {
// Don't try to scale 0 output as it will be clamped to 1
if (output.eq(ZERO_AMOUNT)) {
return output;
}
const scaled = output
.times(scale)
.decimalPlaces(0, side === MarketOperation.Sell ? BigNumber.ROUND_FLOOR : BigNumber.ROUND_CEIL);
return BigNumber.max(BigNumber.min(scaled, maxSampledOutput), 1);
};
adjustedFills.push({
...fill,
input: rustInputAdjusted,
output: scaleOutput(fill.output),
adjustedOutput: scaleOutput(fill.adjustedOutput),
index: 0,
parent: undefined,
sourcePathId: sourcePathId ?? hexUtils.random(),
});
}
if (adjustedFills.length === 0) {
return undefined;
}
const pathFromRustInputs = Path.create(side, adjustedFills, input, opts);
return pathFromRustInputs;
}
export function findOptimalRustPathFromSamples(
side: MarketOperation,
samples: DexSample[][],
nativeOrders: NativeOrderWithFillableAmounts[],
input: BigNumber,
opts: PathPenaltyOpts,
fees: FeeSchedule,
chainId: ChainId,
neonRouterNumSamples: number,
samplerMetrics?: SamplerMetrics,
): Path | undefined {
const beforeAllTimeMs = performance.now();
let beforeTimeMs = performance.now();
const allSourcesPath = findRoutesAndCreateOptimalPath(
side,
samples,
nativeOrders,
input,
opts,
fees,
neonRouterNumSamples,
);
// tslint:disable-next-line: no-unused-expression
samplerMetrics &&
samplerMetrics.logRouterDetails({
router: 'neon-router',
type: 'all',
timingMs: performance.now() - beforeTimeMs,
});
if (!allSourcesPath) {
return undefined;
}
const vipSources = VIP_ERC20_BRIDGE_SOURCES_BY_CHAIN_ID[chainId];
// HACK(kimpers): The Rust router currently doesn't account for VIP sources correctly
// we need to try to route them in isolation and compare with the results all sources
if (vipSources.length > 0) {
beforeTimeMs = performance.now();
const vipSourcesSet = new Set(vipSources);
const vipSourcesSamples = samples.filter(s => s[0] && vipSourcesSet.has(s[0].source));
if (vipSourcesSamples.length > 0) {
const vipSourcesPath = findRoutesAndCreateOptimalPath(
side,
vipSourcesSamples,
[],
input,
opts,
fees,
neonRouterNumSamples,
);
// tslint:disable-next-line: no-unused-expression
samplerMetrics &&
samplerMetrics.logRouterDetails({
router: 'neon-router',
type: 'vip',
timingMs: performance.now() - beforeTimeMs,
});
if (vipSourcesPath?.isBetterThan(allSourcesPath)) {
return vipSourcesPath;
}
}
}
// tslint:disable-next-line: no-unused-expression
samplerMetrics &&
samplerMetrics.logRouterDetails({
router: 'neon-router',
type: 'total',
timingMs: performance.now() - beforeAllTimeMs,
});
return allSourcesPath;
}
/**
* Find the optimal mixture of fills that maximizes (for sells) or minimizes
* (for buys) output, while meeting the input requirement.
*/
export async function findOptimalPathAsync(
export async function findOptimalPathJSAsync(
side: MarketOperation,
fills: Fill[][],
targetInput: BigNumber,
runLimit: number = 2 ** 8,
samplerMetrics?: SamplerMetrics,
opts: PathPenaltyOpts = DEFAULT_PATH_PENALTY_OPTS,
): Promise<Path | undefined> {
const beforeTimeMs = performance.now();
// Sort fill arrays by descending adjusted completed rate.
// Remove any paths which cannot impact the optimal path
const sortedPaths = reducePaths(fillsToSortedPaths(fills, side, targetInput, opts), side);
@@ -34,7 +410,15 @@ export async function findOptimalPathAsync(
// Yield to event loop.
await Promise.resolve();
}
return optimalPath.isComplete() ? optimalPath : undefined;
const finalPath = optimalPath.isComplete() ? optimalPath : undefined;
// tslint:disable-next-line: no-unused-expression
samplerMetrics &&
samplerMetrics.logRouterDetails({
router: 'js',
type: 'total',
timingMs: performance.now() - beforeTimeMs,
});
return finalPath;
}
// Sort fill arrays by descending adjusted completed rate.

View File

@@ -14,7 +14,8 @@ import { BatchedOperation, ERC20BridgeSource, LiquidityProviderRegistry, TokenAd
*/
export function getSampleAmounts(maxFillAmount: BigNumber, numSamples: number, expBase: number = 1): BigNumber[] {
const distribution = [...Array<BigNumber>(numSamples)].map((_v, i) => new BigNumber(expBase).pow(i));
const stepSizes = distribution.map(d => d.div(BigNumber.sum(...distribution)));
const distributionSum = BigNumber.sum(...distribution);
const stepSizes = distribution.map(d => d.div(distributionSum));
const amounts = stepSizes.map((_s, i) => {
if (i === numSamples - 1) {
return maxFillAmount;
@@ -130,6 +131,37 @@ export class DexOrderSampler extends SamplerOperations {
BatchedOperationResult<T8>
]>;
// prettier-ignore
public async executeAsync<
T1, T2, T3, T4, T5, T6, T7, T8, T9
>(...ops: [T1, T2, T3, T4, T5, T6, T7, T8, T9]): Promise<[
BatchedOperationResult<T1>,
BatchedOperationResult<T2>,
BatchedOperationResult<T3>,
BatchedOperationResult<T4>,
BatchedOperationResult<T5>,
BatchedOperationResult<T6>,
BatchedOperationResult<T7>,
BatchedOperationResult<T8>,
BatchedOperationResult<T9>
]>;
// prettier-ignore
public async executeAsync<
T1, T2, T3, T4, T5, T6, T7, T8, T9, T10
>(...ops: [T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]): Promise<[
BatchedOperationResult<T1>,
BatchedOperationResult<T2>,
BatchedOperationResult<T3>,
BatchedOperationResult<T4>,
BatchedOperationResult<T5>,
BatchedOperationResult<T6>,
BatchedOperationResult<T7>,
BatchedOperationResult<T8>,
BatchedOperationResult<T9>,
BatchedOperationResult<T10>,
]>;
/**
* Run a series of operations from `DexOrderSampler.ops` in a single transaction.
*/

View File

@@ -0,0 +1,36 @@
import { BigNumber, logUtils, NULL_BYTES } from '@0x/utils';
import { ERC20BridgeSource, FillData, SourceQuoteOperation } from './types';
interface SamplerNoOperationCall {
callback: () => BigNumber[];
}
/**
* SamplerNoOperation can be used for sources where we already have all the necessary information
* required to perform the sample operations, without needing access to any on-chain data. Using a noop sample
* you can skip the eth_call, and just calculate the results directly in typescript land.
*/
export class SamplerNoOperation<TFillData extends FillData = FillData> implements SourceQuoteOperation<TFillData> {
public readonly source: ERC20BridgeSource;
public fillData: TFillData;
private readonly _callback: () => BigNumber[];
constructor(opts: { source: ERC20BridgeSource; fillData?: TFillData } & SamplerNoOperationCall) {
this.source = opts.source;
this.fillData = opts.fillData || ({} as TFillData); // tslint:disable-line:no-object-literal-type-assertion
this._callback = opts.callback;
}
// tslint:disable-next-line:prefer-function-over-method
public encodeCall(): string {
return NULL_BYTES;
}
public handleCallResults(_callResults: string): BigNumber[] {
return this._callback();
}
public handleRevert(_callResults: string): BigNumber[] {
logUtils.warn(`SamplerNoOperation: ${this.source} reverted`);
return [];
}
}

View File

@@ -3,9 +3,11 @@ import { LimitOrderFields } from '@0x/protocol-utils';
import { BigNumber, logUtils } from '@0x/utils';
import * as _ from 'lodash';
import { AaveV2Sampler } from '../../noop_samplers/AaveV2Sampler';
import { SamplerCallResult, SignedNativeOrder } from '../../types';
import { ERC20BridgeSamplerContract } from '../../wrappers';
import { AaveV2ReservesCache } from './aave_reserves_cache';
import { BancorService } from './bancor_service';
import {
getCurveLikeInfosForPair,
@@ -17,10 +19,14 @@ import {
isValidAddress,
uniswapV2LikeRouterAddress,
} from './bridge_source_utils';
import { CompoundCTokenCache } from './compound_ctoken_cache';
import {
AAVE_V2_SUBGRAPH_URL_BY_CHAIN_ID,
BALANCER_V2_VAULT_ADDRESS_BY_CHAIN,
BANCOR_REGISTRY_BY_CHAIN_ID,
CLIPPER_INFO_BY_CHAIN,
BEETHOVEN_X_SUBGRAPH_URL_BY_CHAIN,
BEETHOVEN_X_VAULT_ADDRESS_BY_CHAIN,
COMPOUND_API_URL_BY_CHAIN_ID,
DODOV1_CONFIG_BY_CHAIN_ID,
DODOV2_FACTORIES_BY_CHAIN_ID,
KYBER_CONFIG_BY_CHAIN_ID,
@@ -44,13 +50,17 @@ import { getLiquidityProvidersForPair } from './liquidity_provider_utils';
import { getIntermediateTokens } from './multihop_utils';
import { BalancerPoolsCache, BalancerV2PoolsCache, CreamPoolsCache, PoolsCache } from './pools_cache';
import { SamplerContractOperation } from './sampler_contract_operation';
import { SamplerNoOperation } from './sampler_no_operation';
import { SourceFilters } from './source_filters';
import {
AaveV2FillData,
AaveV2Info,
BalancerFillData,
BalancerV2FillData,
BalancerV2PoolInfo,
BancorFillData,
BatchedOperation,
CompoundFillData,
CurveFillData,
CurveInfo,
DexSample,
@@ -98,6 +108,8 @@ export const BATCH_SOURCE_FILTERS = SourceFilters.all().exclude([ERC20BridgeSour
export class SamplerOperations {
public readonly liquidityProviderRegistry: LiquidityProviderRegistry;
public readonly poolsCaches: { [key in SourcesWithPoolsCache]: PoolsCache };
public readonly aaveReservesCache: AaveV2ReservesCache | undefined;
public readonly compoundCTokenCache: CompoundCTokenCache | undefined;
protected _bancorService?: BancorService;
public static constant<T>(result: T): BatchedOperation<T> {
return {
@@ -123,9 +135,26 @@ export class SamplerOperations {
? poolsCaches
: {
[ERC20BridgeSource.BalancerV2]: new BalancerV2PoolsCache(chainId),
[ERC20BridgeSource.Beethovenx]: new BalancerV2PoolsCache(
chainId,
BEETHOVEN_X_SUBGRAPH_URL_BY_CHAIN[chainId],
),
[ERC20BridgeSource.Balancer]: new BalancerPoolsCache(),
[ERC20BridgeSource.Cream]: new CreamPoolsCache(),
};
const aaveSubgraphUrl = AAVE_V2_SUBGRAPH_URL_BY_CHAIN_ID[chainId];
if (aaveSubgraphUrl) {
this.aaveReservesCache = new AaveV2ReservesCache(aaveSubgraphUrl);
}
const compoundApiUrl = COMPOUND_API_URL_BY_CHAIN_ID[chainId];
if (compoundApiUrl) {
this.compoundCTokenCache = new CompoundCTokenCache(
compoundApiUrl,
NATIVE_FEE_TOKEN_BY_CHAIN_ID[this.chainId],
);
}
// Initialize the Bancor service, fetching paths in the background
bancorServiceFn()
.then(service => (this._bancorService = service))
@@ -153,6 +182,30 @@ export class SamplerOperations {
};
}
public getGasLeft(): BatchedOperation<BigNumber> {
return {
encodeCall: () => this._samplerContract.getGasLeft().getABIEncodedTransactionData(),
handleCallResults: (callResults: string) =>
this._samplerContract.getABIDecodedReturnData<BigNumber>('getGasLeft', callResults),
handleRevert: () => {
/* should never happen */
throw new Error('Invalid result for getGasLeft');
},
};
}
public getBlockNumber(): BatchedOperation<BigNumber> {
return {
encodeCall: () => this._samplerContract.getBlockNumber().getABIEncodedTransactionData(),
handleCallResults: (callResults: string) =>
this._samplerContract.getABIDecodedReturnData<BigNumber>('getBlockNumber', callResults),
handleRevert: () => {
/* should never happen */
throw new Error('Invalid result for getBlockNumber');
},
};
}
public getLimitOrderFillableTakerAmounts(
orders: SignedNativeOrder[],
exchangeAddress: string,
@@ -1070,6 +1123,64 @@ export class SamplerOperations {
});
}
// tslint:disable-next-line:prefer-function-over-method
public getAaveV2SellQuotes(
aaveInfo: AaveV2Info,
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): SourceQuoteOperation<AaveV2FillData> {
return new SamplerNoOperation({
source: ERC20BridgeSource.AaveV2,
fillData: { ...aaveInfo, takerToken },
callback: () => AaveV2Sampler.sampleSellsFromAaveV2(aaveInfo, takerToken, makerToken, takerFillAmounts),
});
}
// tslint:disable-next-line:prefer-function-over-method
public getAaveV2BuyQuotes(
aaveInfo: AaveV2Info,
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): SourceQuoteOperation<AaveV2FillData> {
return new SamplerNoOperation({
source: ERC20BridgeSource.AaveV2,
fillData: { ...aaveInfo, takerToken },
callback: () => AaveV2Sampler.sampleBuysFromAaveV2(aaveInfo, takerToken, makerToken, makerFillAmounts),
});
}
public getCompoundSellQuotes(
cToken: string,
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): SourceQuoteOperation<CompoundFillData> {
return new SamplerContractOperation({
source: ERC20BridgeSource.Compound,
fillData: { cToken, takerToken, makerToken },
contract: this._samplerContract,
function: this._samplerContract.sampleSellsFromCompound,
params: [cToken, takerToken, makerToken, takerFillAmounts],
});
}
public getCompoundBuyQuotes(
cToken: string,
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): SourceQuoteOperation<CompoundFillData> {
return new SamplerContractOperation({
source: ERC20BridgeSource.Compound,
fillData: { cToken, takerToken, makerToken },
contract: this._samplerContract,
function: this._samplerContract.sampleBuysFromCompound,
params: [cToken, takerToken, makerToken, makerFillAmounts],
});
}
public getMedianSellRate(
sources: ERC20BridgeSource[],
makerToken: string,
@@ -1198,6 +1309,10 @@ export class SamplerOperations {
case ERC20BridgeSource.JetSwap:
case ERC20BridgeSource.Pangolin:
case ERC20BridgeSource.TraderJoe:
case ERC20BridgeSource.UbeSwap:
case ERC20BridgeSource.SpiritSwap:
case ERC20BridgeSource.SpookySwap:
case ERC20BridgeSource.MorpheusSwap:
const uniLikeRouter = uniswapV2LikeRouterAddress(this.chainId, source);
if (!isValidAddress(uniLikeRouter)) {
return [];
@@ -1227,6 +1342,7 @@ export class SamplerOperations {
case ERC20BridgeSource.Swerve:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
case ERC20BridgeSource.Ellipsis:
case ERC20BridgeSource.Saddle:
@@ -1299,13 +1415,14 @@ export class SamplerOperations {
),
);
case ERC20BridgeSource.BalancerV2:
case ERC20BridgeSource.Beethovenx:
const poolIds =
this.poolsCaches[ERC20BridgeSource.BalancerV2].getCachedPoolAddressesForPair(
takerToken,
makerToken,
) || [];
this.poolsCaches[source].getCachedPoolAddressesForPair(takerToken, makerToken) || [];
const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId];
const vault =
source === ERC20BridgeSource.BalancerV2
? BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId]
: BEETHOVEN_X_VAULT_ADDRESS_BY_CHAIN[this.chainId];
if (vault === NULL_ADDRESS) {
return [];
}
@@ -1315,10 +1432,9 @@ export class SamplerOperations {
makerToken,
takerToken,
takerFillAmounts,
ERC20BridgeSource.BalancerV2,
source,
),
);
case ERC20BridgeSource.Cream:
return (
this.poolsCaches[ERC20BridgeSource.Cream].getCachedPoolAddressesForPair(
@@ -1416,32 +1532,38 @@ export class SamplerOperations {
return this.getLidoSellQuotes(lidoInfo, makerToken, takerToken, takerFillAmounts);
}
case ERC20BridgeSource.Clipper:
const { poolAddress: clipperPoolAddress, tokens: clipperTokens } = CLIPPER_INFO_BY_CHAIN[
this.chainId
];
if (
clipperPoolAddress === NULL_ADDRESS ||
!clipperTokens.includes(makerToken) ||
!clipperTokens.includes(takerToken)
) {
case ERC20BridgeSource.AaveV2: {
if (!this.aaveReservesCache) {
return [];
}
// Clipper requires WETH to be represented as address(0)
const adjustedMakerToken =
makerToken === NATIVE_FEE_TOKEN_BY_CHAIN_ID[this.chainId] ? NULL_ADDRESS : makerToken;
const adjustedTakerToken =
takerToken === NATIVE_FEE_TOKEN_BY_CHAIN_ID[this.chainId] ? NULL_ADDRESS : takerToken;
// Supports the PLP interface
return this.getLiquidityProviderSellQuotes(
clipperPoolAddress,
adjustedMakerToken,
adjustedTakerToken,
const reserve = this.aaveReservesCache.get(takerToken, makerToken);
if (!reserve) {
return [];
}
const info: AaveV2Info = {
lendingPool: reserve.pool.lendingPool,
aToken: reserve.aToken.id,
underlyingToken: reserve.underlyingAsset,
};
return this.getAaveV2SellQuotes(info, makerToken, takerToken, takerFillAmounts);
}
case ERC20BridgeSource.Compound: {
if (!this.compoundCTokenCache) {
return [];
}
const cToken = this.compoundCTokenCache.get(takerToken, makerToken);
if (!cToken) {
return [];
}
return this.getCompoundSellQuotes(
cToken.tokenAddress,
makerToken,
takerToken,
takerFillAmounts,
// tslint:disable-next-line: custom-no-magic-numbers
0, // Not used for Clipper
ERC20BridgeSource.Clipper,
);
}
default:
throw new Error(`Unsupported sell sample source: ${source}`);
}
@@ -1493,6 +1615,10 @@ export class SamplerOperations {
case ERC20BridgeSource.JetSwap:
case ERC20BridgeSource.Pangolin:
case ERC20BridgeSource.TraderJoe:
case ERC20BridgeSource.UbeSwap:
case ERC20BridgeSource.SpiritSwap:
case ERC20BridgeSource.SpookySwap:
case ERC20BridgeSource.MorpheusSwap:
const uniLikeRouter = uniswapV2LikeRouterAddress(this.chainId, source);
if (!isValidAddress(uniLikeRouter)) {
return [];
@@ -1522,6 +1648,7 @@ export class SamplerOperations {
case ERC20BridgeSource.Swerve:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
case ERC20BridgeSource.Ellipsis:
case ERC20BridgeSource.Saddle:
@@ -1594,13 +1721,14 @@ export class SamplerOperations {
),
);
case ERC20BridgeSource.BalancerV2:
case ERC20BridgeSource.Beethovenx:
const poolIds =
this.poolsCaches[ERC20BridgeSource.BalancerV2].getCachedPoolAddressesForPair(
takerToken,
makerToken,
) || [];
this.poolsCaches[source].getCachedPoolAddressesForPair(takerToken, makerToken) || [];
const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId];
const vault =
source === ERC20BridgeSource.BalancerV2
? BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId]
: BEETHOVEN_X_VAULT_ADDRESS_BY_CHAIN[this.chainId];
if (vault === NULL_ADDRESS) {
return [];
}
@@ -1610,7 +1738,7 @@ export class SamplerOperations {
makerToken,
takerToken,
makerFillAmounts,
ERC20BridgeSource.BalancerV2,
source,
),
);
case ERC20BridgeSource.Cream:
@@ -1706,32 +1834,32 @@ export class SamplerOperations {
return this.getLidoBuyQuotes(lidoInfo, makerToken, takerToken, makerFillAmounts);
}
case ERC20BridgeSource.Clipper:
const { poolAddress: clipperPoolAddress, tokens: clipperTokens } = CLIPPER_INFO_BY_CHAIN[
this.chainId
];
if (
clipperPoolAddress === NULL_ADDRESS ||
!clipperTokens.includes(makerToken) ||
!clipperTokens.includes(takerToken)
) {
case ERC20BridgeSource.AaveV2: {
if (!this.aaveReservesCache) {
return [];
}
// Clipper requires WETH to be represented as address(0)
const adjustedMakerToken =
makerToken === NATIVE_FEE_TOKEN_BY_CHAIN_ID[this.chainId] ? NULL_ADDRESS : makerToken;
const adjustedTakerToken =
takerToken === NATIVE_FEE_TOKEN_BY_CHAIN_ID[this.chainId] ? NULL_ADDRESS : takerToken;
// Supports the PLP interface
return this.getLiquidityProviderBuyQuotes(
clipperPoolAddress,
adjustedMakerToken,
adjustedTakerToken,
makerFillAmounts,
// tslint:disable-next-line: custom-no-magic-numbers
0, // Not used for Clipper
ERC20BridgeSource.Clipper,
);
const reserve = this.aaveReservesCache.get(takerToken, makerToken);
if (!reserve) {
return [];
}
const info: AaveV2Info = {
lendingPool: reserve.pool.lendingPool,
aToken: reserve.aToken.id,
underlyingToken: reserve.underlyingAsset,
};
return this.getAaveV2BuyQuotes(info, makerToken, takerToken, makerFillAmounts);
}
case ERC20BridgeSource.Compound: {
if (!this.compoundCTokenCache) {
return [];
}
const cToken = this.compoundCTokenCache.get(takerToken, makerToken);
if (!cToken) {
return [];
}
return this.getCompoundBuyQuotes(cToken.tokenAddress, makerToken, takerToken, makerFillAmounts);
}
default:
throw new Error(`Unsupported buy sample source: ${source}`);
}

View File

@@ -3,13 +3,12 @@ import {
FillQuoteTransformerOrderType,
FillQuoteTransformerRfqOrderInfo,
} from '@0x/protocol-utils';
import { V4RFQIndicativeQuote } from '@0x/quote-server';
import { MarketOperation } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { NativeOrderWithFillableAmounts, RfqFirmQuoteValidator, RfqRequestOpts } from '../../types';
import { QuoteRequestor } from '../../utils/quote_requestor';
import { PriceComparisonsReport, QuoteReport } from '../quote_report_generator';
import { QuoteRequestor, V4RFQIndicativeQuoteMM } from '../../utils/quote_requestor';
import { ExtendedQuoteReportSources, PriceComparisonsReport, QuoteReport } from '../quote_report_generator';
import { CollapsedPath } from './path';
import { SourceFilters } from './source_filters';
@@ -69,7 +68,9 @@ export enum ERC20BridgeSource {
CurveV2 = 'Curve_V2',
Lido = 'Lido',
ShibaSwap = 'ShibaSwap',
Clipper = 'Clipper',
AaveV2 = 'Aave_V2',
Compound = 'Compound',
Synapse = 'Synapse',
// BSC only
PancakeSwap = 'PancakeSwap',
PancakeSwapV2 = 'PancakeSwap_V2',
@@ -94,8 +95,19 @@ export enum ERC20BridgeSource {
// Avalanche
Pangolin = 'Pangolin',
TraderJoe = 'TraderJoe',
// Celo only
UbeSwap = 'UbeSwap',
// Fantom
SpiritSwap = 'SpiritSwap',
SpookySwap = 'SpookySwap',
Beethovenx = 'Beethovenx',
MorpheusSwap = 'MorpheusSwap',
}
export type SourcesWithPoolsCache = ERC20BridgeSource.Balancer | ERC20BridgeSource.BalancerV2 | ERC20BridgeSource.Cream;
export type SourcesWithPoolsCache =
| ERC20BridgeSource.Balancer
| ERC20BridgeSource.BalancerV2
| ERC20BridgeSource.Beethovenx
| ERC20BridgeSource.Cream;
// tslint:disable: enum-naming
/**
@@ -104,11 +116,13 @@ export type SourcesWithPoolsCache = ERC20BridgeSource.Balancer | ERC20BridgeSour
export enum CurveFunctionSelectors {
None = '0x00000000',
exchange = '0x3df02124',
exchange_underlying = '0xa6417ed6',
exchange_underlying = '0xa6417ed6', // exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy)
get_dy_underlying = '0x07211ef7',
get_dx_underlying = '0x0e71d1b9',
get_dy = '0x5e0d443f',
get_dy = '0x5e0d443f', // get_dy(int128,int128,uint256)
get_dx = '0x67df02ca',
get_dy_uint256 = '0x556d6e9f', // get_dy(uint256,uint256,uint256)
exchange_underlying_uint256 = '0x65b2489b', // exchange_underlying(uint256,uint256,uint256,uint256)
// Curve V2
exchange_v2 = '0x5b41b908',
exchange_underlying_v2 = '0x65b2489b',
@@ -117,7 +131,7 @@ export enum CurveFunctionSelectors {
// Smoothy
swap_uint256 = '0x5673b02d', // swap(uint256,uint256,uint256,uint256)
get_swap_amount = '0x45cf2ef6', // getSwapAmount(uint256,uint256,uint256)
// Nerve BSC, Saddle Mainnet
// Nerve BSC, Saddle Mainnet, Synapse
swap = '0x91695586', // swap(uint8,uint8,uint256,uint256,uint256)
calculateSwap = '0xa95b089f', // calculateSwap(uint8,uint8,uint256)
}
@@ -161,6 +175,12 @@ export interface BalancerV2PoolInfo {
vault: string;
}
export interface AaveV2Info {
lendingPool: string;
aToken: string;
underlyingToken: string;
}
// Internal `fillData` field for `Fill` objects.
export interface FillData {}
@@ -268,6 +288,19 @@ export interface LidoFillData extends FillData {
takerToken: string;
}
export interface AaveV2FillData extends FillData {
lendingPool: string;
aToken: string;
underlyingToken: string;
takerToken: string;
}
export interface CompoundFillData extends FillData {
cToken: string;
takerToken: string;
makerToken: string;
}
/**
* Represents a node on a fill path.
*/
@@ -423,6 +456,10 @@ export interface GetMarketOrdersOpts {
* Default: 1.25.
*/
sampleDistributionBase: number;
/**
* Number of samples to use when creating fill curves with neon-router
*/
neonRouterNumSamples: number;
/**
* Fees for each liquidity source, expressed in gas.
*/
@@ -455,6 +492,42 @@ export interface GetMarketOrdersOpts {
* hopping to. E.g DAI->USDC via an adjacent token WETH
*/
tokenAdjacencyGraph: TokenAdjacencyGraph;
/**
* Gas price to use for quote
*/
gasPrice: BigNumber;
/**
* Sampler metrics for recording data on the sampler service and operations
*/
samplerMetrics?: SamplerMetrics;
}
export interface SamplerMetrics {
/**
* Logs the gas information performed during a sampler call.
*
* @param data.gasBefore The gas remaining measured before any operations have been performed
* @param data.gasAfter The gas remaining measured after all operations have been performed
*/
logGasDetails(data: { gasBefore: BigNumber; gasAfter: BigNumber }): void;
/**
* Logs the block number
*
* @param blockNumber block number of the sampler call
*/
logBlockNumber(blockNumber: BigNumber): void;
/**
* Logs the routing timings
*
* @param data.router The router type (neon-router or js)
* @param data.type The type of timing being recorded (e.g total timing, all sources timing or vip timing)
* @param data.timingMs The timing in milliseconds
*/
logRouterDetails(data: { router: 'neon-router' | 'js'; type: 'all' | 'vip' | 'total'; timingMs: number }): void;
}
/**
@@ -484,6 +557,7 @@ export interface OptimizerResult {
export interface OptimizerResultWithReport extends OptimizerResult {
quoteReport?: QuoteReport;
extendedQuoteReportSources?: ExtendedQuoteReportSources;
priceComparisonsReport?: PriceComparisonsReport;
}
@@ -512,7 +586,7 @@ export interface MarketSideLiquidity {
export interface RawQuotes {
nativeOrders: NativeOrderWithFillableAmounts[];
rfqtIndicativeQuotes: V4RFQIndicativeQuote[];
rfqtIndicativeQuotes: V4RFQIndicativeQuoteMM[];
twoHopQuotes: Array<DexSample<MultiHopFillData>>;
dexQuotes: Array<Array<DexSample<FillData>>>;
}
@@ -534,10 +608,13 @@ export interface GenerateOptimizedOrdersOpts {
bridgeSlippage?: number;
maxFallbackSlippage?: number;
excludedSources?: ERC20BridgeSource[];
feeSchedule?: FeeSchedule;
feeSchedule: FeeSchedule;
exchangeProxyOverhead?: ExchangeProxyOverhead;
allowFallback?: boolean;
shouldBatchBridgeOrders?: boolean;
gasPrice: BigNumber;
neonRouterNumSamples: number;
samplerMetrics?: SamplerMetrics;
}
export interface ComparisonPrice {

View File

@@ -14,8 +14,9 @@ import {
NativeFillData,
NativeLimitOrderFillData,
NativeRfqOrderFillData,
RawQuotes,
} from './market_operation_utils/types';
import { QuoteRequestor } from './quote_requestor';
import { QuoteRequestor, V4RFQIndicativeQuoteMM } from './quote_requestor';
export interface QuoteReportEntryBase {
liquiditySource: ERC20BridgeSource;
@@ -36,30 +37,77 @@ export interface NativeLimitOrderQuoteReportEntry extends QuoteReportEntryBase {
liquiditySource: ERC20BridgeSource.Native;
fillData: NativeFillData;
fillableTakerAmount: BigNumber;
isRfqt: false;
isRFQ: false;
}
export interface NativeRfqOrderQuoteReportEntry extends QuoteReportEntryBase {
liquiditySource: ERC20BridgeSource.Native;
fillData: NativeFillData;
fillableTakerAmount: BigNumber;
isRfqt: true;
isRFQ: true;
nativeOrder: RfqOrderFields;
makerUri: string;
comparisonPrice?: number;
}
export interface IndicativeRfqOrderQuoteReportEntry extends QuoteReportEntryBase {
liquiditySource: ERC20BridgeSource.Native;
fillableTakerAmount: BigNumber;
isRFQ: true;
makerUri?: string;
comparisonPrice?: number;
}
export type QuoteReportEntry =
| BridgeQuoteReportEntry
| MultiHopQuoteReportEntry
| NativeLimitOrderQuoteReportEntry
| NativeRfqOrderQuoteReportEntry;
export type ExtendedQuoteReportEntry =
| BridgeQuoteReportEntry
| MultiHopQuoteReportEntry
| NativeLimitOrderQuoteReportEntry
| NativeRfqOrderQuoteReportEntry
| IndicativeRfqOrderQuoteReportEntry;
export type ExtendedQuoteReportIndexedEntry = ExtendedQuoteReportEntry & {
quoteEntryIndex: number;
isDelivered: boolean;
};
export type ExtendedQuoteReportIndexedEntryOutbound = Omit<ExtendedQuoteReportIndexedEntry, 'fillData'> & {
fillData?: string;
};
export interface QuoteReport {
sourcesConsidered: QuoteReportEntry[];
sourcesDelivered: QuoteReportEntry[];
}
export interface ExtendedQuoteReportSources {
sourcesConsidered: ExtendedQuoteReportIndexedEntry[];
sourcesDelivered: ExtendedQuoteReportIndexedEntry[] | undefined;
}
export interface ExtendedQuoteReport {
quoteId?: string;
taker?: string;
timestamp: number;
firmQuoteReport: boolean;
submissionBy: 'taker' | 'metaTxn' | 'rfqm';
buyAmount?: string;
sellAmount?: string;
buyTokenAddress: string;
sellTokenAddress: string;
integratorId?: string;
slippageBips?: number;
zeroExTransactionHash?: string;
decodedUniqueId?: string;
sourcesConsidered: ExtendedQuoteReportIndexedEntryOutbound[];
sourcesDelivered: ExtendedQuoteReportIndexedEntryOutbound[] | undefined;
}
export interface PriceComparisonsReport {
dexSources: BridgeQuoteReportEntry[];
multiHopSources: MultiHopQuoteReportEntry[];
@@ -80,7 +128,7 @@ export function generateQuoteReport(
const nativeOrderSourcesConsidered = nativeOrders.map(order =>
nativeOrderToReportEntry(order.type, order as any, order.fillableTakerAmount, comparisonPrice, quoteRequestor),
);
const sourcesConsidered = [...nativeOrderSourcesConsidered.filter(order => order.isRfqt)];
const sourcesConsidered = [...nativeOrderSourcesConsidered.filter(order => order.isRFQ)];
let sourcesDelivered;
if (Array.isArray(liquidityDelivered)) {
@@ -116,6 +164,105 @@ export function generateQuoteReport(
};
}
/**
* Generates a report of sources considered while computing the optimized
* swap quote, the sources ultimately included in the computed quote. This
* extende version incudes all considered quotes, not only native liquidity.
*/
export function generateExtendedQuoteReportSources(
marketOperation: MarketOperation,
quotes: RawQuotes,
liquidityDelivered: ReadonlyArray<CollapsedFill> | DexSample<MultiHopFillData>,
amount: BigNumber,
comparisonPrice?: BigNumber | undefined,
quoteRequestor?: QuoteRequestor,
): ExtendedQuoteReportSources {
const sourcesConsidered: ExtendedQuoteReportEntry[] = [];
// NativeOrders
sourcesConsidered.push(
...quotes.nativeOrders.map(order =>
nativeOrderToReportEntry(
order.type,
order as any,
order.fillableTakerAmount,
comparisonPrice,
quoteRequestor,
),
),
);
// IndicativeQuotes
sourcesConsidered.push(
...quotes.rfqtIndicativeQuotes.map(order => indicativeQuoteToReportEntry(order, comparisonPrice)),
);
// MultiHop
sourcesConsidered.push(...quotes.twoHopQuotes.map(quote => multiHopSampleToReportSource(quote, marketOperation)));
// Dex Quotes
sourcesConsidered.push(
..._.flatten(
quotes.dexQuotes.map(dex =>
dex
.filter(quote => isDexSampleForTotalAmount(quote, marketOperation, amount))
.map(quote => dexSampleToReportSource(quote, marketOperation)),
),
),
);
const sourcesConsideredIndexed = sourcesConsidered.map(
(quote, index): ExtendedQuoteReportIndexedEntry => {
return {
...quote,
quoteEntryIndex: index,
isDelivered: false,
};
},
);
let sourcesDelivered;
if (Array.isArray(liquidityDelivered)) {
// create easy way to look up fillable amounts
const nativeOrderSignaturesToFillableAmounts = _.fromPairs(
quotes.nativeOrders.map(o => {
return [_nativeDataToId(o), o.fillableTakerAmount];
}),
);
// map sources delivered
sourcesDelivered = liquidityDelivered.map(collapsedFill => {
if (_isNativeOrderFromCollapsedFill(collapsedFill)) {
return nativeOrderToReportEntry(
collapsedFill.type,
collapsedFill.fillData,
nativeOrderSignaturesToFillableAmounts[_nativeDataToId(collapsedFill.fillData)],
comparisonPrice,
quoteRequestor,
);
} else {
return dexSampleToReportSource(collapsedFill, marketOperation);
}
});
} else {
sourcesDelivered = [
// tslint:disable-next-line: no-unnecessary-type-assertion
multiHopSampleToReportSource(liquidityDelivered as DexSample<MultiHopFillData>, marketOperation),
];
}
const sourcesDeliveredIndexed = sourcesDelivered.map(
(quote, index): ExtendedQuoteReportIndexedEntry => {
return {
...quote,
quoteEntryIndex: index,
isDelivered: false,
};
},
);
return {
sourcesConsidered: sourcesConsideredIndexed,
sourcesDelivered: sourcesDeliveredIndexed,
};
}
function _nativeDataToId(data: { signature: Signature }): string {
const { v, r, s } = data.signature;
return `${v}${r}${s}`;
@@ -153,6 +300,22 @@ export function dexSampleToReportSource(ds: DexSample, marketOperation: MarketOp
}
}
/**
* Checks if a DEX sample is the one that represents the whole amount requested by taker
* NOTE: this is used for the QuoteReport to filter samples
*/
function isDexSampleForTotalAmount(ds: DexSample, marketOperation: MarketOperation, amount: BigNumber): boolean {
// input and output map to different values
// based on the market operation
if (marketOperation === MarketOperation.Buy) {
return ds.input === amount;
} else if (marketOperation === MarketOperation.Sell) {
return ds.output === amount;
} else {
throw new Error(`Unexpected marketOperation ${marketOperation}`);
}
}
/**
* Generates a report sample for a MultiHop source
* NOTE: this is used for the QuoteReport and quote price comparison data
@@ -208,17 +371,17 @@ export function nativeOrderToReportEntry(
};
// if we find this is an rfqt order, label it as such and associate makerUri
const isRfqt = type === FillQuoteTransformerOrderType.Rfq;
const isRFQ = type === FillQuoteTransformerOrderType.Rfq;
const rfqtMakerUri =
isRfqt && quoteRequestor ? quoteRequestor.getMakerUriForSignature(fillData.signature) : undefined;
isRFQ && quoteRequestor ? quoteRequestor.getMakerUriForSignature(fillData.signature) : undefined;
if (isRfqt) {
if (isRFQ) {
const nativeOrder = fillData.order as RfqOrderFields;
// tslint:disable-next-line: no-object-literal-type-assertion
return {
liquiditySource: ERC20BridgeSource.Native,
...nativeOrderBase,
isRfqt: true,
isRFQ: true,
makerUri: rfqtMakerUri || '',
...(comparisonPrice ? { comparisonPrice: comparisonPrice.toNumber() } : {}),
nativeOrder,
@@ -229,8 +392,49 @@ export function nativeOrderToReportEntry(
return {
liquiditySource: ERC20BridgeSource.Native,
...nativeOrderBase,
isRfqt: false,
isRFQ: false,
fillData,
};
}
}
/**
* Generates a report entry for an indicative RFQ Quote
* NOTE: this is used for the QuoteReport and quote price comparison data
*/
export function indicativeQuoteToReportEntry(
order: V4RFQIndicativeQuoteMM,
comparisonPrice?: BigNumber | undefined,
): IndicativeRfqOrderQuoteReportEntry {
const nativeOrderBase = {
makerAmount: order.makerAmount,
takerAmount: order.takerAmount,
fillableTakerAmount: order.takerAmount,
};
// tslint:disable-next-line: no-object-literal-type-assertion
return {
liquiditySource: ERC20BridgeSource.Native,
...nativeOrderBase,
isRFQ: true,
makerUri: order.makerUri,
fillData: {},
...(comparisonPrice ? { comparisonPrice: comparisonPrice.toNumber() } : {}),
};
}
/**
* For the extended quote report, we output the filldata as JSON
*/
export function jsonifyFillData(source: ExtendedQuoteReportIndexedEntry): ExtendedQuoteReportIndexedEntryOutbound {
return {
...source,
fillData: JSON.stringify(source.fillData, (key: string, value: any) => {
if (key === '_samplerContract') {
return {};
} else {
return value;
}
}),
};
}

View File

@@ -39,6 +39,10 @@ interface RfqQuote<T> {
makerUri: string;
}
export interface V4RFQIndicativeQuoteMM extends V4RFQIndicativeQuote {
makerUri: string;
}
export interface MetricsProxy {
/**
* Increments a counter that is tracking valid Firm Quotes that are dropped due to low expiration.
@@ -343,7 +347,7 @@ export class QuoteRequestor {
marketOperation: MarketOperation,
comparisonPrice: BigNumber | undefined,
options: RfqmRequestOptions,
): Promise<V4RFQIndicativeQuote[]> {
): Promise<V4RFQIndicativeQuoteMM[]> {
const _opts: RfqRequestOpts = {
...constants.DEFAULT_RFQT_REQUEST_OPTS,
...options,
@@ -367,7 +371,7 @@ export class QuoteRequestor {
marketOperation: MarketOperation,
comparisonPrice: BigNumber | undefined,
options: RfqRequestOpts,
): Promise<V4RFQIndicativeQuote[]> {
): Promise<V4RFQIndicativeQuoteMM[]> {
const _opts: RfqRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
// Originally a takerAddress was required for indicative quotes, but
// now we've eliminated that requirement. @0x/quote-server, however,
@@ -398,8 +402,8 @@ export class QuoteRequestor {
return this._orderSignatureToMakerUri[nativeDataToId({ signature })];
}
private _isValidRfqtIndicativeQuoteResponse(response: V4RFQIndicativeQuote): boolean {
const requiredKeys: Array<keyof V4RFQIndicativeQuote> = [
private _isValidRfqtIndicativeQuoteResponse(response: V4RFQIndicativeQuoteMM): boolean {
const requiredKeys: Array<keyof V4RFQIndicativeQuoteMM> = [
'makerAmount',
'takerAmount',
'makerToken',
@@ -545,7 +549,10 @@ export class QuoteRequestor {
},
});
rfqMakerBlacklist.logTimeoutOrLackThereof(typedMakerUrl.url, latencyMs >= timeoutMs);
return { response: response.data, makerUri: typedMakerUrl.url };
return {
response: { ...response.data, makerUri: typedMakerUrl.url },
makerUri: typedMakerUrl.url,
};
} else {
if (this._altRfqCreds === undefined) {
throw new Error(`don't have credentials for alt MM`);
@@ -694,7 +701,6 @@ export class QuoteRequestor {
} else {
const secondsRemaining = msRemainingUntilExpiration.div(ONE_SECOND_MS);
this._metrics?.measureExpirationForValidOrder(isLastLook, order.maker, secondsRemaining);
const takerAmount = new BigNumber(order.takerAmount);
const fillRatio = takerAmount.div(assetFillAmount);
if (fillRatio.lt(1) && fillRatio.gte(FILL_RATIO_WARNING_LEVEL)) {
@@ -744,9 +750,9 @@ export class QuoteRequestor {
comparisonPrice: BigNumber | undefined,
options: RfqRequestOpts,
assetOfferings: RfqMakerAssetOfferings,
): Promise<V4RFQIndicativeQuote[]> {
): Promise<V4RFQIndicativeQuoteMM[]> {
// fetch quotes
const rawQuotes = await this._getQuotesAsync<V4RFQIndicativeQuote>(
const rawQuotes = await this._getQuotesAsync<V4RFQIndicativeQuoteMM>(
makerToken,
takerToken,
assetFillAmount,
@@ -758,7 +764,7 @@ export class QuoteRequestor {
);
// validate
const validationFunction = (o: V4RFQIndicativeQuote) => this._isValidRfqtIndicativeQuoteResponse(o);
const validationFunction = (o: V4RFQIndicativeQuoteMM) => this._isValidRfqtIndicativeQuoteResponse(o);
const validQuotes = rawQuotes.filter(result => {
const order = result.response;
if (!validationFunction(order)) {

View File

@@ -10,6 +10,7 @@ import * as BalanceChecker from '../test/generated-artifacts/BalanceChecker.json
import * as BalancerSampler from '../test/generated-artifacts/BalancerSampler.json';
import * as BalancerV2Sampler from '../test/generated-artifacts/BalancerV2Sampler.json';
import * as BancorSampler from '../test/generated-artifacts/BancorSampler.json';
import * as CompoundSampler from '../test/generated-artifacts/CompoundSampler.json';
import * as CurveSampler from '../test/generated-artifacts/CurveSampler.json';
import * as DODOSampler from '../test/generated-artifacts/DODOSampler.json';
import * as DODOV2Sampler from '../test/generated-artifacts/DODOV2Sampler.json';
@@ -52,6 +53,7 @@ export const artifacts = {
BalancerSampler: BalancerSampler as ContractArtifact,
BalancerV2Sampler: BalancerV2Sampler as ContractArtifact,
BancorSampler: BancorSampler as ContractArtifact,
CompoundSampler: CompoundSampler as ContractArtifact,
CurveSampler: CurveSampler as ContractArtifact,
DODOSampler: DODOSampler as ContractArtifact,
DODOV2Sampler: DODOV2Sampler as ContractArtifact,

View File

@@ -125,6 +125,7 @@ describe('ExchangeProxySwapQuoteConsumer', () => {
gas: Math.floor(Math.random() * 8e6),
protocolFeeInWeiAmount: getRandomAmount(),
feeTakerTokenAmount: getRandomAmount(),
slippage: 0,
},
worstCaseQuoteInfo: {
makerAmount: makerTokenFillAmount,
@@ -133,6 +134,7 @@ describe('ExchangeProxySwapQuoteConsumer', () => {
gas: Math.floor(Math.random() * 8e6),
protocolFeeInWeiAmount: getRandomAmount(),
feeTakerTokenAmount: getRandomAmount(),
slippage: 0,
},
makerAmountPerEth: getRandomInteger(1, 1e9),
takerAmountPerEth: getRandomInteger(1, 1e9),
@@ -186,7 +188,7 @@ describe('ExchangeProxySwapQuoteConsumer', () => {
);
}
const transformERC20Encoder = AbiEncoder.createMethod('transformERC20Staging', [
const transformERC20Encoder = AbiEncoder.createMethod('transformERC20', [
{ type: 'address', name: 'inputToken' },
{ type: 'address', name: 'outputToken' },
{ type: 'uint256', name: 'inputTokenAmount' },

View File

@@ -23,6 +23,7 @@ import {
POSITIVE_INF,
SELL_SOURCE_FILTER_BY_CHAIN_ID,
SOURCE_FLAGS,
ZERO_AMOUNT,
} from '../src/utils/market_operation_utils/constants';
import { createFills } from '../src/utils/market_operation_utils/fills';
import { PoolsCache } from '../src/utils/market_operation_utils/pools_cache';
@@ -79,7 +80,7 @@ async function getMarketSellOrdersAsync(
utils: MarketOperationUtils,
nativeOrders: SignedNativeOrder[],
takerAmount: BigNumber,
opts?: Partial<GetMarketOrdersOpts>,
opts: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber },
): Promise<OptimizerResultWithReport> {
return utils.getOptimizerResultAsync(nativeOrders, takerAmount, MarketOperation.Sell, opts);
}
@@ -96,7 +97,7 @@ async function getMarketBuyOrdersAsync(
utils: MarketOperationUtils,
nativeOrders: SignedNativeOrder[],
makerAmount: BigNumber,
opts?: Partial<GetMarketOrdersOpts>,
opts: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber },
): Promise<OptimizerResultWithReport> {
return utils.getOptimizerResultAsync(nativeOrders, makerAmount, MarketOperation.Buy, opts);
}
@@ -159,7 +160,11 @@ describe('MarketOperationUtils tests', () => {
} else {
requestor
.setup(r => r.requestRfqtIndicativeQuotesAsync(...args))
.returns(async () => results.map(r => r.order))
.returns(async () =>
results.map(r => {
return { ...r.order, makerUri: 'https://foo.bar/' };
}),
)
.verifiable(verifiable);
}
return requestor;
@@ -423,6 +428,8 @@ describe('MarketOperationUtils tests', () => {
getTwoHopSellQuotes: (..._params: any[]) => [],
getTwoHopBuyQuotes: (..._params: any[]) => [],
isAddressContract: (..._params: any[]) => false,
getGasLeft: () => ZERO_AMOUNT,
getBlockNumber: () => ZERO_AMOUNT,
};
const MOCK_SAMPLER = ({
@@ -459,7 +466,7 @@ describe('MarketOperationUtils tests', () => {
FILL_AMOUNT,
_.times(NUM_SAMPLES, i => DEFAULT_RATES[ERC20BridgeSource.Native][i]),
);
const DEFAULT_OPTS: Partial<GetMarketOrdersOpts> = {
const DEFAULT_OPTS: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber } = {
numSamples: NUM_SAMPLES,
sampleDistributionBase: 1,
bridgeSlippage: 0,
@@ -468,6 +475,7 @@ describe('MarketOperationUtils tests', () => {
allowFallback: false,
gasSchedule: {},
feeSchedule: {},
gasPrice: new BigNumber(30e9),
};
beforeEach(() => {
@@ -1229,6 +1237,7 @@ describe('MarketOperationUtils tests', () => {
excludedSources: [],
numSamples: 4,
bridgeSlippage: 0,
gasPrice: new BigNumber(30e9),
},
);
const result = ordersAndReport.optimizedOrders;
@@ -1298,7 +1307,8 @@ describe('MarketOperationUtils tests', () => {
FILL_AMOUNT,
_.times(NUM_SAMPLES, () => DEFAULT_RATES[ERC20BridgeSource.Native][0]),
);
const DEFAULT_OPTS: Partial<GetMarketOrdersOpts> = {
const GAS_PRICE = new BigNumber(100e9); // 100 gwei
const DEFAULT_OPTS: Partial<GetMarketOrdersOpts> & { gasPrice: BigNumber } = {
numSamples: NUM_SAMPLES,
sampleDistributionBase: 1,
bridgeSlippage: 0,
@@ -1307,6 +1317,7 @@ describe('MarketOperationUtils tests', () => {
allowFallback: false,
gasSchedule: {},
feeSchedule: {},
gasPrice: GAS_PRICE,
};
beforeEach(() => {
@@ -1626,11 +1637,10 @@ describe('MarketOperationUtils tests', () => {
getMedianSellRate: createGetMedianSellRate(ETH_TO_TAKER_RATE),
});
const optimizer = new MarketOperationUtils(MOCK_SAMPLER, contractAddresses, ORDER_DOMAIN);
const gasPrice = 100e9; // 100 gwei
const exchangeProxyOverhead = (sourceFlags: bigint) =>
sourceFlags === SOURCE_FLAGS.LiquidityProvider
? constants.ZERO_AMOUNT
: new BigNumber(1.3e5).times(gasPrice);
: new BigNumber(1.3e5).times(GAS_PRICE);
const improvedOrdersResponse = await optimizer.getOptimizerResultAsync(
createOrdersFromSellRates(FILL_AMOUNT, rates[ERC20BridgeSource.Native]),
FILL_AMOUNT,

View File

@@ -155,7 +155,7 @@ describe('generateQuoteReport', async () => {
makerAmount: rfqtOrder1.order.makerAmount,
takerAmount: rfqtOrder1.order.takerAmount,
fillableTakerAmount: rfqtOrder1.fillableTakerAmount,
isRfqt: true,
isRFQ: true,
makerUri: 'https://rfqt1.provider.club',
nativeOrder: rfqtOrder1.order,
fillData: {
@@ -167,7 +167,7 @@ describe('generateQuoteReport', async () => {
makerAmount: rfqtOrder2.order.makerAmount,
takerAmount: rfqtOrder2.order.takerAmount,
fillableTakerAmount: rfqtOrder2.fillableTakerAmount,
isRfqt: true,
isRFQ: true,
makerUri: 'https://rfqt2.provider.club',
nativeOrder: rfqtOrder2.order,
fillData: {
@@ -179,7 +179,7 @@ describe('generateQuoteReport', async () => {
makerAmount: orderbookOrder2.order.makerAmount,
takerAmount: orderbookOrder2.order.takerAmount,
fillableTakerAmount: orderbookOrder2.fillableTakerAmount,
isRfqt: false,
isRFQ: false,
fillData: {
order: orderbookOrder2.order,
} as NativeLimitOrderFillData,
@@ -263,7 +263,7 @@ describe('generateQuoteReport', async () => {
makerAmount: orderbookOrder1.order.makerAmount,
takerAmount: orderbookOrder1.order.takerAmount,
fillableTakerAmount: orderbookOrder1.fillableTakerAmount,
isRfqt: false,
isRFQ: false,
fillData: {
order: orderbookOrder1.order,
} as NativeLimitOrderFillData,

View File

@@ -494,15 +494,18 @@ describe('QuoteRequestor', async () => {
expiry: makeThreeMinuteExpiry(),
};
const goodMMUri1 = 'https://1337.0.0.1';
const goodMMUri2 = 'https://37.0.0.1';
mockedRequests.push({
...mockedDefaults,
endpoint: 'https://1337.0.0.1',
endpoint: goodMMUri1,
responseData: successfulQuote1,
});
// [GOOD] Another Successful response
mockedRequests.push({
...mockedDefaults,
endpoint: 'https://37.0.0.1',
endpoint: goodMMUri2,
responseData: successfulQuote1,
});
@@ -532,6 +535,16 @@ describe('QuoteRequestor', async () => {
responseData: { ...successfulQuote1, takerToken: otherToken1 },
});
const assetOfferings: { [k: string]: [[string, string]] } = {
'https://420.0.0.1': [[makerToken, takerToken]],
'https://421.0.0.1': [[makerToken, takerToken]],
'https://422.0.0.1': [[makerToken, takerToken]],
'https://423.0.0.1': [[makerToken, takerToken]],
'https://424.0.0.1': [[makerToken, takerToken]],
};
assetOfferings[goodMMUri1] = [[makerToken, takerToken]];
assetOfferings[goodMMUri2] = [[makerToken, takerToken]];
return testHelpers.withMockedRfqQuotes(
mockedRequests,
[],
@@ -539,15 +552,7 @@ describe('QuoteRequestor', async () => {
async () => {
const qr = new QuoteRequestor(
{}, // No RFQ-T asset offerings
{
'https://1337.0.0.1': [[makerToken, takerToken]],
'https://37.0.0.1': [[makerToken, takerToken]],
'https://420.0.0.1': [[makerToken, takerToken]],
'https://421.0.0.1': [[makerToken, takerToken]],
'https://422.0.0.1': [[makerToken, takerToken]],
'https://423.0.0.1': [[makerToken, takerToken]],
'https://424.0.0.1': [[makerToken, takerToken]],
},
assetOfferings,
quoteRequestorHttpClient,
);
const resp = await qr.requestRfqmIndicativeQuotesAsync(
@@ -572,7 +577,12 @@ describe('QuoteRequestor', async () => {
},
},
);
expect(resp.sort()).to.eql([successfulQuote1, successfulQuote1].sort());
expect(resp.sort()).to.eql(
[
{ ...successfulQuote1, makerUri: goodMMUri1 },
{ ...successfulQuote1, makerUri: goodMMUri2 },
].sort(),
);
},
quoteRequestorHttpClient,
);
@@ -622,9 +632,12 @@ describe('QuoteRequestor', async () => {
expiry: makeThreeMinuteExpiry(),
};
const goodMMUri1 = 'https://1337.0.0.1';
const goodMMUri2 = 'https://37.0.0.1';
mockedRequests.push({
...mockedDefaults,
endpoint: 'https://1337.0.0.1',
endpoint: goodMMUri1,
responseData: successfulQuote1,
});
// Test out a bad response code, ensure it doesnt cause throw
@@ -655,28 +668,26 @@ describe('QuoteRequestor', async () => {
// Another Successful response
mockedRequests.push({
...mockedDefaults,
endpoint: 'https://37.0.0.1',
endpoint: goodMMUri2,
responseData: successfulQuote1,
});
const assetOfferings: { [k: string]: [[string, string]] } = {
'https://420.0.0.1': [[makerToken, takerToken]],
'https://421.0.0.1': [[makerToken, takerToken]],
'https://422.0.0.1': [[makerToken, takerToken]],
'https://423.0.0.1': [[makerToken, takerToken]],
'https://424.0.0.1': [[makerToken, takerToken]],
};
assetOfferings[goodMMUri1] = [[makerToken, takerToken]];
assetOfferings[goodMMUri2] = [[makerToken, takerToken]];
return testHelpers.withMockedRfqQuotes(
mockedRequests,
[],
RfqQuoteEndpoint.Indicative,
async () => {
const qr = new QuoteRequestor(
{
'https://1337.0.0.1': [[makerToken, takerToken]],
'https://420.0.0.1': [[makerToken, takerToken]],
'https://421.0.0.1': [[makerToken, takerToken]],
'https://422.0.0.1': [[makerToken, takerToken]],
'https://423.0.0.1': [[makerToken, takerToken]],
'https://424.0.0.1': [[makerToken, takerToken]],
'https://37.0.0.1': [[makerToken, takerToken]],
},
{},
quoteRequestorHttpClient,
);
const qr = new QuoteRequestor(assetOfferings, {}, quoteRequestorHttpClient);
const resp = await qr.requestRfqtIndicativeQuotesAsync(
makerToken,
takerToken,
@@ -693,7 +704,12 @@ describe('QuoteRequestor', async () => {
intentOnFilling: true,
},
);
expect(resp.sort()).to.eql([successfulQuote1, successfulQuote1].sort());
expect(resp.sort()).to.eql(
[
{ ...successfulQuote1, makerUri: goodMMUri1 },
{ ...successfulQuote1, makerUri: goodMMUri2 },
].sort(),
);
},
quoteRequestorHttpClient,
);
@@ -784,7 +800,7 @@ describe('QuoteRequestor', async () => {
makerEndpointMaxResponseTimeMs: maxTimeoutMs,
},
);
expect(resp.sort()).to.eql([successfulQuote1].sort()); // notice only one result, despite two requests made
expect(resp.sort()).to.eql([{ ...successfulQuote1, makerUri: 'https://1337.0.0.1' }].sort()); // notice only one result, despite two requests made
},
quoteRequestorHttpClient,
);
@@ -847,7 +863,7 @@ describe('QuoteRequestor', async () => {
intentOnFilling: true,
},
);
expect(resp.sort()).to.eql([successfulQuote1].sort());
expect(resp.sort()).to.eql([{ ...successfulQuote1, makerUri: 'https://1337.0.0.1' }].sort());
},
quoteRequestorHttpClient,
);

View File

@@ -24,6 +24,7 @@ export async function getFullyFillableSwapQuoteWithNoFeesAsync(
totalTakerAmount: takerAmount,
protocolFeeInWeiAmount: protocolFeePerOrder.times(orders.length),
gas: 200e3,
slippage: 0,
};
const breakdown = {

View File

@@ -8,6 +8,7 @@ export * from '../test/generated-wrappers/balance_checker';
export * from '../test/generated-wrappers/balancer_sampler';
export * from '../test/generated-wrappers/balancer_v2_sampler';
export * from '../test/generated-wrappers/bancor_sampler';
export * from '../test/generated-wrappers/compound_sampler';
export * from '../test/generated-wrappers/curve_sampler';
export * from '../test/generated-wrappers/d_o_d_o_sampler';
export * from '../test/generated-wrappers/d_o_d_o_v2_sampler';

View File

@@ -11,6 +11,7 @@
"test/generated-artifacts/BalancerSampler.json",
"test/generated-artifacts/BalancerV2Sampler.json",
"test/generated-artifacts/BancorSampler.json",
"test/generated-artifacts/CompoundSampler.json",
"test/generated-artifacts/CurveSampler.json",
"test/generated-artifacts/DODOSampler.json",
"test/generated-artifacts/DODOV2Sampler.json",

View File

@@ -1,4 +1,53 @@
[
{
"version": "6.11.0",
"changes": [
{
"note": "Add Optimism addresses",
"pr": 385
}
],
"timestamp": 1640364306
},
{
"version": "6.10.0",
"changes": [
{
"note": "Add Aave supported FQT addresses for Polygon, Avalanche",
"pr": 321
}
],
"timestamp": 1638390144
},
{
"version": "6.9.0",
"changes": [
{
"note": "Add Celo addresses",
"pr": 368
}
],
"timestamp": 1637102971
},
{
"timestamp": 1635903615,
"version": "6.8.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "6.8.0",
"changes": [
{
"note": "Fantom deployment",
"pr": 347
}
],
"timestamp": 1634668033
},
{
"version": "6.7.0",
"changes": [

View File

@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v6.11.0 - _December 24, 2021_
* Add Optimism addresses (#385)
## v6.10.0 - _December 1, 2021_
* Add Aave supported FQT addresses for Polygon, Avalanche (#321)
## v6.9.0 - _November 16, 2021_
* Add Celo addresses (#368)
## v6.8.1 - _November 3, 2021_
* Dependencies updated
## v6.8.0 - _October 19, 2021_
* Fantom deployment (#347)
## v6.7.0 - _September 1, 2021_
* Avalanche deployment (#312)

View File

@@ -244,11 +244,11 @@
"exchangeProxyLiquidityProviderSandbox": "0x0000000000000000000000000000000000000000",
"zrxTreasury": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0xc6b0d3c45a6b5092808196cb00df5c357d55e1d5",
"payTakerTransformer": "0x7209185959d7227fb77274e1e88151d7c4c368d3",
"affiliateFeeTransformer": "0x3f16ca81691dab9184cb4606c361d73c4fd2510a",
"fillQuoteTransformer": "0x99356167edba8fbdc36959e3f5d0c43d1ba9c6db",
"positiveSlippageFeeTransformer": "0x45b3a72221e571017c0f0ec42189e11d149d0ace"
"wethTransformer": "0x7209185959d7227fb77274e1e88151d7c4c368d3",
"payTakerTransformer": "0x3f16ca81691dab9184cb4606c361d73c4fd2510a",
"affiliateFeeTransformer": "0x99356167edba8fbdc36959e3f5d0c43d1ba9c6db",
"fillQuoteTransformer": "0x45b3a72221e571017c0f0ec42189e11d149d0ace",
"positiveSlippageFeeTransformer": "0xdd66c23e07b4d6925b6089b5fe6fc9e62941afe8"
}
},
"137": {
@@ -289,7 +289,7 @@
"wethTransformer": "0xe309d011cc6f189a3e8dcba85922715a019fed38",
"payTakerTransformer": "0x5ba7b9be86cda01cfbf56e0fb97184783be9dda1",
"affiliateFeeTransformer": "0xbed27284b42e5684e987169cf1da09c5d6c49fa8",
"fillQuoteTransformer": "0xf708d512b8a82e2862543a630403327174410baf",
"fillQuoteTransformer": "0xd3afdf4a8ea9183e76c9c2306cda03ea4afffea5",
"positiveSlippageFeeTransformer": "0x4cd8f1c0df4d40fcc1e073845d5f6f4ed5cc8dab"
}
},
@@ -373,8 +373,134 @@
"wethTransformer": "0x9b8b52391071d71cd4ad1e61d7f273268fa34c6c",
"payTakerTransformer": "0x898c6fde239d646c73f0a57e3570b6f86a3d62a3",
"affiliateFeeTransformer": "0x34617b855411e52fbc05899435f44cbd0503022c",
"fillQuoteTransformer": "0x8a5417dd7ffde61ec61e11b45797e16686e1d6b9",
"fillQuoteTransformer": "0xd421f50b3ae27f223aa35a04944236d257235412",
"positiveSlippageFeeTransformer": "0x470ba89da18a6db6e8a0567b3c9214b960861857"
}
},
"250": {
"erc20Proxy": "0x0000000000000000000000000000000000000000",
"erc721Proxy": "0x0000000000000000000000000000000000000000",
"zrxToken": "0x0000000000000000000000000000000000000000",
"etherToken": "0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83",
"exchangeV2": "0x0000000000000000000000000000000000000000",
"exchange": "0x0000000000000000000000000000000000000000",
"assetProxyOwner": "0x0000000000000000000000000000000000000000",
"zeroExGovernor": "0x0000000000000000000000000000000000000000",
"forwarder": "0x0000000000000000000000000000000000000000",
"coordinatorRegistry": "0x0000000000000000000000000000000000000000",
"coordinator": "0x0000000000000000000000000000000000000000",
"multiAssetProxy": "0x0000000000000000000000000000000000000000",
"staticCallProxy": "0x0000000000000000000000000000000000000000",
"erc1155Proxy": "0x0000000000000000000000000000000000000000",
"devUtils": "0x0000000000000000000000000000000000000000",
"zrxVault": "0x0000000000000000000000000000000000000000",
"staking": "0x0000000000000000000000000000000000000000",
"stakingProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeSampler": "0x0000000000000000000000000000000000000000",
"chaiBridge": "0x0000000000000000000000000000000000000000",
"dydxBridge": "0x0000000000000000000000000000000000000000",
"godsUnchainedValidator": "0x0000000000000000000000000000000000000000",
"broker": "0x0000000000000000000000000000000000000000",
"chainlinkStopLimit": "0x0000000000000000000000000000000000000000",
"maximumGasPrice": "0x0000000000000000000000000000000000000000",
"dexForwarderBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxyGovernor": "0xf760c5b88d970d6f97e64e264dac5a3767dafd74",
"exchangeProxy": "0xdef189deaef76e379df891899eb5a00a94cbc250",
"exchangeProxyTransformerDeployer": "0x47f01db18a38261e4cb153bae6db7d3743acb33c",
"exchangeProxyFlashWallet": "0xb4d961671cadfed687e040b076eee29840c142e5",
"exchangeProxyLiquidityProviderSandbox": "0xca64d4225804f2ae069760cb5ff2f1d8bac1c2f9",
"zrxTreasury": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x9b6aa8f26a92108e7d1f66373d757bb955112703",
"payTakerTransformer": "0x32df54951d33d7460e15fa59b1fcc262183ce4c2",
"affiliateFeeTransformer": "0x67efa679a4b56c38713d478e649c88247f4f8e88",
"fillQuoteTransformer": "0x71de60a1b160094a3f6c7e1b883ff9337d639131",
"positiveSlippageFeeTransformer": "0xe87d69b285005cc82b53b844322652c49ed64600"
}
},
"42220": {
"erc20Proxy": "0x0000000000000000000000000000000000000000",
"erc721Proxy": "0x0000000000000000000000000000000000000000",
"zrxToken": "0x0000000000000000000000000000000000000000",
"etherToken": "0x471ece3750da237f93b8e339c536989b8978a438",
"exchangeV2": "0x0000000000000000000000000000000000000000",
"exchange": "0x0000000000000000000000000000000000000000",
"assetProxyOwner": "0x0000000000000000000000000000000000000000",
"zeroExGovernor": "0x0000000000000000000000000000000000000000",
"forwarder": "0x0000000000000000000000000000000000000000",
"coordinatorRegistry": "0x0000000000000000000000000000000000000000",
"coordinator": "0x0000000000000000000000000000000000000000",
"multiAssetProxy": "0x0000000000000000000000000000000000000000",
"staticCallProxy": "0x0000000000000000000000000000000000000000",
"erc1155Proxy": "0x0000000000000000000000000000000000000000",
"devUtils": "0x0000000000000000000000000000000000000000",
"zrxVault": "0x0000000000000000000000000000000000000000",
"staking": "0x0000000000000000000000000000000000000000",
"stakingProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeSampler": "0x0000000000000000000000000000000000000000",
"chaiBridge": "0x0000000000000000000000000000000000000000",
"dydxBridge": "0x0000000000000000000000000000000000000000",
"godsUnchainedValidator": "0x0000000000000000000000000000000000000000",
"broker": "0x0000000000000000000000000000000000000000",
"chainlinkStopLimit": "0x0000000000000000000000000000000000000000",
"maximumGasPrice": "0x0000000000000000000000000000000000000000",
"dexForwarderBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxyGovernor": "0x92115010fd9b170d4918b102efc86b1b7bebdc7f",
"exchangeProxy": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
"exchangeProxyTransformerDeployer": "0x1fe80d5ad9464dba2d60b88e449305f184823f8a",
"exchangeProxyFlashWallet": "0xdb6f1920a889355780af7570773609bd8cb1f498",
"exchangeProxyLiquidityProviderSandbox": "0x0000000000000000000000000000000000000000",
"zrxTreasury": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x948e03e708b4c62c63f89157a3aa76b986c110ed",
"payTakerTransformer": "0x90fb6c638ece8f3e4bfda1c6d6425626b53148b0",
"affiliateFeeTransformer": "0xc93913692ed073cb0cb37d4a760afd7916e9cb01",
"fillQuoteTransformer": "0xa825d4d3c4d2820c52da69fcccf269b4081871f2",
"positiveSlippageFeeTransformer": "0x9ffc7a79133ed5242777e40764777a6d5aab282c"
}
},
"10": {
"erc20Proxy": "0x0000000000000000000000000000000000000000",
"erc721Proxy": "0x0000000000000000000000000000000000000000",
"zrxToken": "0x0000000000000000000000000000000000000000",
"etherToken": "0x4200000000000000000000000000000000000006",
"exchangeV2": "0x0000000000000000000000000000000000000000",
"exchange": "0x0000000000000000000000000000000000000000",
"assetProxyOwner": "0x0000000000000000000000000000000000000000",
"zeroExGovernor": "0x0000000000000000000000000000000000000000",
"forwarder": "0x0000000000000000000000000000000000000000",
"coordinatorRegistry": "0x0000000000000000000000000000000000000000",
"coordinator": "0x0000000000000000000000000000000000000000",
"multiAssetProxy": "0x0000000000000000000000000000000000000000",
"staticCallProxy": "0x0000000000000000000000000000000000000000",
"erc1155Proxy": "0x0000000000000000000000000000000000000000",
"devUtils": "0x0000000000000000000000000000000000000000",
"zrxVault": "0x0000000000000000000000000000000000000000",
"staking": "0x0000000000000000000000000000000000000000",
"stakingProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeProxy": "0x0000000000000000000000000000000000000000",
"erc20BridgeSampler": "0x0000000000000000000000000000000000000000",
"chaiBridge": "0x0000000000000000000000000000000000000000",
"dydxBridge": "0x0000000000000000000000000000000000000000",
"godsUnchainedValidator": "0x0000000000000000000000000000000000000000",
"broker": "0x0000000000000000000000000000000000000000",
"chainlinkStopLimit": "0x0000000000000000000000000000000000000000",
"maximumGasPrice": "0x0000000000000000000000000000000000000000",
"dexForwarderBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxyGovernor": "0x6d506b2847df0c6f04d2628da1adaf4d8fb2e81b",
"exchangeProxy": "0xdef1abe32c034e558cdd535791643c58a13acc10",
"exchangeProxyTransformerDeployer": "0x3a539ed6bd42de8fbaf3899fb490c792e153d647",
"exchangeProxyFlashWallet": "0xa3128d9b7cca7d5af29780a56abeec12b05a6740",
"exchangeProxyLiquidityProviderSandbox": "0x0000000000000000000000000000000000000000",
"zrxTreasury": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x02ce7af6520e2862f961f5d7eda746642865179c",
"payTakerTransformer": "0x085d10a34f14f6a631ea8ff7d016782ee3ffaa11",
"affiliateFeeTransformer": "0x55cf1d7535250db75bf0190493f55781ee583553",
"fillQuoteTransformer": "0x3543ef833d28b7e983c293856561f21a7f089f1d",
"positiveSlippageFeeTransformer": "0xb11e14565dfbeb702dea9bc0cb47f1a8b32f4783"
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contract-addresses",
"version": "6.7.0",
"version": "6.11.0",
"engines": {
"node": ">=6.12"
},

View File

@@ -53,6 +53,9 @@ export enum ChainId {
Polygon = 137,
PolygonMumbai = 80001,
Avalanche = 43114,
Fantom = 250,
Celo = 42220,
Optimism = 10,
}
/**

View File

@@ -1,4 +1,49 @@
[
{
"timestamp": 1640364306,
"version": "13.18.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "13.18.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "13.18.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "13.18.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "13.18.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "13.18.0",
"changes": [

View File

@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v13.18.5 - _December 24, 2021_
* Dependencies updated
## v13.18.4 - _December 1, 2021_
* Dependencies updated
## v13.18.3 - _November 16, 2021_
* Dependencies updated
## v13.18.2 - _November 3, 2021_
* Dependencies updated
## v13.18.1 - _October 19, 2021_
* Dependencies updated
## v13.18.0 - _September 29, 2021_
* Update IZeroEx and ITransformERC20 wrappers (#282)

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contract-wrappers",
"version": "13.18.0",
"version": "13.18.5",
"engines": {
"node": ">=6.12"
},
@@ -57,7 +57,7 @@
"dependencies": {
"@0x/assert": "^3.0.29",
"@0x/base-contract": "^6.4.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contract-addresses": "^6.11.0",
"@0x/json-schemas": "^6.3.0",
"@0x/types": "^3.3.4",
"@0x/utils": "^6.4.4",

View File

@@ -1,4 +1,68 @@
[
{
"timestamp": 1640364306,
"version": "8.1.14",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "8.1.13",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "8.1.12",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637065617,
"version": "8.1.11",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "8.1.10",
"changes": [
{
"note": "Add OtcOrders to fullMigrateAsync",
"pr": 350
}
],
"timestamp": 1635903615
},
{
"timestamp": 1634668033,
"version": "8.1.9",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1633374058,
"version": "8.1.8",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1632957537,
"version": "8.1.7",

View File

@@ -5,6 +5,34 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v8.1.14 - _December 24, 2021_
* Dependencies updated
## v8.1.13 - _December 1, 2021_
* Dependencies updated
## v8.1.12 - _November 16, 2021_
* Dependencies updated
## v8.1.11 - _November 16, 2021_
* Dependencies updated
## v8.1.10 - _November 3, 2021_
* Add OtcOrders to fullMigrateAsync (#350)
## v8.1.9 - _October 19, 2021_
* Dependencies updated
## v8.1.8 - _October 4, 2021_
* Dependencies updated
## v8.1.7 - _September 29, 2021_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/migrations",
"version": "8.1.7",
"version": "8.1.14",
"engines": {
"node": ">=6.12"
},
@@ -68,20 +68,20 @@
},
"dependencies": {
"@0x/base-contract": "^6.4.2",
"@0x/contract-addresses": "^6.7.0",
"@0x/contract-addresses": "^6.11.0",
"@0x/contracts-asset-proxy": "^3.7.19",
"@0x/contracts-coordinator": "^3.1.38",
"@0x/contracts-dev-utils": "^1.3.36",
"@0x/contracts-erc1155": "^2.1.37",
"@0x/contracts-erc20": "^3.3.20",
"@0x/contracts-erc20": "^3.3.25",
"@0x/contracts-erc721": "^3.1.37",
"@0x/contracts-exchange": "^3.2.38",
"@0x/contracts-exchange-forwarder": "^4.2.38",
"@0x/contracts-extensions": "^6.2.32",
"@0x/contracts-multisig": "^4.1.38",
"@0x/contracts-staking": "^2.0.45",
"@0x/contracts-utils": "^4.8.1",
"@0x/contracts-zero-ex": "^0.29.0",
"@0x/contracts-utils": "^4.8.6",
"@0x/contracts-zero-ex": "^0.30.1",
"@0x/sol-compiler": "^4.7.5",
"@0x/subproviders": "^6.6.0",
"@0x/typescript-typings": "^5.2.1",

View File

@@ -1,4 +1,59 @@
[
{
"timestamp": 1640364306,
"version": "1.10.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "1.10.0",
"changes": [
{
"note": "Add `AaveV2` and `Compound` deposit/withdrawal liquidity source",
"pr": 321
}
],
"timestamp": 1638390144
},
{
"timestamp": 1637102971,
"version": "1.9.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "1.9.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "1.9.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1633374058,
"version": "1.9.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1632957537,
"version": "1.9.1",

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