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: opBNB farm #8599

Merged
merged 11 commits into from
Dec 18, 2023
Merged
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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"LINEA",
"Merkl",
"multicall",
"OPBNB",
"pancakeswap",
"vecake",
"wagmi",
Expand Down
2 changes: 2 additions & 0 deletions apis/farms/.dev.vars
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ZKSYNC_NODE=https://mainnet.era.zksync.io
ARBITRUM_ONE_NODE=https://arb1.arbitrum.io/rpc
LINEA_NODE=https://rpc.linea.build
BASE_NODE=https://mainnet.base.org
OPBNB_NODE=https://opbnb-mainnet-rpc.bnbchain.org
OPBNB_TESTNET_NODE=https://opbnb-testnet-rpc.bnbchain.org
2 changes: 2 additions & 0 deletions apis/farms/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ declare global {
const ARBITRUM_ONE_NODE: string
const LINEA_NODE: string
const BASE_NODE: string
const OPBNB_NODE: string
const OPBNB_TESTNET_NODE: string
}
47 changes: 43 additions & 4 deletions apis/farms/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { ChainId } from '@pancakeswap/chains'
import { createPublicClient, http, PublicClient } from 'viem'
import { bsc, bscTestnet, goerli, mainnet, zkSyncTestnet, polygonZkEvm, zkSync, arbitrum } from 'viem/chains'
import { Chain, createPublicClient, http, PublicClient } from 'viem'
import {
arbitrum,
bsc,
bscTestnet,
goerli,
mainnet,
opBNB,
opBNBTestnet,
polygonZkEvm,
zkSync,
zkSyncTestnet,
} from 'viem/chains'

