Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sor): support routing on unichain mainnet #766

Merged
merged 17 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ jobs:
TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}

integration-tests-quote-for-other-networks-UNICHAIN:
name: Integration Tests - Quote For Other Networks UNICHAIN
integration-tests-quote-for-other-networks-unichain:
name: Integration Tests - Quote For Other Networks Unichain
runs-on: ubuntu-latest

steps:
Expand All @@ -805,7 +805,41 @@ jobs:
run: npm run build

- name: Run Integration tests
run: npm run integ-test -- -t 'quote for other networks * UNICHAIN'
run: npm run integ-test -- -t 'quote for other networks * unichain'
env:
# TODO: add secret in github secrets
JSON_RPC_PROVIDER_UNICHAIN: ${{ secrets.JSON_RPC_PROVIDER_UNICHAIN }}
TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
TENDERLY_USER: ${{ secrets.TENDERLY_USER }}
TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}

integration-tests-quote-for-other-networks-unichain-sepolia:
name: Integration Tests - Quote For Other Networks Unichain Sepolia
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 18.x
registry-url: https://registry.npmjs.org

- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install

# This is required separately from yarn test because it generates the typechain definitions
- name: Compile
run: npm run build

- name: Run Integration tests
run: npm run integ-test -- -t 'quote for other networks * unichain sepolia'
env:
JSON_RPC_PROVIDER_UNICHAIN_SEPOLIA: ${{ secrets.JSON_RPC_PROVIDER_UNICHAIN_SEPOLIA }}
TENDERLY_BASE_URL: ${{ secrets.TENDERLY_BASE_URL }}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ Total ticks crossed: 7
./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x31d0220469e10c4E71834a79b1f276d740d3768F --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 1301
```

## Unichain Mainnet

```
./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x078D782b760474a361dDA0AF3839290b0EF57AD6 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 130
```

## Monad Testnet

```
Expand Down
9 changes: 8 additions & 1 deletion src/providers/caching-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DAI_MAINNET,
DAI_MOONBEAM,
DAI_OPTIMISM,
DAI_UNICHAIN,
ETH_BNB,
OP_OPTIMISM,
USDB_BLAST,
Expand All @@ -34,6 +35,7 @@
USDC_NATIVE_ARBITRUM,
USDC_OPTIMISM,
USDC_POLYGON,
USDC_UNICHAIN,
USDC_UNICHAIN_SEPOLIA,
USDC_WORLDCHAIN,
USDC_ZKSYNC,
Expand Down Expand Up @@ -61,22 +63,22 @@
export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
[ChainId.MAINNET]: [
nativeOnChain(ChainId.MAINNET),
WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET]!,

Check warning on line 66 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
DAI_MAINNET,
USDC_MAINNET,
USDT_MAINNET,
WBTC_MAINNET,
WSTETH_MAINNET,
],
[ChainId.GOERLI]: [WRAPPED_NATIVE_CURRENCY[ChainId.GOERLI]!],

Check warning on line 73 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
[ChainId.SEPOLIA]: [
nativeOnChain(ChainId.SEPOLIA),
WRAPPED_NATIVE_CURRENCY[ChainId.SEPOLIA]!,

Check warning on line 76 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
],
//v2 not deployed on [arbitrum, polygon, celo, gnosis, moonbeam, bnb, avalanche] and their testnets
[ChainId.OPTIMISM]: [
nativeOnChain(ChainId.OPTIMISM),
WRAPPED_NATIVE_CURRENCY[ChainId.OPTIMISM]!,

Check warning on line 81 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
USDC_OPTIMISM,
DAI_OPTIMISM,
USDT_OPTIMISM,
Expand All @@ -85,7 +87,7 @@
],
[ChainId.ARBITRUM_ONE]: [
nativeOnChain(ChainId.ARBITRUM_ONE),
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_ONE]!,

Check warning on line 90 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
WBTC_ARBITRUM,
DAI_ARBITRUM,
USDC_ARBITRUM,
Expand Down Expand Up @@ -136,17 +138,17 @@
],
[ChainId.ZORA]: [
nativeOnChain(ChainId.ZORA),
WRAPPED_NATIVE_CURRENCY[ChainId.ZORA]!,

Check warning on line 141 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
],
[ChainId.ZORA_SEPOLIA]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZORA_SEPOLIA]!],

