Skip to content

Commit

Permalink
chore: Update opbnb subgraph (#8821)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
### Focus of this PR:
This PR introduces a new environment variable
`NODE_REAL_SUBGRAPH_API_KEY` and updates multiple files to use it for
subgraph API endpoints.

### Detailed summary:
- Added `NODE_REAL_SUBGRAPH_API_KEY` environment variable
- Updated `apis/farms/src/provider.ts` to use
`NODE_REAL_SUBGRAPH_API_KEY` for subgraph API endpoint
- Updated `apis/farms/src/v3.ts` to use `NODE_REAL_SUBGRAPH_API_KEY` for
subgraph API endpoint
- Updated `apis/routing/src/provider.ts` to use
`NODE_REAL_SUBGRAPH_API_KEY` for subgraph API endpoint
- Updated `apis/routing/src/bindings.d.ts` to include
`NODE_REAL_SUBGRAPH_API_KEY` constant
- Updated `apis/farms/wrangler.toml` and `apis/routing/wrangler.toml` to
include `NODE_REAL_SUBGRAPH_API_KEY` in secret put command
- Updated `packages/chains/src/index.test.ts` to include
`BLOCKS_SUBGRAPHS` and related functions

> The following files were skipped due to too many changes:
`packages/chains/src/subgraphs.ts`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
chefjackson authored Jan 15, 2024
1 parent ef50410 commit 8fcd67c
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-teachers-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pancakeswap/chains': minor
---

Add getters for subgraph endpoints by chain
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
}
1 change: 1 addition & 0 deletions apis/farms/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const requireCheck = [
BASE_NODE,
OPBNB_NODE,
OPBNB_TESTNET_NODE,
NODE_REAL_SUBGRAPH_API_KEY,
]

const base = {
Expand Down
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
}
8 changes: 6 additions & 2 deletions apis/routing/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
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 requireCheck = [ETH_NODE, GOERLI_NODE, BSC_NODE, BSC_TESTNET_NODE]
const requireCheck = [ETH_NODE, GOERLI_NODE, BSC_NODE, BSC_TESTNET_NODE, NODE_REAL_SUBGRAPH_API_KEY]
requireCheck.forEach((node) => {
if (!node) {
throw new Error('Missing env var')
}
})

const V3_SUBGRAPHS = getV3Subgraphs({
noderealApiKey: NODE_REAL_SUBGRAPH_API_KEY,
})

const mainnetClient = createPublicClient({
chain: mainnet,
transport: http(ETH_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
28 changes: 9 additions & 19 deletions apps/web/src/config/constants/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId, V2_SUBGRAPHS, V3_SUBGRAPHS } from '@pancakeswap/chains'
import { ChainId, V2_SUBGRAPHS, V3_SUBGRAPHS, BLOCKS_SUBGRAPHS } from '@pancakeswap/chains'

export const GRAPH_API_PROFILE = 'https://api.thegraph.com/subgraphs/name/pancakeswap/profile'

Expand All @@ -24,14 +24,13 @@ export const V3_BSC_INFO_CLIENT = `https://open-platform.nodereal.io/${
}/pancakeswap-v3/graphql`

export const INFO_CLIENT_ETH = 'https://api.thegraph.com/subgraphs/name/pancakeswap/exhange-eth'
export const BLOCKS_CLIENT = 'https://api.thegraph.com/subgraphs/name/pancakeswap/blocks'
export const BLOCKS_CLIENT_ETH = 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks'
export const BLOCKS_CLIENT_POLYGON_ZKEVM =
'https://api.studio.thegraph.com/query/45376/polygon-zkevm-block/version/latest'
export const BLOCKS_CLIENT_ZKSYNC = 'https://api.studio.thegraph.com/query/45376/blocks-zksync/version/latest'
export const BLOCKS_CLIENT_LINEA = 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks'
export const BLOCKS_CLIENT_BASE = 'https://api.studio.thegraph.com/query/48211/base-blocks/version/latest'
export const BLOCKS_CLIENT_OPBNB = 'https://opbnb-mainnet-graph.nodereal.io/subgraphs/name/pancakeswap/blocks'
export const BLOCKS_CLIENT = BLOCKS_SUBGRAPHS[ChainId.BSC]
export const BLOCKS_CLIENT_ETH = BLOCKS_SUBGRAPHS[ChainId.ETHEREUM]
export const BLOCKS_CLIENT_POLYGON_ZKEVM = BLOCKS_SUBGRAPHS[ChainId.POLYGON_ZKEVM]
export const BLOCKS_CLIENT_ZKSYNC = BLOCKS_SUBGRAPHS[ChainId.ZKSYNC]
export const BLOCKS_CLIENT_LINEA = BLOCKS_SUBGRAPHS[ChainId.LINEA]
export const BLOCKS_CLIENT_BASE = BLOCKS_SUBGRAPHS[ChainId.BASE]
export const BLOCKS_CLIENT_OPBNB = BLOCKS_SUBGRAPHS[ChainId.OPBNB]
export const STABLESWAP_SUBGRAPH_CLIENT = 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-stableswap'
export const GRAPH_API_NFTMARKET = 'https://api.thegraph.com/subgraphs/name/pancakeswap/nft-market'
export const GRAPH_HEALTH = 'https://api.thegraph.com/index-node/graphql'
Expand All @@ -47,16 +46,7 @@ export const CELER_API = 'https://api.celerscan.com/scan'

export const INFO_CLIENT_WITH_CHAIN = V2_SUBGRAPHS

export const BLOCKS_CLIENT_WITH_CHAIN = {
[ChainId.BSC]: BLOCKS_CLIENT,
[ChainId.ETHEREUM]: BLOCKS_CLIENT_ETH,
[ChainId.POLYGON_ZKEVM]: BLOCKS_CLIENT_POLYGON_ZKEVM,
[ChainId.ZKSYNC]: BLOCKS_CLIENT_ZKSYNC,
[ChainId.ARBITRUM_ONE]: 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-one-blocks',
[ChainId.LINEA]: BLOCKS_CLIENT_LINEA,
[ChainId.BASE]: BLOCKS_CLIENT_BASE,
[ChainId.OPBNB]: BLOCKS_CLIENT_OPBNB,
}
export const BLOCKS_CLIENT_WITH_CHAIN = BLOCKS_SUBGRAPHS

export const ASSET_CDN = 'https://assets.pancakeswap.finance'

Expand Down
4 changes: 4 additions & 0 deletions packages/chains/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ test('exports', () => {
"isTestnetChainId",
"V3_SUBGRAPHS",
"V2_SUBGRAPHS",
"BLOCKS_SUBGRAPHS",
"getV3Subgraphs",
"getV2Subgraphs",
"getBlocksSubgraphs",
]
`)
})
96 changes: 64 additions & 32 deletions packages/chains/src/subgraphs.ts
Original file line number Diff line number Diff line change
@@ -1,35 +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://opbnb-mainnet-graph.nodereal.io/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
}

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

2 comments on commit 8fcd67c

@vercel
Copy link

@vercel vercel bot commented on 8fcd67c Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

uikit – ./packages/uikit

uikit-git-develop.pancake.run
uikit.pancake.run

@vercel
Copy link

@vercel vercel bot commented on 8fcd67c Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

pancakeswap.finance
pancake-prod.vercel.app
www.pancakeswap.finance
web2.pancake.run
web.pancake.run

Please sign in to comment.