@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
@@ -1,34 +1,33 @@
1
1
  import type { Address } from "viem";
2
2
 
3
- import {
4
- GetValidatorAnalytics,
5
- type GetValidatorAnalyticsQuery,
6
- type GetValidatorAnalyticsQueryVariables,
7
- } from "@berachain/graphql/pol/subgraph";
3
+ import type { GetValidatorAnalyticsQuery } from "@berachain/graphql/pol/subgraph";
8
4
 
9
- import { calculateTimestampFromDays } from "../../utils/formatTimestamps";
10
- import { getApolloClient } from "../clients/getApolloClient";
5
+ import { BeraError } from "../../errors/BeraError";
6
+ import { beraFetchJson } from "../../utils/beraFetch";
11
7
 
8
+ /** Browser-only. Hits `/api/pol/validator-analytics`. */
12
9
  export async function getValidatorAnalytics({
13
10
  pubkey,
14
11
  dayRange,
15
- ...args
16
- }: BeraJS.BaseFunctionArgs & {
12
+ }: {
17
13
  pubkey: Address;
18
14
  dayRange: number;
19
15
  }): Promise<GetValidatorAnalyticsQuery | undefined> {
20
- const bgtClient = getApolloClient("pol.subgraph", args);
16
+ if (typeof window === "undefined") {
17
+ throw new BeraError({
18
+ message:
19
+ "getValidatorAnalytics is browser-only; call from a Client Component / SWR hook",
20
+ level: "error",
21
+ });
22
+ }
21
23
 
22
- const result = await bgtClient.query<
23
- GetValidatorAnalyticsQuery,
24
- GetValidatorAnalyticsQueryVariables
25
- >({
26
- query: GetValidatorAnalytics,
27
- variables: {
28
- pubKey: pubkey,
29
- timestamp: calculateTimestampFromDays(dayRange).toString(),
30
- },
24
+ const params = new URLSearchParams({
25
+ pubkey,
26
+ dayRange: String(dayRange),
27
+ });
28
+ return beraFetchJson<GetValidatorAnalyticsQuery>({
29
+ url: `/api/pol/validator-analytics?${params}`,
30
+ name: "pol-validator-analytics",
31
+ type: "rest",
31
32
  });
32
-
33
- return result.data;
34
33
  }
@@ -0,0 +1,33 @@
1
+ import type { Address } from "viem";
2
+
3
+ import type { GetValidatorIncentiveDistributionQuery } from "@berachain/graphql/pol/subgraph";
4
+
5
+ import { BeraError } from "../../errors/BeraError";
6
+ import { beraFetchJson } from "../../utils/beraFetch";
7
+
8
+ /** Browser-only. Hits `/api/pol/validator-incentive-distribution`. */
9
+ export async function getValidatorIncentiveDistribution({
10
+ pubkey,
11
+ dayRange,
12
+ }: {
13
+ pubkey: Address;
14
+ dayRange: number;
15
+ }): Promise<GetValidatorIncentiveDistributionQuery | undefined> {
16
+ if (typeof window === "undefined") {
17
+ throw new BeraError({
18
+ message:
19
+ "getValidatorIncentiveDistribution is browser-only; call from a Client Component / SWR hook",
20
+ level: "error",
21
+ });
22
+ }
23
+
24
+ const params = new URLSearchParams({
25
+ pubkey,
26
+ dayRange: String(dayRange),
27
+ });
28
+ return beraFetchJson<GetValidatorIncentiveDistributionQuery>({
29
+ url: `/api/pol/validator-incentive-distribution?${params}`,
30
+ name: "pol-validator-incentive-distribution",
31
+ type: "rest",
32
+ });
33
+ }
@@ -4,6 +4,7 @@
4
4
  export enum ContractName {
5
5
  ENSO_ROUTER = "enso.router",
6
6
  POL_REWARD_VAULT = "pol.rewardVault",
7
+ POL_REWARD_VAULT_HELPER = "pol.rewardVaultHelper",
7
8
  BEX_POOL = "bex.pool",
8
9
  ERC20 = "others.erc20",
9
10
  ERC4626 = "others.erc4626",
@@ -1,6 +1,5 @@
1
1
  export * from "./contracts";
2
2
  export * from "./dex";
3
- export * from "./governance";
4
3
  export * from "./honey";
5
4
  export * from "./polling";
6
5
  export * from "./slippage";
@@ -0,0 +1 @@
1
+ export * from "../governance";
@@ -6,6 +6,7 @@ import { GENERAL_ERROR } from "./errorMap";
6
6
  import { findMatchingError } from "./getErrorMessage";
7
7
  import { parseViemError, rpcErrorToReason } from "./parseViemError";
8
8
  import type { SeverityLevel } from "./severity";
9
+ import { reasonToSpanStatus, type SpanStatusType } from "./spanStatus";
9
10
 
10
11
  export interface IBeraErrorArgs {
11
12
  message?: string;
@@ -26,6 +27,12 @@ export interface IBeraErrorArgs {
26
27
  * Optional ABI to be used to parse the error.
27
28
  */
28
29
  abi?: Abi;
30
+ /**
31
+ * Span status for tracing. When set, the tracing adapter uses this to
32
+ * set the span status instead of a generic "internal_error".
33
+ * Auto-inferred from `reason` when not explicitly provided.
34
+ */
35
+ spanStatus?: SpanStatusType;
29
36
  }
30
37
 
31
38
  type Primitive = number | string | boolean | bigint | symbol | null | undefined;
@@ -123,6 +130,12 @@ export class BeraError extends Error {
123
130
 
124
131
  level: SeverityLevel = "error";
125
132
 
133
+ /**
134
+ * Span status for tracing providers.
135
+ * Auto-inferred from `reason` when not explicitly provided.
136
+ */
137
+ spanStatus?: SpanStatusType;
138
+
126
139
  extra: Record<string, unknown> = {};
127
140
 
128
141
  constructor({
@@ -135,6 +148,7 @@ export class BeraError extends Error {
135
148
  tags,
136
149
  chainId,
137
150
  fingerprint,
151
+ spanStatus,
138
152
  }: IBeraErrorArgs) {
139
153
  let message = m;
140
154
 
@@ -200,6 +214,19 @@ export class BeraError extends Error {
200
214
  this.level = "error";
201
215
  }
202
216
 
217
+ // ── Span status inference ───────────────────────────────────────────
218
+ // Priority:
219
+ // 1. Explicit `spanStatus` from caller
220
+ // 2. Cascaded from a BeraError cause
221
+ // 3. Auto-inferred from `reason` via reasonToSpanStatus()
222
+ if (spanStatus) {
223
+ this.spanStatus = spanStatus;
224
+ } else if (this.cause instanceof BeraError && this.cause.spanStatus) {
225
+ this.spanStatus = this.cause.spanStatus;
226
+ } else {
227
+ this.spanStatus = reasonToSpanStatus(this.reason);
228
+ }
229
+
203
230
  // ── displayMessage resolution ─────────────────────────────────────────
204
231
  // Priority:
205
232
  // 1. Explicit `displayMessage` passed by caller
@@ -243,13 +270,26 @@ export class BeraError extends Error {
243
270
  (process.env.NEXT_PUBLIC_IS_MONOBERA === "true" || currentDapp) &&
244
271
  process.env.NODE_ENV !== "test"
245
272
  ) {
246
- console.group("BeraError thrown");
247
- console.debug("Level", this.level);
248
- console.debug("Reason", this.reason);
249
- console.debug("Message", this.message);
250
- console.debug("Display Message", this.displayMessage);
251
- console.debug("Cause", this.cause);
252
- console.groupEnd();
273
+ // `console.group`/`groupEnd` are not implemented in Vercel's edge
274
+ // runtime — calling them there throws a TypeError which masks the
275
+ // original error. Fall back to a single debug line in that case.
276
+ if (typeof console.group === "function") {
277
+ console.group("BeraError thrown");
278
+ console.debug("Level", this.level);
279
+ console.debug("Reason", this.reason);
280
+ console.debug("Message", this.message);
281
+ console.debug("Display Message", this.displayMessage);
282
+ console.debug("Cause", this.cause);
283
+ console.groupEnd();
284
+ } else {
285
+ console.debug("BeraError thrown", {
286
+ level: this.level,
287
+ reason: this.reason,
288
+ message: this.message,
289
+ displayMessage: this.displayMessage,
290
+ cause: this.cause,
291
+ });
292
+ }
253
293
  }
254
294
  }
255
295
  }
@@ -165,6 +165,71 @@ describe("BeraTracing", () => {
165
165
  });
166
166
  });
167
167
 
168
+ describe("span status adapter pattern", () => {
169
+ it("adapter handler can read spanStatus from BeraError", async () => {
170
+ const { BeraError } = await import("./BeraError.js");
171
+ const statuses: string[] = [];
172
+
173
+ // Simulates the Sentry adapter wrapper pattern
174
+ const adapterHandler = async (
175
+ _ctx: any,
176
+ callback: () => Promise<any>,
177
+ ) => {
178
+ try {
179
+ const result = await callback();
180
+ statuses.push("ok");
181
+ return result;
182
+ } catch (error) {
183
+ const status =
184
+ error instanceof BeraError && error.spanStatus
185
+ ? error.spanStatus
186
+ : "internal_error";
187
+ statuses.push(status);
188
+ throw error;
189
+ }
190
+ };
191
+
192
+ const unsub = BeraTracing.addSpanHandler(adapterHandler);
193
+
194
+ // Test: error with spanStatus propagates through
195
+ await expect(
196
+ BeraTracing.startSpan(
197
+ { name: "test", op: "test.op", attributes: {} },
198
+ async () => {
199
+ throw new BeraError({
200
+ message: "user cancelled",
201
+ reason: "UserRejectedRequestError",
202
+ });
203
+ },
204
+ ),
205
+ ).rejects.toThrow("user cancelled");
206
+
207
+ expect(statuses).toEqual(["cancelled"]);
208
+
209
+ // Test: success sets ok
210
+ statuses.length = 0;
211
+ await BeraTracing.startSpan(
212
+ { name: "test", op: "test.op", attributes: {} },
213
+ async () => "done",
214
+ );
215
+ expect(statuses).toEqual(["ok"]);
216
+
217
+ // Test: non-BeraError defaults to internal_error
218
+ statuses.length = 0;
219
+ await expect(
220
+ BeraTracing.startSpan(
221
+ { name: "test", op: "test.op", attributes: {} },
222
+ async () => {
223
+ throw new Error("plain error");
224
+ },
225
+ ),
226
+ ).rejects.toThrow("plain error");
227
+ expect(statuses).toEqual(["internal_error"]);
228
+
229
+ unsub();
230
+ });
231
+ });
232
+
168
233
  describe("Sentry.startSpan compatibility", () => {
169
234
  it("works with a handler that accepts (options, callback) like Sentry.startSpan", async () => {
170
235
  // Sentry.startSpan signature: <T>(options, callback: (span) => T) => T
@@ -5,6 +5,7 @@ import { mainnet } from "@berachain/config/mainnet";
5
5
 
6
6
  import { BeraError, type IBeraErrorArgs } from "./BeraError";
7
7
  import { errorMsgMap } from "./errorMap";
8
+ import { httpStatusToSpanStatus, reasonToSpanStatus } from "./spanStatus";
8
9
 
9
10
  /**
10
11
  * This is an error class that should be used to handle errors from fetch requests.
@@ -37,7 +38,7 @@ export class RequestError extends BeraError {
37
38
  // vercel internal proxy
38
39
  "/api/aggregators?aggregator",
39
40
  // bonder endpoints have date-based query params (e.g. ?start=2025-11-28)
40
- mainnet.staking,
41
+ mainnet.backend,
41
42
  ];
42
43
 
43
44
  statusCode: number | undefined;
@@ -104,6 +105,17 @@ export class RequestError extends BeraError {
104
105
  }
105
106
  }
106
107
 
108
+ // ── Span status inference ─────────────────────────────────────────
109
+ // Re-infer from reason since it may have been set after super() ran
110
+ // (e.g. NETWORK_ERROR → unavailable, RATE_LIMITED_429 → resource_exhausted).
111
+ if (!this.spanStatus && this.reason) {
112
+ this.spanStatus = reasonToSpanStatus(this.reason);
113
+ }
114
+ // Fall back to HTTP status code mapping when no reason-based status.
115
+ if (!this.spanStatus && this.statusCode) {
116
+ this.spanStatus = httpStatusToSpanStatus(this.statusCode);
117
+ }
118
+
107
119
  this.tags = {
108
120
  ...this.tags,
109
121
  "error.statusCode": this.statusCode,
@@ -12,4 +12,9 @@ export * from "./initBeraError";
12
12
  export * from "./NotFoundError";
13
13
  export * from "./RequestError";
14
14
  export type { SeverityLevel } from "./severity";
15
+ export {
16
+ httpStatusToSpanStatus,
17
+ reasonToSpanStatus,
18
+ type SpanStatusType,
19
+ } from "./spanStatus";
15
20
  export * from "./TransactionFailedError";
@@ -29,6 +29,7 @@ import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
29
29
 
30
30
  import { getConfig } from "@berachain/wagmi/config";
31
31
 
32
+ import { testTransports } from "../actions/__test/transports";
32
33
  import { beraWriteContract } from "../actions/transactions/beraWriteContract";
33
34
  import { ContractName } from "../enum/contracts";
34
35
  import { TransactionActionType } from "../enum/txnEnum";
@@ -414,10 +415,9 @@ describe("eip5972 transactions", () => {
414
415
  account: anvilMockAccount,
415
416
  chain: publicClient.chain!,
416
417
  });
418
+
417
419
  const beraWagmiConfig = getConfig({
418
- transports: {
419
- [publicClient.chain!.id]: http(getRpcUrls().publicJsonRpcUrl),
420
- },
420
+ transports: testTransports,
421
421
  defaultChain: publicClient.chain!,
422
422
  thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
423
423
  });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Span status codes for tracing.
3
+ * Mirrors Sentry's SpanStatusType for compatibility, but owned by berajs
4
+ * so we don't depend on @sentry/nextjs.
5
+ *
6
+ * @see https://develop.sentry.dev/sdk/foundations/transport/event-payloads/span/
7
+ */
8
+ export type SpanStatusType =
9
+ | "ok"
10
+ | "cancelled"
11
+ | "unknown_error"
12
+ | "invalid_argument"
13
+ | "deadline_exceeded"
14
+ | "not_found"
15
+ | "already_exists"
16
+ | "permission_denied"
17
+ | "resource_exhausted"
18
+ | "failed_precondition"
19
+ | "aborted"
20
+ | "out_of_range"
21
+ | "unimplemented"
22
+ | "internal_error"
23
+ | "unavailable"
24
+ | "data_loss"
25
+ | "unauthenticated";
26
+
27
+ /**
28
+ * Maps an HTTP status code to a span status.
29
+ */
30
+ export function httpStatusToSpanStatus(code: number): SpanStatusType {
31
+ if (code >= 200 && code < 300) return "ok";
32
+ switch (code) {
33
+ case 400:
34
+ return "invalid_argument";
35
+ case 401:
36
+ return "unauthenticated";
37
+ case 403:
38
+ return "permission_denied";
39
+ case 404:
40
+ return "not_found";
41
+ case 409:
42
+ return "already_exists";
43
+ case 429:
44
+ return "resource_exhausted";
45
+ case 499:
46
+ return "cancelled";
47
+ case 501:
48
+ return "unimplemented";
49
+ case 503:
50
+ return "unavailable";
51
+ case 504:
52
+ return "deadline_exceeded";
53
+ default:
54
+ return code >= 500 ? "internal_error" : "unknown_error";
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Maps a BeraError reason code to a span status.
60
+ * Returns undefined if no mapping exists (caller keeps existing spanStatus).
61
+ */
62
+ export function reasonToSpanStatus(
63
+ reason: string | null,
64
+ ): SpanStatusType | undefined {
65
+ switch (reason) {
66
+ case "UserRejectedRequestError":
67
+ case "AtomicReadyWalletRejectedUpgradeError":
68
+ return "cancelled";
69
+ case "NO_SWAP_PATHS":
70
+ return "not_found";
71
+ case "RATE_LIMITED_429":
72
+ return "resource_exhausted";
73
+ case "NETWORK_ERROR":
74
+ return "unavailable";
75
+ default:
76
+ return undefined;
77
+ }
78
+ }
@@ -0,0 +1,62 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { httpStatusToSpanStatus, reasonToSpanStatus } from "./spanStatus.js";
4
+
5
+ describe("httpStatusToSpanStatus", () => {
6
+ it("maps 2xx to ok", () => {
7
+ expect(httpStatusToSpanStatus(200)).toBe("ok");
8
+ expect(httpStatusToSpanStatus(201)).toBe("ok");
9
+ expect(httpStatusToSpanStatus(204)).toBe("ok");
10
+ });
11
+
12
+ it("maps specific 4xx codes", () => {
13
+ expect(httpStatusToSpanStatus(400)).toBe("invalid_argument");
14
+ expect(httpStatusToSpanStatus(401)).toBe("unauthenticated");
15
+ expect(httpStatusToSpanStatus(403)).toBe("permission_denied");
16
+ expect(httpStatusToSpanStatus(404)).toBe("not_found");
17
+ expect(httpStatusToSpanStatus(409)).toBe("already_exists");
18
+ expect(httpStatusToSpanStatus(429)).toBe("resource_exhausted");
19
+ expect(httpStatusToSpanStatus(499)).toBe("cancelled");
20
+ });
21
+
22
+ it("maps specific 5xx codes", () => {
23
+ expect(httpStatusToSpanStatus(500)).toBe("internal_error");
24
+ expect(httpStatusToSpanStatus(501)).toBe("unimplemented");
25
+ expect(httpStatusToSpanStatus(503)).toBe("unavailable");
26
+ expect(httpStatusToSpanStatus(504)).toBe("deadline_exceeded");
27
+ });
28
+
29
+ it("maps unknown 4xx to unknown_error", () => {
30
+ expect(httpStatusToSpanStatus(418)).toBe("unknown_error");
31
+ });
32
+
33
+ it("maps unknown 5xx to internal_error", () => {
34
+ expect(httpStatusToSpanStatus(502)).toBe("internal_error");
35
+ });
36
+ });
37
+
38
+ describe("reasonToSpanStatus", () => {
39
+ it("maps user rejection reasons to cancelled", () => {
40
+ expect(reasonToSpanStatus("UserRejectedRequestError")).toBe("cancelled");
41
+ expect(reasonToSpanStatus("AtomicReadyWalletRejectedUpgradeError")).toBe(
42
+ "cancelled",
43
+ );
44
+ });
45
+
46
+ it("maps NO_SWAP_PATHS to not_found", () => {
47
+ expect(reasonToSpanStatus("NO_SWAP_PATHS")).toBe("not_found");
48
+ });
49
+
50
+ it("maps RATE_LIMITED_429 to resource_exhausted", () => {
51
+ expect(reasonToSpanStatus("RATE_LIMITED_429")).toBe("resource_exhausted");
52
+ });
53
+
54
+ it("maps NETWORK_ERROR to unavailable", () => {
55
+ expect(reasonToSpanStatus("NETWORK_ERROR")).toBe("unavailable");
56
+ });
57
+
58
+ it("returns undefined for unknown reasons", () => {
59
+ expect(reasonToSpanStatus("SomeOtherError")).toBeUndefined();
60
+ expect(reasonToSpanStatus(null)).toBeUndefined();
61
+ });
62
+ });
@@ -1,23 +1,9 @@
1
1
  import { useMemo } from "react";
2
2
  import { PoolType } from "@berachain-foundation/berancer-sdk";
3
- import useSWRImmutable from "swr/immutable";
4
- import {
5
- type Address,
6
- formatUnits,
7
- keccak256,
8
- parseUnits,
9
- zeroAddress,
10
- } from "viem";
3
+ import { type Address, keccak256, parseUnits, zeroAddress } from "viem";
11
4
 
12
5
  import { poolCreationHelperAbi as balancerPoolCreationHelperAbi } from "@berachain/abis/bex/poolCreationHelper";
13
6
 
14
- import {
15
- GetDedupedSubgraphPools,
16
- type GetDedupedSubgraphPoolsQuery,
17
- type SubgraphPoolFragment,
18
- } from "@berachain/graphql/dex/subgraph";
19
-
20
- import { getApolloClient } from "../../actions/clients/getApolloClient";
21
7
  import { TransactionActionType } from "../../enum/txnEnum";
22
8
  import type { Token, TokenWithAmount } from "../../types/dex";
23
9
  import type { IContractWrite } from "../../types/global";
@@ -25,9 +11,7 @@ import { DEFAULT_METAMASK_GAS_LIMIT } from "../../utils/constants";
25
11
  import { parseBaseArgs } from "../../utils/parseBaseArgs";
26
12
  import { generatePoolName, generatePoolSymbol } from "../../utils/poolNamings";
27
13
  import { isToken } from "../../utils/tokens";
28
- import { wrapNativeTokens } from "../../utils/tokenWrapping";
29
14
 
30
- const DEFAULT_WEIGHTS_DUPLICATION_THRESHOLD = 0.005;
31
15
  interface UseCreatePoolProps extends BeraJS.BaseFunctionArgs {
32
16
  poolCreateTokens: Token[];
33
17
  initialLiquidityTokens: TokenWithAmount[];
@@ -38,17 +22,12 @@ interface UseCreatePoolProps extends BeraJS.BaseFunctionArgs {
38
22
  poolSymbol: string;
39
23
  poolName: string;
40
24
  amplification: number;
41
- weightsDuplicationThreshold?: number;
42
25
  oracles: Oracle[]; // NOTE: the default state for oracles should be 0x0 address for each token with cache duration of ~100
43
26
  }
44
27
  interface UseCreatePoolReturn {
45
28
  generatedPoolName: string;
46
29
  generatedPoolSymbol: string;
47
- isDupePool: boolean;
48
- dupePool?: SubgraphPoolFragment | null;
49
30
  createPoolArgs: any;
50
- isLoadingPools: boolean;
51
- errorLoadingPools: boolean;
52
31
  }
53
32
 
54
33
  export enum OracleMode {
@@ -276,70 +255,8 @@ export const useCreatePool = ({
276
255
  owner,
277
256
  amplification,
278
257
  oracles,
279
- weightsDuplicationThreshold = DEFAULT_WEIGHTS_DUPLICATION_THRESHOLD,
280
258
  ...baseArgs
281
259
  }: UseCreatePoolProps): UseCreatePoolReturn => {
282
- // 1. identify if the pool is a duplicate
283
- const {
284
- data: dupePool,
285
- error: errorLoadingPools,
286
- isLoading: isLoadingPools,
287
- } = useSWRImmutable<SubgraphPoolFragment | null>(
288
- [
289
- "useCreatePool__deduped_pool",
290
- poolCreateTokens,
291
- poolType,
292
- normalizedWeights,
293
- ],
294
- async () => {
295
- if (poolCreateTokens.length === 0 || !poolType) {
296
- return null;
297
- }
298
- const bexSubgraphClient = getApolloClient("bex.subgraph", {});
299
- try {
300
- // NOTE: it should not be possible for native token to be in poolCreateTokens
301
- const tokensSorted = wrapNativeTokens(poolCreateTokens)
302
- .map((token) => token.address.toLowerCase())
303
- .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1));
304
-
305
- // fetch pools of the same type as the one we are creating
306
- const res = await bexSubgraphClient.query<GetDedupedSubgraphPoolsQuery>(
307
- {
308
- query: GetDedupedSubgraphPools,
309
- variables: {
310
- tokens: tokensSorted,
311
- type: poolType,
312
- },
313
- },
314
- );
315
-
316
- const matchingPools = res.data.pools.filter((pool) => {
317
- return pool.tokens?.every((token) =>
318
- poolType === PoolType.Weighted
319
- ? // in weighted pools, a dupe is if tokens and weights match within tolerance FIXME: we aren't getting weighted pools returned here
320
- tokensSorted.includes(token.address) &&
321
- Math.abs(
322
- Number(token.weight) -
323
- Number(
324
- formatUnits(
325
- normalizedWeights[tokensSorted.indexOf(token.address)],
326
- 18,
327
- ),
328
- ),
329
- ) < weightsDuplicationThreshold
330
- : // in composable pools a dupe is if the tokens match, handling that the LP token is in the tokens list
331
- tokensSorted.includes(token.address) ||
332
- token.address === pool.address,
333
- );
334
- });
335
-
336
- return matchingPools?.at(0) ?? null;
337
- } catch {
338
- return null;
339
- }
340
- },
341
- );
342
-
343
260
  // Generated names
344
261
  const { generatedPoolName, generatedPoolSymbol } = useMemo(() => {
345
262
  if (!poolCreateTokens) {
@@ -430,10 +347,6 @@ export const useCreatePool = ({
430
347
  return {
431
348
  generatedPoolName,
432
349
  generatedPoolSymbol,
433
- isDupePool: !!dupePool,
434
- dupePool,
435
350
  createPoolArgs,
436
- isLoadingPools,
437
- errorLoadingPools,
438
351
  };
439
352
  };
@@ -2,10 +2,10 @@ import { useMemo } from "react";
2
2
  import useSWRImmutable from "swr/immutable";
3
3
  import { type Address, formatUnits, isAddress } from "viem";
4
4
 
5
- import type { SubgraphPoolFragment } from "@berachain/graphql/dex/subgraph";
6
5
  import { usePublicClient } from "@berachain/wagmi/hooks";
7
6
 
8
7
  import { getOnChainPool } from "../../actions/dex/getOnChainPool";
8
+ import type { TokenPriceInfo } from "../../types/dex";
9
9
  import { useMultipleTokenInformation } from "../tokens/useMultipleTokenInformation";
10
10
  import { useTokenCurrentPrices } from "../tokens/useTokenCurrentPrices";
11
11
 
@@ -21,7 +21,32 @@ export function useOnChainPoolDataQueryKey(
21
21
  return isValid && address ? (["useOnChainPoolData", address] as const) : null;
22
22
  }
23
23
 
24
- export interface OnChainPoolFragment extends SubgraphPoolFragment {
24
+ interface OnChainPoolToken {
25
+ address: Address;
26
+ name: string;
27
+ decimals: number;
28
+ symbol: string;
29
+ index: number;
30
+ weight?: string;
31
+ balance: string;
32
+ token: {
33
+ __typename: "Token";
34
+ token: { address: Address; name: string; decimals: number; symbol: string };
35
+ latestUSDPrice: TokenPriceInfo | undefined;
36
+ };
37
+ }
38
+
39
+ export interface OnChainPoolFragment {
40
+ id: string;
41
+ name: string;
42
+ address: Address;
43
+ factory: Address;
44
+ swapFee: string;
45
+ totalShares: string;
46
+ totalLiquidity: string;
47
+ createTime: number;
48
+ type: string;
49
+ tokens: OnChainPoolToken[];
25
50
  // Reference: https://github.com/balancer/docs-developers/blob/main/references/valuing-balancer-lp-tokens/pools/stablepools.md#getamplificationparameter
26
51
  amplificationParameter:
27
52
  | {