@berachain/berajs 0.2.8-beta.9 → 0.2.9

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 (237) 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 +2 -0
  6. package/dist/actions/clients/exports.mjs +12 -0
  7. package/dist/actions/exports.d.ts +104 -189
  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-3EARVV7K.mjs +414 -0
  14. package/dist/chunk-4Z4AK6SH.mjs +211 -0
  15. package/dist/chunk-75M6TF7M.mjs +25 -0
  16. package/dist/chunk-AFN4CVD3.mjs +326 -0
  17. package/dist/chunk-BGMRHTBQ.mjs +23 -0
  18. package/dist/chunk-CDFWPU2R.mjs +473 -0
  19. package/dist/chunk-CDK4YV3D.mjs +571 -0
  20. package/dist/chunk-DKMAIU74.mjs +62 -0
  21. package/dist/chunk-EXIUPSFN.mjs +86 -0
  22. package/dist/chunk-FFB5LFDW.mjs +35 -0
  23. package/dist/chunk-HQCOU6GY.mjs +243 -0
  24. package/dist/chunk-HSSJKHZ4.mjs +135 -0
  25. package/dist/chunk-J5I45WGQ.mjs +1769 -0
  26. package/dist/chunk-KQUMKB66.mjs +89 -0
  27. package/dist/chunk-NBYLMO2L.mjs +14 -0
  28. package/dist/chunk-NPBQLVL3.mjs +80 -0
  29. package/dist/chunk-O2NQFKJK.mjs +170 -0
  30. package/dist/chunk-QJIXTYTZ.mjs +4054 -0
  31. package/dist/chunk-SGIJVHZO.mjs +12 -0
  32. package/dist/chunk-SZ5C44L5.mjs +35 -0
  33. package/dist/chunk-WXXOISTU.mjs +96 -0
  34. package/dist/chunk-XIYN6AL6.mjs +160 -0
  35. package/dist/contexts/exports.d.ts +2 -2
  36. package/dist/contexts/exports.mjs +85 -2
  37. package/dist/enum/exports.d.ts +1 -1
  38. package/dist/enum/exports.mjs +46 -2
  39. package/dist/enum/governance/exports.d.ts +60 -0
  40. package/dist/enum/governance/exports.mjs +14 -0
  41. package/dist/errors/exports.d.ts +4 -3
  42. package/dist/errors/exports.mjs +48 -2
  43. package/dist/exports-BcUTGFUb.d.ts +40 -0
  44. package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-Dw5KN5sh.d.ts} +2 -2
  45. package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
  46. package/dist/hooks/exports.d.ts +69 -211
  47. package/dist/hooks/exports.mjs +7434 -4
  48. package/dist/hooks/governance/exports.d.ts +181 -0
  49. package/dist/hooks/governance/exports.mjs +888 -0
  50. package/dist/pol.d-CqPA9K6m.d.ts +142 -0
  51. package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
  52. package/dist/types/exports.d.ts +9 -9
  53. package/dist/types/exports.mjs +0 -1
  54. package/dist/types/governance/exports.d.ts +109 -0
  55. package/dist/types/governance/exports.mjs +0 -0
  56. package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
  57. package/dist/utils/exports.d.ts +15 -6
  58. package/dist/utils/exports.mjs +825 -2
  59. package/package.json +49 -13
  60. package/src/actions/__test/transports.ts +61 -0
  61. package/src/actions/clients/exports.ts +4 -0
  62. package/src/actions/clients/getApolloClient.ts +58 -23
  63. package/src/actions/clients/getEnsoClient.ts +20 -9
  64. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  65. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  66. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  67. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  68. package/src/actions/exports.ts +4 -9
  69. package/src/actions/governance/exports.ts +9 -0
  70. package/src/actions/governance/getAllProposals.ts +10 -65
  71. package/src/actions/governance/getProposalDetails.ts +6 -33
  72. package/src/actions/governance/getProposalVotes.ts +8 -15
  73. package/src/actions/honey/getChartData.ts +27 -21
  74. package/src/actions/honey/getHoney24hVolume.ts +19 -22
  75. package/src/actions/pol/getAutoclaimedIncentives.ts +30 -0
  76. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  77. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +35 -0
  78. package/src/actions/pol/getEarnedStakedBeraVault.ts +7 -11
  79. package/src/actions/pol/getGlobalData.ts +1 -0
  80. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  81. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  82. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  83. package/src/actions/pol/getStakingDailyAssets.ts +7 -10
  84. package/src/actions/server/exports.ts +1 -0
  85. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  86. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  87. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  88. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  89. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  90. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  91. package/src/enum/contracts.ts +1 -0
  92. package/src/enum/exports.ts +0 -1
  93. package/src/enum/governance/exports.ts +1 -0
  94. package/src/errors/BeraError.ts +47 -7
  95. package/src/errors/BeraTracing.unit.test.ts +65 -0
  96. package/src/errors/RequestError.ts +13 -1
  97. package/src/errors/exports.ts +5 -0
  98. package/src/errors/getRevertReason.integration.test.ts +3 -3
  99. package/src/errors/spanStatus.ts +78 -0
  100. package/src/errors/spanStatus.unit.test.ts +62 -0
  101. package/src/hooks/dex/useCreatePool.ts +1 -88
  102. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  103. package/src/hooks/dex/usePriceImpact.ts +12 -5
  104. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  105. package/src/hooks/enso/useBendMultiply.ts +9 -1
  106. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  107. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  108. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  109. package/src/hooks/exports.ts +2 -15
  110. package/src/hooks/governance/exports.ts +14 -0
  111. package/src/hooks/pol/useAutoclaimedIncentives.ts +49 -0
  112. package/src/hooks/pol/useStakedAPR.ts +2 -2
  113. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  114. package/src/hooks/validators/useValidator.ts +2 -0
  115. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  116. package/src/types/bribe-boost.d.ts +8 -0
  117. package/src/types/exports.ts +0 -1
  118. package/src/types/governance/exports.ts +1 -0
  119. package/src/utils/beraFetch.ts +9 -3
  120. package/src/utils/exports.ts +1 -0
  121. package/src/utils/getServerSideClient.ts +4 -2
  122. package/src/utils/sanitizeRpcUrl.ts +22 -0
  123. package/src/utils/tracedTransport.ts +35 -0
  124. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  125. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  126. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  127. package/dist/RequestError-DSUzJ1Iy.d.cts +0 -144
  128. package/dist/abi/exports.cjs +0 -2
  129. package/dist/abi/exports.cjs.map +0 -1
  130. package/dist/abi/exports.d.cts +0 -6574
  131. package/dist/abi/exports.mjs.map +0 -1
  132. package/dist/actions/exports.cjs +0 -2
  133. package/dist/actions/exports.cjs.map +0 -1
  134. package/dist/actions/exports.d.cts +0 -1650
  135. package/dist/actions/exports.mjs.map +0 -1
  136. package/dist/chunk-45HIEVNI.cjs +0 -4
  137. package/dist/chunk-45HIEVNI.cjs.map +0 -1
  138. package/dist/chunk-47ILYVHC.mjs +0 -2
  139. package/dist/chunk-47ILYVHC.mjs.map +0 -1
  140. package/dist/chunk-575OK77P.mjs +0 -2
  141. package/dist/chunk-575OK77P.mjs.map +0 -1
  142. package/dist/chunk-5NVZG5N6.mjs +0 -2
  143. package/dist/chunk-5NVZG5N6.mjs.map +0 -1
  144. package/dist/chunk-6DIA6PXV.cjs +0 -2
  145. package/dist/chunk-6DIA6PXV.cjs.map +0 -1
  146. package/dist/chunk-6JJIZCVY.cjs +0 -2
  147. package/dist/chunk-6JJIZCVY.cjs.map +0 -1
  148. package/dist/chunk-7F72ZH4Q.mjs +0 -2
  149. package/dist/chunk-7F72ZH4Q.mjs.map +0 -1
  150. package/dist/chunk-AUA42YIG.mjs +0 -4
  151. package/dist/chunk-AUA42YIG.mjs.map +0 -1
  152. package/dist/chunk-BC2WX6O6.cjs +0 -2
  153. package/dist/chunk-BC2WX6O6.cjs.map +0 -1
  154. package/dist/chunk-CJOZC5Z2.cjs +0 -2
  155. package/dist/chunk-CJOZC5Z2.cjs.map +0 -1
  156. package/dist/chunk-D6L7LTA2.cjs +0 -2
  157. package/dist/chunk-D6L7LTA2.cjs.map +0 -1
  158. package/dist/chunk-DDEQFR3M.cjs +0 -2
  159. package/dist/chunk-DDEQFR3M.cjs.map +0 -1
  160. package/dist/chunk-GXV2JA36.mjs +0 -2
  161. package/dist/chunk-GXV2JA36.mjs.map +0 -1
  162. package/dist/chunk-ISYNEDET.mjs +0 -2
  163. package/dist/chunk-ISYNEDET.mjs.map +0 -1
  164. package/dist/chunk-JDDRTHFG.mjs +0 -2
  165. package/dist/chunk-JDDRTHFG.mjs.map +0 -1
  166. package/dist/chunk-JDZGYU5T.mjs +0 -2
  167. package/dist/chunk-JDZGYU5T.mjs.map +0 -1
  168. package/dist/chunk-LVOXBZMA.cjs +0 -2
  169. package/dist/chunk-LVOXBZMA.cjs.map +0 -1
  170. package/dist/chunk-MK5NS5B5.mjs +0 -2
  171. package/dist/chunk-MK5NS5B5.mjs.map +0 -1
  172. package/dist/chunk-NAXAZJJY.mjs +0 -2
  173. package/dist/chunk-NAXAZJJY.mjs.map +0 -1
  174. package/dist/chunk-NLVWRMGD.mjs +0 -2
  175. package/dist/chunk-NLVWRMGD.mjs.map +0 -1
  176. package/dist/chunk-OGBD5YOG.mjs +0 -2
  177. package/dist/chunk-OGBD5YOG.mjs.map +0 -1
  178. package/dist/chunk-OGJMSGB2.mjs +0 -2
  179. package/dist/chunk-OGJMSGB2.mjs.map +0 -1
  180. package/dist/chunk-OIYXOKTT.cjs +0 -2
  181. package/dist/chunk-OIYXOKTT.cjs.map +0 -1
  182. package/dist/chunk-OUD27MU7.cjs +0 -2
  183. package/dist/chunk-OUD27MU7.cjs.map +0 -1
  184. package/dist/chunk-PRLVZIKD.mjs +0 -2
  185. package/dist/chunk-PRLVZIKD.mjs.map +0 -1
  186. package/dist/chunk-Q2SNRLW3.cjs +0 -2
  187. package/dist/chunk-Q2SNRLW3.cjs.map +0 -1
  188. package/dist/chunk-REWME3FY.cjs +0 -2
  189. package/dist/chunk-REWME3FY.cjs.map +0 -1
  190. package/dist/chunk-RJN36GBU.mjs +0 -2
  191. package/dist/chunk-RJN36GBU.mjs.map +0 -1
  192. package/dist/chunk-RWOICHRW.cjs +0 -2
  193. package/dist/chunk-RWOICHRW.cjs.map +0 -1
  194. package/dist/chunk-S4CDSVLK.cjs +0 -2
  195. package/dist/chunk-S4CDSVLK.cjs.map +0 -1
  196. package/dist/chunk-SFEULGSX.cjs +0 -2
  197. package/dist/chunk-SFEULGSX.cjs.map +0 -1
  198. package/dist/chunk-WBTS6KFG.mjs +0 -2
  199. package/dist/chunk-WBTS6KFG.mjs.map +0 -1
  200. package/dist/chunk-WRFDB3QJ.cjs +0 -2
  201. package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
  202. package/dist/chunk-XNJLSA6P.cjs +0 -2
  203. package/dist/chunk-XNJLSA6P.cjs.map +0 -1
  204. package/dist/contexts/exports.cjs +0 -2
  205. package/dist/contexts/exports.cjs.map +0 -1
  206. package/dist/contexts/exports.d.cts +0 -66
  207. package/dist/contexts/exports.mjs.map +0 -1
  208. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  209. package/dist/dex-C_BB0b0O.d.cts +0 -37
  210. package/dist/enum/exports.cjs +0 -2
  211. package/dist/enum/exports.cjs.map +0 -1
  212. package/dist/enum/exports.d.cts +0 -23
  213. package/dist/enum/exports.mjs.map +0 -1
  214. package/dist/errors/exports.cjs +0 -2
  215. package/dist/errors/exports.cjs.map +0 -1
  216. package/dist/errors/exports.d.cts +0 -327
  217. package/dist/errors/exports.mjs.map +0 -1
  218. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  219. package/dist/global.d-B7IeayVX.d.cts +0 -474
  220. package/dist/honey-CYm0RWf4.d.cts +0 -14
  221. package/dist/hooks/exports.cjs +0 -4
  222. package/dist/hooks/exports.cjs.map +0 -1
  223. package/dist/hooks/exports.d.cts +0 -1734
  224. package/dist/hooks/exports.mjs.map +0 -1
  225. package/dist/polling-BKnyavLI.d.cts +0 -8
  226. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  227. package/dist/types/exports.cjs +0 -1
  228. package/dist/types/exports.cjs.map +0 -1
  229. package/dist/types/exports.d.cts +0 -90
  230. package/dist/types/exports.mjs.map +0 -1
  231. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  232. package/dist/utils/exports.cjs +0 -2
  233. package/dist/utils/exports.cjs.map +0 -1
  234. package/dist/utils/exports.d.cts +0 -420
  235. package/dist/utils/exports.mjs.map +0 -1
  236. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  237. package/src/hooks/dex/useExploitedTokens.ts +0 -57
