asset-s: use @0x/quote-server, not local typedefs
This commit is contained in:
@@ -65,6 +65,7 @@
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/mesh-rpc-client": "^7.0.4-beta-0xv3",
|
||||
"@0x/migrations": "^6.2.4",
|
||||
"@0x/quote-server": "^0.1.1",
|
||||
"@0x/subproviders": "^6.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
|
||||
@@ -70,5 +70,5 @@ export {
|
||||
} from './utils/market_operation_utils/types';
|
||||
export { affiliateFeeUtils } from './utils/affiliate_fee_utils';
|
||||
export { ProtocolFeeUtils } from './utils/protocol_fee_utils';
|
||||
export { QuoteRequestor, RfqtIndicativeQuoteResponse } from './utils/quote_requestor';
|
||||
export { QuoteRequestor, IndicativeQuote } from './utils/quote_requestor';
|
||||
export { rfqtMocker } from './utils/rfqt_mocker';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { SignedOrder } from '@0x/types';
|
||||
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
||||
|
||||
import { MarketOperation } from '../../types';
|
||||
import { RfqtIndicativeQuoteResponse } from '../quote_requestor';
|
||||
import { IndicativeQuote } from '../quote_requestor';
|
||||
import { difference } from '../utils';
|
||||
|
||||
import { BUY_SOURCES, DEFAULT_GET_MARKET_ORDERS_OPTS, FEE_QUOTE_SOURCES, ONE_ETHER, SELL_SOURCES } from './constants';
|
||||
@@ -31,7 +31,7 @@ async function getRfqtIndicativeQuotesAsync(
|
||||
marketOperation: MarketOperation,
|
||||
assetFillAmount: BigNumber,
|
||||
opts: Partial<GetMarketOrdersOpts>,
|
||||
): Promise<RfqtIndicativeQuoteResponse[]> {
|
||||
): Promise<IndicativeQuote[]> {
|
||||
if (opts.rfqt && opts.rfqt.isIndicative === true && opts.rfqt.quoteRequestor) {
|
||||
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
|
||||
makerAssetData,
|
||||
@@ -41,7 +41,7 @@ async function getRfqtIndicativeQuotesAsync(
|
||||
opts.rfqt,
|
||||
);
|
||||
} else {
|
||||
return Promise.resolve<RfqtIndicativeQuoteResponse[]>([]);
|
||||
return Promise.resolve<IndicativeQuote[]>([]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ export class MarketOperationUtils {
|
||||
nativeOrders: SignedOrder[];
|
||||
orderFillableAmounts: BigNumber[];
|
||||
dexQuotes: DexSample[][];
|
||||
rfqtIndicativeQuotes: RfqtIndicativeQuoteResponse[];
|
||||
rfqtIndicativeQuotes: IndicativeQuote[];
|
||||
runLimit?: number;
|
||||
ethToOutputRate?: BigNumber;
|
||||
bridgeSlippage?: number;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ERC20BridgeAssetData, SignedOrder } from '@0x/types';
|
||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||
|
||||
import { MarketOperation, SignedOrderWithFillableAmounts } from '../../types';
|
||||
import { RfqtIndicativeQuoteResponse } from '../quote_requestor';
|
||||
import { IndicativeQuote } from '../quote_requestor';
|
||||
import { getCurveInfo, isCurveSource } from '../source_utils';
|
||||
|
||||
import {
|
||||
@@ -352,7 +352,7 @@ function createNativeOrder(fill: CollapsedFill): OptimizedMarketOrder {
|
||||
}
|
||||
|
||||
export function createSignedOrdersFromRfqtIndicativeQuotes(
|
||||
quotes: RfqtIndicativeQuoteResponse[],
|
||||
quotes: IndicativeQuote[],
|
||||
): SignedOrderWithFillableAmounts[] {
|
||||
return quotes.map(quote => {
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { IERC20BridgeSamplerContract } from '@0x/contract-wrappers';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { RfqtRequestOpts, SignedOrderWithFillableAmounts } from '../../types';
|
||||
import { QuoteRequestor, RfqtIndicativeQuoteResponse } from '../../utils/quote_requestor';
|
||||
import { IndicativeQuote, QuoteRequestor } from '../../utils/quote_requestor';
|
||||
|
||||
/**
|
||||
* Order domain keys: chainId and exchange
|
||||
@@ -47,7 +47,7 @@ export interface NativeFillData extends FillData {
|
||||
}
|
||||
|
||||
export interface RfqtFillData extends FillData {
|
||||
quote: RfqtIndicativeQuoteResponse;
|
||||
quote: IndicativeQuote;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { schemas, SchemaValidator } from '@0x/json-schemas';
|
||||
import { assetDataUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
|
||||
import { FirmQuote, IndicativeQuote } from '@0x/quote-server';
|
||||
import { ERC20AssetData } from '@0x/types';
|
||||
import { BigNumber, logUtils } from '@0x/utils';
|
||||
import Axios, { AxiosResponse } from 'axios';
|
||||
@@ -7,18 +8,13 @@ import Axios, { AxiosResponse } from 'axios';
|
||||
import { constants } from '../constants';
|
||||
import { MarketOperation, RfqtMakerAssetOfferings, RfqtRequestOpts } from '../types';
|
||||
|
||||
export { SignedOrder } from '@0x/order-utils';
|
||||
export { IndicativeQuote } from '@0x/quote-server';
|
||||
|
||||
/**
|
||||
* Request quotes from RFQ-T providers
|
||||
*/
|
||||
|
||||
export interface RfqtIndicativeQuoteResponse {
|
||||
makerAssetData: string;
|
||||
makerAssetAmount: BigNumber;
|
||||
takerAssetData: string;
|
||||
takerAssetAmount: BigNumber;
|
||||
expirationTimeSeconds: BigNumber;
|
||||
}
|
||||
|
||||
function getTokenAddressOrThrow(assetData: string): string {
|
||||
const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
|
||||
if (decodedAssetData.hasOwnProperty('tokenAddress')) {
|
||||
@@ -112,7 +108,7 @@ export class QuoteRequestor {
|
||||
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
||||
assertTakerAddressOrThrow(_opts.takerAddress);
|
||||
|
||||
const ordersWithStringInts = await this._getQuotesAsync<SignedOrder>( // not yet BigNumber
|
||||
const firmQuotes = await this._getQuotesAsync<FirmQuote>( // not yet BigNumber
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
assetFillAmount,
|
||||
@@ -121,6 +117,8 @@ export class QuoteRequestor {
|
||||
'firm',
|
||||
);
|
||||
|
||||
const ordersWithStringInts = firmQuotes.map(quote => quote.signedOrder);
|
||||
|
||||
const validatedOrdersWithStringInts = ordersWithStringInts.filter(order => {
|
||||
const hasValidSchema = this._schemaValidator.isValid(order, schemas.signedOrderSchema);
|
||||
if (!hasValidSchema) {
|
||||
@@ -177,11 +175,11 @@ export class QuoteRequestor {
|
||||
assetFillAmount: BigNumber,
|
||||
marketOperation: MarketOperation,
|
||||
options: RfqtRequestOpts,
|
||||
): Promise<RfqtIndicativeQuoteResponse[]> {
|
||||
): Promise<IndicativeQuote[]> {
|
||||
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
||||
assertTakerAddressOrThrow(_opts.takerAddress);
|
||||
|
||||
const responsesWithStringInts = await this._getQuotesAsync<RfqtIndicativeQuoteResponse>( // not yet BigNumber
|
||||
const responsesWithStringInts = await this._getQuotesAsync<IndicativeQuote>( // not yet BigNumber
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
assetFillAmount,
|
||||
@@ -224,7 +222,7 @@ export class QuoteRequestor {
|
||||
return responses;
|
||||
}
|
||||
|
||||
private _isValidRfqtIndicativeQuoteResponse(response: RfqtIndicativeQuoteResponse): boolean {
|
||||
private _isValidRfqtIndicativeQuoteResponse(response: IndicativeQuote): boolean {
|
||||
const hasValidMakerAssetAmount =
|
||||
response.makerAssetAmount !== undefined &&
|
||||
this._schemaValidator.isValid(response.makerAssetAmount, schemas.wholeNumberSchema);
|
||||
|
||||
@@ -54,7 +54,7 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://1337.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: successfulOrder1,
|
||||
responseData: { signedOrder: successfulOrder1, quoteExpiry: successfulOrder1.expirationTimeSeconds },
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
// Test out a bad response code, ensure it doesnt cause throw
|
||||
@@ -83,7 +83,10 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://422.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: wrongMakerAssetDataOrder,
|
||||
responseData: {
|
||||
signedOrder: wrongMakerAssetDataOrder,
|
||||
quoteExpiry: wrongMakerAssetDataOrder.expirationTimeSeconds,
|
||||
},
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
// A successful response code and valid order, but for wrong taker asset data
|
||||
@@ -96,7 +99,10 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://423.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: wrongTakerAssetDataOrder,
|
||||
responseData: {
|
||||
signedOrder: wrongTakerAssetDataOrder,
|
||||
quoteExpiry: wrongTakerAssetDataOrder.expirationTimeSeconds,
|
||||
},
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
// A successful response code and good order but its unsigned
|
||||
@@ -111,7 +117,7 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://424.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: unsignedOrder,
|
||||
responseData: { signedOrder: unsignedOrder, quoteExpiry: unsignedOrder.expirationTimeSeconds },
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
// A successful response code and good order but for the wrong takerAddress
|
||||
@@ -126,7 +132,10 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://425.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: orderWithNullTaker,
|
||||
responseData: {
|
||||
signedOrder: orderWithNullTaker,
|
||||
quoteExpiry: orderWithNullTaker.expirationTimeSeconds,
|
||||
},
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
|
||||
@@ -141,7 +150,7 @@ describe('QuoteRequestor', async () => {
|
||||
endpoint: 'https://37.0.0.1',
|
||||
requestApiKey: apiKey,
|
||||
requestParams: expectedParams,
|
||||
responseData: successfulOrder2,
|
||||
responseData: { signedOrder: successfulOrder2, quoteExpiry: successfulOrder2.expirationTimeSeconds },
|
||||
responseCode: StatusCodes.Success,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user