@berachain/berajs 0.2.8-beta.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BeraError-_mQdkanr.d.cts → BeraError-7-A5JYy_.d.ts} +31 -2
- package/dist/{HoneyConfigProvider-DVP_9KZn.d.ts → HoneyConfigProvider-Dkj-_a5x.d.ts} +1 -1
- package/dist/{RequestError-BRIiJgHk.d.ts → RequestError-DBOIV65x.d.ts} +1 -1
- package/dist/abi/exports.mjs +4452 -2
- package/dist/actions/clients/exports.d.ts +78 -0
- package/dist/actions/clients/exports.mjs +21 -0
- package/dist/actions/exports.d.ts +154 -207
- package/dist/actions/exports.mjs +853 -2
- package/dist/actions/governance/exports.d.ts +140 -0
- package/dist/actions/governance/exports.mjs +226 -0
- package/dist/actions/server/exports.d.ts +13 -0
- package/dist/actions/server/exports.mjs +27 -0
- package/dist/chunk-3JJLQ2JX.mjs +211 -0
- package/dist/chunk-7YVNSDXG.mjs +86 -0
- package/dist/chunk-AUOPN6NK.mjs +96 -0
- package/dist/chunk-BGMRHTBQ.mjs +23 -0
- package/dist/chunk-CDK4YV3D.mjs +571 -0
- package/dist/chunk-DKMAIU74.mjs +62 -0
- package/dist/chunk-DQRH5VE3.mjs +25 -0
- package/dist/chunk-E7YFXBBQ.mjs +349 -0
- package/dist/chunk-GUURQAME.mjs +326 -0
- package/dist/chunk-GY6B3PD5.mjs +89 -0
- package/dist/chunk-HQCOU6GY.mjs +243 -0
- package/dist/chunk-HYDP32P6.mjs +135 -0
- package/dist/chunk-IXIBY5FP.mjs +80 -0
- package/dist/chunk-KHXJDYA4.mjs +1776 -0
- package/dist/chunk-NBYLMO2L.mjs +14 -0
- package/dist/chunk-O2NQFKJK.mjs +170 -0
- package/dist/chunk-P5WXXULM.mjs +54 -0
- package/dist/chunk-QBBOWFMH.mjs +4129 -0
- package/dist/chunk-QVHEM4BG.mjs +35 -0
- package/dist/chunk-SGIJVHZO.mjs +12 -0
- package/dist/chunk-SZ5C44L5.mjs +35 -0
- package/dist/chunk-WNBWX23Q.mjs +426 -0
- package/dist/chunk-Y6THHG77.mjs +126 -0
- package/dist/chunk-ZLTMIFCZ.mjs +165 -0
- package/dist/contexts/exports.d.ts +2 -2
- package/dist/contexts/exports.mjs +85 -2
- package/dist/enum/exports.d.ts +1 -1
- package/dist/enum/exports.mjs +46 -2
- package/dist/enum/governance/exports.d.ts +60 -0
- package/dist/enum/governance/exports.mjs +14 -0
- package/dist/errors/exports.d.ts +4 -3
- package/dist/errors/exports.mjs +48 -2
- package/dist/getApolloClient-BcUTGFUb.d.ts +40 -0
- package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-DphU3qhE.d.ts} +2 -2
- package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
- package/dist/hooks/exports.d.ts +83 -226
- package/dist/hooks/exports.mjs +7463 -4
- package/dist/hooks/governance/exports.d.ts +181 -0
- package/dist/hooks/governance/exports.mjs +888 -0
- package/dist/pol.d-Dw5SQcRX.d.ts +153 -0
- package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
- package/dist/types/exports.d.ts +9 -9
- package/dist/types/exports.mjs +0 -1
- package/dist/types/governance/exports.d.ts +109 -0
- package/dist/types/governance/exports.mjs +0 -0
- package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
- package/dist/utils/exports.d.ts +15 -6
- package/dist/utils/exports.mjs +827 -2
- package/package.json +49 -13
- package/src/actions/__test/transports.ts +61 -0
- package/src/actions/clients/exports.ts +7 -0
- package/src/actions/clients/fetchBeep.ts +34 -0
- package/src/actions/clients/fetchOpenApi.ts +93 -0
- package/src/actions/clients/fetchOpenApi.unit.test.ts +223 -0
- package/src/actions/clients/fetchRailwayBackend.ts +34 -0
- package/src/actions/clients/getApolloClient.ts +58 -23
- package/src/actions/clients/getEnsoClient.ts +20 -9
- package/src/actions/dex/aggregators/enso/enso.ts +27 -17
- package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
- package/src/actions/dex/aggregators/kyberswap.ts +18 -23
- package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
- package/src/actions/enso/getEnsoUserTokensWithBalances.ts +18 -0
- package/src/actions/exports.ts +5 -9
- package/src/actions/governance/exports.ts +9 -0
- package/src/actions/governance/getAllProposals.ts +10 -65
- package/src/actions/governance/getProposalDetails.ts +6 -33
- package/src/actions/governance/getProposalVotes.ts +8 -15
- package/src/actions/honey/getChartData.ts +27 -21
- package/src/actions/honey/getHoney24hVolume.ts +19 -22
- package/src/actions/honey/getPythLatestPrices.ts +7 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
- package/src/actions/pol/getAutoclaimedIncentives.ts +41 -0
- package/src/actions/pol/getAutoclaimedIncentivesTxHash.ts +41 -0
- package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
- package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +28 -0
- package/src/actions/pol/getEarnedStakedBeraVault.ts +20 -20
- package/src/actions/pol/getGlobalData.ts +1 -0
- package/src/actions/pol/getHeroEarnVaults.ts +62 -0
- package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
- package/src/actions/pol/getRewardVaults.ts +4 -4
- package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
- package/src/actions/pol/getStakingDailyAssets.ts +18 -17
- package/src/actions/server/exports.ts +1 -0
- package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
- package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
- package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
- package/src/actions/validators/getValidatorAnalytics.ts +20 -21
- package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
- package/src/actions/validators/utils/getValidatorBoostApy.ts +1 -1
- package/src/enum/contracts.ts +1 -0
- package/src/enum/exports.ts +0 -1
- package/src/enum/governance/exports.ts +1 -0
- package/src/errors/BeraError.ts +47 -7
- package/src/errors/BeraTracing.unit.test.ts +65 -0
- package/src/errors/RequestError.ts +25 -4
- package/src/errors/RequestError.unit.test.ts +55 -0
- package/src/errors/errorMap.ts +8 -0
- package/src/errors/exports.ts +5 -0
- package/src/errors/getRevertReason.integration.test.ts +3 -3
- package/src/errors/spanStatus.ts +78 -0
- package/src/errors/spanStatus.unit.test.ts +62 -0
- package/src/hooks/dex/useCreatePool.ts +1 -88
- package/src/hooks/dex/useOnChainPoolData.ts +27 -2
- package/src/hooks/dex/usePriceImpact.ts +12 -5
- package/src/hooks/enso/useBendDemultiply.ts +9 -1
- package/src/hooks/enso/useBendMultiply.ts +9 -1
- package/src/hooks/enso/useBendZapSupply.ts +26 -7
- package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
- package/src/hooks/exports.ts +3 -15
- package/src/hooks/governance/exports.ts +14 -0
- package/src/hooks/pol/useAutoclaimedIncentives.ts +40 -0
- package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +45 -0
- package/src/hooks/pol/useStakedAPR.ts +2 -2
- package/src/hooks/pol/useStakedSnapshots.ts +5 -9
- package/src/hooks/validators/useValidator.ts +6 -8
- package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
- package/src/types/bribe-boost.d.ts +19 -0
- package/src/types/exports.ts +0 -1
- package/src/types/governance/exports.ts +1 -0
- package/src/utils/beraFetch.ts +9 -3
- package/src/utils/exports.ts +1 -0
- package/src/utils/getServerSideClient.ts +4 -2
- package/src/utils/polyfillAbortSignalAny.ts +53 -0
- package/src/utils/polyfillAbortSignalAny.unit.test.ts +81 -0
- package/src/utils/sanitizeRpcUrl.ts +22 -0
- package/src/utils/tracedTransport.ts +35 -0
- package/dist/BeraError-_mQdkanr.d.ts +0 -94
- package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
- package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
- package/dist/RequestError-DSUzJ1Iy.d.cts +0 -144
- package/dist/abi/exports.cjs +0 -2
- package/dist/abi/exports.cjs.map +0 -1
- package/dist/abi/exports.d.cts +0 -6574
- package/dist/abi/exports.mjs.map +0 -1
- package/dist/actions/exports.cjs +0 -2
- package/dist/actions/exports.cjs.map +0 -1
- package/dist/actions/exports.d.cts +0 -1650
- package/dist/actions/exports.mjs.map +0 -1
- package/dist/chunk-45HIEVNI.cjs +0 -4
- package/dist/chunk-45HIEVNI.cjs.map +0 -1
- package/dist/chunk-47ILYVHC.mjs +0 -2
- package/dist/chunk-47ILYVHC.mjs.map +0 -1
- package/dist/chunk-575OK77P.mjs +0 -2
- package/dist/chunk-575OK77P.mjs.map +0 -1
- package/dist/chunk-5NVZG5N6.mjs +0 -2
- package/dist/chunk-5NVZG5N6.mjs.map +0 -1
- package/dist/chunk-6DIA6PXV.cjs +0 -2
- package/dist/chunk-6DIA6PXV.cjs.map +0 -1
- package/dist/chunk-6JJIZCVY.cjs +0 -2
- package/dist/chunk-6JJIZCVY.cjs.map +0 -1
- package/dist/chunk-7F72ZH4Q.mjs +0 -2
- package/dist/chunk-7F72ZH4Q.mjs.map +0 -1
- package/dist/chunk-AUA42YIG.mjs +0 -4
- package/dist/chunk-AUA42YIG.mjs.map +0 -1
- package/dist/chunk-BC2WX6O6.cjs +0 -2
- package/dist/chunk-BC2WX6O6.cjs.map +0 -1
- package/dist/chunk-CJOZC5Z2.cjs +0 -2
- package/dist/chunk-CJOZC5Z2.cjs.map +0 -1
- package/dist/chunk-D6L7LTA2.cjs +0 -2
- package/dist/chunk-D6L7LTA2.cjs.map +0 -1
- package/dist/chunk-DDEQFR3M.cjs +0 -2
- package/dist/chunk-DDEQFR3M.cjs.map +0 -1
- package/dist/chunk-GXV2JA36.mjs +0 -2
- package/dist/chunk-GXV2JA36.mjs.map +0 -1
- package/dist/chunk-ISYNEDET.mjs +0 -2
- package/dist/chunk-ISYNEDET.mjs.map +0 -1
- package/dist/chunk-JDDRTHFG.mjs +0 -2
- package/dist/chunk-JDDRTHFG.mjs.map +0 -1
- package/dist/chunk-JDZGYU5T.mjs +0 -2
- package/dist/chunk-JDZGYU5T.mjs.map +0 -1
- package/dist/chunk-LVOXBZMA.cjs +0 -2
- package/dist/chunk-LVOXBZMA.cjs.map +0 -1
- package/dist/chunk-MK5NS5B5.mjs +0 -2
- package/dist/chunk-MK5NS5B5.mjs.map +0 -1
- package/dist/chunk-NAXAZJJY.mjs +0 -2
- package/dist/chunk-NAXAZJJY.mjs.map +0 -1
- package/dist/chunk-NLVWRMGD.mjs +0 -2
- package/dist/chunk-NLVWRMGD.mjs.map +0 -1
- package/dist/chunk-OGBD5YOG.mjs +0 -2
- package/dist/chunk-OGBD5YOG.mjs.map +0 -1
- package/dist/chunk-OGJMSGB2.mjs +0 -2
- package/dist/chunk-OGJMSGB2.mjs.map +0 -1
- package/dist/chunk-OIYXOKTT.cjs +0 -2
- package/dist/chunk-OIYXOKTT.cjs.map +0 -1
- package/dist/chunk-OUD27MU7.cjs +0 -2
- package/dist/chunk-OUD27MU7.cjs.map +0 -1
- package/dist/chunk-PRLVZIKD.mjs +0 -2
- package/dist/chunk-PRLVZIKD.mjs.map +0 -1
- package/dist/chunk-Q2SNRLW3.cjs +0 -2
- package/dist/chunk-Q2SNRLW3.cjs.map +0 -1
- package/dist/chunk-REWME3FY.cjs +0 -2
- package/dist/chunk-REWME3FY.cjs.map +0 -1
- package/dist/chunk-RJN36GBU.mjs +0 -2
- package/dist/chunk-RJN36GBU.mjs.map +0 -1
- package/dist/chunk-RWOICHRW.cjs +0 -2
- package/dist/chunk-RWOICHRW.cjs.map +0 -1
- package/dist/chunk-S4CDSVLK.cjs +0 -2
- package/dist/chunk-S4CDSVLK.cjs.map +0 -1
- package/dist/chunk-SFEULGSX.cjs +0 -2
- package/dist/chunk-SFEULGSX.cjs.map +0 -1
- package/dist/chunk-WBTS6KFG.mjs +0 -2
- package/dist/chunk-WBTS6KFG.mjs.map +0 -1
- package/dist/chunk-WRFDB3QJ.cjs +0 -2
- package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
- package/dist/chunk-XNJLSA6P.cjs +0 -2
- package/dist/chunk-XNJLSA6P.cjs.map +0 -1
- package/dist/contexts/exports.cjs +0 -2
- package/dist/contexts/exports.cjs.map +0 -1
- package/dist/contexts/exports.d.cts +0 -66
- package/dist/contexts/exports.mjs.map +0 -1
- package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
- package/dist/dex-C_BB0b0O.d.cts +0 -37
- package/dist/enum/exports.cjs +0 -2
- package/dist/enum/exports.cjs.map +0 -1
- package/dist/enum/exports.d.cts +0 -23
- package/dist/enum/exports.mjs.map +0 -1
- package/dist/errors/exports.cjs +0 -2
- package/dist/errors/exports.cjs.map +0 -1
- package/dist/errors/exports.d.cts +0 -327
- package/dist/errors/exports.mjs.map +0 -1
- package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
- package/dist/global.d-B7IeayVX.d.cts +0 -474
- package/dist/honey-CYm0RWf4.d.cts +0 -14
- package/dist/hooks/exports.cjs +0 -4
- package/dist/hooks/exports.cjs.map +0 -1
- package/dist/hooks/exports.d.cts +0 -1734
- package/dist/hooks/exports.mjs.map +0 -1
- package/dist/polling-BKnyavLI.d.cts +0 -8
- package/dist/txnEnum-7_o92X3N.d.ts +0 -164
- package/dist/types/exports.cjs +0 -1
- package/dist/types/exports.cjs.map +0 -1
- package/dist/types/exports.d.cts +0 -90
- package/dist/types/exports.mjs.map +0 -1
- package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
- package/dist/utils/exports.cjs +0 -2
- package/dist/utils/exports.cjs.map +0 -1
- package/dist/utils/exports.d.cts +0 -420
- package/dist/utils/exports.mjs.map +0 -1
- package/src/actions/dex/getIsTokenExploited.ts +0 -63
- package/src/hooks/dex/useExploitedTokens.ts +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@berachain/berajs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -11,37 +11,73 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@apollo/client": "4.1.6",
|
|
14
|
-
"@berachain-foundation/berancer-sdk": "1.1.
|
|
15
|
-
"@berachain/abis": "0.1.0",
|
|
16
|
-
"@berachain/config": "0.1.
|
|
17
|
-
"@berachain/graphql": "0.
|
|
18
|
-
"@ensofinance/sdk": "2.
|
|
14
|
+
"@berachain-foundation/berancer-sdk": "1.1.7",
|
|
15
|
+
"@berachain/abis": "0.1.3-beta.0",
|
|
16
|
+
"@berachain/config": "0.1.17",
|
|
17
|
+
"@berachain/graphql": "0.5.0",
|
|
18
|
+
"@ensofinance/sdk": "2.3.1",
|
|
19
19
|
"@pythnetwork/hermes-client": "2.0.0",
|
|
20
20
|
"@wagmi/core": "2.22.1",
|
|
21
21
|
"gray-matter": "4.0.3",
|
|
22
22
|
"swr": "2.4.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react-dom": "19.
|
|
26
|
-
"@types/react": "19.
|
|
25
|
+
"@types/react-dom": "19.2.3",
|
|
26
|
+
"@types/react": "19.2.14",
|
|
27
27
|
"@typescript/analyze-trace": "0.10.1",
|
|
28
28
|
"tsup": "8.5.1",
|
|
29
29
|
"typescript": "5.5.4",
|
|
30
30
|
"viem": "2.45.0",
|
|
31
31
|
"vitest": "3.2.4",
|
|
32
32
|
"@berachain/utils": "0.1.0",
|
|
33
|
-
"@berachain/wagmi": "0.4.2"
|
|
33
|
+
"@berachain/wagmi": "0.4.2-beta.6"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
|
+
"./actions/*": {
|
|
37
|
+
"types": "./dist/actions/*/exports.d.ts",
|
|
38
|
+
"import": "./dist/actions/*/exports.mjs",
|
|
39
|
+
"require": "./dist/actions/*/exports.cjs",
|
|
40
|
+
"default": "./dist/actions/*/exports.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./hooks/*": {
|
|
43
|
+
"types": "./dist/hooks/*/exports.d.ts",
|
|
44
|
+
"import": "./dist/hooks/*/exports.mjs",
|
|
45
|
+
"require": "./dist/hooks/*/exports.cjs",
|
|
46
|
+
"default": "./dist/hooks/*/exports.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./enum/*": {
|
|
49
|
+
"types": "./dist/enum/*/exports.d.ts",
|
|
50
|
+
"import": "./dist/enum/*/exports.mjs",
|
|
51
|
+
"require": "./dist/enum/*/exports.cjs",
|
|
52
|
+
"default": "./dist/enum/*/exports.cjs"
|
|
53
|
+
},
|
|
54
|
+
"./types/*": {
|
|
55
|
+
"types": "./dist/types/*/exports.d.ts",
|
|
56
|
+
"import": "./dist/types/*/exports.mjs",
|
|
57
|
+
"require": "./dist/types/*/exports.cjs",
|
|
58
|
+
"default": "./dist/types/*/exports.cjs"
|
|
59
|
+
},
|
|
36
60
|
"./*": {
|
|
37
61
|
"types": "./dist/*/exports.d.ts",
|
|
38
62
|
"import": "./dist/*/exports.mjs",
|
|
39
|
-
"
|
|
63
|
+
"require": "./dist/*/exports.cjs",
|
|
40
64
|
"default": "./dist/*/exports.cjs"
|
|
41
65
|
}
|
|
42
66
|
},
|
|
43
67
|
"typesVersions": {
|
|
44
68
|
"*": {
|
|
69
|
+
"actions/*": [
|
|
70
|
+
"dist/actions/*/exports.d.ts"
|
|
71
|
+
],
|
|
72
|
+
"hooks/*": [
|
|
73
|
+
"dist/hooks/*/exports.d.ts"
|
|
74
|
+
],
|
|
75
|
+
"enum/*": [
|
|
76
|
+
"dist/enum/*/exports.d.ts"
|
|
77
|
+
],
|
|
78
|
+
"types/*": [
|
|
79
|
+
"dist/types/*/exports.d.ts"
|
|
80
|
+
],
|
|
45
81
|
"*": [
|
|
46
82
|
"dist/*/exports.d.ts"
|
|
47
83
|
]
|
|
@@ -51,7 +87,7 @@
|
|
|
51
87
|
"react": "^19.1",
|
|
52
88
|
"react-dom": "^19.1",
|
|
53
89
|
"viem": "^2.41.2",
|
|
54
|
-
"@berachain/wagmi": "0.4.2"
|
|
90
|
+
"@berachain/wagmi": "0.4.2-beta.6"
|
|
55
91
|
},
|
|
56
92
|
"peerDependenciesMeta": {
|
|
57
93
|
"react": {
|
|
@@ -65,11 +101,11 @@
|
|
|
65
101
|
}
|
|
66
102
|
},
|
|
67
103
|
"scripts": {
|
|
68
|
-
"build": "tsup",
|
|
104
|
+
"build": "NODE_OPTIONS='--max-old-space-size=8192' tsup",
|
|
69
105
|
"prebuild": "pnpm contracts:update",
|
|
70
106
|
"test": "vitest",
|
|
71
107
|
"clean": "git clean -xdf dist .turbo node_modules",
|
|
72
|
-
"check-types": "tsup --dtsOnly",
|
|
108
|
+
"check-types": "NODE_OPTIONS='--max-old-space-size=8192' tsup --dtsOnly",
|
|
73
109
|
"precheck-types": "pnpm prebuild",
|
|
74
110
|
"dev": "tsup --watch",
|
|
75
111
|
"lint": "biome lint",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { fallback, http } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
arbitrum,
|
|
4
|
+
avalanche,
|
|
5
|
+
base,
|
|
6
|
+
bsc,
|
|
7
|
+
mainnet,
|
|
8
|
+
optimism,
|
|
9
|
+
polygon,
|
|
10
|
+
} from "viem/chains";
|
|
11
|
+
|
|
12
|
+
import { publicJsonRpcUrl } from "@berachain/config/internal";
|
|
13
|
+
import { defaultChain } from "@berachain/config/internal/wagmi";
|
|
14
|
+
|
|
15
|
+
const transportOptions = {
|
|
16
|
+
batch: { wait: 35 },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const externalTransportOptions = {
|
|
20
|
+
batch: { wait: 15 },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const urls = [publicJsonRpcUrl].filter(Boolean) as string[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Thirdweb RPC URLs have a rate limit of 3 RPS.
|
|
27
|
+
* http() uses default viem transport which varies based on the chain definition.
|
|
28
|
+
*
|
|
29
|
+
* Quicknode RPC URLs are CORS restricted to *.berachain.com, *.berachain-staging.com. They have a 100rpm rate limit.
|
|
30
|
+
*/
|
|
31
|
+
export const testTransports = {
|
|
32
|
+
[defaultChain.id]: fallback(urls.map((url) => http(url, transportOptions))),
|
|
33
|
+
[mainnet.id]: fallback([
|
|
34
|
+
http("https://1.rpc.thirdweb.com/", externalTransportOptions),
|
|
35
|
+
http(),
|
|
36
|
+
]),
|
|
37
|
+
[polygon.id]: fallback([
|
|
38
|
+
http("https://137.rpc.thirdweb.com/", externalTransportOptions),
|
|
39
|
+
http(),
|
|
40
|
+
]),
|
|
41
|
+
[optimism.id]: fallback([
|
|
42
|
+
http("https://10.rpc.thirdweb.com/", externalTransportOptions),
|
|
43
|
+
http(),
|
|
44
|
+
]),
|
|
45
|
+
[base.id]: fallback([
|
|
46
|
+
http("https://8453.rpc.thirdweb.com/", externalTransportOptions),
|
|
47
|
+
http(),
|
|
48
|
+
]),
|
|
49
|
+
[bsc.id]: fallback([
|
|
50
|
+
http("https://56.rpc.thirdweb.com/", externalTransportOptions),
|
|
51
|
+
http(),
|
|
52
|
+
]),
|
|
53
|
+
[avalanche.id]: fallback([
|
|
54
|
+
http("https://43114.rpc.thirdweb.com/", externalTransportOptions),
|
|
55
|
+
http(),
|
|
56
|
+
]),
|
|
57
|
+
[arbitrum.id]: fallback([
|
|
58
|
+
http("https://42161.rpc.thirdweb.com/", externalTransportOptions),
|
|
59
|
+
http(),
|
|
60
|
+
]),
|
|
61
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { paths } from "@berachain/graphql/beep";
|
|
2
|
+
|
|
3
|
+
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
4
|
+
import {
|
|
5
|
+
type DefinedParams,
|
|
6
|
+
fetchOpenApi,
|
|
7
|
+
type GetPath,
|
|
8
|
+
type GetResponse,
|
|
9
|
+
} from "./fetchOpenApi";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Typed GET against the next-gen "beep" backend.
|
|
13
|
+
*
|
|
14
|
+
* The `path`, its path/query params and the response are all type-checked
|
|
15
|
+
* against the beep schema (`@berachain/graphql/beep`), so route shapes (e.g.
|
|
16
|
+
* the `/v0/stake/*` namespace) can never drift out of sync with the backend.
|
|
17
|
+
* The base URL is resolved from `config.beep`.
|
|
18
|
+
*
|
|
19
|
+
* @throws if `config.beep` is not set for the active chain. Callers should only
|
|
20
|
+
* reach for beep when `config.beep` is non-null.
|
|
21
|
+
*/
|
|
22
|
+
export function fetchBeep<P extends GetPath<paths>>(
|
|
23
|
+
path: P,
|
|
24
|
+
params: DefinedParams<paths, P>,
|
|
25
|
+
args: BeraJS.BaseFunctionArgs = {},
|
|
26
|
+
): Promise<GetResponse<paths, P>> {
|
|
27
|
+
const { config } = parseBaseArgs(args);
|
|
28
|
+
|
|
29
|
+
if (!config.beep) {
|
|
30
|
+
throw new Error("fetchBeep: `beep` backend is not configured.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return fetchOpenApi<paths, P>(config.beep, path, params, "beep");
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { HttpLink } from "@berachain/config";
|
|
2
|
+
import { getUriFromLink } from "@berachain/config";
|
|
3
|
+
|
|
4
|
+
import { beraFetchJson } from "../../utils/beraFetch";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A minimal, fully-typed GET helper for our `openapi-typescript`-generated
|
|
8
|
+
* backends. Both backends serve only GETs, so rather than a full OpenAPI client
|
|
9
|
+
* we type a single `fetchOpenApi` against a schema's `paths` and wrap it per
|
|
10
|
+
* backend (`fetchBeep`, `fetchRailwayBackend`).
|
|
11
|
+
*
|
|
12
|
+
* The `path`, its path/query params and the response body are all type-checked
|
|
13
|
+
* against the schema, so route shapes can never drift out of sync with the
|
|
14
|
+
* backend. Requests go through {@link beraFetchJson} so they keep the same
|
|
15
|
+
* Sentry tracing, `RequestError` handling and URL sanitization as the rest of
|
|
16
|
+
* the codebase.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Any `openapi-typescript` `paths` object. */
|
|
20
|
+
// biome-ignore lint/suspicious/noExplicitAny: schema `paths` are structurally diverse; constrained at call sites by the concrete schema.
|
|
21
|
+
type AnyPaths = Record<string, any>;
|
|
22
|
+
|
|
23
|
+
/** Paths in a schema that expose a JSON GET response. */
|
|
24
|
+
export type GetPath<Paths extends AnyPaths> = {
|
|
25
|
+
[P in keyof Paths]: Paths[P] extends {
|
|
26
|
+
get: { responses: { 200: { content: { "application/json": unknown } } } };
|
|
27
|
+
}
|
|
28
|
+
? P
|
|
29
|
+
: never;
|
|
30
|
+
}[keyof Paths];
|
|
31
|
+
|
|
32
|
+
type GetParams<
|
|
33
|
+
Paths extends AnyPaths,
|
|
34
|
+
P extends GetPath<Paths>,
|
|
35
|
+
> = Paths[P]["get"] extends { parameters: infer Params } ? Params : never;
|
|
36
|
+
|
|
37
|
+
export type GetResponse<
|
|
38
|
+
Paths extends AnyPaths,
|
|
39
|
+
P extends GetPath<Paths>,
|
|
40
|
+
> = Paths[P]["get"]["responses"][200]["content"]["application/json"];
|
|
41
|
+
|
|
42
|
+
// Drop the params keys that are `never` (e.g. an endpoint with no query) so
|
|
43
|
+
// callers only pass what an endpoint actually accepts.
|
|
44
|
+
export type DefinedParams<Paths extends AnyPaths, P extends GetPath<Paths>> = {
|
|
45
|
+
[K in keyof GetParams<Paths, P> as GetParams<Paths, P>[K] extends never
|
|
46
|
+
? never
|
|
47
|
+
: K]: GetParams<Paths, P>[K];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Perform a typed GET against an OpenAPI backend.
|
|
52
|
+
*
|
|
53
|
+
* @param link The backend `HttpLink`. The base URL and monitoring name are
|
|
54
|
+
* read from it.
|
|
55
|
+
* @param path An OpenAPI path template, e.g. `/v0/stake/{vault}/stats-by-day`.
|
|
56
|
+
* @param params Path and query params, typed from the schema for `path`.
|
|
57
|
+
* @param fallbackName Monitoring name to use when `link` is a bare string.
|
|
58
|
+
*/
|
|
59
|
+
// biome-ignore lint/complexity/useMaxParams: internal helper; the wrappers (fetchBeep / fetchRailwayBackend) are the public surface.
|
|
60
|
+
export function fetchOpenApi<Paths extends AnyPaths, P extends GetPath<Paths>>(
|
|
61
|
+
link: HttpLink,
|
|
62
|
+
path: P,
|
|
63
|
+
params: DefinedParams<Paths, P>,
|
|
64
|
+
fallbackName: string,
|
|
65
|
+
): Promise<GetResponse<Paths, P>> {
|
|
66
|
+
const { path: pathParams, query } = params as {
|
|
67
|
+
path?: Record<string, string | number>;
|
|
68
|
+
query?: Record<string, string | number>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Substitute `{param}` placeholders from the typed path params.
|
|
72
|
+
const pathStr = path as string;
|
|
73
|
+
const resolvedPath = pathStr.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
74
|
+
const value = pathParams?.[key];
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`fetchOpenApi: missing path param "${key}" for "${pathStr}"`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return encodeURIComponent(String(value));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const search = query
|
|
84
|
+
? new URLSearchParams(
|
|
85
|
+
Object.entries(query).map(([k, v]) => [k, String(v)]),
|
|
86
|
+
).toString()
|
|
87
|
+
: "";
|
|
88
|
+
|
|
89
|
+
const url = `${getUriFromLink(link)}${resolvedPath}${search ? `?${search}` : ""}`;
|
|
90
|
+
const name = typeof link === "string" ? fallbackName : link.name;
|
|
91
|
+
|
|
92
|
+
return beraFetchJson<GetResponse<Paths, P>>({ url, name, type: "rest" });
|
|
93
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assert,
|
|
3
|
+
beforeEach,
|
|
4
|
+
describe,
|
|
5
|
+
expect,
|
|
6
|
+
expectTypeOf,
|
|
7
|
+
it,
|
|
8
|
+
vi,
|
|
9
|
+
} from "vitest";
|
|
10
|
+
|
|
11
|
+
import type { HttpLink } from "@berachain/config";
|
|
12
|
+
import { bepolia } from "@berachain/config/bepolia";
|
|
13
|
+
import { mainnet } from "@berachain/config/mainnet";
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
paths as beepPaths,
|
|
17
|
+
StakeEarningResponse,
|
|
18
|
+
StakeStatsByDayResponse,
|
|
19
|
+
ValidatorsResponse,
|
|
20
|
+
} from "@berachain/graphql/beep";
|
|
21
|
+
|
|
22
|
+
import { fetchBeep } from "./fetchBeep";
|
|
23
|
+
import { fetchOpenApi } from "./fetchOpenApi";
|
|
24
|
+
|
|
25
|
+
// Mock the network layer so we can assert exactly what the helpers build and
|
|
26
|
+
// pass through, without hitting a backend.
|
|
27
|
+
const beraFetchJson = vi.fn();
|
|
28
|
+
vi.mock("../../utils/beraFetch", () => ({
|
|
29
|
+
beraFetchJson: (...args: unknown[]) => beraFetchJson(...args),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const BASE = "https://beep.testnet.berachain.com";
|
|
33
|
+
const NAMED_LINK: HttpLink = { name: "Berachain Beep", uri: BASE };
|
|
34
|
+
|
|
35
|
+
const VAULT = "0x1111111111111111111111111111111111111111" as const;
|
|
36
|
+
const OWNER = "0x2222222222222222222222222222222222222222" as const;
|
|
37
|
+
|
|
38
|
+
describe("fetchOpenApi", () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
beraFetchJson.mockReset();
|
|
41
|
+
beraFetchJson.mockResolvedValue(undefined);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("substitutes path params and serializes the query", async () => {
|
|
45
|
+
await fetchOpenApi<beepPaths, "/v0/stake/{vault}/stats-by-day">(
|
|
46
|
+
NAMED_LINK,
|
|
47
|
+
"/v0/stake/{vault}/stats-by-day",
|
|
48
|
+
{ path: { vault: VAULT }, query: { days: "30" } },
|
|
49
|
+
"beep",
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(beraFetchJson).toHaveBeenCalledTimes(1);
|
|
53
|
+
expect(beraFetchJson).toHaveBeenCalledWith({
|
|
54
|
+
url: `${BASE}/v0/stake/${VAULT}/stats-by-day?days=30`,
|
|
55
|
+
name: "Berachain Beep",
|
|
56
|
+
type: "rest",
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("substitutes multiple path params and omits the query when absent", async () => {
|
|
61
|
+
await fetchOpenApi<beepPaths, "/v0/stake/{vault}/earnings/{owner}">(
|
|
62
|
+
NAMED_LINK,
|
|
63
|
+
"/v0/stake/{vault}/earnings/{owner}",
|
|
64
|
+
{ path: { vault: VAULT, owner: OWNER } },
|
|
65
|
+
"beep",
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(beraFetchJson).toHaveBeenCalledWith({
|
|
69
|
+
url: `${BASE}/v0/stake/${VAULT}/earnings/${OWNER}`,
|
|
70
|
+
name: "Berachain Beep",
|
|
71
|
+
type: "rest",
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("url-encodes path param values", async () => {
|
|
76
|
+
// `pubkey` is a free-form string segment; reserved chars must be encoded.
|
|
77
|
+
await fetchOpenApi<beepPaths, "/v0/validators/{pubkey}/incentives">(
|
|
78
|
+
NAMED_LINK,
|
|
79
|
+
"/v0/validators/{pubkey}/incentives",
|
|
80
|
+
{ path: { pubkey: "a/b c" } },
|
|
81
|
+
"beep",
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(beraFetchJson).toHaveBeenCalledWith(
|
|
85
|
+
expect.objectContaining({
|
|
86
|
+
url: `${BASE}/v0/validators/a%2Fb%20c/incentives`,
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("falls back to the provided name for a string link", async () => {
|
|
92
|
+
await fetchOpenApi<beepPaths, "/v0/validators">(
|
|
93
|
+
BASE,
|
|
94
|
+
"/v0/validators",
|
|
95
|
+
{},
|
|
96
|
+
"beep",
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(beraFetchJson).toHaveBeenCalledWith(
|
|
100
|
+
expect.objectContaining({ name: "beep" }),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("throws when a required path param is missing", () => {
|
|
105
|
+
expect(() =>
|
|
106
|
+
fetchOpenApi<beepPaths, "/v0/stake/{vault}/earnings/{owner}">(
|
|
107
|
+
NAMED_LINK,
|
|
108
|
+
"/v0/stake/{vault}/earnings/{owner}",
|
|
109
|
+
// @ts-expect-error — `vault` is required by the schema for this path.
|
|
110
|
+
{ path: { owner: OWNER } },
|
|
111
|
+
"beep",
|
|
112
|
+
),
|
|
113
|
+
).toThrow(/missing path param "vault"/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("returns the response from beraFetchJson", async () => {
|
|
117
|
+
const response = [{ total_assets: "1", total_supply: "2", timestamp: 3 }];
|
|
118
|
+
beraFetchJson.mockResolvedValue(response);
|
|
119
|
+
|
|
120
|
+
const result = await fetchOpenApi<
|
|
121
|
+
beepPaths,
|
|
122
|
+
"/v0/stake/{vault}/stats-by-day"
|
|
123
|
+
>(
|
|
124
|
+
NAMED_LINK,
|
|
125
|
+
"/v0/stake/{vault}/stats-by-day",
|
|
126
|
+
{ path: { vault: VAULT }, query: { days: "30" } },
|
|
127
|
+
"beep",
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(result).toBe(response);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("fetchBeep", () => {
|
|
135
|
+
beforeEach(() => {
|
|
136
|
+
beraFetchJson.mockReset();
|
|
137
|
+
beraFetchJson.mockResolvedValue(undefined);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("resolves the base URL from config.beep", async () => {
|
|
141
|
+
await fetchBeep(
|
|
142
|
+
"/v0/stake/{vault}/stats-by-day",
|
|
143
|
+
{ path: { vault: VAULT }, query: { days: "30" } },
|
|
144
|
+
{ config: bepolia },
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(beraFetchJson).toHaveBeenCalledWith(
|
|
148
|
+
expect.objectContaining({
|
|
149
|
+
url: `${BASE}/v0/stake/${VAULT}/stats-by-day?days=30`,
|
|
150
|
+
name: "Berachain Beep",
|
|
151
|
+
type: "rest",
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("throws when config.beep is not set (e.g. mainnet)", () => {
|
|
157
|
+
expect(() =>
|
|
158
|
+
fetchBeep(
|
|
159
|
+
"/v0/stake/{vault}/earnings/{owner}",
|
|
160
|
+
{ path: { vault: VAULT, owner: OWNER } },
|
|
161
|
+
{ config: mainnet },
|
|
162
|
+
),
|
|
163
|
+
).toThrow(/`beep` backend is not configured/);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Type-only assertions. The bodies are never executed at runtime (they would
|
|
168
|
+
// hit the `beep` not-configured throw); they exist so `tsc` validates inference
|
|
169
|
+
// and the `@ts-expect-error` lines. `expectTypeOf` is purely compile-time.
|
|
170
|
+
describe("fetchBeep types", () => {
|
|
171
|
+
it("infers the response type per path", () => {
|
|
172
|
+
const _assert = () => {
|
|
173
|
+
expectTypeOf(
|
|
174
|
+
fetchBeep("/v0/stake/{vault}/stats-by-day", {
|
|
175
|
+
path: { vault: VAULT },
|
|
176
|
+
query: { days: "30" },
|
|
177
|
+
}),
|
|
178
|
+
).resolves.toEqualTypeOf<StakeStatsByDayResponse>();
|
|
179
|
+
|
|
180
|
+
expectTypeOf(
|
|
181
|
+
fetchBeep("/v0/stake/{vault}/earnings/{owner}", {
|
|
182
|
+
path: { vault: VAULT, owner: OWNER },
|
|
183
|
+
}),
|
|
184
|
+
).resolves.toEqualTypeOf<StakeEarningResponse>();
|
|
185
|
+
|
|
186
|
+
expectTypeOf(
|
|
187
|
+
fetchBeep("/v0/validators", {}),
|
|
188
|
+
).resolves.toEqualTypeOf<ValidatorsResponse>();
|
|
189
|
+
};
|
|
190
|
+
assert.ok(_assert);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("rejects unknown paths", () => {
|
|
194
|
+
const _assert = () => {
|
|
195
|
+
// @ts-expect-error — not a path in the beep schema.
|
|
196
|
+
fetchBeep("/v0/not/a/real/path", { path: {} });
|
|
197
|
+
};
|
|
198
|
+
assert.ok(_assert);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("rejects unknown path params", () => {
|
|
202
|
+
const _assert = () => {
|
|
203
|
+
fetchBeep("/v0/stake/{vault}/stats-by-day", {
|
|
204
|
+
// @ts-expect-error — `owner` is not a param of stats-by-day.
|
|
205
|
+
path: { vault: VAULT, owner: OWNER },
|
|
206
|
+
query: { days: "30" },
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
assert.ok(_assert);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("constrains query values to the schema enum", () => {
|
|
213
|
+
const _assert = () => {
|
|
214
|
+
fetchBeep("/v0/stake/{vault}/stats-by-day", {
|
|
215
|
+
path: { vault: VAULT },
|
|
216
|
+
// @ts-expect-error — `7` is not an allowed `days` value.
|
|
217
|
+
query: { days: "7" },
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
assert.ok(_assert);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { paths } from "@berachain/graphql/api";
|
|
2
|
+
|
|
3
|
+
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
4
|
+
import {
|
|
5
|
+
type DefinedParams,
|
|
6
|
+
fetchOpenApi,
|
|
7
|
+
type GetPath,
|
|
8
|
+
type GetResponse,
|
|
9
|
+
} from "./fetchOpenApi";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Typed GET against the legacy Railway backend.
|
|
13
|
+
*
|
|
14
|
+
* The `path`, its path/query params and the response are all type-checked
|
|
15
|
+
* against the Railway schema (`@berachain/graphql/api`). The base URL is
|
|
16
|
+
* resolved from `config.backend`.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated The Railway backend is being replaced by beep; prefer
|
|
19
|
+
* {@link fetchBeep} where `config.beep` is available.
|
|
20
|
+
*/
|
|
21
|
+
export function fetchRailwayBackend<P extends GetPath<paths>>(
|
|
22
|
+
path: P,
|
|
23
|
+
params: DefinedParams<paths, P>,
|
|
24
|
+
args: BeraJS.BaseFunctionArgs = {},
|
|
25
|
+
): Promise<GetResponse<paths, P>> {
|
|
26
|
+
const { config } = parseBaseArgs(args);
|
|
27
|
+
|
|
28
|
+
return fetchOpenApi<paths, P>(
|
|
29
|
+
config.backend,
|
|
30
|
+
path,
|
|
31
|
+
params,
|
|
32
|
+
"backend-railway",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -80,28 +80,68 @@ function getClient(
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Browser-reachable Apollo client factory for `api` and Bend's `whisk`
|
|
85
|
+
* endpoints. Subgraph clients (honey/pol) are server-only; browser data
|
|
86
|
+
* access goes through the typed `/api/honey/*` and `/api/pol/*` REST
|
|
87
|
+
* endpoints. Same auth shape as bend.whiskApi — non-public env values only
|
|
88
|
+
* resolve server-side.
|
|
89
|
+
*/
|
|
90
|
+
type GraphqlClient = "api" | "bend.whisk" | "honey.subgraph" | "pol.subgraph";
|
|
91
|
+
|
|
92
|
+
const SUBGRAPH_CLIENTS = [
|
|
93
|
+
"honey.subgraph",
|
|
94
|
+
"pol.subgraph",
|
|
95
|
+
] as const satisfies readonly GraphqlClient[];
|
|
96
|
+
|
|
97
|
+
type SubgraphClient = (typeof SUBGRAPH_CLIENTS)[number];
|
|
98
|
+
|
|
99
|
+
function isSubgraphClient(name: GraphqlClient): name is SubgraphClient {
|
|
100
|
+
return SUBGRAPH_CLIENTS.includes(name as SubgraphClient);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const clientCache = new Map<string, BeraApolloClient>();
|
|
104
|
+
|
|
105
|
+
function store(
|
|
106
|
+
cacheKey: string | null,
|
|
107
|
+
client: BeraApolloClient,
|
|
108
|
+
): BeraApolloClient {
|
|
109
|
+
if (cacheKey) clientCache.set(cacheKey, client);
|
|
110
|
+
return client;
|
|
111
|
+
}
|
|
91
112
|
|
|
92
113
|
export function getApolloClient(
|
|
93
114
|
clientName: GraphqlClient,
|
|
94
115
|
{ ...args }: BeraJS.BaseFunctionArgs,
|
|
95
116
|
): BeraApolloClient {
|
|
96
|
-
|
|
117
|
+
if (typeof window !== "undefined" && isSubgraphClient(clientName)) {
|
|
118
|
+
throw new BeraError({
|
|
119
|
+
message: "Subgraph Apollo client is server-only",
|
|
120
|
+
level: "error",
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const { config, chainId } = parseBaseArgs(args);
|
|
125
|
+
|
|
126
|
+
// Caller-supplied configs are treated as unique (may override URLs/headers),
|
|
127
|
+
// so they bypass the cache. The common path (chainId-only) is memoized.
|
|
128
|
+
const cacheKey = args.config ? null : `${chainId}:${clientName}`;
|
|
129
|
+
|
|
130
|
+
if (cacheKey) {
|
|
131
|
+
const cached = clientCache.get(cacheKey);
|
|
132
|
+
if (cached) return cached;
|
|
133
|
+
}
|
|
97
134
|
|
|
98
135
|
switch (clientName) {
|
|
99
136
|
case "api":
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
137
|
+
return store(
|
|
138
|
+
cacheKey,
|
|
139
|
+
getClient(applyStellateClientName(config.api), {
|
|
140
|
+
inMemoryCacheOptions: {
|
|
141
|
+
possibleTypes: apiResults.possibleTypes,
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
105
145
|
|
|
106
146
|
case "bend.whisk":
|
|
107
147
|
if (!config.bend.whiskApi) {
|
|
@@ -110,17 +150,12 @@ export function getApolloClient(
|
|
|
110
150
|
level: "error",
|
|
111
151
|
});
|
|
112
152
|
}
|
|
113
|
-
return getClient(config.bend.whiskApi);
|
|
153
|
+
return store(cacheKey, getClient(config.bend.whiskApi));
|
|
114
154
|
|
|
115
155
|
case "honey.subgraph":
|
|
116
|
-
return getClient(config.honey.subgraph);
|
|
156
|
+
return store(cacheKey, getClient(config.honey.subgraph));
|
|
157
|
+
|
|
117
158
|
case "pol.subgraph":
|
|
118
|
-
return getClient(config.pol.subgraph);
|
|
119
|
-
case "pol.fees":
|
|
120
|
-
return getClient(config.pol.feesSubgraph);
|
|
121
|
-
case "governance.subgraph":
|
|
122
|
-
return getClient(config.governance.subgraph);
|
|
123
|
-
case "bex.subgraph":
|
|
124
|
-
return getClient(config.bex.subgraph);
|
|
159
|
+
return store(cacheKey, getClient(config.pol.subgraph));
|
|
125
160
|
}
|
|
126
161
|
}
|