Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
feat: Add support for UniswapV2 and MultiBridge (#250)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: mzhu25 <[email protected]>
  • Loading branch information
xianny and moodlezoup authored Jun 12, 2020
1 parent d26d6c6 commit 29636e7
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 17 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion test/meta_transaction_test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<void> {
Expand Down
13 changes: 11 additions & 2 deletions test/rfqt_test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

Expand Down
21 changes: 19 additions & 2 deletions test/swap_test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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' },
Expand All @@ -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' },
]);
}
1 change: 1 addition & 0 deletions test/utils/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions test/utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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' },
];
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 29636e7

Please sign in to comment.