From cd1075ed0f25c697f8617f74fe68ab3a27753c21 Mon Sep 17 00:00:00 2001 From: chefjackson <116779127+chefjackson@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:11:42 +0800 Subject: [PATCH] chore: update api subgraph endpoints --- apis/farms/src/bindings.d.ts | 1 + apis/farms/src/v3.ts | 6 +- apis/farms/wrangler.toml | 1 + apis/routing/src/bindings.d.ts | 1 + apis/routing/src/provider.ts | 6 +- apis/routing/wrangler.toml | 1 + packages/chains/src/index.test.ts | 3 + packages/chains/src/subgraphs.ts | 105 ++++++++++++++++++------------ 8 files changed, 79 insertions(+), 45 deletions(-) diff --git a/apis/farms/src/bindings.d.ts b/apis/farms/src/bindings.d.ts index 67ecaaf631841..66be099f734b9 100644 --- a/apis/farms/src/bindings.d.ts +++ b/apis/farms/src/bindings.d.ts @@ -15,4 +15,5 @@ declare global { const BASE_NODE: string const OPBNB_NODE: string const OPBNB_TESTNET_NODE: string + const NODE_REAL_SUBGRAPH_API_KEY: string } diff --git a/apis/farms/src/v3.ts b/apis/farms/src/v3.ts index a0341676f5482..0d88bdb3efe05 100644 --- a/apis/farms/src/v3.ts +++ b/apis/farms/src/v3.ts @@ -1,5 +1,5 @@ /* eslint-disable no-param-reassign, no-await-in-loop */ -import { ChainId, V3_SUBGRAPHS } from '@pancakeswap/chains' +import { ChainId, getV3Subgraphs } from '@pancakeswap/chains' import { FarmV3SupportedChainId, masterChefV3Addresses } from '@pancakeswap/farms' import { ERC20Token } from '@pancakeswap/sdk' import { CurrencyAmount } from '@pancakeswap/swap-sdk-core' @@ -29,6 +29,10 @@ export const V3_SUBGRAPH_CLIENTS_CHAIN_IDS = [ type SupportChainId = (typeof V3_SUBGRAPH_CLIENTS_CHAIN_IDS)[number] +const V3_SUBGRAPHS = getV3Subgraphs({ + noderealApiKey: NODE_REAL_SUBGRAPH_API_KEY, +}) + export const V3_SUBGRAPH_CLIENTS = V3_SUBGRAPH_CLIENTS_CHAIN_IDS.reduce((acc, chainId) => { acc[chainId] = new GraphQLClient(V3_SUBGRAPHS[chainId], { fetch }) return acc diff --git a/apis/farms/wrangler.toml b/apis/farms/wrangler.toml index c59f307816605..6cb164c8df4bb 100644 --- a/apis/farms/wrangler.toml +++ b/apis/farms/wrangler.toml @@ -32,4 +32,5 @@ crons = ["0 0 * * *", "*/1 * * * *"] # - ARBITRUM_ONE_NODE # - LINEA_NODE # - BASE_NODE +# - NODE_REAL_SUBGRAPH_API_KEY # Run `echo | wrangler secret put ` for each of these diff --git a/apis/routing/src/bindings.d.ts b/apis/routing/src/bindings.d.ts index 7e97a17275af0..f4f669e1cca8e 100644 --- a/apis/routing/src/bindings.d.ts +++ b/apis/routing/src/bindings.d.ts @@ -6,6 +6,7 @@ declare global { const GOERLI_NODE: string const BSC_NODE: string const BSC_TESTNET_NODE: string + const NODE_REAL_SUBGRAPH_API_KEY: string const SUBGRAPH_POOLS: R2Bucket } diff --git a/apis/routing/src/provider.ts b/apis/routing/src/provider.ts index 4680786419917..e270f41d1748e 100644 --- a/apis/routing/src/provider.ts +++ b/apis/routing/src/provider.ts @@ -1,4 +1,4 @@ -import { ChainId, V3_SUBGRAPHS } from '@pancakeswap/chains' +import { ChainId, getV3Subgraphs } from '@pancakeswap/chains' import { OnChainProvider, SubgraphProvider } from '@pancakeswap/smart-router/evm' import { createPublicClient, http } from 'viem' import { bsc, bscTestnet, goerli, mainnet } from 'viem/chains' @@ -6,6 +6,10 @@ import { GraphQLClient } from 'graphql-request' import { SupportedChainId } from './constants' +const V3_SUBGRAPHS = getV3Subgraphs({ + noderealApiKey: NODE_REAL_SUBGRAPH_API_KEY, +}) + const requireCheck = [ETH_NODE, GOERLI_NODE, BSC_NODE, BSC_TESTNET_NODE] requireCheck.forEach((node) => { if (!node) { diff --git a/apis/routing/wrangler.toml b/apis/routing/wrangler.toml index b3d1b7fcdbf36..d53726a9e1cc1 100644 --- a/apis/routing/wrangler.toml +++ b/apis/routing/wrangler.toml @@ -27,4 +27,5 @@ crons = ["*/30 * * * *"] # - GOERLI_NODE # - BSC_NODE # - BSC_TESTNET_NODE +# - NODE_REAL_SUBGRAPH_API_KEY # Run `echo | wrangler secret put ` for each of these diff --git a/packages/chains/src/index.test.ts b/packages/chains/src/index.test.ts index ded531ed968c5..1b8d6b2234197 100644 --- a/packages/chains/src/index.test.ts +++ b/packages/chains/src/index.test.ts @@ -16,6 +16,9 @@ test('exports', () => { "V3_SUBGRAPHS", "V2_SUBGRAPHS", "BLOCKS_SUBGRAPHS", + "getV3Subgraphs", + "getV2Subgraphs", + "getBlocksSubgraphs", ] `) }) diff --git a/packages/chains/src/subgraphs.ts b/packages/chains/src/subgraphs.ts index 368324871e23d..38cdb3e6c2f87 100644 --- a/packages/chains/src/subgraphs.ts +++ b/packages/chains/src/subgraphs.ts @@ -1,48 +1,67 @@ import { ChainId } from './chainId' -export const V3_SUBGRAPHS = { - [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-eth', - [ChainId.GOERLI]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-goerli', - [ChainId.BSC]: `https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc`, - [ChainId.BSC_TESTNET]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-chapel', - [ChainId.ARBITRUM_ONE]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-arb', - [ChainId.ARBITRUM_GOERLI]: 'https://api.thegraph.com/subgraphs/name/chef-jojo/exhange-v3-arb-goerli', - [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-polygon-zkevm/version/latest', - [ChainId.POLYGON_ZKEVM_TESTNET]: null, - [ChainId.ZKSYNC]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-zksync/version/latest', - [ChainId.ZKSYNC_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-zksync-testnet/version/latest', - [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/pancakeswap/exchange-v3-linea', - [ChainId.LINEA_TESTNET]: - 'https://thegraph.goerli.zkevm.consensys.net/subgraphs/name/pancakeswap/exchange-v3-linea-goerli', - [ChainId.BASE]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-base/version/latest', - [ChainId.BASE_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-base-testnet/version/latest', - [ChainId.OPBNB]: - 'https://open-platform-ap.nodereal.io/19bd2b3f75c24e23bb8a0e9d4f55b271/opbnb-mainnet-graph-query/subgraphs/name/pancakeswap/exchange-v3', - [ChainId.OPBNB_TESTNET]: null, - [ChainId.SCROLL_SEPOLIA]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-scroll-sepolia/version/latest', -} satisfies Record - -export const V2_SUBGRAPHS = { - [ChainId.BSC]: 'https://proxy-worker-api.pancakeswap.com/bsc-exchange', - [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exhange-eth', - [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-polygon-zkevm/version/latest', - [ChainId.ZKSYNC_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-zksync-testnet/version/latest', - [ChainId.ZKSYNC]: ' https://api.studio.thegraph.com/query/45376/exchange-v2-zksync/version/latest', - [ChainId.LINEA_TESTNET]: 'https://thegraph.goerli.zkevm.consensys.net/subgraphs/name/pancakeswap/exhange-eth/', - [ChainId.ARBITRUM_ONE]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-arbitrum/version/latest', - [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/pancakeswap/exhange-v2', - [ChainId.BASE]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-base/version/latest', - [ChainId.OPBNB]: 'https://opbnb-mainnet-graph.nodereal.io/subgraphs/name/pancakeswap/exchange-v2', +type SubgraphParams = { + noderealApiKey?: string } -export const BLOCKS_SUBGRAPHS = { - [ChainId.BSC]: - 'https://open-platform-ap.nodereal.io/19bd2b3f75c24e23bb8a0e9d4f55b271/opbnb-mainnet-graph-query/subgraphs/name/pancakeswap/blocks', - [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks', - [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/polygon-zkevm-block/version/latest', - [ChainId.ZKSYNC]: 'https://api.studio.thegraph.com/query/45376/blocks-zksync/version/latest', - [ChainId.ARBITRUM_ONE]: 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-one-blocks', - [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks', - [ChainId.BASE]: 'https://api.studio.thegraph.com/query/48211/base-blocks/version/latest', - [ChainId.OPBNB]: 'https://opbnb-mainnet-graph.nodereal.io/subgraphs/name/pancakeswap/blocks', +const publicSubgraphParams = { + // Public key for nodereal subgraph endpoint + noderealApiKey: '19bd2b3f75c24e23bb8a0e9d4f55b271', +} + +export const V3_SUBGRAPHS = getV3Subgraphs(publicSubgraphParams) + +export const V2_SUBGRAPHS = getV2Subgraphs(publicSubgraphParams) + +export const BLOCKS_SUBGRAPHS = getBlocksSubgraphs(publicSubgraphParams) + +export function getV3Subgraphs({ noderealApiKey }: SubgraphParams) { + return { + [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-eth', + [ChainId.GOERLI]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-goerli', + [ChainId.BSC]: `https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc`, + [ChainId.BSC_TESTNET]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-chapel', + [ChainId.ARBITRUM_ONE]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-arb', + [ChainId.ARBITRUM_GOERLI]: 'https://api.thegraph.com/subgraphs/name/chef-jojo/exhange-v3-arb-goerli', + [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-polygon-zkevm/version/latest', + [ChainId.POLYGON_ZKEVM_TESTNET]: null, + [ChainId.ZKSYNC]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-zksync/version/latest', + [ChainId.ZKSYNC_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-zksync-testnet/version/latest', + [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/pancakeswap/exchange-v3-linea', + [ChainId.LINEA_TESTNET]: + 'https://thegraph.goerli.zkevm.consensys.net/subgraphs/name/pancakeswap/exchange-v3-linea-goerli', + [ChainId.BASE]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-base/version/latest', + [ChainId.BASE_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-base-testnet/version/latest', + [ChainId.OPBNB]: `https://open-platform-ap.nodereal.io/${noderealApiKey}/opbnb-mainnet-graph-query/subgraphs/name/pancakeswap/exchange-v3`, + [ChainId.OPBNB_TESTNET]: null, + [ChainId.SCROLL_SEPOLIA]: 'https://api.studio.thegraph.com/query/45376/exchange-v3-scroll-sepolia/version/latest', + } satisfies Record +} + +export function getV2Subgraphs({ noderealApiKey }: SubgraphParams) { + return { + [ChainId.BSC]: 'https://proxy-worker-api.pancakeswap.com/bsc-exchange', + [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exhange-eth', + [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-polygon-zkevm/version/latest', + [ChainId.ZKSYNC_TESTNET]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-zksync-testnet/version/latest', + [ChainId.ZKSYNC]: ' https://api.studio.thegraph.com/query/45376/exchange-v2-zksync/version/latest', + [ChainId.LINEA_TESTNET]: 'https://thegraph.goerli.zkevm.consensys.net/subgraphs/name/pancakeswap/exhange-eth/', + [ChainId.ARBITRUM_ONE]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-arbitrum/version/latest', + [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/pancakeswap/exhange-v2', + [ChainId.BASE]: 'https://api.studio.thegraph.com/query/45376/exchange-v2-base/version/latest', + [ChainId.OPBNB]: `https://open-platform-ap.nodereal.io/${noderealApiKey}/opbnb-mainnet-graph-query/subgraphs/name/pancakeswap/exchange-v2`, + } +} + +export function getBlocksSubgraphs({ noderealApiKey }: SubgraphParams) { + return { + [ChainId.BSC]: 'https://api.thegraph.com/subgraphs/name/pancakeswap/blocks', + [ChainId.ETHEREUM]: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks', + [ChainId.POLYGON_ZKEVM]: 'https://api.studio.thegraph.com/query/45376/polygon-zkevm-block/version/latest', + [ChainId.ZKSYNC]: 'https://api.studio.thegraph.com/query/45376/blocks-zksync/version/latest', + [ChainId.ARBITRUM_ONE]: 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-one-blocks', + [ChainId.LINEA]: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks', + [ChainId.BASE]: 'https://api.studio.thegraph.com/query/48211/base-blocks/version/latest', + [ChainId.OPBNB]: `https://open-platform-ap.nodereal.io/${noderealApiKey}/opbnb-mainnet-graph-query/subgraphs/name/pancakeswap/blocks`, + } }