Check warning on line 143 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
[ChainId.ROOTSTOCK]: [WRAPPED_NATIVE_CURRENCY[ChainId.ROOTSTOCK]!],

Check warning on line 144 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
[ChainId.BLAST]: [
nativeOnChain(ChainId.BLAST),
WRAPPED_NATIVE_CURRENCY[ChainId.BLAST]!,

Check warning on line 147 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
USDB_BLAST,
],
[ChainId.ZKSYNC]: [
WRAPPED_NATIVE_CURRENCY[ChainId.ZKSYNC]!,

Check warning on line 151 in src/providers/caching-subgraph-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
USDCE_ZKSYNC,
USDC_ZKSYNC,
],
Expand All @@ -162,7 +164,12 @@
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN_SEPOLIA]!,
USDC_UNICHAIN_SEPOLIA,
],
[ChainId.UNICHAIN]: [],
[ChainId.UNICHAIN]: [
nativeOnChain(ChainId.UNICHAIN),
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN]!,
DAI_UNICHAIN,
USDC_UNICHAIN,
],
[ChainId.BASE_SEPOLIA]: [
nativeOnChain(ChainId.BASE_SEPOLIA),
WRAPPED_NATIVE_CURRENCY[ChainId.BASE_SEPOLIA]!,
Expand Down
7 changes: 7 additions & 0 deletions src/providers/caching-token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DAI_OPTIMISM_GOERLI,
DAI_OPTIMISM_SEPOLIA,
DAI_POLYGON_MUMBAI,
DAI_UNICHAIN,
ETH_BNB,
ITokenProvider,
TokenAccessor,
Expand All @@ -43,6 +44,7 @@ import {
USDC_OPTIMISM_SEPOLIA,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_UNICHAIN,
USDC_WORLDCHAIN,
USDT_ARBITRUM,
USDT_BNB,
Expand Down Expand Up @@ -194,6 +196,11 @@ export const CACHE_SEED_TOKENS: {
USDC: USDC_BASE_SEPOLIA,
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.BASE_SEPOLIA],
},
[ChainId.UNICHAIN]: {
DAI: DAI_UNICHAIN,
USDC: USDC_UNICHAIN,
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN],
},
// Currently we do not have providers for Moonbeam mainnet or Gnosis testnet
};

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 @@ -765,6 +765,23 @@ export const USDC_BASE_SEPOLIA = new Token(
'USDC Token'
);

export const USDC_UNICHAIN = new Token(
ChainId.UNICHAIN,
// TODO: validate USDC address is final / validated
'0x078D782b760474a361dDA0AF3839290b0EF57AD6',
6,
'USDC',
'USD Token'
);

export const DAI_UNICHAIN = new Token(
ChainId.UNICHAIN,
'0x20CAb320A855b39F724131C69424240519573f81',
18,
'DAI',
'Dai Stablecoin'
);

