@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
@@ -0,0 +1,35 @@
1
+ import {
2
+ bignumber_js_default
3
+ } from "./chunk-E7YFXBBQ.mjs";
4
+ import {
5
+ isToken,
6
+ wBeraToken
7
+ } from "./chunk-IXIBY5FP.mjs";
8
+
9
+ // src/utils/tokenWrapping.ts
10
+ function wrapNativeToken(token) {
11
+ return {
12
+ ...token,
13
+ ...isToken(token, "BERA") && wBeraToken
14
+ };
15
+ }
16
+ function wrapNativeTokens(tokens) {
17
+ return tokens.map((token) => wrapNativeToken(token));
18
+ }
19
+
20
+ // src/utils/math.ts
21
+ var computePriceImpact = (tokenInPrice, tokenOutPrice, inAmount, outAmount) => {
22
+ if (!tokenInPrice || !tokenOutPrice || !inAmount || !outAmount) return 0;
23
+ const usdIn = new bignumber_js_default(tokenInPrice).times(inAmount);
24
+ const usdOut = new bignumber_js_default(tokenOutPrice).times(outAmount);
25
+ if (usdIn.lt(0.01) || usdOut.lt(0.01)) return 0;
26
+ if (usdIn.isZero() || usdOut.isZero()) return 0;
27
+ const ratio = usdOut.div(usdIn);
28
+ return Number(new bignumber_js_default(1).minus(ratio).toFixed());
29
+ };
30
+
31
+ export {
32
+ wrapNativeToken,
33
+ wrapNativeTokens,
34
+ computePriceImpact
35
+ };
@@ -0,0 +1,12 @@
1
+ // src/enum/polling.ts
2
+ var POLLING = /* @__PURE__ */ ((POLLING2) => {
3
+ POLLING2[POLLING2["FAST"] = 1e4] = "FAST";
4
+ POLLING2[POLLING2["NORMAL"] = 1e5] = "NORMAL";
5
+ POLLING2[POLLING2["SLOW"] = 18e4] = "SLOW";
6
+ POLLING2[POLLING2["REFRESH_BLOCK_INTERVAL"] = 1e4] = "REFRESH_BLOCK_INTERVAL";
7
+ return POLLING2;
8
+ })(POLLING || {});
9
+
10
+ export {
11
+ POLLING
12
+ };
@@ -0,0 +1,35 @@
1
+ // src/errors/BeraTracing.ts
2
+ var _handlers = [];
3
+ var BeraTracing = {
4
+ /**
5
+ * Execute a callback, wrapping it in all registered span handlers.
6
+ *
7
+ * Handlers chain so each wraps the next. First registered = outermost wrapper.
8
+ * If no handlers are registered, the callback is executed directly.
9
+ */
10
+ startSpan(context, callback) {
11
+ if (_handlers.length === 0) return callback();
12
+ return _handlers.reduceRight(
13
+ (next, handler) => () => handler(context, next),
14
+ callback
15
+ )();
16
+ },
17
+ /**
18
+ * Register a span tracing handler.
19
+ *
20
+ * @param _event - Must be "span". Exists for API consistency with BeraMonitoring.
21
+ * @param handler - A StartSpanFn, e.g. Sentry.startSpan.
22
+ * @returns An unsubscribe function to remove the handler.
23
+ */
24
+ addSpanHandler(handler) {
25
+ _handlers.push(handler);
26
+ return () => {
27
+ const idx = _handlers.indexOf(handler);
28
+ if (idx !== -1) _handlers.splice(idx, 1);
29
+ };
30
+ }
31
+ };
32
+
33
+ export {
34
+ BeraTracing
35
+ };
@@ -0,0 +1,426 @@
1
+ import {
2
+ getBalanceCall,
3
+ getEnsoClient
4
+ } from "./chunk-HYDP32P6.mjs";
5
+ import {
6
+ BeraMonitoring,
7
+ initBeraError
8
+ } from "./chunk-7YVNSDXG.mjs";
9
+ import {
10
+ defaultFlags
11
+ } from "./chunk-BGMRHTBQ.mjs";
12
+ import {
13
+ beraToken,
14
+ isToken
15
+ } from "./chunk-IXIBY5FP.mjs";
16
+ import {
17
+ parseBaseArgs
18
+ } from "./chunk-DQRH5VE3.mjs";
19
+ import {
20
+ BeraError,
21
+ InvalidArgumentError
22
+ } from "./chunk-KHXJDYA4.mjs";
23
+
24
+ // src/contexts/BeraFlags/BeraFlags.tsx
25
+ import { createContext, useContext } from "react";
26
+ import {
27
+ isFlagEnabled
28
+ } from "@berachain/config/internal/edge-config";
29
+ import { jsx } from "react/jsx-runtime";
30
+ var BeraFlagContext = createContext(
31
+ void 0
32
+ );
33
+ function BeraFlagsProvider({
34
+ children,
35
+ flags,
36
+ aggregators,
37
+ swberaAprWindow = "DAY"
38
+ }) {
39
+ return /* @__PURE__ */ jsx(
40
+ BeraFlagContext.Provider,
41
+ {
42
+ value: {
43
+ ...defaultFlags,
44
+ ...flags,
45
+ aggregators: aggregators ? Object.entries(aggregators).filter(([, value]) => isFlagEnabled(value)).map(([key]) => key) : void 0,
46
+ swberaAprWindow
47
+ },
48
+ children
49
+ }
50
+ );
51
+ }
52
+ function useBeraFlags() {
53
+ const context = useContext(BeraFlagContext);
54
+ if (!context) {
55
+ throw new Error("BeraFlagsProvider not found");
56
+ }
57
+ return context;
58
+ }
59
+ function useBeraFlag(key) {
60
+ const flags = useBeraFlags();
61
+ return flags[key];
62
+ }
63
+
64
+ // src/contexts/BexStatusProvider.tsx
65
+ import {
66
+ createContext as createContext2,
67
+ useContext as useContext2,
68
+ useState
69
+ } from "react";
70
+ import { jsx as jsx2 } from "react/jsx-runtime";
71
+ var BexStateContext = createContext2({
72
+ protocol: {
73
+ isPaused: false,
74
+ factories: {
75
+ composableStable: "enabled",
76
+ weighted: "enabled",
77
+ allPaused: false
78
+ }
79
+ },
80
+ onPoolChange: () => {
81
+ },
82
+ pool: void 0
83
+ });
84
+ function useBexStatus() {
85
+ const context = useContext2(BexStateContext);
86
+ if (!context) {
87
+ throw new BeraError({
88
+ level: "fatal",
89
+ message: "BexStateContext is not defined"
90
+ });
91
+ }
92
+ return context;
93
+ }
94
+ function BexStatusProvider({
95
+ children,
96
+ isVaultPaused,
97
+ labels,
98
+ factories
99
+ }) {
100
+ const [poolState, setPoolState] = useState();
101
+ const disablePoolWithdrawals = (poolState?.isPaused && !poolState?.isInRecoveryMode) ?? false;
102
+ const disablePoolDeposits = isVaultPaused || poolState?.isPaused;
103
+ return /* @__PURE__ */ jsx2(
104
+ BexStateContext.Provider,
105
+ {
106
+ value: {
107
+ protocol: {
108
+ isPaused: isVaultPaused,
109
+ factories: {
110
+ ...factories,
111
+ allPaused: factories.composableStable === "paused" && factories.weighted === "paused"
112
+ }
113
+ },
114
+ labels,
115
+ onPoolChange: setPoolState,
116
+ pool: poolState ? {
117
+ ...poolState,
118
+ disablePoolWithdrawals: !!disablePoolWithdrawals,
119
+ disablePoolDeposits: !!disablePoolDeposits
120
+ } : void 0
121
+ },
122
+ children
123
+ }
124
+ );
125
+ }
126
+
127
+ // src/contexts/block-time-provider.tsx
128
+ import { createContext as createContext3, useContext as useContext3 } from "react";
129
+ import { mainnet } from "@berachain/config/mainnet";
130
+ import { jsx as jsx3 } from "react/jsx-runtime";
131
+ function useBlockTime() {
132
+ return useContext3(BlockTimeContext);
133
+ }
134
+ var BlockTimeContext = createContext3(
135
+ // this is the default block time for berachain, but actually overridden by the block time provider
136
+ mainnet.averageBlockTime
137
+ );
138
+ function BlockTimeProvider({
139
+ children,
140
+ blockTime,
141
+ ...args
142
+ }) {
143
+ const { config } = parseBaseArgs(args);
144
+ return /* @__PURE__ */ jsx3(BlockTimeContext.Provider, { value: blockTime ?? config.averageBlockTime, children });
145
+ }
146
+
147
+ // src/contexts/HoneyConfigProvider.tsx
148
+ import { createContext as createContext4, useContext as useContext4 } from "react";
149
+ import { jsx as jsx4 } from "react/jsx-runtime";
150
+ var HoneyConfigContext = createContext4(void 0);
151
+ function HoneyConfigProvider({
152
+ children,
153
+ ...props
154
+ }) {
155
+ return /* @__PURE__ */ jsx4(HoneyConfigContext.Provider, { value: props, children });
156
+ }
157
+ function useHoneyConfig() {
158
+ const context = useContext4(HoneyConfigContext);
159
+ if (!context) {
160
+ throw new Error("useHoneyConfig must be used within a HoneyConfigProvider");
161
+ }
162
+ return context;
163
+ }
164
+
165
+ // src/hooks/enso/useEnsoUserTokensWithBalances.ts
166
+ import useSWR from "swr";
167
+ import { useBeraWallet, useConfig } from "@berachain/wagmi/hooks";
168
+
169
+ // src/actions/enso/getEnsoUserTokensWithBalances.ts
170
+ import { getChains, multicall } from "@wagmi/core";
171
+ import { formatUnits } from "viem";
172
+ async function getEnsoUserTokensWithBalances({
173
+ account,
174
+ wagmiConfig,
175
+ chainId,
176
+ ensoClient
177
+ }) {
178
+ const ensoBalances = await ensoClient.getBalances({
179
+ useEoa: true,
180
+ chainId: chainId ?? "all",
181
+ eoaAddress: account
182
+ });
183
+ if (!Array.isArray(ensoBalances)) {
184
+ BeraMonitoring.captureException(
185
+ new InvalidArgumentError({
186
+ property: "ensoBalances",
187
+ value: ensoBalances,
188
+ expected: "BalanceToken[]",
189
+ chainId: typeof chainId === "number" ? chainId : void 0,
190
+ extra: { account, chainId }
191
+ })
192
+ );
193
+ return [];
194
+ }
195
+ const tokens = ensoBalances.map(
196
+ (balance) => ({
197
+ name: balance.name,
198
+ symbol: balance.symbol,
199
+ decimals: balance.decimals,
200
+ address: isToken(balance.token, "ETH") ? beraToken.address : balance.token,
201
+ logoURI: balance.logoUri,
202
+ balance: {
203
+ raw: balance.amount.toString(),
204
+ formatted: formatUnits(BigInt(balance.amount), balance.decimals)
205
+ },
206
+ chainId: Number(
207
+ // @ts-expect-error - balance.chainId is defined just not typed by enso
208
+ balance.chainId
209
+ ),
210
+ price: Number(balance.price)
211
+ })
212
+ );
213
+ const tokenByChainId = Object.groupBy(tokens, (a) => a.chainId ?? 0);
214
+ const balances = await Promise.allSettled(
215
+ Object.entries(tokenByChainId).map(async ([chainId2, chainTokens]) => {
216
+ if (!chainTokens) return void 0;
217
+ const chainConfig = getChains(wagmiConfig).find(
218
+ (chain) => chain.id === Number(chainId2)
219
+ );
220
+ if (!chainConfig) {
221
+ return void 0;
222
+ }
223
+ const multicall3 = chainConfig.contracts?.multicall3;
224
+ const multicallAddress = multicall3?.address;
225
+ if (!multicallAddress) {
226
+ BeraMonitoring.captureException(
227
+ new InvalidArgumentError({
228
+ property: "multicallAddress",
229
+ value: multicallAddress,
230
+ expected: "Address",
231
+ chainId: Number(chainId2)
232
+ })
233
+ );
234
+ return chainTokens;
235
+ }
236
+ const balances2 = await multicall(wagmiConfig, {
237
+ chainId: Number(chainId2),
238
+ contracts: chainTokens.map(
239
+ (token) => getBalanceCall({
240
+ token,
241
+ account,
242
+ multicallAddress
243
+ })
244
+ ),
245
+ allowFailure: true
246
+ });
247
+ const tokensWithBalances = [];
248
+ for (let index = 0; index < chainTokens.length; index++) {
249
+ const token = chainTokens[index];
250
+ if (balances2[index].status === "success") {
251
+ const balance = balances2[index].result;
252
+ tokensWithBalances.push({
253
+ ...token,
254
+ balance: {
255
+ raw: balance?.toString() ?? "0",
256
+ formatted: formatUnits(balance ?? 0n, token.decimals)
257
+ }
258
+ });
259
+ } else {
260
+ console.error("error getting balance", balances2[index].error);
261
+ BeraMonitoring.captureException(
262
+ initBeraError({ cause: balances2[index].error })
263
+ );
264
+ tokensWithBalances.push(token);
265
+ }
266
+ }
267
+ return tokensWithBalances;
268
+ })
269
+ );
270
+ const flattenedBalances = [];
271
+ for (const result of balances) {
272
+ if (result.status === "fulfilled") {
273
+ flattenedBalances.push(...result.value ?? []);
274
+ } else {
275
+ BeraMonitoring.captureException(initBeraError({ cause: result.reason }));
276
+ }
277
+ }
278
+ return flattenedBalances.sort((a, b) => {
279
+ const aValue = Number(a.balance.formatted) * (a.price ?? 0);
280
+ const bValue = Number(b.balance.formatted) * (b.price ?? 0);
281
+ return bValue - aValue;
282
+ });
283
+ }
284
+
285
+ // src/hooks/enso/useEnsoUserTokensWithBalances.ts
286
+ function useEnsoUserTokensWithBalances({ chainId } = {}, options) {
287
+ const { address: fromAddress } = useBeraWallet();
288
+ const wagmiConfig = useConfig();
289
+ const proxyAggregatorsThroughVercel = useBeraFlag(
290
+ "proxyAggregatorsThroughVercel"
291
+ );
292
+ const isEnabled = !!fromAddress && (options?.opts?.isEnabled ?? true);
293
+ const QUERY_KEY = isEnabled && wagmiConfig ? [
294
+ "useEnsoUserTokensWithBalances",
295
+ fromAddress,
296
+ chainId,
297
+ proxyAggregatorsThroughVercel ?? false
298
+ ] : null;
299
+ const swrResponse = useSWR(
300
+ QUERY_KEY,
301
+ async ([, fromAddress2, chainId2]) => getEnsoUserTokensWithBalances({
302
+ account: fromAddress2,
303
+ wagmiConfig,
304
+ chainId: chainId2 ?? "all",
305
+ ensoClient: getEnsoClient({
306
+ baseURL: proxyAggregatorsThroughVercel ? "/api/enso" : void 0
307
+ })
308
+ }),
309
+ {
310
+ refreshInterval: 1e5 /* NORMAL */,
311
+ isEnabled,
312
+ ...options?.opts
313
+ }
314
+ );
315
+ return {
316
+ ...swrResponse,
317
+ refresh: () => swrResponse.mutate()
318
+ };
319
+ }
320
+
321
+ // src/contexts/TokensProvider.tsx
322
+ import { createContext as createContext5, useMemo } from "react";
323
+ import {
324
+ isFlagEnabled as isFlagEnabled2
325
+ } from "@berachain/config/internal/edge-config";
326
+
327
+ // src/utils/formatTokenList.ts
328
+ function formatTokenList({
329
+ defaultTokenList = [],
330
+ externalList = []
331
+ }) {
332
+ if (defaultTokenList.length === 0) {
333
+ return {
334
+ tokenList: externalList,
335
+ customTokenList: externalList,
336
+ featuredTokenList: []
337
+ };
338
+ }
339
+ const defaultList = defaultTokenList.map((token) => {
340
+ return { ...token, default: true };
341
+ });
342
+ const featuredTokenList = defaultList.filter((token) => {
343
+ return token.tags?.some((tag) => tag === "featured");
344
+ });
345
+ const mergedList = [...defaultList, ...externalList];
346
+ const uniqueList = mergedList.filter(
347
+ (item, index) => mergedList.findIndex((i) => isToken(i, item)) === index
348
+ );
349
+ return {
350
+ tokenList: uniqueList,
351
+ customTokenList: externalList,
352
+ featuredTokenList
353
+ };
354
+ }
355
+
356
+ // src/contexts/TokensProvider.tsx
357
+ import { jsx as jsx5 } from "react/jsx-runtime";
358
+ var TokenContext = createContext5(
359
+ void 0
360
+ );
361
+ function TokensProvider({
362
+ children,
363
+ defaultTokens,
364
+ edgeConfigTokenList,
365
+ userTokens,
366
+ onAddToken,
367
+ onRemoveToken
368
+ }) {
369
+ const { data: ensoTokens, refresh } = useEnsoUserTokensWithBalances();
370
+ const { tokenList = [], featuredTokenList = [] } = useMemo(
371
+ () => formatTokenList({
372
+ defaultTokenList: [
373
+ ...defaultTokens,
374
+ ...edgeConfigTokenList?.filter(
375
+ (token) => isFlagEnabled2(token.enabled)
376
+ )
377
+ ],
378
+ externalList: [
379
+ ...userTokens,
380
+ ...(ensoTokens ?? []).map((t) => ({
381
+ ...t,
382
+ balance: void 0,
383
+ price: void 0
384
+ }))
385
+ ]
386
+ }),
387
+ [defaultTokens, userTokens, edgeConfigTokenList, ensoTokens]
388
+ );
389
+ return /* @__PURE__ */ jsx5(
390
+ TokenContext.Provider,
391
+ {
392
+ value: {
393
+ tokenList,
394
+ userTokens,
395
+ featuredTokens: featuredTokenList,
396
+ ensoTokens,
397
+ onAddToken(tk) {
398
+ onAddToken(tk, { defaultTokens, userTokens, tokenList });
399
+ },
400
+ onRemoveToken,
401
+ refresh: () => {
402
+ refresh();
403
+ }
404
+ },
405
+ children
406
+ }
407
+ );
408
+ }
409
+
410
+ export {
411
+ BeraFlagsProvider,
412
+ useBeraFlags,
413
+ useBeraFlag,
414
+ BexStateContext,
415
+ useBexStatus,
416
+ BexStatusProvider,
417
+ useBlockTime,
418
+ BlockTimeContext,
419
+ BlockTimeProvider,
420
+ HoneyConfigContext,
421
+ HoneyConfigProvider,
422
+ useHoneyConfig,
423
+ useEnsoUserTokensWithBalances,
424
+ TokenContext,
425
+ TokensProvider
426
+ };
@@ -0,0 +1,126 @@
1
+ import {
2
+ BeraTracing
3
+ } from "./chunk-SZ5C44L5.mjs";
4
+ import {
5
+ RequestError
6
+ } from "./chunk-ZLTMIFCZ.mjs";
7
+
8
+ // src/utils/getErrorResponse.ts
9
+ async function getErrorResponse(response) {
10
+ const contentType = response.headers.get("content-type");
11
+ if (contentType?.includes("application/json")) {
12
+ return response.json();
13
+ } else {
14
+ const text = await response.text();
15
+ try {
16
+ return JSON.parse(text);
17
+ } catch {
18
+ return {
19
+ message: "Unknown error, can't decode response into JSON",
20
+ cause: text
21
+ };
22
+ }
23
+ }
24
+ }
25
+
26
+ // src/utils/sanitizeRpcUrl.ts
27
+ function sanitizeRpcUrl(url) {
28
+ if (!url) return "";
29
+ try {
30
+ const parsed = new URL(url);
31
+ if (parsed.hostname.endsWith(".quiknode.pro")) {
32
+ parsed.pathname = "/";
33
+ parsed.search = "";
34
+ return parsed.toString();
35
+ }
36
+ return url;
37
+ } catch {
38
+ return url;
39
+ }
40
+ }
41
+
42
+ // src/utils/beraFetch.ts
43
+ async function beraFetch(endpoint, options, spanContext) {
44
+ try {
45
+ let spanUrl = sanitizeRpcUrl(
46
+ typeof endpoint === "string" || endpoint instanceof URL ? endpoint.toString() : endpoint.url.toString()
47
+ ).replace(/0x[a-fA-F0-9]{40}/g, ":address");
48
+ if (spanContext?.keepQueryParams !== true && URL.canParse(spanUrl)) {
49
+ const queryParams = new URL(spanUrl).searchParams;
50
+ if (Array.isArray(spanContext?.keepQueryParams)) {
51
+ const searchParams = new URLSearchParams();
52
+ for (const param of spanContext.keepQueryParams) {
53
+ searchParams.set(param, queryParams.get(param) ?? "");
54
+ }
55
+ const newUrl = new URL(spanUrl);
56
+ newUrl.search = searchParams.toString();
57
+ spanUrl = newUrl.toString();
58
+ } else {
59
+ const newUrl = new URL(spanUrl);
60
+ newUrl.search = "";
61
+ spanUrl = newUrl.toString();
62
+ }
63
+ }
64
+ const endpointName = typeof endpoint === "string" || endpoint instanceof URL ? void 0 : endpoint.name;
65
+ return await BeraTracing.startSpan(
66
+ {
67
+ op: "beraFetch",
68
+ name: endpointName ? `beraFetch ${endpointName}` : "beraFetch",
69
+ attributes: typeof endpoint === "string" || endpoint instanceof URL ? {
70
+ "operation.source.url": spanUrl,
71
+ ...spanContext?.attributes
72
+ } : {
73
+ "operation.source.url": spanUrl,
74
+ "operation.source.type": endpoint.type,
75
+ "operation.source.name": endpoint.name,
76
+ ...spanContext?.attributes
77
+ }
78
+ },
79
+ async () => {
80
+ const response = await fetch(
81
+ typeof endpoint === "string" || endpoint instanceof URL ? endpoint : endpoint.url,
82
+ {
83
+ ...options
84
+ }
85
+ );
86
+ if (!response.ok) {
87
+ const error = await getErrorResponse(response);
88
+ throw new RequestError({
89
+ cause: error,
90
+ // @to-do import getErrorResponse logic in this function
91
+ // when it's removed from other places
92
+ response,
93
+ endpoint
94
+ });
95
+ }
96
+ return response;
97
+ }
98
+ );
99
+ } catch (error) {
100
+ if (error instanceof RequestError) {
101
+ throw error;
102
+ }
103
+ throw new RequestError({
104
+ cause: error,
105
+ endpoint,
106
+ response: void 0
107
+ });
108
+ }
109
+ }
110
+ async function beraFetchJson(endpoint, options) {
111
+ const response = await beraFetch(endpoint, {
112
+ ...options,
113
+ headers: {
114
+ Accept: "application/json",
115
+ ...options?.headers
116
+ }
117
+ });
118
+ return response.json();
119
+ }
120
+
121
+ export {
122
+ getErrorResponse,
123
+ sanitizeRpcUrl,
124
+ beraFetch,
125
+ beraFetchJson
126
+ };