Skip to content

Commit

Permalink
feat: CLI V4 support (Uniswap#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 authored Sep 17, 2024
1 parent ab246ae commit d8b2bb7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cli/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CachingTokenListProvider,
CachingTokenProviderWithFallback,
CachingV3PoolProvider,
CachingV4PoolProvider,
CHAIN_IDS_LIST,
EIP1559GasPriceProvider,
EthEstimateGasSimulator,
Expand Down Expand Up @@ -44,7 +45,8 @@ import {
UniswapMulticallProvider,
V2PoolProvider,
V3PoolProvider,
V3RouteWithValidQuote
V3RouteWithValidQuote,
V4PoolProvider
} from '../src';
import {
LegacyGasPriceProvider
Expand Down Expand Up @@ -286,6 +288,11 @@ export abstract class BaseCommand extends Command {
new NodeCache({ stdTTL: 15, useClones: true })
);

const v4PoolProvider = new CachingV4PoolProvider(
chainId,
new V4PoolProvider(chainId, multicall2Provider),
new NodeJSCache(new NodeCache({ stdTTL: 360, useClones: false }))
);
const v3PoolProvider = new CachingV3PoolProvider(
chainId,
new V3PoolProvider(chainId, multicall2Provider),
Expand All @@ -312,6 +319,7 @@ export abstract class BaseCommand extends Command {
process.env.TENDERLY_NODE_API_KEY!,
v2PoolProvider,
v3PoolProvider,
v4PoolProvider,
provider,
portionProvider,
{ [ChainId.ARBITRUM_ONE]: 1 },
Expand All @@ -325,6 +333,7 @@ export abstract class BaseCommand extends Command {
provider,
v2PoolProvider,
v3PoolProvider,
v4PoolProvider,
portionProvider
);

Expand Down
11 changes: 10 additions & 1 deletion cli/commands/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import { Currency, Percent, TradeType } from '@uniswap/sdk-core';
import dotenv from 'dotenv';
import _ from 'lodash';

import { ID_TO_CHAIN_ID, MapWithLowerCaseKey, nativeOnChain, parseAmount, SwapRoute, SwapType, } from '../../src';
import {
ID_TO_CHAIN_ID,
MapWithLowerCaseKey,
nativeOnChain,
parseAmount,
SwapRoute,
SwapType
} from '../../src';
import { NATIVE_NAMES_BY_ID, TO_PROTOCOL } from '../../src/util';
import { BaseCommand } from '../base-command';
import { UniversalRouterVersion } from '@uniswap/universal-router-sdk';

dotenv.config();

Expand Down Expand Up @@ -138,6 +146,7 @@ export class Quote extends BaseCommand {
recipient,
slippageTolerance: new Percent(5, 100),
simulate: simulate ? { fromAddress: recipient } : undefined,
version: UniversalRouterVersion.V2_0
}
: undefined,
{
Expand Down
2 changes: 2 additions & 0 deletions src/util/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Protocol } from '@uniswap/router-sdk';

export const TO_PROTOCOL = (protocol: string): Protocol => {
switch (protocol.toLowerCase()) {
case 'v4':
return Protocol.V4;
case 'v3':
return Protocol.V3;
case 'v2':
Expand Down

0 comments on commit d8b2bb7

Please sign in to comment.