export class TokenProvider implements ITokenProvider {
constructor(
private chainId: ChainId,
Expand Down Expand Up @@ -994,6 +1011,8 @@ export const DAI_ON = (chainId: ChainId): Token => {
return DAI_AVAX;
case ChainId.ZKSYNC:
return DAI_ZKSYNC;
case ChainId.UNICHAIN:
return DAI_UNICHAIN;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down Expand Up @@ -1068,6 +1087,8 @@ export const USDC_ON = (chainId: ChainId): Token => {
return USDC_UNICHAIN_SEPOLIA;
case ChainId.BASE_SEPOLIA:
return USDC_BASE_SEPOLIA;
case ChainId.UNICHAIN:
return USDC_UNICHAIN;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down
8 changes: 7 additions & 1 deletion src/providers/v2/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
DAI_MAINNET,
DAI_MOONBEAM,
DAI_OPTIMISM,
DAI_UNICHAIN,
ETH_BNB,
OP_OPTIMISM,
USDB_BLAST,
Expand All @@ -32,6 +33,7 @@ import {
USDC_NATIVE_ARBITRUM,
USDC_OPTIMISM,
USDC_POLYGON,
USDC_UNICHAIN,
USDC_UNICHAIN_SEPOLIA,
USDC_WORLDCHAIN,
USDC_ZKSYNC,
Expand Down Expand Up @@ -136,7 +138,11 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN_SEPOLIA]!,
USDC_UNICHAIN_SEPOLIA,
],
[ChainId.UNICHAIN]: [],
[ChainId.UNICHAIN]: [
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN]!,
DAI_UNICHAIN,
USDC_UNICHAIN,
],
[ChainId.MONAD_TESTNET]: [
WRAPPED_NATIVE_CURRENCY[ChainId.MONAD_TESTNET]!,
USDT_MONAD_TESTNET,
Expand Down
8 changes: 7 additions & 1 deletion src/providers/v3/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DAI_OPTIMISM,
DAI_OPTIMISM_GOERLI,
DAI_POLYGON_MUMBAI,
DAI_UNICHAIN,
ETH_BNB,
OP_OPTIMISM,
USDB_BLAST,
Expand All @@ -47,6 +48,7 @@ import {
USDC_OPTIMISM_GOERLI,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_UNICHAIN,
USDC_UNICHAIN_SEPOLIA,
USDC_WORLDCHAIN,
USDC_ZKSYNC,
Expand Down Expand Up @@ -191,7 +193,11 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN_SEPOLIA]!,
USDC_UNICHAIN_SEPOLIA,
],
[ChainId.UNICHAIN]: [],
[ChainId.UNICHAIN]: [
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN]!,
DAI_UNICHAIN,
USDC_UNICHAIN,
],
[ChainId.MONAD_TESTNET]: [
WRAPPED_NATIVE_CURRENCY[ChainId.MONAD_TESTNET]!,
USDT_MONAD_TESTNET,
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 @@ -667,6 +667,7 @@ export class AlphaRouter
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.BASE_SEPOLIA:
case ChainId.UNICHAIN:
case ChainId.BASE_GOERLI:
this.onChainQuoteProvider = new OnChainQuoteProvider(
chainId,
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 @@ -17,6 +17,7 @@ export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (
case ChainId.WORLDCHAIN:
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.UNICHAIN:
return {
v2PoolSelection: {
topN: 3,
Expand Down
7 changes: 7 additions & 0 deletions src/routers/alpha-router/functions/get-candidate-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
DAI_OPTIMISM_GOERLI,
DAI_POLYGON_MUMBAI,
DAI_SEPOLIA,
DAI_UNICHAIN,
FEI_MAINNET,
ITokenProvider,
USDB_BLAST,
Expand All @@ -50,6 +51,7 @@ import {
USDC_OPTIMISM_GOERLI,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_UNICHAIN,
USDT_ARBITRUM,
USDT_BNB,
USDT_MAINNET,
Expand Down Expand Up @@ -249,6 +251,11 @@ const baseTokensByChain: { [chainId in ChainId]?: Token[] } = {
WRAPPED_NATIVE_CURRENCY[ChainId.BASE_SEPOLIA]!,
USDC_BASE_SEPOLIA,
],
[ChainId.UNICHAIN]: [
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN]!,
DAI_UNICHAIN,
USDC_UNICHAIN,
],
};

class SubcategorySelectionPools<SubgraphPool> {
Expand Down
3 changes: 3 additions & 0 deletions src/routers/alpha-router/gas-models/gas-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DAI_OPTIMISM_SEPOLIA,
DAI_POLYGON_MUMBAI,
DAI_SEPOLIA,
DAI_UNICHAIN,
DAI_ZKSYNC,
USDB_BLAST,
USDCE_ZKSYNC,
Expand Down Expand Up @@ -48,6 +49,7 @@ import {
USDC_OPTIMISM_SEPOLIA,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_UNICHAIN,
USDC_UNICHAIN_SEPOLIA,
USDC_WORLDCHAIN,
USDC_WORMHOLE_CELO,
Expand Down Expand Up @@ -130,6 +132,7 @@ export const usdGasTokensByChain: { [chainId in ChainId]?: Token[] } = {
[ChainId.UNICHAIN_SEPOLIA]: [USDC_UNICHAIN_SEPOLIA],
[ChainId.MONAD_TESTNET]: [USDT_MONAD_TESTNET],
[ChainId.BASE_SEPOLIA]: [USDC_BASE_SEPOLIA],
[ChainId.UNICHAIN]: [DAI_UNICHAIN, USDC_UNICHAIN],
};

export type L1ToL2GasCosts = {
Expand Down
8 changes: 7 additions & 1 deletion src/routers/legacy-router/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DAI_AVAX,
DAI_BNB,
DAI_MAINNET,
DAI_UNICHAIN,
ITokenProvider,
USDB_BLAST,
USDCE_ZKSYNC,
Expand All @@ -15,6 +16,7 @@ import {
USDC_BASE_SEPOLIA,
USDC_BNB,
USDC_MAINNET,
USDC_UNICHAIN,
USDC_UNICHAIN_SEPOLIA,
USDC_WORLDCHAIN,
USDC_ZKSYNC,
Expand Down Expand Up @@ -100,7 +102,11 @@ export const BASES_TO_CHECK_TRADES_AGAINST = (
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN_SEPOLIA]!,
USDC_UNICHAIN_SEPOLIA,
],
[ChainId.UNICHAIN]: [],
[ChainId.UNICHAIN]: [
WRAPPED_NATIVE_CURRENCY[ChainId.UNICHAIN]!,
DAI_UNICHAIN,
USDC_UNICHAIN,
],
[ChainId.MONAD_TESTNET]: [
WRAPPED_NATIVE_CURRENCY[ChainId.MONAD_TESTNET]!,
USDT_MONAD_TESTNET,
Expand Down
14 changes: 12 additions & 2 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const V3_CORE_FACTORY_ADDRESSES: AddressMap = {
[ChainId.BASE_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_SEPOLIA].v3CoreFactoryAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
[ChainId.UNICHAIN]:
CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].v3CoreFactoryAddress,
};

export const QUOTER_V2_ADDRESSES: AddressMap = {
Expand Down Expand Up @@ -85,6 +87,7 @@ export const QUOTER_V2_ADDRESSES: AddressMap = {
[ChainId.BASE_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_SEPOLIA].quoterAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
[ChainId.UNICHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].quoterAddress,
};

export const NEW_QUOTER_V2_ADDRESSES: AddressMap = {
Expand All @@ -109,6 +112,7 @@ export const NEW_QUOTER_V2_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.MONAD_TESTNET].quoterAddress, // TODO: deploy view-only-quoter to monad testnet
[ChainId.BASE_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_SEPOLIA].quoterAddress,
[ChainId.UNICHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].quoterAddress, // TODO: deploy view-only-quoter to unichain
};

export const PROTOCOL_V4_QUOTER_ADDRESSES: AddressMap = {
Expand Down Expand Up @@ -167,6 +171,7 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
[ChainId.BASE_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_SEPOLIA].multicallAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
[ChainId.UNICHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].multicallAddress,
};

export const SWAP_ROUTER_02_ADDRESSES = (chainId: number): string => {
Expand Down Expand Up @@ -229,8 +234,6 @@ export const WETH9: {
| ChainId.MONAD_TESTNET
// TODO: remove ROOTSTOCK once we support both at the routing level
| ChainId.ROOTSTOCK
// TODO: remove UNICHAIN once we support both at the routing level
| ChainId.UNICHAIN
>]: Token;
} = {
[ChainId.MAINNET]: new Token(
Expand Down Expand Up @@ -359,6 +362,13 @@ export const WETH9: {
'WETH',
'Wrapped Ether'
),
[ChainId.UNICHAIN]: new Token(
ChainId.UNICHAIN,
'0x4200000000000000000000000000000000000006',
18,
'WETH',
'Wrapped Ether'
),
};

export const BEACON_CHAIN_DEPOSIT_ADDRESS =
Expand Down
Loading
Loading