Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Changes latency to be capped at 600ms, added some extra typing #275

Merged
merged 2 commits into from
Jul 6, 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: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SwapQuoteRequestOpts> = {
excludedSources: EXCLUDED_SOURCES,
bridgeSlippage: DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE,
Expand Down
5 changes: 2 additions & 3 deletions src/services/meta_transaction_service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -113,9 +113,8 @@ export class MetaTransactionService {
takerAddress,
};
}
const assetSwapperOpts = {
const assetSwapperOpts: Partial<SwapQuoteRequestOpts> = {
...ASSET_SWAPPER_MARKET_ORDERS_OPTS,
slippagePercentage,
bridgeSlippage: slippagePercentage,
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
rfqt: _rfqt,
Expand Down
10 changes: 6 additions & 4 deletions src/services/swap_service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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<SwapQuoteRequestOpts> = {
...ASSET_SWAPPER_MARKET_ORDERS_OPTS,
slippagePercentage,
bridgeSlippage: slippagePercentage,
gasPrice: providedGasPrice,
excludedSources, // TODO(dave4506): overrides the excluded sources selected by chainId
Expand Down
14 changes: 8 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -511,11 +517,7 @@ export interface CalculateSwapQuoteParams {
excludedSources?: ERC20BridgeSource[];
affiliateAddress?: string;
apiKey?: string;
rfqt?: {
intentOnFilling?: boolean;
isIndicative?: boolean;
skipBuyRequests?: boolean;
};
rfqt?: Partial<RfqtRequestOpts>;
skipValidation: boolean;
}

Expand Down