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: farm on zksync #7477

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 apis/farms/.dev.vars
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ GOERLI_NODE=https://eth-goerli.public.blastapi.io
BSC_NODE=https://bsc-dataseed.binance.org
BSC_TESTNET_NODE=https://data-seed-prebsc-2-s1.binance.org:8545
POLYGON_ZKEVM_NODE=https://f2562de09abc5efbd21eefa083ff5326.zkevm-rpc.com/
ZKSYNC_NODE=https://mainnet.era.zksync.io
AXIOM_TOKEN=
1 change: 1 addition & 0 deletions apis/farms/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ declare global {
const BSC_NODE: string
const BSC_TESTNET_NODE: string
const POLYGON_ZKEVM_NODE: string
const ZKSYNC_NODE: string
}
1 change: 1 addition & 0 deletions apis/farms/src/lpApr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const BLOCKS_CLIENT_WITH_CHAIN = {
[ChainId.BSC_TESTNET]: '',
[ChainId.GOERLI]: '',
[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',
}

const INFO_CLIENT_WITH_CHAIN = {
Expand Down
16 changes: 14 additions & 2 deletions apis/farms/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChainId } from '@pancakeswap/sdk'
import { createPublicClient, http, PublicClient } from 'viem'
import { bsc, bscTestnet, goerli, mainnet, zkSyncTestnet, polygonZkEvm } from 'viem/chains'
import { bsc, bscTestnet, goerli, mainnet, zkSyncTestnet, polygonZkEvm, zkSync } from 'viem/chains'

const requireCheck = [ETH_NODE, GOERLI_NODE, BSC_NODE, BSC_TESTNET_NODE, POLYGON_ZKEVM_NODE]
const requireCheck = [ETH_NODE, GOERLI_NODE, BSC_NODE, BSC_TESTNET_NODE, POLYGON_ZKEVM_NODE, ZKSYNC_NODE]
requireCheck.forEach((node) => {
if (!node) {
throw new Error('Missing env var')
Expand Down Expand Up @@ -77,6 +77,16 @@ const polygonZkEvmClient = createPublicClient({
},
})

const zksyncClient = createPublicClient({
chain: zkSync,
transport: http(ZKSYNC_NODE),
batch: {
multicall: {
batchSize: 1024 * 200,
},
},
})

export const viemProviders = ({ chainId }: { chainId?: ChainId }): PublicClient => {
switch (chainId) {
case ChainId.ETHEREUM:
Expand All @@ -91,6 +101,8 @@ export const viemProviders = ({ chainId }: { chainId?: ChainId }): PublicClient
return zksyncTestnetClient
case ChainId.POLYGON_ZKEVM:
return polygonZkEvmClient
case ChainId.ZKSYNC:
return zksyncClient
default:
return bscClient
}
Expand Down
4 changes: 4 additions & 0 deletions apis/farms/src/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const V3_SUBGRAPH_CLIENTS = {
fetch,
},
),
[ChainId.ZKSYNC]: new GraphQLClient('https://api.studio.thegraph.com/query/45376/exchange-v3-zksync/version/latest', {
fetch,
}),
} satisfies Record<Exclude<FarmV3SupportedChainId, ChainId.POLYGON_ZKEVM_TESTNET>, GraphQLClient>

const zChainId = z.enum([
Expand All @@ -43,6 +46,7 @@ const zChainId = z.enum([
String(ChainId.BSC_TESTNET),
String(ChainId.ZKSYNC_TESTNET),
String(ChainId.POLYGON_ZKEVM),
String(ChainId.ZKSYNC),
])

const zAddress = z.string().regex(/^0x[a-fA-F0-9]{40}$/)
Expand Down
1 change: 1 addition & 0 deletions apis/farms/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ crons = ["0 0 * * *", "*/1 * * * *"]
# - BSC_NODE
# - BSC_TESTNET_NODE
# - POLYGON_ZKEVM_NODE
# - ZKSYNC_NODE
# Run `echo <VALUE> | wrangler secret put <NAME>` for each of these
1 change: 1 addition & 0 deletions apps/web/src/components/TokenImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const tokenImageChainNameMapping = {
[ChainId.BSC]: '',
[ChainId.ETHEREUM]: 'eth/',
[ChainId.POLYGON_ZKEVM]: 'polygon-zkevm/',
[ChainId.ZKSYNC]: 'zksync/',
}

const getImageUrlFromToken = (token: Token) => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/config/constants/supportChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const SUPPORT_FARMS = [
ChainId.ZKSYNC_TESTNET,
ChainId.POLYGON_ZKEVM_TESTNET,
ChainId.POLYGON_ZKEVM,
ChainId.ZKSYNC,
]
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
"decimals": 18,
"logoURI": "https://pancakeswap.finance/images/tokens/0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82.png"
},
{
"name": "PancakeSwap Token",
"symbol": "CAKE",
"address": "0x3A287a06c66f9E95a56327185cA2BDF5f031cEcD",
"chainId": 324,
"decimals": 18,
"logoURI": "https://pancakeswap.finance/images/tokens/0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82.png"
},
{
"name": "PancakeSwap Token",
"symbol": "CAKE",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/views/TradingReward/config/pairs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const tradingRewardPairConfigChainMap: Record<FarmV3SupportedChainId, Com
[ChainId.POLYGON_ZKEVM]: [],
[ChainId.POLYGON_ZKEVM_TESTNET]: [],
[ChainId.ZKSYNC_TESTNET]: [],
[ChainId.ZKSYNC]: [],
}
20 changes: 20 additions & 0 deletions packages/farms/constants/324.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { zksyncTokens } from '@pancakeswap/tokens'
import { FeeAmount } from '@pancakeswap/v3-sdk'
import { defineFarmV3Configs } from '../src/defineFarmV3Configs'

export const farmsV3 = defineFarmV3Configs([
{
pid: 1,
lpAddress: '0x291d9F9764c72C9BA6fF47b451a9f7885Ebf9977',
token0: zksyncTokens.usdc,
token1: zksyncTokens.weth,
feeAmount: FeeAmount.LOW,
},
{
pid: 2,
lpAddress: '0xFB467bedf483ef92D54b6615770eBEDD9F639a50',
token0: zksyncTokens.usdc,
token1: zksyncTokens.weth,
feeAmount: FeeAmount.MEDIUM,
},
])
7 changes: 7 additions & 0 deletions packages/farms/constants/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
goerliTestnetTokens,
zkSyncTestnetTokens,
polygonZkEvmTokens,
zksyncTokens,
} from '@pancakeswap/tokens'
import type { CommonPrice } from '../../src/fetchFarmsV3'
import type { FarmV3SupportedChainId } from '../../src'
Expand All @@ -23,6 +24,7 @@ export const CHAIN_ID_TO_CHAIN_NAME = {
[ChainId.GOERLI]: 'ethereum',
[ChainId.BSC_TESTNET]: 'bsc',
[ChainId.POLYGON_ZKEVM]: 'polygon_zkevm',
[ChainId.ZKSYNC]: 'zksync',
[ChainId.POLYGON_ZKEVM_TESTNET]: '',
[ChainId.ZKSYNC_TESTNET]: '',
} satisfies Record<FarmV3SupportedChainId, string>
Expand All @@ -40,6 +42,10 @@ export const priceHelperTokens = {
chain: 'polygon_zkevm',
list: [polygonZkEvmTokens.weth, polygonZkEvmTokens.usdc, polygonZkEvmTokens.usdt, polygonZkEvmTokens.matic],
},
[ChainId.ZKSYNC]: {
chain: 'zksync',
list: [zksyncTokens.weth, zksyncTokens.usdc, zksyncTokens.usdt],
},
} satisfies Record<number, PriceHelper>

// for testing purposes
Expand All @@ -59,5 +65,6 @@ export const DEFAULT_COMMON_PRICE: Record<FarmV3SupportedChainId, CommonPrice> =
[zkSyncTestnetTokens.mock.address]: '10',
},
[ChainId.POLYGON_ZKEVM]: {},
[ChainId.ZKSYNC]: {},
[ChainId.POLYGON_ZKEVM_TESTNET]: {},
}
2 changes: 2 additions & 0 deletions packages/farms/constants/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { farmsV3 as farm56 } from '../56'
import { farmsV3 as farm97 } from '../97'
import { farmsV3 as farm280 } from '../280'
import { farmsV3 as farm1101 } from '../1101'
import { farmsV3 as farm324 } from '../324'
import { farmsV3 as farm1442 } from '../1442'

