Skip to content

Commit

Permalink
Merge branch 'fix-base-swap-router' of https://github.com/L1-Advisors…
Browse files Browse the repository at this point in the history
…/smart-order-router into fix-base-swap-router
  • Loading branch information
sismanis committed Feb 15, 2024
2 parents db350e7 + 278defe commit 84d7ee1
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 32 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
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
17 changes: 17 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,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 @@ -308,6 +315,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 @@ -877,6 +892,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
2 changes: 1 addition & 1 deletion src/providers/v2/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
DAI_AVAX,
],
[ChainId.BASE_GOERLI]: [],
[ChainId.BASE]: [WRAPPED_NATIVE_CURRENCY[ChainId.BASE], USDC_BASE],
[ChainId.BASE]: [WRAPPED_NATIVE_CURRENCY[ChainId.BASE], USDC_BASE ]
};

/**
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
22 changes: 13 additions & 9 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 All @@ -82,15 +88,6 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
// TODO: Gnosis + Moonbeam contracts to be deployed
};

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';
};

export const OVM_GASPRICE_ADDRESS =
'0x420000000000000000000000000000000000000F';
export const ARB_GASINFO_ADDRESS = '0x000000000000000000000000000000000000006C';
Expand Down Expand Up @@ -187,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 @@ -363,6 +363,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
11 changes: 8 additions & 3 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 @@ -115,7 +115,7 @@ 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,
Expand All @@ -124,7 +124,8 @@ const GAS_ESTIMATE_DEVIATION_PERCENT: { [chainId in ChainId]: number } = {
[ChainId.OPTIMISM_SEPOLIA]: 30,
[ChainId.ARBITRUM_ONE]: 53,
[ChainId.ARBITRUM_GOERLI]: 50,
[ChainId.POLYGON]: 38,
[ChainId.ARBITRUM_SEPOLIA]: 50,
[ChainId.POLYGON]: 34,
[ChainId.POLYGON_MUMBAI]: 30,
[ChainId.CELO]: 30,
[ChainId.CELO_ALFAJORES]: 30,
Expand Down Expand Up @@ -3318,6 +3319,8 @@ describe('quote for other networks', () => {
[ChainId.BASE]: () => USDC_ON(ChainId.BASE),
[ChainId.BASE]: () => USDC_NATIVE_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 @@ -3338,6 +3341,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 84d7ee1

Please sign in to comment.