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: support zora #584

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 35 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,40 @@ jobs:
TENDERLY_PROJECT: ${{ secrets.TENDERLY_PROJECT }}
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}

integration-tests-quote-for-other-networks-zora:
name: Integration Tests - Quote For Other Networks Zora
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 * zora'
env:
JSON_RPC_PROVIDER_BLAST: ${{ secrets.JSON_RPC_PROVIDER_BLAST }}
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 @@ -684,7 +718,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))'
run: npm run integ-test -- -t 'quote for other networks * (?!(mainnet|optimism|arbitrum|polygon|sepolia|celo|bnb|avalanche|base|blast|zora))'
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
3 changes: 3 additions & 0 deletions src/providers/caching-token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
[chainId in ChainId]?: { [symbol: string]: Token };
} = {
[ChainId.MAINNET]: {
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET]!,

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

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
USDC: USDC_MAINNET,
USDT: USDT_MAINNET,
WBTC: WBTC_MAINNET,
Expand Down Expand Up @@ -165,6 +165,9 @@
USDB: USDB_BLAST,
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.BLAST],
},
[ChainId.ZORA]: {
WETH: WRAPPED_NATIVE_CURRENCY[ChainId.ZORA],
},
// Currently we do not have providers for Moonbeam mainnet or Gnosis testnet
};

Expand Down Expand Up @@ -213,11 +216,11 @@

