@berachain/berajs 0.2.8-beta.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BeraError-_mQdkanr.d.cts → BeraError-7-A5JYy_.d.ts} +31 -2
- package/dist/{HoneyConfigProvider-DVP_9KZn.d.ts → HoneyConfigProvider-Dkj-_a5x.d.ts} +1 -1
- package/dist/{RequestError-BRIiJgHk.d.ts → RequestError-DBOIV65x.d.ts} +1 -1
- package/dist/abi/exports.mjs +4452 -2
- package/dist/actions/clients/exports.d.ts +78 -0
- package/dist/actions/clients/exports.mjs +21 -0
- package/dist/actions/exports.d.ts +154 -207
- package/dist/actions/exports.mjs +853 -2
- package/dist/actions/governance/exports.d.ts +140 -0
- package/dist/actions/governance/exports.mjs +226 -0
- package/dist/actions/server/exports.d.ts +13 -0
- package/dist/actions/server/exports.mjs +27 -0
- package/dist/chunk-3JJLQ2JX.mjs +211 -0
- package/dist/chunk-7YVNSDXG.mjs +86 -0
- package/dist/chunk-AUOPN6NK.mjs +96 -0
- package/dist/chunk-BGMRHTBQ.mjs +23 -0
- package/dist/chunk-CDK4YV3D.mjs +571 -0
- package/dist/chunk-DKMAIU74.mjs +62 -0
- package/dist/chunk-DQRH5VE3.mjs +25 -0
- package/dist/chunk-E7YFXBBQ.mjs +349 -0
- package/dist/chunk-GUURQAME.mjs +326 -0
- package/dist/chunk-GY6B3PD5.mjs +89 -0
- package/dist/chunk-HQCOU6GY.mjs +243 -0
- package/dist/chunk-HYDP32P6.mjs +135 -0
- package/dist/chunk-IXIBY5FP.mjs +80 -0
- package/dist/chunk-KHXJDYA4.mjs +1776 -0
- package/dist/chunk-NBYLMO2L.mjs +14 -0
- package/dist/chunk-O2NQFKJK.mjs +170 -0
- package/dist/chunk-P5WXXULM.mjs +54 -0
- package/dist/chunk-QBBOWFMH.mjs +4129 -0
- package/dist/chunk-QVHEM4BG.mjs +35 -0
- package/dist/chunk-SGIJVHZO.mjs +12 -0
- package/dist/chunk-SZ5C44L5.mjs +35 -0
- package/dist/chunk-WNBWX23Q.mjs +426 -0
- package/dist/chunk-Y6THHG77.mjs +126 -0
- package/dist/chunk-ZLTMIFCZ.mjs +165 -0
- package/dist/contexts/exports.d.ts +2 -2
- package/dist/contexts/exports.mjs +85 -2
- package/dist/enum/exports.d.ts +1 -1
- package/dist/enum/exports.mjs +46 -2
- package/dist/enum/governance/exports.d.ts +60 -0
- package/dist/enum/governance/exports.mjs +14 -0
- package/dist/errors/exports.d.ts +4 -3
- package/dist/errors/exports.mjs +48 -2
- package/dist/getApolloClient-BcUTGFUb.d.ts +40 -0
- package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-DphU3qhE.d.ts} +2 -2
- package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
- package/dist/hooks/exports.d.ts +83 -226
- package/dist/hooks/exports.mjs +7463 -4
- package/dist/hooks/governance/exports.d.ts +181 -0
- package/dist/hooks/governance/exports.mjs +888 -0
- package/dist/pol.d-Dw5SQcRX.d.ts +153 -0
- package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
- package/dist/types/exports.d.ts +9 -9
- package/dist/types/exports.mjs +0 -1
- package/dist/types/governance/exports.d.ts +109 -0
- package/dist/types/governance/exports.mjs +0 -0
- package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
- package/dist/utils/exports.d.ts +15 -6
- package/dist/utils/exports.mjs +827 -2
- package/package.json +49 -13
- package/src/actions/__test/transports.ts +61 -0
- package/src/actions/clients/exports.ts +7 -0
- package/src/actions/clients/fetchBeep.ts +34 -0
- package/src/actions/clients/fetchOpenApi.ts +93 -0
- package/src/actions/clients/fetchOpenApi.unit.test.ts +223 -0
- package/src/actions/clients/fetchRailwayBackend.ts +34 -0
- package/src/actions/clients/getApolloClient.ts +58 -23
- package/src/actions/clients/getEnsoClient.ts +20 -9
- package/src/actions/dex/aggregators/enso/enso.ts +27 -17
- package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
- package/src/actions/dex/aggregators/kyberswap.ts +18 -23
- package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
- package/src/actions/enso/getEnsoUserTokensWithBalances.ts +18 -0
- package/src/actions/exports.ts +5 -9
- package/src/actions/governance/exports.ts +9 -0
- package/src/actions/governance/getAllProposals.ts +10 -65
- package/src/actions/governance/getProposalDetails.ts +6 -33
- package/src/actions/governance/getProposalVotes.ts +8 -15
- package/src/actions/honey/getChartData.ts +27 -21
- package/src/actions/honey/getHoney24hVolume.ts +19 -22
- package/src/actions/honey/getPythLatestPrices.ts +7 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
- package/src/actions/pol/getAutoclaimedIncentives.ts +41 -0
- package/src/actions/pol/getAutoclaimedIncentivesTxHash.ts +41 -0
- package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
- package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +28 -0
- package/src/actions/pol/getEarnedStakedBeraVault.ts +20 -20
- package/src/actions/pol/getGlobalData.ts +1 -0
- package/src/actions/pol/getHeroEarnVaults.ts +62 -0
- package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
- package/src/actions/pol/getRewardVaults.ts +4 -4
- package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
- package/src/actions/pol/getStakingDailyAssets.ts +18 -17
- package/src/actions/server/exports.ts +1 -0
- package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
- package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
- package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
- package/src/actions/validators/getValidatorAnalytics.ts +20 -21
- package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
- package/src/actions/validators/utils/getValidatorBoostApy.ts +1 -1
- package/src/enum/contracts.ts +1 -0
- package/src/enum/exports.ts +0 -1
- package/src/enum/governance/exports.ts +1 -0
- package/src/errors/BeraError.ts +47 -7
- package/src/errors/BeraTracing.unit.test.ts +65 -0
- package/src/errors/RequestError.ts +25 -4
- package/src/errors/RequestError.unit.test.ts +55 -0
- package/src/errors/errorMap.ts +8 -0
- package/src/errors/exports.ts +5 -0
- package/src/errors/getRevertReason.integration.test.ts +3 -3
- package/src/errors/spanStatus.ts +78 -0
- package/src/errors/spanStatus.unit.test.ts +62 -0
- package/src/hooks/dex/useCreatePool.ts +1 -88
- package/src/hooks/dex/useOnChainPoolData.ts +27 -2
- package/src/hooks/dex/usePriceImpact.ts +12 -5
- package/src/hooks/enso/useBendDemultiply.ts +9 -1
- package/src/hooks/enso/useBendMultiply.ts +9 -1
- package/src/hooks/enso/useBendZapSupply.ts +26 -7
- package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
- package/src/hooks/exports.ts +3 -15
- package/src/hooks/governance/exports.ts +14 -0
- package/src/hooks/pol/useAutoclaimedIncentives.ts +40 -0
- package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +45 -0
- package/src/hooks/pol/useStakedAPR.ts +2 -2
- package/src/hooks/pol/useStakedSnapshots.ts +5 -9
- package/src/hooks/validators/useValidator.ts +6 -8
- package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
- package/src/types/bribe-boost.d.ts +19 -0
- package/src/types/exports.ts +0 -1
- package/src/types/governance/exports.ts +1 -0
- package/src/utils/beraFetch.ts +9 -3
- package/src/utils/exports.ts +1 -0
- package/src/utils/getServerSideClient.ts +4 -2
- package/src/utils/polyfillAbortSignalAny.ts +53 -0
- package/src/utils/polyfillAbortSignalAny.unit.test.ts +81 -0
- package/src/utils/sanitizeRpcUrl.ts +22 -0
- package/src/utils/tracedTransport.ts +35 -0
- package/dist/BeraError-_mQdkanr.d.ts +0 -94
- package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
- package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
- package/dist/RequestError-DSUzJ1Iy.d.cts +0 -144
- package/dist/abi/exports.cjs +0 -2
- package/dist/abi/exports.cjs.map +0 -1
- package/dist/abi/exports.d.cts +0 -6574
- package/dist/abi/exports.mjs.map +0 -1
- package/dist/actions/exports.cjs +0 -2
- package/dist/actions/exports.cjs.map +0 -1
- package/dist/actions/exports.d.cts +0 -1650
- package/dist/actions/exports.mjs.map +0 -1
- package/dist/chunk-45HIEVNI.cjs +0 -4
- package/dist/chunk-45HIEVNI.cjs.map +0 -1
- package/dist/chunk-47ILYVHC.mjs +0 -2
- package/dist/chunk-47ILYVHC.mjs.map +0 -1
- package/dist/chunk-575OK77P.mjs +0 -2
- package/dist/chunk-575OK77P.mjs.map +0 -1
- package/dist/chunk-5NVZG5N6.mjs +0 -2
- package/dist/chunk-5NVZG5N6.mjs.map +0 -1
- package/dist/chunk-6DIA6PXV.cjs +0 -2
- package/dist/chunk-6DIA6PXV.cjs.map +0 -1
- package/dist/chunk-6JJIZCVY.cjs +0 -2
- package/dist/chunk-6JJIZCVY.cjs.map +0 -1
- package/dist/chunk-7F72ZH4Q.mjs +0 -2
- package/dist/chunk-7F72ZH4Q.mjs.map +0 -1
- package/dist/chunk-AUA42YIG.mjs +0 -4
- package/dist/chunk-AUA42YIG.mjs.map +0 -1
- package/dist/chunk-BC2WX6O6.cjs +0 -2
- package/dist/chunk-BC2WX6O6.cjs.map +0 -1
- package/dist/chunk-CJOZC5Z2.cjs +0 -2
- package/dist/chunk-CJOZC5Z2.cjs.map +0 -1
- package/dist/chunk-D6L7LTA2.cjs +0 -2
- package/dist/chunk-D6L7LTA2.cjs.map +0 -1
- package/dist/chunk-DDEQFR3M.cjs +0 -2
- package/dist/chunk-DDEQFR3M.cjs.map +0 -1
- package/dist/chunk-GXV2JA36.mjs +0 -2
- package/dist/chunk-GXV2JA36.mjs.map +0 -1
- package/dist/chunk-ISYNEDET.mjs +0 -2
- package/dist/chunk-ISYNEDET.mjs.map +0 -1
- package/dist/chunk-JDDRTHFG.mjs +0 -2
- package/dist/chunk-JDDRTHFG.mjs.map +0 -1
- package/dist/chunk-JDZGYU5T.mjs +0 -2
- package/dist/chunk-JDZGYU5T.mjs.map +0 -1
- package/dist/chunk-LVOXBZMA.cjs +0 -2
- package/dist/chunk-LVOXBZMA.cjs.map +0 -1
- package/dist/chunk-MK5NS5B5.mjs +0 -2
- package/dist/chunk-MK5NS5B5.mjs.map +0 -1
- package/dist/chunk-NAXAZJJY.mjs +0 -2
- package/dist/chunk-NAXAZJJY.mjs.map +0 -1
- package/dist/chunk-NLVWRMGD.mjs +0 -2
- package/dist/chunk-NLVWRMGD.mjs.map +0 -1
- package/dist/chunk-OGBD5YOG.mjs +0 -2
- package/dist/chunk-OGBD5YOG.mjs.map +0 -1
- package/dist/chunk-OGJMSGB2.mjs +0 -2
- package/dist/chunk-OGJMSGB2.mjs.map +0 -1
- package/dist/chunk-OIYXOKTT.cjs +0 -2
- package/dist/chunk-OIYXOKTT.cjs.map +0 -1
- package/dist/chunk-OUD27MU7.cjs +0 -2
- package/dist/chunk-OUD27MU7.cjs.map +0 -1
- package/dist/chunk-PRLVZIKD.mjs +0 -2
- package/dist/chunk-PRLVZIKD.mjs.map +0 -1
- package/dist/chunk-Q2SNRLW3.cjs +0 -2
- package/dist/chunk-Q2SNRLW3.cjs.map +0 -1
- package/dist/chunk-REWME3FY.cjs +0 -2
- package/dist/chunk-REWME3FY.cjs.map +0 -1
- package/dist/chunk-RJN36GBU.mjs +0 -2
- package/dist/chunk-RJN36GBU.mjs.map +0 -1
- package/dist/chunk-RWOICHRW.cjs +0 -2
- package/dist/chunk-RWOICHRW.cjs.map +0 -1
- package/dist/chunk-S4CDSVLK.cjs +0 -2
- package/dist/chunk-S4CDSVLK.cjs.map +0 -1
- package/dist/chunk-SFEULGSX.cjs +0 -2
- package/dist/chunk-SFEULGSX.cjs.map +0 -1
- package/dist/chunk-WBTS6KFG.mjs +0 -2
- package/dist/chunk-WBTS6KFG.mjs.map +0 -1
- package/dist/chunk-WRFDB3QJ.cjs +0 -2
- package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
- package/dist/chunk-XNJLSA6P.cjs +0 -2
- package/dist/chunk-XNJLSA6P.cjs.map +0 -1
- package/dist/contexts/exports.cjs +0 -2
- package/dist/contexts/exports.cjs.map +0 -1
- package/dist/contexts/exports.d.cts +0 -66
- package/dist/contexts/exports.mjs.map +0 -1
- package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
- package/dist/dex-C_BB0b0O.d.cts +0 -37
- package/dist/enum/exports.cjs +0 -2
- package/dist/enum/exports.cjs.map +0 -1
- package/dist/enum/exports.d.cts +0 -23
- package/dist/enum/exports.mjs.map +0 -1
- package/dist/errors/exports.cjs +0 -2
- package/dist/errors/exports.cjs.map +0 -1
- package/dist/errors/exports.d.cts +0 -327
- package/dist/errors/exports.mjs.map +0 -1
- package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
- package/dist/global.d-B7IeayVX.d.cts +0 -474
- package/dist/honey-CYm0RWf4.d.cts +0 -14
- package/dist/hooks/exports.cjs +0 -4
- package/dist/hooks/exports.cjs.map +0 -1
- package/dist/hooks/exports.d.cts +0 -1734
- package/dist/hooks/exports.mjs.map +0 -1
- package/dist/polling-BKnyavLI.d.cts +0 -8
- package/dist/txnEnum-7_o92X3N.d.ts +0 -164
- package/dist/types/exports.cjs +0 -1
- package/dist/types/exports.cjs.map +0 -1
- package/dist/types/exports.d.cts +0 -90
- package/dist/types/exports.mjs.map +0 -1
- package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
- package/dist/utils/exports.cjs +0 -2
- package/dist/utils/exports.cjs.map +0 -1
- package/dist/utils/exports.d.cts +0 -420
- package/dist/utils/exports.mjs.map +0 -1
- package/src/actions/dex/getIsTokenExploited.ts +0 -63
- package/src/hooks/dex/useExploitedTokens.ts +0 -57
package/src/errors/BeraError.ts
CHANGED
|
@@ -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
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
console.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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,10 +1,12 @@
|
|
|
1
1
|
import type { ErrorLike } from "@apollo/client";
|
|
2
2
|
|
|
3
3
|
import { getUriFromLink } from "@berachain/config";
|
|
4
|
+
import { bepolia } from "@berachain/config/bepolia";
|
|
4
5
|
import { mainnet } from "@berachain/config/mainnet";
|
|
5
6
|
|
|
6
7
|
import { BeraError, type IBeraErrorArgs } from "./BeraError";
|
|
7
8
|
import { errorMsgMap } from "./errorMap";
|
|
9
|
+
import { httpStatusToSpanStatus, reasonToSpanStatus } from "./spanStatus";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* This is an error class that should be used to handle errors from fetch requests.
|
|
@@ -32,12 +34,16 @@ export class RequestError extends BeraError {
|
|
|
32
34
|
*/
|
|
33
35
|
private queryRichfulDomains = [
|
|
34
36
|
mainnet.bex.aggregatorsProxyUrl,
|
|
35
|
-
|
|
37
|
+
// covers both /aggregator/quote and /aggregator/transaction?quoteId=...
|
|
38
|
+
// (the transaction endpoint's quoteId would otherwise fragment grouping)
|
|
39
|
+
"https://api.fly.trade/aggregator",
|
|
36
40
|
"https://open-api.openocean.finance/v4/bera/swap",
|
|
37
41
|
// vercel internal proxy
|
|
38
42
|
"/api/aggregators?aggregator",
|
|
39
43
|
// bonder endpoints have date-based query params (e.g. ?start=2025-11-28)
|
|
40
|
-
mainnet.
|
|
44
|
+
mainnet.backend,
|
|
45
|
+
// beep (next-gen backend) on testnet — same date-based bonder query params
|
|
46
|
+
bepolia.beep,
|
|
41
47
|
];
|
|
42
48
|
|
|
43
49
|
statusCode: number | undefined;
|
|
@@ -104,6 +110,17 @@ export class RequestError extends BeraError {
|
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
|
|
113
|
+
// ── Span status inference ─────────────────────────────────────────
|
|
114
|
+
// Re-infer from reason since it may have been set after super() ran
|
|
115
|
+
// (e.g. NETWORK_ERROR → unavailable, RATE_LIMITED_429 → resource_exhausted).
|
|
116
|
+
if (!this.spanStatus && this.reason) {
|
|
117
|
+
this.spanStatus = reasonToSpanStatus(this.reason);
|
|
118
|
+
}
|
|
119
|
+
// Fall back to HTTP status code mapping when no reason-based status.
|
|
120
|
+
if (!this.spanStatus && this.statusCode) {
|
|
121
|
+
this.spanStatus = httpStatusToSpanStatus(this.statusCode);
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
this.tags = {
|
|
108
125
|
...this.tags,
|
|
109
126
|
"error.statusCode": this.statusCode,
|
|
@@ -196,14 +213,18 @@ export class RequestError extends BeraError {
|
|
|
196
213
|
// - have a network error
|
|
197
214
|
// - have CORS errors
|
|
198
215
|
// the list is empirically collected from sentry error logs.
|
|
216
|
+
// The trailing "(host)" suffix is optional: some browsers/transports omit
|
|
217
|
+
// it (e.g. bare "Failed to fetch" / "Load failed"). We normalize all of
|
|
218
|
+
// them to a single NETWORK_ERROR reason so the variants group together,
|
|
219
|
+
// falling back to the endpoint url when no host is present in the message.
|
|
199
220
|
const failedToFetchMatch = message.match(
|
|
200
|
-
/^(?:NetworkError when attempting to fetch resource\.|Failed to fetch|Load failed) \(([a-z0-9-.]+)\)
|
|
221
|
+
/^(?:NetworkError when attempting to fetch resource\.|Failed to fetch|Load failed)(?: \(([a-z0-9-.]+)\))?$/,
|
|
201
222
|
);
|
|
202
223
|
if (failedToFetchMatch) {
|
|
203
224
|
return {
|
|
204
225
|
reason: RequestError.REASON_MAP.NETWORK_ERROR,
|
|
205
226
|
message: message,
|
|
206
|
-
url: failedToFetchMatch[1],
|
|
227
|
+
url: failedToFetchMatch[1] ?? this.endpoint.url,
|
|
207
228
|
};
|
|
208
229
|
}
|
|
209
230
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { RequestError } from "./RequestError.js";
|
|
4
|
+
|
|
5
|
+
describe("RequestError endpoint normalization (grouping)", () => {
|
|
6
|
+
it("strips query params from the fly.trade transaction endpoint so quoteId no longer fragments groups", () => {
|
|
7
|
+
const base = "https://api.fly.trade/aggregator/transaction";
|
|
8
|
+
const a = new RequestError({
|
|
9
|
+
response: undefined,
|
|
10
|
+
endpoint: {
|
|
11
|
+
url: `${base}?quoteId=aaaa-1111&estimateGas=false`,
|
|
12
|
+
type: "rest",
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const b = new RequestError({
|
|
16
|
+
response: undefined,
|
|
17
|
+
endpoint: {
|
|
18
|
+
url: `${base}?quoteId=bbbb-2222&estimateGas=false`,
|
|
19
|
+
type: "rest",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(a.endpoint.url).toBe(base);
|
|
24
|
+
expect(b.endpoint.url).toBe(base);
|
|
25
|
+
expect(a.endpoint.url).toBe(b.endpoint.url);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("RequestError network-error normalization (grouping)", () => {
|
|
30
|
+
it.each([
|
|
31
|
+
"Failed to fetch",
|
|
32
|
+
"Load failed",
|
|
33
|
+
"NetworkError when attempting to fetch resource.",
|
|
34
|
+
"Failed to fetch (api.berachain.com)",
|
|
35
|
+
])("normalizes %s to NETWORK_ERROR reason", (message) => {
|
|
36
|
+
const err = new RequestError({
|
|
37
|
+
response: undefined,
|
|
38
|
+
cause: new TypeError(message),
|
|
39
|
+
endpoint: { url: "https://api.berachain.com", type: "graphql" },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(err.reason).toBe(RequestError.REASON_MAP.NETWORK_ERROR);
|
|
43
|
+
expect(err.level).toBe("warning");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("does not treat unrelated messages as network errors", () => {
|
|
47
|
+
const err = new RequestError({
|
|
48
|
+
response: undefined,
|
|
49
|
+
cause: new TypeError("Cannot read properties of undefined"),
|
|
50
|
+
endpoint: { url: "https://api.berachain.com", type: "graphql" },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(err.reason).not.toBe(RequestError.REASON_MAP.NETWORK_ERROR);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/src/errors/errorMap.ts
CHANGED
|
@@ -89,6 +89,14 @@ export const errorMsgMap = {
|
|
|
89
89
|
errorMSG:
|
|
90
90
|
"Nonce is too low. Your wallet might have unconfirmed transactions.",
|
|
91
91
|
},
|
|
92
|
+
REPLACEMENT_UNDERPRICED: {
|
|
93
|
+
// Transient resubmission issue (gas bump too low). Not function-specific —
|
|
94
|
+
// normalizing the raw RPC string to this key collapses the per-function
|
|
95
|
+
// Sentry groups (functionName is still kept as a tag).
|
|
96
|
+
keywords: ["replacement transaction underpriced"],
|
|
97
|
+
errorMSG:
|
|
98
|
+
"Your wallet tried to replace a pending transaction without raising the gas enough. Please wait for the previous transaction to finish, or try again.",
|
|
99
|
+
},
|
|
92
100
|
GAS_PRICE: {
|
|
93
101
|
keywords: ["gasLimit"],
|
|
94
102
|
errorMSG:
|
package/src/errors/exports.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
| {
|