From da1f1cdad16e4c7677082a96ea7c3d7b97e810b2 Mon Sep 17 00:00:00 2001 From: Alex Sismanis Date: Mon, 29 Jan 2024 17:50:17 -0600 Subject: [PATCH 1/5] Bump uniswap sdk core to 4.09 and add correct base swap router address The swap router address for base is different for other chains so the function needs to account for that. Also, @uniswap/sdk-core needs to be bumped to 4.0.9 where the WETH9 contract for Base was added otherwise any pools with WETH on base will not work in this SDK with the swap router --- package-lock.json | 14 +++++++------- package.json | 2 +- src/providers/v2/static-subgraph-provider.ts | 1 + src/providers/v3/static-subgraph-provider.ts | 1 + .../alpha-router/gas-models/v3/gas-costs.ts | 3 +++ src/routers/legacy-router/bases.ts | 3 +++ src/util/addresses.ts | 9 +++++++++ src/util/chains.ts | 7 +++++++ 8 files changed, 32 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a0b80b89..80f2d7473 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@uniswap/default-token-list": "^11.2.0", "@uniswap/permit2-sdk": "^1.2.0", "@uniswap/router-sdk": "^1.6.0", - "@uniswap/sdk-core": "^4.0.7", + "@uniswap/sdk-core": "^4.0.9", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.0.1", @@ -3181,9 +3181,9 @@ } }, "node_modules/@uniswap/sdk-core": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.7.tgz", - "integrity": "sha512-jscx7KUIWzQatcL5PHY6xy0gEL9IGQcL5h/obxzX9foP2KoNk9cq66Ia8I2Kvpa7zBcPOeW1hU0hJNBq6CzcIQ==", + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.10.tgz", + "integrity": "sha512-RiobXJKXvVVb+wfNM09Ik8djOMOuRQGfyRP5pHgUjojicK/7nscZILjZ87DjVCGjXEoD8yTSIps0UAQuz6pJIw==", "dependencies": { "@ethersproject/address": "^5.0.2", "big.js": "^5.2.2", @@ -14182,9 +14182,9 @@ } }, "@uniswap/sdk-core": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.7.tgz", - "integrity": "sha512-jscx7KUIWzQatcL5PHY6xy0gEL9IGQcL5h/obxzX9foP2KoNk9cq66Ia8I2Kvpa7zBcPOeW1hU0hJNBq6CzcIQ==", + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.10.tgz", + "integrity": "sha512-RiobXJKXvVVb+wfNM09Ik8djOMOuRQGfyRP5pHgUjojicK/7nscZILjZ87DjVCGjXEoD8yTSIps0UAQuz6pJIw==", "requires": { "@ethersproject/address": "^5.0.2", "big.js": "^5.2.2", diff --git a/package.json b/package.json index 25b776ed4..35619faa1 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@uniswap/default-token-list": "^11.2.0", "@uniswap/permit2-sdk": "^1.2.0", "@uniswap/router-sdk": "^1.6.0", - "@uniswap/sdk-core": "^4.0.7", + "@uniswap/sdk-core": "^4.0.9", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.0.1", diff --git a/src/providers/v2/static-subgraph-provider.ts b/src/providers/v2/static-subgraph-provider.ts index 4d6f1241c..19de03708 100644 --- a/src/providers/v2/static-subgraph-provider.ts +++ b/src/providers/v2/static-subgraph-provider.ts @@ -42,6 +42,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = { [ChainId.AVALANCHE]: [], [ChainId.BASE_GOERLI]: [], [ChainId.BASE]: [], + [ChainId.OPTIMISM_SEPOLIA]: [] }; /** diff --git a/src/providers/v3/static-subgraph-provider.ts b/src/providers/v3/static-subgraph-provider.ts index a6fc4366d..cb56a1076 100644 --- a/src/providers/v3/static-subgraph-provider.ts +++ b/src/providers/v3/static-subgraph-provider.ts @@ -154,6 +154,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = { ], [ChainId.BASE_GOERLI]: [WRAPPED_NATIVE_CURRENCY[ChainId.BASE_GOERLI]], [ChainId.BASE]: [WRAPPED_NATIVE_CURRENCY[ChainId.BASE], USDC_BASE], + [ChainId.OPTIMISM_SEPOLIA]: [WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_SEPOLIA]] }; /** diff --git a/src/routers/alpha-router/gas-models/v3/gas-costs.ts b/src/routers/alpha-router/gas-models/v3/gas-costs.ts index b197266ac..d4a23d7ae 100644 --- a/src/routers/alpha-router/gas-models/v3/gas-costs.ts +++ b/src/routers/alpha-router/gas-models/v3/gas-costs.ts @@ -15,6 +15,7 @@ export const BASE_SWAP_COST = (id: ChainId): BigNumber => { case ChainId.SEPOLIA: case ChainId.OPTIMISM: case ChainId.OPTIMISM_GOERLI: + case ChainId.OPTIMISM_SEPOLIA: case ChainId.BNB: case ChainId.AVALANCHE: case ChainId.BASE: @@ -48,6 +49,7 @@ export const COST_PER_INIT_TICK = (id: ChainId): BigNumber => { return BigNumber.from(31000); case ChainId.OPTIMISM: case ChainId.OPTIMISM_GOERLI: + case ChainId.OPTIMISM_SEPOLIA: case ChainId.BASE: case ChainId.BASE_GOERLI: return BigNumber.from(31000); @@ -75,6 +77,7 @@ export const COST_PER_HOP = (id: ChainId): BigNumber => { case ChainId.BNB: case ChainId.OPTIMISM: case ChainId.OPTIMISM_GOERLI: + case ChainId.OPTIMISM_SEPOLIA: case ChainId.AVALANCHE: case ChainId.BASE: case ChainId.BASE_GOERLI: diff --git a/src/routers/legacy-router/bases.ts b/src/routers/legacy-router/bases.ts index ef174dc29..269fdadde 100644 --- a/src/routers/legacy-router/bases.ts +++ b/src/routers/legacy-router/bases.ts @@ -41,6 +41,9 @@ export const BASES_TO_CHECK_TRADES_AGAINST = ( [ChainId.OPTIMISM_GOERLI]: [ WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_GOERLI]!, ], + [ChainId.OPTIMISM_SEPOLIA]: [ + WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM_SEPOLIA]!, + ], [ChainId.ARBITRUM_ONE]: [WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_ONE]!], [ChainId.ARBITRUM_GOERLI]: [ WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_GOERLI]!, diff --git a/src/util/addresses.ts b/src/util/addresses.ts index fead6df9b..a0e4e0796 100644 --- a/src/util/addresses.ts +++ b/src/util/addresses.ts @@ -79,6 +79,8 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = { export const SWAP_ROUTER_02_ADDRESSES = (chainId: number): string => { if (chainId == ChainId.BNB) { return BNB_SWAP_ROUTER_02_ADDRESS; + } else if (chainId == ChainId.BASE) { + return CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].swapRouter02Address!; } return '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'; }; @@ -158,6 +160,13 @@ export const WETH9: { 'WETH', 'Wrapped Ether' ), + [ChainId.OPTIMISM_SEPOLIA]: new Token( + ChainId.OPTIMISM_SEPOLIA, + '0x4200000000000000000000000000000000000006', + 18, + 'WETH', + 'Wrapped Ether' + ), [ChainId.ARBITRUM_ONE]: new Token( ChainId.ARBITRUM_ONE, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', diff --git a/src/util/chains.ts b/src/util/chains.ts index c3a14d5f0..6559ab8f3 100644 --- a/src/util/chains.ts +++ b/src/util/chains.ts @@ -317,6 +317,13 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId in ChainId]: Token } = { 'WETH', 'Wrapped Ether' ), + [ChainId.OPTIMISM_SEPOLIA]: new Token( + ChainId.OPTIMISM_SEPOLIA, + '0x4200000000000000000000000000000000000006', + 18, + 'WETH', + 'Wrapped Ether' + ), [ChainId.ARBITRUM_ONE]: new Token( ChainId.ARBITRUM_ONE, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', From 3b6904224dd541c52ddaac3b6a3fa0d698c64199 Mon Sep 17 00:00:00 2001 From: Alex Sismanis Date: Mon, 29 Jan 2024 18:06:09 -0600 Subject: [PATCH 2/5] Regen package-lock --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 6739a63b0..d3828de68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,8 @@ "@types/brotli": "^1.3.4", "@uniswap/default-token-list": "^11.2.0", "@uniswap/permit2-sdk": "^1.2.0", - "@uniswap/sdk-core": "^4.0.9", "@uniswap/router-sdk": "^1.7.5", + "@uniswap/sdk-core": "^4.0.9", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.6.0", From 9328a0bb52a914b66acbb26525d99a9fd6c067c2 Mon Sep 17 00:00:00 2001 From: Alex Sismanis Date: Fri, 9 Feb 2024 10:03:50 -0700 Subject: [PATCH 3/5] Adding avalanche swap router address --- package-lock.json | 3 ++- package.json | 2 +- src/util/addresses.ts | 14 +++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index d3828de68..35a0e7eab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2323,6 +2323,7 @@ "resolved": "https://registry.npmjs.org/@oclif/config/-/config-1.18.3.tgz", "integrity": "sha512-sBpko86IrTscc39EvHUhL+c++81BVTsIZ3ETu/vG+cCdi0N6vb2DoahR67A9FI2CGnxRRHjnTfa3m6LulwNATA==", "dev": true, + "peer": true, "dependencies": { "@oclif/errors": "^1.3.5", "@oclif/parser": "^3.8.0", @@ -13404,7 +13405,6 @@ "integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==", "dev": true, "requires": { - "@oclif/config": "^1.18.2", "@oclif/errors": "^1.3.5", "@oclif/help": "^1.0.1", "@oclif/parser": "^3.8.6", @@ -13417,6 +13417,7 @@ "resolved": "https://registry.npmjs.org/@oclif/config/-/config-1.18.3.tgz", "integrity": "sha512-sBpko86IrTscc39EvHUhL+c++81BVTsIZ3ETu/vG+cCdi0N6vb2DoahR67A9FI2CGnxRRHjnTfa3m6LulwNATA==", "dev": true, + "peer": true, "requires": { "@oclif/errors": "^1.3.5", "@oclif/parser": "^3.8.0", diff --git a/package.json b/package.json index 8c1355fe7..f426c3292 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "@types/brotli": "^1.3.4", "@uniswap/default-token-list": "^11.2.0", "@uniswap/permit2-sdk": "^1.2.0", - "@uniswap/sdk-core": "^4.0.9", "@uniswap/router-sdk": "^1.7.5", + "@uniswap/sdk-core": "^4.0.9", "@uniswap/swap-router-contracts": "^1.3.0", "@uniswap/token-lists": "^1.0.0-beta.31", "@uniswap/universal-router": "^1.6.0", diff --git a/src/util/addresses.ts b/src/util/addresses.ts index a0e4e0796..c27b9fbfd 100644 --- a/src/util/addresses.ts +++ b/src/util/addresses.ts @@ -77,12 +77,16 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = { }; export const SWAP_ROUTER_02_ADDRESSES = (chainId: number): string => { - if (chainId == ChainId.BNB) { - return BNB_SWAP_ROUTER_02_ADDRESS; - } else if (chainId == ChainId.BASE) { - return CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].swapRouter02Address!; + switch (chainId) { + case ChainId.BNB: + return BNB_SWAP_ROUTER_02_ADDRESS; + case ChainId.BASE: + return CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].swapRouter02Address!; + case ChainId.AVALANCHE: + return CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].swapRouter02Address!; + default: + return '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'; } - return '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'; }; export const OVM_GASPRICE_ADDRESS = From 72513610c23fd7e48231526d27830be655d4912c Mon Sep 17 00:00:00 2001 From: Alex Sismanis Date: Tue, 13 Feb 2024 17:19:45 -0600 Subject: [PATCH 4/5] Bump to uniswap sdk core version 4.1.2 --- package-lock.json | 17 ++++++++--------- package.json | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35a0e7eab..06e6544d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,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", @@ -2323,7 +2323,6 @@ "resolved": "https://registry.npmjs.org/@oclif/config/-/config-1.18.3.tgz", "integrity": "sha512-sBpko86IrTscc39EvHUhL+c++81BVTsIZ3ETu/vG+cCdi0N6vb2DoahR67A9FI2CGnxRRHjnTfa3m6LulwNATA==", "dev": true, - "peer": true, "dependencies": { "@oclif/errors": "^1.3.5", "@oclif/parser": "^3.8.0", @@ -3135,9 +3134,9 @@ } }, "node_modules/@uniswap/sdk-core": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.10.tgz", - "integrity": "sha512-RiobXJKXvVVb+wfNM09Ik8djOMOuRQGfyRP5pHgUjojicK/7nscZILjZ87DjVCGjXEoD8yTSIps0UAQuz6pJIw==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.1.2.tgz", + "integrity": "sha512-bk/oHiNCofy48ix84Q8aK/HHDmMVmk+SaoTq6U/93MmJ/nE7hbsckmY1c3MG2Vz1+jnGMCX9AmdBbnSF7VR5Ow==", "dependencies": { "@ethersproject/address": "^5.0.2", "big.js": "^5.2.2", @@ -13405,6 +13404,7 @@ "integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==", "dev": true, "requires": { + "@oclif/config": "^1.18.2", "@oclif/errors": "^1.3.5", "@oclif/help": "^1.0.1", "@oclif/parser": "^3.8.6", @@ -13417,7 +13417,6 @@ "resolved": "https://registry.npmjs.org/@oclif/config/-/config-1.18.3.tgz", "integrity": "sha512-sBpko86IrTscc39EvHUhL+c++81BVTsIZ3ETu/vG+cCdi0N6vb2DoahR67A9FI2CGnxRRHjnTfa3m6LulwNATA==", "dev": true, - "peer": true, "requires": { "@oclif/errors": "^1.3.5", "@oclif/parser": "^3.8.0", @@ -14099,9 +14098,9 @@ } }, "@uniswap/sdk-core": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.0.10.tgz", - "integrity": "sha512-RiobXJKXvVVb+wfNM09Ik8djOMOuRQGfyRP5pHgUjojicK/7nscZILjZ87DjVCGjXEoD8yTSIps0UAQuz6pJIw==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@uniswap/sdk-core/-/sdk-core-4.1.2.tgz", + "integrity": "sha512-bk/oHiNCofy48ix84Q8aK/HHDmMVmk+SaoTq6U/93MmJ/nE7hbsckmY1c3MG2Vz1+jnGMCX9AmdBbnSF7VR5Ow==", "requires": { "@ethersproject/address": "^5.0.2", "big.js": "^5.2.2", diff --git a/package.json b/package.json index f426c3292..345034008 100644 --- a/package.json +++ b/package.json @@ -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", From 278defeafbf819fb6074ca2eba1fc2c960402ee9 Mon Sep 17 00:00:00 2001 From: Alex Sismanis Date: Tue, 13 Feb 2024 18:23:25 -0600 Subject: [PATCH 5/5] Adding arbitrum sepolia and importing swap router address from sdk core --- src/providers/simulation-provider.ts | 4 +-- src/providers/swap-router-provider.ts | 4 +-- src/providers/tenderly-simulation-provider.ts | 3 +- src/providers/token-provider.ts | 19 +++++++++++ src/routers/alpha-router/alpha-router.ts | 3 +- src/routers/legacy-router/legacy-router.ts | 3 +- src/util/addresses.ts | 32 +++++++++++-------- src/util/chains.ts | 7 ++++ src/util/methodParameters.ts | 3 +- .../alpha-router.integration.test.ts | 10 ++++-- 10 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/providers/simulation-provider.ts b/src/providers/simulation-provider.ts index 434889106..259f4c34b 100644 --- a/src/providers/simulation-provider.ts +++ b/src/providers/simulation-provider.ts @@ -1,5 +1,5 @@ import { JsonRpcProvider } from '@ethersproject/providers'; -import { ChainId, TradeType } from '@uniswap/sdk-core'; +import { ChainId, TradeType, SWAP_ROUTER_02_ADDRESSES } from '@uniswap/sdk-core'; import { PERMIT2_ADDRESS } from '@uniswap/universal-router-sdk'; import { BigNumber } from 'ethers/lib/ethers'; @@ -11,7 +11,7 @@ import { } from '../routers'; import { Erc20__factory } from '../types/other/factories/Erc20__factory'; import { Permit2__factory } from '../types/other/factories/Permit2__factory'; -import { CurrencyAmount, log, SWAP_ROUTER_02_ADDRESSES } from '../util'; +import { CurrencyAmount, log } from '../util'; import { IPortionProvider } from './portion-provider'; import { ArbitrumGasData, OptimismGasData } from './v3/gas-data-provider'; diff --git a/src/providers/swap-router-provider.ts b/src/providers/swap-router-provider.ts index ccd8fb5bf..cd7a788c9 100644 --- a/src/providers/swap-router-provider.ts +++ b/src/providers/swap-router-provider.ts @@ -1,8 +1,8 @@ import { ApprovalTypes } from '@uniswap/router-sdk'; -import { ChainId, Currency, CurrencyAmount } from '@uniswap/sdk-core'; +import { ChainId, Currency, CurrencyAmount, SWAP_ROUTER_02_ADDRESSES } from '@uniswap/sdk-core'; import { SwapRouter02__factory } from '../types/other/factories/SwapRouter02__factory'; -import { log, SWAP_ROUTER_02_ADDRESSES } from '../util'; +import { log } from '../util'; import { IMulticallProvider } from './multicall-provider'; diff --git a/src/providers/tenderly-simulation-provider.ts b/src/providers/tenderly-simulation-provider.ts index 4fa345904..d18d76acd 100644 --- a/src/providers/tenderly-simulation-provider.ts +++ b/src/providers/tenderly-simulation-provider.ts @@ -3,7 +3,7 @@ import https from 'https'; import { MaxUint256 } from '@ethersproject/constants'; import { JsonRpcProvider } from '@ethersproject/providers'; -import { ChainId } from '@uniswap/sdk-core'; +import { ChainId, SWAP_ROUTER_02_ADDRESSES } from '@uniswap/sdk-core'; import { PERMIT2_ADDRESS, UNIVERSAL_ROUTER_ADDRESS, @@ -25,7 +25,6 @@ import { BEACON_CHAIN_DEPOSIT_ADDRESS, log, MAX_UINT160, - SWAP_ROUTER_02_ADDRESSES, } from '../util'; import { APPROVE_TOKEN_FOR_TRANSFER } from '../util/callData'; import { diff --git a/src/providers/token-provider.ts b/src/providers/token-provider.ts index 6bc0c4851..5bff84c78 100644 --- a/src/providers/token-provider.ts +++ b/src/providers/token-provider.ts @@ -182,6 +182,13 @@ export const OP_OPTIMISM = new Token( 'Optimism' ); +export const USDC_OPTIMISM_SEPOLIA = new Token( + ChainId.OPTIMISM_SEPOLIA, + '0x5fd84259d66Cd46123540766Be93DFE6D43130D7', + 6, + 'USDC', + 'USD//C' +); export const USDC_OPTIMISM_GOERLI = new Token( ChainId.OPTIMISM_GOERLI, '0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E', @@ -265,6 +272,14 @@ export const USDC_ARBITRUM_GOERLI = new Token( 'USD//C' ); +export const USDC_ARBITRUM_SEPOLIA = new Token( + ChainId.ARBITRUM_SEPOLIA, + '0x1459F5c7FC539F42ffd0c63A0e4AD000dfF70919', + 6, + 'USDC', + 'USD//C' +); + //polygon tokens export const WMATIC_POLYGON = new Token( ChainId.POLYGON, @@ -775,10 +790,14 @@ export const USDC_ON = (chainId: ChainId): Token => { return USDC_OPTIMISM; case ChainId.OPTIMISM_GOERLI: return USDC_OPTIMISM_GOERLI; + case ChainId.OPTIMISM_SEPOLIA: + return USDC_OPTIMISM_SEPOLIA; case ChainId.ARBITRUM_ONE: 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: diff --git a/src/routers/alpha-router/alpha-router.ts b/src/routers/alpha-router/alpha-router.ts index d955f73b5..51ea6c452 100644 --- a/src/routers/alpha-router/alpha-router.ts +++ b/src/routers/alpha-router/alpha-router.ts @@ -6,6 +6,7 @@ import { ChainId, Currency, Fraction, + SWAP_ROUTER_02_ADDRESSES, Token, TradeType, } from '@uniswap/sdk-core'; @@ -83,7 +84,7 @@ import { } from '../../providers/v3/pool-provider'; import { IV3SubgraphProvider } from '../../providers/v3/subgraph-provider'; import { Erc20__factory } from '../../types/other/factories/Erc20__factory'; -import { SWAP_ROUTER_02_ADDRESSES, WRAPPED_NATIVE_CURRENCY } from '../../util'; +import { WRAPPED_NATIVE_CURRENCY } from '../../util'; import { CurrencyAmount } from '../../util/amounts'; import { ID_TO_CHAIN_ID, diff --git a/src/routers/legacy-router/legacy-router.ts b/src/routers/legacy-router/legacy-router.ts index 3519ff08c..f280081c7 100644 --- a/src/routers/legacy-router/legacy-router.ts +++ b/src/routers/legacy-router/legacy-router.ts @@ -1,7 +1,7 @@ import { BigNumber } from '@ethersproject/bignumber'; import { Logger } from '@ethersproject/logger'; import { SwapRouter, Trade } from '@uniswap/router-sdk'; -import { ChainId, Currency, Token, TradeType } from '@uniswap/sdk-core'; +import { ChainId, Currency, SWAP_ROUTER_02_ADDRESSES, Token, TradeType } from '@uniswap/sdk-core'; import { FeeAmount, MethodParameters, Pool, Route } from '@uniswap/v3-sdk'; import _ from 'lodash'; @@ -13,7 +13,6 @@ import { USDC_MAINNET, } from '../../providers/token-provider'; import { IV3PoolProvider } from '../../providers/v3/pool-provider'; -import { SWAP_ROUTER_02_ADDRESSES } from '../../util'; import { CurrencyAmount } from '../../util/amounts'; import { log } from '../../util/log'; import { routeToString } from '../../util/routes'; diff --git a/src/util/addresses.ts b/src/util/addresses.ts index c27b9fbfd..bc5577a08 100644 --- a/src/util/addresses.ts +++ b/src/util/addresses.ts @@ -19,10 +19,14 @@ export const V3_CORE_FACTORY_ADDRESSES: AddressMap = { CHAIN_TO_ADDRESSES_MAP[ChainId.CELO_ALFAJORES].v3CoreFactoryAddress, [ChainId.OPTIMISM_GOERLI]: CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_GOERLI].v3CoreFactoryAddress, + [ChainId.OPTIMISM_SEPOLIA]: + CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_SEPOLIA].v3CoreFactoryAddress, [ChainId.SEPOLIA]: 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, @@ -39,9 +43,13 @@ export const QUOTER_V2_ADDRESSES: AddressMap = { CHAIN_TO_ADDRESSES_MAP[ChainId.CELO_ALFAJORES].quoterAddress, [ChainId.OPTIMISM_GOERLI]: CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_GOERLI].quoterAddress, + [ChainId.OPTIMISM_SEPOLIA]: + CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_SEPOLIA].quoterAddress, [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]: @@ -64,9 +72,13 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = { CHAIN_TO_ADDRESSES_MAP[ChainId.CELO_ALFAJORES].multicallAddress, [ChainId.OPTIMISM_GOERLI]: CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_GOERLI].multicallAddress, + [ChainId.OPTIMISM_SEPOLIA]: + CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM_SEPOLIA].multicallAddress, [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, @@ -76,19 +88,6 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = { // TODO: Gnosis + Moonbeam contracts to be deployed }; -export const SWAP_ROUTER_02_ADDRESSES = (chainId: number): string => { - switch (chainId) { - case ChainId.BNB: - return BNB_SWAP_ROUTER_02_ADDRESS; - case ChainId.BASE: - return CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].swapRouter02Address!; - case ChainId.AVALANCHE: - return CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].swapRouter02Address!; - default: - return '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'; - } -}; - export const OVM_GASPRICE_ADDRESS = '0x420000000000000000000000000000000000000F'; export const ARB_GASINFO_ADDRESS = '0x000000000000000000000000000000000000006C'; @@ -185,6 +184,13 @@ export const WETH9: { 'WETH', 'Wrapped Ether' ), + [ChainId.ARBITRUM_SEPOLIA]: new Token( + ChainId.ARBITRUM_SEPOLIA, + '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73', + 18, + 'WETH', + 'Wrapped Ether' + ), [ChainId.BASE_GOERLI]: new Token( ChainId.BASE_GOERLI, '0x4200000000000000000000000000000000000006', diff --git a/src/util/chains.ts b/src/util/chains.ts index eec7e6746..cad54f7c7 100644 --- a/src/util/chains.ts +++ b/src/util/chains.ts @@ -348,6 +348,13 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId in ChainId]: Token } = { 'WETH', 'Wrapped Ether' ), + [ChainId.ARBITRUM_SEPOLIA]: new Token( + ChainId.ARBITRUM_SEPOLIA, + '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73', + 18, + 'WETH', + 'Wrapped Ether' + ), [ChainId.POLYGON]: new Token( ChainId.POLYGON, '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', diff --git a/src/util/methodParameters.ts b/src/util/methodParameters.ts index 4f02125c0..ec77c3acd 100644 --- a/src/util/methodParameters.ts +++ b/src/util/methodParameters.ts @@ -4,7 +4,7 @@ import { SwapRouter as SwapRouter02, Trade, } from '@uniswap/router-sdk'; -import { ChainId, Currency, TradeType } from '@uniswap/sdk-core'; +import { ChainId, Currency, SWAP_ROUTER_02_ADDRESSES, TradeType } from '@uniswap/sdk-core'; import { UNIVERSAL_ROUTER_ADDRESS, SwapRouter as UniversalRouter, @@ -18,7 +18,6 @@ import { MethodParameters, MixedRouteWithValidQuote, RouteWithValidQuote, - SWAP_ROUTER_02_ADDRESSES, SwapOptions, SwapType, V2RouteWithValidQuote, diff --git a/test/integ/routers/alpha-router/alpha-router.integration.test.ts b/test/integ/routers/alpha-router/alpha-router.integration.test.ts index e10387f4d..b8bc4b8be 100644 --- a/test/integ/routers/alpha-router/alpha-router.integration.test.ts +++ b/test/integ/routers/alpha-router/alpha-router.integration.test.ts @@ -13,6 +13,7 @@ import { Fraction, Percent, Rounding, + SWAP_ROUTER_02_ADDRESSES, Token, TradeType } from '@uniswap/sdk-core'; @@ -56,7 +57,6 @@ import { SimulationStatus, StaticGasPriceProvider, SUPPORTED_CHAINS, - SWAP_ROUTER_02_ADDRESSES, SwapOptions, SwapType, TenderlySimulator, @@ -98,14 +98,16 @@ const LARGE_SLIPPAGE = new Percent(45, 100); // 5% or 10_000? // Those are the worst deviation (we intend to keep them low and strict) tested manually with FORK_BLOCK = 18222746 // We may need to tune them if we change the FORK_BLOCK -const GAS_ESTIMATE_DEVIATION_PERCENT: { [chainId in ChainId]: number } = { +const GAS_ESTIMATE_DEVIATION_PERCENT: { [chainId in ChainId]: number } = { [ChainId.MAINNET]: 35, [ChainId.GOERLI]: 62, [ChainId.SEPOLIA]: 50, [ChainId.OPTIMISM]: 26, [ChainId.OPTIMISM_GOERLI]: 30, + [ChainId.OPTIMISM_SEPOLIA]: 30, [ChainId.ARBITRUM_ONE]: 53, [ChainId.ARBITRUM_GOERLI]: 50, + [ChainId.ARBITRUM_SEPOLIA]: 50, [ChainId.POLYGON]: 34, [ChainId.POLYGON_MUMBAI]: 30, [ChainId.CELO]: 30, @@ -3285,6 +3287,8 @@ describe('quote for other networks', () => { [ChainId.AVALANCHE]: () => USDC_ON(ChainId.AVALANCHE), [ChainId.BASE]: () => USDC_ON(ChainId.BASE), [ChainId.BASE_GOERLI]: () => USDC_ON(ChainId.BASE_GOERLI), + [ChainId.OPTIMISM_SEPOLIA]: () => USDC_ON(ChainId.OPTIMISM_SEPOLIA), + [ChainId.ARBITRUM_SEPOLIA]: () => USDC_ON(ChainId.ARBITRUM_SEPOLIA), }; const TEST_ERC20_2: { [chainId in ChainId]: () => Token } = { [ChainId.MAINNET]: () => DAI_ON(1), @@ -3304,6 +3308,8 @@ describe('quote for other networks', () => { [ChainId.AVALANCHE]: () => DAI_ON(ChainId.AVALANCHE), [ChainId.BASE]: () => WNATIVE_ON(ChainId.BASE), [ChainId.BASE_GOERLI]: () => WNATIVE_ON(ChainId.BASE_GOERLI), + [ChainId.OPTIMISM_SEPOLIA]: () => WNATIVE_ON(ChainId.OPTIMISM_SEPOLIA), + [ChainId.ARBITRUM_SEPOLIA]: () => WNATIVE_ON(ChainId.ARBITRUM_SEPOLIA), }; // TODO: Find valid pools/tokens on optimistic kovan and polygon mumbai. We skip those tests for now.