@@ -0,0 +1,414 @@
1
+ import {
2
+ getBalanceCall,
3
+ getEnsoClient
4
+ } from "./chunk-HSSJKHZ4.mjs";
5
+ import {
6
+ BeraMonitoring,
7
+ initBeraError
8
+ } from "./chunk-EXIUPSFN.mjs";
9
+ import {
10
+ defaultFlags
11
+ } from "./chunk-BGMRHTBQ.mjs";
12
+ import {
13
+ beraToken,
14
+ isToken
15
+ } from "./chunk-NPBQLVL3.mjs";
16
+ import {
17
+ parseBaseArgs
18
+ } from "./chunk-75M6TF7M.mjs";
19
+ import {
20
+ BeraError,
21
+ InvalidArgumentError
22
+ } from "./chunk-J5I45WGQ.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
+ const tokens = ensoBalances.map(
184
+ (balance) => ({
185
+ name: balance.name,
186
+ symbol: balance.symbol,
187
+ decimals: balance.decimals,
188
+ address: isToken(balance.token, "ETH") ? beraToken.address : balance.token,
189
+ logoURI: balance.logoUri,
190
+ balance: {
191
+ raw: balance.amount.toString(),
192
+ formatted: formatUnits(BigInt(balance.amount), balance.decimals)
193
+ },
194
+ chainId: Number(
195
+ // @ts-expect-error - balance.chainId is defined just not typed by enso
196
+ balance.chainId
197
+ ),
198
+ price: Number(balance.price)
199
+ })
200
+ );
201
+ const tokenByChainId = Object.groupBy(tokens, (a) => a.chainId ?? 0);
202
+ const balances = await Promise.allSettled(
203
+ Object.entries(tokenByChainId).map(async ([chainId2, chainTokens]) => {
204
+ if (!chainTokens) return void 0;
205
+ const chainConfig = getChains(wagmiConfig).find(
206
+ (chain) => chain.id === Number(chainId2)
207
+ );
208
+ if (!chainConfig) {
209
+ return void 0;
210
+ }
211
+ const multicall3 = chainConfig.contracts?.multicall3;
212
+ const multicallAddress = multicall3?.address;
213
+ if (!multicallAddress) {
214
+ BeraMonitoring.captureException(
215
+ new InvalidArgumentError({
216
+ property: "multicallAddress",
217
+ value: multicallAddress,
218
+ expected: "Address",
219
+ chainId: Number(chainId2)
220
+ })
221
+ );
222
+ return chainTokens;
223
+ }
224
+ const balances2 = await multicall(wagmiConfig, {
225
+ chainId: Number(chainId2),
226
+ contracts: chainTokens.map(
227
+ (token) => getBalanceCall({
228
+ token,
229
+ account,
230
+ multicallAddress
231
+ })
232
+ ),
233
+ allowFailure: true
234
+ });
235
+ const tokensWithBalances = [];
236
+ for (let index = 0; index < chainTokens.length; index++) {
237
+ const token = chainTokens[index];
238
+ if (balances2[index].status === "success") {
239
+ const balance = balances2[index].result;
240
+ tokensWithBalances.push({
241
+ ...token,
242
+ balance: {
243
+ raw: balance?.toString() ?? "0",
244
+ formatted: formatUnits(balance ?? 0n, token.decimals)
245
+ }
246
+ });
247
+ } else {
248
+ console.error("error getting balance", balances2[index].error);
249
+ BeraMonitoring.captureException(
250
+ initBeraError({ cause: balances2[index].error })
251
+ );
252
+ tokensWithBalances.push(token);
253
+ }
254
+ }
255
+ return tokensWithBalances;
256
+ })
257
+ );
258
+ const flattenedBalances = [];
259
+ for (const result of balances) {
260
+ if (result.status === "fulfilled") {
261
+ flattenedBalances.push(...result.value ?? []);
262
+ } else {
263
+ BeraMonitoring.captureException(initBeraError({ cause: result.reason }));
264
+ }
265
+ }
266
+ return flattenedBalances.sort((a, b) => {
267
+ const aValue = Number(a.balance.formatted) * (a.price ?? 0);
268
+ const bValue = Number(b.balance.formatted) * (b.price ?? 0);
269
+ return bValue - aValue;
270
+ });
271
+ }
272
+
273
+ // src/hooks/enso/useEnsoUserTokensWithBalances.ts
274
+ function useEnsoUserTokensWithBalances({ chainId } = {}, options) {
275
+ const { address: fromAddress } = useBeraWallet();
276
+ const wagmiConfig = useConfig();
277
+ const proxyAggregatorsThroughVercel = useBeraFlag(
278
+ "proxyAggregatorsThroughVercel"
279
+ );
280
+ const isEnabled = !!fromAddress && (options?.opts?.isEnabled ?? true);
281
+ const QUERY_KEY = isEnabled && wagmiConfig ? [
282
+ "useEnsoUserTokensWithBalances",
283
+ fromAddress,
284
+ chainId,
285
+ proxyAggregatorsThroughVercel ?? false
286
+ ] : null;
287
+ const swrResponse = useSWR(
288
+ QUERY_KEY,
289
+ async ([, fromAddress2, chainId2]) => getEnsoUserTokensWithBalances({
290
+ account: fromAddress2,
291
+ wagmiConfig,
292
+ chainId: chainId2 ?? "all",
293
+ ensoClient: getEnsoClient({
294
+ baseURL: proxyAggregatorsThroughVercel ? "/api/enso" : void 0
295
+ })
296
+ }),
297
+ {
298
+ refreshInterval: 1e5 /* NORMAL */,
299
+ isEnabled,
300
+ ...options?.opts
301
+ }
302
+ );
303
+ return {
304
+ ...swrResponse,
305
+ refresh: () => swrResponse.mutate()
306
+ };
307
+ }
308
+
309
+ // src/contexts/TokensProvider.tsx
310
+ import { createContext as createContext5, useMemo } from "react";
311
+ import {
312
+ isFlagEnabled as isFlagEnabled2
313
+ } from "@berachain/config/internal/edge-config";
314
+
315
+ // src/utils/formatTokenList.ts
316
+ function formatTokenList({
317
+ defaultTokenList = [],
318
+ externalList = []
319
+ }) {
320
+ if (defaultTokenList.length === 0) {
321
+ return {
322
+ tokenList: externalList,
323
+ customTokenList: externalList,
324
+ featuredTokenList: []
325
+ };
326
+ }
327
+ const defaultList = defaultTokenList.map((token) => {
328
+ return { ...token, default: true };
329
+ });
330
+ const featuredTokenList = defaultList.filter((token) => {
331
+ return token.tags?.some((tag) => tag === "featured");
332
+ });
333
+ const mergedList = [...defaultList, ...externalList];
334
+ const uniqueList = mergedList.filter(
335
+ (item, index) => mergedList.findIndex((i) => isToken(i, item)) === index
336
+ );
337
+ return {
338
+ tokenList: uniqueList,
339
+ customTokenList: externalList,
340
+ featuredTokenList
341
+ };
342
+ }
343
+
344
+ // src/contexts/TokensProvider.tsx
345
+ import { jsx as jsx5 } from "react/jsx-runtime";
346
+ var TokenContext = createContext5(
347
+ void 0
348
+ );
349
+ function TokensProvider({
350
+ children,
351
+ defaultTokens,
352
+ edgeConfigTokenList,
353
+ userTokens,
354
+ onAddToken,
355
+ onRemoveToken
356
+ }) {
357
+ const { data: ensoTokens, refresh } = useEnsoUserTokensWithBalances();
358
+ const { tokenList = [], featuredTokenList = [] } = useMemo(
359
+ () => formatTokenList({
360
+ defaultTokenList: [
361
+ ...defaultTokens,
362
+ ...edgeConfigTokenList?.filter(
363
+ (token) => isFlagEnabled2(token.enabled)
364
+ )
365
+ ],
366
+ externalList: [
367
+ ...userTokens,
368
+ ...(ensoTokens ?? []).map((t) => ({
369
+ ...t,
370
+ balance: void 0,
371
+ price: void 0
372
+ }))
373
+ ]
374
+ }),
375
+ [defaultTokens, userTokens, edgeConfigTokenList, ensoTokens]
376
+ );
377
+ return /* @__PURE__ */ jsx5(
378
+ TokenContext.Provider,
379
+ {
380
+ value: {
381
+ tokenList,
382
+ userTokens,
383
+ featuredTokens: featuredTokenList,
384
+ ensoTokens,
385
+ onAddToken(tk) {
386
+ onAddToken(tk, { defaultTokens, userTokens, tokenList });
387
+ },
388
+ onRemoveToken,
389
+ refresh: () => {
390
+ refresh();
391
+ }
392
+ },
393
+ children
394
+ }
395
+ );
396
+ }
397
+
398
+ export {
399
+ BeraFlagsProvider,
400
+ useBeraFlags,
401
+ useBeraFlag,
402
+ BexStateContext,
403
+ useBexStatus,
404
+ BexStatusProvider,
405
+ useBlockTime,
406
+ BlockTimeContext,
407
+ BlockTimeProvider,
408
+ HoneyConfigContext,
409
+ HoneyConfigProvider,
410
+ useHoneyConfig,
411
+ useEnsoUserTokensWithBalances,
412
+ TokenContext,
413
+ TokensProvider
414
+ };
@@ -0,0 +1,211 @@
1
+ import {
2
+ parseBaseArgs
3
+ } from "./chunk-75M6TF7M.mjs";
4
+ import {
5
+ BeraTracing
6
+ } from "./chunk-SZ5C44L5.mjs";
7
+ import {
8
+ RequestError
9
+ } from "./chunk-XIYN6AL6.mjs";
10
+ import {
11
+ BeraError
12
+ } from "./chunk-J5I45WGQ.mjs";
13
+
14
+ // src/actions/clients/BeraApolloClient.ts
15
+ import {
16
+ ApolloClient,
17
+ ServerError
18
+ } from "@apollo/client";
19
+ import { appConfig } from "@berachain/config/internal";
20
+ var BeraApolloClient = class extends ApolloClient {
21
+ /**
22
+ * The URL of the endpoint. Used for error reporting only.
23
+ */
24
+ url;
25
+ serviceName;
26
+ constructor(options) {
27
+ super(options);
28
+ this.url = options.url;
29
+ this.serviceName = options.name;
30
+ }
31
+ async query(options) {
32
+ const queryName = getQueryName(options.query);
33
+ const endpoint = {
34
+ url: this.url,
35
+ type: "graphql",
36
+ name: this.serviceName
37
+ };
38
+ const tags = {
39
+ "operation.type": "query",
40
+ "operation.source.name": endpoint.name,
41
+ "operation.source.url": endpoint.url,
42
+ "operation.source.type": endpoint.type,
43
+ "operation.source.queryName": queryName
44
+ };
45
+ try {
46
+ const executeQuery = () => super.query(
47
+ options
48
+ );
49
+ const res = await BeraTracing.startSpan(
50
+ {
51
+ name: `GraphQL ${queryName}`,
52
+ op: "BeraApolloClient.query",
53
+ attributes: tags
54
+ },
55
+ executeQuery
56
+ );
57
+ if (res.error || res.data === void 0) {
58
+ throw new BeraError({
59
+ level: "fatal",
60
+ tags,
61
+ message: "Bera Apollo Client: No data returned from query, but error should be thrown since errorPolicy is none"
62
+ });
63
+ }
64
+ return { data: res.data };
65
+ } catch (error) {
66
+ !appConfig.env.isProduction && console.error("BeraApolloClient error", error);
67
+ if (ServerError.is(error)) {
68
+ throw new RequestError({
69
+ // reason: error,
70
+ response: error.response,
71
+ cause: error,
72
+ statusCode: error.statusCode,
73
+ endpoint,
74
+ tags
75
+ });
76
+ }
77
+ if (error instanceof TypeError) {
78
+ throw new RequestError({
79
+ level: "fatal",
80
+ reason: "TypeError",
81
+ response: error,
82
+ cause: error,
83
+ endpoint,
84
+ tags
85
+ });
86
+ }
87
+ throw new RequestError({
88
+ response: error,
89
+ tags,
90
+ cause: error,
91
+ endpoint
92
+ });
93
+ }
94
+ }
95
+ };
96
+ function getQueryName(queryDefinition) {
97
+ const likelyNode = queryDefinition.definitions.find(
98
+ (def) => def.kind === "OperationDefinition"
99
+ );
100
+ return likelyNode?.name?.value;
101
+ }
102
+
103
+ // src/actions/clients/getApolloClient.ts
104
+ import { InMemoryCache } from "@apollo/client";
105
+ import { HttpLink } from "@apollo/client/link/http";
106
+ import { getUriFromLink } from "@berachain/config";
107
+ import { currentDapp, goldskyBaseUrl } from "@berachain/config/internal";
108
+ import apiResults from "@berachain/graphql/dex/api";
109
+ import { gql } from "@apollo/client";
110
+ function applyStellateClientName(url) {
111
+ const headers = typeof url === "string" ? void 0 : url.headers;
112
+ const isDapp = !!currentDapp;
113
+ const isTest = process.env.VERCEL_ENV === "test";
114
+ const uri = getUriFromLink(url);
115
+ const name = typeof url === "string" ? "unknown" : url.name;
116
+ return {
117
+ uri,
118
+ name,
119
+ headers: {
120
+ ...headers,
121
+ "x-graphql-client-name": `berachain.${isDapp ? "dapps" : isTest ? "test" : (
122
+ // this tracks usage of the berajs package in other packages
123
+ "berajs"
124
+ )}`,
125
+ "x-graphql-client-version": `${process.env.VERCEL_TARGET_ENV}.${process.env.VERCEL_GIT_COMMIT_SHA}`
126
+ }
127
+ };
128
+ }
129
+ function getClient(endpoint, {
130
+ ssrMode,
131
+ inMemoryCacheOptions
132
+ } = {}) {
133
+ const url = getUriFromLink(endpoint);
134
+ const headers = typeof endpoint === "string" ? void 0 : endpoint.headers;
135
+ let name = typeof endpoint === "string" ? void 0 : endpoint.name;
136
+ if (!name && url.includes(goldskyBaseUrl)) {
137
+ name = url.replace(goldskyBaseUrl, "").replace("/gn", "");
138
+ }
139
+ return new BeraApolloClient({
140
+ url,
141
+ name: name ?? "unknown",
142
+ link: new HttpLink({
143
+ uri: url,
144
+ headers
145
+ }),
146
+ defaultOptions: {
147
+ query: {
148
+ // With the default none error policy, an error causes the promise to reject.
149
+ errorPolicy: "none",
150
+ fetchPolicy: "no-cache"
151
+ }
152
+ },
153
+ cache: new InMemoryCache(inMemoryCacheOptions),
154
+ ssrMode
155
+ });
156
+ }
157
+ var SUBGRAPH_CLIENTS = [
158
+ "honey.subgraph",
159
+ "pol.subgraph"
160
+ ];
161
+ function isSubgraphClient(name) {
162
+ return SUBGRAPH_CLIENTS.includes(name);
163
+ }
164
+ var clientCache = /* @__PURE__ */ new Map();
165
+ function store(cacheKey, client) {
166
+ if (cacheKey) clientCache.set(cacheKey, client);
167
+ return client;
168
+ }
169
+ function getApolloClient(clientName, { ...args }) {
170
+ if (typeof window !== "undefined" && isSubgraphClient(clientName)) {
171
+ throw new BeraError({
172
+ message: "Subgraph Apollo client is server-only",
173
+ level: "error"
174
+ });
175
+ }
176
+ const { config, chainId } = parseBaseArgs(args);
177
+ const cacheKey = args.config ? null : `${chainId}:${clientName}`;
178
+ if (cacheKey) {
179
+ const cached = clientCache.get(cacheKey);
180
+ if (cached) return cached;
181
+ }
182
+ switch (clientName) {
183
+ case "api":
184
+ return store(
185
+ cacheKey,
186
+ getClient(applyStellateClientName(config.api), {
187
+ inMemoryCacheOptions: {
188
+ possibleTypes: apiResults.possibleTypes
189
+ }
190
+ })
191
+ );
192
+ case "bend.whisk":
193
+ if (!config.bend.whiskApi) {
194
+ throw new BeraError({
195
+ message: "Bend whisk API is not configured on this chain",
196
+ level: "error"
197
+ });
198
+ }
199
+ return store(cacheKey, getClient(config.bend.whiskApi));
200
+ case "honey.subgraph":
201
+ return store(cacheKey, getClient(config.honey.subgraph));
202
+ case "pol.subgraph":
203
+ return store(cacheKey, getClient(config.pol.subgraph));
204
+ }
205
+ }
206
+
207
+ export {
208
+ BeraApolloClient,
209
+ getApolloClient,
210
+ gql
211
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ InvalidArgumentError
3
+ } from "./chunk-J5I45WGQ.mjs";
4
+
5
+ // src/utils/parseBaseArgs.ts
6
+ import {
7
+ chainConfigs,
8
+ defaultChainId
9
+ } from "@berachain/config/internal";
10
+ function parseBaseArgs(args) {
11
+ const chainId = args.chainId ?? defaultChainId;
12
+ const config = args.config ?? chainConfigs[chainId];
13
+ if (args.chainId && args.chainId !== config.chainId) {
14
+ throw new InvalidArgumentError({
15
+ property: "chainId",
16
+ value: chainId,
17
+ expected: `config.chainId: ${config.chainId}`
18
+ });
19
+ }
20
+ return { config, chainId: config.chainId };
21
+ }
22
+
23
+ export {
24
+ parseBaseArgs
25
+ };