const requireCheck = [
ETH_NODE,
Expand All @@ -12,6 +23,8 @@ const requireCheck = [
ARBITRUM_ONE_NODE,
LINEA_NODE,
BASE_NODE,
OPBNB_NODE,
OPBNB_TESTNET_NODE,
]

const base = {
Expand Down Expand Up @@ -150,7 +163,7 @@ const goerliClient = createPublicClient({
})

const zksyncTestnetClient = createPublicClient({
chain: zkSyncTestnet,
chain: zkSyncTestnet as Chain,
transport: http(),
batch: {
multicall: {
Expand Down Expand Up @@ -182,7 +195,7 @@ const polygonZkEvmClient = createPublicClient({
})

const zksyncClient = createPublicClient({
chain: zkSync,
chain: zkSync as Chain,
transport: http(ZKSYNC_NODE),
batch: {
multicall: {
Expand Down Expand Up @@ -229,6 +242,28 @@ const baseClient = createPublicClient({
pollingInterval: 6_000,
})

const opBNBClient = createPublicClient({
chain: opBNB,
transport: http(OPBNB_NODE),
batch: {
multicall: {
batchSize: 1024 * 200,
wait: 16,
},
},
})

const opBNBTestnetClient = createPublicClient({
chain: opBNBTestnet,
transport: http(OPBNB_TESTNET_NODE),
batch: {
multicall: {
batchSize: 1024 * 200,
wait: 16,
},
},
})

export const viemProviders = ({ chainId }: { chainId?: ChainId }): PublicClient => {
switch (chainId) {
case ChainId.ETHEREUM:
Expand All @@ -251,6 +286,10 @@ export const viemProviders = ({ chainId }: { chainId?: ChainId }): PublicClient
return lineaClient
case ChainId.BASE:
return baseClient
case ChainId.OPBNB:
return opBNBClient
case ChainId.OPBNB_TESTNET:
return opBNBTestnetClient
default:
return bscClient
}
Expand Down
89 changes: 28 additions & 61 deletions apis/farms/src/v3.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,40 @@
/* eslint-disable no-param-reassign, no-await-in-loop */
import { masterChefV3Addresses, FarmV3SupportedChainId } from '@pancakeswap/farms'
import { ChainId, V3_SUBGRAPHS } from '@pancakeswap/chains'
import { FarmV3SupportedChainId, masterChefV3Addresses } from '@pancakeswap/farms'
import { ERC20Token } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'
import { CurrencyAmount } from '@pancakeswap/swap-sdk-core'
import { PositionMath } from '@pancakeswap/v3-sdk'
import { gql, GraphQLClient } from 'graphql-request'
import { GraphQLClient, gql } from 'graphql-request'
import { Request } from 'itty-router'
import { error, json } from 'itty-router-extras'
import { z } from 'zod'
import { Address } from 'viem'
import { z } from 'zod'

import { viemProviders } from './provider'
import { FarmKV } from './kv'
import { viemProviders } from './provider'

export const V3_SUBGRAPH_CLIENTS = {
[ChainId.ETHEREUM]: new GraphQLClient('https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-eth', {
fetch,
}),
[ChainId.GOERLI]: new GraphQLClient('https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-goerli', {
fetch,
}),
[ChainId.BSC]: new GraphQLClient('https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc', { fetch }),
[ChainId.BSC_TESTNET]: new GraphQLClient('https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-chapel', {
fetch,
}),
[ChainId.ZKSYNC_TESTNET]: new GraphQLClient(
'https://api.studio.thegraph.com/query/45376/exchange-v3-zksync-testnet/version/latest',
{
fetch,
},
),
[ChainId.POLYGON_ZKEVM]: new GraphQLClient(
'https://api.studio.thegraph.com/query/45376/exchange-v3-polygon-zkevm/version/latest',
{
fetch,
},
),
[ChainId.ZKSYNC]: new GraphQLClient('https://api.studio.thegraph.com/query/45376/exchange-v3-zksync/version/latest', {
fetch,
}),
[ChainId.ARBITRUM_ONE]: new GraphQLClient('https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-arb', {
fetch,
}),
[ChainId.LINEA]: new GraphQLClient('https://graph-query.linea.build/subgraphs/name/pancakeswap/exchange-v3-linea', {
fetch,
}),
[ChainId.BASE]: new GraphQLClient('https://api.studio.thegraph.com/query/45376/exchange-v3-base/version/latest', {
fetch,
}),
} satisfies Record<
Exclude<FarmV3SupportedChainId, ChainId.POLYGON_ZKEVM_TESTNET | ChainId.OPBNB_TESTNET>,
GraphQLClient
>

const zChainId = z.enum([
String(ChainId.BSC),
String(ChainId.ETHEREUM),
String(ChainId.GOERLI),
String(ChainId.BSC_TESTNET),
String(ChainId.ZKSYNC_TESTNET),
String(ChainId.POLYGON_ZKEVM),
String(ChainId.ZKSYNC),
String(ChainId.ARBITRUM_ONE),
String(ChainId.LINEA),
String(ChainId.BASE),
])
export const V3_SUBGRAPH_CLIENTS_CHAIN_IDS = [
ChainId.ETHEREUM,
ChainId.GOERLI,
ChainId.BSC,
ChainId.BSC_TESTNET,
ChainId.ZKSYNC_TESTNET,
ChainId.POLYGON_ZKEVM,
ChainId.ZKSYNC,
ChainId.ARBITRUM_ONE,
ChainId.LINEA,
ChainId.BASE,
ChainId.OPBNB,
] as const

type SupportChainId = (typeof V3_SUBGRAPH_CLIENTS_CHAIN_IDS)[number]

export const V3_SUBGRAPH_CLIENTS = V3_SUBGRAPH_CLIENTS_CHAIN_IDS.reduce((acc, chainId) => {
acc[chainId] = new GraphQLClient(V3_SUBGRAPHS[chainId], { fetch })
return acc
}, {} as Record<Exclude<FarmV3SupportedChainId, ChainId.POLYGON_ZKEVM_TESTNET | ChainId.OPBNB_TESTNET>, GraphQLClient>)

const zChainId = z.enum(V3_SUBGRAPH_CLIENTS_CHAIN_IDS.map((chainId) => String(chainId)) as [string, ...string[]])

const zAddress = z.string().regex(/^0x[a-fA-F0-9]{40}$/)

Expand Down Expand Up @@ -176,10 +146,7 @@ const handler_ = async (req: Request, event: FetchEvent) => {
}

const { chainId: chainIdString, address: address_ } = parsed.data
const chainId = Number(chainIdString) as Exclude<
FarmV3SupportedChainId,
ChainId.POLYGON_ZKEVM_TESTNET | ChainId.OPBNB_TESTNET
>
const chainId = Number(chainIdString) as SupportChainId

const address = address_.toLowerCase()

Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/components/TokenImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChainId } from '@pancakeswap/chains'
import { Token } from '@pancakeswap/sdk'
import {
ImageProps,
TokenImage as UIKitTokenImage,
TokenPairImage as UIKitTokenPairImage,
TokenPairImageProps as UIKitTokenPairImageProps,
TokenImage as UIKitTokenImage,
ImageProps,
} from '@pancakeswap/uikit'
import { Token } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'

interface TokenPairImageProps extends Omit<UIKitTokenPairImageProps, 'primarySrc' | 'secondarySrc'> {
primaryToken: Token
Expand All @@ -20,6 +20,7 @@ export const tokenImageChainNameMapping = {
[ChainId.ARBITRUM_ONE]: 'arbitrum/',
[ChainId.LINEA]: 'linea/',
[ChainId.BASE]: 'base/',
[ChainId.OPBNB]: 'opbnb/',
}

const getImageUrlFromToken = (token: Token) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@
"chainId": 5611,
"decimals": 18,
"logoURI": "https://tokens.pancakeswap.finance/images/symbol/usdt.png"
},
{
"name": "PancakeSwap Token",
"symbol": "CAKE",
"address": "0x2779106e4F4A8A28d77A24c18283651a2AE22D1C",
"chainId": 204,
"decimals": 18,
"logoURI": "https://tokens.pancakeswap.finance/images/symbol/cake.png"
}
]
}
18 changes: 10 additions & 8 deletions apps/web/src/views/TradingReward/config/pairs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ChainId } from '@pancakeswap/chains'
import { ComputedFarmConfigV3, FarmV3SupportedChainId } from '@pancakeswap/farms/src'
import { farmsV3 as ethFarm } from '@pancakeswap/farms/constants/eth'
import { farmsV3 as farm5 } from '@pancakeswap/farms/constants/goerli'
import { farmsV3 as arbitrumFarm } from '@pancakeswap/farms/constants/arb'
import { farmsV3 as baseFarm } from '@pancakeswap/farms/constants/base'
import { farmsV3 as bscFarm } from '@pancakeswap/farms/constants/bsc'
import { farmsV3 as farm97 } from '@pancakeswap/farms/constants/bscTestnet'
import { farmsV3 as ethFarm } from '@pancakeswap/farms/constants/eth'
import { farmsV3 as farm5 } from '@pancakeswap/farms/constants/goerli'
import { farmsV3 as lineaFarm } from '@pancakeswap/farms/constants/linea'
import { farmsV3 as opBNBFarms } from '@pancakeswap/farms/constants/opBNB'
import { farmsV3 as opBNBTestnetFarms } from '@pancakeswap/farms/constants/opBnbTestnet'
import { farmsV3 as zkEvmFarm } from '@pancakeswap/farms/constants/polygonZkEVM'
import { farmsV3 as zkSyncFarm } from '@pancakeswap/farms/constants/zkSync'
import { farmsV3 as lineaFarm } from '@pancakeswap/farms/constants/linea'
import { farmsV3 as arbitrumFarm } from '@pancakeswap/farms/constants/arb'
import { farmsV3 as baseFarm } from '@pancakeswap/farms/constants/base'
import { farmsV3 as opBnbTestnetFarms } from '@pancakeswap/farms/constants/opBnbTestnet'
import { ComputedFarmConfigV3, FarmV3SupportedChainId } from '@pancakeswap/farms/src'
import { tradingRewardV3Pair as tradingRewardV3Pair56 } from './56'

export const tradingRewardPairConfigChainMap: Record<FarmV3SupportedChainId, ComputedFarmConfigV3[]> = {
Expand All @@ -24,5 +25,6 @@ export const tradingRewardPairConfigChainMap: Record<FarmV3SupportedChainId, Com
[ChainId.ARBITRUM_ONE]: arbitrumFarm,
[ChainId.LINEA]: lineaFarm,
[ChainId.BASE]: baseFarm,
[ChainId.OPBNB_TESTNET]: opBnbTestnetFarms,
[ChainId.OPBNB_TESTNET]: opBNBTestnetFarms,
[ChainId.OPBNB]: opBNBFarms,
}
2 changes: 1 addition & 1 deletion packages/chains/src/subgraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const V3_SUBGRAPHS = {
[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/v0.0.0',
[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',
Expand Down
13 changes: 7 additions & 6 deletions packages/farms/constants/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ERC20Token } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'
import { ERC20Token } from '@pancakeswap/sdk'
import {
arbitrumTokens,
baseTokens,
bscTestnetTokens,
bscTokens,
ethereumTokens,
goerliTestnetTokens,
zkSyncTestnetTokens,
lineaTokens,
polygonZkEvmTokens,
zkSyncTestnetTokens,
zksyncTokens,
arbitrumTokens,
lineaTokens,
baseTokens,
} from '@pancakeswap/tokens'
import type { CommonPrice } from '../../src/fetchFarmsV3'
import type { FarmV3SupportedChainId } from '../../src'
import type { CommonPrice } from '../../src/fetchFarmsV3'

export const CAKE_BNB_LP_MAINNET = '0x0eD7e52944161450477ee417DE9Cd3a859b14fD0'

Expand Down Expand Up @@ -76,4 +76,5 @@ export const DEFAULT_COMMON_PRICE: Record<FarmV3SupportedChainId, CommonPrice> =
[ChainId.LINEA]: {},
[ChainId.BASE]: {},
[ChainId.OPBNB_TESTNET]: {},
[ChainId.OPBNB]: {},
}
14 changes: 14 additions & 0 deletions packages/farms/constants/opBNB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { opBnbTokens } from '@pancakeswap/tokens'
import { FeeAmount } from '@pancakeswap/v3-sdk'

import { defineFarmV3Configs } from '../src/defineFarmV3Configs'

export const farmsV3 = defineFarmV3Configs([
{
pid: 1,
lpAddress: '0xc4f981189558682F15F60513158B699354B30204',
token0: opBnbTokens.wbnb,
token1: opBnbTokens.usdt,
feeAmount: FeeAmount.LOW,
},
])
2 changes: 2 additions & 0 deletions packages/farms/constants/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { farmsV3 as bscTestnetFarms } from '../bscTestnet'
import { farmsV3 as ethFarms } from '../eth'
import { farmsV3 as goerliFarms } from '../goerli'
import { farmsV3 as lineaFarms } from '../linea'
import { farmsV3 as opBNBFarms } from '../opBNB'
import { farmsV3 as opBnbTestnetFarms } from '../opBnbTestnet'
import { farmsV3 as polygonZkEVMFarms } from '../polygonZkEVM'
import { farmsV3 as polygonZkEVMTestnetFarms } from '../polygonZkEVMTestnet'
Expand All @@ -28,6 +29,7 @@ export const farmsV3ConfigChainMap: Record<FarmV3SupportedChainId, ComputedFarmC
[ChainId.LINEA]: lineaFarms,
[ChainId.BASE]: baseFarms,
[ChainId.OPBNB_TESTNET]: opBnbTestnetFarms,
[ChainId.OPBNB]: opBNBFarms,
}

export type Addresses = {
Expand Down
2 changes: 2 additions & 0 deletions packages/farms/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const supportedChainIdV3 = [
ChainId.ARBITRUM_ONE,
ChainId.LINEA,
ChainId.BASE,
ChainId.OPBNB,
ChainId.OPBNB_TESTNET,
] as const
export const supportedChainId = uniq([...supportedChainIdV2, ...supportedChainIdV3])
Expand Down Expand Up @@ -44,6 +45,7 @@ export const masterChefV3Addresses = {
[ChainId.ARBITRUM_ONE]: '0x5e09ACf80C0296740eC5d6F643005a4ef8DaA694',
[ChainId.LINEA]: '0x22E2f236065B780FA33EC8C4E58b99ebc8B55c57',
[ChainId.BASE]: '0xC6A2Db661D5a5690172d8eB0a7DEA2d3008665A3',
[ChainId.OPBNB]: '0x05ddEDd07C51739d2aE21F6A9d97a8d69C2C3aaA',
[ChainId.OPBNB_TESTNET]: '0x236e713bFF45adb30e25D1c29A887aBCb0Ea7E21',
} as const satisfies Record<FarmV3SupportedChainId, string>

Expand Down
2 changes: 2 additions & 0 deletions packages/multicall/src/constants/gasLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {
[ChainId.ZKSYNC]: 500000000n,
[ChainId.POLYGON_ZKEVM]: 1500000n,
[ChainId.BASE]: 60000000n,
[ChainId.OPBNB]: 100_000_000n,
[ChainId.OPBNB_TESTNET]: 100_000_000n,
ChefJerry marked this conversation as resolved.
Show resolved Hide resolved
}

export const DEFAULT_GAS_BUFFER = 3000000n
Expand Down
Loading
Loading