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

Commit a996c7b

Browse files
authored
feat: Update protocol fee to 70k. Yield to event loop in path optimizer (#285)
* fix: yield to event loop * disable Balancer * fix: Balancer promist, native skip when excluded * fix: rfqt logging * chore: update protocol fee multiplier * fix: update to latest AS with 70k protocol fee
1 parent 861d2b5 commit a996c7b

6 files changed

Lines changed: 34 additions & 947 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
},
124124
"dependencies": {
125125
"@0x/assert": "^3.0.4",
126-
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-916f6785b",
126+
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-0f2d9d210",
127127
"@0x/connect": "^6.0.4",
128128
"@0x/contract-addresses": "^4.11.0",
129129
"@0x/contract-wrappers": "^13.7.0",

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ export const MAX_PER_PAGE = 1000;
256256
// Default ERC20 token precision
257257
export const DEFAULT_ERC20_TOKEN_PRECISION = 18;
258258

259+
export const PROTOCOL_FEE_MULTIPLIER = new BigNumber(70000);
260+
259261
const EXCLUDED_SOURCES = (() => {
260262
switch (CHAIN_ID) {
261263
case ChainId.Mainnet:
@@ -308,7 +310,7 @@ export const GAS_SCHEDULE_V0: FeeSchedule = {
308310
const FEE_SCHEDULE_V0: FeeSchedule = Object.assign(
309311
{},
310312
...(Object.keys(GAS_SCHEDULE_V0) as ERC20BridgeSource[]).map(k => ({
311-
[k]: fillData => new BigNumber(1.5e5).plus(GAS_SCHEDULE_V0[k](fillData)),
313+
[k]: fillData => PROTOCOL_FEE_MULTIPLIER.plus(GAS_SCHEDULE_V0[k](fillData)),
312314
})),
313315
);
314316

@@ -333,7 +335,7 @@ const FEE_SCHEDULE_V1: FeeSchedule = Object.assign(
333335
...(Object.keys(GAS_SCHEDULE_V0) as ERC20BridgeSource[]).map(k => ({
334336
[k]:
335337
k === ERC20BridgeSource.Native
336-
? fillData => new BigNumber(1.5e5).plus(GAS_SCHEDULE_V1[k](fillData))
338+
? fillData => PROTOCOL_FEE_MULTIPLIER.plus(GAS_SCHEDULE_V1[k](fillData))
337339
: fillData => GAS_SCHEDULE_V1[k](fillData),
338340
})),
339341
);
@@ -368,8 +370,6 @@ export const SWAP_QUOTER_OPTS: Partial<SwapQuoterOpts> = {
368370
takerApiKeyWhitelist: RFQT_API_KEY_WHITELIST,
369371
makerAssetOfferings: RFQT_MAKER_ASSET_OFFERINGS,
370372
skipBuyRequests: RFQT_SKIP_BUY_REQUESTS,
371-
// warningLogger: logger.warn.bind(logger),
372-
// infoLogger: logger.info.bind(logger),
373373
},
374374
ethGasStationUrl: ETH_GAS_STATION_API_URL,
375375
permittedOrderFeeTypes: new Set([OrderPrunerPermittedFeeTypes.NoFees]),

src/ormconfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export const config: ConnectionOptions = {
1313
logging: true,
1414
logger: 'debug',
1515
extra: {
16-
connectionLimit: 50,
16+
max: 50,
1717
},
1818
};

src/services/meta_transaction_service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Orderbook, SwapQuoter } from '@0x/asset-swapper';
2-
import { SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
1+
import { Orderbook, SwapQuoter, SwapQuoteRequestOpts, SwapQuoterOpts } from '@0x/asset-swapper';
32
import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
43
import { ContractWrappers } from '@0x/contract-wrappers';
54
import { DevUtilsContract } from '@0x/contracts-dev-utils';
@@ -64,7 +63,15 @@ export class MetaTransactionService {
6463
}
6564
constructor(orderbook: Orderbook, provider: SupportedProvider, dbConnection: Connection) {
6665
this._provider = provider;
67-
this._swapQuoter = new SwapQuoter(this._provider, orderbook, SWAP_QUOTER_OPTS);
66+
const swapQuoterOpts: Partial<SwapQuoterOpts> = {
67+
...SWAP_QUOTER_OPTS,
68+
rfqt: {
69+
...SWAP_QUOTER_OPTS.rfqt,
70+
warningLogger: logger.warn.bind(logger),
71+
infoLogger: logger.info.bind(logger),
72+
},
73+
};
74+
this._swapQuoter = new SwapQuoter(this._provider, orderbook, swapQuoterOpts);
6875
this._contractWrappers = new ContractWrappers(this._provider, { chainId: CHAIN_ID });
6976
this._web3Wrapper = new Web3Wrapper(this._provider);
7077
this._devUtils = new DevUtilsContract(this._contractWrappers.contractAddresses.devUtils, this._provider);
@@ -100,7 +107,7 @@ export class MetaTransactionService {
100107
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
101108
...ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS,
102109
bridgeSlippage: slippagePercentage,
103-
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
110+
excludedSources: ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS.excludedSources.concat(...(excludedSources || [])),
104111
rfqt: _rfqt,
105112
};
106113

src/services/swap_service.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SwapQuoteGetOutputOpts,
99
SwapQuoter,
1010
} from '@0x/asset-swapper';
11-
import { SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
11+
import { SwapQuoteRequestOpts, SwapQuoterOpts } from '@0x/asset-swapper/lib/src/types';
1212
import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
1313
import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers';
1414
import { assetDataUtils, SupportedProvider } from '@0x/order-utils';
@@ -64,8 +64,16 @@ export class SwapService {
6464

6565
constructor(orderbook: Orderbook, provider: SupportedProvider) {
6666
this._provider = provider;
67-
this._swapQuoter = new SwapQuoter(this._provider, orderbook, SWAP_QUOTER_OPTS);
68-
this._swapQuoteConsumer = new SwapQuoteConsumer(this._provider, SWAP_QUOTER_OPTS);
67+
const swapQuoterOpts: Partial<SwapQuoterOpts> = {
68+
...SWAP_QUOTER_OPTS,
69+
rfqt: {
70+
...SWAP_QUOTER_OPTS.rfqt,
71+
warningLogger: logger.warn.bind(logger),
72+
infoLogger: logger.info.bind(logger),
73+
},
74+
};
75+
this._swapQuoter = new SwapQuoter(this._provider, orderbook, swapQuoterOpts);
76+
this._swapQuoteConsumer = new SwapQuoteConsumer(this._provider, swapQuoterOpts);
6977
this._web3Wrapper = new Web3Wrapper(this._provider);
7078

7179
this._contractAddresses = getContractAddressesForChainOrThrow(CHAIN_ID);
@@ -398,13 +406,13 @@ export class SwapService {
398406
takerAddress,
399407
};
400408
}
409+
const swapQuoteRequestOpts =
410+
swapVersion === SwapVersion.V0 ? ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS : ASSET_SWAPPER_MARKET_ORDERS_V1_OPTS;
401411
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
402-
...(swapVersion === SwapVersion.V0
403-
? ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS
404-
: ASSET_SWAPPER_MARKET_ORDERS_V1_OPTS),
412+
...swapQuoteRequestOpts,
405413
bridgeSlippage: slippagePercentage,
406414
gasPrice: providedGasPrice,
407-
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
415+
excludedSources: swapQuoteRequestOpts.excludedSources.concat(...(excludedSources || [])),
408416
rfqt: _rfqt,
409417
};
410418
if (sellAmount !== undefined) {

0 commit comments

Comments
 (0)