From a84b523793fbd57639dfec1747b7e3fb461fc89b Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Thu, 2 Jul 2020 18:04:49 -0700 Subject: [PATCH 1/2] Changes latency to be capped at 600ms, added some extra typing --- src/config.ts | 2 ++ src/services/swap_service.ts | 10 ++++++---- src/types.ts | 14 ++++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/config.ts b/src/config.ts index 230084c01..5792adf6e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -283,6 +283,8 @@ const feeSchedule: { [key in ERC20BridgeSource]: BigNumber } = Object.assign( })), ); +export const RFQT_REQUEST_MAX_RESPONSE_MS = 600; + export const ASSET_SWAPPER_MARKET_ORDERS_OPTS: Partial = { excludedSources: EXCLUDED_SOURCES, bridgeSlippage: DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE, diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index 6da45fe76..2144149c2 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -1,12 +1,13 @@ import { ExtensionContractType, Orderbook, + RfqtRequestOpts, SwapQuote, SwapQuoteConsumer, SwapQuoter, SwapQuoterOpts, } from '@0x/asset-swapper'; -import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types'; +import { OrderPrunerPermittedFeeTypes, SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types'; import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers'; import { assetDataUtils, SupportedProvider } from '@0x/order-utils'; @@ -21,6 +22,7 @@ import { LIQUIDITY_POOL_REGISTRY_ADDRESS, RFQT_API_KEY_WHITELIST, RFQT_MAKER_ASSET_OFFERINGS, + RFQT_REQUEST_MAX_RESPONSE_MS, RFQT_SKIP_BUY_REQUESTS, } from '../config'; import { @@ -338,7 +340,7 @@ export class SwapService { rfqt, // tslint:disable-next-line:boolean-naming } = params; - let _rfqt; + let _rfqt: RfqtRequestOpts | undefined; if (apiKey !== undefined && (isETHSell || from !== undefined)) { _rfqt = { ...rfqt, @@ -348,11 +350,11 @@ export class SwapService { // forwarder contract. If it's not, then we want to request quotes with the taker set to the // API's takerAddress query parameter, which in this context is known as `from`. takerAddress: isETHSell ? this._forwarderAddress : from || '', + makerEndpointMaxResponseTimeMs: RFQT_REQUEST_MAX_RESPONSE_MS, }; } - const assetSwapperOpts = { + const assetSwapperOpts: Partial = { ...ASSET_SWAPPER_MARKET_ORDERS_OPTS, - slippagePercentage, bridgeSlippage: slippagePercentage, gasPrice: providedGasPrice, excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId diff --git a/src/types.ts b/src/types.ts index 82fa5815e..32581c579 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,10 @@ -import { ERC20BridgeSource, MarketBuySwapQuote, MarketSellSwapQuote, SupportedProvider } from '@0x/asset-swapper'; +import { + ERC20BridgeSource, + MarketBuySwapQuote, + MarketSellSwapQuote, + RfqtRequestOpts, + SupportedProvider, +} from '@0x/asset-swapper'; import { AcceptedOrderInfo, RejectedOrderInfo } from '@0x/mesh-rpc-client'; import { APIOrder, @@ -511,11 +517,7 @@ export interface CalculateSwapQuoteParams { excludedSources?: ERC20BridgeSource[]; affiliateAddress?: string; apiKey?: string; - rfqt?: { - intentOnFilling?: boolean; - isIndicative?: boolean; - skipBuyRequests?: boolean; - }; + rfqt?: Partial; skipValidation: boolean; } From cc54ed12cb264affccb9951076f6211fcc3d443e Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Thu, 2 Jul 2020 18:12:23 -0700 Subject: [PATCH 2/2] remove `slippagePercentage` in meta-transactions --- src/services/meta_transaction_service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/services/meta_transaction_service.ts b/src/services/meta_transaction_service.ts index 727a4a1af..f82235839 100644 --- a/src/services/meta_transaction_service.ts +++ b/src/services/meta_transaction_service.ts @@ -1,5 +1,5 @@ import { Orderbook, SwapQuoter, SwapQuoterOpts } from '@0x/asset-swapper'; -import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types'; +import { OrderPrunerPermittedFeeTypes, SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types'; import { ContractWrappers } from '@0x/contract-wrappers'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { generatePseudoRandomSalt, SupportedProvider, ZeroExTransaction } from '@0x/order-utils'; @@ -113,9 +113,8 @@ export class MetaTransactionService { takerAddress, }; } - const assetSwapperOpts = { + const assetSwapperOpts: Partial = { ...ASSET_SWAPPER_MARKET_ORDERS_OPTS, - slippagePercentage, bridgeSlippage: slippagePercentage, excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId rfqt: _rfqt,