Ran prettier

This commit is contained in:
F. Eugene Aumson 2020-10-14 12:01:10 -04:00
parent 2db52c6983
commit 05b25c6229
No known key found for this signature in database
GPG Key ID: 23E6737B1374A24A
4 changed files with 106 additions and 88 deletions

View File

@ -601,16 +601,27 @@ export class MarketOperationUtils {
// If RFQ liquidity is enabled, make a request to check RFQ liquidity // If RFQ liquidity is enabled, make a request to check RFQ liquidity
const { rfqt } = _opts; const { rfqt } = _opts;
if (rfqt && rfqt.quoteRequestor && marketSideLiquidity.quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)) { if (rfqt && rfqt.quoteRequestor && marketSideLiquidity.quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)) {
// Calculate a suggested price. For now, this is simply the overall price of the aggregation. // Calculate a suggested price. For now, this is simply the overall price of the aggregation.
let comparisonPrice: BigNumber | undefined; let comparisonPrice: BigNumber | undefined;
if (optimizerResult) { if (optimizerResult) {
const totalMakerAmount = BigNumber.sum(...optimizerResult.optimizedOrders.map(order => order.makerAssetAmount)); const totalMakerAmount = BigNumber.sum(
const totalTakerAmount = BigNumber.sum(...optimizerResult.optimizedOrders.map(order => order.takerAssetAmount)); ...optimizerResult.optimizedOrders.map(order => order.makerAssetAmount),
);
const totalTakerAmount = BigNumber.sum(
...optimizerResult.optimizedOrders.map(order => order.takerAssetAmount),
);
if (totalMakerAmount.gt(0)) { if (totalMakerAmount.gt(0)) {
const totalMakerAmountUnitAmount = Web3Wrapper.toUnitAmount(totalMakerAmount, marketSideLiquidity.makerTokenDecimals); const totalMakerAmountUnitAmount = Web3Wrapper.toUnitAmount(
const totalTakerAmountUnitAmount = Web3Wrapper.toUnitAmount(totalTakerAmount, marketSideLiquidity.takerTokenDecimals); totalMakerAmount,
comparisonPrice = totalMakerAmountUnitAmount.div(totalTakerAmountUnitAmount).decimalPlaces(COMPARISON_PRICE_DECIMALS); marketSideLiquidity.makerTokenDecimals,
);
const totalTakerAmountUnitAmount = Web3Wrapper.toUnitAmount(
totalTakerAmount,
marketSideLiquidity.takerTokenDecimals,
);
comparisonPrice = totalMakerAmountUnitAmount
.div(totalTakerAmountUnitAmount)
.decimalPlaces(COMPARISON_PRICE_DECIMALS);
} }
} }

View File

@ -119,9 +119,16 @@ export class QuoteRequestor {
assetFillAmount: BigNumber, assetFillAmount: BigNumber,
comparisonPrice?: BigNumber | undefined, comparisonPrice?: BigNumber | undefined,
): TakerRequestQueryParams { ): TakerRequestQueryParams {
const { buyAmountBaseUnits, sellAmountBaseUnits, ...rest } = inferQueryParams(
const {buyAmountBaseUnits, sellAmountBaseUnits, ...rest } = inferQueryParams(marketOperation, makerAssetData, takerAssetData, assetFillAmount); marketOperation,
const requestParamsWithBigNumbers: Pick<TakerRequestQueryParams, 'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'> = { makerAssetData,
takerAssetData,
assetFillAmount,
);
const requestParamsWithBigNumbers: Pick<
TakerRequestQueryParams,
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'
> = {
takerAddress, takerAddress,
comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(), comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(),
...rest, ...rest,

View File

@ -694,19 +694,14 @@ describe('MarketOperationUtils tests', () => {
}); });
it('optimizer will send in a comparison price to RFQ providers', async () => { it('optimizer will send in a comparison price to RFQ providers', async () => {
// Set up mocked quote requestor, will return an order that is better // Set up mocked quote requestor, will return an order that is better
// than the best of the orders. // than the best of the orders.
const mockedQuoteRequestor = TypeMoq.Mock.ofType( const mockedQuoteRequestor = TypeMoq.Mock.ofType(QuoteRequestor, TypeMoq.MockBehavior.Loose, false, {});
QuoteRequestor,
TypeMoq.MockBehavior.Loose,
false,
{},
);
let requestedComparisonPrice: BigNumber | undefined; let requestedComparisonPrice: BigNumber | undefined;
mockedQuoteRequestor.setup( mockedQuoteRequestor
mqr => mqr.requestRfqtFirmQuotesAsync( .setup(mqr =>
mqr.requestRfqtFirmQuotesAsync(
TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(),
@ -714,7 +709,9 @@ describe('MarketOperationUtils tests', () => {
TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(),
), ),
).callback(( )
.callback(
(
_makerAssetData: string, _makerAssetData: string,
_takerAssetData: string, _takerAssetData: string,
_assetFillAmount: BigNumber, _assetFillAmount: BigNumber,
@ -723,7 +720,9 @@ describe('MarketOperationUtils tests', () => {
_options: RfqtRequestOpts, _options: RfqtRequestOpts,
) => { ) => {
requestedComparisonPrice = comparisonPrice; requestedComparisonPrice = comparisonPrice;
}).returns(async () => { },
)
.returns(async () => {
return [ return [
{ {
signedOrder: createOrder({ signedOrder: createOrder({
@ -746,13 +745,11 @@ describe('MarketOperationUtils tests', () => {
ORDER_DOMAIN, ORDER_DOMAIN,
); );
mockedMarketOpUtils.callBase = true; mockedMarketOpUtils.callBase = true;
mockedMarketOpUtils.setup( mockedMarketOpUtils
mou => mou.getMarketSellLiquidityAsync( .setup(mou =>
TypeMoq.It.isAny(), mou.getMarketSellLiquidityAsync(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
TypeMoq.It.isAny(), )
TypeMoq.It.isAny(), .returns(async () => {
),
).returns(async () => {
return { return {
dexQuotes: [], dexQuotes: [],
ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18), ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18),
@ -777,7 +774,10 @@ describe('MarketOperationUtils tests', () => {
takerTokenDecimals: 18, takerTokenDecimals: 18,
}; };
}); });
const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(ORDERS, Web3Wrapper.toBaseUnitAmount(1, 18), { const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(
ORDERS,
Web3Wrapper.toBaseUnitAmount(1, 18),
{
...DEFAULT_OPTS, ...DEFAULT_OPTS,
rfqt: { rfqt: {
isIndicative: false, isIndicative: false,
@ -788,7 +788,8 @@ describe('MarketOperationUtils tests', () => {
requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync, requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync,
} as any, } as any,
}, },
}); },
);
expect(result.optimizedOrders.length).to.eql(1); expect(result.optimizedOrders.length).to.eql(1);
// tslint:disable-next-line:no-unnecessary-type-assertion // tslint:disable-next-line:no-unnecessary-type-assertion
expect(requestedComparisonPrice!.toString()).to.eql('320'); expect(requestedComparisonPrice!.toString()).to.eql('320');

View File

@ -191,7 +191,6 @@ describe('QuoteRequestor', async () => {
}); });
}); });
describe('requestRfqtIndicativeQuotesAsync for Indicative quotes', async () => { describe('requestRfqtIndicativeQuotesAsync for Indicative quotes', async () => {
it('should optionally accept a "comparisonPrice" parameter', async () => { it('should optionally accept a "comparisonPrice" parameter', async () => {
const response = QuoteRequestor.makeQueryParameters( const response = QuoteRequestor.makeQueryParameters(
otherToken1, otherToken1,