Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Sep 23, 2024
1 parent c056240 commit 89e891f
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 60 deletions.
8 changes: 5 additions & 3 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1903,14 +1903,15 @@ export class AlphaRouter
);

const beforeGetQuotes = Date.now();
const quoteToken = quoteCurrency.wrapped;

quotePromises.push(
this.v3Quoter
.getQuotes(
v3RoutesFromCache,
amounts,
percents,
quoteCurrency,
quoteToken,
tradeType,
routingConfig,
undefined,
Expand Down Expand Up @@ -1940,6 +1941,7 @@ export class AlphaRouter
);

const beforeGetQuotes = Date.now();
const quoteToken = quoteCurrency.wrapped;

quotePromises.push(
this.v2Quoter
Expand All @@ -1949,7 +1951,7 @@ export class AlphaRouter
v2RoutesFromCache,
amounts,
percents,
quoteCurrency,
quoteToken,
tradeType,
routingConfig,
gasPriceWei
Expand Down Expand Up @@ -2201,7 +2203,7 @@ export class AlphaRouter
v4CandidatePools!,
tradeType,
routingConfig,
v3GasModel
v4GasModel
)
.then((result) => {
metric.putMetric(
Expand Down
26 changes: 10 additions & 16 deletions src/routers/alpha-router/entities/route-with-valid-quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type V2RouteWithValidQuoteParams = {
percent: number;
route: V2Route;
gasModel: IGasModel<V2RouteWithValidQuote>;
quoteCurrency: Currency;
quoteToken: Token;
tradeType: TradeType;
v2PoolProvider: IV2PoolProvider;
};
Expand All @@ -95,7 +95,7 @@ export class V2RouteWithValidQuote implements IV2RouteWithValidQuote {
public quoteAdjustedForGas: CurrencyAmount;
public percent: number;
public route: V2Route;
public quoteCurrency: Currency;
public quoteToken: Token;
public gasModel: IGasModel<V2RouteWithValidQuote>;
public gasEstimate: BigNumber;
public gasCostInToken: CurrencyAmount;
Expand All @@ -119,20 +119,17 @@ export class V2RouteWithValidQuote implements IV2RouteWithValidQuote {
percent,
route,
gasModel,
quoteCurrency,
quoteToken,
tradeType,
v2PoolProvider,
}: V2RouteWithValidQuoteParams) {
this.amount = amount;
this.rawQuote = rawQuote;
this.quote = CurrencyAmount.fromRawAmount(
quoteCurrency,
rawQuote.toString()
);
this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());
this.percent = percent;
this.route = route;
this.gasModel = gasModel;
this.quoteCurrency = quoteCurrency;
this.quoteToken = quoteToken;
this.tradeType = tradeType;

const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =
Expand Down Expand Up @@ -170,7 +167,7 @@ export type V3RouteWithValidQuoteParams = {
percent: number;
route: V3Route;
gasModel: IGasModel<V3RouteWithValidQuote>;
quoteCurrency: Currency;
quoteToken: Token;
tradeType: TradeType;
v3PoolProvider: IV3PoolProvider;
};
Expand All @@ -194,7 +191,7 @@ export class V3RouteWithValidQuote implements IV3RouteWithValidQuote {
public quoterGasEstimate: BigNumber;
public percent: number;
public route: V3Route;
public quoteCurrency: Currency;
public quoteToken: Token;
public gasModel: IGasModel<V3RouteWithValidQuote>;
public gasEstimate: BigNumber;
public gasCostInToken: CurrencyAmount;
Expand All @@ -221,7 +218,7 @@ export class V3RouteWithValidQuote implements IV3RouteWithValidQuote {
percent,
route,
gasModel,
quoteCurrency,
quoteToken,
tradeType,
v3PoolProvider,
}: V3RouteWithValidQuoteParams) {
Expand All @@ -230,14 +227,11 @@ export class V3RouteWithValidQuote implements IV3RouteWithValidQuote {
this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;
this.initializedTicksCrossedList = initializedTicksCrossedList;
this.quoterGasEstimate = quoterGasEstimate;
this.quote = CurrencyAmount.fromRawAmount(
quoteCurrency,
rawQuote.toString()
);
this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());
this.percent = percent;
this.route = route;
this.gasModel = gasModel;
this.quoteCurrency = quoteCurrency;
this.quoteToken = quoteToken;
this.tradeType = tradeType;

const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =
Expand Down
10 changes: 8 additions & 2 deletions src/routers/alpha-router/functions/best-swap-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AlphaRouterConfig } from '../alpha-router';
import { IGasModel, L1ToL2GasCosts, usdGasTokensByChain } from '../gas-models';

import {
MixedRouteWithValidQuote,
RouteWithValidQuote,
V2RouteWithValidQuote,
V3RouteWithValidQuote,
Expand Down Expand Up @@ -492,8 +493,13 @@ export async function getBestSwapRouteBy(
gasUsedL1OnL2: BigNumber.from(0),
gasCostL1USD: CurrencyAmount.fromRawAmount(usdToken, 0),
gasCostL1QuoteToken: CurrencyAmount.fromRawAmount(
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
bestSwap[0]?.quoteCurrency!,
bestSwap[0] &&
(bestSwap[0] instanceof V4RouteWithValidQuote ||
bestSwap[0] instanceof MixedRouteWithValidQuote)
? // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
bestSwap[0]?.quoteCurrency!
: // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
bestSwap[0]?.quoteToken!,
0
),
};
Expand Down
12 changes: 6 additions & 6 deletions src/routers/alpha-router/quoters/v2-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
routes: V2Route[],
amounts: CurrencyAmount[],
percents: number[],
quoteCurrency: Currency,
quoteToken: Token,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
candidatePools?: CandidatePoolsBySelectionCriteria,
Expand Down Expand Up @@ -186,14 +186,14 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
chainId: this.chainId,
gasPriceWei,
poolProvider: this.v2PoolProvider,
token: quoteCurrency.wrapped,
token: quoteToken,
l2GasDataProvider: this.l2GasDataProvider,
providerConfig: {
...routingConfig,
additionalGasOverhead: NATIVE_OVERHEAD(
this.chainId,
amountToken,
quoteCurrency
quoteToken
),
gasToken,
},
Expand Down Expand Up @@ -240,7 +240,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
amount,
percent,
gasModel: v2GasModel,
quoteCurrency: quoteCurrency,
quoteToken,
tradeType,
v2PoolProvider: this.v2PoolProvider,
});
Expand All @@ -267,7 +267,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
routes: V2Route[],
amounts: CurrencyAmount[],
percents: number[],
quoteCurrency: Currency,
quoteToken: Token,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
gasPriceWei?: BigNumber
Expand All @@ -291,7 +291,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route, Token> {
routes,
amounts,
percents,
quoteCurrency,
quoteToken,
tradeType,
routingConfig,
undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/routers/alpha-router/quoters/v3-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class V3Quoter extends BaseQuoter<V3CandidatePools, V3Route, Token> {
routes: V3Route[],
amounts: CurrencyAmount[],
percents: number[],
quoteCurrency: Currency,
quoteToken: Token,
tradeType: TradeType,
routingConfig: AlphaRouterConfig,
candidatePools?: CandidatePoolsBySelectionCriteria,
Expand Down Expand Up @@ -223,7 +223,7 @@ export class V3Quoter extends BaseQuoter<V3CandidatePools, V3Route, Token> {
initializedTicksCrossedList,
quoterGasEstimate: gasEstimate,
gasModel,
quoteCurrency,
quoteToken,
tradeType,
v3PoolProvider: this.v3PoolProvider,
});
Expand Down
2 changes: 1 addition & 1 deletion src/routers/legacy-router/legacy-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class LegacyRouter {
initializedTicksCrossedList: [],
quoterGasEstimate: BigNumber.from(0),
tradeType: routeType,
quoteCurrency: quoteToken,
quoteToken: quoteToken,
v3PoolProvider: this.poolProvider,
});
});
Expand Down
20 changes: 10 additions & 10 deletions src/util/gas-factory-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ export function initSwapRouteFromExisting(
percent: route.percent,
route: route.route,
gasModel: route.gasModel,
quoteCurrency: new Token(
quoteToken: new Token(
currencyIn.chainId,
route.quoteCurrency.wrapped.address,
route.quoteCurrency.decimals,
route.quoteCurrency.symbol,
route.quoteCurrency.name
route.quoteToken.address,
route.quoteToken.decimals,
route.quoteToken.symbol,
route.quoteToken.name
),
tradeType: tradeType,
v3PoolProvider: v3PoolProvider,
Expand All @@ -456,12 +456,12 @@ export function initSwapRouteFromExisting(
percent: route.percent,
route: route.route,
gasModel: route.gasModel,
quoteCurrency: new Token(
quoteToken: new Token(
currencyIn.chainId,
route.quoteCurrency.wrapped.address,
route.quoteCurrency.decimals,
route.quoteCurrency.symbol,
route.quoteCurrency.name
route.quoteToken.address,
route.quoteToken.decimals,
route.quoteToken.symbol,
route.quoteToken.name
),
tradeType: tradeType,
v2PoolProvider: v2PoolProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getV2RouteWithValidQuoteStub(
percent: 100,
route,
gasModel: getMockedV2GasModel(),
quoteCurrency: DAI,
quoteToken: DAI,
tradeType: TradeType.EXACT_INPUT,
v2PoolProvider: getMockedV2PoolProvider(),
...overrides,
Expand Down
5 changes: 3 additions & 2 deletions test/unit/routers/alpha-router/alpha-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe('alpha router', () => {
return {
gasEstimate: BigNumber.from(10000),
gasCostInToken: CurrencyAmount.fromRawAmount(
r.quoteCurrency,
r.quoteToken,
r.quote.multiply(new Fraction(95, 100)).quotient
),
gasCostInUSD: CurrencyAmount.fromRawAmount(
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('alpha router', () => {
return {
gasEstimate: BigNumber.from(10000),
gasCostInToken: CurrencyAmount.fromRawAmount(
r.quoteCurrency,
r.quoteToken,
r.quote.multiply(new Fraction(95, 100)).quotient
),
gasCostInUSD: CurrencyAmount.fromRawAmount(
Expand Down Expand Up @@ -493,6 +493,7 @@ describe('alpha router', () => {
multicall2Provider: mockMulticallProvider as any,
v4SubgraphProvider: mockV4SubgraphProvider,
v4PoolProvider: mockV4PoolProvider,
v4GasModelFactory: mockV4GasModelFactory,
v3SubgraphProvider: mockV3SubgraphProvider,
v3PoolProvider: mockV3PoolProvider,
onChainQuoteProvider: mockOnChainQuoteProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('get best swap route', () => {
quote: number,
percent: number
): V3RouteWithValidQuote => {
const quoteToken =
const quoteCurrency =
tradeType == TradeType.EXACT_OUTPUT ? route.output : route.input;
return new V3RouteWithValidQuote({
amount,
Expand All @@ -169,7 +169,7 @@ describe('get best swap route', () => {
percent,
route,
gasModel: mockV3GasModel,
quoteToken,
quoteToken: quoteCurrency,
tradeType,
v3PoolProvider: mockV3PoolProvider,
});
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('get best swap route', () => {
percent,
route,
gasModel: mockV2GasModel,
quoteCurrency: quoteToken,
quoteToken,
tradeType,
v2PoolProvider: mockV2PoolProvider,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getMockedMixedGasModel(): IGasModel<MixedRouteWithValidQuote> {
mockMixedGasModel.estimateGasCost.callsFake((r) => {
return {
gasEstimate: BigNumber.from(10000),
gasCostInToken: CurrencyAmount.fromRawAmount(r.quoteToken, 0),
gasCostInToken: CurrencyAmount.fromRawAmount(r.quoteCurrency, 0),
gasCostInUSD: CurrencyAmount.fromRawAmount(USDC, 0),
};
});
Expand Down
Loading

0 comments on commit 89e891f

Please sign in to comment.