@berachain/berajs 0.2.8-beta.8 → 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 (225) 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-DBOIV65x.d.ts +144 -0
  4. package/dist/abi/exports.mjs +3 -4
  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 +108 -187
  8. package/dist/actions/exports.mjs +97 -158
  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-VA3BQ34H.mjs → chunk-3EARVV7K.mjs} +20 -9
  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-7TFV6UKF.mjs → chunk-BGMRHTBQ.mjs} +0 -1
  18. package/dist/{chunk-3M47ZRXT.mjs → chunk-CDFWPU2R.mjs} +73 -17
  19. package/dist/{chunk-GWSTVITN.mjs → chunk-CDK4YV3D.mjs} +0 -1
  20. package/dist/{chunk-KL6YZ5VR.mjs → chunk-DKMAIU74.mjs} +0 -1
  21. package/dist/chunk-EXIUPSFN.mjs +86 -0
  22. package/dist/{chunk-VA5L5FDG.mjs → chunk-FFB5LFDW.mjs} +2 -3
  23. package/dist/{chunk-ZCEFC2TK.mjs → chunk-HQCOU6GY.mjs} +0 -1
  24. package/dist/{chunk-SGZP4O6R.mjs → chunk-HSSJKHZ4.mjs} +11 -11
  25. package/dist/{chunk-7QKRRIHI.mjs → chunk-J5I45WGQ.mjs} +77 -152
  26. package/dist/chunk-KQUMKB66.mjs +89 -0
  27. package/dist/{chunk-JA4DHMTG.mjs → chunk-NBYLMO2L.mjs} +0 -1
  28. package/dist/{chunk-4GFN4LEP.mjs → chunk-NPBQLVL3.mjs} +4 -21
  29. package/dist/{chunk-I3FTWD6I.mjs → chunk-O2NQFKJK.mjs} +1 -1
  30. package/dist/{chunk-2R73G2PO.mjs → chunk-QJIXTYTZ.mjs} +121 -765
  31. package/dist/{chunk-GLWPRM33.mjs → chunk-SGIJVHZO.mjs} +0 -1
  32. package/dist/chunk-SZ5C44L5.mjs +35 -0
  33. package/dist/{chunk-5NMATIH4.mjs → chunk-WXXOISTU.mjs} +1 -35
  34. package/dist/chunk-XIYN6AL6.mjs +160 -0
  35. package/dist/contexts/exports.d.ts +2 -2
  36. package/dist/contexts/exports.mjs +11 -9
  37. package/dist/enum/exports.d.ts +1 -1
  38. package/dist/enum/exports.mjs +3 -16
  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 +5 -90
  42. package/dist/errors/exports.mjs +19 -10
  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 +80 -236
  47. package/dist/hooks/exports.mjs +609 -1508
  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 +24 -7
  58. package/dist/utils/exports.mjs +49 -11
  59. package/package.json +60 -13
  60. package/src/actions/__test/transports.ts +61 -0
  61. package/src/actions/clients/BeraApolloClient.ts +9 -0
  62. package/src/actions/clients/exports.ts +4 -0
  63. package/src/actions/clients/getApolloClient.ts +70 -25
  64. package/src/actions/clients/getEnsoClient.ts +20 -9
  65. package/src/actions/dex/aggregators/base.ts +1 -1
  66. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  67. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  68. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  69. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  70. package/src/actions/exports.ts +5 -10
  71. package/src/actions/governance/exports.ts +9 -0
  72. package/src/actions/governance/getAllProposals.ts +10 -65
  73. package/src/actions/governance/getProposalDetails.ts +6 -33
  74. package/src/actions/governance/getProposalVotes.ts +8 -15
  75. package/src/actions/honey/getChartData.ts +27 -21
  76. package/src/actions/honey/getHoney24hVolume.ts +27 -0
  77. package/src/actions/pol/getAutoclaimedIncentives.ts +30 -0
  78. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  79. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +35 -0
  80. package/src/actions/pol/getEarnedStakedBeraVault.ts +15 -9
  81. package/src/actions/pol/getGlobalData.ts +1 -0
  82. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  83. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  84. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  85. package/src/actions/pol/getStakingDailyAssets.ts +11 -8
  86. package/src/actions/server/exports.ts +1 -0
  87. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  88. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  89. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  90. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  91. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  92. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  93. package/src/data/contracts.ts +5 -0
  94. package/src/enum/contracts.ts +1 -0
  95. package/src/enum/exports.ts +0 -1
  96. package/src/enum/governance/exports.ts +1 -0
  97. package/src/errors/BeraError.ts +47 -7
  98. package/src/errors/BeraTracing.unit.test.ts +65 -0
  99. package/src/errors/RequestError.ts +15 -2
  100. package/src/errors/exports.ts +5 -0
  101. package/src/errors/getRevertReason.integration.test.ts +3 -3
  102. package/src/errors/spanStatus.ts +78 -0
  103. package/src/errors/spanStatus.unit.test.ts +62 -0
  104. package/src/hooks/dex/useCreatePool.ts +1 -88
  105. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  106. package/src/hooks/dex/usePriceImpact.ts +12 -5
  107. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  108. package/src/hooks/enso/useBendMultiply.ts +9 -1
  109. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  110. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  111. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  112. package/src/hooks/exports.ts +3 -16
  113. package/src/hooks/governance/exports.ts +14 -0
  114. package/src/hooks/honey/useHoney24hVolume.ts +16 -0
  115. package/src/hooks/pol/useAutoclaimedIncentives.ts +49 -0
  116. package/src/hooks/pol/useStakedAPR.ts +2 -2
  117. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  118. package/src/hooks/validators/useValidator.ts +2 -0
  119. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  120. package/src/types/bribe-boost.d.ts +8 -0
  121. package/src/types/exports.ts +0 -1
  122. package/src/types/governance/exports.ts +1 -0
  123. package/src/utils/beraFetch.ts +76 -15
  124. package/src/utils/exports.ts +1 -0
  125. package/src/utils/getServerSideClient.ts +4 -2
  126. package/src/utils/sanitizeRpcUrl.ts +22 -0
  127. package/src/utils/tracedTransport.ts +35 -0
  128. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  129. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  130. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  131. package/dist/RequestError-A8XJ6QR9.d.cts +0 -57
  132. package/dist/RequestError-Dk97z8rm.d.ts +0 -57
  133. package/dist/abi/exports.cjs +0 -4453
  134. package/dist/abi/exports.cjs.map +0 -1
  135. package/dist/abi/exports.d.cts +0 -6574
  136. package/dist/abi/exports.mjs.map +0 -1
  137. package/dist/actions/exports.cjs +0 -914
  138. package/dist/actions/exports.cjs.map +0 -1
  139. package/dist/actions/exports.d.cts +0 -1644
  140. package/dist/actions/exports.mjs.map +0 -1
  141. package/dist/chunk-2R73G2PO.mjs.map +0 -1
  142. package/dist/chunk-3M47ZRXT.mjs.map +0 -1
  143. package/dist/chunk-4GFN4LEP.mjs.map +0 -1
  144. package/dist/chunk-5N7QQS55.cjs +0 -130
  145. package/dist/chunk-5N7QQS55.cjs.map +0 -1
  146. package/dist/chunk-5NMATIH4.mjs.map +0 -1
  147. package/dist/chunk-7QKRRIHI.mjs.map +0 -1
  148. package/dist/chunk-7TFV6UKF.mjs.map +0 -1
  149. package/dist/chunk-A4FPM7U3.cjs +0 -63
  150. package/dist/chunk-A4FPM7U3.cjs.map +0 -1
  151. package/dist/chunk-BDHINMWQ.cjs +0 -417
  152. package/dist/chunk-BDHINMWQ.cjs.map +0 -1
  153. package/dist/chunk-BEHP54S3.cjs +0 -24
  154. package/dist/chunk-BEHP54S3.cjs.map +0 -1
  155. package/dist/chunk-EGDXV2PT.cjs +0 -36
  156. package/dist/chunk-EGDXV2PT.cjs.map +0 -1
  157. package/dist/chunk-EWBKSMPG.cjs +0 -13
  158. package/dist/chunk-EWBKSMPG.cjs.map +0 -1
  159. package/dist/chunk-F6ZW7ZDD.cjs +0 -403
  160. package/dist/chunk-F6ZW7ZDD.cjs.map +0 -1
  161. package/dist/chunk-FTXTRUYT.cjs +0 -170
  162. package/dist/chunk-FTXTRUYT.cjs.map +0 -1
  163. package/dist/chunk-GLWPRM33.mjs.map +0 -1
  164. package/dist/chunk-GWSTVITN.mjs.map +0 -1
  165. package/dist/chunk-H3Z37RYU.cjs +0 -15
  166. package/dist/chunk-H3Z37RYU.cjs.map +0 -1
  167. package/dist/chunk-I3FTWD6I.mjs.map +0 -1
  168. package/dist/chunk-JA4DHMTG.mjs.map +0 -1
  169. package/dist/chunk-KL6YZ5VR.mjs.map +0 -1
  170. package/dist/chunk-MXWPP6MS.cjs +0 -572
  171. package/dist/chunk-MXWPP6MS.cjs.map +0 -1
  172. package/dist/chunk-SGZP4O6R.mjs.map +0 -1
  173. package/dist/chunk-TDW5SPXR.cjs +0 -244
  174. package/dist/chunk-TDW5SPXR.cjs.map +0 -1
  175. package/dist/chunk-TGK3IXDN.cjs +0 -169
  176. package/dist/chunk-TGK3IXDN.cjs.map +0 -1
  177. package/dist/chunk-TJEW6YCJ.cjs +0 -97
  178. package/dist/chunk-TJEW6YCJ.cjs.map +0 -1
  179. package/dist/chunk-VA3BQ34H.mjs.map +0 -1
  180. package/dist/chunk-VA5L5FDG.mjs.map +0 -1
  181. package/dist/chunk-XSGCRLSD.cjs +0 -1844
  182. package/dist/chunk-XSGCRLSD.cjs.map +0 -1
  183. package/dist/chunk-XV3GG3HC.cjs +0 -135
  184. package/dist/chunk-XV3GG3HC.cjs.map +0 -1
  185. package/dist/chunk-Y5B224UX.cjs +0 -4698
  186. package/dist/chunk-Y5B224UX.cjs.map +0 -1
  187. package/dist/chunk-ZBTRKBSI.mjs +0 -169
  188. package/dist/chunk-ZBTRKBSI.mjs.map +0 -1
  189. package/dist/chunk-ZCEFC2TK.mjs.map +0 -1
  190. package/dist/contexts/exports.cjs +0 -83
  191. package/dist/contexts/exports.cjs.map +0 -1
  192. package/dist/contexts/exports.d.cts +0 -66
  193. package/dist/contexts/exports.mjs.map +0 -1
  194. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  195. package/dist/dex-C_BB0b0O.d.cts +0 -37
  196. package/dist/enum/exports.cjs +0 -59
  197. package/dist/enum/exports.cjs.map +0 -1
  198. package/dist/enum/exports.d.cts +0 -23
  199. package/dist/enum/exports.mjs.map +0 -1
  200. package/dist/errors/exports.cjs +0 -39
  201. package/dist/errors/exports.cjs.map +0 -1
  202. package/dist/errors/exports.d.cts +0 -413
  203. package/dist/errors/exports.mjs.map +0 -1
  204. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  205. package/dist/global.d-B7IeayVX.d.cts +0 -474
  206. package/dist/honey-CYm0RWf4.d.cts +0 -14
  207. package/dist/hooks/exports.cjs +0 -8333
  208. package/dist/hooks/exports.cjs.map +0 -1
  209. package/dist/hooks/exports.d.cts +0 -1748
  210. package/dist/hooks/exports.mjs.map +0 -1
  211. package/dist/polling-BKnyavLI.d.cts +0 -8
  212. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  213. package/dist/types/exports.cjs +0 -1
  214. package/dist/types/exports.cjs.map +0 -1
  215. package/dist/types/exports.d.cts +0 -90
  216. package/dist/types/exports.mjs.map +0 -1
  217. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  218. package/dist/utils/exports.cjs +0 -787
  219. package/dist/utils/exports.cjs.map +0 -1
  220. package/dist/utils/exports.d.cts +0 -412
  221. package/dist/utils/exports.mjs.map +0 -1
  222. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  223. package/src/actions/honey/getHoneyGlobalData.ts +0 -21
  224. package/src/hooks/dex/useExploitedTokens.ts +0 -57
  225. package/src/hooks/honey/useHoneyGlobalData.ts +0 -23
