From 86fe325aa452b75cf3a010672e99d8f906b535d7 Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Tue, 28 Feb 2023 11:55:34 -0500 Subject: [PATCH] Fix gas factory pool resolver to include FeeAmount.lowest, routeToString (#200) --- cli/base-command.ts | 9 +++------ src/util/gas-factory-helpers.ts | 16 +++++++++++++--- src/util/routes.ts | 5 ++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cli/base-command.ts b/cli/base-command.ts index dab187a8d..0bc672eab 100644 --- a/cli/base-command.ts +++ b/cli/base-command.ts @@ -280,14 +280,11 @@ export abstract class BaseCommand extends Command { // chainId != ChainId.ARBITRUM_ONE && chainId != ChainId.ARBITRUM_RINKEBY; const v3PoolProvider = new CachingV3PoolProvider( - ChainId.MAINNET, - new V3PoolProvider(ChainId.MAINNET, multicall2Provider), + chainId, + new V3PoolProvider(chainId, multicall2Provider), new NodeJSCache(new NodeCache({ stdTTL: 360, useClones: false })) ); - const v2PoolProvider = new V2PoolProvider( - ChainId.MAINNET, - multicall2Provider - ); + const v2PoolProvider = new V2PoolProvider(chainId, multicall2Provider); const tenderlySimulator = new TenderlySimulator( chainId, diff --git a/src/util/gas-factory-helpers.ts b/src/util/gas-factory-helpers.ts index 55e4b65b2..bbd739612 100644 --- a/src/util/gas-factory-helpers.ts +++ b/src/util/gas-factory-helpers.ts @@ -41,7 +41,7 @@ export async function getV2NativePool( reserve0: pool?.reserve0.toExact(), reserve1: pool?.reserve1.toExact(), }, - `Could not find a valid WETH pool with ${token.symbol} for computing gas costs.` + `Could not find a valid WETH V2 pool with ${token.symbol} for computing gas costs.` ); return null; @@ -56,7 +56,12 @@ export async function getHighestLiquidityV3NativePool( ): Promise { const nativeCurrency = WRAPPED_NATIVE_CURRENCY[token.chainId as ChainId]!; - const nativePools = _([FeeAmount.HIGH, FeeAmount.MEDIUM, FeeAmount.LOW]) + const nativePools = _([ + FeeAmount.HIGH, + FeeAmount.MEDIUM, + FeeAmount.LOW, + FeeAmount.LOWEST, + ]) .map<[Token, Token, FeeAmount]>((feeAmount) => { return [nativeCurrency, token, feeAmount]; }) @@ -64,7 +69,12 @@ export async function getHighestLiquidityV3NativePool( const poolAccessor = await poolProvider.getPools(nativePools); - const pools = _([FeeAmount.HIGH, FeeAmount.MEDIUM, FeeAmount.LOW]) + const pools = _([ + FeeAmount.HIGH, + FeeAmount.MEDIUM, + FeeAmount.LOW, + FeeAmount.LOWEST, + ]) .map((feeAmount) => { return poolAccessor.getPool(nativeCurrency, token, feeAmount); }) diff --git a/src/util/routes.ts b/src/util/routes.ts index 6decc5caa..c65f79a0b 100644 --- a/src/util/routes.ts +++ b/src/util/routes.ts @@ -6,6 +6,7 @@ import _ from 'lodash'; import { RouteWithValidQuote } from '../routers/alpha-router'; import { MixedRoute, V2Route, V3Route } from '../routers/router'; +import { V3_CORE_FACTORY_ADDRESSES } from './addresses'; import { CurrencyAmount } from '.'; @@ -29,7 +30,9 @@ export const routeToString = ( ? ` -- ${pool.fee / 10000}% [${Pool.getAddress( pool.token0, pool.token1, - pool.fee + pool.fee, + undefined, + V3_CORE_FACTORY_ADDRESSES[pool.chainId] )}]` : ` -- [${Pair.getAddress( (pool as Pair).token0,