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

Commit

Permalink
feat: Update protocol fee to 70k. Yield to event loop in path optimiz…
Browse files Browse the repository at this point in the history
…er (#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
  • Loading branch information
dekz authored Jul 21, 2020
1 parent 861d2b5 commit a996c7b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 947 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
},
"dependencies": {
"@0x/assert": "^3.0.4",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-916f6785b",
"@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-0f2d9d210",
"@0x/connect": "^6.0.4",
"@0x/contract-addresses": "^4.11.0",
"@0x/contract-wrappers": "^13.7.0",
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ export const MAX_PER_PAGE = 1000;
// Default ERC20 token precision
export const DEFAULT_ERC20_TOKEN_PRECISION = 18;

export const PROTOCOL_FEE_MULTIPLIER = new BigNumber(70000);

const EXCLUDED_SOURCES = (() => {
switch (CHAIN_ID) {
case ChainId.Mainnet:
Expand Down Expand Up @@ -308,7 +310,7 @@ export const GAS_SCHEDULE_V0: FeeSchedule = {
const FEE_SCHEDULE_V0: FeeSchedule = Object.assign(
{},
...(Object.keys(GAS_SCHEDULE_V0) as ERC20BridgeSource[]).map(k => ({
[k]: fillData => new BigNumber(1.5e5).plus(GAS_SCHEDULE_V0[k](fillData)),
[k]: fillData => PROTOCOL_FEE_MULTIPLIER.plus(GAS_SCHEDULE_V0[k](fillData)),
})),
);

Expand All @@ -333,7 +335,7 @@ const FEE_SCHEDULE_V1: FeeSchedule = Object.assign(
...(Object.keys(GAS_SCHEDULE_V0) as ERC20BridgeSource[]).map(k => ({
[k]:
k === ERC20BridgeSource.Native
? fillData => new BigNumber(1.5e5).plus(GAS_SCHEDULE_V1[k](fillData))
? fillData => PROTOCOL_FEE_MULTIPLIER.plus(GAS_SCHEDULE_V1[k](fillData))
: fillData => GAS_SCHEDULE_V1[k](fillData),
})),
);
Expand Down Expand Up @@ -368,8 +370,6 @@ export const SWAP_QUOTER_OPTS: Partial<SwapQuoterOpts> = {
takerApiKeyWhitelist: RFQT_API_KEY_WHITELIST,
makerAssetOfferings: RFQT_MAKER_ASSET_OFFERINGS,
skipBuyRequests: RFQT_SKIP_BUY_REQUESTS,
// warningLogger: logger.warn.bind(logger),
// infoLogger: logger.info.bind(logger),
},
ethGasStationUrl: ETH_GAS_STATION_API_URL,
permittedOrderFeeTypes: new Set([OrderPrunerPermittedFeeTypes.NoFees]),
Expand Down
2 changes: 1 addition & 1 deletion src/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const config: ConnectionOptions = {
logging: true,
logger: 'debug',
extra: {
connectionLimit: 50,
max: 50,
},
};
15 changes: 11 additions & 4 deletions src/services/meta_transaction_service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Orderbook, SwapQuoter } from '@0x/asset-swapper';
import { SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
import { Orderbook, SwapQuoter, SwapQuoteRequestOpts, SwapQuoterOpts } from '@0x/asset-swapper';
import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { ContractWrappers } from '@0x/contract-wrappers';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
Expand Down Expand Up @@ -64,7 +63,15 @@ export class MetaTransactionService {
}
constructor(orderbook: Orderbook, provider: SupportedProvider, dbConnection: Connection) {
this._provider = provider;
this._swapQuoter = new SwapQuoter(this._provider, orderbook, SWAP_QUOTER_OPTS);
const swapQuoterOpts: Partial<SwapQuoterOpts> = {
...SWAP_QUOTER_OPTS,
rfqt: {
...SWAP_QUOTER_OPTS.rfqt,
warningLogger: logger.warn.bind(logger),
infoLogger: logger.info.bind(logger),
},
};
this._swapQuoter = new SwapQuoter(this._provider, orderbook, swapQuoterOpts);
this._contractWrappers = new ContractWrappers(this._provider, { chainId: CHAIN_ID });
this._web3Wrapper = new Web3Wrapper(this._provider);
this._devUtils = new DevUtilsContract(this._contractWrappers.contractAddresses.devUtils, this._provider);
Expand Down Expand Up @@ -100,7 +107,7 @@ export class MetaTransactionService {
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
...ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS,
bridgeSlippage: slippagePercentage,
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
excludedSources: ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS.excludedSources.concat(...(excludedSources || [])),
rfqt: _rfqt,
};

Expand Down
22 changes: 15 additions & 7 deletions src/services/swap_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SwapQuoteGetOutputOpts,
SwapQuoter,
} from '@0x/asset-swapper';
import { SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
import { SwapQuoteRequestOpts, SwapQuoterOpts } from '@0x/asset-swapper/lib/src/types';
import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers';
import { assetDataUtils, SupportedProvider } from '@0x/order-utils';
Expand Down Expand Up @@ -64,8 +64,16 @@ export class SwapService {

constructor(orderbook: Orderbook, provider: SupportedProvider) {
this._provider = provider;
this._swapQuoter = new SwapQuoter(this._provider, orderbook, SWAP_QUOTER_OPTS);
this._swapQuoteConsumer = new SwapQuoteConsumer(this._provider, SWAP_QUOTER_OPTS);
const swapQuoterOpts: Partial<SwapQuoterOpts> = {
...SWAP_QUOTER_OPTS,
rfqt: {
...SWAP_QUOTER_OPTS.rfqt,
warningLogger: logger.warn.bind(logger),
infoLogger: logger.info.bind(logger),
},
};
this._swapQuoter = new SwapQuoter(this._provider, orderbook, swapQuoterOpts);
this._swapQuoteConsumer = new SwapQuoteConsumer(this._provider, swapQuoterOpts);
this._web3Wrapper = new Web3Wrapper(this._provider);

this._contractAddresses = getContractAddressesForChainOrThrow(CHAIN_ID);
Expand Down Expand Up @@ -398,13 +406,13 @@ export class SwapService {
takerAddress,
};
}
const swapQuoteRequestOpts =
swapVersion === SwapVersion.V0 ? ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS : ASSET_SWAPPER_MARKET_ORDERS_V1_OPTS;
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
...(swapVersion === SwapVersion.V0
? ASSET_SWAPPER_MARKET_ORDERS_V0_OPTS
: ASSET_SWAPPER_MARKET_ORDERS_V1_OPTS),
...swapQuoteRequestOpts,
bridgeSlippage: slippagePercentage,
gasPrice: providedGasPrice,
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
excludedSources: swapQuoteRequestOpts.excludedSources.concat(...(excludedSources || [])),
rfqt: _rfqt,
};
if (sellAmount !== undefined) {
Expand Down
Loading

0 comments on commit a996c7b

Please sign in to comment.