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 5 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
4 changes: 4 additions & 0 deletions bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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 @@ -410,6 +412,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
4 changes: 2 additions & 2 deletions bin/stacks/routing-lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class RoutingLambdaStack extends cdk.NestedStack {

description: 'Caching Routing Lambda',
environment: {
VERSION: '1',
VERSION: '2',
NODE_OPTIONS: '--enable-source-maps',
POOL_CACHE_BUCKET: poolCacheBucket.bucketName,
POOL_CACHE_BUCKET_3: poolCacheBucket3.bucketName,
Expand Down Expand Up @@ -186,7 +186,7 @@ export class RoutingLambdaStack extends cdk.NestedStack {

description: 'Routing Lambda',
environment: {
VERSION: '28',
VERSION: '29',
NODE_OPTIONS: '--enable-source-maps',
POOL_CACHE_BUCKET: poolCacheBucket.bucketName,
POOL_CACHE_BUCKET_3: poolCacheBucket3.bucketName,
Expand Down
15 changes: 12 additions & 3 deletions lib/config/rpcProviderProdConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,17 @@
"useMultiProviderProb": 1,
"latencyEvaluationSampleProb": 0,
"healthCheckSampleProb": 0,
"providerInitialWeights": [1],
"providerUrls": ["QUICKNODE_1301"],
"providerNames": ["QUICKNODE"]
"providerInitialWeights": [0, 1],
"providerUrls": ["QUICKNODE_1301", "UNIRPC_0"],
"providerNames": ["QUICKNODE", "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 @@ -66,6 +68,8 @@ export const v2SubgraphUrlOverride = (chainId: ChainId) => {
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v2-worldchain/api`
case ChainId.UNICHAIN_SEPOLIA:
return `https://subgraph.satsuma-prod.com/${process.env.ALCHEMY_QUERY_KEY}/uniswap/uniswap-v2-astrochain-sepolia/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 @@ -21,6 +21,7 @@ const ID_TO_PROVIDER = (id: ChainId): string => {
case ChainId.BNB:
case ChainId.BASE:
case ChainId.UNICHAIN_SEPOLIA:
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 @@ -61,6 +61,8 @@ export class UniGraphQLProvider implements IUniGraphQLProvider {
return 'WORLDCHAIN'
case ChainId.UNICHAIN_SEPOLIA:
return 'UNICHAIN_SEPOLIA'
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 @@ -109,6 +109,7 @@ export const SUPPORTED_CHAINS: ChainId[] = [
ChainId.ZKSYNC,
ChainId.WORLDCHAIN,
ChainId.UNICHAIN_SEPOLIA,
ChainId.UNICHAIN,
]
const DEFAULT_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'

Expand Down Expand Up @@ -367,6 +368,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
case ChainId.ZKSYNC:
case ChainId.WORLDCHAIN:
case ChainId.UNICHAIN_SEPOLIA:
case ChainId.UNICHAIN:
const currentQuoteProvider = new OnChainQuoteProvider(
chainId,
provider,
Expand Down Expand Up @@ -507,6 +509,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
ChainId.AVALANCHE,
ChainId.BLAST,
ChainId.WORLDCHAIN,
//ChainId.UNICHAIN, // Supported?
]

const v4Supported = [ChainId.SEPOLIA]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const QUOTE_PROVIDER_TRAFFIC_SWITCH_CONFIGURATION = (
// worldchain and unichain sepolia don't have the view-only quoter yet, so we can shadow sample 0.1% of traffic
case ChainId.WORLDCHAIN:
case ChainId.UNICHAIN_SEPOLIA:
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 @@ -83,6 +83,7 @@ export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (chainId: ChainId): AlphaRouterCo
case ChainId.OPTIMISM:
case ChainId.WORLDCHAIN:
case ChainId.UNICHAIN_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 @@ -22,6 +22,8 @@ export function chainIdToNetworkName(networkId: ChainId): string {
return 'worldchain'
case ChainId.UNICHAIN_SEPOLIA:
return 'unichain-sepolia'
case ChainId.UNICHAIN:
return 'unichain'
default:
return 'ethereum'
}
Expand Down Expand Up @@ -102,6 +104,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 @@ -52,6 +52,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 @@ -115,12 +120,18 @@ 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,
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 @@ -180,12 +191,18 @@ 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,
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 @@ -246,12 +263,18 @@ 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,
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 @@ -312,6 +335,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 @@ -383,6 +412,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 @@ -448,6 +483,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 @@ -514,6 +555,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 @@ -574,6 +621,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,
},
},
}

Expand Down Expand Up @@ -611,6 +664,10 @@ export const GAS_ERROR_FAILURE_OVERRIDES: { [chainId: number]: FailureOverrides
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
[ChainId.UNICHAIN]: {
gasLimitOverride: 3_000_000,
multicallChunk: 45,
},
}

export const SUCCESS_RATE_FAILURE_OVERRIDES: { [chainId: number]: FailureOverrides } = {
Expand Down Expand Up @@ -647,6 +704,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 @@ -699,6 +760,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
Loading
Loading