@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.
Files changed (254) hide show
  1. package/dist/{BeraError-_mQdkanr.d.cts → BeraError-7-A5JYy_.d.ts} +31 -2
  2. package/dist/{HoneyConfigProvider-DVP_9KZn.d.ts → HoneyConfigProvider-Dkj-_a5x.d.ts} +1 -1
  3. package/dist/{RequestError-BRIiJgHk.d.ts → RequestError-DBOIV65x.d.ts} +1 -1
  4. package/dist/abi/exports.mjs +4452 -2
  5. package/dist/actions/clients/exports.d.ts +78 -0
  6. package/dist/actions/clients/exports.mjs +21 -0
  7. package/dist/actions/exports.d.ts +154 -207
  8. package/dist/actions/exports.mjs +853 -2
  9. package/dist/actions/governance/exports.d.ts +140 -0
  10. package/dist/actions/governance/exports.mjs +226 -0
  11. package/dist/actions/server/exports.d.ts +13 -0
  12. package/dist/actions/server/exports.mjs +27 -0
  13. package/dist/chunk-3JJLQ2JX.mjs +211 -0
  14. package/dist/chunk-7YVNSDXG.mjs +86 -0
  15. package/dist/chunk-AUOPN6NK.mjs +96 -0
  16. package/dist/chunk-BGMRHTBQ.mjs +23 -0
  17. package/dist/chunk-CDK4YV3D.mjs +571 -0
  18. package/dist/chunk-DKMAIU74.mjs +62 -0
  19. package/dist/chunk-DQRH5VE3.mjs +25 -0
  20. package/dist/chunk-E7YFXBBQ.mjs +349 -0
  21. package/dist/chunk-GUURQAME.mjs +326 -0
  22. package/dist/chunk-GY6B3PD5.mjs +89 -0
  23. package/dist/chunk-HQCOU6GY.mjs +243 -0
  24. package/dist/chunk-HYDP32P6.mjs +135 -0
  25. package/dist/chunk-IXIBY5FP.mjs +80 -0
  26. package/dist/chunk-KHXJDYA4.mjs +1776 -0
  27. package/dist/chunk-NBYLMO2L.mjs +14 -0
  28. package/dist/chunk-O2NQFKJK.mjs +170 -0
  29. package/dist/chunk-P5WXXULM.mjs +54 -0
  30. package/dist/chunk-QBBOWFMH.mjs +4129 -0
  31. package/dist/chunk-QVHEM4BG.mjs +35 -0
  32. package/dist/chunk-SGIJVHZO.mjs +12 -0
  33. package/dist/chunk-SZ5C44L5.mjs +35 -0
  34. package/dist/chunk-WNBWX23Q.mjs +426 -0
  35. package/dist/chunk-Y6THHG77.mjs +126 -0
  36. package/dist/chunk-ZLTMIFCZ.mjs +165 -0
  37. package/dist/contexts/exports.d.ts +2 -2
  38. package/dist/contexts/exports.mjs +85 -2
  39. package/dist/enum/exports.d.ts +1 -1
  40. package/dist/enum/exports.mjs +46 -2
  41. package/dist/enum/governance/exports.d.ts +60 -0
  42. package/dist/enum/governance/exports.mjs +14 -0
  43. package/dist/errors/exports.d.ts +4 -3
  44. package/dist/errors/exports.mjs +48 -2
  45. package/dist/getApolloClient-BcUTGFUb.d.ts +40 -0
  46. package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-DphU3qhE.d.ts} +2 -2
  47. package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
  48. package/dist/hooks/exports.d.ts +83 -226
  49. package/dist/hooks/exports.mjs +7463 -4
  50. package/dist/hooks/governance/exports.d.ts +181 -0
  51. package/dist/hooks/governance/exports.mjs +888 -0
  52. package/dist/pol.d-Dw5SQcRX.d.ts +153 -0
  53. package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
  54. package/dist/types/exports.d.ts +9 -9
  55. package/dist/types/exports.mjs +0 -1
  56. package/dist/types/governance/exports.d.ts +109 -0
  57. package/dist/types/governance/exports.mjs +0 -0
  58. package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
  59. package/dist/utils/exports.d.ts +15 -6
  60. package/dist/utils/exports.mjs +827 -2
  61. package/package.json +49 -13
  62. package/src/actions/__test/transports.ts +61 -0
  63. package/src/actions/clients/exports.ts +7 -0
  64. package/src/actions/clients/fetchBeep.ts +34 -0
  65. package/src/actions/clients/fetchOpenApi.ts +93 -0
  66. package/src/actions/clients/fetchOpenApi.unit.test.ts +223 -0
  67. package/src/actions/clients/fetchRailwayBackend.ts +34 -0
  68. package/src/actions/clients/getApolloClient.ts +58 -23
  69. package/src/actions/clients/getEnsoClient.ts +20 -9
  70. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  71. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  72. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  73. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  74. package/src/actions/enso/getEnsoUserTokensWithBalances.ts +18 -0
  75. package/src/actions/exports.ts +5 -9
  76. package/src/actions/governance/exports.ts +9 -0
  77. package/src/actions/governance/getAllProposals.ts +10 -65
  78. package/src/actions/governance/getProposalDetails.ts +6 -33
  79. package/src/actions/governance/getProposalVotes.ts +8 -15
  80. package/src/actions/honey/getChartData.ts +27 -21
  81. package/src/actions/honey/getHoney24hVolume.ts +19 -22
  82. package/src/actions/honey/getPythLatestPrices.ts +7 -0
  83. package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
  84. package/src/actions/pol/getAutoclaimedIncentives.ts +41 -0
  85. package/src/actions/pol/getAutoclaimedIncentivesTxHash.ts +41 -0
  86. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  87. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +28 -0
  88. package/src/actions/pol/getEarnedStakedBeraVault.ts +20 -20
  89. package/src/actions/pol/getGlobalData.ts +1 -0
  90. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  91. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  92. package/src/actions/pol/getRewardVaults.ts +4 -4
  93. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  94. package/src/actions/pol/getStakingDailyAssets.ts +18 -17
  95. package/src/actions/server/exports.ts +1 -0
  96. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  97. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  98. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  99. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  100. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  101. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  102. package/src/actions/validators/utils/getValidatorBoostApy.ts +1 -1
  103. package/src/enum/contracts.ts +1 -0
  104. package/src/enum/exports.ts +0 -1
  105. package/src/enum/governance/exports.ts +1 -0
  106. package/src/errors/BeraError.ts +47 -7
  107. package/src/errors/BeraTracing.unit.test.ts +65 -0
  108. package/src/errors/RequestError.ts +25 -4
  109. package/src/errors/RequestError.unit.test.ts +55 -0
  110. package/src/errors/errorMap.ts +8 -0
  111. package/src/errors/exports.ts +5 -0
  112. package/src/errors/getRevertReason.integration.test.ts +3 -3
  113. package/src/errors/spanStatus.ts +78 -0
  114. package/src/errors/spanStatus.unit.test.ts +62 -0
  115. package/src/hooks/dex/useCreatePool.ts +1 -88
  116. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  117. package/src/hooks/dex/usePriceImpact.ts +12 -5
  118. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  119. package/src/hooks/enso/useBendMultiply.ts +9 -1
  120. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  121. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  122. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  123. package/src/hooks/exports.ts +3 -15
  124. package/src/hooks/governance/exports.ts +14 -0
  125. package/src/hooks/pol/useAutoclaimedIncentives.ts +40 -0
  126. package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +45 -0
  127. package/src/hooks/pol/useStakedAPR.ts +2 -2
  128. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  129. package/src/hooks/validators/useValidator.ts +6 -8
  130. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  131. package/src/types/bribe-boost.d.ts +19 -0
  132. package/src/types/exports.ts +0 -1
  133. package/src/types/governance/exports.ts +1 -0
  134. package/src/utils/beraFetch.ts +9 -3
  135. package/src/utils/exports.ts +1 -0
  136. package/src/utils/getServerSideClient.ts +4 -2
  137. package/src/utils/polyfillAbortSignalAny.ts +53 -0
  138. package/src/utils/polyfillAbortSignalAny.unit.test.ts +81 -0
  139. package/src/utils/sanitizeRpcUrl.ts +22 -0
  140. package/src/utils/tracedTransport.ts +35 -0
  141. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  142. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  143. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  144. package/dist/RequestError-DSUzJ1Iy.d.cts +0 -144
  145. package/dist/abi/exports.cjs +0 -2
  146. package/dist/abi/exports.cjs.map +0 -1
  147. package/dist/abi/exports.d.cts +0 -6574
  148. package/dist/abi/exports.mjs.map +0 -1
  149. package/dist/actions/exports.cjs +0 -2
  150. package/dist/actions/exports.cjs.map +0 -1
  151. package/dist/actions/exports.d.cts +0 -1650
  152. package/dist/actions/exports.mjs.map +0 -1
  153. package/dist/chunk-45HIEVNI.cjs +0 -4
  154. package/dist/chunk-45HIEVNI.cjs.map +0 -1
  155. package/dist/chunk-47ILYVHC.mjs +0 -2
  156. package/dist/chunk-47ILYVHC.mjs.map +0 -1
  157. package/dist/chunk-575OK77P.mjs +0 -2
  158. package/dist/chunk-575OK77P.mjs.map +0 -1
  159. package/dist/chunk-5NVZG5N6.mjs +0 -2
  160. package/dist/chunk-5NVZG5N6.mjs.map +0 -1
  161. package/dist/chunk-6DIA6PXV.cjs +0 -2
  162. package/dist/chunk-6DIA6PXV.cjs.map +0 -1
  163. package/dist/chunk-6JJIZCVY.cjs +0 -2
  164. package/dist/chunk-6JJIZCVY.cjs.map +0 -1
  165. package/dist/chunk-7F72ZH4Q.mjs +0 -2
  166. package/dist/chunk-7F72ZH4Q.mjs.map +0 -1
  167. package/dist/chunk-AUA42YIG.mjs +0 -4
  168. package/dist/chunk-AUA42YIG.mjs.map +0 -1
  169. package/dist/chunk-BC2WX6O6.cjs +0 -2
  170. package/dist/chunk-BC2WX6O6.cjs.map +0 -1
  171. package/dist/chunk-CJOZC5Z2.cjs +0 -2
  172. package/dist/chunk-CJOZC5Z2.cjs.map +0 -1
  173. package/dist/chunk-D6L7LTA2.cjs +0 -2
  174. package/dist/chunk-D6L7LTA2.cjs.map +0 -1
  175. package/dist/chunk-DDEQFR3M.cjs +0 -2
  176. package/dist/chunk-DDEQFR3M.cjs.map +0 -1
  177. package/dist/chunk-GXV2JA36.mjs +0 -2
  178. package/dist/chunk-GXV2JA36.mjs.map +0 -1
  179. package/dist/chunk-ISYNEDET.mjs +0 -2
  180. package/dist/chunk-ISYNEDET.mjs.map +0 -1
  181. package/dist/chunk-JDDRTHFG.mjs +0 -2
  182. package/dist/chunk-JDDRTHFG.mjs.map +0 -1
  183. package/dist/chunk-JDZGYU5T.mjs +0 -2
  184. package/dist/chunk-JDZGYU5T.mjs.map +0 -1
  185. package/dist/chunk-LVOXBZMA.cjs +0 -2
  186. package/dist/chunk-LVOXBZMA.cjs.map +0 -1
  187. package/dist/chunk-MK5NS5B5.mjs +0 -2
  188. package/dist/chunk-MK5NS5B5.mjs.map +0 -1
  189. package/dist/chunk-NAXAZJJY.mjs +0 -2
  190. package/dist/chunk-NAXAZJJY.mjs.map +0 -1
  191. package/dist/chunk-NLVWRMGD.mjs +0 -2
  192. package/dist/chunk-NLVWRMGD.mjs.map +0 -1
  193. package/dist/chunk-OGBD5YOG.mjs +0 -2
  194. package/dist/chunk-OGBD5YOG.mjs.map +0 -1
  195. package/dist/chunk-OGJMSGB2.mjs +0 -2
  196. package/dist/chunk-OGJMSGB2.mjs.map +0 -1
  197. package/dist/chunk-OIYXOKTT.cjs +0 -2
  198. package/dist/chunk-OIYXOKTT.cjs.map +0 -1
  199. package/dist/chunk-OUD27MU7.cjs +0 -2
  200. package/dist/chunk-OUD27MU7.cjs.map +0 -1
  201. package/dist/chunk-PRLVZIKD.mjs +0 -2
  202. package/dist/chunk-PRLVZIKD.mjs.map +0 -1
  203. package/dist/chunk-Q2SNRLW3.cjs +0 -2
  204. package/dist/chunk-Q2SNRLW3.cjs.map +0 -1
  205. package/dist/chunk-REWME3FY.cjs +0 -2
  206. package/dist/chunk-REWME3FY.cjs.map +0 -1
  207. package/dist/chunk-RJN36GBU.mjs +0 -2
  208. package/dist/chunk-RJN36GBU.mjs.map +0 -1
  209. package/dist/chunk-RWOICHRW.cjs +0 -2
  210. package/dist/chunk-RWOICHRW.cjs.map +0 -1
  211. package/dist/chunk-S4CDSVLK.cjs +0 -2
  212. package/dist/chunk-S4CDSVLK.cjs.map +0 -1
  213. package/dist/chunk-SFEULGSX.cjs +0 -2
  214. package/dist/chunk-SFEULGSX.cjs.map +0 -1
  215. package/dist/chunk-WBTS6KFG.mjs +0 -2
  216. package/dist/chunk-WBTS6KFG.mjs.map +0 -1
  217. package/dist/chunk-WRFDB3QJ.cjs +0 -2
  218. package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
  219. package/dist/chunk-XNJLSA6P.cjs +0 -2
  220. package/dist/chunk-XNJLSA6P.cjs.map +0 -1
  221. package/dist/contexts/exports.cjs +0 -2
  222. package/dist/contexts/exports.cjs.map +0 -1
  223. package/dist/contexts/exports.d.cts +0 -66
  224. package/dist/contexts/exports.mjs.map +0 -1
  225. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  226. package/dist/dex-C_BB0b0O.d.cts +0 -37
  227. package/dist/enum/exports.cjs +0 -2
  228. package/dist/enum/exports.cjs.map +0 -1
  229. package/dist/enum/exports.d.cts +0 -23
  230. package/dist/enum/exports.mjs.map +0 -1
  231. package/dist/errors/exports.cjs +0 -2
  232. package/dist/errors/exports.cjs.map +0 -1
  233. package/dist/errors/exports.d.cts +0 -327
  234. package/dist/errors/exports.mjs.map +0 -1
  235. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  236. package/dist/global.d-B7IeayVX.d.cts +0 -474
  237. package/dist/honey-CYm0RWf4.d.cts +0 -14
  238. package/dist/hooks/exports.cjs +0 -4
  239. package/dist/hooks/exports.cjs.map +0 -1
  240. package/dist/hooks/exports.d.cts +0 -1734
  241. package/dist/hooks/exports.mjs.map +0 -1
  242. package/dist/polling-BKnyavLI.d.cts +0 -8
  243. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  244. package/dist/types/exports.cjs +0 -1
  245. package/dist/types/exports.cjs.map +0 -1
  246. package/dist/types/exports.d.cts +0 -90
  247. package/dist/types/exports.mjs.map +0 -1
  248. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  249. package/dist/utils/exports.cjs +0 -2
  250. package/dist/utils/exports.cjs.map +0 -1
  251. package/dist/utils/exports.d.cts +0 -420
  252. package/dist/utils/exports.mjs.map +0 -1
  253. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  254. package/src/hooks/dex/useExploitedTokens.ts +0 -57
