Skip to content

Commit

Permalink
Adding arbitrum sepolia and importing swap router address from sdk core
Browse files Browse the repository at this point in the history
  • Loading branch information
sismanis committed Feb 14, 2024
1 parent 7251361 commit 278defe
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/providers/simulation-provider.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/providers/swap-router-provider.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
3 changes: 1 addition & 2 deletions src/providers/tenderly-simulation-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ChainId,
Currency,
Fraction,
SWAP_ROUTER_02_ADDRESSES,
Token,
TradeType,
} from '@uniswap/sdk-core';
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/routers/legacy-router/legacy-router.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
Expand Down
32 changes: 19 additions & 13 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]:
Expand All @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions src/util/methodParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +18,6 @@ import {
MethodParameters,
MixedRouteWithValidQuote,
RouteWithValidQuote,
SWAP_ROUTER_02_ADDRESSES,
SwapOptions,
SwapType,
V2RouteWithValidQuote,
Expand Down
10 changes: 8 additions & 2 deletions test/integ/routers/alpha-router/alpha-router.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Fraction,
Percent,
Rounding,
SWAP_ROUTER_02_ADDRESSES,
Token,
TradeType
} from '@uniswap/sdk-core';
Expand Down Expand Up @@ -56,7 +57,6 @@ import {
SimulationStatus,
StaticGasPriceProvider,
SUPPORTED_CHAINS,
SWAP_ROUTER_02_ADDRESSES,
SwapOptions,
SwapType,
TenderlySimulator,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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.
Expand Down

0 comments on commit 278defe

Please sign in to comment.