@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
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
getRpcUrls,
|
|
8
8
|
} from "@berachain/config/internal";
|
|
9
9
|
|
|
10
|
+
import { tracedTransport } from "./tracedTransport";
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* This is a singleton to avoid creating a new client for each request.
|
|
12
14
|
*
|
|
@@ -31,10 +33,10 @@ export const getServerSidePublicClient = (
|
|
|
31
33
|
rpcs.publicJsonRpcUrl,
|
|
32
34
|
]
|
|
33
35
|
.filter((i) => i)
|
|
34
|
-
.map((url) => http(url));
|
|
36
|
+
.map((url) => tracedTransport(http(url)));
|
|
35
37
|
|
|
36
38
|
if (fallbackTransports.length === 0) {
|
|
37
|
-
fallbackTransports.push(http());
|
|
39
|
+
fallbackTransports.push(tracedTransport(http()));
|
|
38
40
|
}
|
|
39
41
|
const chain = chainId === ChainId.MAINNET ? berachain : berachainBepolia;
|
|
40
42
|
const client = createPublicClient({
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for `AbortSignal.any`.
|
|
3
|
+
*
|
|
4
|
+
* `AbortSignal.any` ships in Chrome 116+, Safari 17.4+, Firefox 124+. Older
|
|
5
|
+
* environments — notably Android WebViews bundled with old Chromium (e.g.
|
|
6
|
+
* Chrome Mobile WebView 114) — lack it, and third-party libraries that call it
|
|
7
|
+
* (e.g. @pythnetwork/hermes-client) throw "AbortSignal.any is not a function".
|
|
8
|
+
*
|
|
9
|
+
* This installs a spec-compatible-enough fallback: it returns a controller's
|
|
10
|
+
* signal that aborts as soon as any of the input signals abort (propagating the
|
|
11
|
+
* abort reason). It is idempotent and a no-op when the native API exists.
|
|
12
|
+
*/
|
|
13
|
+
export function polyfillAbortSignalAny(): void {
|
|
14
|
+
if (typeof AbortSignal === "undefined") return;
|
|
15
|
+
if (typeof (AbortSignal as { any?: unknown }).any === "function") return;
|
|
16
|
+
|
|
17
|
+
(
|
|
18
|
+
AbortSignal as unknown as { any: (signals: AbortSignal[]) => AbortSignal }
|
|
19
|
+
).any = (signals: AbortSignal[]): AbortSignal => {
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
|
|
22
|
+
// Phase 1: if any signal is already aborted, short-circuit before attaching
|
|
23
|
+
// any listeners (attaching to the others would leave dangling listeners
|
|
24
|
+
// that never fire — the leak the WeakRef/FinalizationRegistry versions guard
|
|
25
|
+
// against; checking first avoids it without that machinery).
|
|
26
|
+
for (const signal of signals) {
|
|
27
|
+
if (signal.aborted) {
|
|
28
|
+
controller.abort(signal.reason);
|
|
29
|
+
return controller.signal;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Phase 2: forward the first abort, then detach every listener so none
|
|
34
|
+
// outlive the combined signal. Safe for our short-lived usage (per-request
|
|
35
|
+
// fetch signals that settle and are collected together).
|
|
36
|
+
const listeners: Array<() => void> = [];
|
|
37
|
+
const cleanup = () => {
|
|
38
|
+
for (let i = 0; i < signals.length; i++) {
|
|
39
|
+
signals[i].removeEventListener("abort", listeners[i]);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
for (const signal of signals) {
|
|
43
|
+
const onAbort = () => {
|
|
44
|
+
if (!controller.signal.aborted) controller.abort(signal.reason);
|
|
45
|
+
cleanup();
|
|
46
|
+
};
|
|
47
|
+
listeners.push(onAbort);
|
|
48
|
+
signal.addEventListener("abort", onAbort);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return controller.signal;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { polyfillAbortSignalAny } from "./polyfillAbortSignalAny.js";
|
|
4
|
+
|
|
5
|
+
describe("polyfillAbortSignalAny", () => {
|
|
6
|
+
const original = (AbortSignal as { any?: unknown }).any;
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
// restore whatever the runtime had (native or undefined)
|
|
10
|
+
(AbortSignal as { any?: unknown }).any = original;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("does not overwrite a native AbortSignal.any", () => {
|
|
14
|
+
const native = () => new AbortController().signal;
|
|
15
|
+
(AbortSignal as { any?: unknown }).any = native;
|
|
16
|
+
polyfillAbortSignalAny();
|
|
17
|
+
expect((AbortSignal as { any?: unknown }).any).toBe(native);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("installs a fallback when AbortSignal.any is missing", () => {
|
|
21
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
22
|
+
polyfillAbortSignalAny();
|
|
23
|
+
expect(typeof (AbortSignal as { any?: unknown }).any).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("aborts the combined signal when one input aborts", () => {
|
|
27
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
28
|
+
polyfillAbortSignalAny();
|
|
29
|
+
|
|
30
|
+
const a = new AbortController();
|
|
31
|
+
const b = new AbortController();
|
|
32
|
+
const combined = (
|
|
33
|
+
AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }
|
|
34
|
+
).any([a.signal, b.signal]);
|
|
35
|
+
|
|
36
|
+
expect(combined.aborted).toBe(false);
|
|
37
|
+
b.abort("boom");
|
|
38
|
+
expect(combined.aborted).toBe(true);
|
|
39
|
+
expect(combined.reason).toBe("boom");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("removes listeners from all inputs once the combined signal aborts", () => {
|
|
43
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
44
|
+
polyfillAbortSignalAny();
|
|
45
|
+
|
|
46
|
+
const a = new AbortController();
|
|
47
|
+
const b = new AbortController();
|
|
48
|
+
const removed: AbortSignal[] = [];
|
|
49
|
+
for (const c of [a, b]) {
|
|
50
|
+
const orig = c.signal.removeEventListener.bind(c.signal);
|
|
51
|
+
c.signal.removeEventListener = ((...args: Parameters<typeof orig>) => {
|
|
52
|
+
removed.push(c.signal);
|
|
53
|
+
return orig(...args);
|
|
54
|
+
}) as typeof orig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
(AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }).any([
|
|
58
|
+
a.signal,
|
|
59
|
+
b.signal,
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
a.abort("x");
|
|
63
|
+
// both inputs should have had their abort listener detached, not just the firing one
|
|
64
|
+
expect(removed).toContain(a.signal);
|
|
65
|
+
expect(removed).toContain(b.signal);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("is already aborted if an input is already aborted", () => {
|
|
69
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
70
|
+
polyfillAbortSignalAny();
|
|
71
|
+
|
|
72
|
+
const a = new AbortController();
|
|
73
|
+
a.abort("early");
|
|
74
|
+
const combined = (
|
|
75
|
+
AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }
|
|
76
|
+
).any([a.signal]);
|
|
77
|
+
|
|
78
|
+
expect(combined.aborted).toBe(true);
|
|
79
|
+
expect(combined.reason).toBe("early");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips secret tokens from RPC URLs for safe use in span attributes and logs.
|
|
3
|
+
*
|
|
4
|
+
* QuickNode URLs embed API keys as path segments, e.g.:
|
|
5
|
+
* https://polished-morning-sun.bera-mainnet.quiknode.pro/abc123def/
|
|
6
|
+
* This function trims the subpath, producing:
|
|
7
|
+
* https://polished-morning-sun.bera-mainnet.quiknode.pro/
|
|
8
|
+
*/
|
|
9
|
+
export function sanitizeRpcUrl(url: string | undefined): string {
|
|
10
|
+
if (!url) return "";
|
|
11
|
+
try {
|
|
12
|
+
const parsed = new URL(url);
|
|
13
|
+
if (parsed.hostname.endsWith(".quiknode.pro")) {
|
|
14
|
+
parsed.pathname = "/";
|
|
15
|
+
parsed.search = "";
|
|
16
|
+
return parsed.toString();
|
|
17
|
+
}
|
|
18
|
+
return url;
|
|
19
|
+
} catch {
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Transport } from "viem";
|
|
2
|
+
|
|
3
|
+
import { BeraTracing } from "../errors/BeraTracing";
|
|
4
|
+
import { sanitizeRpcUrl } from "./sanitizeRpcUrl";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wraps a viem Transport to trace each RPC request via BeraTracing.
|
|
8
|
+
*
|
|
9
|
+
* Each `request()` call is wrapped in a span with the JSON-RPC method name,
|
|
10
|
+
* transport type, and URL as attributes. Works with `http()`, `fallback()`,
|
|
11
|
+
* and any other viem transport.
|
|
12
|
+
*/
|
|
13
|
+
export function tracedTransport<T extends Transport>(transport: T): T {
|
|
14
|
+
return ((opts: Parameters<Transport>[0]) => {
|
|
15
|
+
const result = transport(opts);
|
|
16
|
+
const originalRequest = result.request;
|
|
17
|
+
|
|
18
|
+
result.request = async (args, options) => {
|
|
19
|
+
return BeraTracing.startSpan(
|
|
20
|
+
{
|
|
21
|
+
name: `RPC ${args.method}`,
|
|
22
|
+
op: "rpc.request",
|
|
23
|
+
attributes: {
|
|
24
|
+
"rpc.method": args.method,
|
|
25
|
+
"rpc.transport": result.config.type,
|
|
26
|
+
"rpc.url": sanitizeRpcUrl(result.value?.url),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
() => originalRequest(args, options),
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}) as T;
|
|
35
|
+
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Abi } from 'viem';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Severity levels for error reporting.
|
|
5
|
-
* Mirrors Sentry's SeverityLevel for compatibility, but owned by berajs
|
|
6
|
-
* so we don't depend on @sentry/nextjs.
|
|
7
|
-
*/
|
|
8
|
-
type SeverityLevel = "fatal" | "error" | "warning" | "log" | "info" | "debug";
|
|
9
|
-
|
|
10
|
-
interface IBeraErrorArgs {
|
|
11
|
-
message?: string;
|
|
12
|
-
displayMessage?: string;
|
|
13
|
-
cause?: unknown;
|
|
14
|
-
reason?: string;
|
|
15
|
-
chainId?: number;
|
|
16
|
-
fingerprint?: string[];
|
|
17
|
-
/**
|
|
18
|
-
* The level of the error to be used for error reporting.
|
|
19
|
-
*/
|
|
20
|
-
level?: SeverityLevel;
|
|
21
|
-
tags?: {
|
|
22
|
-
[key in TagsKey]?: Primitive;
|
|
23
|
-
};
|
|
24
|
-
extra?: Record<string, unknown>;
|
|
25
|
-
/**
|
|
26
|
-
* Optional ABI to be used to parse the error.
|
|
27
|
-
*/
|
|
28
|
-
abi?: Abi;
|
|
29
|
-
}
|
|
30
|
-
type Primitive = number | string | boolean | bigint | symbol | null | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* An helper type to make sure we only use the allowed tags. Sync this with docs/errors.md
|
|
33
|
-
*/
|
|
34
|
-
type TagsKey = "wallet.chain" | "wallet.connector" | "wallet.address" | "error.reason" | "operation.type" | "operation.key" | "operation.txn.functionName" | "operation.txn.to" | "operation.txn.status" | "operation.source.url" | "operation.source.name" | "operation.source.queryName" | "operation.source.type";
|
|
35
|
-
/**
|
|
36
|
-
* Base error class for the entire berajs SDK.
|
|
37
|
-
*
|
|
38
|
-
* All errors should be a BeraError or one of its subclasses. Unknown errors should be
|
|
39
|
-
* normalized via `initBeraError({ cause })`.
|
|
40
|
-
*
|
|
41
|
-
* Key design: the constructor runs an **automatic reason detection pipeline** when `reason`
|
|
42
|
-
* is not explicitly provided. It calls `parseViemError` on the `cause` to extract a
|
|
43
|
-
* machine-readable reason code (e.g. "NotEnoughBalance", "BAL#508", "UserRejectedRequestError").
|
|
44
|
-
* That reason is then matched against `errorMap.ts` to resolve a user-friendly `displayMessage`.
|
|
45
|
-
*
|
|
46
|
-
* This means: for most viem errors, you only need to pass `cause` and everything else
|
|
47
|
-
* (reason, displayMessage, level) is derived automatically.
|
|
48
|
-
*
|
|
49
|
-
* @see parseViemError — the reason extraction engine
|
|
50
|
-
* @see errorMap.ts — reason → displayMessage mapping
|
|
51
|
-
* @see initBeraError — normalizes any error into a BeraError (preferred entry point)
|
|
52
|
-
*/
|
|
53
|
-
declare class BeraError extends Error {
|
|
54
|
-
/**
|
|
55
|
-
* A human-readable message that can be displayed to end user.
|
|
56
|
-
*
|
|
57
|
-
* In berachain dapps, this is shown in the error pop-up.
|
|
58
|
-
*/
|
|
59
|
-
displayMessage: string;
|
|
60
|
-
/**
|
|
61
|
-
* The cause of the error.
|
|
62
|
-
*
|
|
63
|
-
* This is typically the error that was thrown.
|
|
64
|
-
*/
|
|
65
|
-
cause: unknown;
|
|
66
|
-
/**
|
|
67
|
-
* The chain id of the error.
|
|
68
|
-
*/
|
|
69
|
-
chainId?: number;
|
|
70
|
-
/**
|
|
71
|
-
* The code for the reason for the error.
|
|
72
|
-
*
|
|
73
|
-
* This is typically the error code can be found in the errorMap.ts file. I.e. NotEnoughBalance or BAL#508
|
|
74
|
-
*/
|
|
75
|
-
reason: string | null;
|
|
76
|
-
/**
|
|
77
|
-
* The fingerprint for the error.
|
|
78
|
-
*
|
|
79
|
-
* This is typically used to group errors in Sentry.
|
|
80
|
-
*/
|
|
81
|
-
fingerprint: string[] | undefined;
|
|
82
|
-
private _tags;
|
|
83
|
-
set tags(tags: {
|
|
84
|
-
[key: string | TagsKey]: Primitive;
|
|
85
|
-
});
|
|
86
|
-
get tags(): {
|
|
87
|
-
[key: string | TagsKey]: Primitive;
|
|
88
|
-
};
|
|
89
|
-
level: SeverityLevel;
|
|
90
|
-
extra: Record<string, unknown>;
|
|
91
|
-
constructor({ message: m, displayMessage: dm, cause, reason, level, abi, tags, chainId, fingerprint, }: IBeraErrorArgs);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { BeraError as B, type IBeraErrorArgs as I, type SeverityLevel as S };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
4
|
-
import { Hex } from 'viem';
|
|
5
|
-
import { EdgeConfigSchema } from '@berachain/config/internal/edge-config';
|
|
6
|
-
|
|
7
|
-
type FactoryStatus = {
|
|
8
|
-
/**
|
|
9
|
-
* If the composable stable factory is enabled
|
|
10
|
-
*/
|
|
11
|
-
composableStable: "paused" | "enabled";
|
|
12
|
-
/**
|
|
13
|
-
* If the weighted factory is enabled
|
|
14
|
-
*/
|
|
15
|
-
weighted: "paused" | "enabled";
|
|
16
|
-
};
|
|
17
|
-
interface BexStatusProviderProps {
|
|
18
|
-
isVaultPaused: boolean;
|
|
19
|
-
pool?: {
|
|
20
|
-
id: Hex;
|
|
21
|
-
isInRecoveryMode: boolean;
|
|
22
|
-
isPaused: boolean;
|
|
23
|
-
};
|
|
24
|
-
factories: FactoryStatus;
|
|
25
|
-
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
26
|
-
}
|
|
27
|
-
declare const BexStateContext: react.Context<{
|
|
28
|
-
protocol: {
|
|
29
|
-
isPaused: boolean;
|
|
30
|
-
factories: FactoryStatus & {
|
|
31
|
-
allPaused: boolean;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
onPoolChange: Dispatch<SetStateAction<BexStatusProviderProps["pool"]>>;
|
|
35
|
-
pool?: {
|
|
36
|
-
id: Hex;
|
|
37
|
-
isInRecoveryMode: boolean;
|
|
38
|
-
isPaused: boolean;
|
|
39
|
-
disablePoolWithdrawals: boolean;
|
|
40
|
-
disablePoolDeposits: boolean;
|
|
41
|
-
};
|
|
42
|
-
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* @description Determines the status of a pool or vault and returns the appropriate messages and flags to disable functionality.
|
|
46
|
-
* More information here https://www.notion.so/berachain/BEX-RecoveryMode-and-Pause-explained-17c6120abced80e0985dd589b57ff018
|
|
47
|
-
*
|
|
48
|
-
* @returns status flags to enable/disable/notify users across the BEX
|
|
49
|
-
*
|
|
50
|
-
**/
|
|
51
|
-
declare function useBexStatus(): {
|
|
52
|
-
protocol: {
|
|
53
|
-
isPaused: boolean;
|
|
54
|
-
factories: FactoryStatus & {
|
|
55
|
-
allPaused: boolean;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
onPoolChange: Dispatch<SetStateAction<BexStatusProviderProps["pool"]>>;
|
|
59
|
-
pool?: {
|
|
60
|
-
id: Hex;
|
|
61
|
-
isInRecoveryMode: boolean;
|
|
62
|
-
isPaused: boolean;
|
|
63
|
-
disablePoolWithdrawals: boolean;
|
|
64
|
-
disablePoolDeposits: boolean;
|
|
65
|
-
};
|
|
66
|
-
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
67
|
-
};
|
|
68
|
-
declare function BexStatusProvider({ children, isVaultPaused, labels, factories, }: PropsWithChildren<BexStatusProviderProps>): react_jsx_runtime.JSX.Element;
|
|
69
|
-
|
|
70
|
-
export { BexStateContext as B, BexStatusProvider as a, type BexStatusProviderProps as b, useBexStatus as u };
|