Ran prettier
This commit is contained in:
parent
2db52c6983
commit
05b25c6229
@ -601,16 +601,27 @@ export class MarketOperationUtils {
|
||||
// If RFQ liquidity is enabled, make a request to check RFQ liquidity
|
||||
const { rfqt } = _opts;
|
||||
if (rfqt && rfqt.quoteRequestor && marketSideLiquidity.quoteSourceFilters.isAllowed(ERC20BridgeSource.Native)) {
|
||||
|
||||
// Calculate a suggested price. For now, this is simply the overall price of the aggregation.
|
||||
let comparisonPrice: BigNumber | undefined;
|
||||
if (optimizerResult) {
|
||||
const totalMakerAmount = BigNumber.sum(...optimizerResult.optimizedOrders.map(order => order.makerAssetAmount));
|
||||
const totalTakerAmount = BigNumber.sum(...optimizerResult.optimizedOrders.map(order => order.takerAssetAmount));
|
||||
const totalMakerAmount = BigNumber.sum(
|
||||
...optimizerResult.optimizedOrders.map(order => order.makerAssetAmount),
|
||||
);
|
||||
const totalTakerAmount = BigNumber.sum(
|
||||
...optimizerResult.optimizedOrders.map(order => order.takerAssetAmount),
|
||||
);
|
||||
if (totalMakerAmount.gt(0)) {
|
||||
const totalMakerAmountUnitAmount = Web3Wrapper.toUnitAmount(totalMakerAmount, marketSideLiquidity.makerTokenDecimals);
|
||||
const totalTakerAmountUnitAmount = Web3Wrapper.toUnitAmount(totalTakerAmount, marketSideLiquidity.takerTokenDecimals);
|
||||
comparisonPrice = totalMakerAmountUnitAmount.div(totalTakerAmountUnitAmount).decimalPlaces(COMPARISON_PRICE_DECIMALS);
|
||||
const totalMakerAmountUnitAmount = Web3Wrapper.toUnitAmount(
|
||||
totalMakerAmount,
|
||||
marketSideLiquidity.makerTokenDecimals,
|
||||
);
|
||||
const totalTakerAmountUnitAmount = Web3Wrapper.toUnitAmount(
|
||||
totalTakerAmount,
|
||||
marketSideLiquidity.takerTokenDecimals,
|
||||
);
|
||||
comparisonPrice = totalMakerAmountUnitAmount
|
||||
.div(totalTakerAmountUnitAmount)
|
||||
.decimalPlaces(COMPARISON_PRICE_DECIMALS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,9 +119,16 @@ export class QuoteRequestor {
|
||||
assetFillAmount: BigNumber,
|
||||
comparisonPrice?: BigNumber | undefined,
|
||||
): TakerRequestQueryParams {
|
||||
|
||||
const {buyAmountBaseUnits, sellAmountBaseUnits, ...rest } = inferQueryParams(marketOperation, makerAssetData, takerAssetData, assetFillAmount);
|
||||
const requestParamsWithBigNumbers: Pick<TakerRequestQueryParams, 'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'> = {
|
||||
const { buyAmountBaseUnits, sellAmountBaseUnits, ...rest } = inferQueryParams(
|
||||
marketOperation,
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
assetFillAmount,
|
||||
);
|
||||
const requestParamsWithBigNumbers: Pick<
|
||||
TakerRequestQueryParams,
|
||||
'buyTokenAddress' | 'sellTokenAddress' | 'takerAddress' | 'comparisonPrice'
|
||||
> = {
|
||||
takerAddress,
|
||||
comparisonPrice: comparisonPrice === undefined ? undefined : comparisonPrice.toString(),
|
||||
...rest,
|
||||
|
@ -694,47 +694,46 @@ describe('MarketOperationUtils tests', () => {
|
||||
});
|
||||
|
||||
it('optimizer will send in a comparison price to RFQ providers', async () => {
|
||||
|
||||
// Set up mocked quote requestor, will return an order that is better
|
||||
// than the best of the orders.
|
||||
const mockedQuoteRequestor = TypeMoq.Mock.ofType(
|
||||
QuoteRequestor,
|
||||
TypeMoq.MockBehavior.Loose,
|
||||
false,
|
||||
{},
|
||||
);
|
||||
const mockedQuoteRequestor = TypeMoq.Mock.ofType(QuoteRequestor, TypeMoq.MockBehavior.Loose, false, {});
|
||||
|
||||
let requestedComparisonPrice: BigNumber | undefined;
|
||||
mockedQuoteRequestor.setup(
|
||||
mqr => mqr.requestRfqtFirmQuotesAsync(
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
),
|
||||
).callback((
|
||||
_makerAssetData: string,
|
||||
_takerAssetData: string,
|
||||
_assetFillAmount: BigNumber,
|
||||
_marketOperation: MarketOperation,
|
||||
comparisonPrice: BigNumber | undefined,
|
||||
_options: RfqtRequestOpts,
|
||||
) => {
|
||||
requestedComparisonPrice = comparisonPrice;
|
||||
}).returns(async () => {
|
||||
return [
|
||||
{
|
||||
signedOrder: createOrder({
|
||||
makerAssetData: MAKER_ASSET_DATA,
|
||||
takerAssetData: TAKER_ASSET_DATA,
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(321, 6),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
}),
|
||||
mockedQuoteRequestor
|
||||
.setup(mqr =>
|
||||
mqr.requestRfqtFirmQuotesAsync(
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
),
|
||||
)
|
||||
.callback(
|
||||
(
|
||||
_makerAssetData: string,
|
||||
_takerAssetData: string,
|
||||
_assetFillAmount: BigNumber,
|
||||
_marketOperation: MarketOperation,
|
||||
comparisonPrice: BigNumber | undefined,
|
||||
_options: RfqtRequestOpts,
|
||||
) => {
|
||||
requestedComparisonPrice = comparisonPrice;
|
||||
},
|
||||
];
|
||||
});
|
||||
)
|
||||
.returns(async () => {
|
||||
return [
|
||||
{
|
||||
signedOrder: createOrder({
|
||||
makerAssetData: MAKER_ASSET_DATA,
|
||||
takerAssetData: TAKER_ASSET_DATA,
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(321, 6),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
}),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
// Set up sampler, will only return 1 on-chain order
|
||||
const mockedMarketOpUtils = TypeMoq.Mock.ofType(
|
||||
@ -746,49 +745,51 @@ describe('MarketOperationUtils tests', () => {
|
||||
ORDER_DOMAIN,
|
||||
);
|
||||
mockedMarketOpUtils.callBase = true;
|
||||
mockedMarketOpUtils.setup(
|
||||
mou => mou.getMarketSellLiquidityAsync(
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(),
|
||||
),
|
||||
).returns(async () => {
|
||||
return {
|
||||
dexQuotes: [],
|
||||
ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
ethToOutputRate: Web3Wrapper.toBaseUnitAmount(1, 6),
|
||||
inputAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
inputToken: MAKER_TOKEN,
|
||||
outputToken: TAKER_TOKEN,
|
||||
nativeOrders: [
|
||||
createOrder({
|
||||
makerAssetData: MAKER_ASSET_DATA,
|
||||
takerAssetData: TAKER_ASSET_DATA,
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(320, 6),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
}),
|
||||
],
|
||||
orderFillableAmounts: [Web3Wrapper.toBaseUnitAmount(1, 18)],
|
||||
rfqtIndicativeQuotes: [],
|
||||
side: MarketOperation.Sell,
|
||||
twoHopQuotes: [],
|
||||
quoteSourceFilters: new SourceFilters(),
|
||||
makerTokenDecimals: 6,
|
||||
takerTokenDecimals: 18,
|
||||
};
|
||||
});
|
||||
const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(ORDERS, Web3Wrapper.toBaseUnitAmount(1, 18), {
|
||||
...DEFAULT_OPTS,
|
||||
rfqt: {
|
||||
isIndicative: false,
|
||||
apiKey: 'foo',
|
||||
takerAddress: randomAddress(),
|
||||
intentOnFilling: true,
|
||||
quoteRequestor: {
|
||||
requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync,
|
||||
} as any,
|
||||
mockedMarketOpUtils
|
||||
.setup(mou =>
|
||||
mou.getMarketSellLiquidityAsync(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
|
||||
)
|
||||
.returns(async () => {
|
||||
return {
|
||||
dexQuotes: [],
|
||||
ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
ethToOutputRate: Web3Wrapper.toBaseUnitAmount(1, 6),
|
||||
inputAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
inputToken: MAKER_TOKEN,
|
||||
outputToken: TAKER_TOKEN,
|
||||
nativeOrders: [
|
||||
createOrder({
|
||||
makerAssetData: MAKER_ASSET_DATA,
|
||||
takerAssetData: TAKER_ASSET_DATA,
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(320, 6),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
}),
|
||||
],
|
||||
orderFillableAmounts: [Web3Wrapper.toBaseUnitAmount(1, 18)],
|
||||
rfqtIndicativeQuotes: [],
|
||||
side: MarketOperation.Sell,
|
||||
twoHopQuotes: [],
|
||||
quoteSourceFilters: new SourceFilters(),
|
||||
makerTokenDecimals: 6,
|
||||
takerTokenDecimals: 18,
|
||||
};
|
||||
});
|
||||
const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(
|
||||
ORDERS,
|
||||
Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||
{
|
||||
...DEFAULT_OPTS,
|
||||
rfqt: {
|
||||
isIndicative: false,
|
||||
apiKey: 'foo',
|
||||
takerAddress: randomAddress(),
|
||||
intentOnFilling: true,
|
||||
quoteRequestor: {
|
||||
requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync,
|
||||
} as any,
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
expect(result.optimizedOrders.length).to.eql(1);
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
expect(requestedComparisonPrice!.toString()).to.eql('320');
|
||||
|
@ -191,7 +191,6 @@ describe('QuoteRequestor', async () => {
|
||||
});
|
||||
});
|
||||
describe('requestRfqtIndicativeQuotesAsync for Indicative quotes', async () => {
|
||||
|
||||
it('should optionally accept a "comparisonPrice" parameter', async () => {
|
||||
const response = QuoteRequestor.makeQueryParameters(
|
||||
otherToken1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user