for (const address of addresses) {
if (await this.tokenCache.has(this.CACHE_KEY(this.chainId, address))) {
addressToToken[address.toLowerCase()] = (await this.tokenCache.get(

Check warning on line 219 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
this.CACHE_KEY(this.chainId, address)
))!;
symbolToToken[addressToToken[address]!.symbol!] =

Check warning on line 222 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion

Check warning on line 222 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
(await this.tokenCache.get(this.CACHE_KEY(this.chainId, address)))!;

Check warning on line 223 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
} else {
addressesToFindInPrimary.push(address);
}
Expand Down Expand Up @@ -245,10 +248,10 @@

if (token) {
addressToToken[address.toLowerCase()] = token;
symbolToToken[addressToToken[address]!.symbol!] = token;

Check warning on line 251 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion

Check warning on line 251 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
await this.tokenCache.set(
this.CACHE_KEY(this.chainId, address.toLowerCase()),
addressToToken[address]!

Check warning on line 254 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
);
} else {
addressesToFindInSecondary.push(address);
Expand Down Expand Up @@ -276,7 +279,7 @@
const token = secondaryTokenAccessor.getTokenByAddress(address);
if (token) {
addressToToken[address.toLowerCase()] = token;
symbolToToken[addressToToken[address]!.symbol!] = token;

Check warning on line 282 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion

Check warning on line 282 in src/providers/caching-token-provider.ts

View workflow job for this annotation

GitHub Actions / Run linters 2

Forbidden non-null assertion
await this.tokenCache.set(
this.CACHE_KEY(this.chainId, address.toLowerCase()),
addressToToken[address]!
Expand Down
10 changes: 10 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,14 @@ export const USDB_BLAST = new Token(
'USD Blast'
)

export const USDC_ZORA = new Token(
ChainId.ZORA,
'0xCccCCccc7021b32EBb4e8C08314bD62F7c653EC4',
6,
'USDzC',
'USD Coin (Bridged from Ethereum)'
);

export class TokenProvider implements ITokenProvider {
constructor(
private chainId: ChainId,
Expand Down Expand Up @@ -923,6 +931,8 @@ export const USDC_ON = (chainId: ChainId): Token => {
return USDC_BASE;
case ChainId.BASE_GOERLI:
return USDC_BASE_GOERLI;
case ChainId.ZORA:
return USDC_ZORA;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
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 @@ -553,6 +553,7 @@ export class AlphaRouter
break;
case ChainId.BASE:
case ChainId.BLAST:
case ChainId.ZORA:
case ChainId.BASE_GOERLI:
this.onChainQuoteProvider = new OnChainQuoteProvider(
chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const baseTokensByChain: { [chainId in ChainId]?: Token[] } = {
[ChainId.AVALANCHE]: [DAI_AVAX, USDC_AVAX],
[ChainId.BASE]: [USDC_BASE],
[ChainId.BLAST]: [WRAPPED_NATIVE_CURRENCY[ChainId.BLAST]!, USDB_BLAST],
[ChainId.ZORA]: [WRAPPED_NATIVE_CURRENCY[ChainId.ZORA]!],
};

class SubcategorySelectionPools<SubgraphPool> {
Expand Down
3 changes: 2 additions & 1 deletion src/routers/alpha-router/gas-models/gas-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
USDC_OPTIMISM_SEPOLIA,
USDC_POLYGON,
USDC_SEPOLIA,
USDC_WORMHOLE_CELO,
USDC_WORMHOLE_CELO, USDC_ZORA,
USDT_ARBITRUM,
USDT_BNB,
USDT_GOERLI,
Expand Down Expand Up @@ -114,6 +114,7 @@ export const usdGasTokensByChain: { [chainId in ChainId]?: Token[] } = {
],
[ChainId.BASE]: [USDC_BASE, USDC_NATIVE_BASE],
[ChainId.BLAST]: [USDB_BLAST],
[ChainId.ZORA]: [USDC_ZORA],
};

export type L1ToL2GasCosts = {
Expand Down
24 changes: 20 additions & 4 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const V3_CORE_FACTORY_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_GOERLI].v3CoreFactoryAddress,
[ChainId.BASE]: CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].v3CoreFactoryAddress,
[ChainId.BLAST]: CHAIN_TO_ADDRESSES_MAP[ChainId.BLAST].v3CoreFactoryAddress,
[ChainId.ZORA]: CHAIN_TO_ADDRESSES_MAP[ChainId.ZORA].v3CoreFactoryAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand All @@ -62,6 +63,7 @@ export const QUOTER_V2_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_GOERLI].quoterAddress,
[ChainId.BASE]: CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].quoterAddress,
[ChainId.BLAST]: CHAIN_TO_ADDRESSES_MAP[ChainId.BLAST].quoterAddress,
[ChainId.ZORA]: CHAIN_TO_ADDRESSES_MAP[ChainId.ZORA].quoterAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand All @@ -77,6 +79,7 @@ export const NEW_QUOTER_V2_ADDRESSES: AddressMap = {
[ChainId.POLYGON_MUMBAI]: '0x60e06b92bC94a665036C26feC5FF2A92E2d04c5f',
[ChainId.BASE]: '0x222cA98F00eD15B1faE10B61c277703a194cf5d2',
[ChainId.BLAST]: '0x9D0F15f2cf58655fDDcD1EE6129C547fDaeD01b1',
[ChainId.ZORA]: '0x9D0F15f2cf58655fDDcD1EE6129C547fDaeD01b1',
};

export const MIXED_ROUTE_QUOTER_V1_ADDRESSES: AddressMap = {
Expand Down Expand Up @@ -107,6 +110,7 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.BASE_GOERLI].multicallAddress,
[ChainId.BASE]: CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].multicallAddress,
[ChainId.BLAST]: CHAIN_TO_ADDRESSES_MAP[ChainId.BLAST].multicallAddress,
[ChainId.ZORA]: CHAIN_TO_ADDRESSES_MAP[ChainId.ZORA].multicallAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand Down Expand Up @@ -152,10 +156,8 @@ export const WETH9: {
| ChainId.MOONBEAM
| ChainId.BNB
| ChainId.AVALANCHE
// TODO: remove ROOTSTOCK, ZORA and ZORA_SEPOLIA once we support both at the routing level
// TODO: remove ROOTSTOCK once we support both at the routing level
| ChainId.ROOTSTOCK
| ChainId.ZORA
| ChainId.ZORA_SEPOLIA
>]: Token;
} = {
[ChainId.MAINNET]: new Token(
Expand Down Expand Up @@ -241,7 +243,21 @@ export const WETH9: {
18,
'WETH',
'Wrapped Ether'
)
),
[ChainId.ZORA]: new Token(
ChainId.ZORA,
'0x4200000000000000000000000000000000000006',
18,
'WETH',
'Wrapped Ether'
),
[ChainId.ZORA_SEPOLIA]: new Token(
ChainId.ZORA_SEPOLIA,
'0x4200000000000000000000000000000000000006',
18,
'WETH',
'Wrapped Ether'
),
};

export const BEACON_CHAIN_DEPOSIT_ADDRESS =
Expand Down
19 changes: 17 additions & 2 deletions src/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Currency,
Ether,
NativeCurrency,
Token,
Token
} from '@uniswap/sdk-core';

// WIP: Gnosis, Moonbeam
Expand All @@ -24,6 +24,7 @@ export const SUPPORTED_CHAINS: ChainId[] = [
ChainId.AVALANCHE,
ChainId.BASE,
ChainId.BLAST,
ChainId.ZORA,
// Gnosis and Moonbeam don't yet have contracts deployed yet
];

Expand All @@ -48,6 +49,7 @@ export const HAS_L1_FEE = [
ChainId.BASE,
ChainId.BASE_GOERLI,
ChainId.BLAST,
ChainId.ZORA,
];

export const NETWORKS_WITH_SAME_UNISWAP_ADDRESSES = [
Expand Down Expand Up @@ -101,6 +103,8 @@ export const ID_TO_CHAIN_ID = (id: number): ChainId => {
return ChainId.BASE_GOERLI;
case 81457:
return ChainId.BLAST;
case 7777777:
return ChainId.ZORA;
default:
throw new Error(`Unknown chain id: ${id}`);
}
Expand All @@ -127,6 +131,7 @@ export enum ChainName {
BASE = 'base-mainnet',
BASE_GOERLI = 'base-goerli',
BLAST = 'blast-mainnet',
ZORA = 'zora-mainnet',
}

export enum NativeCurrencyName {
Expand Down Expand Up @@ -211,6 +216,11 @@ export const NATIVE_NAMES_BY_ID: { [chainId: number]: string[] } = {
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.ZORA]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
};

export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = {
Expand All @@ -233,6 +243,7 @@ export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = {
[ChainId.AVALANCHE]: NativeCurrencyName.AVALANCHE,
[ChainId.BASE]: NativeCurrencyName.ETHER,
[ChainId.BLAST]: NativeCurrencyName.ETHER,
[ChainId.ZORA]: NativeCurrencyName.ETHER,
};

export const ID_TO_NETWORK_NAME = (id: number): ChainName => {
Expand Down Expand Up @@ -277,6 +288,8 @@ export const ID_TO_NETWORK_NAME = (id: number): ChainName => {
return ChainName.BASE_GOERLI;
case 81457:
return ChainName.BLAST;
case 7777777:
return ChainName.ZORA;
default:
throw new Error(`Unknown chain id: ${id}`);
}
Expand Down Expand Up @@ -322,6 +335,8 @@ export const ID_TO_PROVIDER = (id: ChainId): string => {
return process.env.JSON_RPC_PROVIDER_BASE!;
case ChainId.BLAST:
return process.env.JSON_RPC_PROVIDER_BLAST!;
case ChainId.ZORA:
return process.env.JSON_RPC_PROVIDER_ZORA!;
default:
throw new Error(`Chain id: ${id} not supported`);
}
Expand Down Expand Up @@ -486,7 +501,7 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId in ChainId]: Token } = {
),
[ChainId.BLAST]: new Token(
ChainId.BLAST,
'0x4300000000000000000000000000000000000004',
'0x4200000000000000000000000000000000000006',
18,
'WETH',
'Wrapped Ether'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,6 @@ describe('quote for other networks', () => {
c != ChainId.ARBITRUM_SEPOLIA &&
// Tests are failing https://github.com/Uniswap/smart-order-router/issues/104
c != ChainId.CELO_ALFAJORES &&
c != ChainId.ZORA &&
c != ChainId.ZORA_SEPOLIA &&
c != ChainId.ROOTSTOCK
)) {
Expand Down
Loading