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

feat: Update protocol fee to 70k. Yield to event loop in path optimizer #285

Merged
merged 6 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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