@berachain/berajs 0.2.8-beta.11 → 0.2.8-beta.12
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.cts} +31 -2
- package/dist/{BeraError-_mQdkanr.d.ts → BeraError-7-A5JYy_.d.ts} +31 -2
- package/dist/{RequestError-DSUzJ1Iy.d.cts → RequestError-02juqN-5.d.cts} +1 -1
- package/dist/{RequestError-BRIiJgHk.d.ts → RequestError-DBOIV65x.d.ts} +1 -1
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/abi/exports.mjs +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +2 -2
- package/dist/actions/exports.d.ts +2 -2
- package/dist/actions/exports.mjs +1 -1
- package/dist/actions/governance/exports.cjs +1 -1
- package/dist/actions/governance/exports.cjs.map +1 -1
- package/dist/actions/governance/exports.mjs +1 -1
- package/dist/chunk-2A347ZVN.mjs +2 -0
- package/dist/{chunk-NXXMW2O7.mjs.map → chunk-2A347ZVN.mjs.map} +1 -1
- package/dist/{chunk-WLJHFHKF.mjs → chunk-2VO2D4QO.mjs} +2 -2
- package/dist/chunk-5FVW5XU3.mjs +2 -0
- package/dist/chunk-5FVW5XU3.mjs.map +1 -0
- package/dist/{chunk-GXV2JA36.mjs → chunk-5SIQ7BKT.mjs} +2 -2
- package/dist/chunk-5SIQ7BKT.mjs.map +1 -0
- package/dist/{chunk-ENT2OSXT.mjs → chunk-5XOEJ6XX.mjs} +2 -2
- package/dist/{chunk-ZW2N63FI.mjs → chunk-A5BNPBXN.mjs} +2 -2
- package/dist/{chunk-4TALWNXE.cjs → chunk-COSP3YIF.cjs} +2 -2
- package/dist/chunk-COSP3YIF.cjs.map +1 -0
- package/dist/chunk-D6L7LTA2.cjs.map +1 -1
- package/dist/{chunk-JXM5S4IU.mjs → chunk-DA7GK43B.mjs} +2 -2
- package/dist/chunk-DDEQFR3M.cjs.map +1 -1
- package/dist/{chunk-6JJIZCVY.cjs → chunk-DKZGCMH4.cjs} +2 -2
- package/dist/chunk-DKZGCMH4.cjs.map +1 -0
- package/dist/{chunk-Y2FETC6T.cjs → chunk-F4V5B6F7.cjs} +2 -2
- package/dist/chunk-F4V5B6F7.cjs.map +1 -0
- package/dist/{chunk-QVIAMSZ6.cjs → chunk-FDEUAXET.cjs} +2 -2
- package/dist/chunk-FDEUAXET.cjs.map +1 -0
- package/dist/{chunk-33XNWMPP.cjs → chunk-FQSOUEIJ.cjs} +2 -2
- package/dist/chunk-FQSOUEIJ.cjs.map +1 -0
- package/dist/{chunk-XZC34BHM.cjs → chunk-GEIY554A.cjs} +2 -2
- package/dist/chunk-GEIY554A.cjs.map +1 -0
- package/dist/{chunk-KUQEX7H3.mjs → chunk-JHUVLM54.mjs} +2 -2
- package/dist/{chunk-RCWM55DE.cjs → chunk-JZL5JPDJ.cjs} +2 -2
- package/dist/chunk-JZL5JPDJ.cjs.map +1 -0
- package/dist/{chunk-H6ZO4SLB.mjs → chunk-LUNZGZWN.mjs} +2 -2
- package/dist/{chunk-RJN36GBU.mjs → chunk-OCAMR6XC.mjs} +2 -2
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-OUD27MU7.cjs.map +1 -1
- package/dist/{chunk-JIPSTWKO.mjs → chunk-OYF32BQQ.mjs} +2 -2
- package/dist/{chunk-54BTOQE3.cjs → chunk-PFUVKW6F.cjs} +2 -2
- package/dist/chunk-PFUVKW6F.cjs.map +1 -0
- package/dist/{chunk-JSTCUTXP.cjs → chunk-QHCLZTCK.cjs} +2 -2
- package/dist/chunk-QHCLZTCK.cjs.map +1 -0
- package/dist/chunk-RWOICHRW.cjs.map +1 -1
- package/dist/{chunk-CHFETMC6.cjs → chunk-S2TNHMSV.cjs} +3 -3
- package/dist/chunk-S2TNHMSV.cjs.map +1 -0
- package/dist/chunk-S4CDSVLK.cjs.map +1 -1
- package/dist/{chunk-5QAFKFM5.mjs → chunk-TU63NRNL.mjs} +2 -2
- package/dist/{chunk-REWME3FY.cjs → chunk-W4JE2NIN.cjs} +2 -2
- package/dist/chunk-W4JE2NIN.cjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XB2SEO4Y.cjs +2 -0
- package/dist/chunk-XB2SEO4Y.cjs.map +1 -0
- package/dist/chunk-XCVDZUEF.mjs +2 -0
- package/dist/{chunk-K5L2B4DU.mjs.map → chunk-XCVDZUEF.mjs.map} +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/chunk-YYUSCGVI.cjs +2 -0
- package/dist/chunk-YYUSCGVI.cjs.map +1 -0
- package/dist/contexts/exports.cjs +1 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/contexts/exports.mjs +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/governance/exports.cjs.map +1 -1
- package/dist/errors/exports.cjs +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.d.cts +4 -3
- package/dist/errors/exports.d.ts +4 -3
- package/dist/errors/exports.mjs +1 -1
- package/dist/{global.d-ylUk_etZ.d.ts → global.d-C4FnE4cz.d.ts} +1 -1
- package/dist/{global.d-B9nLZ7ul.d.cts → global.d-CicOIudf.d.cts} +1 -1
- package/dist/hooks/exports.cjs +2 -2
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +3 -3
- package/dist/hooks/exports.d.ts +3 -3
- package/dist/hooks/exports.mjs +2 -2
- package/dist/hooks/governance/exports.cjs +1 -1
- package/dist/hooks/governance/exports.cjs.map +1 -1
- package/dist/hooks/governance/exports.d.cts +2 -2
- package/dist/hooks/governance/exports.d.ts +2 -2
- package/dist/hooks/governance/exports.mjs +1 -1
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +2 -2
- package/dist/types/exports.d.ts +2 -2
- package/dist/types/governance/exports.cjs.map +1 -1
- package/dist/utils/exports.cjs +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.d.cts +13 -4
- package/dist/utils/exports.d.ts +13 -4
- package/dist/utils/exports.mjs +1 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +46 -40
- package/src/actions/__test/transports.ts +61 -0
- package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
- package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
- package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
- package/src/data/contracts.ts +5 -0
- package/src/errors/BeraError.ts +27 -0
- package/src/errors/BeraTracing.unit.test.ts +65 -0
- package/src/errors/RequestError.ts +12 -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/utils/beraFetch.ts +9 -3
- package/src/utils/exports.ts +1 -0
- package/src/utils/getServerSideClient.ts +4 -2
- package/src/utils/sanitizeRpcUrl.ts +22 -0
- package/src/utils/tracedTransport.ts +35 -0
- package/dist/chunk-33XNWMPP.cjs.map +0 -1
- package/dist/chunk-4TALWNXE.cjs.map +0 -1
- package/dist/chunk-54BTOQE3.cjs.map +0 -1
- package/dist/chunk-6DIA6PXV.cjs +0 -2
- package/dist/chunk-6DIA6PXV.cjs.map +0 -1
- package/dist/chunk-6JJIZCVY.cjs.map +0 -1
- package/dist/chunk-BE6B4PQF.cjs +0 -2
- package/dist/chunk-BE6B4PQF.cjs.map +0 -1
- package/dist/chunk-CHFETMC6.cjs.map +0 -1
- package/dist/chunk-GXV2JA36.mjs.map +0 -1
- package/dist/chunk-JDDRTHFG.mjs +0 -2
- package/dist/chunk-JDDRTHFG.mjs.map +0 -1
- package/dist/chunk-JSTCUTXP.cjs.map +0 -1
- package/dist/chunk-K5L2B4DU.mjs +0 -2
- package/dist/chunk-NXXMW2O7.mjs +0 -2
- package/dist/chunk-QVIAMSZ6.cjs.map +0 -1
- package/dist/chunk-RCWM55DE.cjs.map +0 -1
- package/dist/chunk-REWME3FY.cjs.map +0 -1
- package/dist/chunk-XZC34BHM.cjs.map +0 -1
- package/dist/chunk-Y2FETC6T.cjs.map +0 -1
- /package/dist/{chunk-WLJHFHKF.mjs.map → chunk-2VO2D4QO.mjs.map} +0 -0
- /package/dist/{chunk-ENT2OSXT.mjs.map → chunk-5XOEJ6XX.mjs.map} +0 -0
- /package/dist/{chunk-ZW2N63FI.mjs.map → chunk-A5BNPBXN.mjs.map} +0 -0
- /package/dist/{chunk-JXM5S4IU.mjs.map → chunk-DA7GK43B.mjs.map} +0 -0
- /package/dist/{chunk-KUQEX7H3.mjs.map → chunk-JHUVLM54.mjs.map} +0 -0
- /package/dist/{chunk-H6ZO4SLB.mjs.map → chunk-LUNZGZWN.mjs.map} +0 -0
- /package/dist/{chunk-RJN36GBU.mjs.map → chunk-OCAMR6XC.mjs.map} +0 -0
- /package/dist/{chunk-JIPSTWKO.mjs.map → chunk-OYF32BQQ.mjs.map} +0 -0
- /package/dist/{chunk-5QAFKFM5.mjs.map → chunk-TU63NRNL.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@berachain/berajs",
|
|
3
|
-
"version": "0.2.8-beta.
|
|
3
|
+
"version": "0.2.8-beta.12",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@apollo/client": "4.1.6",
|
|
14
14
|
"@berachain-foundation/berancer-sdk": "1.1.4",
|
|
15
|
-
"@berachain/abis": "0.1.
|
|
16
|
-
"@berachain/config": "0.1.
|
|
17
|
-
"@berachain/graphql": "0.4.10-beta.
|
|
18
|
-
"@ensofinance/sdk": "2.
|
|
15
|
+
"@berachain/abis": "0.1.2",
|
|
16
|
+
"@berachain/config": "0.1.9-beta.0",
|
|
17
|
+
"@berachain/graphql": "0.4.10-beta.2",
|
|
18
|
+
"@ensofinance/sdk": "2.3.1",
|
|
19
19
|
"@pythnetwork/hermes-client": "2.0.0",
|
|
20
20
|
"@wagmi/core": "2.22.1",
|
|
21
21
|
"gray-matter": "4.0.3",
|
|
22
22
|
"swr": "2.4.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react-dom": "19.
|
|
26
|
-
"@types/react": "19.
|
|
25
|
+
"@types/react-dom": "19.2.3",
|
|
26
|
+
"@types/react": "19.2.14",
|
|
27
27
|
"@typescript/analyze-trace": "0.10.1",
|
|
28
28
|
"tsup": "8.5.1",
|
|
29
29
|
"typescript": "5.5.4",
|
|
@@ -33,55 +33,50 @@
|
|
|
33
33
|
"@berachain/wagmi": "0.4.2-beta.6"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
|
-
"./actions
|
|
37
|
-
"types": "./dist/actions
|
|
38
|
-
"import": "./dist/actions
|
|
39
|
-
"require": "./dist/actions
|
|
40
|
-
"
|
|
41
|
-
"default": "./dist/actions/governance/exports.cjs"
|
|
36
|
+
"./actions/*": {
|
|
37
|
+
"types": "./dist/actions/*/exports.d.ts",
|
|
38
|
+
"import": "./dist/actions/*/exports.mjs",
|
|
39
|
+
"require": "./dist/actions/*/exports.cjs",
|
|
40
|
+
"default": "./dist/actions/*/exports.cjs"
|
|
42
41
|
},
|
|
43
|
-
"./hooks
|
|
44
|
-
"types": "./dist/hooks
|
|
45
|
-
"import": "./dist/hooks
|
|
46
|
-
"require": "./dist/hooks
|
|
47
|
-
"
|
|
48
|
-
"default": "./dist/hooks/governance/exports.cjs"
|
|
42
|
+
"./hooks/*": {
|
|
43
|
+
"types": "./dist/hooks/*/exports.d.ts",
|
|
44
|
+
"import": "./dist/hooks/*/exports.mjs",
|
|
45
|
+
"require": "./dist/hooks/*/exports.cjs",
|
|
46
|
+
"default": "./dist/hooks/*/exports.cjs"
|
|
49
47
|
},
|
|
50
|
-
"./enum
|
|
51
|
-
"types": "./dist/enum
|
|
52
|
-
"import": "./dist/enum
|
|
53
|
-
"require": "./dist/enum
|
|
54
|
-
"
|
|
55
|
-
"default": "./dist/enum/governance/exports.cjs"
|
|
48
|
+
"./enum/*": {
|
|
49
|
+
"types": "./dist/enum/*/exports.d.ts",
|
|
50
|
+
"import": "./dist/enum/*/exports.mjs",
|
|
51
|
+
"require": "./dist/enum/*/exports.cjs",
|
|
52
|
+
"default": "./dist/enum/*/exports.cjs"
|
|
56
53
|
},
|
|
57
|
-
"./types
|
|
58
|
-
"types": "./dist/types
|
|
59
|
-
"import": "./dist/types
|
|
60
|
-
"require": "./dist/types
|
|
61
|
-
"
|
|
62
|
-
"default": "./dist/types/governance/exports.cjs"
|
|
54
|
+
"./types/*": {
|
|
55
|
+
"types": "./dist/types/*/exports.d.ts",
|
|
56
|
+
"import": "./dist/types/*/exports.mjs",
|
|
57
|
+
"require": "./dist/types/*/exports.cjs",
|
|
58
|
+
"default": "./dist/types/*/exports.cjs"
|
|
63
59
|
},
|
|
64
60
|
"./*": {
|
|
65
61
|
"types": "./dist/*/exports.d.ts",
|
|
66
62
|
"import": "./dist/*/exports.mjs",
|
|
67
63
|
"require": "./dist/*/exports.cjs",
|
|
68
|
-
"module": "./dist/*/exports.mjs",
|
|
69
64
|
"default": "./dist/*/exports.cjs"
|
|
70
65
|
}
|
|
71
66
|
},
|
|
72
67
|
"typesVersions": {
|
|
73
68
|
"*": {
|
|
74
|
-
"actions
|
|
75
|
-
"dist/actions
|
|
69
|
+
"actions/*": [
|
|
70
|
+
"dist/actions/*/exports.d.ts"
|
|
76
71
|
],
|
|
77
|
-
"hooks
|
|
78
|
-
"dist/hooks
|
|
72
|
+
"hooks/*": [
|
|
73
|
+
"dist/hooks/*/exports.d.ts"
|
|
79
74
|
],
|
|
80
|
-
"enum
|
|
81
|
-
"dist/enum
|
|
75
|
+
"enum/*": [
|
|
76
|
+
"dist/enum/*/exports.d.ts"
|
|
82
77
|
],
|
|
83
|
-
"types
|
|
84
|
-
"dist/types
|
|
78
|
+
"types/*": [
|
|
79
|
+
"dist/types/*/exports.d.ts"
|
|
85
80
|
],
|
|
86
81
|
"*": [
|
|
87
82
|
"dist/*/exports.d.ts"
|
|
@@ -94,6 +89,17 @@
|
|
|
94
89
|
"viem": "^2.41.2",
|
|
95
90
|
"@berachain/wagmi": "0.4.2-beta.6"
|
|
96
91
|
},
|
|
92
|
+
"peerDependenciesMeta": {
|
|
93
|
+
"react": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"react-dom": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"viem": {
|
|
100
|
+
"optional": false
|
|
101
|
+
}
|
|
102
|
+
},
|
|
97
103
|
"scripts": {
|
|
98
104
|
"build": "NODE_OPTIONS='--max-old-space-size=8192' tsup",
|
|
99
105
|
"prebuild": "pnpm contracts:update",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { fallback, http } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
arbitrum,
|
|
4
|
+
avalanche,
|
|
5
|
+
base,
|
|
6
|
+
bsc,
|
|
7
|
+
mainnet,
|
|
8
|
+
optimism,
|
|
9
|
+
polygon,
|
|
10
|
+
} from "viem/chains";
|
|
11
|
+
|
|
12
|
+
import { publicJsonRpcUrl } from "@berachain/config/internal";
|
|
13
|
+
import { defaultChain } from "@berachain/config/internal/wagmi";
|
|
14
|
+
|
|
15
|
+
const transportOptions = {
|
|
16
|
+
batch: { wait: 35 },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const externalTransportOptions = {
|
|
20
|
+
batch: { wait: 15 },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const urls = [publicJsonRpcUrl].filter(Boolean) as string[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Thirdweb RPC URLs have a rate limit of 3 RPS.
|
|
27
|
+
* http() uses default viem transport which varies based on the chain definition.
|
|
28
|
+
*
|
|
29
|
+
* Quicknode RPC URLs are CORS restricted to *.berachain.com, *.berachain-staging.com. They have a 100rpm rate limit.
|
|
30
|
+
*/
|
|
31
|
+
export const testTransports = {
|
|
32
|
+
[defaultChain.id]: fallback(urls.map((url) => http(url, transportOptions))),
|
|
33
|
+
[mainnet.id]: fallback([
|
|
34
|
+
http("https://1.rpc.thirdweb.com/", externalTransportOptions),
|
|
35
|
+
http(),
|
|
36
|
+
]),
|
|
37
|
+
[polygon.id]: fallback([
|
|
38
|
+
http("https://137.rpc.thirdweb.com/", externalTransportOptions),
|
|
39
|
+
http(),
|
|
40
|
+
]),
|
|
41
|
+
[optimism.id]: fallback([
|
|
42
|
+
http("https://10.rpc.thirdweb.com/", externalTransportOptions),
|
|
43
|
+
http(),
|
|
44
|
+
]),
|
|
45
|
+
[base.id]: fallback([
|
|
46
|
+
http("https://8453.rpc.thirdweb.com/", externalTransportOptions),
|
|
47
|
+
http(),
|
|
48
|
+
]),
|
|
49
|
+
[bsc.id]: fallback([
|
|
50
|
+
http("https://56.rpc.thirdweb.com/", externalTransportOptions),
|
|
51
|
+
http(),
|
|
52
|
+
]),
|
|
53
|
+
[avalanche.id]: fallback([
|
|
54
|
+
http("https://43114.rpc.thirdweb.com/", externalTransportOptions),
|
|
55
|
+
http(),
|
|
56
|
+
]),
|
|
57
|
+
[arbitrum.id]: fallback([
|
|
58
|
+
http("https://42161.rpc.thirdweb.com/", externalTransportOptions),
|
|
59
|
+
http(),
|
|
60
|
+
]),
|
|
61
|
+
};
|
|
@@ -9,15 +9,12 @@ import {
|
|
|
9
9
|
} from "vitest";
|
|
10
10
|
|
|
11
11
|
import { appConfig } from "@berachain/config/internal";
|
|
12
|
-
import {
|
|
13
|
-
defaultChain,
|
|
14
|
-
externalChains,
|
|
15
|
-
transports,
|
|
16
|
-
} from "@berachain/config/internal/wagmi";
|
|
12
|
+
import { defaultChain, externalChains } from "@berachain/config/internal/wagmi";
|
|
17
13
|
|
|
18
14
|
import { getConfig } from "@berachain/wagmi/config";
|
|
19
15
|
|
|
20
16
|
import { BeraMonitoring } from "../../../errors/BeraMonitoring";
|
|
17
|
+
import { testTransports } from "../../__test/transports";
|
|
21
18
|
import { getEnsoClient } from "../../clients/getEnsoClient";
|
|
22
19
|
import { getEnsoUserTokensWithBalances } from "../getEnsoUserTokensWithBalances";
|
|
23
20
|
|
|
@@ -41,7 +38,7 @@ describe("getEnsoUserTokensWithBalances", () => {
|
|
|
41
38
|
const ensoClient = getEnsoClient();
|
|
42
39
|
|
|
43
40
|
const beraWagmiConfig = getConfig({
|
|
44
|
-
transports,
|
|
41
|
+
transports: testTransports,
|
|
45
42
|
defaultChain,
|
|
46
43
|
chains: externalChains,
|
|
47
44
|
thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
|
|
@@ -2,15 +2,12 @@ import { ethAddress } from "viem";
|
|
|
2
2
|
import { assert, describe, expect, it } from "vitest";
|
|
3
3
|
|
|
4
4
|
import { appConfig } from "@berachain/config/internal";
|
|
5
|
-
import {
|
|
6
|
-
defaultChain,
|
|
7
|
-
externalChains,
|
|
8
|
-
transports,
|
|
9
|
-
} from "@berachain/config/internal/wagmi";
|
|
5
|
+
import { defaultChain, externalChains } from "@berachain/config/internal/wagmi";
|
|
10
6
|
|
|
11
7
|
import { getConfig } from "@berachain/wagmi/config";
|
|
12
8
|
|
|
13
9
|
import { isToken } from "../../utils/tokens";
|
|
10
|
+
import { testTransports } from "../__test/transports";
|
|
14
11
|
import { getTokens } from "./getTokens";
|
|
15
12
|
import { getWalletBalances } from "./getWalletBalances";
|
|
16
13
|
|
|
@@ -22,7 +19,7 @@ import { getWalletBalances } from "./getWalletBalances";
|
|
|
22
19
|
const account = "0x08194D89A52C1410F4bcc46FE11AC2387aC69de8";
|
|
23
20
|
describe("getWalletBalances", async () => {
|
|
24
21
|
const { wagmi: wagmiConfig } = getConfig({
|
|
25
|
-
transports,
|
|
22
|
+
transports: testTransports,
|
|
26
23
|
defaultChain,
|
|
27
24
|
chains: externalChains,
|
|
28
25
|
thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
|
|
@@ -11,11 +11,7 @@ import { mnemonicToAccount } from "viem/accounts";
|
|
|
11
11
|
import { assert, describe, expect, it } from "vitest";
|
|
12
12
|
|
|
13
13
|
import { appConfig, ChainId, getRpcUrls } from "@berachain/config/internal";
|
|
14
|
-
import {
|
|
15
|
-
defaultChain,
|
|
16
|
-
externalChains,
|
|
17
|
-
transports,
|
|
18
|
-
} from "@berachain/config/internal/wagmi";
|
|
14
|
+
import { defaultChain, externalChains } from "@berachain/config/internal/wagmi";
|
|
19
15
|
|
|
20
16
|
import { bgtAbi } from "@berachain/abis/pol/bgt";
|
|
21
17
|
import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
|
|
@@ -28,6 +24,7 @@ import { getServerSidePublicClient } from "../../utils/getServerSideClient";
|
|
|
28
24
|
import { getTestClient } from "../../utils/getTestClient";
|
|
29
25
|
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
30
26
|
import { anvilMnemonic } from "../../utils/test-utils";
|
|
27
|
+
import { testTransports } from "../__test/transports";
|
|
31
28
|
import { getUserVaults } from "../pol/getUserVaults";
|
|
32
29
|
import { beraWriteContract } from "./beraWriteContract";
|
|
33
30
|
|
|
@@ -38,7 +35,7 @@ const testFn: IContractWriteFn = async (_args) => {
|
|
|
38
35
|
describe("beraWriteContract", () => {
|
|
39
36
|
const { config } = parseBaseArgs({ chainId: defaultChain.id });
|
|
40
37
|
const beraWagmiConfig = getConfig({
|
|
41
|
-
transports,
|
|
38
|
+
transports: testTransports,
|
|
42
39
|
defaultChain,
|
|
43
40
|
chains: externalChains,
|
|
44
41
|
thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
|
package/src/data/contracts.ts
CHANGED
|
@@ -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",
|
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
|
|
@@ -165,6 +165,71 @@ describe("BeraTracing", () => {
|
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
+
describe("span status adapter pattern", () => {
|
|
169
|
+
it("adapter handler can read spanStatus from BeraError", async () => {
|
|
170
|
+
const { BeraError } = await import("./BeraError.js");
|
|
171
|
+
const statuses: string[] = [];
|
|
172
|
+
|
|
173
|
+
// Simulates the Sentry adapter wrapper pattern
|
|
174
|
+
const adapterHandler = async (
|
|
175
|
+
_ctx: any,
|
|
176
|
+
callback: () => Promise<any>,
|
|
177
|
+
) => {
|
|
178
|
+
try {
|
|
179
|
+
const result = await callback();
|
|
180
|
+
statuses.push("ok");
|
|
181
|
+
return result;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
const status =
|
|
184
|
+
error instanceof BeraError && error.spanStatus
|
|
185
|
+
? error.spanStatus
|
|
186
|
+
: "internal_error";
|
|
187
|
+
statuses.push(status);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const unsub = BeraTracing.addSpanHandler(adapterHandler);
|
|
193
|
+
|
|
194
|
+
// Test: error with spanStatus propagates through
|
|
195
|
+
await expect(
|
|
196
|
+
BeraTracing.startSpan(
|
|
197
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
198
|
+
async () => {
|
|
199
|
+
throw new BeraError({
|
|
200
|
+
message: "user cancelled",
|
|
201
|
+
reason: "UserRejectedRequestError",
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
),
|
|
205
|
+
).rejects.toThrow("user cancelled");
|
|
206
|
+
|
|
207
|
+
expect(statuses).toEqual(["cancelled"]);
|
|
208
|
+
|
|
209
|
+
// Test: success sets ok
|
|
210
|
+
statuses.length = 0;
|
|
211
|
+
await BeraTracing.startSpan(
|
|
212
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
213
|
+
async () => "done",
|
|
214
|
+
);
|
|
215
|
+
expect(statuses).toEqual(["ok"]);
|
|
216
|
+
|
|
217
|
+
// Test: non-BeraError defaults to internal_error
|
|
218
|
+
statuses.length = 0;
|
|
219
|
+
await expect(
|
|
220
|
+
BeraTracing.startSpan(
|
|
221
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
222
|
+
async () => {
|
|
223
|
+
throw new Error("plain error");
|
|
224
|
+
},
|
|
225
|
+
),
|
|
226
|
+
).rejects.toThrow("plain error");
|
|
227
|
+
expect(statuses).toEqual(["internal_error"]);
|
|
228
|
+
|
|
229
|
+
unsub();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
168
233
|
describe("Sentry.startSpan compatibility", () => {
|
|
169
234
|
it("works with a handler that accepts (options, callback) like Sentry.startSpan", async () => {
|
|
170
235
|
// Sentry.startSpan signature: <T>(options, callback: (span) => T) => T
|
|
@@ -5,6 +5,7 @@ import { mainnet } from "@berachain/config/mainnet";
|
|
|
5
5
|
|
|
6
6
|
import { BeraError, type IBeraErrorArgs } from "./BeraError";
|
|
7
7
|
import { errorMsgMap } from "./errorMap";
|
|
8
|
+
import { httpStatusToSpanStatus, reasonToSpanStatus } from "./spanStatus";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* This is an error class that should be used to handle errors from fetch requests.
|
|
@@ -104,6 +105,17 @@ export class RequestError extends BeraError {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
// ── Span status inference ─────────────────────────────────────────
|
|
109
|
+
// Re-infer from reason since it may have been set after super() ran
|
|
110
|
+
// (e.g. NETWORK_ERROR → unavailable, RATE_LIMITED_429 → resource_exhausted).
|
|
111
|
+
if (!this.spanStatus && this.reason) {
|
|
112
|
+
this.spanStatus = reasonToSpanStatus(this.reason);
|
|
113
|
+
}
|
|
114
|
+
// Fall back to HTTP status code mapping when no reason-based status.
|
|
115
|
+
if (!this.spanStatus && this.statusCode) {
|
|
116
|
+
this.spanStatus = httpStatusToSpanStatus(this.statusCode);
|
|
117
|
+
}
|
|
118
|
+
|
|
107
119
|
this.tags = {
|
|
108
120
|
...this.tags,
|
|
109
121
|
"error.statusCode": this.statusCode,
|
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
|
+
});
|
package/src/utils/beraFetch.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BeraTracing, type SpanContext } from "../errors/BeraTracing";
|
|
2
2
|
import { RequestError } from "../errors/RequestError";
|
|
3
3
|
import { getErrorResponse } from "./getErrorResponse";
|
|
4
|
+
import { sanitizeRpcUrl } from "./sanitizeRpcUrl";
|
|
4
5
|
|
|
5
6
|
type RequestOptions = RequestInit;
|
|
6
7
|
|
|
@@ -18,10 +19,10 @@ export async function beraFetch(
|
|
|
18
19
|
},
|
|
19
20
|
) {
|
|
20
21
|
try {
|
|
21
|
-
let spanUrl = (
|
|
22
|
+
let spanUrl = sanitizeRpcUrl(
|
|
22
23
|
typeof endpoint === "string" || endpoint instanceof URL
|
|
23
24
|
? endpoint.toString()
|
|
24
|
-
: endpoint.url.toString()
|
|
25
|
+
: endpoint.url.toString(),
|
|
25
26
|
).replace(/0x[a-fA-F0-9]{40}/g, ":address");
|
|
26
27
|
|
|
27
28
|
if (spanContext?.keepQueryParams !== true && URL.canParse(spanUrl)) {
|
|
@@ -43,10 +44,15 @@ export async function beraFetch(
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
const endpointName =
|
|
48
|
+
typeof endpoint === "string" || endpoint instanceof URL
|
|
49
|
+
? undefined
|
|
50
|
+
: endpoint.name;
|
|
51
|
+
|
|
46
52
|
return await BeraTracing.startSpan(
|
|
47
53
|
{
|
|
48
54
|
op: "beraFetch",
|
|
49
|
-
name: "beraFetch",
|
|
55
|
+
name: endpointName ? `beraFetch ${endpointName}` : "beraFetch",
|
|
50
56
|
attributes:
|
|
51
57
|
typeof endpoint === "string" || endpoint instanceof URL
|
|
52
58
|
? {
|
package/src/utils/exports.ts
CHANGED