@berachain/berajs 0.2.8-beta.0 → 0.2.8-beta.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/RequestError-BRIiJgHk.d.ts +144 -0
- package/dist/RequestError-DSUzJ1Iy.d.cts +144 -0
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +22 -105
- package/dist/actions/exports.d.ts +22 -105
- package/dist/actions/exports.mjs +1 -1
- package/dist/actions/exports.mjs.map +1 -1
- package/dist/actions/governance/exports.cjs +2 -0
- package/dist/actions/governance/exports.cjs.map +1 -0
- package/dist/actions/governance/exports.d.cts +140 -0
- package/dist/actions/governance/exports.d.ts +140 -0
- package/dist/actions/governance/exports.mjs +2 -0
- package/dist/actions/governance/exports.mjs.map +1 -0
- package/dist/chunk-33XNWMPP.cjs +2 -0
- package/dist/chunk-33XNWMPP.cjs.map +1 -0
- package/dist/chunk-4TALWNXE.cjs +2 -0
- package/dist/chunk-4TALWNXE.cjs.map +1 -0
- package/dist/chunk-54BTOQE3.cjs +2 -0
- package/dist/chunk-54BTOQE3.cjs.map +1 -0
- package/dist/chunk-5QAFKFM5.mjs +2 -0
- package/dist/chunk-5QAFKFM5.mjs.map +1 -0
- package/dist/chunk-6DIA6PXV.cjs +2 -0
- package/dist/chunk-6DIA6PXV.cjs.map +1 -0
- package/dist/{chunk-NMH7LHPW.cjs → chunk-6JJIZCVY.cjs} +2 -2
- package/dist/chunk-6JJIZCVY.cjs.map +1 -0
- package/dist/chunk-BE6B4PQF.cjs +2 -0
- package/dist/chunk-BE6B4PQF.cjs.map +1 -0
- package/dist/chunk-CHFETMC6.cjs +4 -0
- package/dist/chunk-CHFETMC6.cjs.map +1 -0
- package/dist/{chunk-I7M43BB4.cjs → chunk-D6L7LTA2.cjs} +2 -2
- package/dist/chunk-D6L7LTA2.cjs.map +1 -0
- package/dist/chunk-DDEQFR3M.cjs.map +1 -1
- package/dist/chunk-ENT2OSXT.mjs +2 -0
- package/dist/chunk-ENT2OSXT.mjs.map +1 -0
- package/dist/{chunk-74QD4JAH.mjs → chunk-GXV2JA36.mjs} +2 -2
- package/dist/chunk-GXV2JA36.mjs.map +1 -0
- package/dist/chunk-H6ZO4SLB.mjs +4 -0
- package/dist/chunk-H6ZO4SLB.mjs.map +1 -0
- package/dist/chunk-JDDRTHFG.mjs +2 -0
- package/dist/chunk-JDDRTHFG.mjs.map +1 -0
- package/dist/{chunk-T5FSQ3YE.mjs → chunk-JDZGYU5T.mjs} +2 -2
- package/dist/{chunk-T5FSQ3YE.mjs.map → chunk-JDZGYU5T.mjs.map} +1 -1
- package/dist/chunk-JIPSTWKO.mjs +2 -0
- package/dist/{chunk-COMMLZ3O.mjs.map → chunk-JIPSTWKO.mjs.map} +1 -1
- package/dist/chunk-JSTCUTXP.cjs +2 -0
- package/dist/chunk-JSTCUTXP.cjs.map +1 -0
- package/dist/{chunk-MJZHJFZO.mjs → chunk-JXM5S4IU.mjs} +2 -2
- package/dist/chunk-K5L2B4DU.mjs +2 -0
- package/dist/{chunk-FM3WDBFH.mjs.map → chunk-K5L2B4DU.mjs.map} +1 -1
- package/dist/chunk-KUQEX7H3.mjs +2 -0
- package/dist/chunk-KUQEX7H3.mjs.map +1 -0
- package/dist/chunk-NXXMW2O7.mjs +2 -0
- package/dist/chunk-NXXMW2O7.mjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-OUD27MU7.cjs.map +1 -1
- package/dist/chunk-PRLVZIKD.mjs +2 -0
- package/dist/chunk-PRLVZIKD.mjs.map +1 -0
- package/dist/chunk-QVIAMSZ6.cjs +2 -0
- package/dist/chunk-QVIAMSZ6.cjs.map +1 -0
- package/dist/chunk-RCWM55DE.cjs +2 -0
- package/dist/chunk-RCWM55DE.cjs.map +1 -0
- package/dist/chunk-REWME3FY.cjs +2 -0
- package/dist/chunk-REWME3FY.cjs.map +1 -0
- package/dist/chunk-RJN36GBU.mjs +2 -0
- package/dist/chunk-RJN36GBU.mjs.map +1 -0
- package/dist/chunk-RWOICHRW.cjs.map +1 -1
- package/dist/chunk-S4CDSVLK.cjs +2 -0
- package/dist/chunk-S4CDSVLK.cjs.map +1 -0
- package/dist/chunk-WLJHFHKF.mjs +2 -0
- package/dist/chunk-WLJHFHKF.mjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/chunk-XZC34BHM.cjs +2 -0
- package/dist/chunk-XZC34BHM.cjs.map +1 -0
- package/dist/chunk-Y2FETC6T.cjs +2 -0
- package/dist/chunk-Y2FETC6T.cjs.map +1 -0
- package/dist/chunk-ZW2N63FI.mjs +2 -0
- package/dist/chunk-ZW2N63FI.mjs.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/contexts/exports.mjs.map +1 -1
- package/dist/enum/exports.cjs +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/exports.d.cts +1 -1
- package/dist/enum/exports.d.ts +1 -1
- package/dist/enum/exports.mjs +1 -1
- package/dist/enum/exports.mjs.map +1 -1
- package/dist/enum/governance/exports.cjs +2 -0
- package/dist/enum/governance/exports.cjs.map +1 -0
- package/dist/enum/governance/exports.d.cts +60 -0
- package/dist/enum/governance/exports.d.ts +60 -0
- package/dist/enum/governance/exports.mjs +2 -0
- package/dist/enum/governance/exports.mjs.map +1 -0
- package/dist/errors/exports.cjs +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.d.cts +3 -89
- package/dist/errors/exports.d.ts +3 -89
- package/dist/errors/exports.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-BfKrMaui.d.cts → getValidatorQueuedOperatorAddress-CPuIw7n5.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-Bef1e1c_.d.ts → getValidatorQueuedOperatorAddress-CbZQ0kv2.d.ts} +2 -2
- package/dist/{global.d-DW7dpBsz.d.cts → global.d-B2WavzCY.d.cts} +3 -239
- package/dist/{global.d-CrPSEwwf.d.ts → global.d-D8byjWYx.d.ts} +3 -239
- package/dist/hooks/exports.cjs +3 -3
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +19 -198
- package/dist/hooks/exports.d.ts +19 -198
- package/dist/hooks/exports.mjs +3 -3
- package/dist/hooks/exports.mjs.map +1 -1
- package/dist/hooks/governance/exports.cjs +2 -0
- package/dist/hooks/governance/exports.cjs.map +1 -0
- package/dist/hooks/governance/exports.d.cts +181 -0
- package/dist/hooks/governance/exports.d.ts +181 -0
- package/dist/hooks/governance/exports.mjs +2 -0
- package/dist/hooks/governance/exports.mjs.map +1 -0
- package/dist/pol.d-o6Iw75bK.d.cts +134 -0
- package/dist/pol.d-qR8bGEP5.d.ts +134 -0
- package/dist/{txnEnum-CCuQUFlh.d.cts → txnEnum-CwAJN4zV.d.cts} +3 -60
- package/dist/{txnEnum-CCuQUFlh.d.ts → txnEnum-CwAJN4zV.d.ts} +3 -60
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +7 -7
- package/dist/types/exports.d.ts +7 -7
- package/dist/types/governance/exports.cjs +1 -0
- package/dist/types/governance/exports.cjs.map +1 -0
- package/dist/types/governance/exports.d.cts +109 -0
- package/dist/types/governance/exports.d.ts +109 -0
- package/dist/types/governance/exports.mjs +1 -0
- package/dist/types/governance/exports.mjs.map +1 -0
- package/dist/utils/exports.cjs +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.d.cts +10 -2
- package/dist/utils/exports.d.ts +10 -2
- package/dist/utils/exports.mjs +1 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +16 -7
- package/src/actions/clients/BeraApolloClient.ts +9 -0
- package/src/actions/clients/getApolloClient.ts +23 -6
- package/src/actions/dex/getOnChainPool.ts +1 -1
- package/src/actions/enso/getBendMultiplyBundle.ts +9 -2
- package/src/actions/enso/util.ts +6 -8
- package/src/actions/exports.ts +1 -10
- package/src/actions/governance/checkProposalField.ts +108 -54
- package/src/actions/governance/computeActualStatus.ts +7 -3
- package/src/actions/governance/exports.ts +9 -0
- package/src/actions/governance/getAllProposals.ts +15 -8
- package/src/actions/governance/getBodyErrors.ts +13 -5
- package/src/actions/governance/getDecodedFunctionData.ts +31 -22
- package/src/actions/governance/getProposalDetails.ts +8 -4
- package/src/actions/governance/getProposalFromTx.ts +19 -10
- package/src/actions/governance/getProposalParams.ts +17 -17
- package/src/actions/governance/getProposalVotes.ts +7 -3
- package/src/actions/governance/getQuorum.ts +7 -7
- package/src/actions/governance/parseProposalBody.ts +19 -9
- package/src/actions/honey/getChartData.ts +5 -5
- package/src/actions/honey/getHoney24hVolume.ts +30 -0
- package/src/actions/honey/getHoneyPythPriceOracle.ts +1 -1
- package/src/actions/honey/getHoneyRootPriceOracle.ts +1 -1
- package/src/actions/pol/getEarnedStakedBeraVault.ts +12 -2
- package/src/actions/pol/getRewardVaultBeaconImplementation.ts +1 -1
- package/src/actions/pol/getRewardVaultIncentives.ts +15 -15
- package/src/actions/pol/getStakingDailyAssets.ts +7 -1
- package/src/actions/pol/getTotalStakedAmount.ts +1 -1
- package/src/actions/pol/getUserClaimableIncentives.ts +1 -1
- package/src/actions/pol/getUserVaultsReward.ts +1 -1
- package/src/actions/tokens/getTokenInformation.ts +8 -15
- package/src/actions/tokens/getUnderlyingToken.ts +1 -1
- package/src/actions/validators/getUserBoosts.ts +1 -1
- package/src/enum/exports.ts +0 -1
- package/src/enum/governance/exports.ts +1 -0
- package/src/enum/txnEnum.ts +2 -0
- package/src/errors/BeraError.ts +7 -2
- package/src/errors/RequestError.ts +2 -1
- package/src/hooks/dex/usePoolHistoricalData.ts +1 -1
- package/src/hooks/enso/useBendZapSupply.ts +1 -1
- package/src/hooks/exports.ts +1 -15
- package/src/hooks/governance/exports.ts +14 -0
- package/src/hooks/honey/useHoney24hVolume.ts +16 -0
- package/src/hooks/perps/usePythUpdateFee.ts +1 -1
- package/src/hooks/validators/useValidatorRewardAllocation.ts +1 -1
- package/src/types/exports.ts +0 -1
- package/src/types/governance/exports.ts +1 -0
- package/src/utils/beraFetch.ts +70 -15
- package/src/utils/getErrorResponse.ts +1 -1
- package/dist/RequestError-A8XJ6QR9.d.cts +0 -57
- package/dist/RequestError-Dk97z8rm.d.ts +0 -57
- package/dist/chunk-2YBHAMDV.cjs +0 -2
- package/dist/chunk-2YBHAMDV.cjs.map +0 -1
- package/dist/chunk-57RINXU6.cjs +0 -2
- package/dist/chunk-57RINXU6.cjs.map +0 -1
- package/dist/chunk-74QD4JAH.mjs.map +0 -1
- package/dist/chunk-74WA35RI.cjs +0 -2
- package/dist/chunk-74WA35RI.cjs.map +0 -1
- package/dist/chunk-BEKH5EYT.mjs +0 -2
- package/dist/chunk-BEKH5EYT.mjs.map +0 -1
- package/dist/chunk-CF3LFNXG.cjs +0 -2
- package/dist/chunk-CF3LFNXG.cjs.map +0 -1
- package/dist/chunk-COMMLZ3O.mjs +0 -2
- package/dist/chunk-DK42F2ZM.cjs +0 -2
- package/dist/chunk-DK42F2ZM.cjs.map +0 -1
- package/dist/chunk-FCZ72ML6.mjs +0 -4
- package/dist/chunk-FCZ72ML6.mjs.map +0 -1
- package/dist/chunk-FM3WDBFH.mjs +0 -2
- package/dist/chunk-I7M43BB4.cjs.map +0 -1
- package/dist/chunk-IDFMLLDY.mjs +0 -2
- package/dist/chunk-IDFMLLDY.mjs.map +0 -1
- package/dist/chunk-LHR24OO7.cjs +0 -4
- package/dist/chunk-LHR24OO7.cjs.map +0 -1
- package/dist/chunk-LNVR4BW6.cjs +0 -2
- package/dist/chunk-LNVR4BW6.cjs.map +0 -1
- package/dist/chunk-NMH7LHPW.cjs.map +0 -1
- package/dist/chunk-NVHV2LDK.cjs +0 -2
- package/dist/chunk-NVHV2LDK.cjs.map +0 -1
- package/dist/chunk-PLIH6KQM.mjs +0 -2
- package/dist/chunk-PLIH6KQM.mjs.map +0 -1
- package/dist/chunk-QRAIGQF2.mjs +0 -2
- package/dist/chunk-QRAIGQF2.mjs.map +0 -1
- package/src/actions/honey/getHoneyGlobalData.ts +0 -21
- package/src/hooks/honey/useHoneyGlobalData.ts +0 -23
- /package/dist/{chunk-MJZHJFZO.mjs.map → chunk-JXM5S4IU.mjs.map} +0 -0
|
@@ -10,43 +10,74 @@ type CheckProposalFieldResult =
|
|
|
10
10
|
| CheckProposalFieldResultMinimal[]
|
|
11
11
|
| Record<string, CheckProposalFieldResultMinimal>;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
baseUrl?: string;
|
|
39
|
-
components?: readonly (AbiParameter | readonly AbiParameter[])[];
|
|
40
|
-
}): CheckProposalFieldResult;
|
|
13
|
+
/**
|
|
14
|
+
* Internal implementation arg covering the full union of all valid fieldOrType
|
|
15
|
+
* values. The public overloads below provide the narrowed return types.
|
|
16
|
+
*/
|
|
17
|
+
interface CheckProposalFieldImplArg {
|
|
18
|
+
fieldOrType:
|
|
19
|
+
| "address"
|
|
20
|
+
| "hex"
|
|
21
|
+
| "abi"
|
|
22
|
+
| "string"
|
|
23
|
+
| "bool"
|
|
24
|
+
| `uint${string}`
|
|
25
|
+
| `int${string}`
|
|
26
|
+
| "action"
|
|
27
|
+
| "title"
|
|
28
|
+
| "forumLink"
|
|
29
|
+
| "description"
|
|
30
|
+
| "logoURI"
|
|
31
|
+
| "url"
|
|
32
|
+
| "tuple[]"
|
|
33
|
+
| "tuple";
|
|
34
|
+
value: unknown;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
components?: readonly (AbiParameter | readonly AbiParameter[])[];
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Validates a single proposal field or ABI-typed value.
|
|
42
|
+
* Returns `null` if valid, or a `ProposalErrorCodes` value describing the problem.
|
|
43
|
+
*/
|
|
44
|
+
export function checkProposalField(arg: {
|
|
45
|
+
fieldOrType:
|
|
46
|
+
| "address"
|
|
47
|
+
| "hex"
|
|
48
|
+
| "abi"
|
|
49
|
+
| "string"
|
|
50
|
+
| "bool"
|
|
51
|
+
| `uint${string}`
|
|
52
|
+
| `int${string}`
|
|
53
|
+
| "action"
|
|
54
|
+
| "title"
|
|
55
|
+
| "forumLink"
|
|
56
|
+
| "description"
|
|
57
|
+
| "logoURI"
|
|
58
|
+
| "url";
|
|
59
|
+
value: unknown;
|
|
60
|
+
required?: boolean;
|
|
61
|
+
baseUrl?: string;
|
|
62
|
+
components?: readonly (AbiParameter | readonly AbiParameter[])[];
|
|
63
|
+
}): CheckProposalFieldResultMinimal;
|
|
64
|
+
/**
|
|
65
|
+
* For tuple/tuple[] types, may return nested error structures.
|
|
66
|
+
*/
|
|
67
|
+
export function checkProposalField(arg: {
|
|
68
|
+
fieldOrType: "tuple[]" | "tuple";
|
|
69
|
+
value: unknown;
|
|
70
|
+
required?: boolean;
|
|
71
|
+
baseUrl?: string;
|
|
72
|
+
components?: readonly (AbiParameter | readonly AbiParameter[])[];
|
|
73
|
+
}): CheckProposalFieldResult;
|
|
74
|
+
export function checkProposalField({
|
|
44
75
|
fieldOrType,
|
|
45
76
|
value,
|
|
46
77
|
required = true,
|
|
47
78
|
baseUrl,
|
|
48
79
|
components,
|
|
49
|
-
})
|
|
80
|
+
}: CheckProposalFieldImplArg): CheckProposalFieldResult {
|
|
50
81
|
const notRequiredAbiTypes = ["bool", "string"];
|
|
51
82
|
|
|
52
83
|
if (
|
|
@@ -89,19 +120,19 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
89
120
|
return null;
|
|
90
121
|
|
|
91
122
|
case "title":
|
|
92
|
-
if (value.length === 0) {
|
|
123
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
93
124
|
return ProposalErrorCodes.REQUIRED;
|
|
94
125
|
}
|
|
95
126
|
return null;
|
|
96
127
|
|
|
97
128
|
case "description":
|
|
98
|
-
if (value.length === 0) {
|
|
129
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
99
130
|
return ProposalErrorCodes.REQUIRED;
|
|
100
131
|
}
|
|
101
132
|
return null;
|
|
102
133
|
|
|
103
|
-
case "forumLink":
|
|
104
|
-
if (value.length === 0) {
|
|
134
|
+
case "forumLink": {
|
|
135
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
105
136
|
return ProposalErrorCodes.REQUIRED;
|
|
106
137
|
}
|
|
107
138
|
|
|
@@ -109,8 +140,7 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
109
140
|
return ProposalErrorCodes.INVALID_ADDRESS;
|
|
110
141
|
}
|
|
111
142
|
|
|
112
|
-
|
|
113
|
-
const base = new URL(baseUrl as string);
|
|
143
|
+
const base = new URL(baseUrl!);
|
|
114
144
|
|
|
115
145
|
// base.pathname = "/c/";
|
|
116
146
|
|
|
@@ -119,21 +149,25 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
119
149
|
}
|
|
120
150
|
|
|
121
151
|
return null;
|
|
152
|
+
}
|
|
122
153
|
|
|
123
154
|
case "address":
|
|
124
|
-
if (!isAddress(value, { strict: true })) {
|
|
155
|
+
if (typeof value !== "string" || !isAddress(value, { strict: true })) {
|
|
125
156
|
return ProposalErrorCodes.INVALID_ADDRESS;
|
|
126
157
|
}
|
|
127
158
|
|
|
128
159
|
return null;
|
|
129
160
|
|
|
130
161
|
case "hex":
|
|
131
|
-
if (!isHex(value, { strict: true })) {
|
|
162
|
+
if (typeof value !== "string" || !isHex(value, { strict: true })) {
|
|
132
163
|
return ProposalErrorCodes.INVALID_ADDRESS;
|
|
133
164
|
}
|
|
134
165
|
return null;
|
|
135
166
|
|
|
136
167
|
case "abi":
|
|
168
|
+
if (typeof value !== "string") {
|
|
169
|
+
return ProposalErrorCodes.INVALID_ABI;
|
|
170
|
+
}
|
|
137
171
|
try {
|
|
138
172
|
JSON.parse(value);
|
|
139
173
|
} catch {
|
|
@@ -142,20 +176,29 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
142
176
|
return null;
|
|
143
177
|
|
|
144
178
|
case "action":
|
|
145
|
-
if (!isAddress(value, { strict: true })) {
|
|
179
|
+
if (typeof value !== "string" || !isAddress(value, { strict: true })) {
|
|
146
180
|
return ProposalErrorCodes.INVALID_ADDRESS;
|
|
147
181
|
}
|
|
148
182
|
return null;
|
|
149
183
|
|
|
150
184
|
case "tuple":
|
|
151
185
|
if (typeof value === "object" && Array.isArray(components)) {
|
|
152
|
-
const errors: Record<string,
|
|
186
|
+
const errors: Record<string, CheckProposalFieldResult> = {};
|
|
153
187
|
|
|
154
188
|
for (const component of components) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
components
|
|
189
|
+
// Intersect with components? to access the field safely;
|
|
190
|
+
// it only exists on tuple AbiParameter variants
|
|
191
|
+
const abiParam = component as AbiParameter & {
|
|
192
|
+
components?: readonly AbiParameter[];
|
|
193
|
+
};
|
|
194
|
+
const name = abiParam.name!;
|
|
195
|
+
// fieldOrType is cast to "tuple" | "tuple[]" to satisfy overload 2
|
|
196
|
+
// (returns CheckProposalFieldResult). The actual runtime type dispatches
|
|
197
|
+
// to the correct branch.
|
|
198
|
+
errors[name] = checkProposalField({
|
|
199
|
+
fieldOrType: abiParam.type as "tuple" | "tuple[]",
|
|
200
|
+
value: (value as Record<string, unknown>)[name],
|
|
201
|
+
components: abiParam.components,
|
|
159
202
|
});
|
|
160
203
|
}
|
|
161
204
|
|
|
@@ -163,7 +206,7 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
163
206
|
return null;
|
|
164
207
|
}
|
|
165
208
|
|
|
166
|
-
return errors
|
|
209
|
+
return errors as Record<string, CheckProposalFieldResultMinimal>;
|
|
167
210
|
}
|
|
168
211
|
|
|
169
212
|
return null;
|
|
@@ -182,30 +225,41 @@ export const checkProposalField: CheckProposalField = ({
|
|
|
182
225
|
return null;
|
|
183
226
|
}
|
|
184
227
|
|
|
185
|
-
|
|
228
|
+
// errors contains tuple results (null | Record<string, ...>);
|
|
229
|
+
// cast is intentional — the type definition predates nested support
|
|
230
|
+
return errors as unknown as CheckProposalFieldResultMinimal[];
|
|
186
231
|
}
|
|
187
232
|
|
|
188
233
|
return null;
|
|
234
|
+
|
|
189
235
|
case "logoURI": {
|
|
190
236
|
if (value === undefined || value === "") {
|
|
191
237
|
return null;
|
|
192
238
|
}
|
|
193
|
-
if (
|
|
194
|
-
|
|
239
|
+
if (
|
|
240
|
+
typeof value !== "string" ||
|
|
241
|
+
!URL.canParse(value) ||
|
|
242
|
+
new URL(value).protocol !== "https:"
|
|
243
|
+
) {
|
|
244
|
+
return ProposalErrorCodes.MUST_BE_HTTPS_OR_IPFS;
|
|
195
245
|
}
|
|
196
|
-
return
|
|
246
|
+
return null;
|
|
197
247
|
}
|
|
198
248
|
case "url": {
|
|
199
249
|
if (value === undefined || value === "") {
|
|
200
250
|
return null;
|
|
201
251
|
}
|
|
202
|
-
if (
|
|
203
|
-
|
|
252
|
+
if (
|
|
253
|
+
typeof value !== "string" ||
|
|
254
|
+
!URL.canParse(value) ||
|
|
255
|
+
new URL(value).protocol !== "https:"
|
|
256
|
+
) {
|
|
257
|
+
return ProposalErrorCodes.MUST_BE_HTTPS;
|
|
204
258
|
}
|
|
205
|
-
return
|
|
259
|
+
return null;
|
|
206
260
|
}
|
|
207
261
|
default:
|
|
208
262
|
console.error(`Invalid field or type: ${fieldOrType}`);
|
|
209
263
|
return null;
|
|
210
264
|
}
|
|
211
|
-
}
|
|
265
|
+
}
|
|
@@ -15,11 +15,15 @@ export const MOCKED_PROPOSAL_STATUSES: readonly ProposalStatus[] = [
|
|
|
15
15
|
ProposalStatus.QuorumNotReached,
|
|
16
16
|
];
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Derives the effective `ProposalStatus` by reconciling subgraph data with the
|
|
20
|
+
* on-chain contract state. Falls back to subgraph timestamps when the on-chain
|
|
21
|
+
* state is unavailable.
|
|
22
|
+
*/
|
|
18
23
|
export function computeActualStatus(
|
|
24
|
+
/** Subgraph proposal data */
|
|
19
25
|
proposal: ProposalSelectionFragment,
|
|
20
|
-
/**
|
|
21
|
-
* Value returned by the `state` function of the governance contract.
|
|
22
|
-
*/
|
|
26
|
+
/** Value returned by the `state` function of the governance contract */
|
|
23
27
|
proposalOnChainState?: ProposalState,
|
|
24
28
|
): ProposalStatus {
|
|
25
29
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./checkProposalField";
|
|
2
|
+
export * from "./computeActualStatus";
|
|
3
|
+
export * from "./getAllProposals";
|
|
4
|
+
export * from "./getBodyErrors";
|
|
5
|
+
export * from "./getDecodedFunctionData";
|
|
6
|
+
export * from "./getProposalDetails";
|
|
7
|
+
export * from "./getProposalFromTx";
|
|
8
|
+
export * from "./getProposalVotes";
|
|
9
|
+
export * from "./parseProposalBody";
|
|
@@ -14,6 +14,20 @@ import {
|
|
|
14
14
|
import { getApolloClient } from "../clients/getApolloClient";
|
|
15
15
|
import { computeActualStatus } from "./computeActualStatus";
|
|
16
16
|
|
|
17
|
+
export type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
|
|
18
|
+
/** Subgraph filter applied to the proposals query */
|
|
19
|
+
where: Proposal_Filter;
|
|
20
|
+
/** Number of proposals to skip (for pagination) */
|
|
21
|
+
offset?: number;
|
|
22
|
+
/** Maximum proposals per page; must be ≤ 1000 */
|
|
23
|
+
perPage?: number;
|
|
24
|
+
orderBy?: Proposal_OrderBy;
|
|
25
|
+
orderDirection?: OrderDirection;
|
|
26
|
+
/** Full-text search query; switches to the search endpoint when provided */
|
|
27
|
+
text?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Fetches a paginated list of governance proposals from the subgraph */
|
|
17
31
|
export async function getAllProposals({
|
|
18
32
|
where,
|
|
19
33
|
orderBy,
|
|
@@ -22,14 +36,7 @@ export async function getAllProposals({
|
|
|
22
36
|
perPage = 20,
|
|
23
37
|
text,
|
|
24
38
|
...args
|
|
25
|
-
}:
|
|
26
|
-
offset?: number;
|
|
27
|
-
where: Proposal_Filter;
|
|
28
|
-
perPage?: number;
|
|
29
|
-
orderBy?: Proposal_OrderBy;
|
|
30
|
-
orderDirection?: OrderDirection;
|
|
31
|
-
text?: string;
|
|
32
|
-
}): Promise<ProposalSelectionFragment[] | undefined> {
|
|
39
|
+
}: GetAllProposalsArgs): Promise<ProposalSelectionFragment[] | undefined> {
|
|
33
40
|
try {
|
|
34
41
|
if (perPage > 1000) {
|
|
35
42
|
throw new Error("perPage must be less than 1000");
|
|
@@ -5,10 +5,18 @@ import type {
|
|
|
5
5
|
} from "../../types/governance";
|
|
6
6
|
import { checkProposalField } from "./checkProposalField";
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
proposal
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export interface GetBodyErrorsArgs {
|
|
9
|
+
/** The proposal to validate */
|
|
10
|
+
proposal: CustomProposal;
|
|
11
|
+
/** The current governance topic, used for forum link base URL validation */
|
|
12
|
+
currentTopic: GovernanceTopic;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Validates the body fields (title, description, forum link) of a proposal */
|
|
16
|
+
export function getBodyErrors({
|
|
17
|
+
proposal,
|
|
18
|
+
currentTopic,
|
|
19
|
+
}: GetBodyErrorsArgs): CustomProposalErrors {
|
|
12
20
|
const e: CustomProposalErrors = {};
|
|
13
21
|
e.title = checkProposalField({
|
|
14
22
|
fieldOrType: "title",
|
|
@@ -25,4 +33,4 @@ export const getBodyErrors = (
|
|
|
25
33
|
});
|
|
26
34
|
|
|
27
35
|
return e;
|
|
28
|
-
}
|
|
36
|
+
}
|
|
@@ -17,14 +17,19 @@ import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
|
|
|
17
17
|
import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
|
|
18
18
|
|
|
19
19
|
// Function to check if ABI contains proxy-related functions
|
|
20
|
-
function isProxyABI(abi: Abi
|
|
21
|
-
return abi.some(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
function isProxyABI(abi: Abi): boolean {
|
|
21
|
+
return abi.some((item: AbiItem) => {
|
|
22
|
+
const i = item as {
|
|
23
|
+
name?: string;
|
|
24
|
+
type: string;
|
|
25
|
+
inputs?: readonly { name?: string }[];
|
|
26
|
+
};
|
|
27
|
+
return (
|
|
28
|
+
i.name === "implementation" ||
|
|
29
|
+
i.name === "proxyType" ||
|
|
30
|
+
(i.type === "constructor" && i.inputs?.[0]?.name === "implementation")
|
|
31
|
+
);
|
|
32
|
+
});
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/**
|
|
@@ -89,9 +94,10 @@ async function _getAbiForCallData({
|
|
|
89
94
|
return knownAbi;
|
|
90
95
|
}
|
|
91
96
|
} catch {}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
|
|
98
|
+
return _getAbi({ contractAddress: address, chainId, publicClient }).catch(
|
|
99
|
+
() => undefined,
|
|
100
|
+
);
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
function _decodeCallData(callData: `0x${string}`, abi: AbiItem[]) {
|
|
@@ -117,27 +123,30 @@ function _getFunctionSignature(abiItem: AbiFunction | undefined) {
|
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
|
|
126
|
+
export interface GetDecodedFunctionDataArgs {
|
|
127
|
+
/** Contract address that emitted the calldata */
|
|
128
|
+
address: Address;
|
|
129
|
+
/** Raw calldata to decode */
|
|
130
|
+
callData: `0x${string}`;
|
|
131
|
+
/** @default defaultChainId */
|
|
132
|
+
chainId?: number;
|
|
133
|
+
publicClient: PublicClient;
|
|
134
|
+
}
|
|
135
|
+
|
|
120
136
|
/**
|
|
121
137
|
* Decodes the function data from a given contract address and calldata.
|
|
122
138
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
139
|
+
* Attempts to decode using a known set of ABIs first, then falls back to
|
|
140
|
+
* fetching the ABI from the block-explorer API.
|
|
125
141
|
*
|
|
126
|
-
* @
|
|
127
|
-
* @param callData - The calldata to decode, in hexadecimal format.
|
|
128
|
-
* @returns An object containing the decoded ABI item, function signature, function name, and arguments.
|
|
142
|
+
* @returns An object with the decoded ABI item, function signature, function name, and arguments.
|
|
129
143
|
*/
|
|
130
144
|
export async function getDecodedFunctionData({
|
|
131
145
|
address,
|
|
132
146
|
callData,
|
|
133
147
|
chainId = defaultChainId,
|
|
134
148
|
publicClient,
|
|
135
|
-
}: {
|
|
136
|
-
address: Address;
|
|
137
|
-
callData: `0x${string}`;
|
|
138
|
-
chainId?: number;
|
|
139
|
-
publicClient: PublicClient;
|
|
140
|
-
}) {
|
|
149
|
+
}: GetDecodedFunctionDataArgs) {
|
|
141
150
|
const knownAbi = [...beraChefAbi, ...rewardVaultAbi, ...erc20Abi];
|
|
142
151
|
|
|
143
152
|
const abi = await _getAbiForCallData({
|
|
@@ -10,13 +10,17 @@ import {
|
|
|
10
10
|
import { getApolloClient } from "../clients/getApolloClient";
|
|
11
11
|
import { computeActualStatus } from "./computeActualStatus";
|
|
12
12
|
|
|
13
|
+
export type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
|
|
14
|
+
/** On-chain proposal ID */
|
|
15
|
+
proposalId: string;
|
|
16
|
+
client?: PublicClient;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Fetches a single proposal with its vote data from the subgraph */
|
|
13
20
|
export async function getProposalDetails({
|
|
14
21
|
proposalId,
|
|
15
22
|
...args
|
|
16
|
-
}:
|
|
17
|
-
proposalId: string;
|
|
18
|
-
client?: PublicClient;
|
|
19
|
-
}): Promise<ProposalWithVotesFragment | undefined> {
|
|
23
|
+
}: GetProposalDetailsArgs): Promise<ProposalWithVotesFragment | undefined> {
|
|
20
24
|
const governanceClient = getApolloClient("governance.subgraph", args);
|
|
21
25
|
|
|
22
26
|
const res = await governanceClient.query<
|
|
@@ -16,17 +16,26 @@ import {
|
|
|
16
16
|
import { assertPublicClient } from "../../errors/assert";
|
|
17
17
|
import { parseProposalBody } from "./parseProposalBody";
|
|
18
18
|
|
|
19
|
+
export type GetProposalFromTxArgs = {
|
|
20
|
+
/** Viem public client used to fetch block and receipt data */
|
|
21
|
+
publicClient: PublicClient | undefined;
|
|
22
|
+
} & (
|
|
23
|
+
| {
|
|
24
|
+
/** Pre-fetched transaction receipt */
|
|
25
|
+
tx: TransactionReceipt;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
/** Transaction hash to look up */
|
|
29
|
+
txHash: Address;
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Reconstructs a `ProposalWithVotesFragment` from the `ProposalCreated` event
|
|
35
|
+
* emitted in a given transaction. Returns `null` if the event is not found.
|
|
36
|
+
*/
|
|
19
37
|
export async function getProposalFromTx(
|
|
20
|
-
args:
|
|
21
|
-
publicClient: PublicClient | undefined;
|
|
22
|
-
} & (
|
|
23
|
-
| {
|
|
24
|
-
tx: TransactionReceipt;
|
|
25
|
-
}
|
|
26
|
-
| {
|
|
27
|
-
txHash: Address;
|
|
28
|
-
}
|
|
29
|
-
),
|
|
38
|
+
args: GetProposalFromTxArgs,
|
|
30
39
|
): Promise<ProposalWithVotesFragment | null> {
|
|
31
40
|
assertPublicClient(args.publicClient);
|
|
32
41
|
|
|
@@ -21,25 +21,25 @@ import { hasAnyTruthyValues } from "../../utils/hasAnyTruthyValues";
|
|
|
21
21
|
import { checkProposalField } from "./checkProposalField";
|
|
22
22
|
import { getBodyErrors } from "./getBodyErrors";
|
|
23
23
|
|
|
24
|
-
export
|
|
25
|
-
proposal
|
|
26
|
-
currentTopic,
|
|
27
|
-
onError,
|
|
28
|
-
}: {
|
|
29
|
-
/**
|
|
30
|
-
* The proposal to get the parameters for
|
|
31
|
-
*/
|
|
24
|
+
export interface GetProposalParamsArgs {
|
|
25
|
+
/** The proposal to encode and validate */
|
|
32
26
|
proposal: CustomProposal;
|
|
33
|
-
/**
|
|
34
|
-
* The current topic
|
|
35
|
-
*/
|
|
27
|
+
/** The current governance topic */
|
|
36
28
|
currentTopic: GovernanceTopic;
|
|
37
|
-
/**
|
|
38
|
-
* Callback to handle errors
|
|
39
|
-
*/
|
|
29
|
+
/** Called with validation errors if the proposal is invalid */
|
|
40
30
|
onError?: (e: CustomProposalErrors) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Validates a governance proposal and encodes its on-chain call parameters.
|
|
35
|
+
* Returns the encoded targets, values, calldatas, and description, or `undefined` if validation fails.
|
|
36
|
+
*/
|
|
37
|
+
export function getProposalParams({
|
|
38
|
+
proposal,
|
|
39
|
+
currentTopic,
|
|
40
|
+
onError,
|
|
41
|
+
}: GetProposalParamsArgs) {
|
|
42
|
+
const e: CustomProposalErrors = getBodyErrors({ proposal, currentTopic });
|
|
43
43
|
|
|
44
44
|
const actions: Address[] = [];
|
|
45
45
|
|
|
@@ -244,4 +244,4 @@ export const getProposalParams = ({
|
|
|
244
244
|
actions,
|
|
245
245
|
description,
|
|
246
246
|
] as const;
|
|
247
|
-
}
|
|
247
|
+
}
|
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
|
|
7
7
|
import { getApolloClient } from "../clients/getApolloClient";
|
|
8
8
|
|
|
9
|
+
export type GetProposalVotesArgs = BeraJS.BaseFunctionArgs & {
|
|
10
|
+
/** GraphQL variables forwarded to the GetProposalVotes query */
|
|
11
|
+
variables: GetProposalVotesQueryVariables;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Fetches the votes for a proposal from the subgraph */
|
|
9
15
|
export async function getProposalVotes({
|
|
10
16
|
variables,
|
|
11
17
|
...args
|
|
12
|
-
}:
|
|
13
|
-
variables: GetProposalVotesQueryVariables;
|
|
14
|
-
}) {
|
|
18
|
+
}: GetProposalVotesArgs) {
|
|
15
19
|
const governanceClient = getApolloClient("governance.subgraph", args);
|
|
16
20
|
return governanceClient.query<GetProposalVotesQuery>({
|
|
17
21
|
query: GetProposalVotes,
|
|
@@ -5,6 +5,12 @@ import { berachainGovernanceAbi as governanceAbi } from "@berachain/abis/gov/ber
|
|
|
5
5
|
import { assertPublicClient } from "../../errors/assert";
|
|
6
6
|
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
7
7
|
|
|
8
|
+
export type GetQuorumArgs = BeraJS.BaseFunctionArgs & {
|
|
9
|
+
/** Timestamp in seconds; defaults to now. Returns the current quorum when in the future. */
|
|
10
|
+
at?: number | string;
|
|
11
|
+
publicClient: PublicClient | undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
8
14
|
/**
|
|
9
15
|
* Queries the quorum for a given timestamp.
|
|
10
16
|
*
|
|
@@ -14,13 +20,7 @@ export async function getQuorum({
|
|
|
14
20
|
at,
|
|
15
21
|
publicClient,
|
|
16
22
|
...args
|
|
17
|
-
}: {
|
|
18
|
-
/**
|
|
19
|
-
* Timestamp in seconds
|
|
20
|
-
*/
|
|
21
|
-
at?: number | string;
|
|
22
|
-
publicClient: PublicClient | undefined;
|
|
23
|
-
} & BeraJS.BaseFunctionArgs): Promise<string> {
|
|
23
|
+
}: GetQuorumArgs): Promise<string> {
|
|
24
24
|
const { config } = parseBaseArgs(args);
|
|
25
25
|
assertPublicClient(publicClient);
|
|
26
26
|
|
|
@@ -2,9 +2,16 @@ import graymatter from "gray-matter";
|
|
|
2
2
|
|
|
3
3
|
import type { ProposalSelectionFragment } from "@berachain/graphql/governance";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export type ParseProposalBodyResult = graymatter.GrayMatterFile<string> & {
|
|
6
|
+
/** Whether the body uses YAML front-matter (true) or legacy heading format (false) */
|
|
7
|
+
isFrontMatter: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function parseLegacyBody(s: string): {
|
|
11
|
+
type: string | null;
|
|
12
|
+
title: string;
|
|
13
|
+
content: string;
|
|
14
|
+
} {
|
|
8
15
|
const pattern = /#(?:([\w-]+)# )?(.+)\n([\s\S]*)/;
|
|
9
16
|
const match = s.match(pattern);
|
|
10
17
|
|
|
@@ -20,13 +27,16 @@ const parseLegacyBody = (
|
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
throw new Error("Invalid proposal body");
|
|
23
|
-
}
|
|
30
|
+
}
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Parses the body of a governance proposal into structured front-matter and content.
|
|
34
|
+
* Supports YAML front-matter format and a legacy heading-based format.
|
|
35
|
+
* Falls back to raw description on parse failure.
|
|
36
|
+
*/
|
|
37
|
+
export function parseProposalBody(
|
|
26
38
|
proposal?: Pick<ProposalSelectionFragment, "description">,
|
|
27
|
-
):
|
|
28
|
-
isFrontMatter: boolean;
|
|
29
|
-
} => {
|
|
39
|
+
): ParseProposalBodyResult {
|
|
30
40
|
if (!proposal) {
|
|
31
41
|
return {
|
|
32
42
|
isFrontMatter: false,
|
|
@@ -70,4 +80,4 @@ export const parseProposalBody = (
|
|
|
70
80
|
stringify: () => body,
|
|
71
81
|
};
|
|
72
82
|
}
|
|
73
|
-
}
|
|
83
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Aggregation_Interval,
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type
|
|
3
|
+
GetSnapshots,
|
|
4
|
+
type GetSnapshotsQuery,
|
|
5
|
+
type GetSnapshotsQueryVariables,
|
|
6
6
|
} from "@berachain/graphql/honey";
|
|
7
7
|
|
|
8
8
|
import { getApolloClient } from "../clients/getApolloClient";
|
|
@@ -14,9 +14,9 @@ export async function getChartData({
|
|
|
14
14
|
}) {
|
|
15
15
|
const client = getApolloClient("honey.subgraph", args);
|
|
16
16
|
|
|
17
|
-
const res = await client.query<
|
|
17
|
+
const res = await client.query<GetSnapshotsQuery, GetSnapshotsQueryVariables>(
|
|
18
18
|
{
|
|
19
|
-
query:
|
|
19
|
+
query: GetSnapshots,
|
|
20
20
|
variables: {
|
|
21
21
|
interval: Aggregation_Interval.Day,
|
|
22
22
|
first: days,
|