From 29636e7a2d69e2077ee1a496b99767e02239f737 Mon Sep 17 00:00:00 2001 From: Xianny <8582774+xianny@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:08:14 -0700 Subject: [PATCH] feat: Add support for UniswapV2 and MultiBridge (#250) * add uniswap V2 support * add speed bump after log scraping * fix enum strings * bump contract-wrappers version * REALLY update contract-wrappers version * feat: Add support for MultiBridge (#252) * add MultiBridge support * bump asset-swapper version Co-authored-by: xianny Co-authored-by: mzhu25 --- package.json | 10 +++++----- src/config.ts | 12 +++++++++++- test/meta_transaction_test.ts | 12 +++++++++++- test/rfqt_test.ts | 13 +++++++++++-- test/swap_test.ts | 21 +++++++++++++++++++-- test/utils/deployment.ts | 1 + test/utils/mocks.ts | 3 +++ yarn.lock | 12 ++++++------ 8 files changed, 67 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index bb58559d9..8e191e3e9 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "prettier_target": "{.,test/**,src/**}/*.{ts,tsx,json,md}" }, "resolutions": { - "@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-fb0311e67", - "@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-fb0311e67" + "@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-e936c7c50", + "@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-e936c7c50" }, "release": { "plugins": [ @@ -124,10 +124,10 @@ }, "dependencies": { "@0x/assert": "^3.0.4", - "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.4.0-98a99d96a", + "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.4.0-b6fe17711", "@0x/connect": "^6.0.4", - "@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-fb0311e67", - "@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-fb0311e67", + "@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-e936c7c50", + "@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-e936c7c50", "@0x/contracts-dev-utils": "0xProject/gitpkg-registry#0x-contracts-dev-utils-v1.3.3-110e1afa8", "@0x/json-schemas": "^5.0.4", "@0x/mesh-rpc-client": "^9.3.0", diff --git a/src/config.ts b/src/config.ts index 37ac7ffdc..f43195a7a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -226,14 +226,24 @@ const EXCLUDED_SOURCES = (() => { case ChainId.Kovan: return [ERC20BridgeSource.Kyber]; default: - return [ERC20BridgeSource.Eth2Dai, ERC20BridgeSource.Kyber, ERC20BridgeSource.Uniswap]; + return [ + ERC20BridgeSource.Eth2Dai, + ERC20BridgeSource.Kyber, + ERC20BridgeSource.Uniswap, + ERC20BridgeSource.UniswapV2, + ERC20BridgeSource.UniswapV2Eth, + ERC20BridgeSource.MultiBridge, + ]; } })(); export const GAS_SCHEDULE: { [key in ERC20BridgeSource]: number } = { [ERC20BridgeSource.Native]: 1.5e5, [ERC20BridgeSource.Uniswap]: 3e5, + [ERC20BridgeSource.UniswapV2]: 3.5e5, + [ERC20BridgeSource.UniswapV2Eth]: 4e5, [ERC20BridgeSource.LiquidityProvider]: 3e5, + [ERC20BridgeSource.MultiBridge]: 6.5e5, [ERC20BridgeSource.Eth2Dai]: 5.5e5, [ERC20BridgeSource.Kyber]: 8e5, [ERC20BridgeSource.CurveUsdcDai]: 9e5, diff --git a/test/meta_transaction_test.ts b/test/meta_transaction_test.ts index 8544e8d29..404391591 100644 --- a/test/meta_transaction_test.ts +++ b/test/meta_transaction_test.ts @@ -1,3 +1,4 @@ +import { ERC20BridgeSource } from '@0x/asset-swapper'; import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; import { DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; import { constants, expect, signingUtils, transactionHashUtils } from '@0x/contracts-test-utils'; @@ -66,11 +67,20 @@ describe(SUITE_NAME, () => { await teardownApiAsync(SUITE_NAME); }); + const excludedSources = [ + ERC20BridgeSource.Uniswap, + ERC20BridgeSource.UniswapV2, + ERC20BridgeSource.UniswapV2Eth, + ERC20BridgeSource.Kyber, + ERC20BridgeSource.LiquidityProvider, + ERC20BridgeSource.Eth2Dai, + ERC20BridgeSource.MultiBridge, + ]; const DEFAULT_QUERY_PARAMS = { buyToken: 'ZRX', sellToken: 'WETH', buyAmount, - excludedSources: 'Uniswap,Eth2Dai,Kyber,LiquidityProvider', + excludedSources: excludedSources.join(','), }; async function assertFailureAsync(baseRoute: string, testCase: TestCase): Promise { diff --git a/test/rfqt_test.ts b/test/rfqt_test.ts index e792f25aa..9be32a776 100644 --- a/test/rfqt_test.ts +++ b/test/rfqt_test.ts @@ -1,5 +1,5 @@ // tslint:disable:max-file-line-count -import { rfqtMocker } from '@0x/asset-swapper'; +import { ERC20BridgeSource, rfqtMocker } from '@0x/asset-swapper'; import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers'; import { expect } from '@0x/contracts-test-utils'; @@ -32,7 +32,16 @@ let dependencies: AppDependencies; // tslint:disable-next-line:custom-no-magic-numbers const MAX_UINT256 = new BigNumber(2).pow(256).minus(1); const SUITE_NAME = 'rfqt tests'; -const DEFAULT_EXCLUDED_SOURCES = 'Uniswap,Eth2Dai,Kyber,LiquidityProvider'; +const excludedSources = [ + ERC20BridgeSource.Uniswap, + ERC20BridgeSource.UniswapV2, + ERC20BridgeSource.UniswapV2Eth, + ERC20BridgeSource.Kyber, + ERC20BridgeSource.LiquidityProvider, + ERC20BridgeSource.Eth2Dai, + ERC20BridgeSource.MultiBridge, +]; +const DEFAULT_EXCLUDED_SOURCES = excludedSources.join(','); const DEFAULT_SELL_AMOUNT = new BigNumber(100000000000000000); let DEFAULT_RFQT_RESPONSE_DATA; diff --git a/test/swap_test.ts b/test/swap_test.ts index 55889f416..788fd57c8 100644 --- a/test/swap_test.ts +++ b/test/swap_test.ts @@ -1,3 +1,4 @@ +import { ERC20BridgeSource } from '@0x/asset-swapper'; import { expect } from '@0x/contracts-test-utils'; import { BlockchainLifecycle, web3Factory, Web3ProviderEngine } from '@0x/dev-utils'; import { ObjectMap, SignedOrder } from '@0x/types'; @@ -29,10 +30,20 @@ import { MAKER_WETH_AMOUNT, MeshTestUtils } from './utils/mesh_test_utils'; const SUITE_NAME = '/swap'; +const excludedSources = [ + ERC20BridgeSource.Uniswap, + ERC20BridgeSource.UniswapV2, + ERC20BridgeSource.UniswapV2Eth, + ERC20BridgeSource.Kyber, + ERC20BridgeSource.LiquidityProvider, + ERC20BridgeSource.Eth2Dai, + ERC20BridgeSource.MultiBridge, +]; + const DEFAULT_QUERY_PARAMS = { buyToken: 'ZRX', sellToken: 'WETH', - excludedSources: 'Uniswap,Eth2Dai,Kyber,LiquidityProvider', + excludedSources: excludedSources.join(','), }; const ONE_THOUSAND_IN_BASE = new BigNumber('1000000000000000000000'); @@ -157,7 +168,10 @@ describe(SUITE_NAME, () => { }); it('should respect excludedSources', async () => { await quoteAndExpectAsync( - { sellAmount: '1234', excludedSources: 'Uniswap,Eth2Dai,Kyber,LiquidityProvider,0x' }, + { + sellAmount: '1234', + excludedSources: Object.values(ERC20BridgeSource).join(','), + }, { validationErrors: [ { @@ -311,6 +325,8 @@ function expectCorrectQuote(quoteResponse: GetSwapQuoteResponse, quoteAssertions expect(quoteResponse.sources).to.be.eql([ { name: '0x', proportion: '1' }, { name: 'Uniswap', proportion: '0' }, + { name: 'Uniswap_V2', proportion: '0' }, + { name: 'Uniswap_V2_ETH', proportion: '0' }, { name: 'Eth2Dai', proportion: '0' }, { name: 'Kyber', proportion: '0' }, { name: 'Curve_USDC_DAI', proportion: '0' }, @@ -319,5 +335,6 @@ function expectCorrectQuote(quoteResponse: GetSwapQuoteResponse, quoteAssertions { name: 'Curve_USDC_DAI_USDT_BUSD', proportion: '0' }, { name: 'Curve_USDC_DAI_USDT_SUSD', proportion: '0' }, { name: 'LiquidityProvider', proportion: '0' }, + { name: 'MultiBridge', proportion: '0' }, ]); } diff --git a/test/utils/deployment.ts b/test/utils/deployment.ts index 0addbd417..7ca40b9c7 100644 --- a/test/utils/deployment.ts +++ b/test/utils/deployment.ts @@ -95,6 +95,7 @@ export async function setupDependenciesAsync(suiteName: string, logType?: LogTyp // Wait for the dependencies to boot up. await waitForDependencyStartupAsync(up); + await sleepAsync(5); // tslint:disable-line:custom-no-magic-numbers await confirmPostgresConnectivityAsync(); } diff --git a/test/utils/mocks.ts b/test/utils/mocks.ts index 427e92c4b..2562eb8fd 100644 --- a/test/utils/mocks.ts +++ b/test/utils/mocks.ts @@ -30,6 +30,8 @@ export const rfqtIndicativeQuoteResponse = { export const liquiditySources0xOnly = [ { name: '0x', proportion: '1' }, { name: 'Uniswap', proportion: '0' }, + { name: 'Uniswap_V2', proportion: '0' }, + { name: 'Uniswap_V2_ETH', proportion: '0' }, { name: 'Eth2Dai', proportion: '0' }, { name: 'Kyber', proportion: '0' }, { name: 'Curve_USDC_DAI', proportion: '0' }, @@ -38,4 +40,5 @@ export const liquiditySources0xOnly = [ { name: 'Curve_USDC_DAI_USDT_BUSD', proportion: '0' }, { name: 'Curve_USDC_DAI_USDT_SUSD', proportion: '0' }, { name: 'LiquidityProvider', proportion: '0' }, + { name: 'MultiBridge', proportion: '0' }, ]; diff --git a/yarn.lock b/yarn.lock index 501711a4c..990373e39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,9 +22,9 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.4.0-98a99d96a": +"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.4.0-b6fe17711": version "4.4.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/8bf61afc0605d11bd13d09681e82d89b91b87d12" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/6b5de262d21ea5888f8385080b3954be5a786de7" dependencies: "@0x/assert" "^3.0.7" "@0x/contract-addresses" "^4.9.0" @@ -70,13 +70,13 @@ uuid "^3.3.2" websocket "^1.0.26" -"@0x/contract-addresses@0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-fb0311e67", "@0x/contract-addresses@^4.9.0": +"@0x/contract-addresses@0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-e936c7c50", "@0x/contract-addresses@^4.9.0": version "4.9.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/3ec82a85ca67caf5743d0820c3043871f5eef9a4" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/f197899086a7f591d1faa26da15bfc988fdab051" -"@0x/contract-wrappers@0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-fb0311e67", "@0x/contract-wrappers@^13.6.3": +"@0x/contract-wrappers@0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-e936c7c50", "@0x/contract-wrappers@^13.6.3": version "13.6.3" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/9ad98d1f1d8fb110f15028b82432227d32f9ddc8" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/39535ea8a21512aa5ad05e6c27a302311572da92" dependencies: "@0x/assert" "^3.0.7" "@0x/base-contract" "^6.2.1"