Appease linter
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.3.1",
|
||||
"@0x/contracts-gen": "^2.0.10",
|
||||
"@0x/contracts-erc20": "^3.2.1",
|
||||
"@0x/contracts-test-utils": "^5.3.4",
|
||||
"@0x/dev-utils": "^3.3.0",
|
||||
"@0x/order-utils": "^10.3.0",
|
||||
|
@@ -3,7 +3,7 @@ import { BigNumber } from '@0x/utils';
|
||||
import { SourceFilters } from './source_filters';
|
||||
import { CurveFunctionSelectors, CurveInfo, ERC20BridgeSource, GetMarketOrdersOpts } from './types';
|
||||
|
||||
// tslint:disable: custom-no-magic-numbers
|
||||
// tslint:disable: custom-no-magic-numbers no-bitwise
|
||||
|
||||
/**
|
||||
* Valid sources for market sell.
|
||||
|
@@ -143,10 +143,10 @@ function dexSamplesToFills(
|
||||
// We need not worry about Kyber fills going to UniswapReserve as the input amount
|
||||
// we fill is the same as we sampled. I.e we received [0,20,30] output from [1,2,3] input
|
||||
// and we only fill [2,3] on Kyber (as 1 returns 0 output)
|
||||
samples = samples.filter(q => !q.output.isZero());
|
||||
for (let i = 0; i < samples.length; i++) {
|
||||
const sample = samples[i];
|
||||
const prevSample = i === 0 ? undefined : samples[i - 1];
|
||||
const nonzeroSamples = samples.filter(q => !q.output.isZero());
|
||||
for (let i = 0; i < nonzeroSamples.length; i++) {
|
||||
const sample = nonzeroSamples[i];
|
||||
const prevSample = i === 0 ? undefined : nonzeroSamples[i - 1];
|
||||
const { source, fillData } = sample;
|
||||
const input = sample.input.minus(prevSample ? prevSample.input : 0);
|
||||
const output = sample.output.minus(prevSample ? prevSample.output : 0);
|
||||
|
@@ -579,7 +579,7 @@ export class MarketOperationUtils {
|
||||
ethToInputRate,
|
||||
exchangeProxyOverhead: opts.exchangeProxyOverhead || (() => ZERO_AMOUNT),
|
||||
};
|
||||
let optimalPath = await findOptimalPathAsync(side, fills, inputAmount, opts.runLimit, optimizerOpts);
|
||||
const optimalPath = await findOptimalPathAsync(side, fills, inputAmount, opts.runLimit, optimizerOpts);
|
||||
if (optimalPath === undefined) {
|
||||
throw new Error(AggregationError.NoOptimalPath);
|
||||
}
|
||||
|
@@ -46,13 +46,6 @@ export class Path {
|
||||
protected _size: PathSize = { input: ZERO_AMOUNT, output: ZERO_AMOUNT };
|
||||
protected _adjustedSize: PathSize = { input: ZERO_AMOUNT, output: ZERO_AMOUNT };
|
||||
|
||||
protected constructor(
|
||||
protected readonly side: MarketOperation,
|
||||
public fills: ReadonlyArray<Fill>,
|
||||
protected readonly targetInput: BigNumber,
|
||||
public readonly pathPenaltyOpts: PathPenaltyOpts,
|
||||
) {}
|
||||
|
||||
public static create(
|
||||
side: MarketOperation,
|
||||
fills: ReadonlyArray<Fill>,
|
||||
@@ -77,6 +70,13 @@ export class Path {
|
||||
return clonedPath;
|
||||
}
|
||||
|
||||
protected constructor(
|
||||
protected readonly side: MarketOperation,
|
||||
public fills: ReadonlyArray<Fill>,
|
||||
protected readonly targetInput: BigNumber,
|
||||
public readonly pathPenaltyOpts: PathPenaltyOpts,
|
||||
) {}
|
||||
|
||||
public append(fill: Fill): this {
|
||||
(this.fills as Fill[]).push(fill);
|
||||
this.sourceFlags |= fill.flags;
|
||||
@@ -101,7 +101,7 @@ export class Path {
|
||||
const nativeFills = this.fills.filter(f => f.source === ERC20BridgeSource.Native);
|
||||
this.fills = [...nativeFills.filter(f => f !== lastNativeFillIfExists), ...fallback.fills];
|
||||
// Recompute the source flags
|
||||
this.sourceFlags = this.fills.reduce((flags, fill) => (flags |= fill.flags), 0);
|
||||
this.sourceFlags = this.fills.reduce((flags, fill) => flags | fill.flags, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@ function mixPaths(
|
||||
pathB: Path,
|
||||
targetInput: BigNumber,
|
||||
maxSteps: number,
|
||||
rateBySourcePathId: { [id: string]: BigNumber },
|
||||
rates: { [id: string]: BigNumber },
|
||||
): Path {
|
||||
const _maxSteps = Math.max(maxSteps, 32);
|
||||
let steps = 0;
|
||||
@@ -76,7 +76,7 @@ function mixPaths(
|
||||
// chances of walking ideal, valid paths first.
|
||||
const sortedFills = allFills.sort((a, b) => {
|
||||
if (a.sourcePathId !== b.sourcePathId) {
|
||||
return rateBySourcePathId[b.sourcePathId].comparedTo(rateBySourcePathId[a.sourcePathId]);
|
||||
return rates[b.sourcePathId].comparedTo(rates[a.sourcePathId]);
|
||||
}
|
||||
return a.index - b.index;
|
||||
});
|
||||
|
@@ -5,6 +5,10 @@ import { MarketOperation } from '../../types';
|
||||
import { ZERO_AMOUNT } from './constants';
|
||||
import { DexSample, ERC20BridgeSource, FeeSchedule, MultiHopFillData } from './types';
|
||||
|
||||
/**
|
||||
* Returns the fee-adjusted rate of a two-hop quote. Returns zero if the
|
||||
* quote falls short of the target input.
|
||||
*/
|
||||
export function getTwoHopAdjustedRate(
|
||||
side: MarketOperation,
|
||||
twoHopQuote: DexSample<MultiHopFillData>,
|
||||
@@ -21,6 +25,10 @@ export function getTwoHopAdjustedRate(
|
||||
return side === MarketOperation.Sell ? adjustedOutput.div(input) : input.div(adjustedOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the "complete" rate given the input/output of a path.
|
||||
* This value penalizes the path if it falls short of the target input.
|
||||
*/
|
||||
export function getCompleteRate(
|
||||
side: MarketOperation,
|
||||
input: BigNumber,
|
||||
@@ -40,6 +48,9 @@ export function getCompleteRate(
|
||||
return input.div(output).times(input.div(targetInput));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the rate given the input/output of a path.
|
||||
*/
|
||||
export function getRate(side: MarketOperation, input: BigNumber, output: BigNumber): BigNumber {
|
||||
if (input.eq(0) || output.eq(0)) {
|
||||
return ZERO_AMOUNT;
|
||||
|
@@ -139,7 +139,7 @@ export class SwapQuoteCalculator {
|
||||
feeSchedule: _.mapValues(opts.feeSchedule, gasCost => (fillData?: FillData) =>
|
||||
gasCost === undefined ? 0 : gasPrice.times(gasCost(fillData)),
|
||||
),
|
||||
exchangeProxyOverhead: (sourceFlags: number) => gasPrice.times(opts.exchangeProxyOverhead!(sourceFlags)),
|
||||
exchangeProxyOverhead: flags => gasPrice.times(opts.exchangeProxyOverhead(flags)),
|
||||
};
|
||||
|
||||
const firstOrderMakerAssetData = !!prunedOrders[0]
|
||||
|
Reference in New Issue
Block a user