diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts b/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts index 195d1a862c..3b81620efa 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts @@ -60,10 +60,20 @@ export class EthBalanceCheckerContract extends BaseContract { // tslint:enable boolean-naming return result; }, +<<<<<<< HEAD getABIEncodedTransactionData(addresses: string[]): string { assert.isArray('addresses', addresses); const self = (this as any) as EthBalanceCheckerContract; 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; }, }; diff --git a/packages/asset-buyer/src/swap_quoter.ts b/packages/asset-buyer/src/swap_quoter.ts index 5858aedcfb..33657779b2 100644 --- a/packages/asset-buyer/src/swap_quoter.ts +++ b/packages/asset-buyer/src/swap_quoter.ts @@ -1,7 +1,7 @@ import { ContractWrappers } from '@0x/contract-wrappers'; import { schemas } from '@0x/json-schemas'; import { SignedOrder } from '@0x/order-utils'; -import { ObjectMap } from '@0x/types'; +import { MarketOperation, ObjectMap } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { SupportedProvider, ZeroExProvider } from 'ethereum-types'; import * as _ from 'lodash'; @@ -138,42 +138,8 @@ export class SwapQuoter { takerAssetSellAmount: BigNumber, options: Partial = {}, ): Promise { - const { shouldForceOrderRefresh, slippagePercentage } = _.merge( - {}, - 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; + assert.isBigNumber('makerAssetBuyAmount', takerAssetSellAmount); + return await this._getSwapQuoteAsync(makerAssetData, takerAssetData, takerAssetSellAmount, 'marketSell', options) as MarketSellSwapQuote; } /** @@ -192,43 +158,8 @@ export class SwapQuoter { makerAssetBuyAmount: BigNumber, options: Partial = {}, ): Promise { - const { shouldForceOrderRefresh, slippagePercentage } = _.merge( - {}, - constants.DEFAULT_SWAP_QUOTE_REQUEST_OPTS, - options, - ); - assert.isString('makerAssetData', makerAssetData); - assert.isString('takerAssetData', takerAssetData); assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount); - 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.calculateMarketBuySwapQuote( - ordersAndFillableAmounts, - feeOrdersAndFillableAmounts, - makerAssetBuyAmount, - slippagePercentage, - isMakerAssetZrxToken, - ); - - return swapQuote; + return await this._getSwapQuoteAsync(makerAssetData, takerAssetData, makerAssetBuyAmount, 'marketBuy', options) as MarketBuySwapQuote; } /** * 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 { return this._contractWrappers.exchange.getZRXAssetData(); } + + private async _getSwapQuoteAsync( + makerAssetData: string, + takerAssetData: string, + assetFillAmount: BigNumber, + marketOperation: MarketOperation, + options: Partial): Promise { + 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; + } } diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index 8a606c0ad6..1edffa9382 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -71,8 +71,6 @@ export interface SmartContractParamsBase { 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. * makerAssetFillAmount: The amount of makerAsset to swap for. diff --git a/packages/asset-buyer/src/utils/swap_quote_calculator.ts b/packages/asset-buyer/src/utils/swap_quote_calculator.ts index fc411bc001..6bbb7aacfd 100644 --- a/packages/asset-buyer/src/utils/swap_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/swap_quote_calculator.ts @@ -1,12 +1,12 @@ import { marketUtils, orderCalculationUtils, SignedOrder } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; +import { MarketOperation } from '@0x/types'; import * as _ from 'lodash'; import { constants } from '../constants'; import { InsufficientAssetLiquidityError } from '../errors'; import { MarketBuySwapQuote, - MarketOperation, MarketSellSwapQuote, OrdersAndFillableAmounts, SwapQuote, diff --git a/packages/asset-buyer/test/utils/swap_quote.ts b/packages/asset-buyer/test/utils/swap_quote.ts index cf07ca39ef..2b6f5d0643 100644 --- a/packages/asset-buyer/test/utils/swap_quote.ts +++ b/packages/asset-buyer/test/utils/swap_quote.ts @@ -1,9 +1,9 @@ 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 * as _ from 'lodash'; -import { MarketOperation, SwapQuote } from '../../src/types'; +import { SwapQuote } from '../../src/types'; const ZERO_BIG_NUMBER = new BigNumber(0); diff --git a/packages/order-utils/src/market_utils.ts b/packages/order-utils/src/market_utils.ts index 4370d09ddf..efc97c5530 100644 --- a/packages/order-utils/src/market_utils.ts +++ b/packages/order-utils/src/market_utils.ts @@ -1,5 +1,5 @@ import { schemas } from '@0x/json-schemas'; -import { Order } from '@0x/types'; +import { MarketOperation, Order } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; @@ -10,7 +10,6 @@ import { FindFeeOrdersThatCoverFeesForTargetOrdersOpts, FindOrdersThatCoverMakerAssetFillAmountOpts, FindOrdersThatCoverTakerAssetFillAmountOpts, - MarketOperation, OrdersAndRemainingMakerFillAmount, OrdersAndRemainingTakerFillAmount, } from './types'; diff --git a/packages/order-utils/src/types.ts b/packages/order-utils/src/types.ts index fd48114270..c58eafe036 100644 --- a/packages/order-utils/src/types.ts +++ b/packages/order-utils/src/types.ts @@ -49,8 +49,6 @@ export interface FindOrdersThatCoverTakerAssetFillAmountOpts { slippageBufferAmount?: BigNumber; } -export type MarketOperation = 'marketSell' | 'marketBuy'; - /** * remainingFillableMakerAssetAmount: An array of BigNumbers corresponding to the `orders` parameter. * You can use `OrderStateUtils` `@0x/order-utils` to perform blockchain lookups for these values. diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index a182e995f6..7bc1ff4d9a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -41,6 +41,8 @@ export interface SignedOrder extends Order { signature: string; } +export type MarketOperation = 'marketBuy' | 'marketSell'; + /** * ZeroExTransaction for use with 0x Exchange executeTransaction */