Skip to content

Commit

Permalink
fix: native currency routing quote token has to be currency type
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Oct 3, 2024
1 parent dddedad commit 3b80d85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
31 changes: 15 additions & 16 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ export class AlphaRouter
await partialRoutingConfig.blockNumber
);

const quoteToken = quoteCurrency.wrapped;
// const gasTokenAccessor = await this.tokenProvider.getTokens([routingConfig.gasToken!]);
const gasToken = routingConfig.gasToken
? (
Expand Down Expand Up @@ -1344,7 +1343,7 @@ export class AlphaRouter
} = await this.getGasModels(
gasPriceWei,
amount.currency.wrapped,
quoteToken,
quoteCurrency.wrapped,
providerConfig
);

Expand All @@ -1359,7 +1358,7 @@ export class AlphaRouter
(await this.routeCachingProvider?.getCacheMode(
this.chainId,
amount,
quoteToken,
quoteCurrency,
tradeType,
protocols
));
Expand All @@ -1370,7 +1369,7 @@ export class AlphaRouter
cachedRoutes = await this.routeCachingProvider?.getCachedRoute(
this.chainId,
amount,
quoteToken,
quoteCurrency,
tradeType,
protocols,
await blockNumber,
Expand Down Expand Up @@ -1452,7 +1451,7 @@ export class AlphaRouter
cachedRoutes,
await blockNumber,
amount,
quoteToken,
quoteCurrency,
tradeType,
routingConfig,
v3GasModel,
Expand All @@ -1473,7 +1472,7 @@ export class AlphaRouter
currencyIn,
currencyOut,
protocols,
quoteToken,
quoteCurrency,
tradeType,
routingConfig,
v3GasModel,
Expand Down Expand Up @@ -1795,7 +1794,7 @@ export class AlphaRouter
cachedRoutes: CachedRoutes,
blockNumber: number,
amount: CurrencyAmount,
quoteToken: Token,
quoteCurrency: Currency,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
v3GasModel: IGasModel<V3RouteWithValidQuote>,
Expand Down Expand Up @@ -1876,7 +1875,7 @@ export class AlphaRouter
v4RoutesFromCache,
amounts,
percents,
quoteToken,
quoteCurrency,
tradeType,
routingConfig,
undefined,
Expand Down Expand Up @@ -1913,7 +1912,7 @@ export class AlphaRouter
v3RoutesFromCache,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
tradeType,
routingConfig,
undefined,
Expand Down Expand Up @@ -1952,7 +1951,7 @@ export class AlphaRouter
v2RoutesFromCache,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
tradeType,
routingConfig,
gasPriceWei
Expand Down Expand Up @@ -1988,7 +1987,7 @@ export class AlphaRouter
mixedRoutesFromCache,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
tradeType,
routingConfig,
undefined,
Expand Down Expand Up @@ -2034,7 +2033,7 @@ export class AlphaRouter
currencyIn: Currency,
currencyOut: Currency,
protocols: Protocol[],
quoteToken: Token,
quoteCurrency: Currency,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
v3GasModel: IGasModel<V3RouteWithValidQuote>,
Expand Down Expand Up @@ -2200,7 +2199,7 @@ export class AlphaRouter
amount,
amounts,
percents,
quoteToken,
quoteCurrency,
v4CandidatePools!,
tradeType,
routingConfig,
Expand Down Expand Up @@ -2242,7 +2241,7 @@ export class AlphaRouter
amount,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
v3CandidatePools!,
tradeType,
routingConfig,
Expand Down Expand Up @@ -2284,7 +2283,7 @@ export class AlphaRouter
amount,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
v2CandidatePools!,
tradeType,
routingConfig,
Expand Down Expand Up @@ -2347,7 +2346,7 @@ export class AlphaRouter
amount,
amounts,
percents,
quoteToken,
quoteCurrency.wrapped,
[
v4CandidatePools!,
v3CandidatePools!,
Expand Down
6 changes: 3 additions & 3 deletions src/routers/alpha-router/quoters/base-quoter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber';
import { Protocol } from '@uniswap/router-sdk';
import { ChainId, Currency, Token, TradeType } from '@uniswap/sdk-core';
import { ChainId, Currency, TradeType } from '@uniswap/sdk-core';
import _ from 'lodash';

import {
Expand Down Expand Up @@ -110,7 +110,7 @@ export abstract class BaseQuoter<
routes: Route[],
amounts: CurrencyAmount[],
percents: number[],
quoteToken: Token,
quoteToken: TCurrency,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
candidatePools?: CandidatePoolsBySelectionCriteria,
Expand Down Expand Up @@ -138,7 +138,7 @@ export abstract class BaseQuoter<
amount: CurrencyAmount,
amounts: CurrencyAmount[],
percents: number[],
quoteToken: Token,
quoteToken: TCurrency,
candidatePools: CandidatePools,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
Expand Down
3 changes: 3 additions & 0 deletions src/routers/alpha-router/quoters/v4-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ export class V4Quoter extends BaseQuoter<V4CandidatePools, V4Route, Currency> {
initializedTicksCrossedList,
quoterGasEstimate: gasEstimate,
gasModel,
// TODO: make it unwrapped, once v4 gas model supports native quote currency
// For now it's ok to keep it wrapped,
// because the quote is the fairly accurate quote from the native currency routing
quoteToken: quoteCurrency.wrapped,
tradeType,
v4PoolProvider: this.v4PoolProvider,
Expand Down
1 change: 1 addition & 0 deletions src/util/gas-factory-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ export function initSwapRouteFromExisting(
: undefined,
simulationStatus: swapRoute.simulationStatus,
portionAmount: swapRoute.portionAmount,
hitsCachedRoute: swapRoute.hitsCachedRoute,
};
}

Expand Down

0 comments on commit 3b80d85

Please sign in to comment.