fix: Upgrade quote server and Asset Swapper types (and specify protocol ve… (#108)

* Upgrade quote server and Asset Swapper types (and specify protocol version in API requests)

* add package and lockfile

* fix tests
This commit is contained in:
Daniel Pyrathon 2021-01-13 17:07:45 -08:00 committed by GitHub
parent f283108586
commit a7a905de4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 20 deletions

View File

@ -65,7 +65,7 @@
"@0x/json-schemas": "^5.3.4",
"@0x/order-utils": "^10.4.14",
"@0x/orderbook": "0xProject/gitpkg-registry#0x-orderbook-v2.2.7-e10a81023",
"@0x/quote-server": "^3.1.0",
"@0x/quote-server": "^4.0.1",
"@0x/types": "^3.3.1",
"@0x/typescript-typings": "^5.1.6",
"@0x/utils": "^6.1.1",

View File

@ -18,7 +18,7 @@ export {
SRAPollingOrderProviderOpts,
SRAWebsocketOrderProviderOpts,
} from '@0x/orderbook';
export { RFQTFirmQuote, RFQTIndicativeQuote, TakerRequestQueryParams } from '@0x/quote-server';
export { V3RFQFirmQuote, V3RFQIndicativeQuote, TakerRequestQueryParams } from '@0x/quote-server';
export {
APIOrder,
Asset,

View File

@ -1,4 +1,4 @@
import { RFQTIndicativeQuote } from '@0x/quote-server';
import { V3RFQIndicativeQuote } from '@0x/quote-server';
import { SignedOrder } from '@0x/types';
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
import * as _ from 'lodash';
@ -59,7 +59,7 @@ export async function getRfqtIndicativeQuotesAsync(
assetFillAmount: BigNumber,
comparisonPrice: BigNumber | undefined,
opts: Partial<GetMarketOrdersOpts>,
): Promise<RFQTIndicativeQuote[]> {
): Promise<V3RFQIndicativeQuote[]> {
if (opts.rfqt && opts.rfqt.isIndicative === true && opts.rfqt.quoteRequestor) {
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
makerAssetData,
@ -70,7 +70,7 @@ export async function getRfqtIndicativeQuotesAsync(
opts.rfqt,
);
} else {
return Promise.resolve<RFQTIndicativeQuote[]>([]);
return Promise.resolve<V3RFQIndicativeQuote[]>([]);
}
}

View File

@ -1,5 +1,5 @@
import { assetDataUtils, ERC20AssetData, generatePseudoRandomSalt, orderCalculationUtils } from '@0x/order-utils';
import { RFQTIndicativeQuote } from '@0x/quote-server';
import { V3RFQIndicativeQuote } from '@0x/quote-server';
import { SignedOrder } from '@0x/types';
import { AbiEncoder, BigNumber } from '@0x/utils';
@ -498,7 +498,7 @@ export function createNativeOrder(fill: NativeCollapsedFill): OptimizedMarketOrd
}
export function createSignedOrdersFromRfqtIndicativeQuotes(
quotes: RFQTIndicativeQuote[],
quotes: V3RFQIndicativeQuote[],
): SignedOrderWithFillableAmounts[] {
return quotes.map(quote => {
return {

View File

@ -1,4 +1,4 @@
import { RFQTIndicativeQuote } from '@0x/quote-server';
import { V3RFQIndicativeQuote } from '@0x/quote-server';
import { MarketOperation, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
@ -374,7 +374,7 @@ export interface MarketSideLiquidity {
orderFillableAmounts: BigNumber[];
ethToOutputRate: BigNumber;
ethToInputRate: BigNumber;
rfqtIndicativeQuotes: RFQTIndicativeQuote[];
rfqtIndicativeQuotes: V3RFQIndicativeQuote[];
twoHopQuotes: Array<DexSample<MultiHopFillData>>;
quoteSourceFilters: SourceFilters;
makerTokenDecimals: number;

View File

@ -1,6 +1,6 @@
import { schemas, SchemaValidator } from '@0x/json-schemas';
import { assetDataUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
import { RFQTFirmQuote, RFQTIndicativeQuote, TakerRequestQueryParams } from '@0x/quote-server';
import { TakerRequestQueryParams, V3RFQFirmQuote, V3RFQIndicativeQuote } from '@0x/quote-server';
import { ERC20AssetData } from '@0x/types';
import { BigNumber } from '@0x/utils';
import Axios, { AxiosInstance } from 'axios';
@ -111,12 +111,15 @@ export class QuoteRequestor {
const requestParamsWithBigNumbers: Pick<
TakerRequestQueryParams,
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice' | 'protocolVersion'
> = {
takerAddress,
comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(),
buyTokenAddress,
sellTokenAddress,
// The request parameter below defines what protocol version the RFQ servers should be returning.
protocolVersion: '3',
};
// convert BigNumbers to strings
@ -152,7 +155,7 @@ export class QuoteRequestor {
marketOperation: MarketOperation,
comparisonPrice: BigNumber | undefined,
options: RfqtRequestOpts,
): Promise<RFQTFirmQuote[]> {
): Promise<V3RFQFirmQuote[]> {
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
if (
_opts.takerAddress === undefined ||
@ -164,7 +167,7 @@ export class QuoteRequestor {
throw new Error('RFQ-T firm quotes require the presence of a taker address');
}
const firmQuoteResponses = await this._getQuotesAsync<RFQTFirmQuote>( // not yet BigNumber
const firmQuoteResponses = await this._getQuotesAsync<V3RFQFirmQuote>( // not yet BigNumber
makerAssetData,
takerAssetData,
assetFillAmount,
@ -174,7 +177,7 @@ export class QuoteRequestor {
'firm',
);
const result: RFQTFirmQuote[] = [];
const result: V3RFQFirmQuote[] = [];
firmQuoteResponses.forEach(firmQuoteResponse => {
const orderWithStringInts = firmQuoteResponse.response.signedOrder;
@ -242,7 +245,7 @@ export class QuoteRequestor {
marketOperation: MarketOperation,
comparisonPrice: BigNumber | undefined,
options: RfqtRequestOpts,
): Promise<RFQTIndicativeQuote[]> {
): Promise<V3RFQIndicativeQuote[]> {
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
// Originally a takerAddress was required for indicative quotes, but
@ -254,7 +257,7 @@ export class QuoteRequestor {
_opts.takerAddress = constants.NULL_ADDRESS;
}
const responsesWithStringInts = await this._getQuotesAsync<RFQTIndicativeQuote>( // not yet BigNumber
const responsesWithStringInts = await this._getQuotesAsync<V3RFQIndicativeQuote>( // not yet BigNumber
makerAssetData,
takerAssetData,
assetFillAmount,
@ -307,7 +310,7 @@ export class QuoteRequestor {
return this._orderSignatureToMakerUri[orderSignature];
}
private _isValidRfqtIndicativeQuoteResponse(response: RFQTIndicativeQuote): boolean {
private _isValidRfqtIndicativeQuoteResponse(response: V3RFQIndicativeQuote): boolean {
const hasValidMakerAssetAmount =
response.makerAssetAmount !== undefined &&
this._schemaValidator.isValid(response.makerAssetAmount, schemas.wholeNumberSchema);

View File

@ -42,6 +42,7 @@ describe('QuoteRequestor', async () => {
sellAmountBaseUnits: '10000',
comparisonPrice: undefined,
takerAddress,
protocolVersion: '3',
};
// Successful response
const successfulOrder1 = testOrderFactory.generateTestSignedOrder({
@ -214,6 +215,7 @@ describe('QuoteRequestor', async () => {
buyTokenAddress: makerToken,
sellAmountBaseUnits: '10000',
comparisonPrice: undefined,
protocolVersion: '3',
takerAddress,
};
// Successful response
@ -313,6 +315,7 @@ describe('QuoteRequestor', async () => {
buyTokenAddress: makerToken,
buyAmountBaseUnits: '10000',
comparisonPrice: undefined,
protocolVersion: '3',
takerAddress,
};
// Successful response

View File

@ -892,12 +892,14 @@
"@0x/order-utils" "^10.4.2"
"@0x/utils" "^6.1.0"
"@0x/quote-server@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@0x/quote-server/-/quote-server-3.1.0.tgz#ba5c0de9f88fedfd522ec1ef608dd8eebb868509"
"@0x/quote-server@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@0x/quote-server/-/quote-server-4.0.1.tgz#05947589bfa7905d274ac3c726cb9918b93b0f9e"
integrity sha512-/5yP07a78Fqfj7IKicz57Z1R337iLYQP5qi17lMAmuIjwr7DOoUPMh0HL8FSmrf/Mk79GqC+f3jApTkXyR99fw==
dependencies:
"@0x/json-schemas" "^5.0.7"
"@0x/order-utils" "^10.2.4"
"@0x/protocol-utils" "^1.0.1"
"@0x/utils" "^5.4.1"
"@types/express" "^4.17.3"
express "^4.17.1"