@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
@@ -8,17 +8,28 @@ const isProduction =
8
8
  process.env.NODE_ENV !== "development" && process.env.NODE_ENV !== "test";
9
9
 
10
10
  export function getEnsoClient({
11
- useProxy = isProduction,
11
+ baseURL,
12
12
  ...args
13
- }: BeraJS.BaseFunctionArgs & { useProxy?: boolean } = {}) {
13
+ }: BeraJS.BaseFunctionArgs & {
14
+ /**
15
+ * Override the Enso API base URL.
16
+ *
17
+ * - Omit (or pass `undefined`) → external proxy in production, direct in dev/test
18
+ * - Pass a URL string (e.g. `"/api/enso"`) → route through that proxy
19
+ */
20
+ baseURL?: string;
21
+ } = {}) {
14
22
  const { config } = parseBaseArgs(args);
23
+ const resolvedBaseURL =
24
+ baseURL !== undefined
25
+ ? baseURL
26
+ : isProduction
27
+ ? `${config.bex.aggregatorsProxyUrl}/enso/api/v1/`
28
+ : undefined;
29
+
15
30
  return new EnsoClient({
16
- baseURL: useProxy
17
- ? `${config.bex.aggregatorsProxyUrl}/enso/api/v1/`
18
- : undefined,
19
- apiKey: useProxy
20
- ? // no API key since proxy has CORS for .berachain.com domains
21
- ""
22
- : appConfig.apiKeys.public.enso,
31
+ baseURL: resolvedBaseURL,
32
+ // no API key when routing through a proxy — the proxy handles auth
33
+ apiKey: resolvedBaseURL ? "" : appConfig.apiKeys.public.enso,
23
34
  });
24
35
  }
@@ -49,25 +49,35 @@ class EnsoAggregator extends BaseAggregator {
49
49
  aggregatorsFeeBps,
50
50
  );
51
51
 
52
+ // Enso rejects a zero-address `refundReceiver` with 400 Bad Request, so
53
+ // when no wallet is connected (or the account hasn't hydrated yet) fall
54
+ // back to the executor. Only matters for quotes — on execution the user's
55
+ // real address is always set.
56
+ const refundReceiver =
57
+ account === zeroAddress
58
+ ? this.config.bex.aggregatorsRouterExecutor
59
+ : account;
60
+
61
+ const params = new URLSearchParams({
62
+ fromAddress: this.config.bex.aggregatorsRouterExecutor,
63
+ receiver: this.config.bex.aggregatorsRouterExecutor,
64
+ spender: this.config.bex.aggregatorsRouterExecutor,
65
+ amountIn: inputAmountAfterFees,
66
+ tokenIn: tokenInAddress,
67
+ tokenOut: tokenOutAddress,
68
+ chainId: ChainId.MAINNET.toString(),
69
+ slippage: (Number(slippage) * 100).toString(),
70
+ refundReceiver,
71
+ });
72
+
73
+ // Build the URL via string concat — the `new URL(relative)` constructor
74
+ // throws on relative paths like `/api/aggregators?...`, which silently
75
+ // breaks the Vercel-proxy path.
52
76
  this.url = proxyAggregatorsThroughVercel
53
- ? `/api/aggregators?aggregator=enso`
54
- : `${this.config.bex.aggregatorsProxyUrl}/enso/api/v1/shortcuts/route?`;
77
+ ? `/api/aggregators?aggregator=enso&${params.toString()}`
78
+ : `${this.config.bex.aggregatorsProxyUrl}/enso/api/v1/shortcuts/route?${params.toString()}`;
55
79
 
