Skip to content

Commit

Permalink
Added debug logs for v2 quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
willpote committed Jan 11, 2022
1 parent c4ea0c5 commit 7ecc886
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/providers/v2/quote-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
import { BigNumber } from 'ethers';
import { V2Route } from '../../routers/router';
import { CurrencyAmount } from '../../util/amounts';
import { log } from '../../util/log';
import { routeToString } from '../../util/routes';

// Quotes can be null (e.g. pool did not have enough liquidity).
export type V2AmountQuote = {
Expand Down Expand Up @@ -58,9 +60,12 @@ export class V2QuoteProvider implements IV2QuoteProvider {
): Promise<{ routesWithQuotes: V2RouteWithQuotes[] }> {
const routesWithQuotes: V2RouteWithQuotes[] = [];

let debugStrs: string[] = [];
for (const route of routes) {
const amountQuotes: V2AmountQuote[] = [];

let insufficientInputAmountErrorCount = 0;
let insufficientReservesErrorCount = 0;
for (const amount of amounts) {
try {
if (tradeType == TradeType.EXACT_INPUT) {
Expand Down Expand Up @@ -90,19 +95,36 @@ export class V2QuoteProvider implements IV2QuoteProvider {
}
} catch (err) {
// Can fail to get quotes, e.g. throws InsufficientReservesError or InsufficientInputAmountError.
if (
err instanceof InsufficientInputAmountError ||
err instanceof InsufficientReservesError
) {
if (err instanceof InsufficientInputAmountError) {
insufficientInputAmountErrorCount =
insufficientInputAmountErrorCount + 1;
amountQuotes.push({ amount, quote: null });
} else if (err instanceof InsufficientReservesError) {
insufficientReservesErrorCount = insufficientReservesErrorCount + 1;
amountQuotes.push({ amount, quote: null });
} else {
throw err;
}
}
}

if (
insufficientInputAmountErrorCount > 0 ||
insufficientReservesErrorCount > 0
) {
debugStrs.push(
`${[
routeToString(route),
]} Input: ${insufficientInputAmountErrorCount} Reserves: ${insufficientReservesErrorCount} }`
);
}

routesWithQuotes.push([route, amountQuotes]);
}

if (debugStrs.length > 0) {
log.info({ debugStrs }, `Failed quotes for V2 routes`);
}

return {
routesWithQuotes,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/v3/quote-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ export class V3QuoteProvider implements IV3QuoteProvider {
(amounts, routeStr) => `${routeStr} : ${amounts}`
),
},
`Failed quotes for routes Part ${idx}/${Math.ceil(
`Failed quotes for V3 routes Part ${idx}/${Math.ceil(
debugFailedQuotes.length / debugChunk
)}`
);
Expand Down

0 comments on commit 7ecc886

Please sign in to comment.