@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.
Files changed (254) hide show
  1. package/dist/{BeraError-_mQdkanr.d.cts → BeraError-7-A5JYy_.d.ts} +31 -2
  2. package/dist/{HoneyConfigProvider-DVP_9KZn.d.ts → HoneyConfigProvider-Dkj-_a5x.d.ts} +1 -1
  3. package/dist/{RequestError-BRIiJgHk.d.ts → RequestError-DBOIV65x.d.ts} +1 -1
  4. package/dist/abi/exports.mjs +4452 -2
  5. package/dist/actions/clients/exports.d.ts +78 -0
  6. package/dist/actions/clients/exports.mjs +21 -0
  7. package/dist/actions/exports.d.ts +154 -207
  8. package/dist/actions/exports.mjs +853 -2
  9. package/dist/actions/governance/exports.d.ts +140 -0
  10. package/dist/actions/governance/exports.mjs +226 -0
  11. package/dist/actions/server/exports.d.ts +13 -0
  12. package/dist/actions/server/exports.mjs +27 -0
  13. package/dist/chunk-3JJLQ2JX.mjs +211 -0
  14. package/dist/chunk-7YVNSDXG.mjs +86 -0
  15. package/dist/chunk-AUOPN6NK.mjs +96 -0
  16. package/dist/chunk-BGMRHTBQ.mjs +23 -0
  17. package/dist/chunk-CDK4YV3D.mjs +571 -0
  18. package/dist/chunk-DKMAIU74.mjs +62 -0
  19. package/dist/chunk-DQRH5VE3.mjs +25 -0
  20. package/dist/chunk-E7YFXBBQ.mjs +349 -0
  21. package/dist/chunk-GUURQAME.mjs +326 -0
  22. package/dist/chunk-GY6B3PD5.mjs +89 -0
  23. package/dist/chunk-HQCOU6GY.mjs +243 -0
  24. package/dist/chunk-HYDP32P6.mjs +135 -0
  25. package/dist/chunk-IXIBY5FP.mjs +80 -0
  26. package/dist/chunk-KHXJDYA4.mjs +1776 -0
  27. package/dist/chunk-NBYLMO2L.mjs +14 -0
  28. package/dist/chunk-O2NQFKJK.mjs +170 -0
  29. package/dist/chunk-P5WXXULM.mjs +54 -0
  30. package/dist/chunk-QBBOWFMH.mjs +4129 -0
  31. package/dist/chunk-QVHEM4BG.mjs +35 -0
  32. package/dist/chunk-SGIJVHZO.mjs +12 -0
  33. package/dist/chunk-SZ5C44L5.mjs +35 -0
  34. package/dist/chunk-WNBWX23Q.mjs +426 -0
  35. package/dist/chunk-Y6THHG77.mjs +126 -0
  36. package/dist/chunk-ZLTMIFCZ.mjs +165 -0
  37. package/dist/contexts/exports.d.ts +2 -2
  38. package/dist/contexts/exports.mjs +85 -2
  39. package/dist/enum/exports.d.ts +1 -1
  40. package/dist/enum/exports.mjs +46 -2
  41. package/dist/enum/governance/exports.d.ts +60 -0
  42. package/dist/enum/governance/exports.mjs +14 -0
  43. package/dist/errors/exports.d.ts +4 -3
  44. package/dist/errors/exports.mjs +48 -2
  45. package/dist/getApolloClient-BcUTGFUb.d.ts +40 -0
  46. package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-DphU3qhE.d.ts} +2 -2
  47. package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
  48. package/dist/hooks/exports.d.ts +83 -226
  49. package/dist/hooks/exports.mjs +7463 -4
  50. package/dist/hooks/governance/exports.d.ts +181 -0
  51. package/dist/hooks/governance/exports.mjs +888 -0
  52. package/dist/pol.d-Dw5SQcRX.d.ts +153 -0
  53. package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
  54. package/dist/types/exports.d.ts +9 -9
  55. package/dist/types/exports.mjs +0 -1
  56. package/dist/types/governance/exports.d.ts +109 -0
  57. package/dist/types/governance/exports.mjs +0 -0
  58. package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
  59. package/dist/utils/exports.d.ts +15 -6
  60. package/dist/utils/exports.mjs +827 -2
  61. package/package.json +49 -13
  62. package/src/actions/__test/transports.ts +61 -0
  63. package/src/actions/clients/exports.ts +7 -0
  64. package/src/actions/clients/fetchBeep.ts +34 -0
  65. package/src/actions/clients/fetchOpenApi.ts +93 -0
  66. package/src/actions/clients/fetchOpenApi.unit.test.ts +223 -0
  67. package/src/actions/clients/fetchRailwayBackend.ts +34 -0
  68. package/src/actions/clients/getApolloClient.ts +58 -23
  69. package/src/actions/clients/getEnsoClient.ts +20 -9
  70. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  71. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  72. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  73. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  74. package/src/actions/enso/getEnsoUserTokensWithBalances.ts +18 -0
  75. package/src/actions/exports.ts +5 -9
  76. package/src/actions/governance/exports.ts +9 -0
  77. package/src/actions/governance/getAllProposals.ts +10 -65
  78. package/src/actions/governance/getProposalDetails.ts +6 -33
  79. package/src/actions/governance/getProposalVotes.ts +8 -15
  80. package/src/actions/honey/getChartData.ts +27 -21
  81. package/src/actions/honey/getHoney24hVolume.ts +19 -22
  82. package/src/actions/honey/getPythLatestPrices.ts +7 -0
  83. package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
  84. package/src/actions/pol/getAutoclaimedIncentives.ts +41 -0
  85. package/src/actions/pol/getAutoclaimedIncentivesTxHash.ts +41 -0
  86. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  87. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +28 -0
  88. package/src/actions/pol/getEarnedStakedBeraVault.ts +20 -20
  89. package/src/actions/pol/getGlobalData.ts +1 -0
  90. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  91. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  92. package/src/actions/pol/getRewardVaults.ts +4 -4
  93. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  94. package/src/actions/pol/getStakingDailyAssets.ts +18 -17
  95. package/src/actions/server/exports.ts +1 -0
  96. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  97. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  98. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  99. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  100. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  101. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  102. package/src/actions/validators/utils/getValidatorBoostApy.ts +1 -1
  103. package/src/enum/contracts.ts +1 -0
  104. package/src/enum/exports.ts +0 -1
  105. package/src/enum/governance/exports.ts +1 -0
  106. package/src/errors/BeraError.ts +47 -7
  107. package/src/errors/BeraTracing.unit.test.ts +65 -0
  108. package/src/errors/RequestError.ts +25 -4
  109. package/src/errors/RequestError.unit.test.ts +55 -0
  110. package/src/errors/errorMap.ts +8 -0
  111. package/src/errors/exports.ts +5 -0
  112. package/src/errors/getRevertReason.integration.test.ts +3 -3
  113. package/src/errors/spanStatus.ts +78 -0
  114. package/src/errors/spanStatus.unit.test.ts +62 -0
  115. package/src/hooks/dex/useCreatePool.ts +1 -88
  116. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  117. package/src/hooks/dex/usePriceImpact.ts +12 -5
  118. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  119. package/src/hooks/enso/useBendMultiply.ts +9 -1
  120. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  121. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  122. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  123. package/src/hooks/exports.ts +3 -15
  124. package/src/hooks/governance/exports.ts +14 -0
  125. package/src/hooks/pol/useAutoclaimedIncentives.ts +40 -0
  126. package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +45 -0
  127. package/src/hooks/pol/useStakedAPR.ts +2 -2
  128. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  129. package/src/hooks/validators/useValidator.ts +6 -8
  130. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  131. package/src/types/bribe-boost.d.ts +19 -0
  132. package/src/types/exports.ts +0 -1
  133. package/src/types/governance/exports.ts +1 -0
  134. package/src/utils/beraFetch.ts +9 -3
  135. package/src/utils/exports.ts +1 -0
  136. package/src/utils/getServerSideClient.ts +4 -2
  137. package/src/utils/polyfillAbortSignalAny.ts +53 -0
  138. package/src/utils/polyfillAbortSignalAny.unit.test.ts +81 -0
  139. package/src/utils/sanitizeRpcUrl.ts +22 -0
  140. package/src/utils/tracedTransport.ts +35 -0
  141. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  142. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  143. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  144. package/dist/RequestError-DSUzJ1Iy.d.cts +0 -144
  145. package/dist/abi/exports.cjs +0 -2
  146. package/dist/abi/exports.cjs.map +0 -1
  147. package/dist/abi/exports.d.cts +0 -6574
  148. package/dist/abi/exports.mjs.map +0 -1
  149. package/dist/actions/exports.cjs +0 -2
  150. package/dist/actions/exports.cjs.map +0 -1
  151. package/dist/actions/exports.d.cts +0 -1650
  152. package/dist/actions/exports.mjs.map +0 -1
  153. package/dist/chunk-45HIEVNI.cjs +0 -4
  154. package/dist/chunk-45HIEVNI.cjs.map +0 -1
  155. package/dist/chunk-47ILYVHC.mjs +0 -2
  156. package/dist/chunk-47ILYVHC.mjs.map +0 -1
  157. package/dist/chunk-575OK77P.mjs +0 -2
  158. package/dist/chunk-575OK77P.mjs.map +0 -1
  159. package/dist/chunk-5NVZG5N6.mjs +0 -2
  160. package/dist/chunk-5NVZG5N6.mjs.map +0 -1
  161. package/dist/chunk-6DIA6PXV.cjs +0 -2
  162. package/dist/chunk-6DIA6PXV.cjs.map +0 -1
  163. package/dist/chunk-6JJIZCVY.cjs +0 -2
  164. package/dist/chunk-6JJIZCVY.cjs.map +0 -1
  165. package/dist/chunk-7F72ZH4Q.mjs +0 -2
  166. package/dist/chunk-7F72ZH4Q.mjs.map +0 -1
  167. package/dist/chunk-AUA42YIG.mjs +0 -4
  168. package/dist/chunk-AUA42YIG.mjs.map +0 -1
  169. package/dist/chunk-BC2WX6O6.cjs +0 -2
  170. package/dist/chunk-BC2WX6O6.cjs.map +0 -1
  171. package/dist/chunk-CJOZC5Z2.cjs +0 -2
  172. package/dist/chunk-CJOZC5Z2.cjs.map +0 -1
  173. package/dist/chunk-D6L7LTA2.cjs +0 -2
  174. package/dist/chunk-D6L7LTA2.cjs.map +0 -1
  175. package/dist/chunk-DDEQFR3M.cjs +0 -2
  176. package/dist/chunk-DDEQFR3M.cjs.map +0 -1
  177. package/dist/chunk-GXV2JA36.mjs +0 -2
  178. package/dist/chunk-GXV2JA36.mjs.map +0 -1
  179. package/dist/chunk-ISYNEDET.mjs +0 -2
  180. package/dist/chunk-ISYNEDET.mjs.map +0 -1
  181. package/dist/chunk-JDDRTHFG.mjs +0 -2
  182. package/dist/chunk-JDDRTHFG.mjs.map +0 -1
  183. package/dist/chunk-JDZGYU5T.mjs +0 -2
  184. package/dist/chunk-JDZGYU5T.mjs.map +0 -1
  185. package/dist/chunk-LVOXBZMA.cjs +0 -2
  186. package/dist/chunk-LVOXBZMA.cjs.map +0 -1
  187. package/dist/chunk-MK5NS5B5.mjs +0 -2
  188. package/dist/chunk-MK5NS5B5.mjs.map +0 -1
  189. package/dist/chunk-NAXAZJJY.mjs +0 -2
  190. package/dist/chunk-NAXAZJJY.mjs.map +0 -1
  191. package/dist/chunk-NLVWRMGD.mjs +0 -2
  192. package/dist/chunk-NLVWRMGD.mjs.map +0 -1
  193. package/dist/chunk-OGBD5YOG.mjs +0 -2
  194. package/dist/chunk-OGBD5YOG.mjs.map +0 -1
  195. package/dist/chunk-OGJMSGB2.mjs +0 -2
  196. package/dist/chunk-OGJMSGB2.mjs.map +0 -1
  197. package/dist/chunk-OIYXOKTT.cjs +0 -2
  198. package/dist/chunk-OIYXOKTT.cjs.map +0 -1
  199. package/dist/chunk-OUD27MU7.cjs +0 -2
  200. package/dist/chunk-OUD27MU7.cjs.map +0 -1
  201. package/dist/chunk-PRLVZIKD.mjs +0 -2
  202. package/dist/chunk-PRLVZIKD.mjs.map +0 -1
  203. package/dist/chunk-Q2SNRLW3.cjs +0 -2
  204. package/dist/chunk-Q2SNRLW3.cjs.map +0 -1
  205. package/dist/chunk-REWME3FY.cjs +0 -2
  206. package/dist/chunk-REWME3FY.cjs.map +0 -1
  207. package/dist/chunk-RJN36GBU.mjs +0 -2
  208. package/dist/chunk-RJN36GBU.mjs.map +0 -1
  209. package/dist/chunk-RWOICHRW.cjs +0 -2
  210. package/dist/chunk-RWOICHRW.cjs.map +0 -1
  211. package/dist/chunk-S4CDSVLK.cjs +0 -2
  212. package/dist/chunk-S4CDSVLK.cjs.map +0 -1
  213. package/dist/chunk-SFEULGSX.cjs +0 -2
  214. package/dist/chunk-SFEULGSX.cjs.map +0 -1
  215. package/dist/chunk-WBTS6KFG.mjs +0 -2
  216. package/dist/chunk-WBTS6KFG.mjs.map +0 -1
  217. package/dist/chunk-WRFDB3QJ.cjs +0 -2
  218. package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
  219. package/dist/chunk-XNJLSA6P.cjs +0 -2
  220. package/dist/chunk-XNJLSA6P.cjs.map +0 -1
  221. package/dist/contexts/exports.cjs +0 -2
  222. package/dist/contexts/exports.cjs.map +0 -1
  223. package/dist/contexts/exports.d.cts +0 -66
  224. package/dist/contexts/exports.mjs.map +0 -1
  225. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  226. package/dist/dex-C_BB0b0O.d.cts +0 -37
  227. package/dist/enum/exports.cjs +0 -2
  228. package/dist/enum/exports.cjs.map +0 -1
  229. package/dist/enum/exports.d.cts +0 -23
  230. package/dist/enum/exports.mjs.map +0 -1
  231. package/dist/errors/exports.cjs +0 -2
  232. package/dist/errors/exports.cjs.map +0 -1
  233. package/dist/errors/exports.d.cts +0 -327
  234. package/dist/errors/exports.mjs.map +0 -1
  235. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  236. package/dist/global.d-B7IeayVX.d.cts +0 -474
  237. package/dist/honey-CYm0RWf4.d.cts +0 -14
  238. package/dist/hooks/exports.cjs +0 -4
  239. package/dist/hooks/exports.cjs.map +0 -1
  240. package/dist/hooks/exports.d.cts +0 -1734
  241. package/dist/hooks/exports.mjs.map +0 -1
  242. package/dist/polling-BKnyavLI.d.cts +0 -8
  243. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  244. package/dist/types/exports.cjs +0 -1
  245. package/dist/types/exports.cjs.map +0 -1
  246. package/dist/types/exports.d.cts +0 -90
  247. package/dist/types/exports.mjs.map +0 -1
  248. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  249. package/dist/utils/exports.cjs +0 -2
  250. package/dist/utils/exports.cjs.map +0 -1
  251. package/dist/utils/exports.d.cts +0 -420
  252. package/dist/utils/exports.mjs.map +0 -1
  253. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  254. 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.8-beta.9",
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.4",
15
- "@berachain/abis": "0.1.0",
16
- "@berachain/config": "0.1.8",
17
- "@berachain/graphql": "0.4.10-beta.2",
18
- "@ensofinance/sdk": "2.0.12",
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.1.6",
26
- "@types/react": "19.1.8",
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
- "module": "./dist/*/exports.mjs",
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,7 @@
1
+ export { fetchBeep } from "./fetchBeep";
2
+ export { fetchOpenApi } from "./fetchOpenApi";
3
+ export { fetchRailwayBackend } from "./fetchRailwayBackend";
4
+ export {
5
+ getApolloClient,
6
+ gql,
7
+ } from "./getApolloClient";
@@ -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
- type GraphqlClient =
84
- | "honey.subgraph"
85
- | "pol.subgraph"
86
- | "pol.fees"
87
- | "governance.subgraph"
88
- | "bex.subgraph"
89
- | "api"
90
- | "bend.whisk";
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
- const { config } = parseBaseArgs(args);
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 getClient(applyStellateClientName(config.api), {
101
- inMemoryCacheOptions: {
102
- possibleTypes: apiResults.possibleTypes,
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
  }