Skip to content

Commit

Permalink
feat: support routing on Zksync (Uniswap#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 authored Jun 10, 2024
1 parent d5cb825 commit 74c0396
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 48 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,39 @@ jobs:
TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}

integration-tests-quote-for-other-networks-zksync:
name: Integration Tests - Quote For Other Networks ZkSync
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 * zksync'
env:
JSON_RPC_PROVIDER_BLAST: ${{ secrets.JSON_RPC_PROVIDER_ZKSYNC }}
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-remaining-networks:
name: Integration Tests - Quote For Other Networks Remaining Networks
runs-on: ubuntu-latest
Expand Down Expand Up @@ -718,7 +751,7 @@ jobs:

# This is to capture any new networks added into the integ-test suite
- name: Run Integration tests
run: npm run integ-test -- -t 'quote for other networks * (?!(mainnet|optimism|arbitrum|polygon|sepolia|celo|bnb|avalanche|base|blast|zora))'
run: npm run integ-test -- -t 'quote for other networks * (?!(mainnet|optimism|arbitrum|polygon|sepolia|celo|bnb|avalanche|base|blast|zora|zksync))'
env:
# We don't know which new networks will be added, so we have no way to provider RPC URL ahead of time
# This will make remaining networks integ-test suite to fail, and dev is expected to manually add RPC URL for the new network
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ Total ticks crossed: 7
./bin/cli quote --tokenIn 0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA --tokenOut 0x4200000000000000000000000000000000000006 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 8453
```

## ZKSYNC Mainnet

```
./bin/cli quote --tokenIn 0x5aea5775959fbc2557cc8789bc1bf90a239d9a91 --tokenOut 0x1d17cbcf0d6d143135ae902365d2e5e2a16538d4 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 324
```


## Adding a new Chain

Expand Down
78 changes: 42 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
"@eth-optimism/sdk": "^3.2.2",
"@types/brotli": "^1.3.4",
"@uniswap/default-token-list": "^11.13.0",
"@uniswap/permit2-sdk": "^1.2.0",
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.9.2",
"@uniswap/sdk-core": "^5.0.0",
"@uniswap/sdk-core": "^5.3.0",
"@uniswap/swap-router-contracts": "^1.3.1",
"@uniswap/token-lists": "^1.0.0-beta.31",
"@uniswap/universal-router": "^1.6.0",
"@uniswap/universal-router-sdk": "^2.1.0",
"@uniswap/universal-router-sdk": "^2.2.0",
"@uniswap/v2-sdk": "^4.3.2",
"@uniswap/v3-sdk": "^3.11.2",
"@uniswap/v3-sdk": "^3.13.0",
"async-retry": "^1.3.1",
"await-timeout": "^1.1.1",
"axios": "^0.21.1",
Expand Down
3 changes: 3 additions & 0 deletions src/providers/caching-token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export const CACHE_SEED_TOKENS: {
[ChainId.ZORA]: {
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.ZORA],
},
[ChainId.ZKSYNC]: {
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.ZKSYNC],
},
// Currently we do not have providers for Moonbeam mainnet or Gnosis testnet
};

Expand Down
28 changes: 28 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,30 @@ export const USDC_ZORA = new Token(
'USD Coin (Bridged from Ethereum)'
);

export const USDC_ZKSYNC = new Token(
ChainId.ZKSYNC,
'0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4',
6,
'USDC',
'USDC'
);

export const USDCE_ZKSYNC = new Token(
ChainId.ZKSYNC,
'0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4',
6,
'USDC.e',
'Bridged USDC (zkSync)'
);

export const DAI_ZKSYNC = new Token(
ChainId.ZKSYNC,
'0x4B9eb6c0b6ea15176BBF62841C6B2A8a398cb656',
18,
'DAI',
'Dai Stablecoin'
);

export class TokenProvider implements ITokenProvider {
constructor(
private chainId: ChainId,
Expand Down Expand Up @@ -869,6 +893,8 @@ export const DAI_ON = (chainId: ChainId): Token => {
return DAI_BNB;
case ChainId.AVALANCHE:
return DAI_AVAX;
case ChainId.ZKSYNC:
return DAI_ZKSYNC;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down Expand Up @@ -933,6 +959,8 @@ export const USDC_ON = (chainId: ChainId): Token => {
return USDC_BASE_GOERLI;
case ChainId.ZORA:
return USDC_ZORA;
case ChainId.ZKSYNC:
return USDCE_ZKSYNC;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/v2/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
USDC_NATIVE_ARBITRUM,
USDC_OPTIMISM,
USDC_POLYGON,
USDC_ZKSYNC, USDCE_ZKSYNC,
USDT_ARBITRUM,
USDT_BNB,
USDT_MAINNET,
Expand All @@ -39,7 +40,7 @@ import {
WBTC_MOONBEAM,
WBTC_OPTIMISM,
WETH_POLYGON,
WMATIC_POLYGON,
WMATIC_POLYGON
} from '../token-provider';

import { IV2SubgraphProvider, V2SubgraphPool } from './subgraph-provider';
Expand Down Expand Up @@ -111,6 +112,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
[ChainId.ZORA_SEPOLIA]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZORA_SEPOLIA]!],
[ChainId.ROOTSTOCK]: [WRAPPED_NATIVE_CURRENCY[ChainId.ROOTSTOCK]!],
[ChainId.BLAST]: [WRAPPED_NATIVE_CURRENCY[ChainId.BLAST]!, USDB_BLAST],
[ChainId.ZKSYNC]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZKSYNC]!, USDCE_ZKSYNC, USDC_ZKSYNC],
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/providers/v3/pool-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export class V3PoolProvider implements IV3PoolProvider {
tokenA: token0,
tokenB: token1,
fee: feeAmount,
initCodeHashManualOverride: undefined,
chainId: this.chainId,
});

this.POOL_ADDRESS_CACHE[cacheKey] = poolAddress;
Expand Down
5 changes: 3 additions & 2 deletions src/providers/v3/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
USDC_OPTIMISM,
USDC_OPTIMISM_GOERLI,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_SEPOLIA, USDC_ZKSYNC, USDCE_ZKSYNC,
USDT_ARBITRUM,
USDT_BNB,
USDT_GOERLI,
Expand All @@ -61,7 +61,7 @@ import {
WETH_POLYGON,
WMATIC_POLYGON,
WMATIC_POLYGON_MUMBAI,
WXDAI_GNOSIS,
WXDAI_GNOSIS
} from '../token-provider';

import { IV3PoolProvider } from './pool-provider';
Expand Down Expand Up @@ -166,6 +166,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
[ChainId.ZORA_SEPOLIA]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZORA_SEPOLIA]!],
[ChainId.ROOTSTOCK]: [WRAPPED_NATIVE_CURRENCY[ChainId.ROOTSTOCK]!],
[ChainId.BLAST]: [WRAPPED_NATIVE_CURRENCY[ChainId.BLAST]!, USDB_BLAST],
[ChainId.ZKSYNC]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZKSYNC]!, USDCE_ZKSYNC, USDC_ZKSYNC],
};

/**
Expand Down
Loading

0 comments on commit 74c0396

Please sign in to comment.