Remove chainId when using connect from asset-swapper

This commit is contained in:
fragosti 2019-11-08 17:41:26 -08:00
parent 8a8ec79c6c
commit 595358fa69
9 changed files with 36 additions and 23 deletions

View File

@ -15,7 +15,6 @@ import { assert } from '../utils/assert';
export class StandardRelayerAPIOrderProvider implements OrderProvider {
public readonly apiUrl: string;
public readonly chainId: number;
private readonly _sraClient: HttpClient;
/**
* Given an array of APIOrder objects from a standard relayer api, return an array
@ -49,14 +48,11 @@ export class StandardRelayerAPIOrderProvider implements OrderProvider {
/**
* Instantiates a new StandardRelayerAPIOrderProvider instance
* @param apiUrl The standard relayer API base HTTP url you would like to source orders from.
* @param chainId The ethereum chain id.
* @return An instance of StandardRelayerAPIOrderProvider
*/
constructor(apiUrl: string, chainId: number) {
constructor(apiUrl: string) {
assert.isWebUri('apiUrl', apiUrl);
assert.isNumber('chainId', chainId);
this.apiUrl = apiUrl;
this.chainId = chainId;
this._sraClient = new HttpClient(apiUrl);
}
/**
@ -68,10 +64,9 @@ export class StandardRelayerAPIOrderProvider implements OrderProvider {
assert.isValidOrderProviderRequest('orderProviderRequest', orderProviderRequest);
const { makerAssetData, takerAssetData } = orderProviderRequest;
const orderbookRequest = { baseAssetData: makerAssetData, quoteAssetData: takerAssetData };
const requestOpts = { chainId: this.chainId };
let orderbook: OrderbookResponse;
try {
orderbook = await this._sraClient.getOrderbookAsync(orderbookRequest, requestOpts);
orderbook = await this._sraClient.getOrderbookAsync(orderbookRequest);
} catch (err) {
throw new Error(AssetBuyerError.StandardRelayerApiError);
}
@ -91,7 +86,7 @@ export class StandardRelayerAPIOrderProvider implements OrderProvider {
public async getAvailableMakerAssetDatasAsync(takerAssetData: string): Promise<string[]> {
// Return a maximum of 1000 asset datas
const maxPerPage = 1000;
const requestOpts = { chainId: this.chainId, perPage: maxPerPage };
const requestOpts = { perPage: maxPerPage };
const assetPairsRequest = { assetDataA: takerAssetData };
const fullRequest = {
...requestOpts,

View File

@ -69,7 +69,6 @@ export class SwapQuoter {
httpEndpoint: sraApiUrl,
pollingIntervalMs:
options.orderRefreshIntervalMs || constants.DEFAULT_SWAP_QUOTER_OPTS.orderRefreshIntervalMs,
chainId: options.chainId || constants.DEFAULT_SWAP_QUOTER_OPTS.chainId,
perPage: options.perPage || constants.DEFAULT_PER_PAGE,
});
const swapQuoter = new SwapQuoter(provider, orderbook, options);
@ -97,7 +96,6 @@ export class SwapQuoter {
const orderbook = Orderbook.getOrderbookForWebsocketProvider({
httpEndpoint: sraApiUrl,
websocketEndpoint: sraWebsocketAPIUrl,
chainId: options.chainId,
});
const swapQuoter = new SwapQuoter(provider, orderbook, options);
return swapQuoter;

View File

@ -5,12 +5,10 @@ import { MethodAbi } from 'ethereum-types';
/**
* makerAssetData: The assetData representing the desired makerAsset.
* takerAssetData: The assetData representing the desired takerAsset.
* chainId: The chainId that the desired orders should be for.
*/
export interface OrderProviderRequest {
makerAssetData: string;
takerAssetData: string;
chainId: number;
}
/**
@ -111,14 +109,14 @@ export interface ForwarderSmartContractParamsBase {
export interface ForwarderMarketBuySmartContractParams
extends ExchangeMarketBuySmartContractParams,
ForwarderSmartContractParamsBase {}
ForwarderSmartContractParamsBase { }
// Temporary fix until typescript is upgraded to ^3.5
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export interface ForwarderMarketSellSmartContractParams
extends Omit<ExchangeMarketSellSmartContractParams, 'takerAssetFillAmount'>,
ForwarderSmartContractParamsBase {}
ForwarderSmartContractParamsBase { }
/**
* Represents all the parameters to interface with 0x forwarder extension contract marketSell and marketBuy functions.
@ -157,7 +155,7 @@ export interface SwapQuoteConsumerOpts {
/**
* Represents the options provided to a generic SwapQuoteConsumer
*/
export interface SwapQuoteGetOutputOptsBase {}
export interface SwapQuoteGetOutputOptsBase { }
/**
* takerAddress: The address to perform the buy. Defaults to the first available address from the provider.
@ -196,12 +194,12 @@ export interface SwapQuoteGetOutputOpts extends ForwarderSwapQuoteGetOutputOpts
useExtensionContract: ExtensionContractType;
}
export interface ForwarderSwapQuoteExecutionOpts extends ForwarderSwapQuoteGetOutputOpts, SwapQuoteExecutionOptsBase {}
export interface ForwarderSwapQuoteExecutionOpts extends ForwarderSwapQuoteGetOutputOpts, SwapQuoteExecutionOptsBase { }
/**
* Represents the options for executing a swap quote with SwapQuoteConsumer
*/
export interface SwapQuoteExecutionOpts extends SwapQuoteGetOutputOpts, ForwarderSwapQuoteExecutionOpts {}
export interface SwapQuoteExecutionOpts extends SwapQuoteGetOutputOpts, ForwarderSwapQuoteExecutionOpts { }
/**
* takerAssetData: String that represents a specific taker asset (for more info: https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md).
@ -242,9 +240,9 @@ export interface SwapQuoteWithAffiliateFeeBase {
feePercentage: number;
}
export interface MarketSellSwapQuoteWithAffiliateFee extends SwapQuoteWithAffiliateFeeBase, MarketSellSwapQuote {}
export interface MarketSellSwapQuoteWithAffiliateFee extends SwapQuoteWithAffiliateFeeBase, MarketSellSwapQuote { }
export interface MarketBuySwapQuoteWithAffiliateFee extends SwapQuoteWithAffiliateFeeBase, MarketBuySwapQuote {}
export interface MarketBuySwapQuoteWithAffiliateFee extends SwapQuoteWithAffiliateFeeBase, MarketBuySwapQuote { }
export type SwapQuoteWithAffiliateFee = MarketBuySwapQuoteWithAffiliateFee | MarketSellSwapQuoteWithAffiliateFee;

View File

@ -33,12 +33,14 @@ describe('swapQuoteCalculator', () => {
// generate one order for fees
// the fee order has a rate of 1 ZRX / WETH with no taker fee and has 100 ZRX left to fill (completely fillable)
firstOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(400),
takerAssetAmount: new BigNumber(100),
takerFee: new BigNumber(200),
});
firstRemainingFillAmount = new BigNumber(200);
secondOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(200),
takerAssetAmount: new BigNumber(100),
takerFee: new BigNumber(100),
@ -49,6 +51,7 @@ describe('swapQuoteCalculator', () => {
remainingFillableMakerAssetAmounts: [firstRemainingFillAmount, secondRemainingFillAmount],
};
const smallFeeOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(100),
takerAssetAmount: new BigNumber(100),
});
@ -57,6 +60,7 @@ describe('swapQuoteCalculator', () => {
remainingFillableMakerAssetAmounts: [smallFeeOrder.makerAssetAmount],
};
const largeFeeOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(113),
takerAssetAmount: new BigNumber(200),
takerFee: new BigNumber(11),
@ -132,6 +136,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw if not enough taker asset liquidity (completely fillable order)', () => {
const completelyFillableOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(123),
takerAssetAmount: new BigNumber(80),
takerFee: new BigNumber(200),
@ -154,6 +159,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw with 1 amount available if no slippage', () => {
const smallOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
takerFee: new BigNumber(0),
@ -172,6 +178,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw with 0 available to fill if amount rounds to 0', () => {
const smallOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
takerFee: new BigNumber(0),
@ -391,12 +398,14 @@ describe('swapQuoteCalculator', () => {
// generate one order for fees
// the fee order has a rate of 1 ZRX / WETH with no taker fee and has 100 ZRX left to fill (completely fillable)
firstOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(400),
takerAssetAmount: new BigNumber(100),
takerFee: new BigNumber(200),
});
firstRemainingFillAmount = new BigNumber(200);
secondOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(200),
takerAssetAmount: new BigNumber(100),
takerFee: new BigNumber(100),
@ -407,6 +416,7 @@ describe('swapQuoteCalculator', () => {
remainingFillableMakerAssetAmounts: [firstRemainingFillAmount, secondRemainingFillAmount],
};
const smallFeeOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(100),
takerAssetAmount: new BigNumber(100),
});
@ -415,6 +425,7 @@ describe('swapQuoteCalculator', () => {
remainingFillableMakerAssetAmounts: [smallFeeOrder.makerAssetAmount],
};
const largeFeeOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(113),
takerAssetAmount: new BigNumber(200),
takerFee: new BigNumber(11),
@ -490,6 +501,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw if not enough maker asset liquidity (completely fillable order)', () => {
const completelyFillableOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(123),
takerAssetAmount: new BigNumber(100),
takerFee: new BigNumber(200),
@ -512,6 +524,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw with 1 amount available if no slippage', () => {
const smallOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
takerFee: new BigNumber(0),
@ -530,6 +543,7 @@ describe('swapQuoteCalculator', () => {
});
it('should throw with 0 available to fill if amount rounds to 0', () => {
const smallOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
takerFee: new BigNumber(0),

View File

@ -155,10 +155,12 @@ describe('SwapQuoter', () => {
const sellTwoTokensFor1Weth: SignedOrder = orderFactory.createSignedOrderFromPartial({
makerAssetAmount: baseUnitAmount(2),
takerAssetAmount: baseUnitAmount(1, WETH_DECIMALS),
chainId: 42,
});
const sellTenTokensFor10Weth: SignedOrder = orderFactory.createSignedOrderFromPartial({
makerAssetAmount: baseUnitAmount(10),
takerAssetAmount: baseUnitAmount(10, WETH_DECIMALS),
chainId: 42,
});
beforeEach(() => {

View File

@ -46,6 +46,7 @@ export const getPartialSignedOrdersWithNoFees = (
makerAssetData,
takerAssetAmount: fillableAmount,
takerAssetData,
chainId: 42,
}),
);
};
@ -69,6 +70,7 @@ export const getPartialSignedOrdersWithFees = (
orderFactory.createSignedOrderFromPartial({
...order,
...{ takerFee: takerFees[index] },
chainId: 42,
}),
);
};

View File

@ -24,19 +24,23 @@ const baseUnitAmount = (unitAmount: number, decimals = TOKEN_DECIMALS): BigNumbe
describe('utils', () => {
// orders
const sellTwoTokensFor1Weth: SignedOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: baseUnitAmount(2),
takerAssetAmount: baseUnitAmount(1, WETH_DECIMALS),
});
const sellTenTokensFor10Weth: SignedOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: baseUnitAmount(10),
takerAssetAmount: baseUnitAmount(10, WETH_DECIMALS),
});
const sellTwoTokensFor1WethWithTwoTokenFee: SignedOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: baseUnitAmount(2),
takerAssetAmount: baseUnitAmount(1, WETH_DECIMALS),
takerFee: baseUnitAmount(2),
});
const sellTenTokensFor1WethWithFourTokenFee: SignedOrder = orderFactory.createSignedOrderFromPartial({
chainId: 42,
makerAssetAmount: baseUnitAmount(2),
takerAssetAmount: baseUnitAmount(1, WETH_DECIMALS),
takerFee: baseUnitAmount(4),

View File

@ -36,7 +36,6 @@ import * as relayerApiOrdersChannelSubscribeSchema from '../schemas/relayer_api_
import * as relayerApiOrdersChannelUpdateSchema from '../schemas/relayer_api_orders_channel_update_response_schema.json';
import * as relayerApiOrdersResponseSchema from '../schemas/relayer_api_orders_response_schema.json';
import * as relayerApiOrdersSchema from '../schemas/relayer_api_orders_schema.json';
import * as requestOptsSchema from '../schemas/request_opts_schema.json';
import * as signedOrderSchema from '../schemas/signed_order_schema.json';
import * as signedOrdersSchema from '../schemas/signed_orders_schema.json';
import * as tokenSchema from '../schemas/token_schema.json';
@ -66,7 +65,6 @@ export const schemas = {
blockRangeSchema,
tokenSchema,
jsNumber,
requestOptsSchema,
pagedRequestOptsSchema,
ordersRequestOptsSchema,
orderBookRequestSchema,

View File

@ -5,7 +5,10 @@
"rootDir": ".",
"resolveJsonModule": true
},
"include": ["./src/**/*", "./test/**/*"],
"include": [
"./src/**/*",
"./test/**/*"
],
"files": [
"./schemas/address_schema.json",
"./schemas/number_schema.json",
@ -50,7 +53,6 @@
"./schemas/orderbook_request_schema.json",
"./schemas/orders_request_opts_schema.json",
"./schemas/paged_request_opts_schema.json",
"./schemas/request_opts_schema.json",
"./schemas/order_config_request_schema.json"
]
}