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
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -694,47 +694,46 @@ 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 =>
|
||||||
TypeMoq.It.isAny(),
|
mqr.requestRfqtFirmQuotesAsync(
|
||||||
TypeMoq.It.isAny(),
|
TypeMoq.It.isAny(),
|
||||||
TypeMoq.It.isAny(),
|
TypeMoq.It.isAny(),
|
||||||
TypeMoq.It.isAny(),
|
TypeMoq.It.isAny(),
|
||||||
TypeMoq.It.isAny(),
|
TypeMoq.It.isAny(),
|
||||||
TypeMoq.It.isAny(),
|
TypeMoq.It.isAny(),
|
||||||
),
|
TypeMoq.It.isAny(),
|
||||||
).callback((
|
),
|
||||||
_makerAssetData: string,
|
)
|
||||||
_takerAssetData: string,
|
.callback(
|
||||||
_assetFillAmount: BigNumber,
|
(
|
||||||
_marketOperation: MarketOperation,
|
_makerAssetData: string,
|
||||||
comparisonPrice: BigNumber | undefined,
|
_takerAssetData: string,
|
||||||
_options: RfqtRequestOpts,
|
_assetFillAmount: BigNumber,
|
||||||
) => {
|
_marketOperation: MarketOperation,
|
||||||
requestedComparisonPrice = comparisonPrice;
|
comparisonPrice: BigNumber | undefined,
|
||||||
}).returns(async () => {
|
_options: RfqtRequestOpts,
|
||||||
return [
|
) => {
|
||||||
{
|
requestedComparisonPrice = comparisonPrice;
|
||||||
signedOrder: createOrder({
|
|
||||||
makerAssetData: MAKER_ASSET_DATA,
|
|
||||||
takerAssetData: TAKER_ASSET_DATA,
|
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(321, 6),
|
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
];
|
)
|
||||||
});
|
.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
|
// Set up sampler, will only return 1 on-chain order
|
||||||
const mockedMarketOpUtils = TypeMoq.Mock.ofType(
|
const mockedMarketOpUtils = TypeMoq.Mock.ofType(
|
||||||
@ -746,49 +745,51 @@ 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 () => {
|
||||||
),
|
return {
|
||||||
).returns(async () => {
|
dexQuotes: [],
|
||||||
return {
|
ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||||
dexQuotes: [],
|
ethToOutputRate: Web3Wrapper.toBaseUnitAmount(1, 6),
|
||||||
ethToInputRate: Web3Wrapper.toBaseUnitAmount(1, 18),
|
inputAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||||
ethToOutputRate: Web3Wrapper.toBaseUnitAmount(1, 6),
|
inputToken: MAKER_TOKEN,
|
||||||
inputAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
outputToken: TAKER_TOKEN,
|
||||||
inputToken: MAKER_TOKEN,
|
nativeOrders: [
|
||||||
outputToken: TAKER_TOKEN,
|
createOrder({
|
||||||
nativeOrders: [
|
makerAssetData: MAKER_ASSET_DATA,
|
||||||
createOrder({
|
takerAssetData: TAKER_ASSET_DATA,
|
||||||
makerAssetData: MAKER_ASSET_DATA,
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(320, 6),
|
||||||
takerAssetData: TAKER_ASSET_DATA,
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(320, 6),
|
}),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 18),
|
],
|
||||||
}),
|
orderFillableAmounts: [Web3Wrapper.toBaseUnitAmount(1, 18)],
|
||||||
],
|
rfqtIndicativeQuotes: [],
|
||||||
orderFillableAmounts: [Web3Wrapper.toBaseUnitAmount(1, 18)],
|
side: MarketOperation.Sell,
|
||||||
rfqtIndicativeQuotes: [],
|
twoHopQuotes: [],
|
||||||
side: MarketOperation.Sell,
|
quoteSourceFilters: new SourceFilters(),
|
||||||
twoHopQuotes: [],
|
makerTokenDecimals: 6,
|
||||||
quoteSourceFilters: new SourceFilters(),
|
takerTokenDecimals: 18,
|
||||||
makerTokenDecimals: 6,
|
};
|
||||||
takerTokenDecimals: 18,
|
});
|
||||||
};
|
const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(
|
||||||
});
|
ORDERS,
|
||||||
const result = await mockedMarketOpUtils.object.getMarketSellOrdersAsync(ORDERS, Web3Wrapper.toBaseUnitAmount(1, 18), {
|
Web3Wrapper.toBaseUnitAmount(1, 18),
|
||||||
...DEFAULT_OPTS,
|
{
|
||||||
rfqt: {
|
...DEFAULT_OPTS,
|
||||||
isIndicative: false,
|
rfqt: {
|
||||||
apiKey: 'foo',
|
isIndicative: false,
|
||||||
takerAddress: randomAddress(),
|
apiKey: 'foo',
|
||||||
intentOnFilling: true,
|
takerAddress: randomAddress(),
|
||||||
quoteRequestor: {
|
intentOnFilling: true,
|
||||||
requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync,
|
quoteRequestor: {
|
||||||
} as any,
|
requestRfqtFirmQuotesAsync: mockedQuoteRequestor.object.requestRfqtFirmQuotesAsync,
|
||||||
|
} 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');
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user