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(routing-api): support routing on unichain mainnet #919

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export class RoutingAPIPipeline extends Stack {
chainId !== ChainId.WORLDCHAIN &&
chainId !== ChainId.UNICHAIN_SEPOLIA &&
chainId !== ChainId.MONAD_TESTNET &&
chainId !== ChainId.BASE_SEPOLIA
chainId !== ChainId.BASE_SEPOLIA &&
chainId !== ChainId.UNICHAIN
) {
const key = `WEB3_RPC_${chainId}`
jsonRpcProviders[key] = jsonRpcProvidersSecret.secretValueFromJson(key).toString()
Expand Down Expand Up @@ -240,6 +241,8 @@ export class RoutingAPIPipeline extends Stack {
'ALCHEMY_324',
// WorldChain,
'QUICKNODE_480',
// Unichain
'QUICKNODE_130',
// Unichain Sepolia,
'QUICKNODE_1301',
// unirpc - serves all chains
Expand Down Expand Up @@ -416,6 +419,8 @@ const jsonRpcProviders = {
ALCHEMY_324: process.env.ALCHEMY_324!,
// WorldChain,
QUICKNODE_480: process.env.QUICKNODE_480!,
// Unichain
QUICKNODE_130: process.env.QUICKNODE_130!,
// Unichain Sepolia,
QUICKNODE_1301: process.env.QUICKNODE_1301!,
// unirpc - serves all chains
Expand Down
9 changes: 9 additions & 0 deletions lib/config/rpcProviderProdConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,14 @@
"providerInitialWeights": [1],
"providerUrls": ["UNIRPC_0"],
"providerNames": ["UNIRPC"]
},
{
"chainId": 130,
"useMultiProviderProb": 1,
"latencyEvaluationSampleProb": 0,
"healthCheckSampleProb": 0,
"providerInitialWeights": [0, 1],
"providerUrls": ["QUICKNODE_130", "UNIRPC_0"],
"providerNames": ["QUICKNODE", "UNIRPC"]
}
]
4 changes: 4 additions & 0 deletions lib/cron/cache-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const v3SubgraphUrlOverride = (chainId: ChainId) => {
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v3-worldchain/api`
case ChainId.UNICHAIN_SEPOLIA:
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v3-astrochain-sepolia/api`
case ChainId.UNICHAIN:
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v3-unichain/api`
default:
return undefined
}
Expand Down Expand Up @@ -68,6 +70,8 @@ export const v2SubgraphUrlOverride = (chainId: ChainId) => {
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v2-astrochain-sepolia/api`
case ChainId.MONAD_TESTNET:
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v2-monad-testnet/api`
case ChainId.UNICHAIN:
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v2-unichain/api`
default:
return undefined
}
Expand Down
1 change: 1 addition & 0 deletions lib/dashboards/rpc-providers-widgets-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ID_TO_PROVIDER = (id: ChainId): string => {
case ChainId.BASE_SEPOLIA:
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.UNICHAIN:
return ProviderName.QUIKNODE
case ChainId.CELO_ALFAJORES:
return ProviderName.FORNO
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/graphql-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class UniGraphQLProvider implements IUniGraphQLProvider {
return 'UNICHAIN_SEPOLIA'
case ChainId.MONAD_TESTNET:
return 'MONAD_TESTNET'
case ChainId.UNICHAIN:
return 'UNICHAIN'
default:
throw new Error(`UniGraphQLProvider._chainIdToGraphQLChainName unsupported ChainId: ${chainId}`)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const SUPPORTED_CHAINS: ChainId[] = [
ChainId.UNICHAIN_SEPOLIA,
ChainId.MONAD_TESTNET,
ChainId.BASE_SEPOLIA,
ChainId.UNICHAIN,
]
const DEFAULT_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'

Expand Down Expand Up @@ -371,6 +372,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.BASE_SEPOLIA:
case ChainId.UNICHAIN:
const currentQuoteProvider = new OnChainQuoteProvider(
chainId,
provider,
Expand Down Expand Up @@ -512,6 +514,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
ChainId.BLAST,
ChainId.WORLDCHAIN,
ChainId.MONAD_TESTNET,
ChainId.UNICHAIN,
]

const v4Supported = [ChainId.SEPOLIA]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const QUOTE_PROVIDER_TRAFFIC_SWITCH_CONFIGURATION = (
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.BASE_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.UNICHAIN:
switch (protocol) {
case Protocol.MIXED:
case Protocol.V4:
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (chainId: ChainId): AlphaRouterCo
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.MONAD_TESTNET:
case ChainId.BASE_SEPOLIA:
case ChainId.UNICHAIN:
return {
v2PoolSelection: {
topN: 3,
Expand Down
5 changes: 5 additions & 0 deletions lib/rpc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function chainIdToNetworkName(networkId: ChainId): string {
return 'monad-testnet'
case ChainId.BASE_SEPOLIA:
return 'base-sepolia'
case ChainId.UNICHAIN:
return 'unichain'
default:
return 'ethereum'
}
Expand Down Expand Up @@ -109,6 +111,9 @@ export function generateProviderUrl(key: string, value: string, chainId: number)
// URL contains unichain-sepolia.quiknode.pro, we had to not disclose prior to the unichain annouce
return `${tokens[0]}`
}
case 'QUICKNODE_130': {
return `https://${tokens[0]}.unichain-mainnet.quiknode.pro/${tokens[1]}`
}
case 'QUICKNODE_480': {
return `https://${tokens[0]}.worldchain-mainnet.quiknode.pro/${tokens[1]}`
}
Expand Down
75 changes: 72 additions & 3 deletions lib/util/onChainQuoteProviderConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const RETRY_OPTIONS: { [chainId: number]: AsyncRetry.Options | undefined
minTimeout: 100,
maxTimeout: 1000,
},
[ChainId.UNICHAIN]: {
retries: 2,
minTimeout: 100,
maxTimeout: 1000,
},
}

export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: { [chainId: number]: BatchParams } } = {
Expand Down Expand Up @@ -125,7 +130,7 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once astrochain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
// TODO: once unichain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN_SEPOLIA]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
Expand All @@ -142,6 +147,12 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
[Protocol.V3]: {
...constructSameBatchParamsMap(DEFAULT_BATCH_PARAMS),
Expand Down Expand Up @@ -201,7 +212,7 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once astrochain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
// TODO: once unichain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN_SEPOLIA]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
Expand All @@ -218,6 +229,12 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
// V4 can be the same as V4 to begin. likely v4 is more gas efficient because of pool singleton for swaps by accounting mechanism
[Protocol.V4]: {
Expand Down Expand Up @@ -278,7 +295,7 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once astrochain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
// TODO: once unichain-sepolia has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN_SEPOLIA]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
Expand All @@ -295,6 +312,12 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
[Protocol.MIXED]: {
...constructSameBatchParamsMap(DEFAULT_BATCH_PARAMS),
Expand Down Expand Up @@ -366,6 +389,12 @@ export const OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]: {
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
}

Expand Down Expand Up @@ -448,6 +477,12 @@ export const NON_OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
[Protocol.V3]: {
...constructSameBatchParamsMap(DEFAULT_BATCH_PARAMS),
Expand Down Expand Up @@ -524,6 +559,12 @@ export const NON_OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
// V4 can be the same as V4 to begin. likely v4 is more gas efficient because of pool singleton for swaps by accounting mechanism
[Protocol.V4]: {
Expand Down Expand Up @@ -601,6 +642,12 @@ export const NON_OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
},
[Protocol.MIXED]: {
...constructSameBatchParamsMap(DEFAULT_BATCH_PARAMS),
Expand Down Expand Up @@ -661,6 +708,12 @@ export const NON_OPTIMISTIC_CACHED_ROUTES_BATCH_PARAMS: { [protocol in Protocol]
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once unichain has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.UNICHAIN]: {
multicallChunk: 80,
gasLimitPerCall: 1_200_000,
quoteMinSuccessRate: 0.1,
},
// TODO: once monad-testnet has view-quoter, optimize muilcallChunk and gasLimitPerCall
[ChainId.MONAD_TESTNET]: {
multicallChunk: 80,
Expand Down Expand Up @@ -709,6 +762,10 @@ export const GAS_ERROR_FAILURE_OVERRIDES: { [chainId: number]: FailureOverrides
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
[ChainId.UNICHAIN]: {
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
[ChainId.MONAD_TESTNET]: {
gasLimitOverride: 3_000_000,
multicallChunk: 45,
Expand Down Expand Up @@ -761,6 +818,10 @@ export const SUCCESS_RATE_FAILURE_OVERRIDES: { [chainId: number]: FailureOverrid
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
[ChainId.UNICHAIN]: {
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
}

export const BLOCK_NUMBER_CONFIGS: { [chainId: number]: BlockNumberConfig } = {
Expand Down Expand Up @@ -829,6 +890,14 @@ export const BLOCK_NUMBER_CONFIGS: { [chainId: number]: BlockNumberConfig } = {
rollbackBlockOffset: -20,
},
},
[ChainId.UNICHAIN]: {
baseBlockOffset: -25,
rollback: {
enabled: true,
attemptsBeforeRollback: 1,
rollbackBlockOffset: -20,
},
},
}

// block -1 means it's never deployed
Expand Down
12 changes: 6 additions & 6 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 @@ -88,7 +88,7 @@
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.18.0",
"@uniswap/sdk-core": "^7.1.0",
"@uniswap/smart-order-router": "4.14.0",
"@uniswap/smart-order-router": "file:/tmp/uniswap-smart-order-router-4.14.0.tgz",
"@uniswap/token-lists": "^1.0.0-beta.33",
"@uniswap/universal-router-sdk": "^4.10.0",
"@uniswap/v2-sdk": "^4.9.0",
Expand Down
3 changes: 3 additions & 0 deletions test/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
USDT_OPTIMISM,
WRAPPED_NATIVE_CURRENCY,
USDC_BASE_SEPOLIA,
USDC_UNICHAIN,
} from '@uniswap/smart-order-router'
import { ethers } from 'ethers'
import NodeCache from 'node-cache'
Expand Down Expand Up @@ -150,6 +151,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
Loading