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

Commit cd545c8

Browse files
authored
fix: Changes latency to be capped at 600ms, added some extra typing (#275)
* Changes latency to be capped at 600ms, added some extra typing * remove `slippagePercentage` in meta-transactions
1 parent 3681ea2 commit cd545c8

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ const feeSchedule: { [key in ERC20BridgeSource]: BigNumber } = Object.assign(
283283
})),
284284
);
285285

286+
export const RFQT_REQUEST_MAX_RESPONSE_MS = 600;
287+
286288
export const ASSET_SWAPPER_MARKET_ORDERS_OPTS: Partial<SwapQuoteRequestOpts> = {
287289
excludedSources: EXCLUDED_SOURCES,
288290
bridgeSlippage: DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE,

src/services/meta_transaction_service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Orderbook, SwapQuoter, SwapQuoterOpts } from '@0x/asset-swapper';
2-
import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types';
2+
import { OrderPrunerPermittedFeeTypes, SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
33
import { ContractWrappers } from '@0x/contract-wrappers';
44
import { DevUtilsContract } from '@0x/contracts-dev-utils';
55
import { generatePseudoRandomSalt, SupportedProvider, ZeroExTransaction } from '@0x/order-utils';
@@ -113,9 +113,8 @@ export class MetaTransactionService {
113113
takerAddress,
114114
};
115115
}
116-
const assetSwapperOpts = {
116+
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
117117
...ASSET_SWAPPER_MARKET_ORDERS_OPTS,
118-
slippagePercentage,
119118
bridgeSlippage: slippagePercentage,
120119
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
121120
rfqt: _rfqt,

src/services/swap_service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
ExtensionContractType,
33
Orderbook,
4+
RfqtRequestOpts,
45
SwapQuote,
56
SwapQuoteConsumer,
67
SwapQuoter,
78
SwapQuoterOpts,
89
} from '@0x/asset-swapper';
9-
import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types';
10+
import { OrderPrunerPermittedFeeTypes, SwapQuoteRequestOpts } from '@0x/asset-swapper/lib/src/types';
1011
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
1112
import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers';
1213
import { assetDataUtils, SupportedProvider } from '@0x/order-utils';
@@ -21,6 +22,7 @@ import {
2122
LIQUIDITY_POOL_REGISTRY_ADDRESS,
2223
RFQT_API_KEY_WHITELIST,
2324
RFQT_MAKER_ASSET_OFFERINGS,
25+
RFQT_REQUEST_MAX_RESPONSE_MS,
2426
RFQT_SKIP_BUY_REQUESTS,
2527
} from '../config';
2628
import {
@@ -338,7 +340,7 @@ export class SwapService {
338340
rfqt,
339341
// tslint:disable-next-line:boolean-naming
340342
} = params;
341-
let _rfqt;
343+
let _rfqt: RfqtRequestOpts | undefined;
342344
if (apiKey !== undefined && (isETHSell || from !== undefined)) {
343345
_rfqt = {
344346
...rfqt,
@@ -348,11 +350,11 @@ export class SwapService {
348350
// forwarder contract. If it's not, then we want to request quotes with the taker set to the
349351
// API's takerAddress query parameter, which in this context is known as `from`.
350352
takerAddress: isETHSell ? this._forwarderAddress : from || '',
353+
makerEndpointMaxResponseTimeMs: RFQT_REQUEST_MAX_RESPONSE_MS,
351354
};
352355
}
353-
const assetSwapperOpts = {
356+
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
354357
...ASSET_SWAPPER_MARKET_ORDERS_OPTS,
355-
slippagePercentage,
356358
bridgeSlippage: slippagePercentage,
357359
gasPrice: providedGasPrice,
358360
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId

src/types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ERC20BridgeSource, MarketBuySwapQuote, MarketSellSwapQuote, SupportedProvider } from '@0x/asset-swapper';
1+
import {
2+
ERC20BridgeSource,
3+
MarketBuySwapQuote,
4+
MarketSellSwapQuote,
5+
RfqtRequestOpts,
6+
SupportedProvider,
7+
} from '@0x/asset-swapper';
28
import { AcceptedOrderInfo, RejectedOrderInfo } from '@0x/mesh-rpc-client';
39
import {
410
APIOrder,
@@ -511,11 +517,7 @@ export interface CalculateSwapQuoteParams {
511517
excludedSources?: ERC20BridgeSource[];
512518
affiliateAddress?: string;
513519
apiKey?: string;
514-
rfqt?: {
515-
intentOnFilling?: boolean;
516-
isIndicative?: boolean;
517-
skipBuyRequests?: boolean;
518-
};
520+
rfqt?: Partial<RfqtRequestOpts>;
519521
skipValidation: boolean;
520522
}
521523

0 commit comments

Comments
 (0)