Jacob Evans 4f82543bdf
feat: asset-swapper tweak the gas schedule + return decimals (#34)
* feat: asset-swapper Return decimals from sampler in quote

* feat: asset-swapper tweak the gas schedule

* fix lint

* CHANGELOG
2020-11-17 11:36:53 +10:00

62 lines
1.9 KiB
TypeScript

import { BigNumber } from '@0x/utils';
import { ERC20BridgeSource } from '../../src';
import { constants } from '../../src/constants';
import { MarketOperation, SignedOrderWithFillableAmounts, SwapQuote } from '../../src/types';
/**
* Creates a swap quote given orders.
*/
export async function getFullyFillableSwapQuoteWithNoFeesAsync(
makerAssetData: string,
takerAssetData: string,
orders: SignedOrderWithFillableAmounts[],
operation: MarketOperation,
gasPrice: BigNumber,
): Promise<SwapQuote> {
const makerAssetFillAmount = BigNumber.sum(...[0, ...orders.map(o => o.makerAssetAmount)]);
const totalTakerAssetAmount = BigNumber.sum(...[0, ...orders.map(o => o.takerAssetAmount)]);
const protocolFeePerOrder = constants.PROTOCOL_FEE_MULTIPLIER.times(gasPrice);
const quoteInfo = {
makerAssetAmount: makerAssetFillAmount,
feeTakerAssetAmount: constants.ZERO_AMOUNT,
takerAssetAmount: totalTakerAssetAmount,
totalTakerAssetAmount,
protocolFeeInWeiAmount: protocolFeePerOrder.times(orders.length),
gas: 200e3,
};
const breakdown = {
[ERC20BridgeSource.Native]: new BigNumber(1),
};
const quoteBase = {
makerAssetData,
takerAssetData,
orders: orders.map(order => ({ ...order, fills: [] })),
gasPrice,
bestCaseQuoteInfo: quoteInfo,
worstCaseQuoteInfo: quoteInfo,
sourceBreakdown: breakdown,
isTwoHop: false,
};
if (operation === MarketOperation.Buy) {
return {
...quoteBase,
type: MarketOperation.Buy,
makerAssetFillAmount,
makerTokenDecimals: 18,
takerTokenDecimals: 18,
};
} else {
return {
...quoteBase,
type: MarketOperation.Sell,
takerAssetFillAmount: totalTakerAssetAmount,
makerTokenDecimals: 18,
takerTokenDecimals: 18,
};
}
}