asset-swapper: use RFQT-specific response types

@0x/quote-server was recently updated to offer RFQT- and RFQM-specific
types, in addition to abstracted types.  Since everything here is RFQT
specific, usage has been changed to use those specific types.

Addresses review comments
https://github.com/0xProject/0x-monorepo/pull/2582#discussion_r437623138
and
https://github.com/0xProject/0x-monorepo/pull/2582#discussion_r437625305
This commit is contained in:
F. Eugene Aumson
2020-06-11 15:46:54 -04:00
parent f7cd7110ea
commit ad868af96e
4 changed files with 20 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ export {
SRAPollingOrderProviderOpts,
SRAWebsocketOrderProviderOpts,
} from '@0x/orderbook';
export { IndicativeQuote } from '@0x/quote-server';
export { RFQTIndicativeQuote, RFQTFirmQuote } from '@0x/quote-server';
export { APIOrder, Asset, AssetPairsItem, SignedOrder } from '@0x/types';
export { BigNumber } from '@0x/utils';
export {

View File

@@ -550,13 +550,15 @@ export class SwapQuoter {
throw new Error('RFQ-T requests must specify a taker address');
}
orderBatchPromises.push(
this._quoteRequestor.requestRfqtFirmQuotesAsync(
makerAssetData,
takerAssetData,
assetFillAmount,
marketOperation,
opts.rfqt,
),
this._quoteRequestor
.requestRfqtFirmQuotesAsync(
makerAssetData,
takerAssetData,
assetFillAmount,
marketOperation,
opts.rfqt,
)
.then(firmQuotes => firmQuotes.map(quote => quote.signedOrder)),
);
}

View File

@@ -1,6 +1,6 @@
import { schemas, SchemaValidator } from '@0x/json-schemas';
import { assetDataUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
import { FirmQuote, IndicativeQuote, TakerRequest } from '@0x/quote-server';
import { RFQTFirmQuote, RFQTIndicativeQuote, TakerRequest } from '@0x/quote-server';
import { ERC20AssetData } from '@0x/types';
import { BigNumber, logUtils } from '@0x/utils';
import Axios, { AxiosResponse } from 'axios';
@@ -101,11 +101,11 @@ export class QuoteRequestor {
assetFillAmount: BigNumber,
marketOperation: MarketOperation,
options: RfqtRequestOpts,
): Promise<SignedOrder[]> {
): Promise<RFQTFirmQuote[]> {
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
assertTakerAddressOrThrow(_opts.takerAddress);
const firmQuotes = await this._getQuotesAsync<FirmQuote>( // not yet BigNumber
const firmQuotes = await this._getQuotesAsync<RFQTFirmQuote>( // not yet BigNumber
makerAssetData,
takerAssetData,
assetFillAmount,
@@ -167,7 +167,7 @@ export class QuoteRequestor {
return true;
});
return orders;
return orders.map(order => ({ signedOrder: order }));
}
public async requestRfqtIndicativeQuotesAsync(
@@ -176,11 +176,11 @@ export class QuoteRequestor {
assetFillAmount: BigNumber,
marketOperation: MarketOperation,
options: RfqtRequestOpts,
): Promise<IndicativeQuote[]> {
): Promise<RFQTIndicativeQuote[]> {
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
assertTakerAddressOrThrow(_opts.takerAddress);
const responsesWithStringInts = await this._getQuotesAsync<IndicativeQuote>( // not yet BigNumber
const responsesWithStringInts = await this._getQuotesAsync<RFQTIndicativeQuote>( // not yet BigNumber
makerAssetData,
takerAssetData,
assetFillAmount,
@@ -223,7 +223,7 @@ export class QuoteRequestor {
return responses;
}
private _isValidRfqtIndicativeQuoteResponse(response: IndicativeQuote): boolean {
private _isValidRfqtIndicativeQuoteResponse(response: RFQTIndicativeQuote): boolean {
const hasValidMakerAssetAmount =
response.makerAssetAmount !== undefined &&
this._schemaValidator.isValid(response.makerAssetAmount, schemas.wholeNumberSchema);

View File

@@ -188,7 +188,9 @@ describe('QuoteRequestor', async () => {
intentOnFilling: true,
},
);
expect(resp.sort()).to.eql([successfulOrder1, successfulOrder2].sort());
expect(resp.sort()).to.eql(
[{ signedOrder: successfulOrder1 }, { signedOrder: successfulOrder2 }].sort(),
);
});
});
});