Skip to content

Commit

Permalink
feat: add remaining l2 on v2 integ-tests (Uniswap#489)
Browse files Browse the repository at this point in the history
* add optimism l2 on v2 integ-tests

* simplify test setup

* add error log for quote provider to debug reserve issue in github ci

* change to console log

* add polygon and base v2 integ-test

* add avax v2 integ-test

* add v2 supported L2 chains

* remove console log

* add whales address for other L2 usdc native

* increase polygon gas deviation to 38% due to v2 split
  • Loading branch information
jsy1218 authored Feb 15, 2024
1 parent e577081 commit ee61c9a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const V2_SUPPORTED = [
ChainId.GOERLI,
ChainId.SEPOLIA,
ChainId.ARBITRUM_ONE,
ChainId.OPTIMISM,
ChainId.POLYGON,
ChainId.BASE,
ChainId.BNB,
ChainId.AVALANCHE,
];

export const HAS_L1_FEE = [
Expand Down
2 changes: 1 addition & 1 deletion src/util/gas-factory-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber';
import { Protocol } from '@uniswap/router-sdk';
import { ChainId, Percent, Token, TradeType } from '@uniswap/sdk-core';
import { Pair } from '@uniswap/v2-sdk/dist/entities';
import { FeeAmount, Pool } from '@uniswap/v3-sdk';
import brotli from 'brotli';
import JSBI from 'jsbi';
Expand Down Expand Up @@ -32,6 +31,7 @@ import { CurrencyAmount, log, WRAPPED_NATIVE_CURRENCY } from '../util';

import { opStackChains } from './l2FeeChains';
import { buildSwapMethodParameters, buildTrade } from './methodParameters';
import { Pair } from '@uniswap/v2-sdk';

export async function getV2NativePool(
token: Token,
Expand Down
48 changes: 38 additions & 10 deletions test/integ/routers/alpha-router/alpha-router.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import {
USDC_BNB,
USDC_ETHEREUM_GNOSIS,
USDC_MAINNET,
USDC_NATIVE_ARBITRUM,
USDC_NATIVE_OPTIMISM,
USDC_ON,
USDT_BNB,
USDT_MAINNET,
Expand All @@ -80,14 +82,28 @@ import {
WETH9,
WNATIVE_ON,
WRAPPED_NATIVE_CURRENCY,
USDC_NATIVE_ARBITRUM
USDC_NATIVE_POLYGON,
USDC_NATIVE_BASE,
USDC_NATIVE_AVAX
} from '../../../../src';
import { PortionProvider } from '../../../../src/providers/portion-provider';
import { OnChainTokenFeeFetcher } from '../../../../src/providers/token-fee-fetcher';
import { DEFAULT_ROUTING_CONFIG_BY_CHAIN } from '../../../../src/routers/alpha-router/config';
import { Permit2__factory } from '../../../../src/types/other/factories/Permit2__factory';
import {
OnChainTokenFeeFetcher
} from '../../../../src/providers/token-fee-fetcher';
import {
DEFAULT_ROUTING_CONFIG_BY_CHAIN
} from '../../../../src/routers/alpha-router/config';
import {
Permit2__factory
} from '../../../../src/types/other/factories/Permit2__factory';
import { getBalanceAndApprove } from '../../../test-util/getBalanceAndApprove';
import { BULLET, BULLET_WITHOUT_TAX, FLAT_PORTION, GREENLIST_TOKEN_PAIRS, Portion } from '../../../test-util/mock-data';
import {
BULLET,
BULLET_WITHOUT_TAX,
FLAT_PORTION,
GREENLIST_TOKEN_PAIRS,
Portion
} from '../../../test-util/mock-data';
import { WHALES } from '../../../test-util/whales';

// TODO: this should be at a later block that's aware of universal router v1.3 0x3F6328669a86bef431Dc6F9201A5B90F7975a023 deployed at block 18222746. We can use later block, e.g. at block 18318644
Expand All @@ -103,25 +119,30 @@ const GAS_ESTIMATE_DEVIATION_PERCENT: { [chainId in ChainId]: number } = {
[ChainId.MAINNET]: 35,
[ChainId.GOERLI]: 62,
[ChainId.SEPOLIA]: 50,
[ChainId.OPTIMISM]: 26,
[ChainId.OPTIMISM]: 35,
[ChainId.OPTIMISM_GOERLI]: 30,
[ChainId.OPTIMISM_SEPOLIA]: 30,
[ChainId.ARBITRUM_ONE]: 53,
[ChainId.ARBITRUM_GOERLI]: 50,
[ChainId.POLYGON]: 34,
[ChainId.POLYGON]: 38,
[ChainId.POLYGON_MUMBAI]: 30,
[ChainId.CELO]: 30,
[ChainId.CELO_ALFAJORES]: 30,
[ChainId.GNOSIS]: 30,
[ChainId.MOONBEAM]: 30,
[ChainId.BNB]: 35,
[ChainId.BNB]: 44,
[ChainId.AVALANCHE]: 36,
[ChainId.BASE]: 34,
[ChainId.BASE_GOERLI]: 30,
}

const V2_SUPPORTED_PAIRS = [
[WETH9[ChainId.ARBITRUM_ONE], USDC_NATIVE_ARBITRUM],
[WETH9[ChainId.OPTIMISM], USDC_NATIVE_OPTIMISM],
[WRAPPED_NATIVE_CURRENCY[ChainId.POLYGON], USDC_NATIVE_POLYGON],
[WETH9[ChainId.BASE], USDC_NATIVE_BASE],
[WRAPPED_NATIVE_CURRENCY[ChainId.BNB], USDC_BNB],
[WRAPPED_NATIVE_CURRENCY[ChainId.AVALANCHE], USDC_NATIVE_AVAX],
];

const checkQuoteToken = (
Expand Down Expand Up @@ -3278,19 +3299,24 @@ describe('quote for other networks', () => {
[ChainId.GOERLI]: () => UNI_GOERLI,
[ChainId.SEPOLIA]: () => USDC_ON(ChainId.SEPOLIA),
[ChainId.OPTIMISM]: () => USDC_ON(ChainId.OPTIMISM),
[ChainId.OPTIMISM]: () => USDC_NATIVE_OPTIMISM,
[ChainId.OPTIMISM_GOERLI]: () => USDC_ON(ChainId.OPTIMISM_GOERLI),
[ChainId.OPTIMISM_SEPOLIA]: () => USDC_ON(ChainId.OPTIMISM_SEPOLIA),
[ChainId.ARBITRUM_ONE]: () => USDC_ON(ChainId.ARBITRUM_ONE),
[ChainId.ARBITRUM_ONE]: () => USDC_NATIVE_ARBITRUM,
[ChainId.ARBITRUM_GOERLI]: () => USDC_ON(ChainId.ARBITRUM_GOERLI),
[ChainId.POLYGON]: () => USDC_ON(ChainId.POLYGON),
[ChainId.POLYGON]: () => USDC_NATIVE_POLYGON,
[ChainId.POLYGON_MUMBAI]: () => USDC_ON(ChainId.POLYGON_MUMBAI),
[ChainId.CELO]: () => CUSD_CELO,
[ChainId.CELO_ALFAJORES]: () => CUSD_CELO_ALFAJORES,
[ChainId.GNOSIS]: () => WBTC_GNOSIS,
[ChainId.MOONBEAM]: () => WBTC_MOONBEAM,
[ChainId.BNB]: () => USDC_BNB,
[ChainId.AVALANCHE]: () => USDC_ON(ChainId.AVALANCHE),
[ChainId.AVALANCHE]: () => USDC_NATIVE_AVAX,
[ChainId.BASE]: () => USDC_ON(ChainId.BASE),
[ChainId.BASE]: () => USDC_NATIVE_BASE,
[ChainId.BASE_GOERLI]: () => USDC_ON(ChainId.BASE_GOERLI),
};
const TEST_ERC20_2: { [chainId in ChainId]: () => Token } = {
Expand Down Expand Up @@ -3427,7 +3453,8 @@ describe('quote for other networks', () => {
const tokenIn = wrappedNative;
const tokenOut = erc1;

const isV2PairRoutable = V2_SUPPORTED_PAIRS.find((pair) => pair[0]!.equals(tokenIn) && pair[1]!.equals(tokenOut));
const isV2PairRoutable =
V2_SUPPORTED_PAIRS.find((pair) => pair[0]!.equals(tokenIn) && pair[1]!.equals(tokenOut));

if (!isV2PairRoutable) {
return;
Expand Down Expand Up @@ -3697,7 +3724,8 @@ describe('quote for other networks', () => {
const tokenIn = wrappedNative;
const tokenOut = erc1;

const isV2PairRoutable = V2_SUPPORTED_PAIRS.find((pair) => pair[0]!.equals(tokenIn) && pair[1]!.equals(tokenOut));
const isV2PairRoutable =
V2_SUPPORTED_PAIRS.find((pair) => pair[0]!.equals(tokenIn) && pair[1]!.equals(tokenOut));

if (!isV2PairRoutable) {
return;
Expand Down
14 changes: 13 additions & 1 deletion test/test-util/whales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import {
UNI_MAINNET,
USDC_MAINNET,
USDC_NATIVE_ARBITRUM,
USDC_NATIVE_AVAX,
USDC_NATIVE_BASE,
USDC_NATIVE_OPTIMISM,
USDC_NATIVE_POLYGON,
USDC_ON,
USDT_MAINNET,
WETH9,
WNATIVE_ON,
WNATIVE_ON
} from '../../src';
import { BULLET, BULLET_WITHOUT_TAX } from './mock-data';

Expand Down Expand Up @@ -66,6 +70,8 @@ export const WHALES = (token: Currency): string => {
return '0x41653c7d61609d856f29355e404f310ec4142cfb';
case USDC_ON(ChainId.OPTIMISM):
return '0xad7b4c162707e0b2b5f6fddbd3f8538a5fba0d60';
case USDC_NATIVE_OPTIMISM:
return '0xf491d040110384dbcf7f241ffe2a546513fd873d';
case USDC_ON(ChainId.OPTIMISM_GOERLI):
return '0x4cb0645e92a3b5872ae54e5704e03c09ca0ea220';
case USDC_ON(ChainId.ARBITRUM_ONE):
Expand All @@ -78,14 +84,20 @@ export const WHALES = (token: Currency): string => {
return '0xe2a3422f3168149AD2d11b4dE2B97b05f1ebF76e';
case USDC_ON(ChainId.POLYGON):
return '0xe7804c37c13166ff0b37f5ae0bb07a3aebb6e245';
case USDC_NATIVE_POLYGON:
return '0x2C2301FDB0bfA06EAABaA0122CbCEb2265337C25';
case USDC_ON(ChainId.POLYGON_MUMBAI):
return '0x48520ff9b32d8b5bf87abf789ea7b3c394c95ebe';
case USDC_ON(ChainId.AVALANCHE):
return '0x9f8c163cBA728e99993ABe7495F06c0A3c8Ac8b9';
case USDC_NATIVE_AVAX:
return '0x3A2434c698f8D79af1f5A9e43013157ca8B11a66';
case USDC_ON(ChainId.BNB):
return '0x8894E0a0c962CB723c1976a4421c95949bE2D4E3';
case USDC_ON(ChainId.BASE):
return '0x4a3636608d7bc5776cb19eb72caa36ebb9ea683b';
case USDC_NATIVE_BASE:
return '0x20fe51a9229eef2cf8ad9e89d91cab9312cf3b7a';
case DAI_ON(ChainId.GOERLI):
return '0x20918f71e99c09ae2ac3e33dbde33457d3be01f4';
case DAI_ON(ChainId.SEPOLIA):
Expand Down

0 comments on commit ee61c9a

Please sign in to comment.