export const farmsV3ConfigChainMap: Record<FarmV3SupportedChainId, ComputedFarmConfigV3[]> = {
Expand All @@ -17,4 +18,5 @@ export const farmsV3ConfigChainMap: Record<FarmV3SupportedChainId, ComputedFarmC
[ChainId.ZKSYNC_TESTNET]: farm280,
[ChainId.POLYGON_ZKEVM]: farm1101,
[ChainId.POLYGON_ZKEVM_TESTNET]: farm1442,
[ChainId.ZKSYNC]: farm324,
}
2 changes: 2 additions & 0 deletions packages/farms/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const supportedChainIdV3 = [
ChainId.ZKSYNC_TESTNET,
ChainId.POLYGON_ZKEVM_TESTNET,
ChainId.POLYGON_ZKEVM,
ChainId.ZKSYNC,
] as const
export const bCakeSupportedChainId = [ChainId.BSC] as const

Expand All @@ -31,6 +32,7 @@ export const masterChefV3Addresses = {
[ChainId.ZKSYNC_TESTNET]: '0x3c6Aa61f72932aD5D7C917737367be32D5509e6f',
[ChainId.POLYGON_ZKEVM_TESTNET]: '0xb66b07590B30d4E6E22e45Ddc83B06Bb018A7B44',
[ChainId.POLYGON_ZKEVM]: '0xe9c7f3196ab8c09f6616365e8873daeb207c0391',
[ChainId.ZKSYNC]: '0x4c615E78c5fCA1Ad31e4d66eb0D8688d84307463',
} as const satisfies Record<FarmV3SupportedChainId, string>

