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:
parent
f283108586
commit
a7a905de4c
@ -65,7 +65,7 @@
|
|||||||
"@0x/json-schemas": "^5.3.4",
|
"@0x/json-schemas": "^5.3.4",
|
||||||
"@0x/order-utils": "^10.4.14",
|
"@0x/order-utils": "^10.4.14",
|
||||||
"@0x/orderbook": "0xProject/gitpkg-registry#0x-orderbook-v2.2.7-e10a81023",
|
"@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/types": "^3.3.1",
|
||||||
"@0x/typescript-typings": "^5.1.6",
|
"@0x/typescript-typings": "^5.1.6",
|
||||||
"@0x/utils": "^6.1.1",
|
"@0x/utils": "^6.1.1",
|
||||||
|
@ -18,7 +18,7 @@ export {
|
|||||||
SRAPollingOrderProviderOpts,
|
SRAPollingOrderProviderOpts,
|
||||||
SRAWebsocketOrderProviderOpts,
|
SRAWebsocketOrderProviderOpts,
|
||||||
} from '@0x/orderbook';
|
} from '@0x/orderbook';
|
||||||
export { RFQTFirmQuote, RFQTIndicativeQuote, TakerRequestQueryParams } from '@0x/quote-server';
|
export { V3RFQFirmQuote, V3RFQIndicativeQuote, TakerRequestQueryParams } from '@0x/quote-server';
|
||||||
export {
|
export {
|
||||||
APIOrder,
|
APIOrder,
|
||||||
Asset,
|
Asset,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { RFQTIndicativeQuote } from '@0x/quote-server';
|
import { V3RFQIndicativeQuote } from '@0x/quote-server';
|
||||||
import { SignedOrder } from '@0x/types';
|
import { SignedOrder } from '@0x/types';
|
||||||
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
import { BigNumber, NULL_ADDRESS } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -59,7 +59,7 @@ export async function getRfqtIndicativeQuotesAsync(
|
|||||||
assetFillAmount: BigNumber,
|
assetFillAmount: BigNumber,
|
||||||
comparisonPrice: BigNumber | undefined,
|
comparisonPrice: BigNumber | undefined,
|
||||||
opts: Partial<GetMarketOrdersOpts>,
|
opts: Partial<GetMarketOrdersOpts>,
|
||||||
): Promise<RFQTIndicativeQuote[]> {
|
): Promise<V3RFQIndicativeQuote[]> {
|
||||||
if (opts.rfqt && opts.rfqt.isIndicative === true && opts.rfqt.quoteRequestor) {
|
if (opts.rfqt && opts.rfqt.isIndicative === true && opts.rfqt.quoteRequestor) {
|
||||||
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
|
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync(
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
@ -70,7 +70,7 @@ export async function getRfqtIndicativeQuotesAsync(
|
|||||||
opts.rfqt,
|
opts.rfqt,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve<RFQTIndicativeQuote[]>([]);
|
return Promise.resolve<V3RFQIndicativeQuote[]>([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { assetDataUtils, ERC20AssetData, generatePseudoRandomSalt, orderCalculationUtils } from '@0x/order-utils';
|
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 { SignedOrder } from '@0x/types';
|
||||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ export function createNativeOrder(fill: NativeCollapsedFill): OptimizedMarketOrd
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createSignedOrdersFromRfqtIndicativeQuotes(
|
export function createSignedOrdersFromRfqtIndicativeQuotes(
|
||||||
quotes: RFQTIndicativeQuote[],
|
quotes: V3RFQIndicativeQuote[],
|
||||||
): SignedOrderWithFillableAmounts[] {
|
): SignedOrderWithFillableAmounts[] {
|
||||||
return quotes.map(quote => {
|
return quotes.map(quote => {
|
||||||
return {
|
return {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { RFQTIndicativeQuote } from '@0x/quote-server';
|
import { V3RFQIndicativeQuote } from '@0x/quote-server';
|
||||||
import { MarketOperation, SignedOrder } from '@0x/types';
|
import { MarketOperation, SignedOrder } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
|
|
||||||
@ -374,7 +374,7 @@ export interface MarketSideLiquidity {
|
|||||||
orderFillableAmounts: BigNumber[];
|
orderFillableAmounts: BigNumber[];
|
||||||
ethToOutputRate: BigNumber;
|
ethToOutputRate: BigNumber;
|
||||||
ethToInputRate: BigNumber;
|
ethToInputRate: BigNumber;
|
||||||
rfqtIndicativeQuotes: RFQTIndicativeQuote[];
|
rfqtIndicativeQuotes: V3RFQIndicativeQuote[];
|
||||||
twoHopQuotes: Array<DexSample<MultiHopFillData>>;
|
twoHopQuotes: Array<DexSample<MultiHopFillData>>;
|
||||||
quoteSourceFilters: SourceFilters;
|
quoteSourceFilters: SourceFilters;
|
||||||
makerTokenDecimals: number;
|
makerTokenDecimals: number;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { schemas, SchemaValidator } from '@0x/json-schemas';
|
import { schemas, SchemaValidator } from '@0x/json-schemas';
|
||||||
import { assetDataUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
|
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 { ERC20AssetData } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import Axios, { AxiosInstance } from 'axios';
|
import Axios, { AxiosInstance } from 'axios';
|
||||||
@ -111,12 +111,15 @@ export class QuoteRequestor {
|
|||||||
|
|
||||||
const requestParamsWithBigNumbers: Pick<
|
const requestParamsWithBigNumbers: Pick<
|
||||||
TakerRequestQueryParams,
|
TakerRequestQueryParams,
|
||||||
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'
|
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice' | 'protocolVersion'
|
||||||
> = {
|
> = {
|
||||||
takerAddress,
|
takerAddress,
|
||||||
comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(),
|
comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(),
|
||||||
buyTokenAddress,
|
buyTokenAddress,
|
||||||
sellTokenAddress,
|
sellTokenAddress,
|
||||||
|
|
||||||
|
// The request parameter below defines what protocol version the RFQ servers should be returning.
|
||||||
|
protocolVersion: '3',
|
||||||
};
|
};
|
||||||
|
|
||||||
// convert BigNumbers to strings
|
// convert BigNumbers to strings
|
||||||
@ -152,7 +155,7 @@ export class QuoteRequestor {
|
|||||||
marketOperation: MarketOperation,
|
marketOperation: MarketOperation,
|
||||||
comparisonPrice: BigNumber | undefined,
|
comparisonPrice: BigNumber | undefined,
|
||||||
options: RfqtRequestOpts,
|
options: RfqtRequestOpts,
|
||||||
): Promise<RFQTFirmQuote[]> {
|
): Promise<V3RFQFirmQuote[]> {
|
||||||
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
||||||
if (
|
if (
|
||||||
_opts.takerAddress === undefined ||
|
_opts.takerAddress === undefined ||
|
||||||
@ -164,7 +167,7 @@ export class QuoteRequestor {
|
|||||||
throw new Error('RFQ-T firm quotes require the presence of a taker address');
|
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,
|
makerAssetData,
|
||||||
takerAssetData,
|
takerAssetData,
|
||||||
assetFillAmount,
|
assetFillAmount,
|
||||||
@ -174,7 +177,7 @@ export class QuoteRequestor {
|
|||||||
'firm',
|
'firm',
|
||||||
);
|
);
|
||||||
|
|
||||||
const result: RFQTFirmQuote[] = [];
|
const result: V3RFQFirmQuote[] = [];
|
||||||
firmQuoteResponses.forEach(firmQuoteResponse => {
|
firmQuoteResponses.forEach(firmQuoteResponse => {
|
||||||
const orderWithStringInts = firmQuoteResponse.response.signedOrder;
|
const orderWithStringInts = firmQuoteResponse.response.signedOrder;
|
||||||
|
|
||||||
@ -242,7 +245,7 @@ export class QuoteRequestor {
|
|||||||
marketOperation: MarketOperation,
|
marketOperation: MarketOperation,
|
||||||
comparisonPrice: BigNumber | undefined,
|
comparisonPrice: BigNumber | undefined,
|
||||||
options: RfqtRequestOpts,
|
options: RfqtRequestOpts,
|
||||||
): Promise<RFQTIndicativeQuote[]> {
|
): Promise<V3RFQIndicativeQuote[]> {
|
||||||
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
const _opts: RfqtRequestOpts = { ...constants.DEFAULT_RFQT_REQUEST_OPTS, ...options };
|
||||||
|
|
||||||
// Originally a takerAddress was required for indicative quotes, but
|
// Originally a takerAddress was required for indicative quotes, but
|
||||||
@ -254,7 +257,7 @@ export class QuoteRequestor {
|
|||||||
_opts.takerAddress = constants.NULL_ADDRESS;
|
_opts.takerAddress = constants.NULL_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const responsesWithStringInts = await this._getQuotesAsync<RFQTIndicativeQuote>( // not yet BigNumber
|
const responsesWithStringInts = await this._getQuotesAsync<V3RFQIndicativeQuote>( // not yet BigNumber
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
takerAssetData,
|
takerAssetData,
|
||||||
assetFillAmount,
|
assetFillAmount,
|
||||||
@ -307,7 +310,7 @@ export class QuoteRequestor {
|
|||||||
return this._orderSignatureToMakerUri[orderSignature];
|
return this._orderSignatureToMakerUri[orderSignature];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _isValidRfqtIndicativeQuoteResponse(response: RFQTIndicativeQuote): boolean {
|
private _isValidRfqtIndicativeQuoteResponse(response: V3RFQIndicativeQuote): boolean {
|
||||||
const hasValidMakerAssetAmount =
|
const hasValidMakerAssetAmount =
|
||||||
response.makerAssetAmount !== undefined &&
|
response.makerAssetAmount !== undefined &&
|
||||||
this._schemaValidator.isValid(response.makerAssetAmount, schemas.wholeNumberSchema);
|
this._schemaValidator.isValid(response.makerAssetAmount, schemas.wholeNumberSchema);
|
||||||
|
@ -42,6 +42,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
sellAmountBaseUnits: '10000',
|
sellAmountBaseUnits: '10000',
|
||||||
comparisonPrice: undefined,
|
comparisonPrice: undefined,
|
||||||
takerAddress,
|
takerAddress,
|
||||||
|
protocolVersion: '3',
|
||||||
};
|
};
|
||||||
// Successful response
|
// Successful response
|
||||||
const successfulOrder1 = testOrderFactory.generateTestSignedOrder({
|
const successfulOrder1 = testOrderFactory.generateTestSignedOrder({
|
||||||
@ -214,6 +215,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
buyTokenAddress: makerToken,
|
buyTokenAddress: makerToken,
|
||||||
sellAmountBaseUnits: '10000',
|
sellAmountBaseUnits: '10000',
|
||||||
comparisonPrice: undefined,
|
comparisonPrice: undefined,
|
||||||
|
protocolVersion: '3',
|
||||||
takerAddress,
|
takerAddress,
|
||||||
};
|
};
|
||||||
// Successful response
|
// Successful response
|
||||||
@ -313,6 +315,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
buyTokenAddress: makerToken,
|
buyTokenAddress: makerToken,
|
||||||
buyAmountBaseUnits: '10000',
|
buyAmountBaseUnits: '10000',
|
||||||
comparisonPrice: undefined,
|
comparisonPrice: undefined,
|
||||||
|
protocolVersion: '3',
|
||||||
takerAddress,
|
takerAddress,
|
||||||
};
|
};
|
||||||
// Successful response
|
// Successful response
|
||||||
|
@ -892,12 +892,14 @@
|
|||||||
"@0x/order-utils" "^10.4.2"
|
"@0x/order-utils" "^10.4.2"
|
||||||
"@0x/utils" "^6.1.0"
|
"@0x/utils" "^6.1.0"
|
||||||
|
|
||||||
"@0x/quote-server@^3.1.0":
|
"@0x/quote-server@^4.0.1":
|
||||||
version "3.1.0"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@0x/quote-server/-/quote-server-3.1.0.tgz#ba5c0de9f88fedfd522ec1ef608dd8eebb868509"
|
resolved "https://registry.yarnpkg.com/@0x/quote-server/-/quote-server-4.0.1.tgz#05947589bfa7905d274ac3c726cb9918b93b0f9e"
|
||||||
|
integrity sha512-/5yP07a78Fqfj7IKicz57Z1R337iLYQP5qi17lMAmuIjwr7DOoUPMh0HL8FSmrf/Mk79GqC+f3jApTkXyR99fw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@0x/json-schemas" "^5.0.7"
|
"@0x/json-schemas" "^5.0.7"
|
||||||
"@0x/order-utils" "^10.2.4"
|
"@0x/order-utils" "^10.2.4"
|
||||||
|
"@0x/protocol-utils" "^1.0.1"
|
||||||
"@0x/utils" "^5.4.1"
|
"@0x/utils" "^5.4.1"
|
||||||
"@types/express" "^4.17.3"
|
"@types/express" "^4.17.3"
|
||||||
express "^4.17.1"
|
express "^4.17.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user