Skip to content

Commit

Permalink
fix: improve quote provider logging & update sepolia quoter address (U…
Browse files Browse the repository at this point in the history
…niswap#547)

* improve quote provider logging

* fix minor string placeholder

* revert unintended lodash import

* revert unintended lodash import

* add override quoter address definedness check to be consistent
  • Loading branch information
jsy1218 authored Apr 22, 2024
1 parent 5255334 commit f73799d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 18 deletions.
83 changes: 66 additions & 17 deletions src/providers/on-chain-quote-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,26 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
// In alpha-router default case, we will also define the constants with same values as below.
protected successRateFailureOverrides: FailureOverrides = DEFAULT_SUCCESS_RATE_FAILURE_OVERRIDES,
protected blockNumberConfig: BlockNumberConfig = DEFAULT_BLOCK_NUMBER_CONFIGS,
protected quoterAddressOverride?: string,
protected metricsPrefix: string = '' // default metric prefix to be empty string
protected quoterAddressOverride?: (useMixedRouteQuoter: boolean) => string | undefined,
protected metricsPrefix: (
chainId: ChainId,
useMixedRouteQuoter: boolean
) => string = (chainId, useMixedRouteQuoter) =>
useMixedRouteQuoter
? `ChainId_${chainId}_MixedQuoter`
: `ChainId_${chainId}_V3Quoter`
) {}

private getQuoterAddress(useMixedRouteQuoter: boolean): string {
if (this.quoterAddressOverride) {
return this.quoterAddressOverride;
const quoterAddress = this.quoterAddressOverride(useMixedRouteQuoter);

if (!quoterAddress) {
throw new Error(
`No address for the quoter contract on chain id: ${this.chainId}`
);
}
return quoterAddress;
}
const quoterAddress = useMixedRouteQuoter
? MIXED_ROUTE_QUOTER_V1_ADDRESSES[this.chainId]
Expand Down Expand Up @@ -424,12 +437,15 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
);

metric.putMetric(
`${this.metricsPrefix}QuoteBatchSize`,
`${this.metricsPrefix(this.chainId, useMixedRouteQuoter)}QuoteBatchSize`,
inputs.length,
MetricLoggerUnit.Count
);
metric.putMetric(
`${this.metricsPrefix}QuoteBatchSize_${ID_TO_NETWORK_NAME(this.chainId)}`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteBatchSize_${ID_TO_NETWORK_NAME(this.chainId)}`,
inputs.length,
MetricLoggerUnit.Count
);
Expand Down Expand Up @@ -602,7 +618,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
if (error instanceof BlockConflictError) {
if (!haveRetriedForBlockConflictError) {
metric.putMetric(
`${this.metricsPrefix}QuoteBlockConflictErrorRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteBlockConflictErrorRetry`,
1,
MetricLoggerUnit.Count
);
Expand All @@ -613,7 +632,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
} else if (error instanceof ProviderBlockHeaderError) {
if (!haveRetriedForBlockHeader) {
metric.putMetric(
`${this.metricsPrefix}QuoteBlockHeaderNotFoundRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteBlockHeaderNotFoundRetry`,
1,
MetricLoggerUnit.Count
);
Expand Down Expand Up @@ -653,7 +675,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
} else if (error instanceof ProviderTimeoutError) {
if (!haveRetriedForTimeout) {
metric.putMetric(
`${this.metricsPrefix}QuoteTimeoutRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteTimeoutRetry`,
1,
MetricLoggerUnit.Count
);
Expand All @@ -662,7 +687,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
} else if (error instanceof ProviderGasError) {
if (!haveRetriedForOutOfGas) {
metric.putMetric(
`${this.metricsPrefix}QuoteOutOfGasExceptionRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteOutOfGasExceptionRetry`,
1,
MetricLoggerUnit.Count
);
Expand All @@ -674,7 +702,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
} else if (error instanceof SuccessRateError) {
if (!haveRetriedForSuccessRate) {
metric.putMetric(
`${this.metricsPrefix}QuoteSuccessRateRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteSuccessRateRetry`,
1,
MetricLoggerUnit.Count
);
Expand All @@ -690,7 +721,10 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {
} else {
if (!haveRetriedForUnknownReason) {
metric.putMetric(
`${this.metricsPrefix}QuoteUnknownReasonRetry`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteUnknownReasonRetry`,
1,
MetricLoggerUnit.Count
);
Expand Down Expand Up @@ -781,37 +815,52 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {

const endTime = Date.now();
metric.putMetric(
`${this.metricsPrefix}QuoteLatency`,
`${this.metricsPrefix(this.chainId, useMixedRouteQuoter)}QuoteLatency`,
endTime - startTime,
MetricLoggerUnit.Milliseconds
);

metric.putMetric(
`${this.metricsPrefix}QuoteApproxGasUsedPerSuccessfulCall`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteApproxGasUsedPerSuccessfulCall`,
approxGasUsedPerSuccessCall,
MetricLoggerUnit.Count
);

metric.putMetric(
`${this.metricsPrefix}QuoteNumRetryLoops`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteNumRetryLoops`,
finalAttemptNumber - 1,
MetricLoggerUnit.Count
);

metric.putMetric(
`${this.metricsPrefix}QuoteTotalCallsToProvider`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteTotalCallsToProvider`,
totalCallsMade,
MetricLoggerUnit.Count
);

metric.putMetric(
`${this.metricsPrefix}QuoteExpectedCallsToProvider`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteExpectedCallsToProvider`,
expectedCallsMade,
MetricLoggerUnit.Count
);

metric.putMetric(
`${this.metricsPrefix}QuoteNumRetriedCalls`,
`${this.metricsPrefix(
this.chainId,
useMixedRouteQuoter
)}QuoteNumRetriedCalls`,
totalCallsMade - expectedCallsMade,
MetricLoggerUnit.Count
);
Expand Down
8 changes: 7 additions & 1 deletion src/util/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CHAIN_TO_ADDRESSES_MAP, ChainId, SWAP_ROUTER_02_ADDRESSES as SWAP_ROUTER_02_ADDRESSES_HELPER, Token } from '@uniswap/sdk-core';
import {
ChainId,
CHAIN_TO_ADDRESSES_MAP,
SWAP_ROUTER_02_ADDRESSES as SWAP_ROUTER_02_ADDRESSES_HELPER,
Token,
} from '@uniswap/sdk-core';
import { FACTORY_ADDRESS } from '@uniswap/v3-sdk';

import { NETWORKS_WITH_SAME_UNISWAP_ADDRESSES } from './chains';
Expand Down Expand Up @@ -62,6 +67,7 @@ export const QUOTER_V2_ADDRESSES: AddressMap = {

export const NEW_QUOTER_V2_ADDRESSES: AddressMap = {
...constructSameAddressMap('0x5e55C9e631FAE526cd4B0526C4818D6e0a9eF0e3'),
[ChainId.SEPOLIA]: '0xf0c802dcb0cf1c4f7b953756b49d940eed190221',
[ChainId.POLYGON_MUMBAI]: '0x60e06b92bC94a665036C26feC5FF2A92E2d04c5f',
[ChainId.BASE]: '0x222cA98F00eD15B1faE10B61c277703a194cf5d2',
[ChainId.BLAST]: '0x9D0F15f2cf58655fDDcD1EE6129C547fDaeD01b1',
Expand Down

0 comments on commit f73799d

Please sign in to comment.