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

Commit

Permalink
Add Balancer as a source and make changes to reflect updates ERC20Bri…
Browse files Browse the repository at this point in the history
…dgeSource and gas/fee schedules
  • Loading branch information
moodlezoup committed Jul 10, 2020
1 parent cd545c8 commit 6d15016
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 49 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prettier_target": "{.,test/**,src/**}/*.{ts,tsx,json,md}"
},
"resolutions": {
"@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-f14b6f2ba",
"@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.10.0-529905efd",
"@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-f14b6f2ba",
"@0x/contracts-zero-ex": "0xProject/gitpkg-registry#0x-contracts-zero-ex-v0.1.0-f14b6f2ba"
},
Expand Down Expand Up @@ -126,9 +126,9 @@
},
"dependencies": {
"@0x/assert": "^3.0.4",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.5.0-0eb0d4d45",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.5.0-529905efd",
"@0x/connect": "^6.0.4",
"@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-f14b6f2ba",
"@0x/contract-addresses": "0xProject/gitpkg-registry#0x-contract-addresses-v4.10.0-529905efd",
"@0x/contract-wrappers": "0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-f14b6f2ba",
"@0x/contracts-dev-utils": "0xProject/gitpkg-registry#0x-contracts-dev-utils-v1.3.3-110e1afa8",
"@0x/contracts-zero-ex": "0xProject/gitpkg-registry#0x-contracts-zero-ex-v0.1.0-f14b6f2ba",
Expand Down
58 changes: 40 additions & 18 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// tslint:disable:custom-no-magic-numbers
import { assert } from '@0x/assert';
import { ERC20BridgeSource, RfqtMakerAssetOfferings, SwapQuoteRequestOpts } from '@0x/asset-swapper';
import {
CurveFillData,
ERC20BridgeSource,
FeeSchedule,
RfqtMakerAssetOfferings,
SwapQuoteRequestOpts,
UniswapV2FillData,
} from '@0x/asset-swapper';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import * as validateUUID from 'uuid-validate';
Expand Down Expand Up @@ -254,32 +261,47 @@ const EXCLUDED_SOURCES = (() => {
ERC20BridgeSource.Kyber,
ERC20BridgeSource.Uniswap,
ERC20BridgeSource.UniswapV2,
ERC20BridgeSource.UniswapV2Eth,
ERC20BridgeSource.MultiBridge,
ERC20BridgeSource.Balancer,
];
}
})();

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,
[ERC20BridgeSource.CurveUsdcDaiUsdt]: 9e5,
[ERC20BridgeSource.CurveUsdcDaiUsdtTusd]: 10e5,
[ERC20BridgeSource.CurveUsdcDaiUsdtBusd]: 10e5,
[ERC20BridgeSource.CurveUsdcDaiUsdtSusd]: 6e5,
export const GAS_SCHEDULE: FeeSchedule = {
[ERC20BridgeSource.Native]: () => 1.5e5,
[ERC20BridgeSource.Uniswap]: () => 3e5,
[ERC20BridgeSource.LiquidityProvider]: () => 3e5,
[ERC20BridgeSource.Eth2Dai]: () => 5.5e5,
[ERC20BridgeSource.Kyber]: () => 8e5,
[ERC20BridgeSource.Curve]: fillData => {
switch ((fillData as CurveFillData).poolAddress.toLowerCase()) {
case '0xa2b47e3d5c44877cca798226b7b8118f9bfb7a56':
case '0x52ea46506b9cc5ef470c5bf89f17dc28bb35d85c':
return 9e5;
case '0x45f783cce6b7ff23b2ab2d70e416cdb7d6055f51':
case '0x79a8c46dea5ada233abaffd40f3a0a2b1e5a4f27':
return 10e5;
case '0xa5407eae9ba41422680e2e00537571bcc53efbfd':
return 6e5;
default:
throw new Error('Unrecognized Curve address');
}
},
[ERC20BridgeSource.MultiBridge]: () => 6.5e5,
[ERC20BridgeSource.UniswapV2]: fillData => {
let gas = 3e5;
if ((fillData as UniswapV2FillData).tokenAddressPath.length > 2) {
gas += 5e4;
}
return gas;
},
[ERC20BridgeSource.Balancer]: () => 4.5e5,
};

const feeSchedule: { [key in ERC20BridgeSource]: BigNumber } = Object.assign(
const feeSchedule: FeeSchedule = Object.assign(
{},
...(Object.keys(GAS_SCHEDULE) as ERC20BridgeSource[]).map(k => ({
[k]: new BigNumber(GAS_SCHEDULE[k] + 1.5e5),
[k]: fillData => new BigNumber(1.5e5).plus(GAS_SCHEDULE[k](fillData)),
})),
);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/service_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const serviceUtils = {
gasTokenGasCost: ZERO,
};
}
const costOfBridgeFills = BigNumber.sum(...bridgeFills.map(o => GAS_SCHEDULE[o.source]))
const costOfBridgeFills = BigNumber.sum(...bridgeFills.map(o => GAS_SCHEDULE[o.source](o.fillData)))
.plus(bridgeFills.length * SSTORE_COST)
.plus(SSTORE_INIT_COST);
const usedGasTokens = BigNumber.min(
Expand Down
2 changes: 1 addition & 1 deletion test/meta_transaction_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ describe(SUITE_NAME, () => {
const excludedSources = [
ERC20BridgeSource.Uniswap,
ERC20BridgeSource.UniswapV2,
ERC20BridgeSource.UniswapV2Eth,
ERC20BridgeSource.Kyber,
ERC20BridgeSource.LiquidityProvider,
ERC20BridgeSource.Eth2Dai,
ERC20BridgeSource.MultiBridge,
ERC20BridgeSource.Balancer,
];
const DEFAULT_QUERY_PARAMS = {
buyToken: 'ZRX',
Expand Down
2 changes: 1 addition & 1 deletion test/rfqt_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const SUITE_NAME = 'rfqt tests';
const excludedSources = [
ERC20BridgeSource.Uniswap,
ERC20BridgeSource.UniswapV2,
ERC20BridgeSource.UniswapV2Eth,
ERC20BridgeSource.Kyber,
ERC20BridgeSource.LiquidityProvider,
ERC20BridgeSource.Eth2Dai,
ERC20BridgeSource.MultiBridge,
ERC20BridgeSource.Balancer,
];
const DEFAULT_EXCLUDED_SOURCES = excludedSources.join(',');
const DEFAULT_SELL_AMOUNT = new BigNumber(100000000000000000);
Expand Down
10 changes: 5 additions & 5 deletions test/service_utils_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(SUITE_NAME, () => {
{
fills: [
{
source: ERC20BridgeSource.CurveUsdcDai,
source: ERC20BridgeSource.Uniswap,
},
],
},
Expand All @@ -27,16 +27,16 @@ describe(SUITE_NAME, () => {
fakeOrders,
MAX_INT,
);
expect(usedGasTokens).to.be.eq(22);
expect(gasTokenRefund.toNumber()).to.be.eq(5280000);
expect(gasTokenGasCost.toNumber()).to.be.eq(151140);
expect(usedGasTokens).to.be.eq(8);
expect(gasTokenRefund.toNumber()).to.be.eq(1920000);
expect(gasTokenGasCost.toNumber()).to.be.eq(54960);
});
it('does not return an estimate when there are bridge fills but no gas tokens', () => {
const fakeOrders: any = [
{
fills: [
{
source: ERC20BridgeSource.CurveUsdcDai,
source: ERC20BridgeSource.Uniswap,
},
],
},
Expand Down
10 changes: 3 additions & 7 deletions test/swap_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const SUITE_NAME = '/swap';
const excludedSources = [
ERC20BridgeSource.Uniswap,
ERC20BridgeSource.UniswapV2,
ERC20BridgeSource.UniswapV2Eth,
ERC20BridgeSource.Kyber,
ERC20BridgeSource.LiquidityProvider,
ERC20BridgeSource.Eth2Dai,
ERC20BridgeSource.MultiBridge,
ERC20BridgeSource.Balancer,
];

const DEFAULT_QUERY_PARAMS = {
Expand Down Expand Up @@ -326,15 +326,11 @@ function expectCorrectQuote(quoteResponse: GetSwapQuoteResponse, quoteAssertions
{ 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' },
{ name: 'Curve_USDC_DAI_USDT', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_TUSD', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_BUSD', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_SUSD', proportion: '0' },
{ name: 'Curve', proportion: '0' },
{ name: 'LiquidityProvider', proportion: '0' },
{ name: 'MultiBridge', proportion: '0' },
{ name: 'Balancer', proportion: '0' },
]);
}
8 changes: 2 additions & 6 deletions test/utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ 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' },
{ name: 'Curve_USDC_DAI_USDT', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_TUSD', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_BUSD', proportion: '0' },
{ name: 'Curve_USDC_DAI_USDT_SUSD', proportion: '0' },
{ name: 'Curve', proportion: '0' },
{ name: 'LiquidityProvider', proportion: '0' },
{ name: 'MultiBridge', proportion: '0' },
{ name: 'Balancer', proportion: '0' },
];
31 changes: 24 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
lodash "^4.17.11"
valid-url "^1.0.9"

"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.5.0-0eb0d4d45":
"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.5.0-529905efd":
version "4.5.0"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/cc0d5b67008429f0f6cacfdc795e34b8986eeabb"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/e02dc90d558014f9946064aefbcf1f5aa58b8285"
dependencies:
"@0x/assert" "^3.0.8"
"@0x/contract-addresses" "^4.10.0"
Expand All @@ -45,8 +45,10 @@
"@0x/quote-server" "^2.0.2"
"@0x/utils" "^5.5.0"
"@0x/web3-wrapper" "^7.1.0"
"@balancer-labs/sor" "^0.3.0"
axios "^0.19.2"
axios-mock-adapter "^1.18.1"
decimal.js "^10.2.0"
ethereumjs-util "^5.1.1"
heartbeats "^5.0.1"
lodash "^4.17.11"
Expand Down Expand Up @@ -113,9 +115,9 @@
uuid "^3.3.2"
websocket "^1.0.26"

"@0x/contract-addresses@0xProject/gitpkg-registry#0x-contract-addresses-v4.9.0-f14b6f2ba", "@0x/contract-addresses@^4.10.0", "@0x/contract-addresses@^4.9.0":
version "4.9.0"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/8aa115995636ca07134a1634c084778c5ac05b76"
"@0x/contract-addresses@0xProject/gitpkg-registry#0x-contract-addresses-v4.10.0-529905efd", "@0x/contract-addresses@^4.10.0", "@0x/contract-addresses@^4.9.0":
version "4.10.0"
resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/653e40ce2655eebd9179dd2f5826e88354c46d64"

"@0x/contract-wrappers@0xProject/gitpkg-registry#0x-contract-wrappers-v13.6.3-f14b6f2ba", "@0x/contract-wrappers@^13.6.3", "@0x/contract-wrappers@^13.7.0":
version "13.6.3"
Expand Down Expand Up @@ -799,6 +801,16 @@
dependencies:
regenerator-runtime "^0.13.4"

"@balancer-labs/sor@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@balancer-labs/sor/-/sor-0.3.0.tgz#c221225d9a3d1791ebfc3c566f7a76843bca98fa"
integrity sha512-QTVkeDmcGCaEgBhcVSu8c7cz6HA1ueWRbniuT+Yh0N/sqcZIcDMdoCFcpq66SD+hOxQ88RvzShmJ+P/3vKbXfg==
dependencies:
bignumber.js "^9.0.0"
ethers "^4.0.39"
isomorphic-fetch "^2.2.1"
typescript "^3.8.3"

"@hapi/bourne@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@hapi/bourne/-/bourne-1.3.2.tgz#0a7095adea067243ce3283e1b56b8a8f453b242a"
Expand Down Expand Up @@ -3612,7 +3624,7 @@ ethers@4.0.0-beta.3:
uuid "2.0.1"
xmlhttprequest "1.8.0"

ethers@~4.0.4:
ethers@^4.0.39, ethers@~4.0.4:
version "4.0.47"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.47.tgz#91b9cd80473b1136dd547095ff9171bd1fc68c85"
dependencies:
Expand Down Expand Up @@ -4865,7 +4877,7 @@ isobject@^3.0.0, isobject@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"

isomorphic-fetch@2.2.1:
isomorphic-fetch@2.2.1, isomorphic-fetch@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
Expand Down Expand Up @@ -7967,6 +7979,11 @@ typescript@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"

typescript@^3.8.3:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

typewise-core@^1.2, typewise-core@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195"
Expand Down

0 comments on commit 6d15016

Please sign in to comment.