light refactor
This commit is contained in:
parent
1c6130a492
commit
82da33d742
@ -60,10 +60,20 @@ export class EthBalanceCheckerContract extends BaseContract {
|
|||||||
// tslint:enable boolean-naming
|
// tslint:enable boolean-naming
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
<<<<<<< HEAD
|
||||||
getABIEncodedTransactionData(addresses: string[]): string {
|
getABIEncodedTransactionData(addresses: string[]): string {
|
||||||
assert.isArray('addresses', addresses);
|
assert.isArray('addresses', addresses);
|
||||||
const self = (this as any) as EthBalanceCheckerContract;
|
const self = (this as any) as EthBalanceCheckerContract;
|
||||||
const abiEncodedTransactionData = self._strictEncodeArguments('getEthBalances(address[])', [addresses]);
|
const abiEncodedTransactionData = self._strictEncodeArguments('getEthBalances(address[])', [addresses]);
|
||||||
|
=======
|
||||||
|
getABIEncodedTransactionData(
|
||||||
|
addresses: string[],
|
||||||
|
): string {
|
||||||
|
assert.isArray('addresses', addresses);
|
||||||
|
const self = this as any as EthBalanceCheckerContract;
|
||||||
|
const abiEncodedTransactionData = self._strictEncodeArguments('getEthBalances(address[])', [addresses
|
||||||
|
]);
|
||||||
|
>>>>>>> 70ce7fe82... light refactor
|
||||||
return abiEncodedTransactionData;
|
return abiEncodedTransactionData;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ContractWrappers } from '@0x/contract-wrappers';
|
import { ContractWrappers } from '@0x/contract-wrappers';
|
||||||
import { schemas } from '@0x/json-schemas';
|
import { schemas } from '@0x/json-schemas';
|
||||||
import { SignedOrder } from '@0x/order-utils';
|
import { SignedOrder } from '@0x/order-utils';
|
||||||
import { ObjectMap } from '@0x/types';
|
import { MarketOperation, ObjectMap } from '@0x/types';
|
||||||
import { BigNumber, providerUtils } from '@0x/utils';
|
import { BigNumber, providerUtils } from '@0x/utils';
|
||||||
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
|
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -138,42 +138,8 @@ export class SwapQuoter {
|
|||||||
takerAssetSellAmount: BigNumber,
|
takerAssetSellAmount: BigNumber,
|
||||||
options: Partial<SwapQuoteRequestOpts> = {},
|
options: Partial<SwapQuoteRequestOpts> = {},
|
||||||
): Promise<MarketSellSwapQuote> {
|
): Promise<MarketSellSwapQuote> {
|
||||||
const { shouldForceOrderRefresh, slippagePercentage } = _.merge(
|
assert.isBigNumber('makerAssetBuyAmount', takerAssetSellAmount);
|
||||||
{},
|
return await this._getSwapQuoteAsync(makerAssetData, takerAssetData, takerAssetSellAmount, 'marketSell', options) as MarketSellSwapQuote;
|
||||||
constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
assert.isString('makerAssetData', makerAssetData);
|
|
||||||
assert.isString('takerAssetData', takerAssetData);
|
|
||||||
assert.isBigNumber('takerAssetSellAmount', takerAssetSellAmount);
|
|
||||||
assert.isBoolean('shouldForceOrderRefresh', shouldForceOrderRefresh);
|
|
||||||
assert.isNumber('slippagePercentage', slippagePercentage);
|
|
||||||
const zrxTokenAssetData = this._getZrxTokenAssetDataOrThrow();
|
|
||||||
const isMakerAssetZrxToken = makerAssetData === zrxTokenAssetData;
|
|
||||||
// get the relevant orders for the makerAsset and fees
|
|
||||||
// if the requested assetData is ZRX, don't get the fee info
|
|
||||||
const [ordersAndFillableAmounts, feeOrdersAndFillableAmounts] = await Promise.all([
|
|
||||||
this.getOrdersAndFillableAmountsAsync(makerAssetData, takerAssetData, shouldForceOrderRefresh),
|
|
||||||
isMakerAssetZrxToken
|
|
||||||
? Promise.resolve(constants.EMPTY_ORDERS_AND_FILLABLE_AMOUNTS)
|
|
||||||
: this.getOrdersAndFillableAmountsAsync(zrxTokenAssetData, takerAssetData, shouldForceOrderRefresh),
|
|
||||||
shouldForceOrderRefresh,
|
|
||||||
]);
|
|
||||||
if (ordersAndFillableAmounts.orders.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`${
|
|
||||||
SwapQuoterError.AssetUnavailable
|
|
||||||
}: For makerAssetdata ${makerAssetData} and takerAssetdata ${takerAssetData}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const swapQuote = swapQuoteCalculator.calculateMarketSellSwapQuote(
|
|
||||||
ordersAndFillableAmounts,
|
|
||||||
feeOrdersAndFillableAmounts,
|
|
||||||
takerAssetSellAmount,
|
|
||||||
slippagePercentage,
|
|
||||||
isMakerAssetZrxToken,
|
|
||||||
);
|
|
||||||
return swapQuote;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,43 +158,8 @@ export class SwapQuoter {
|
|||||||
makerAssetBuyAmount: BigNumber,
|
makerAssetBuyAmount: BigNumber,
|
||||||
options: Partial<SwapQuoteRequestOpts> = {},
|
options: Partial<SwapQuoteRequestOpts> = {},
|
||||||
): Promise<MarketBuySwapQuote> {
|
): Promise<MarketBuySwapQuote> {
|
||||||
const { shouldForceOrderRefresh, slippagePercentage } = _.merge(
|
|
||||||
{},
|
|
||||||
constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
assert.isString('makerAssetData', makerAssetData);
|
|
||||||
assert.isString('takerAssetData', takerAssetData);
|
|
||||||
assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount);
|
assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount);
|
||||||
assert.isBoolean('shouldForceOrderRefresh', shouldForceOrderRefresh);
|
return await this._getSwapQuoteAsync(makerAssetData, takerAssetData, makerAssetBuyAmount, 'marketBuy', options) as MarketBuySwapQuote;
|
||||||
assert.isNumber('slippagePercentage', slippagePercentage);
|
|
||||||
const zrxTokenAssetData = this._getZrxTokenAssetDataOrThrow();
|
|
||||||
const isMakerAssetZrxToken = makerAssetData === zrxTokenAssetData;
|
|
||||||
// get the relevant orders for the makerAsset and fees
|
|
||||||
// if the requested assetData is ZRX, don't get the fee info
|
|
||||||
const [ordersAndFillableAmounts, feeOrdersAndFillableAmounts] = await Promise.all([
|
|
||||||
this.getOrdersAndFillableAmountsAsync(makerAssetData, takerAssetData, shouldForceOrderRefresh),
|
|
||||||
isMakerAssetZrxToken
|
|
||||||
? Promise.resolve(constants.EMPTY_ORDERS_AND_FILLABLE_AMOUNTS)
|
|
||||||
: this.getOrdersAndFillableAmountsAsync(zrxTokenAssetData, takerAssetData, shouldForceOrderRefresh),
|
|
||||||
shouldForceOrderRefresh,
|
|
||||||
]);
|
|
||||||
if (ordersAndFillableAmounts.orders.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`${
|
|
||||||
SwapQuoterError.AssetUnavailable
|
|
||||||
}: For makerAssetdata ${makerAssetData} and takerAssetdata ${takerAssetData}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const swapQuote = swapQuoteCalculator.calculateMarketBuySwapQuote(
|
|
||||||
ordersAndFillableAmounts,
|
|
||||||
feeOrdersAndFillableAmounts,
|
|
||||||
makerAssetBuyAmount,
|
|
||||||
slippagePercentage,
|
|
||||||
isMakerAssetZrxToken,
|
|
||||||
);
|
|
||||||
|
|
||||||
return swapQuote;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get a `SwapQuote` containing all information relevant to fulfilling a swap between a desired ERC20 token address and ERC20 owned by a provided address.
|
* Get a `SwapQuote` containing all information relevant to fulfilling a swap between a desired ERC20 token address and ERC20 owned by a provided address.
|
||||||
@ -431,4 +362,62 @@ export class SwapQuoter {
|
|||||||
private _getZrxTokenAssetDataOrThrow(): string {
|
private _getZrxTokenAssetDataOrThrow(): string {
|
||||||
return this._contractWrappers.exchange.getZRXAssetData();
|
return this._contractWrappers.exchange.getZRXAssetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _getSwapQuoteAsync(
|
||||||
|
makerAssetData: string,
|
||||||
|
takerAssetData: string,
|
||||||
|
assetFillAmount: BigNumber,
|
||||||
|
marketOperation: MarketOperation,
|
||||||
|
options: Partial<SwapQuoteRequestOpts>): Promise<SwapQuote> {
|
||||||
|
const { shouldForceOrderRefresh, slippagePercentage } = _.merge(
|
||||||
|
{},
|
||||||
|
constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
assert.isString('makerAssetData', makerAssetData);
|
||||||
|
assert.isString('takerAssetData', takerAssetData);
|
||||||
|
assert.isBoolean('shouldForceOrderRefresh', shouldForceOrderRefresh);
|
||||||
|
assert.isNumber('slippagePercentage', slippagePercentage);
|
||||||
|
const zrxTokenAssetData = this._getZrxTokenAssetDataOrThrow();
|
||||||
|
const isMakerAssetZrxToken = makerAssetData === zrxTokenAssetData;
|
||||||
|
// get the relevant orders for the makerAsset and fees
|
||||||
|
// if the requested assetData is ZRX, don't get the fee info
|
||||||
|
const [ordersAndFillableAmounts, feeOrdersAndFillableAmounts] = await Promise.all([
|
||||||
|
this.getOrdersAndFillableAmountsAsync(makerAssetData, takerAssetData, shouldForceOrderRefresh),
|
||||||
|
isMakerAssetZrxToken
|
||||||
|
? Promise.resolve(constants.EMPTY_ORDERS_AND_FILLABLE_AMOUNTS)
|
||||||
|
: this.getOrdersAndFillableAmountsAsync(zrxTokenAssetData, takerAssetData, shouldForceOrderRefresh),
|
||||||
|
shouldForceOrderRefresh,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (ordersAndFillableAmounts.orders.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`${
|
||||||
|
SwapQuoterError.AssetUnavailable
|
||||||
|
}: For makerAssetdata ${makerAssetData} and takerAssetdata ${takerAssetData}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let swapQuote: SwapQuote;
|
||||||
|
|
||||||
|
if (marketOperation === 'marketBuy') {
|
||||||
|
swapQuote = swapQuoteCalculator.calculateMarketBuySwapQuote(
|
||||||
|
ordersAndFillableAmounts,
|
||||||
|
feeOrdersAndFillableAmounts,
|
||||||
|
assetFillAmount,
|
||||||
|
slippagePercentage,
|
||||||
|
isMakerAssetZrxToken,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
swapQuote = swapQuoteCalculator.calculateMarketSellSwapQuote(
|
||||||
|
ordersAndFillableAmounts,
|
||||||
|
feeOrdersAndFillableAmounts,
|
||||||
|
assetFillAmount,
|
||||||
|
slippagePercentage,
|
||||||
|
isMakerAssetZrxToken,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return swapQuote;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,6 @@ export interface SmartContractParamsBase {
|
|||||||
signatures: string[];
|
signatures: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MarketOperation = 'marketBuy' | 'marketSell';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* orders: An array of objects conforming to SignedOrder. These orders can be used to cover the requested assetBuyAmount plus slippage.
|
* orders: An array of objects conforming to SignedOrder. These orders can be used to cover the requested assetBuyAmount plus slippage.
|
||||||
* makerAssetFillAmount: The amount of makerAsset to swap for.
|
* makerAssetFillAmount: The amount of makerAsset to swap for.
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { marketUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
|
import { marketUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
|
import { MarketOperation } from '@0x/types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { constants } from '../constants';
|
import { constants } from '../constants';
|
||||||
import { InsufficientAssetLiquidityError } from '../errors';
|
import { InsufficientAssetLiquidityError } from '../errors';
|
||||||
import {
|
import {
|
||||||
MarketBuySwapQuote,
|
MarketBuySwapQuote,
|
||||||
MarketOperation,
|
|
||||||
MarketSellSwapQuote,
|
MarketSellSwapQuote,
|
||||||
OrdersAndFillableAmounts,
|
OrdersAndFillableAmounts,
|
||||||
SwapQuote,
|
SwapQuote,
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
|
import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
|
||||||
import { SignedOrder } from '@0x/types';
|
import { SignedOrder, MarketOperation } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { MarketOperation, SwapQuote } from '../../src/types';
|
import { SwapQuote } from '../../src/types';
|
||||||
|
|
||||||
const ZERO_BIG_NUMBER = new BigNumber(0);
|
const ZERO_BIG_NUMBER = new BigNumber(0);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { schemas } from '@0x/json-schemas';
|
import { schemas } from '@0x/json-schemas';
|
||||||
import { Order } from '@0x/types';
|
import { MarketOperation, Order } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
@ -10,7 +10,6 @@ import {
|
|||||||
FindFeeOrdersThatCoverFeesForTargetOrdersOpts,
|
FindFeeOrdersThatCoverFeesForTargetOrdersOpts,
|
||||||
FindOrdersThatCoverMakerAssetFillAmountOpts,
|
FindOrdersThatCoverMakerAssetFillAmountOpts,
|
||||||
FindOrdersThatCoverTakerAssetFillAmountOpts,
|
FindOrdersThatCoverTakerAssetFillAmountOpts,
|
||||||
MarketOperation,
|
|
||||||
OrdersAndRemainingMakerFillAmount,
|
OrdersAndRemainingMakerFillAmount,
|
||||||
OrdersAndRemainingTakerFillAmount,
|
OrdersAndRemainingTakerFillAmount,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
@ -49,8 +49,6 @@ export interface FindOrdersThatCoverTakerAssetFillAmountOpts {
|
|||||||
slippageBufferAmount?: BigNumber;
|
slippageBufferAmount?: BigNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MarketOperation = 'marketSell' | 'marketBuy';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remainingFillableMakerAssetAmount: An array of BigNumbers corresponding to the `orders` parameter.
|
* remainingFillableMakerAssetAmount: An array of BigNumbers corresponding to the `orders` parameter.
|
||||||
* You can use `OrderStateUtils` `@0x/order-utils` to perform blockchain lookups for these values.
|
* You can use `OrderStateUtils` `@0x/order-utils` to perform blockchain lookups for these values.
|
||||||
|
@ -41,6 +41,8 @@ export interface SignedOrder extends Order {
|
|||||||
signature: string;
|
signature: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type MarketOperation = 'marketBuy' | 'marketSell';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZeroExTransaction for use with 0x Exchange executeTransaction
|
* ZeroExTransaction for use with 0x Exchange executeTransaction
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user