add exchange proxy overhead penalty to comparison price (#156)

* add exchange proxy overhead penalty to comparison price

* prettier
This commit is contained in:
Alex Kroeger
2021-02-23 17:32:15 -08:00
committed by GitHub
parent 514f9d2621
commit 74b240fb88
3 changed files with 46 additions and 8 deletions

View File

@@ -5,8 +5,15 @@ import * as _ from 'lodash';
import { MarketOperation } from '../../types';
import { COMPARISON_PRICE_DECIMALS } from './constants';
import { ComparisonPrice, ERC20BridgeSource, FeeEstimate, FeeSchedule, MarketSideLiquidity } from './types';
import { COMPARISON_PRICE_DECIMALS, SOURCE_FLAGS } from './constants';
import {
ComparisonPrice,
ERC20BridgeSource,
ExchangeProxyOverhead,
FeeEstimate,
FeeSchedule,
MarketSideLiquidity,
} from './types';
/**
* Takes in an optimizer response and returns a price for RFQT MMs to beat
@@ -23,6 +30,7 @@ export function getComparisonPrices(
amount: BigNumber,
marketSideLiquidity: MarketSideLiquidity,
feeSchedule: FeeSchedule,
exchangeProxyOverhead: ExchangeProxyOverhead,
): ComparisonPrice {
let wholeOrder: BigNumber | undefined;
let feeInEth: BigNumber | number;
@@ -39,9 +47,11 @@ export function getComparisonPrices(
return { wholeOrder };
} else {
try {
feeInEth = new BigNumber(
const fillFeeInEth = new BigNumber(
(feeSchedule[ERC20BridgeSource.Native] as FeeEstimate)({ type: FillQuoteTransformerOrderType.Rfq }),
);
const exchangeProxyOverheadInEth = new BigNumber(exchangeProxyOverhead(SOURCE_FLAGS.Native));
feeInEth = fillFeeInEth.plus(exchangeProxyOverheadInEth);
} catch {
logUtils.warn('Native order fee schedule requires fill data');

View File

@@ -612,6 +612,7 @@ export class MarketOperationUtils {
amount,
marketSideLiquidity,
_opts.feeSchedule,
_opts.exchangeProxyOverhead,
).wholeOrder;
}

View File

@@ -4,6 +4,7 @@ import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
import { SOURCE_FLAGS } from '../src';
import { MarketOperation } from '../src/types';
import { getComparisonPrices } from '../src/utils/market_operation_utils/comparison_price';
import { SourceFilters } from '../src/utils/market_operation_utils/source_filters';
@@ -38,6 +39,14 @@ const feeSchedule = {
[ERC20BridgeSource.Native]: _.constant(GAS_PRICE.times(NATIVE_ORDER_FEE)),
};
const exchangeProxyOverhead = (sourceFlags: number) => {
if ([SOURCE_FLAGS.Native].includes(sourceFlags)) {
return new BigNumber(150e3).times(GAS_PRICE);
} else {
return new BigNumber(200e3).times(GAS_PRICE);
}
};
const buyMarketSideLiquidity: MarketSideLiquidity = {
// needed params
ethToOutputRate: new BigNumber(500),
@@ -89,10 +98,16 @@ describe('getComparisonPrices', async () => {
// raw maker over taker rate, let's say is 500 flat
const adjustedRate = new BigNumber(500);
const comparisonPrices = getComparisonPrices(adjustedRate, AMOUNT, sellMarketSideLiquidity, feeSchedule);
const comparisonPrices = getComparisonPrices(
adjustedRate,
AMOUNT,
sellMarketSideLiquidity,
feeSchedule,
exchangeProxyOverhead,
);
// expected outcome
const EXPECTED_PRICE = new BigNumber('500.55');
const EXPECTED_PRICE = new BigNumber('500.925');
expect(comparisonPrices.wholeOrder).to.deep.eq(EXPECTED_PRICE);
});
@@ -105,10 +120,16 @@ describe('getComparisonPrices', async () => {
// raw maker over taker rate, let's say is ETH/DAI rate is 500 flat
const adjustedRate = new BigNumber(1).dividedBy(new BigNumber(500));
const comparisonPrices = getComparisonPrices(adjustedRate, AMOUNT, buyMarketSideLiquidity, feeSchedule);
const comparisonPrices = getComparisonPrices(
adjustedRate,
AMOUNT,
buyMarketSideLiquidity,
feeSchedule,
exchangeProxyOverhead,
);
// expected outcome
const EXPECTED_PRICE = new BigNumber('0.0020022024');
const EXPECTED_PRICE = new BigNumber('0.0020037069');
expect(comparisonPrices.wholeOrder).to.deep.eq(EXPECTED_PRICE);
});
@@ -119,7 +140,13 @@ describe('getComparisonPrices', async () => {
// raw maker over taker rate, let's say is 500 flat
const adjustedRate = new BigNumber(500);
const comparisonPrices = getComparisonPrices(adjustedRate, AMOUNT, sellMarketSideLiquidity, feeSchedule);
const comparisonPrices = getComparisonPrices(
adjustedRate,
AMOUNT,
sellMarketSideLiquidity,
feeSchedule,
exchangeProxyOverhead,
);
expect(comparisonPrices.wholeOrder === undefined);
});