@@ -327,6 +327,11 @@ export const contracts = [
327
327
  "80094": "0xc8FD9a3fB3Dad4C22c9F8Cfa7cecC318A667A791",
328
328
  name: "pol.rewardAllocationFactory",
329
329
  },
330
+ {
331
+ "80069": "0xAf10B532cCC25B26a8e28913D5C4056a77e7a178",
332
+ "80094": "0xc41bbD6695AB6bdc6D04701b15f4CE5EbA2e2500",
333
+ name: "pol.lstStakerVaultFactory",
334
+ },
330
335
  {
331
336
  "80069": "0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b",
332
337
  "80094": "0xba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1ba1b",
@@ -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
@@ -1,9 +1,11 @@
1
1
  import type { ErrorLike } from "@apollo/client";
2
2
 
3
+ import { getUriFromLink } from "@berachain/config";
3
4
  import { mainnet } from "@berachain/config/mainnet";
4
5
 
5
6
  import { BeraError, type IBeraErrorArgs } from "./BeraError";
6
7
  import { errorMsgMap } from "./errorMap";
8
+ import { httpStatusToSpanStatus, reasonToSpanStatus } from "./spanStatus";
7
9
 
8
10
  /**
9
11
  * This is an error class that should be used to handle errors from fetch requests.
@@ -36,7 +38,7 @@ export class RequestError extends BeraError {
36
38
  // vercel internal proxy
37
39
  "/api/aggregators?aggregator",
38
40
  // bonder endpoints have date-based query params (e.g. ?start=2025-11-28)
39
- mainnet.staking,
41
+ mainnet.backend,
40
42
  ];
41
43
 
42
44
  statusCode: number | undefined;
@@ -103,6 +105,17 @@ export class RequestError extends BeraError {
103
105
  }
104
106
  }
105
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
+
106
119
  this.tags = {
107
120
  ...this.tags,
108
121
  "error.statusCode": this.statusCode,
@@ -148,7 +161,7 @@ export class RequestError extends BeraError {
148
161
 
149
162
  if (
150
163
  this.queryRichfulDomains.some((domain) =>
151
- this.endpoint.url.includes(domain),
164
+ this.endpoint.url.includes(getUriFromLink(domain)),
152
165
  )
153
166
  ) {
154
167
  // remove query params if it's an aggregator url
@@ -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
  | {
@@ -18,21 +18,28 @@ export function usePriceImpact({
18
18
  const { getTokenPrice, isLoading } = useTokenPrices({
19
19
  tokens: tokenIn && tokenOut ? [tokenIn, tokenOut] : undefined,
20
20
  });
21
+ const tokenInPrice = getTokenPrice(tokenIn);
22
+ const tokenOutPrice = getTokenPrice(tokenOut);
23
+
21
24
  const priceImpact = useMemo(() => {
22
25
  if (!tokenIn || !tokenOut || !formattedAmountIn || !formattedAmountOut)
23
26
  return undefined;
24
27
 
25
- const tokenInPrice = getTokenPrice(tokenIn);
26
- const tokenOutPrice = getTokenPrice(tokenOut);
27
-
28
- if (!tokenInPrice || !tokenOutPrice) return null;
28
+ if (tokenInPrice == null || tokenOutPrice == null) return null;
29
29
  return computePriceImpact(
30
30
  tokenInPrice.toString(),
31
31
  tokenOutPrice.toString(),
32
32
  formattedAmountIn,
33
33
  formattedAmountOut,
34
34
  );
35
- }, [tokenIn, tokenOut, formattedAmountIn, formattedAmountOut]);
35
+ }, [
36
+ tokenIn,
37
+ tokenOut,
38
+ formattedAmountIn,
39
+ formattedAmountOut,
40
+ tokenInPrice,
41
+ tokenOutPrice,
42
+ ]);
36
43
  return {
37
44
  data: priceImpact,
38
45
  isLoading,
@@ -14,6 +14,7 @@ import {
14
14
 
15
15
  import { getEnsoClient } from "../../actions/clients/getEnsoClient";
16
16
  import { getBendDemultiplyBundle } from "../../actions/enso/getBendDemultiplyBundle";
17
+ import { useBeraFlag } from "../../contexts/BeraFlags/BeraFlags";
17
18
  import { POLLING } from "../../enum/polling";
18
19
  import { assertPublicClient } from "../../errors/assert";
19
20
  import type { Token } from "../../types/dex";
@@ -63,6 +64,9 @@ export function useBendDemultiply(
63
64
  primaryAddress,
64
65
  ensoWalletV2Address,
65
66
  });
67
+ const proxyAggregatorsThroughVercel = useBeraFlag(
68
+ "proxyAggregatorsThroughVercel",
69
+ );
66
70
 
67
71
  const QUERY_KEY =
68
72
  collateralToken &&
@@ -96,6 +100,7 @@ export function useBendDemultiply(
96
100
  currentDebt,
97
101
  ensoWalletV2Address,
98
102
  isAuthorized,
103
+ proxyAggregatorsThroughVercel ?? false,
99
104
  ] as const)
100
105
  : null;
101
106
 
@@ -116,6 +121,7 @@ export function useBendDemultiply(
116
121
  currentDebt,
117
122
  ensoWalletV2Address,
118
123
  isAuthorized,
124
+ proxyAggregatorsThroughVercel,
119
125
  ]) => {
120
126
  assertPublicClient(publicClient);
121
127
 
@@ -140,7 +146,9 @@ export function useBendDemultiply(
140
146
  marketId,
141
147
  primaryAddress,
142
148
  chainId,
143
- ensoClient: getEnsoClient(),
149
+ ensoClient: getEnsoClient({
150
+ baseURL: proxyAggregatorsThroughVercel ? "/api/enso" : undefined,
151
+ }),
144
152
  slippage,
145
153
  publicClient,
146
154
  collateralPriceInLoanAsset,