56
- const url = new URL(this.url);
57
- url.searchParams.set(
58
- "fromAddress",
59
- this.config.bex.aggregatorsRouterExecutor,
60
- );
61
- url.searchParams.set("receiver", this.config.bex.aggregatorsRouterExecutor);
62
- url.searchParams.set("spender", this.config.bex.aggregatorsRouterExecutor);
63
- url.searchParams.set("amountIn", inputAmountAfterFees);
64
- url.searchParams.set("tokenIn", tokenInAddress);
65
- url.searchParams.set("tokenOut", tokenOutAddress);
66
- url.searchParams.set("chainId", ChainId.MAINNET.toString());
67
- url.searchParams.set("slippage", (Number(slippage) * 100).toString());
68
- url.searchParams.set("refundReceiver", account);
69
-
70
- const response = await this.fetch(url);
80
+ const response = await this.fetch(this.url);
71
81
 
72
82
  const quote = await response.json();
73
83
 
@@ -39,7 +39,7 @@ class EnsoErc4626Aggregator extends BaseAggregator {
39
39
  assertAddress(account, "account");
40
40
 
41
41
  const ensoClient = getEnsoClient({
42
- useProxy: !proxyAggregatorsThroughVercel,
42
+ baseURL: proxyAggregatorsThroughVercel ? "/api/enso" : undefined,
43
43
  });
44
44
 
45
45
  if (tokenIn.address === zeroAddress) tokenIn.address = ethAddress;
@@ -148,7 +148,7 @@ class EnsoErc4626Aggregator extends BaseAggregator {
148
148
 
149
149
  const amountOut =
150
150
  // @ts-expect-error enso has not typed this but is returned sometimes from API.
151
- bundle.minAmountsOut[tokenOutAddress] ??
151
+ bundle.minAmountsOut?.[tokenOutAddress] ??
152
152
  bundle.amountsOut[tokenOutAddress] ??
153
153
  "0";
154
154
 
@@ -41,20 +41,23 @@ class KyberSwapAggregator extends BaseAggregator {
41
41
  aggregatorsFeeBps,
42
42
  );
43
43
 
44
- this.url = proxyAggregatorsThroughVercel
45
- ? `/api/aggregators?aggregator=kyberswapRoutes`
46
- : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/routes`;
44
+ const params = new URLSearchParams({
45
+ tokenIn: tokenInAddress,
46
+ tokenOut: tokenOutAddress,
47
+ amountIn: inputAmountAfterFees,
48
+ slippageTolerance: (slippage / 100).toString(),
49
+ to: this.config.bex.aggregatorsRouterExecutor,
50
+ clientData: JSON.stringify({ source: "berachain" }),
51
+ });
47
52
 
48
- const url = new URL(this.url);
49
- // First, get route quote
50
- url.searchParams.set("tokenIn", tokenInAddress);
51
- url.searchParams.set("tokenOut", tokenOutAddress);
52
- url.searchParams.set("amountIn", inputAmountAfterFees);
53
- url.searchParams.set("slippageTolerance", (slippage / 100).toString());
54
- url.searchParams.set("to", this.config.bex.aggregatorsRouterExecutor);
55
- url.searchParams.set("clientData", JSON.stringify({ source: "berachain" }));
53
+ // Build URLs via string concat — the `new URL(relative)` constructor
54
+ // throws on relative paths like `/api/aggregators?...`, which silently
55
+ // breaks the Vercel-proxy path.
56
+ this.url = proxyAggregatorsThroughVercel
57
+ ? `/api/aggregators?aggregator=kyberswapRoutes&${params.toString()}`
58
+ : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/routes?${params.toString()}`;
56
59
 
57
- const routeResponse = await this.fetch(url);
60
+ const routeResponse = await this.fetch(this.url);
58
61
 
59
62
  const routeData = await routeResponse.json();
60
63
  const formattedQuote = {
@@ -79,17 +82,9 @@ class KyberSwapAggregator extends BaseAggregator {
79
82
  source: "berachain",
80
83
  };
81
84
 
82
- const params = url.searchParams.entries();
83
-
84
- const buildUrl = new URL(
85
- proxyAggregatorsThroughVercel
86
- ? `/api/aggregators?aggregator=kyberswapBuild`
87
- : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/route/build`,
88
- );
89
-
90
- for (const [key, value] of params) {
91
- buildUrl.searchParams.set(key, value);
92
- }
85
+ const buildUrl = proxyAggregatorsThroughVercel
86
+ ? `/api/aggregators?aggregator=kyberswapBuild&${params.toString()}`
87
+ : `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/route/build?${params.toString()}`;
93
88
 
94
89
  const buildRouteResponse = await this.fetch(buildUrl, {
95
90
  method: "POST",
@@ -9,15 +9,12 @@ import {
9
9
  } from "vitest";
10
10
 
11
11
  import { appConfig } from "@berachain/config/internal";
12
- import {
13
- defaultChain,
14
- externalChains,
15
- transports,
16
- } from "@berachain/config/internal/wagmi";
12
+ import { defaultChain, externalChains } from "@berachain/config/internal/wagmi";
17
13
 
18
14
  import { getConfig } from "@berachain/wagmi/config";
19
15
 
20
16
  import { BeraMonitoring } from "../../../errors/BeraMonitoring";
17
+ import { testTransports } from "../../__test/transports";
21
18
  import { getEnsoClient } from "../../clients/getEnsoClient";
22
19
  import { getEnsoUserTokensWithBalances } from "../getEnsoUserTokensWithBalances";
23
20
 
@@ -41,7 +38,7 @@ describe("getEnsoUserTokensWithBalances", () => {
41
38
  const ensoClient = getEnsoClient();
42
39
 
43
40
  const beraWagmiConfig = getConfig({
44
- transports,
41
+ transports: testTransports,
45
42
  defaultChain,
46
43
  chains: externalChains,
47
44
  thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
@@ -31,6 +31,24 @@ export async function getEnsoUserTokensWithBalances({
31
31
  eoaAddress: account,
32
32
  });
33
33
 
34
+ // The Enso SDK can return a non-array (e.g. an error object) on a malformed
35
+ // or empty response. Guard before mapping to avoid the unactionable minified
36
+ // "(...).map is not a function" crash — but still report it as a typed,
37
+ // stably-grouped warning so we don't silently swallow an Enso API problem
38
+ // (an empty portfolio would otherwise look like "user has no tokens").
39
+ if (!Array.isArray(ensoBalances)) {
40
+ BeraMonitoring.captureException(
41
+ new InvalidArgumentError({
42
+ property: "ensoBalances",
43
+ value: ensoBalances,
44
+ expected: "BalanceToken[]",
45
+ chainId: typeof chainId === "number" ? chainId : undefined,
46
+ extra: { account, chainId },
47
+ }),
48
+ );
49
+ return [];
50
+ }
51
+
34
52
  const tokens: BalanceToken[] = ensoBalances.map(
35
53
  (balance) =>
36
54
  ({
@@ -25,15 +25,6 @@ export * from "./dex/getPoolHistoricalData";
25
25
  export * from "./dex/getPoolPausedState";
26
26
  export * from "./dex/getPoolWithState";
27
27
  export * from "./dex/getVaultPausedState";
28
- export * from "./governance/checkProposalField";
29
- export * from "./governance/computeActualStatus";
30
- export * from "./governance/getAllProposals";
31
- export * from "./governance/getBodyErrors";
32
- export * from "./governance/getDecodedFunctionData";
33
- export * from "./governance/getProposalDetails";
34
- export * from "./governance/getProposalFromTx";
35
- export * from "./governance/getProposalVotes";
36
- export * from "./governance/parseProposalBody";
37
28
  export * from "./honey/getChartData";
38
29
  export * from "./honey/getCollateralWeights";
39
30
  export * from "./honey/getGlobalCapLimit";
@@ -51,10 +42,15 @@ export * from "./honey/getSwapPayload";
51
42
  export * from "./honey/isBadCollateralAsset";
52
43
  export * from "./honey/isBasketModeEnabled";
53
44
  export * from "./misc/getBlockTimestamp";
45
+ export * from "./pol/getAutoclaimedIncentives";
46
+ export * from "./pol/getAutoclaimedIncentivesTxHash";
47
+ export * from "./pol/getBeraTokenTotalSupply";
54
48
  export * from "./pol/getBgtAprSimulation";
49
+ export * from "./pol/getBgtIncentiveDistributorPaused";
55
50
  export * from "./pol/getBlockTime";
56
51
  export * from "./pol/getEarnedStakedBeraVault";
57
52
  export * from "./pol/getGlobalData";
53
+ export * from "./pol/getHeroEarnVaults";
58
54
  export * from "./pol/getIncentiveFeeClaimStats";
59
55
  export * from "./pol/getLSTStakeConfig";
60
56
  export * from "./pol/getMarkets";
@@ -0,0 +1,9 @@
1
+ export * from "./checkProposalField";
2
+ export * from "./computeActualStatus";
3
+ export * from "./getAllProposals";
4
+ export * from "./getBodyErrors";
5
+ export * from "./getDecodedFunctionData";
6
+ export * from "./getProposalDetails";
7
+ export * from "./getProposalFromTx";
8
+ export * from "./getProposalVotes";
9
+ export * from "./parseProposalBody";
@@ -1,19 +1,10 @@
1
- import {
2
- GetProposals,
3
- type GetProposalsQuery,
4
- type GetProposalsQueryVariables,
5
- type OrderDirection,
6
- type Proposal_Filter,
7
- type Proposal_OrderBy,
8
- type ProposalSelectionFragment,
9
- SearchProposals,
10
- type SearchProposalsQuery,
11
- type SearchProposalsQueryVariables,
1
+ import type {
2
+ OrderDirection,
3
+ Proposal_Filter,
4
+ Proposal_OrderBy,
5
+ ProposalSelectionFragment,
12
6
  } from "@berachain/graphql/governance";
13
7
 
14
- import { getApolloClient } from "../clients/getApolloClient";
15
- import { computeActualStatus } from "./computeActualStatus";
16
-
17
8
  export type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
18
9
  /** Subgraph filter applied to the proposals query */
19
10
  where: Proposal_Filter;
@@ -28,55 +19,9 @@ export type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
28
19
  };
29
20
 
30
21
  /** Fetches a paginated list of governance proposals from the subgraph */
31
- export async function getAllProposals({
32
- where,
33
- orderBy,
34
- orderDirection,
35
- offset = 0,
36
- perPage = 20,
37
- text,
38
- ...args
39
- }: GetAllProposalsArgs): Promise<ProposalSelectionFragment[] | undefined> {
40
- try {
41
- if (perPage > 1000) {
42
- throw new Error("perPage must be less than 1000");
43
- }
44
-
45
- const governanceClient = getApolloClient("governance.subgraph", args);
46
- const [response] = await Promise.all([
47
- text
48
- ? governanceClient.query<
49
- SearchProposalsQuery,
50
- SearchProposalsQueryVariables
51
- >({
52
- query: SearchProposals,
53
- variables: {
54
- offset,
55
- limit: perPage,
56
- where,
57
- text,
58
- },
59
- })
60
- : governanceClient.query<GetProposalsQuery, GetProposalsQueryVariables>(
61
- {
62
- query: GetProposals,
63
- variables: {
64
- offset,
65
- limit: perPage,
66
- where,
67
- orderBy,
68
- orderDirection,
69
- },
70
- },
71
- ),
72
- ]);
73
-
74
- return response.data.proposals.map((p) => ({
75
- ...p,
76
- status: computeActualStatus(p),
77
- }));
78
- } catch (e) {
79
- console.error("getAllProposals:", e);
80
- throw e;
81
- }
22
+ export async function getAllProposals(
23
+ _args: GetAllProposalsArgs,
24
+ ): Promise<ProposalSelectionFragment[] | undefined> {
25
+ // Governance subgraph not live — return empty until indexer is available
26
+ return [];
82
27
  }
@@ -1,14 +1,6 @@
1
1
  import type { PublicClient } from "viem";
2
2
 
3
- import {
4
- GetProposal,
5
- type GetProposalQuery,
6
- type GetProposalQueryVariables,
7
- type ProposalWithVotesFragment,
8
- } from "@berachain/graphql/governance";
9
-
10
- import { getApolloClient } from "../clients/getApolloClient";
11
- import { computeActualStatus } from "./computeActualStatus";
3
+ import type { ProposalWithVotesFragment } from "@berachain/graphql/governance";
12
4
 
13
5
  export type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
14
6
  /** On-chain proposal ID */
@@ -17,28 +9,9 @@ export type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
17
9
  };
18
10
 
19
11
  /** Fetches a single proposal with its vote data from the subgraph */
20
- export async function getProposalDetails({
21
- proposalId,
22
- ...args
23
- }: GetProposalDetailsArgs): Promise<ProposalWithVotesFragment | undefined> {
24
- const governanceClient = getApolloClient("governance.subgraph", args);
25
-
26
- const res = await governanceClient.query<
27
- GetProposalQuery,
28
- GetProposalQueryVariables
29
- >({
30
- query: GetProposal,
31
- variables: {
32
- id: proposalId,
33
- },
34
- });
35
-
36
- if (!res.data.proposal) {
37
- return undefined;
38
- }
39
-
40
- return {
41
- ...res.data.proposal,
42
- status: computeActualStatus(res.data.proposal),
43
- } as ProposalWithVotesFragment;
12
+ export async function getProposalDetails(
13
+ _args: GetProposalDetailsArgs,
14
+ ): Promise<ProposalWithVotesFragment | undefined> {
15
+ // Governance subgraph not live — return undefined until indexer is available
16
+ return undefined;
44
17
  }
@@ -1,24 +1,17 @@
1
- import {
2
- GetProposalVotes,
3
- type GetProposalVotesQuery,
4
- type GetProposalVotesQueryVariables,
1
+ import type {
2
+ GetProposalVotesQuery,
3
+ GetProposalVotesQueryVariables,
5
4
  } from "@berachain/graphql/governance";
6
5
 
7
- import { getApolloClient } from "../clients/getApolloClient";
8
-
9
6
  export type GetProposalVotesArgs = BeraJS.BaseFunctionArgs & {
10
7
  /** GraphQL variables forwarded to the GetProposalVotes query */
11
8
  variables: GetProposalVotesQueryVariables;
12
9
  };
13
10
 
14
11
  /** Fetches the votes for a proposal from the subgraph */
15
- export async function getProposalVotes({
16
- variables,
17
- ...args
18
- }: GetProposalVotesArgs) {
19
- const governanceClient = getApolloClient("governance.subgraph", args);
20
- return governanceClient.query<GetProposalVotesQuery>({
21
- query: GetProposalVotes,
22
- variables,
23
- });
12
+ export async function getProposalVotes(
13
+ _args: GetProposalVotesArgs,
14
+ ): Promise<{ data: GetProposalVotesQuery }> {
15
+ // Governance subgraph not live — return empty until indexer is available
16
+ return { data: { votes: [] } };
24
17
  }
@@ -1,27 +1,33 @@
1
- import {
2
- Aggregation_Interval,
3
- GetSnapshots,
4
- type GetSnapshotsQuery,
5
- type GetSnapshotsQueryVariables,
6
- } from "@berachain/graphql/honey";
1
+ import type { GetSnapshotsQuery } from "@berachain/graphql/honey";
7
2
 
8
- import { getApolloClient } from "../clients/getApolloClient";
3
+ import { BeraError } from "../../errors/BeraError";
4
+ import { beraFetchJson } from "../../utils/beraFetch";
5
+
6
+ /**
7
+ * Browser-only. Hits the typed `/api/honey/snapshots` endpoint.
8
+ * Server callers must compose the upstream query directly (this action is
9
+ * not server-safe — `fetch` against a relative URL has no origin off-browser).
10
+ */
9
11
  export async function getChartData({
10
12
  days,
11
- ...args
12
- }: BeraJS.BaseFunctionArgs & {
13
+ }: {
13
14
  days: number;
14
- }) {
15
- const client = getApolloClient("honey.subgraph", args);
15
+ }): Promise<GetSnapshotsQuery> {
16
+ if (typeof window === "undefined") {
17
+ throw new BeraError({
18
+ message:
19
+ "getChartData is browser-only; call from a Client Component / SWR hook",
20
+ level: "error",
21
+ });
22
+ }
16
23
 
17
- const res = await client.query<GetSnapshotsQuery, GetSnapshotsQueryVariables>(
18
- {
19
- query: GetSnapshots,
20
- variables: {
21
- interval: Aggregation_Interval.Day,
22
- first: days,
23
- },
24
- },
25
- );
26
- return res.data;
24
+ const params = new URLSearchParams({ interval: "day", first: String(days) });
25
+ const honeySnapshots = await beraFetchJson<
26
+ GetSnapshotsQuery["honeySnapshots"]
27
+ >({
28
+ url: `/api/honey/snapshots?${params}`,
29
+ name: "honey-snapshots",
30
+ type: "rest",
31
+ });
32
+ return { honeySnapshots };
27
33
  }
@@ -1,29 +1,26 @@
1
- import {
2
- Aggregation_Interval,
3
- GetSnapshots,
4
- type GetSnapshotsQuery,
5
- type GetSnapshotsQueryVariables,
6
- } from "@berachain/graphql/honey";
1
+ import type { GetSnapshotsQuery } from "@berachain/graphql/honey";
7
2
  import BigNumber from "@berachain/utils/pkg/bignumber.js";
8
3
 
9
- import { getApolloClient } from "../clients/getApolloClient";
4
+ import { BeraError } from "../../errors/BeraError";
5
+ import { beraFetchJson } from "../../utils/beraFetch";
10
6
 
11
- export async function getHoney24hVolume({
12
- ...args
13
- }: BeraJS.BaseFunctionArgs = {}) {
14
- const client = getApolloClient("honey.subgraph", args);
15
- const result = await client.query<
16
- GetSnapshotsQuery,
17
- GetSnapshotsQueryVariables
18
- >({
19
- query: GetSnapshots,
20
- variables: {
21
- interval: Aggregation_Interval.Hour,
22
- first: 24,
23
- },
24
- });
7
+ /** Browser-only. Hits `/api/honey/snapshots?interval=hour&first=24` and reduces. */
8
+ export async function getHoney24hVolume(): Promise<BigNumber | undefined> {
9
+ if (typeof window === "undefined") {
10
+ throw new BeraError({
11
+ message:
12
+ "getHoney24hVolume is browser-only; call from a Client Component / SWR hook",
13
+ level: "error",
14
+ });
15
+ }
25
16
 
26
- return result.data?.honeySnapshots.reduce(
17
+ const params = new URLSearchParams({ interval: "hour", first: "24" });
18
+ const snapshots = await beraFetchJson<GetSnapshotsQuery["honeySnapshots"]>({
19
+ url: `/api/honey/snapshots?${params}`,
20
+ name: "honey-snapshots",
21
+ type: "rest",
22
+ });
23
+ return snapshots.reduce(
27
24
  (acc, curr) => new BigNumber(curr.totalVolume).plus(acc),
28
25
  new BigNumber(0),
29
26
  );
@@ -1,8 +1,15 @@
1
1
  import { HermesClient } from "@pythnetwork/hermes-client";
2
2
  import { formatUnits } from "viem";
3
3
 
4
+ import { polyfillAbortSignalAny } from "../../utils/polyfillAbortSignalAny";
5
+
4
6
  const pythEndpoint = "https://hermes.pyth.network";
5
7
 
8
+ // @pythnetwork/hermes-client uses AbortSignal.any, which is missing on older
9
+ // browsers/WebViews (e.g. Chrome Mobile WebView 114). Install the polyfill
10
+ // before the client runs so getLatestPriceUpdates doesn't throw. See HONEY-188.
11
+ polyfillAbortSignalAny();
12
+
6
13
  /**
7
14
  * Interface representing the latest Pyth price updates
8
15
  * @interface PythLatestUpdates
@@ -25,7 +25,7 @@ describe("rewardVaults", async () => {
25
25
  it("should have consistent data", () => {
26
26
  const totalBgtCatpure = gaugeList.reduce(
27
27
  (acc, vault) =>
28
- acc + Number(vault.dynamicData?.bgtCapturePercentage ?? 0),
28
+ acc + Number(vault.dynamicData?.rewardCapturePercentage ?? 0),
29
29
  0,
30
30
  );
31
31
 
@@ -0,0 +1,41 @@
1
+ import type { Address } from "viem";
2
+
3
+ import { RequestError } from "../../errors/RequestError";
4
+ import type { AutoclaimedIncentivesResponse } from "../../types/bribe-boost";
5
+ import { beraFetchJson } from "../../utils/beraFetch";
6
+ import { parseBaseArgs } from "../../utils/parseBaseArgs";
7
+
8
+ /**
9
+ * Server-side function to fetch the incentives the bot autoclaimed on behalf
10
+ * of a wallet during the BGT → BERA cutover. Only valid to call once the
11
+ * bgtIncentiveDistributor contract is paused.
12
+ *
13
+ * Returns `null` on 404 — the endpoint 404s when the bot has not yet processed
14
+ * the wallet, which is a normal "no data yet" state rather than an error.
15
+ */
16
+ export async function getAutoclaimedIncentives({
17
+ account,
18
+ ...args
19
+ }: {
20
+ account: Address;
21
+ } & BeraJS.BaseFunctionArgs): Promise<AutoclaimedIncentivesResponse | null> {
22
+ const { config } = parseBaseArgs(args);
23
+
24
+ try {
25
+ return await beraFetchJson<AutoclaimedIncentivesResponse>(
26
+ {
27
+ url: `${
28
+ config.pol.bribeBoostApi
29
+ }/api/v1/wallets/${account.toLowerCase()}/autoclaimed`,
30
+ name: "pol-autoclaimed-incentives",
31
+ type: "rest",
32
+ },
33
+ { cache: "no-store" },
34
+ );
35
+ } catch (error) {
36
+ if (error instanceof RequestError && error.statusCode === 404) {
37
+ return null;
38
+ }
39
+ throw error;
40
+ }
41
+ }
@@ -0,0 +1,41 @@
1
+ import type { Address } from "viem";
2
+
3
+ import { RequestError } from "../../errors/RequestError";
4
+ import type { AutoclaimedIncentivesTxHashResponse } from "../../types/bribe-boost";
5
+ import { beraFetchJson } from "../../utils/beraFetch";
6
+ import { parseBaseArgs } from "../../utils/parseBaseArgs";
7
+
8
+ /**
9
+ * Companion to `getAutoclaimedIncentives` that fetches the on-chain tx hash
10
+ * for each autoclaimed token. Same nested shape as `/autoclaimed`, but each
11
+ * token leaf is `{ txhash }` where the hash may be absent or empty while the
12
+ * bot is still in flight.
13
+ *
14
+ * Returns `null` on 404 (bot has not run yet for this wallet).
15
+ */
16
+ export async function getAutoclaimedIncentivesTxHash({
17
+ account,
18
+ ...args
19
+ }: {
20
+ account: Address;
21
+ } & BeraJS.BaseFunctionArgs): Promise<AutoclaimedIncentivesTxHashResponse | null> {
22
+ const { config } = parseBaseArgs(args);
23
+
24
+ try {
25
+ return await beraFetchJson<AutoclaimedIncentivesTxHashResponse>(
26
+ {
27
+ url: `${
28
+ config.pol.bribeBoostApi
29
+ }/api/v1/wallets/${account.toLowerCase()}/autoclaimed/txhash`,
30
+ name: "pol-autoclaimed-incentives-txhash",
31
+ type: "rest",
32
+ },
33
+ { cache: "no-store" },
34
+ );
35
+ } catch (error) {
36
+ if (error instanceof RequestError && error.statusCode === 404) {
37
+ return null;
38
+ }
39
+ throw error;
40
+ }
41
+ }