export const nonBSCVaultAddresses = {
Expand Down
1 change: 1 addition & 0 deletions packages/farms/tests/v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mainnetFarms = [
farmsV3ConfigChainMap[ChainId.BSC],
farmsV3ConfigChainMap[ChainId.ETHEREUM],
farmsV3ConfigChainMap[ChainId.POLYGON_ZKEVM],
farmsV3ConfigChainMap[ChainId.ZKSYNC],
]

function hasDuplicates(array: any[]) {
Expand Down
3 changes: 2 additions & 1 deletion packages/tokens/src/324.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ChainId, WETH9 } from '@pancakeswap/sdk'
import { USDC, USDT } from './common'
import { USDC, USDT, CAKE } from './common'

export const zksyncTokens = {
weth: WETH9[ChainId.ZKSYNC],
usdc: USDC[ChainId.ZKSYNC],
usdt: USDT[ChainId.ZKSYNC],
cake: CAKE[ChainId.ZKSYNC],
}
8 changes: 8 additions & 0 deletions packages/tokens/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ export const CAKE = {
'PancakeSwap Token',
'https://pancakeswap.finance/',
),
[ChainId.ZKSYNC]: new ERC20Token(
ChainId.ZKSYNC,
'0x3A287a06c66f9E95a56327185cA2BDF5f031cEcD',
18,
'CAKE',
'PancakeSwap Token',
'https://pancakeswap.finance/',
),
}

export const USDC = {
Expand Down
Loading