@@ -0,0 +1,326 @@
1
+ import {
2
+ assertPublicClient
3
+ } from "./chunk-GY6B3PD5.mjs";
4
+
5
+ // src/actions/governance/checkProposalField.ts
6
+ import { isAddress, isHex } from "viem";
7
+ function checkProposalField({
8
+ fieldOrType,
9
+ value,
10
+ required = true,
11
+ baseUrl,
12
+ components
13
+ }) {
14
+ const notRequiredAbiTypes = ["bool", "string"];
15
+ if (!notRequiredAbiTypes.includes(fieldOrType) && required && (value === void 0 || value === null || value === "")) {
16
+ return "Required" /* REQUIRED */;
17
+ }
18
+ if (fieldOrType.startsWith("uint") || fieldOrType.startsWith("int")) {
19
+ if (typeof value !== "string") {
20
+ return "Invalid amount" /* INVALID_AMOUNT */;
21
+ }
22
+ try {
23
+ const valueBN = BigInt(value);
24
+ if (fieldOrType.startsWith("uint")) {
25
+ if (valueBN < 0n) {
26
+ return "Negative amount" /* NEGATIVE_AMOUNT */;
27
+ }
28
+ }
29
+ } catch {
30
+ return "Invalid amount" /* INVALID_AMOUNT */;
31
+ }
32
+ return null;
33
+ }
34
+ switch (fieldOrType) {
35
+ case "string":
36
+ if (value !== void 0 && typeof value !== "string") {
37
+ return "Invalid amount" /* INVALID_AMOUNT */;
38
+ }
39
+ return null;
40
+ case "bool":
41
+ if (typeof value !== "boolean") {
42
+ return "Invalid amount" /* INVALID_AMOUNT */;
43
+ }
44
+ return null;
45
+ case "title":
46
+ if (typeof value !== "string" || value.length === 0) {
47
+ return "Required" /* REQUIRED */;
48
+ }
49
+ return null;
50
+ case "description":
51
+ if (typeof value !== "string" || value.length === 0) {
52
+ return "Required" /* REQUIRED */;
53
+ }
54
+ return null;
55
+ case "forumLink": {
56
+ if (typeof value !== "string" || value.length === 0) {
57
+ return "Required" /* REQUIRED */;
58
+ }
59
+ if (!URL.canParse(value)) {
60
+ return "Invalid address" /* INVALID_ADDRESS */;
61
+ }
62
+ const base = new URL(baseUrl);
63
+ if (!value.startsWith(base.toString())) {
64
+ return "Must be a berachain forum link" /* INVALID_BASEPATH */;
65
+ }
66
+ return null;
67
+ }
68
+ case "address":
69
+ if (typeof value !== "string" || !isAddress(value, { strict: true })) {
70
+ return "Invalid address" /* INVALID_ADDRESS */;
71
+ }
72
+ return null;
73
+ case "hex":
74
+ if (typeof value !== "string" || !isHex(value, { strict: true })) {
75
+ return "Invalid address" /* INVALID_ADDRESS */;
76
+ }
77
+ return null;
78
+ case "abi":
79
+ if (typeof value !== "string") {
80
+ return "Invalid ABI" /* INVALID_ABI */;
81
+ }
82
+ try {
83
+ JSON.parse(value);
84
+ } catch {
85
+ return "Invalid ABI" /* INVALID_ABI */;
86
+ }
87
+ return null;
88
+ case "action":
89
+ if (typeof value !== "string" || !isAddress(value, { strict: true })) {
90
+ return "Invalid address" /* INVALID_ADDRESS */;
91
+ }
92
+ return null;
93
+ case "tuple":
94
+ if (typeof value === "object" && Array.isArray(components)) {
95
+ const errors = {};
96
+ for (const component of components) {
97
+ const abiParam = component;
98
+ const name = abiParam.name;
99
+ errors[name] = checkProposalField({
100
+ fieldOrType: abiParam.type,
101
+ value: value[name],
102
+ components: abiParam.components
103
+ });
104
+ }
105
+ if (Object.values(errors).every((v) => v === null)) {
106
+ return null;
107
+ }
108
+ return errors;
109
+ }
110
+ return null;
111
+ case "tuple[]":
112
+ if (Array.isArray(value)) {
113
+ const errors = value.map(
114
+ (v) => checkProposalField({
115
+ fieldOrType: "tuple",
116
+ value: v,
117
+ components
118
+ })
119
+ );
120
+ if (errors.every((v) => v === null)) {
121
+ return null;
122
+ }
123
+ return errors;
124
+ }
125
+ return null;
126
+ case "logoURI": {
127
+ if (value === void 0 || value === "") {
128
+ return null;
129
+ }
130
+ if (typeof value !== "string" || !URL.canParse(value) || new URL(value).protocol !== "https:") {
131
+ return "Must be HTTPS or IPFS" /* MUST_BE_HTTPS_OR_IPFS */;
132
+ }
133
+ return null;
134
+ }
135
+ case "url": {
136
+ if (value === void 0 || value === "") {
137
+ return null;
138
+ }
139
+ if (typeof value !== "string" || !URL.canParse(value) || new URL(value).protocol !== "https:") {
140
+ return "Must be HTTPS" /* MUST_BE_HTTPS */;
141
+ }
142
+ return null;
143
+ }
144
+ default:
145
+ console.error(`Invalid field or type: ${fieldOrType}`);
146
+ return null;
147
+ }
148
+ }
149
+
150
+ // src/actions/governance/getAllProposals.ts
151
+ async function getAllProposals(_args) {
152
+ return [];
153
+ }
154
+
155
+ // src/actions/governance/getBodyErrors.ts
156
+ function getBodyErrors({
157
+ proposal,
158
+ currentTopic
159
+ }) {
160
+ const e = {};
161
+ e.title = checkProposalField({
162
+ fieldOrType: "title",
163
+ value: proposal.title
164
+ });
165
+ e.description = checkProposalField({
166
+ fieldOrType: "description",
167
+ value: proposal.description
168
+ });
169
+ e.forumLink = checkProposalField({
170
+ fieldOrType: "forumLink",
171
+ value: proposal.forumLink,
172
+ baseUrl: currentTopic.forumLink
173
+ });
174
+ return e;
175
+ }
176
+
177
+ // src/actions/governance/getProposalDetails.ts
178
+ async function getProposalDetails(_args) {
179
+ return void 0;
180
+ }
181
+
182
+ // src/actions/governance/parseProposalBody.ts
183
+ import graymatter from "gray-matter";
184
+ function parseLegacyBody(s) {
185
+ const pattern = /#(?:([\w-]+)# )?(.+)\n([\s\S]*)/;
186
+ const match = s.match(pattern);
187
+ if (match) {
188
+ const type = match[1] || null;
189
+ const title = match[2];
190
+ const content = match[3].replace("\n", "<br />");
191
+ return {
192
+ type,
193
+ title,
194
+ content
195
+ };
196
+ }
197
+ throw new Error("Invalid proposal body");
198
+ }
199
+ function parseProposalBody(proposal) {
200
+ if (!proposal) {
201
+ return {
202
+ isFrontMatter: false,
203
+ data: { title: "Loading..." },
204
+ content: "",
205
+ matter: "",
206
+ language: "",
207
+ orig: "",
208
+ stringify: () => ""
209
+ };
210
+ }
211
+ const body = proposal?.description ?? "";
212
+ if (graymatter.test(body)) {
213
+ return { ...graymatter(body), isFrontMatter: true };
214
+ }
215
+ try {
216
+ const legacyBody = parseLegacyBody(body);
217
+ return {
218
+ isFrontMatter: false,
219
+ data: { title: legacyBody.title },
220
+ content: legacyBody.content,
221
+ matter: "",
222
+ language: "",
223
+ orig: body,
224
+ stringify: () => body
225
+ };
226
+ } catch {
227
+ return {
228
+ isFrontMatter: false,
229
+ data: {
230
+ title: proposal?.description?.split("\n")[0].slice(0, 100)
231
+ },
232
+ content: body,
233
+ matter: "",
234
+ language: "",
235
+ orig: body,
236
+ stringify: () => body
237
+ };
238
+ }
239
+ }
240
+
241
+ // src/actions/governance/getProposalFromTx.ts
242
+ import {
243
+ parseEventLogs
244
+ } from "viem";
245
+ import { berachainGovernanceAbi as governanceAbi } from "@berachain/abis/gov/berachainGovernance";
246
+ import {
247
+ ProposalStatus
248
+ } from "@berachain/graphql/governance";
249
+ async function getProposalFromTx(args) {
250
+ assertPublicClient(args.publicClient);
251
+ let tx;
252
+ if ("tx" in args) {
253
+ tx = args.tx;
254
+ } else {
255
+ tx = await args.publicClient.getTransactionReceipt({ hash: args.txHash });
256
+ }
257
+ const creationEvent = tx?.logs ? parseEventLogs({
258
+ abi: governanceAbi,
259
+ logs: tx.logs,
260
+ eventName: "ProposalCreated"
261
+ })?.at(0) : void 0;
262
+ if (!tx || !creationEvent) {
263
+ return null;
264
+ }
265
+ const block = await args.publicClient.getBlock({
266
+ blockNumber: tx.blockNumber
267
+ });
268
+ const fm = parseProposalBody({
269
+ description: creationEvent?.args.description
270
+ });
271
+ return {
272
+ id: String(creationEvent.args.proposalId),
273
+ proposalId: String(creationEvent?.args.proposalId),
274
+ createdAt: block.timestamp.toString(),
275
+ title: fm.data.title,
276
+ createdAtBlock: block.timestamp.toString(),
277
+ voteStartAt: String(creationEvent?.args.voteStart),
278
+ voteEndAt: String(creationEvent?.args.voteEnd),
279
+ proposer: creationEvent?.args.proposer,
280
+ description: fm.content,
281
+ unverifiedForumLink: fm.data.forumLink,
282
+ pollResult: {
283
+ for: "0",
284
+ forVotersCount: 0,
285
+ forPercentage: "0",
286
+ against: "0",
287
+ againstVotersCount: 0,
288
+ againstPercentage: "0",
289
+ abstain: "0",
290
+ abstainVotersCount: 0,
291
+ abstainPercentage: "0",
292
+ total: "0",
293
+ totalVotersCount: 0,
294
+ totalTowardsQuorum: "0"
295
+ },
296
+ status: ProposalStatus.Pending,
297
+ quorum: null,
298
+ topics: fm.data.topics,
299
+ votes: [],
300
+ executableCalls: creationEvent?.args.targets.map(
301
+ (target, index) => ({
302
+ __typename: "ExecutableCall",
303
+ id: `${tx.transactionHash}-${index}`,
304
+ target,
305
+ value: String(creationEvent?.args.values[index]),
306
+ calldata: creationEvent?.args.calldatas[index]
307
+ })
308
+ ),
309
+ timelock: void 0
310
+ };
311
+ }
312
+
313
+ // src/actions/governance/getProposalVotes.ts
314
+ async function getProposalVotes(_args) {
315
+ return { data: { votes: [] } };
316
+ }
317
+
318
+ export {
319
+ checkProposalField,
320
+ getAllProposals,
321
+ getBodyErrors,
322
+ getProposalDetails,
323
+ parseProposalBody,
324
+ getProposalFromTx,
325
+ getProposalVotes
326
+ };
@@ -0,0 +1,89 @@
1
+ import {
2
+ InvalidArgumentError
3
+ } from "./chunk-KHXJDYA4.mjs";
4
+
5
+ // src/errors/assert.ts
6
+ import { isAddress } from "viem";
7
+ function _isDefined(value) {
8
+ return value !== void 0 && value !== null;
9
+ }
10
+ function _assert({
11
+ value,
12
+ property,
13
+ fn
14
+ }) {
15
+ const result = fn(value);
16
+ if (!result.isValid) {
17
+ throw new InvalidArgumentError({
18
+ property,
19
+ value,
20
+ expected: result.expectedType
21
+ });
22
+ }
23
+ }
24
+ function _assertDefined({
25
+ value,
26
+ property,
27
+ fn
28
+ }) {
29
+ _assert({
30
+ value,
31
+ property,
32
+ fn: (value2) => {
33
+ const isDefined = _isDefined(value2);
34
+ const { isValid, expectedType } = fn(value2);
35
+ return {
36
+ expectedType,
37
+ isValid: isDefined && isValid
38
+ };
39
+ }
40
+ });
41
+ }
42
+ function assertDefined(value, property) {
43
+ _assertDefined({
44
+ value,
45
+ property,
46
+ fn: (value2) => ({ expectedType: "defined", isValid: _isDefined(value2) })
47
+ });
48
+ }
49
+ function assertPublicClient(value, property = "publicClient") {
50
+ assertDefined(value, property);
51
+ }
52
+ function assertAddress(value, property) {
53
+ _assertDefined({
54
+ value,
55
+ property,
56
+ fn: (value2) => ({
57
+ expectedType: "Address",
58
+ isValid: typeof value2 === "string" && isAddress(value2)
59
+ })
60
+ });
61
+ }
62
+ function assertPositive(value, property) {
63
+ const isPositive = typeof value === "bigint" ? value > 0n : Number(value) > 0;
64
+ if (!isPositive) {
65
+ throw new InvalidArgumentError({
66
+ property,
67
+ value,
68
+ expected: "positive amount"
69
+ });
70
+ }
71
+ }
72
+ function assertAmount(value, property) {
73
+ _assertDefined({
74
+ value,
75
+ property,
76
+ fn: (value2) => ({
77
+ expectedType: "number",
78
+ isValid: (typeof value2 === "string" || typeof value2 === "number") && Number(value2) > 0
79
+ })
80
+ });
81
+ }
82
+
83
+ export {
84
+ assertDefined,
85
+ assertPublicClient,
86
+ assertAddress,
87
+ assertPositive,
88
+ assertAmount
89
+ };
@@ -0,0 +1,243 @@
1
+ // src/abi/utils/multicall3.ts
2
+ var multicall3Abi = [
3
+ {
4
+ inputs: [
5
+ {
6
+ components: [
7
+ { internalType: "address", name: "target", type: "address" },
8
+ { internalType: "bytes", name: "callData", type: "bytes" }
9
+ ],
10
+ internalType: "struct Multicall3.Call[]",
11
+ name: "calls",
12
+ type: "tuple[]"
13
+ }
14
+ ],
15
+ name: "aggregate",
16
+ outputs: [
17
+ { internalType: "uint256", name: "blockNumber", type: "uint256" },
18
+ { internalType: "bytes[]", name: "returnData", type: "bytes[]" }
19
+ ],
20
+ stateMutability: "payable",
21
+ type: "function"
22
+ },
23
+ {
24
+ inputs: [
25
+ {
26
+ components: [
27
+ { internalType: "address", name: "target", type: "address" },
28
+ { internalType: "bool", name: "allowFailure", type: "bool" },
29
+ { internalType: "bytes", name: "callData", type: "bytes" }
30
+ ],
31
+ internalType: "struct Multicall3.Call3[]",
32
+ name: "calls",
33
+ type: "tuple[]"
34
+ }
35
+ ],
36
+ name: "aggregate3",
37
+ outputs: [
38
+ {
39
+ components: [
40
+ { internalType: "bool", name: "success", type: "bool" },
41
+ { internalType: "bytes", name: "returnData", type: "bytes" }
42
+ ],
43
+ internalType: "struct Multicall3.Result[]",
44
+ name: "returnData",
45
+ type: "tuple[]"
46
+ }
47
+ ],
48
+ stateMutability: "payable",
49
+ type: "function"
50
+ },
51
+ {
52
+ inputs: [
53
+ {
54
+ components: [
55
+ { internalType: "address", name: "target", type: "address" },
56
+ { internalType: "bool", name: "allowFailure", type: "bool" },
57
+ { internalType: "uint256", name: "value", type: "uint256" },
58
+ { internalType: "bytes", name: "callData", type: "bytes" }
59
+ ],
60
+ internalType: "struct Multicall3.Call3Value[]",
61
+ name: "calls",
62
+ type: "tuple[]"
63
+ }
64
+ ],
65
+ name: "aggregate3Value",
66
+ outputs: [
67
+ {
68
+ components: [
69
+ { internalType: "bool", name: "success", type: "bool" },
70
+ { internalType: "bytes", name: "returnData", type: "bytes" }
71
+ ],
72
+ internalType: "struct Multicall3.Result[]",
73
+ name: "returnData",
74
+ type: "tuple[]"
75
+ }
76
+ ],
77
+ stateMutability: "payable",
78
+ type: "function"
79
+ },
80
+ {
81
+ inputs: [
82
+ {
83
+ components: [
84
+ { internalType: "address", name: "target", type: "address" },
85
+ { internalType: "bytes", name: "callData", type: "bytes" }
86
+ ],
87
+ internalType: "struct Multicall3.Call[]",
88
+ name: "calls",
89
+ type: "tuple[]"
90
+ }
91
+ ],
92
+ name: "blockAndAggregate",
93
+ outputs: [
94
+ { internalType: "uint256", name: "blockNumber", type: "uint256" },
95
+ { internalType: "bytes32", name: "blockHash", type: "bytes32" },
96
+ {
97
+ components: [
98
+ { internalType: "bool", name: "success", type: "bool" },
99
+ { internalType: "bytes", name: "returnData", type: "bytes" }
100
+ ],
101
+ internalType: "struct Multicall3.Result[]",
102
+ name: "returnData",
103
+ type: "tuple[]"
104
+ }
105
+ ],
106
+ stateMutability: "payable",
107
+ type: "function"
108
+ },
109
+ {
110
+ inputs: [],
111
+ name: "getBasefee",
112
+ outputs: [{ internalType: "uint256", name: "basefee", type: "uint256" }],
113
+ stateMutability: "view",
114
+ type: "function"
115
+ },
116
+ {
117
+ inputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }],
118
+ name: "getBlockHash",
119
+ outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
120
+ stateMutability: "view",
121
+ type: "function"
122
+ },
123
+ {
124
+ inputs: [],
125
+ name: "getBlockNumber",
126
+ outputs: [
127
+ { internalType: "uint256", name: "blockNumber", type: "uint256" }
128
+ ],
129
+ stateMutability: "view",
130
+ type: "function"
131
+ },
132
+ {
133
+ inputs: [],
134
+ name: "getChainId",
135
+ outputs: [{ internalType: "uint256", name: "chainid", type: "uint256" }],
136
+ stateMutability: "view",
137
+ type: "function"
138
+ },
139
+ {
140
+ inputs: [],
141
+ name: "getCurrentBlockCoinbase",
142
+ outputs: [{ internalType: "address", name: "coinbase", type: "address" }],
143
+ stateMutability: "view",
144
+ type: "function"
145
+ },
146
+ {
147
+ inputs: [],
148
+ name: "getCurrentBlockDifficulty",
149
+ outputs: [{ internalType: "uint256", name: "difficulty", type: "uint256" }],
150
+ stateMutability: "view",
151
+ type: "function"
152
+ },
153
+ {
154
+ inputs: [],
155
+ name: "getCurrentBlockGasLimit",
156
+ outputs: [{ internalType: "uint256", name: "gaslimit", type: "uint256" }],
157
+ stateMutability: "view",
158
+ type: "function"
159
+ },
160
+ {
161
+ inputs: [],
162
+ name: "getCurrentBlockTimestamp",
163
+ outputs: [{ internalType: "uint256", name: "timestamp", type: "uint256" }],
164
+ stateMutability: "view",
165
+ type: "function"
166
+ },
167
+ {
168
+ inputs: [{ internalType: "address", name: "addr", type: "address" }],
169
+ name: "getEthBalance",
170
+ outputs: [{ internalType: "uint256", name: "balance", type: "uint256" }],
171
+ stateMutability: "view",
172
+ type: "function"
173
+ },
174
+ {
175
+ inputs: [],
176
+ name: "getLastBlockHash",
177
+ outputs: [{ internalType: "bytes32", name: "blockHash", type: "bytes32" }],
178
+ stateMutability: "view",
179
+ type: "function"
180
+ },
181
+ {
182
+ inputs: [
183
+ { internalType: "bool", name: "requireSuccess", type: "bool" },
184
+ {
185
+ components: [
186
+ { internalType: "address", name: "target", type: "address" },
187
+ { internalType: "bytes", name: "callData", type: "bytes" }
188
+ ],
189
+ internalType: "struct Multicall3.Call[]",
190
+ name: "calls",
191
+ type: "tuple[]"
192
+ }
193
+ ],
194
+ name: "tryAggregate",
195
+ outputs: [
196
+ {
197
+ components: [
198
+ { internalType: "bool", name: "success", type: "bool" },
199
+ { internalType: "bytes", name: "returnData", type: "bytes" }
200
+ ],
201
+ internalType: "struct Multicall3.Result[]",
202
+ name: "returnData",
203
+ type: "tuple[]"
204
+ }
205
+ ],
206
+ stateMutability: "payable",
207
+ type: "function"
208
+ },
209
+ {
210
+ inputs: [
211
+ { internalType: "bool", name: "requireSuccess", type: "bool" },
212
+ {
213
+ components: [
214
+ { internalType: "address", name: "target", type: "address" },
215
+ { internalType: "bytes", name: "callData", type: "bytes" }
216
+ ],
217
+ internalType: "struct Multicall3.Call[]",
218
+ name: "calls",
219
+ type: "tuple[]"
220
+ }
221
+ ],
222
+ name: "tryBlockAndAggregate",
223
+ outputs: [
224
+ { internalType: "uint256", name: "blockNumber", type: "uint256" },
225
+ { internalType: "bytes32", name: "blockHash", type: "bytes32" },
226
+ {
227
+ components: [
228
+ { internalType: "bool", name: "success", type: "bool" },
229
+ { internalType: "bytes", name: "returnData", type: "bytes" }
230
+ ],
231
+ internalType: "struct Multicall3.Result[]",
232
+ name: "returnData",
233
+ type: "tuple[]"
234
+ }
235
+ ],
236
+ stateMutability: "payable",
237
+ type: "function"
238
+ }
239
+ ];
240
+
241
+ export {
242
+ multicall3Abi
243
+ };