Skip to content

Commit

Permalink
feat: support arb-sepolia (Uniswap#493)
Browse files Browse the repository at this point in the history
* support arb-sepolia

* fix prettier

* fix compiling error
  • Loading branch information
jsy1218 authored Feb 15, 2024
1 parent e3b9a70 commit f8dd7b3
Show file tree
Hide file tree
Showing 22 changed files with 120 additions and 29 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@uniswap/default-token-list": "^11.2.0",
"@uniswap/permit2-sdk": "^1.2.0",
"@uniswap/router-sdk": "^1.7.5",
"@uniswap/sdk-core": "^4.0.9",
"@uniswap/sdk-core": "^4.1.2",
"@uniswap/swap-router-contracts": "^1.3.0",
"@uniswap/token-lists": "^1.0.0-beta.31",
"@uniswap/universal-router": "^1.6.0",
Expand Down
20 changes: 15 additions & 5 deletions src/providers/caching-token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,48 @@ import {
CUSD_CELO,
CUSD_CELO_ALFAJORES,
DAI_ARBITRUM,
DAI_ARBITRUM_SEPOLIA,
DAI_AVAX,
DAI_BNB,
DAI_CELO,
DAI_CELO_ALFAJORES,
DAI_MAINNET,
DAI_MOONBEAM,
DAI_OPTIMISM,
DAI_OPTIMISM_GOERLI, DAI_OPTIMISM_SEPOLIA,
DAI_OPTIMISM_GOERLI,
DAI_OPTIMISM_SEPOLIA,
DAI_POLYGON_MUMBAI,
ETH_BNB,
ITokenProvider,
TokenAccessor,
USDC_ARBITRUM,
USDC_ARBITRUM_GOERLI,
USDC_ARBITRUM_SEPOLIA,
USDC_AVAX,
USDC_BASE,
USDC_BNB,
USDC_ETHEREUM_GNOSIS,
USDC_MAINNET,
USDC_MOONBEAM,
USDC_OPTIMISM,
USDC_OPTIMISM_GOERLI, USDC_OPTIMISM_SEPOLIA,
USDC_OPTIMISM_GOERLI,
USDC_OPTIMISM_SEPOLIA,
USDC_POLYGON,
USDC_SEPOLIA,
USDT_ARBITRUM,
USDT_BNB,
USDT_MAINNET,
USDT_OPTIMISM,
USDT_OPTIMISM_GOERLI, USDT_OPTIMISM_SEPOLIA,
USDT_OPTIMISM_GOERLI,
USDT_OPTIMISM_SEPOLIA,
WBTC_ARBITRUM,
WBTC_MAINNET,
WBTC_MOONBEAM,
WBTC_OPTIMISM,
WBTC_OPTIMISM_GOERLI, WBTC_OPTIMISM_SEPOLIA,
WBTC_OPTIMISM_GOERLI,
WBTC_OPTIMISM_SEPOLIA,
WMATIC_POLYGON,
WMATIC_POLYGON_MUMBAI
WMATIC_POLYGON_MUMBAI,
} from './token-provider';

// These tokens will added to the Token cache on initialization.
Expand Down Expand Up @@ -102,6 +108,10 @@ export const CACHE_SEED_TOKENS: {
[ChainId.ARBITRUM_GOERLI]: {
USDC: USDC_ARBITRUM_GOERLI,
},
[ChainId.ARBITRUM_SEPOLIA]: {
USDC: USDC_ARBITRUM_SEPOLIA,
DAI: DAI_ARBITRUM_SEPOLIA,
},
[ChainId.POLYGON]: {
WMATIC: WMATIC_POLYGON,
USDC: USDC_POLYGON,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/multicall-uniswap-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ChainId } from '@uniswap/sdk-core';
import _ from 'lodash';
import stats from 'stats-lite';

import { UniswapInterfaceMulticall } from '../types/v3/UniswapInterfaceMulticall';
import { UniswapInterfaceMulticall__factory } from '../types/v3/factories/UniswapInterfaceMulticall__factory';
import { UniswapInterfaceMulticall } from '../types/v3/UniswapInterfaceMulticall';
import { UNISWAP_MULTICALL_ADDRESSES } from '../util/addresses';
import { log } from '../util/log';

Expand Down
2 changes: 1 addition & 1 deletion src/providers/token-fee-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BigNumber } from '@ethersproject/bignumber';
import { BaseProvider } from '@ethersproject/providers';
import { ChainId } from '@uniswap/sdk-core';

import { TokenFeeDetector } from '../types/other/TokenFeeDetector';
import { TokenFeeDetector__factory } from '../types/other/factories/TokenFeeDetector__factory';
import { TokenFeeDetector } from '../types/other/TokenFeeDetector';
import {
log,
metric,
Expand Down
21 changes: 21 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ export const DAI_ARBITRUM_GOERLI = new Token(
'Dai Stablecoin'
);

export const DAI_ARBITRUM_SEPOLIA = new Token(
ChainId.ARBITRUM_SEPOLIA,
'0xc3826E277485c33F3D99C9e0CBbf8449513210EE',
18,
'DAI',
'Dai Stablecoin'
);

// Bridged version of official Goerli USDC
export const USDC_ARBITRUM_GOERLI = new Token(
ChainId.ARBITRUM_GOERLI,
Expand All @@ -308,6 +316,15 @@ export const USDC_ARBITRUM_GOERLI = new Token(
'USD//C'
);

// Bridged version of official Sepolia USDC
export const USDC_ARBITRUM_SEPOLIA = new Token(
ChainId.ARBITRUM_SEPOLIA,
'0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
6,
'USDC',
'USD//C'
);

//polygon tokens
export const WMATIC_POLYGON = new Token(
ChainId.POLYGON,
Expand Down Expand Up @@ -819,6 +836,8 @@ export const DAI_ON = (chainId: ChainId): Token => {
return DAI_ARBITRUM;
case ChainId.ARBITRUM_GOERLI:
return DAI_ARBITRUM_GOERLI;
case ChainId.ARBITRUM_SEPOLIA:
return DAI_ARBITRUM_SEPOLIA;
case ChainId.POLYGON:
return DAI_POLYGON;
case ChainId.POLYGON_MUMBAI:
Expand Down Expand Up @@ -877,6 +896,8 @@ export const USDC_ON = (chainId: ChainId): Token => {
return USDC_ARBITRUM;
case ChainId.ARBITRUM_GOERLI:
return USDC_ARBITRUM_GOERLI;
case ChainId.ARBITRUM_SEPOLIA:
return USDC_ARBITRUM_SEPOLIA;
case ChainId.POLYGON:
return USDC_POLYGON;
case ChainId.POLYGON_MUMBAI:
Expand Down
1 change: 1 addition & 0 deletions src/providers/v2/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
ARB_ARBITRUM,
],
[ChainId.ARBITRUM_GOERLI]: [],
[ChainId.ARBITRUM_SEPOLIA]: [],
[ChainId.OPTIMISM_GOERLI]: [],
[ChainId.OPTIMISM_SEPOLIA]: [],
[ChainId.POLYGON]: [USDC_POLYGON, WETH_POLYGON, WMATIC_POLYGON],
Expand Down
5 changes: 4 additions & 1 deletion src/providers/v3/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
],
// todo: once subgraph is created
[ChainId.OPTIMISM_SEPOLIA]: [
// WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_SEPOLIA]!,
// WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_SEPOLIA]!,
],
[ChainId.ARBITRUM_ONE]: [
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_ONE]!,
Expand All @@ -110,6 +110,9 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_GOERLI]!,
USDC_ARBITRUM_GOERLI,
],
[ChainId.ARBITRUM_SEPOLIA]: [
// WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_SEPOLIA]!,
],
[ChainId.OPTIMISM_GOERLI]: [
WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_GOERLI]!,
USDC_OPTIMISM_GOERLI,
Expand Down
2 changes: 2 additions & 0 deletions src/providers/v3/subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const SUBGRAPH_URL_BY_CHAIN: { [chainId in ChainId]?: string } = {
[ChainId.OPTIMISM_SEPOLIA]: '',
[ChainId.ARBITRUM_ONE]:
'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-minimal',
// todo: add once subgraph is live
[ChainId.ARBITRUM_SEPOLIA]: '',
[ChainId.POLYGON]:
'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
[ChainId.CELO]:
Expand Down
1 change: 1 addition & 0 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export class AlphaRouter
break;
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.ARBITRUM_SEPOLIA:
this.onChainQuoteProvider = new OnChainQuoteProvider(
chainId,
provider,
Expand Down
1 change: 1 addition & 0 deletions src/routers/alpha-router/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (
// have to adjust the routing config so we explore fewer routes.
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.ARBITRUM_SEPOLIA:
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return {
Expand Down
6 changes: 3 additions & 3 deletions src/routers/alpha-router/functions/best-swap-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ export async function getBestSwapRouteBy(
gasCostsL1ToL2.gasCostL1USD = v2GasCostL1.gasCostL1USD;
}
gasCostsL1ToL2.gasCostL1QuoteToken =
gasCostsL1ToL2.gasCostL1QuoteToken.add(
v2GasCostL1.gasCostL1QuoteToken
);
gasCostsL1ToL2.gasCostL1QuoteToken.add(
v2GasCostL1.gasCostL1QuoteToken
);
}
}
const v3Routes = bestSwap.filter(
Expand Down
9 changes: 7 additions & 2 deletions src/routers/alpha-router/functions/get-candidate-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import _ from 'lodash';
import {
DAI_OPTIMISM_SEPOLIA,
ITokenListProvider,
IV2SubgraphProvider, USDC_OPTIMISM_SEPOLIA, USDT_OPTIMISM_SEPOLIA,
V2SubgraphPool, WBTC_OPTIMISM_SEPOLIA
IV2SubgraphProvider,
USDC_ARBITRUM_SEPOLIA,
USDC_OPTIMISM_SEPOLIA,
USDT_OPTIMISM_SEPOLIA,
V2SubgraphPool,
WBTC_OPTIMISM_SEPOLIA,
} from '../../../providers';
import {
CELO,
Expand Down Expand Up @@ -162,6 +166,7 @@ const baseTokensByChain: { [chainId in ChainId]?: Token[] } = {
USDT_ARBITRUM,
],
[ChainId.ARBITRUM_GOERLI]: [USDC_ARBITRUM_GOERLI],
[ChainId.ARBITRUM_SEPOLIA]: [USDC_ARBITRUM_SEPOLIA],
[ChainId.POLYGON]: [USDC_POLYGON, WMATIC_POLYGON],
[ChainId.POLYGON_MUMBAI]: [DAI_POLYGON_MUMBAI, WMATIC_POLYGON_MUMBAI],
[ChainId.CELO]: [CUSD_CELO, CEUR_CELO, CELO],
Expand Down
4 changes: 3 additions & 1 deletion src/routers/alpha-router/gas-models/gas-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DAI_SEPOLIA,
USDC_ARBITRUM,
USDC_ARBITRUM_GOERLI,
USDC_ARBITRUM_SEPOLIA,
USDC_AVAX,
USDC_BASE,
USDC_BNB,
Expand Down Expand Up @@ -51,7 +52,7 @@ import {
USDT_OPTIMISM,
USDT_OPTIMISM_GOERLI,
USDT_OPTIMISM_SEPOLIA,
WBTC_GOERLI
WBTC_GOERLI,
} from '../../../providers/token-provider';
import { IV2PoolProvider } from '../../../providers/v2/pool-provider';
import {
Expand Down Expand Up @@ -96,6 +97,7 @@ export const usdGasTokensByChain: { [chainId in ChainId]?: Token[] } = {
USDT_OPTIMISM_SEPOLIA,
],
[ChainId.ARBITRUM_GOERLI]: [USDC_ARBITRUM_GOERLI],
[ChainId.ARBITRUM_SEPOLIA]: [USDC_ARBITRUM_SEPOLIA],
[ChainId.GOERLI]: [DAI_GOERLI, USDC_GOERLI, USDT_GOERLI, WBTC_GOERLI],
[ChainId.SEPOLIA]: [USDC_SEPOLIA, DAI_SEPOLIA],
[ChainId.POLYGON]: [USDC_POLYGON, USDC_NATIVE_POLYGON],
Expand Down
3 changes: 3 additions & 0 deletions src/routers/alpha-router/gas-models/v3/gas-costs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const BASE_SWAP_COST = (id: ChainId): BigNumber => {
return BigNumber.from(2000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.ARBITRUM_SEPOLIA:
return BigNumber.from(5000);
case ChainId.POLYGON:
case ChainId.POLYGON_MUMBAI:
Expand Down Expand Up @@ -55,6 +56,7 @@ export const COST_PER_INIT_TICK = (id: ChainId): BigNumber => {
return BigNumber.from(31000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.ARBITRUM_SEPOLIA:
return BigNumber.from(31000);
case ChainId.POLYGON:
case ChainId.POLYGON_MUMBAI:
Expand Down Expand Up @@ -84,6 +86,7 @@ export const COST_PER_HOP = (id: ChainId): BigNumber => {
return BigNumber.from(80000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
case ChainId.ARBITRUM_SEPOLIA:
return BigNumber.from(80000);
case ChainId.POLYGON:
case ChainId.POLYGON_MUMBAI:
Expand Down
3 changes: 3 additions & 0 deletions src/routers/legacy-router/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export const BASES_TO_CHECK_TRADES_AGAINST = (
[ChainId.ARBITRUM_GOERLI]: [
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_GOERLI]!,
],
[ChainId.ARBITRUM_SEPOLIA]: [
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_SEPOLIA]!,
],
[ChainId.POLYGON]: [WMATIC_POLYGON],
[ChainId.POLYGON_MUMBAI]: [WMATIC_POLYGON_MUMBAI],
[ChainId.CELO]: [WRAPPED_NATIVE_CURRENCY[ChainId.CELO]],
Expand Down
2 changes: 1 addition & 1 deletion src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
import { SwapOptions as UniversalRouterSwapOptions } from '@uniswap/universal-router-sdk';
import { Route as V2RouteRaw } from '@uniswap/v2-sdk';
import {
MethodParameters as SDKMethodParameters,
Pool,
Position,
MethodParameters as SDKMethodParameters,
Route as V3RouteRaw,
} from '@uniswap/v3-sdk';

Expand Down
15 changes: 14 additions & 1 deletion src/util/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CHAIN_TO_ADDRESSES_MAP, ChainId, Token } from '@uniswap/sdk-core';
import { ChainId, CHAIN_TO_ADDRESSES_MAP, Token } from '@uniswap/sdk-core';
import { FACTORY_ADDRESS } from '@uniswap/v3-sdk';

import { NETWORKS_WITH_SAME_UNISWAP_ADDRESSES } from './chains';
Expand All @@ -25,6 +25,8 @@ export const V3_CORE_FACTORY_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].v3CoreFactoryAddress,
[ChainId.ARBITRUM_GOERLI]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_GOERLI].v3CoreFactoryAddress,
[ChainId.ARBITRUM_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_SEPOLIA].v3CoreFactoryAddress,
[ChainId.BNB]: CHAIN_TO_ADDRESSES_MAP[ChainId.BNB].v3CoreFactoryAddress,
[ChainId.AVALANCHE]:
CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].v3CoreFactoryAddress,
Expand All @@ -46,6 +48,8 @@ export const QUOTER_V2_ADDRESSES: AddressMap = {
[ChainId.SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].quoterAddress,
[ChainId.ARBITRUM_GOERLI]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_GOERLI].quoterAddress,
[ChainId.ARBITRUM_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_SEPOLIA].quoterAddress,
[ChainId.BNB]: CHAIN_TO_ADDRESSES_MAP[ChainId.BNB].quoterAddress,
[ChainId.AVALANCHE]: CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].quoterAddress,
[ChainId.BASE_GOERLI]:
Expand Down Expand Up @@ -73,6 +77,8 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
[ChainId.SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].multicallAddress,
[ChainId.ARBITRUM_GOERLI]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_GOERLI].multicallAddress,
[ChainId.ARBITRUM_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_SEPOLIA].multicallAddress,
[ChainId.BNB]: CHAIN_TO_ADDRESSES_MAP[ChainId.BNB].multicallAddress,
[ChainId.AVALANCHE]:
CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].multicallAddress,
Expand Down Expand Up @@ -185,6 +191,13 @@ export const WETH9: {
'WETH',
'Wrapped Ether'
),
[ChainId.ARBITRUM_SEPOLIA]: new Token(
ChainId.ARBITRUM_SEPOLIA,
'0xc556bAe1e86B2aE9c22eA5E036b07E55E7596074',
18,
'WETH',
'Wrapped Ether'
),
[ChainId.BASE_GOERLI]: new Token(
ChainId.BASE_GOERLI,
'0x4200000000000000000000000000000000000006',
Expand Down
Loading

0 comments on commit f8dd7b3

Please sign in to comment.