Skip to content

Commit

Permalink
chore: update api subgraph endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chefjackson committed Jan 15, 2024
1 parent ed4dac2 commit cd1075e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 45 deletions.
1 change: 1 addition & 0 deletions apis/farms/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion apis/farms/src/v3.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apis/farms/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ crons = ["0 0 * * *", "*/1 * * * *"]
# - ARBITRUM_ONE_NODE
# - LINEA_NODE
# - BASE_NODE
# - NODE_REAL_SUBGRAPH_API_KEY
# Run `echo <VALUE> | wrangler secret put <NAME>` for each of these
1 change: 1 addition & 0 deletions apis/routing/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion apis/routing/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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'
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) {
Expand Down
1 change: 1 addition & 0 deletions apis/routing/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ crons = ["*/30 * * * *"]
# - GOERLI_NODE
# - BSC_NODE
# - BSC_TESTNET_NODE
# - NODE_REAL_SUBGRAPH_API_KEY
# Run `echo <VALUE> | wrangler secret put <NAME>` for each of these
3 changes: 3 additions & 0 deletions packages/chains/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ test('exports', () => {
"V3_SUBGRAPHS",
"V2_SUBGRAPHS",
"BLOCKS_SUBGRAPHS",
"getV3Subgraphs",
"getV2Subgraphs",
"getBlocksSubgraphs",
]
`)
})
105 changes: 62 additions & 43 deletions packages/chains/src/subgraphs.ts
Original file line number Diff line number Diff line change
@@ -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<ChainId, string | null>

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<ChainId, string | null>
}

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`,
}
}

0 comments on commit cd1075e

Please sign in to comment.