@berachain/berajs 0.2.8-beta.8 → 0.2.9

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 (225) 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-DBOIV65x.d.ts +144 -0
  4. package/dist/abi/exports.mjs +3 -4
  5. package/dist/actions/clients/exports.d.ts +2 -0
  6. package/dist/actions/clients/exports.mjs +12 -0
  7. package/dist/actions/exports.d.ts +108 -187
  8. package/dist/actions/exports.mjs +97 -158
  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-VA3BQ34H.mjs → chunk-3EARVV7K.mjs} +20 -9
  14. package/dist/chunk-4Z4AK6SH.mjs +211 -0
  15. package/dist/chunk-75M6TF7M.mjs +25 -0
  16. package/dist/chunk-AFN4CVD3.mjs +326 -0
  17. package/dist/{chunk-7TFV6UKF.mjs → chunk-BGMRHTBQ.mjs} +0 -1
  18. package/dist/{chunk-3M47ZRXT.mjs → chunk-CDFWPU2R.mjs} +73 -17
  19. package/dist/{chunk-GWSTVITN.mjs → chunk-CDK4YV3D.mjs} +0 -1
  20. package/dist/{chunk-KL6YZ5VR.mjs → chunk-DKMAIU74.mjs} +0 -1
  21. package/dist/chunk-EXIUPSFN.mjs +86 -0
  22. package/dist/{chunk-VA5L5FDG.mjs → chunk-FFB5LFDW.mjs} +2 -3
  23. package/dist/{chunk-ZCEFC2TK.mjs → chunk-HQCOU6GY.mjs} +0 -1
  24. package/dist/{chunk-SGZP4O6R.mjs → chunk-HSSJKHZ4.mjs} +11 -11
  25. package/dist/{chunk-7QKRRIHI.mjs → chunk-J5I45WGQ.mjs} +77 -152
  26. package/dist/chunk-KQUMKB66.mjs +89 -0
  27. package/dist/{chunk-JA4DHMTG.mjs → chunk-NBYLMO2L.mjs} +0 -1
  28. package/dist/{chunk-4GFN4LEP.mjs → chunk-NPBQLVL3.mjs} +4 -21
  29. package/dist/{chunk-I3FTWD6I.mjs → chunk-O2NQFKJK.mjs} +1 -1
  30. package/dist/{chunk-2R73G2PO.mjs → chunk-QJIXTYTZ.mjs} +121 -765
  31. package/dist/{chunk-GLWPRM33.mjs → chunk-SGIJVHZO.mjs} +0 -1
  32. package/dist/chunk-SZ5C44L5.mjs +35 -0
  33. package/dist/{chunk-5NMATIH4.mjs → chunk-WXXOISTU.mjs} +1 -35
  34. package/dist/chunk-XIYN6AL6.mjs +160 -0
  35. package/dist/contexts/exports.d.ts +2 -2
  36. package/dist/contexts/exports.mjs +11 -9
  37. package/dist/enum/exports.d.ts +1 -1
  38. package/dist/enum/exports.mjs +3 -16
  39. package/dist/enum/governance/exports.d.ts +60 -0
  40. package/dist/enum/governance/exports.mjs +14 -0
  41. package/dist/errors/exports.d.ts +5 -90
  42. package/dist/errors/exports.mjs +19 -10
  43. package/dist/exports-BcUTGFUb.d.ts +40 -0
  44. package/dist/{getValidatorQueuedOperatorAddress-BcyxE9uw.d.ts → getValidatorQueuedOperatorAddress-Dw5KN5sh.d.ts} +2 -2
  45. package/dist/{global.d-5w_lvl2J.d.ts → global.d-BuGDKh4k.d.ts} +4 -240
  46. package/dist/hooks/exports.d.ts +80 -236
  47. package/dist/hooks/exports.mjs +609 -1508
  48. package/dist/hooks/governance/exports.d.ts +181 -0
  49. package/dist/hooks/governance/exports.mjs +888 -0
  50. package/dist/pol.d-CqPA9K6m.d.ts +142 -0
  51. package/dist/{txnEnum-7_o92X3N.d.cts → txnEnum-ByI5dtDi.d.ts} +2 -60
  52. package/dist/types/exports.d.ts +9 -9
  53. package/dist/types/exports.mjs +0 -1
  54. package/dist/types/governance/exports.d.ts +109 -0
  55. package/dist/types/governance/exports.mjs +0 -0
  56. package/dist/{useHoneySwapState-B494PQDl.d.ts → useHoneySwapState-vFmuFF0g.d.ts} +1 -1
  57. package/dist/utils/exports.d.ts +24 -7
  58. package/dist/utils/exports.mjs +49 -11
  59. package/package.json +60 -13
  60. package/src/actions/__test/transports.ts +61 -0
  61. package/src/actions/clients/BeraApolloClient.ts +9 -0
  62. package/src/actions/clients/exports.ts +4 -0
  63. package/src/actions/clients/getApolloClient.ts +70 -25
  64. package/src/actions/clients/getEnsoClient.ts +20 -9
  65. package/src/actions/dex/aggregators/base.ts +1 -1
  66. package/src/actions/dex/aggregators/enso/enso.ts +27 -17
  67. package/src/actions/dex/aggregators/enso/ensoErc4626.ts +2 -2
  68. package/src/actions/dex/aggregators/kyberswap.ts +18 -23
  69. package/src/actions/enso/__tests__/getEnsoUserTokensWithBalances.debug.test.ts +3 -6
  70. package/src/actions/exports.ts +5 -10
  71. package/src/actions/governance/exports.ts +9 -0
  72. package/src/actions/governance/getAllProposals.ts +10 -65
  73. package/src/actions/governance/getProposalDetails.ts +6 -33
  74. package/src/actions/governance/getProposalVotes.ts +8 -15
  75. package/src/actions/honey/getChartData.ts +27 -21
  76. package/src/actions/honey/getHoney24hVolume.ts +27 -0
  77. package/src/actions/pol/getAutoclaimedIncentives.ts +30 -0
  78. package/src/actions/pol/getBeraTokenTotalSupply.ts +45 -0
  79. package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +35 -0
  80. package/src/actions/pol/getEarnedStakedBeraVault.ts +15 -9
  81. package/src/actions/pol/getGlobalData.ts +1 -0
  82. package/src/actions/pol/getHeroEarnVaults.ts +62 -0
  83. package/src/actions/pol/getIncentiveFeeClaimStats.ts +19 -38
  84. package/src/actions/pol/getSWBeraVaultMetadata.ts +1 -1
  85. package/src/actions/pol/getStakingDailyAssets.ts +11 -8
  86. package/src/actions/server/exports.ts +1 -0
  87. package/src/actions/server/getDailyValidatorBlockStats.ts +33 -0
  88. package/src/actions/tokens/getWalletBalances.integration.test.ts +3 -6
  89. package/src/actions/transactions/beraWriteContract.integration.test.ts +3 -6
  90. package/src/actions/validators/getDailyValidatorBlockStats.ts +25 -24
  91. package/src/actions/validators/getValidatorAnalytics.ts +20 -21
  92. package/src/actions/validators/getValidatorIncentiveDistribution.ts +33 -0
  93. package/src/data/contracts.ts +5 -0
  94. package/src/enum/contracts.ts +1 -0
  95. package/src/enum/exports.ts +0 -1
  96. package/src/enum/governance/exports.ts +1 -0
  97. package/src/errors/BeraError.ts +47 -7
  98. package/src/errors/BeraTracing.unit.test.ts +65 -0
  99. package/src/errors/RequestError.ts +15 -2
  100. package/src/errors/exports.ts +5 -0
  101. package/src/errors/getRevertReason.integration.test.ts +3 -3
  102. package/src/errors/spanStatus.ts +78 -0
  103. package/src/errors/spanStatus.unit.test.ts +62 -0
  104. package/src/hooks/dex/useCreatePool.ts +1 -88
  105. package/src/hooks/dex/useOnChainPoolData.ts +27 -2
  106. package/src/hooks/dex/usePriceImpact.ts +12 -5
  107. package/src/hooks/enso/useBendDemultiply.ts +9 -1
  108. package/src/hooks/enso/useBendMultiply.ts +9 -1
  109. package/src/hooks/enso/useBendZapSupply.ts +26 -7
  110. package/src/hooks/enso/useEnsoSwapBundle.ts +17 -3
  111. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +13 -2
  112. package/src/hooks/exports.ts +3 -16
  113. package/src/hooks/governance/exports.ts +14 -0
  114. package/src/hooks/honey/useHoney24hVolume.ts +16 -0
  115. package/src/hooks/pol/useAutoclaimedIncentives.ts +49 -0
  116. package/src/hooks/pol/useStakedAPR.ts +2 -2
  117. package/src/hooks/pol/useStakedSnapshots.ts +5 -9
  118. package/src/hooks/validators/useValidator.ts +2 -0
  119. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +39 -0
  120. package/src/types/bribe-boost.d.ts +8 -0
  121. package/src/types/exports.ts +0 -1
  122. package/src/types/governance/exports.ts +1 -0
  123. package/src/utils/beraFetch.ts +76 -15
  124. package/src/utils/exports.ts +1 -0
  125. package/src/utils/getServerSideClient.ts +4 -2
  126. package/src/utils/sanitizeRpcUrl.ts +22 -0
  127. package/src/utils/tracedTransport.ts +35 -0
  128. package/dist/BeraError-_mQdkanr.d.ts +0 -94
  129. package/dist/BexStatusProvider-DRymVlQf.d.cts +0 -70
  130. package/dist/HoneyConfigProvider-DfkjmzEf.d.cts +0 -390
  131. package/dist/RequestError-A8XJ6QR9.d.cts +0 -57
  132. package/dist/RequestError-Dk97z8rm.d.ts +0 -57
  133. package/dist/abi/exports.cjs +0 -4453
  134. package/dist/abi/exports.cjs.map +0 -1
  135. package/dist/abi/exports.d.cts +0 -6574
  136. package/dist/abi/exports.mjs.map +0 -1
  137. package/dist/actions/exports.cjs +0 -914
  138. package/dist/actions/exports.cjs.map +0 -1
  139. package/dist/actions/exports.d.cts +0 -1644
  140. package/dist/actions/exports.mjs.map +0 -1
  141. package/dist/chunk-2R73G2PO.mjs.map +0 -1
  142. package/dist/chunk-3M47ZRXT.mjs.map +0 -1
  143. package/dist/chunk-4GFN4LEP.mjs.map +0 -1
  144. package/dist/chunk-5N7QQS55.cjs +0 -130
  145. package/dist/chunk-5N7QQS55.cjs.map +0 -1
  146. package/dist/chunk-5NMATIH4.mjs.map +0 -1
  147. package/dist/chunk-7QKRRIHI.mjs.map +0 -1
  148. package/dist/chunk-7TFV6UKF.mjs.map +0 -1
  149. package/dist/chunk-A4FPM7U3.cjs +0 -63
  150. package/dist/chunk-A4FPM7U3.cjs.map +0 -1
  151. package/dist/chunk-BDHINMWQ.cjs +0 -417
  152. package/dist/chunk-BDHINMWQ.cjs.map +0 -1
  153. package/dist/chunk-BEHP54S3.cjs +0 -24
  154. package/dist/chunk-BEHP54S3.cjs.map +0 -1
  155. package/dist/chunk-EGDXV2PT.cjs +0 -36
  156. package/dist/chunk-EGDXV2PT.cjs.map +0 -1
  157. package/dist/chunk-EWBKSMPG.cjs +0 -13
  158. package/dist/chunk-EWBKSMPG.cjs.map +0 -1
  159. package/dist/chunk-F6ZW7ZDD.cjs +0 -403
  160. package/dist/chunk-F6ZW7ZDD.cjs.map +0 -1
  161. package/dist/chunk-FTXTRUYT.cjs +0 -170
  162. package/dist/chunk-FTXTRUYT.cjs.map +0 -1
  163. package/dist/chunk-GLWPRM33.mjs.map +0 -1
  164. package/dist/chunk-GWSTVITN.mjs.map +0 -1
  165. package/dist/chunk-H3Z37RYU.cjs +0 -15
  166. package/dist/chunk-H3Z37RYU.cjs.map +0 -1
  167. package/dist/chunk-I3FTWD6I.mjs.map +0 -1
  168. package/dist/chunk-JA4DHMTG.mjs.map +0 -1
  169. package/dist/chunk-KL6YZ5VR.mjs.map +0 -1
  170. package/dist/chunk-MXWPP6MS.cjs +0 -572
  171. package/dist/chunk-MXWPP6MS.cjs.map +0 -1
  172. package/dist/chunk-SGZP4O6R.mjs.map +0 -1
  173. package/dist/chunk-TDW5SPXR.cjs +0 -244
  174. package/dist/chunk-TDW5SPXR.cjs.map +0 -1
  175. package/dist/chunk-TGK3IXDN.cjs +0 -169
  176. package/dist/chunk-TGK3IXDN.cjs.map +0 -1
  177. package/dist/chunk-TJEW6YCJ.cjs +0 -97
  178. package/dist/chunk-TJEW6YCJ.cjs.map +0 -1
  179. package/dist/chunk-VA3BQ34H.mjs.map +0 -1
  180. package/dist/chunk-VA5L5FDG.mjs.map +0 -1
  181. package/dist/chunk-XSGCRLSD.cjs +0 -1844
  182. package/dist/chunk-XSGCRLSD.cjs.map +0 -1
  183. package/dist/chunk-XV3GG3HC.cjs +0 -135
  184. package/dist/chunk-XV3GG3HC.cjs.map +0 -1
  185. package/dist/chunk-Y5B224UX.cjs +0 -4698
  186. package/dist/chunk-Y5B224UX.cjs.map +0 -1
  187. package/dist/chunk-ZBTRKBSI.mjs +0 -169
  188. package/dist/chunk-ZBTRKBSI.mjs.map +0 -1
  189. package/dist/chunk-ZCEFC2TK.mjs.map +0 -1
  190. package/dist/contexts/exports.cjs +0 -83
  191. package/dist/contexts/exports.cjs.map +0 -1
  192. package/dist/contexts/exports.d.cts +0 -66
  193. package/dist/contexts/exports.mjs.map +0 -1
  194. package/dist/defaultFlags-D6KfkTZx.d.cts +0 -10
  195. package/dist/dex-C_BB0b0O.d.cts +0 -37
  196. package/dist/enum/exports.cjs +0 -59
  197. package/dist/enum/exports.cjs.map +0 -1
  198. package/dist/enum/exports.d.cts +0 -23
  199. package/dist/enum/exports.mjs.map +0 -1
  200. package/dist/errors/exports.cjs +0 -39
  201. package/dist/errors/exports.cjs.map +0 -1
  202. package/dist/errors/exports.d.cts +0 -413
  203. package/dist/errors/exports.mjs.map +0 -1
  204. package/dist/getValidatorQueuedOperatorAddress-Cql_D50j.d.cts +0 -562
  205. package/dist/global.d-B7IeayVX.d.cts +0 -474
  206. package/dist/honey-CYm0RWf4.d.cts +0 -14
  207. package/dist/hooks/exports.cjs +0 -8333
  208. package/dist/hooks/exports.cjs.map +0 -1
  209. package/dist/hooks/exports.d.cts +0 -1748
  210. package/dist/hooks/exports.mjs.map +0 -1
  211. package/dist/polling-BKnyavLI.d.cts +0 -8
  212. package/dist/txnEnum-7_o92X3N.d.ts +0 -164
  213. package/dist/types/exports.cjs +0 -1
  214. package/dist/types/exports.cjs.map +0 -1
  215. package/dist/types/exports.d.cts +0 -90
  216. package/dist/types/exports.mjs.map +0 -1
  217. package/dist/useHoneySwapState-D6vpv19r.d.cts +0 -32
  218. package/dist/utils/exports.cjs +0 -787
  219. package/dist/utils/exports.cjs.map +0 -1
  220. package/dist/utils/exports.d.cts +0 -412
  221. package/dist/utils/exports.mjs.map +0 -1
  222. package/src/actions/dex/getIsTokenExploited.ts +0 -63
  223. package/src/actions/honey/getHoneyGlobalData.ts +0 -21
  224. package/src/hooks/dex/useExploitedTokens.ts +0 -57
  225. package/src/hooks/honey/useHoneyGlobalData.ts +0 -23
@@ -0,0 +1,888 @@
1
+ import {
2
+ checkProposalField,
3
+ getAllProposals,
4
+ getBodyErrors,
5
+ getProposalDetails,
6
+ getProposalFromTx,
7
+ getProposalVotes
8
+ } from "../../chunk-AFN4CVD3.mjs";
9
+ import "../../chunk-DKMAIU74.mjs";
10
+ import "../../chunk-SGIJVHZO.mjs";
11
+ import {
12
+ assertPublicClient
13
+ } from "../../chunk-KQUMKB66.mjs";
14
+ import {
15
+ parseBaseArgs
16
+ } from "../../chunk-75M6TF7M.mjs";
17
+ import "../../chunk-J5I45WGQ.mjs";
18
+
19
+ // src/hooks/governance/useCreateProposal.ts
20
+ import { useCallback, useEffect, useState } from "react";
21
+
22
+ // src/actions/governance/getProposalParams.ts
23
+ import matter from "gray-matter";
24
+ import {
25
+ encodeFunctionData,
26
+ erc20Abi,
27
+ parseAbiItem,
28
+ toHex
29
+ } from "viem";
30
+ import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
31
+ import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
32
+
33
+ // src/utils/hasAnyTruthyValues.ts
34
+ function hasAnyTruthyValues(obj) {
35
+ return Object.values(obj).some((value) => {
36
+ if (Array.isArray(value)) {
37
+ return value.some(
38
+ (item) => typeof item === "object" && item !== null ? hasAnyTruthyValues(item) : !!item
39
+ );
40
+ }
41
+ if (typeof value === "object" && value !== null) {
42
+ return hasAnyTruthyValues(value);
43
+ }
44
+ return !!value;
45
+ });
46
+ }
47
+
48
+ // src/actions/governance/getProposalParams.ts
49
+ function getProposalParams({
50
+ proposal,
51
+ currentTopic,
52
+ onError
53
+ }) {
54
+ const e = getBodyErrors({ proposal, currentTopic });
55
+ const actions = [];
56
+ e.actions = proposal.actions.map((action, idx) => {
57
+ const errors = {};
58
+ errors.target = checkProposalField({
59
+ fieldOrType: "address",
60
+ value: action.target
61
+ });
62
+ if (action.type === "custom-action" /* CUSTOM_PROPOSAL */) {
63
+ if (action.input === "ABI") {
64
+ errors.ABI = checkProposalField({
65
+ fieldOrType: "abi",
66
+ value: action.ABI
67
+ });
68
+ if (!action.functionSignature) {
69
+ errors.functionSignature = "Required" /* REQUIRED */;
70
+ } else {
71
+ try {
72
+ const parsedSignatureAbi = parseAbiItem(action.functionSignature);
73
+ if (parsedSignatureAbi.type !== "function") {
74
+ console.error(
75
+ "parsedSignatureAbi is not a function",
76
+ parsedSignatureAbi
77
+ );
78
+ errors.functionSignature = "Invalid ABI" /* INVALID_ABI */;
79
+ } else {
80
+ errors.args = parsedSignatureAbi.inputs.map((input, index) => {
81
+ try {
82
+ if ("components" in input) {
83
+ return checkProposalField({
84
+ // @ts-expect-error this is not typed, will throw if not valid
85
+ fieldOrType: input.type,
86
+ value: action.args?.[index],
87
+ components: input.components
88
+ });
89
+ }
90
+ return checkProposalField({
91
+ // @ts-expect-error this is not typed, will throw if not valid
92
+ fieldOrType: input.type,
93
+ value: action.args?.[index]
94
+ });
95
+ } catch {
96
+ return null;
97
+ }
98
+ });
99
+ if (!errors.args.some((v) => v)) {
100
+ actions[idx] = encodeFunctionData({
101
+ abi: [parsedSignatureAbi],
102
+ args: action.args
103
+ });
104
+ }
105
+ }
106
+ } catch {
107
+ errors.functionSignature = "Invalid ABI" /* INVALID_ABI */;
108
+ }
109
+ }
110
+ } else if (action.input === "rawCalldata") {
111
+ errors.rawCalldata = checkProposalField({
112
+ fieldOrType: "hex",
113
+ value: action.rawCalldata
114
+ });
115
+ actions[idx] = action.rawCalldata;
116
+ } else if (action.input === "message") {
117
+ errors.message = checkProposalField({
118
+ fieldOrType: "string",
119
+ value: action.message
120
+ });
121
+ actions[idx] = toHex(action.message);
122
+ } else {
123
+ throw new Error("Invalid input type");
124
+ }
125
+ } else if (action.type === "whitelist-reward-vault" /* WHITELIST_REWARD_VAULT */ || action.type === "blacklist-reward-vault" /* BLACKLIST_REWARD_VAULT */) {
126
+ errors.vault = checkProposalField({
127
+ fieldOrType: "address",
128
+ value: action.vault
129
+ });
130
+ if (!errors.vault) {
131
+ const whiteList = action.type === "whitelist-reward-vault" /* WHITELIST_REWARD_VAULT */;
132
+ actions[idx] = encodeFunctionData({
133
+ abi: beraChefAbi,
134
+ functionName: "setVaultWhitelistedStatus",
135
+ args: [action.vault, whiteList, ""]
136
+ });
137
+ }
138
+ } else if (action.type === "whitelist-reward-vault-incentive" /* WHITELIST_REWARD_VAULT_INCENTIVE */) {
139
+ errors.token = checkProposalField({
140
+ fieldOrType: "address",
141
+ value: action.token
142
+ });
143
+ errors.minIncentiveRate = checkProposalField({
144
+ fieldOrType: "uint256",
145
+ value: action.minIncentiveRate
146
+ });
147
+ errors.managerAddress = checkProposalField({
148
+ fieldOrType: "address",
149
+ value: action.managerAddress
150
+ });
151
+ if (!errors.token && !errors.minIncentiveRate && !errors.managerAddress) {
152
+ actions[idx] = encodeFunctionData({
153
+ abi: rewardVaultAbi,
154
+ functionName: "whitelistIncentiveToken",
155
+ args: [
156
+ action.token,
157
+ BigInt(action.minIncentiveRate),
158
+ action.managerAddress
159
+ ]
160
+ });
161
+ }
162
+ } else if (action.type === "erc20-transfer" /* ERC20_TRANSFER */) {
163
+ errors.amount = checkProposalField({
164
+ fieldOrType: "uint256",
165
+ value: action.amount
166
+ });
167
+ errors.to = checkProposalField({
168
+ fieldOrType: "address",
169
+ value: action.to
170
+ });
171
+ if (!errors.amount && !errors.to) {
172
+ actions[idx] = encodeFunctionData({
173
+ abi: erc20Abi,
174
+ functionName: "transfer",
175
+ args: [action.to, BigInt(action.amount)]
176
+ });
177
+ }
178
+ }
179
+ const hasErrors = hasAnyTruthyValues(errors);
180
+ if (!hasErrors) {
181
+ return null;
182
+ }
183
+ return errors;
184
+ });
185
+ onError?.(e);
186
+ if (Object.getOwnPropertyNames(e).map((name) => e[name]).some((v) => {
187
+ if (Array.isArray(v)) {
188
+ return v.filter((v2) => v2).length > 0;
189
+ }
190
+ if (v === null) {
191
+ return false;
192
+ }
193
+ return !!v;
194
+ })) {
195
+ console.warn("Proposal has errors", e);
196
+ return;
197
+ }
198
+ if (actions.length === 0) {
199
+ throw new Error("No actions submitted in proposal");
200
+ }
201
+ const link = new URL(proposal.forumLink);
202
+ const description = matter.stringify(proposal.description, {
203
+ title: proposal.title,
204
+ topics: Array.from(proposal.topic.values()),
205
+ forumLink: link.toString(),
206
+ version: "1.0.0",
207
+ "content-encoding": "utf-8",
208
+ "content-type": "text/markdown",
209
+ actions: proposal.actions.map((action) => {
210
+ const actionMetadata = {
211
+ type: action.type
212
+ };
213
+ if (action.type === "custom-action" /* CUSTOM_PROPOSAL */) {
214
+ actionMetadata.inputType = action.input;
215
+ }
216
+ return actionMetadata;
217
+ })
218
+ });
219
+ return [
220
+ proposal.actions.map((action) => action.target),
221
+ proposal.actions.map((action) => action.value ?? 0n),
222
+ actions,
223
+ description
224
+ ];
225
+ }
226
+
227
+ // src/hooks/governance/useCreateProposal.ts
228
+ var defaultAction = {
229
+ type: "custom-action" /* CUSTOM_PROPOSAL */,
230
+ target: "",
231
+ ABI: "",
232
+ value: 0n,
233
+ functionSignature: "",
234
+ args: [],
235
+ input: "ABI",
236
+ rawCalldata: "0x",
237
+ message: ""
238
+ };
239
+ var useCreateProposal = ({
240
+ initialData = {},
241
+ currentTopic,
242
+ onError
243
+ }) => {
244
+ const [proposal, setProposal] = useState({
245
+ title: "",
246
+ description: "",
247
+ forumLink: "",
248
+ actions: [defaultAction],
249
+ ...initialData,
250
+ topic: /* @__PURE__ */ new Set()
251
+ });
252
+ useEffect(() => {
253
+ setProposal((p) => ({
254
+ ...p,
255
+ topic: /* @__PURE__ */ new Set([currentTopic.id])
256
+ }));
257
+ }, [currentTopic]);
258
+ const addProposalAction = useCallback(() => {
259
+ setProposal((p) => ({ ...p, actions: [...p.actions, defaultAction] }));
260
+ }, []);
261
+ const removeProposalAction = useCallback(
262
+ (idx) => {
263
+ setProposal((p) => {
264
+ const actions = [...p.actions];
265
+ actions.splice(idx, 1);
266
+ return { ...p, actions };
267
+ });
268
+ },
269
+ [setProposal]
270
+ );
271
+ const computeParamsAndErrors = useCallback(() => {
272
+ if (!proposal) {
273
+ return;
274
+ }
275
+ const computedParams = getProposalParams({
276
+ proposal,
277
+ currentTopic,
278
+ onError
279
+ });
280
+ return computedParams;
281
+ }, [proposal, currentTopic]);
282
+ return {
283
+ proposal,
284
+ setProposal,
285
+ addProposalAction,
286
+ removeProposalAction,
287
+ computeParamsAndErrors
288
+ };
289
+ };
290
+
291
+ // src/hooks/governance/useGetPastVotes.ts
292
+ import useSWRImmutable2 from "swr/immutable";
293
+ import { formatUnits } from "viem";
294
+ import { bgtAbi } from "@berachain/abis/pol/bgt";
295
+ import { useBeraWallet, usePublicClient as usePublicClient2 } from "@berachain/wagmi/hooks";
296
+
297
+ // src/hooks/governance/useProposalSnapshot.ts
298
+ import useSWRImmutable from "swr/immutable";
299
+ import { berachainGovernanceAbi as governanceAbi } from "@berachain/abis/gov/berachainGovernance";
300
+ import { usePublicClient } from "@berachain/wagmi/hooks";
301
+ var useProposalSnapshot = ({
302
+ proposalId
303
+ }) => {
304
+ const publicClient = usePublicClient();
305
+ const QUERY_KEY = publicClient && proposalId ? ["useProposalSnapshot", proposalId] : null;
306
+ return useSWRImmutable(QUERY_KEY, async ([, proposalId2]) => {
307
+ assertPublicClient(publicClient);
308
+ const { config } = parseBaseArgs({
309
+ chainId: publicClient.chain.id
310
+ });
311
+ const snapshot = await publicClient.readContract({
312
+ abi: governanceAbi,
313
+ address: config.governance.governor,
314
+ functionName: "proposalSnapshot",
315
+ args: [BigInt(proposalId2)]
316
+ });
317
+ return snapshot.toString();
318
+ });
319
+ };
320
+
321
+ // src/hooks/governance/useGetPastVotes.ts
322
+ var useGetPastVotes = (args) => {
323
+ const { address: account } = useBeraWallet();
324
+ const publicClient = usePublicClient2();
325
+ const wallet = args.wallet || account;
326
+ const { data: snapshot } = useProposalSnapshot({
327
+ proposalId: args.proposalId
328
+ });
329
+ const ts = args.timepoint || snapshot;
330
+ const QUERY_KEY = ts && publicClient && wallet ? ["useGetPastVotes", ts, wallet] : null;
331
+ return useSWRImmutable2(QUERY_KEY, async ([, ts2, wallet2]) => {
332
+ assertPublicClient(publicClient);
333
+ const { config } = parseBaseArgs({
334
+ chainId: publicClient.chain.id
335
+ });
336
+ if (Number(ts2) > Date.now() / 1e3) {
337
+ throw new Error("timepoint is in the future");
338
+ }
339
+ const votes = await publicClient.readContract({
340
+ abi: bgtAbi,
341
+ address: config.tokens.bgt,
342
+ functionName: "getPastVotes",
343
+ args: [wallet2, BigInt(ts2)]
344
+ });
345
+ return formatUnits(votes, 18);
346
+ });
347
+ };
348
+
349
+ // src/hooks/governance/useHasVoted.ts
350
+ import useSWR from "swr";
351
+ import { isAddress } from "viem";
352
+ import { berachainGovernanceAbi as governanceAbi2 } from "@berachain/abis/gov/berachainGovernance";
353
+ import { useBeraWallet as useBeraWallet2, usePublicClient as usePublicClient3 } from "@berachain/wagmi/hooks";
354
+ var useHasVoted = ({
355
+ proposalId,
356
+ wallet
357
+ }) => {
358
+ const { address: account } = useBeraWallet2();
359
+ const publicClient = usePublicClient3();
360
+ const address = wallet || account;
361
+ return useSWR(
362
+ publicClient && address && isAddress(address) ? ["useHasVoted", proposalId, address] : null,
363
+ ([, proposalId2, address2]) => {
364
+ assertPublicClient(publicClient);
365
+ const { config } = parseBaseArgs({
366
+ chainId: publicClient.chain.id
367
+ });
368
+ return publicClient.readContract({
369
+ address: config.governance.governor,
370
+ abi: governanceAbi2,
371
+ functionName: "hasVoted",
372
+ args: [BigInt(proposalId2), address2]
373
+ });
374
+ }
375
+ );
376
+ };
377
+
378
+ // src/hooks/governance/useIsCanceller.ts
379
+ import useSWR2 from "swr";
380
+ import { timeLockAbi as governanceTimelockAbi } from "@berachain/abis/gov/timeLock";
381
+ import { usePublicClient as usePublicClient4 } from "@berachain/wagmi/hooks";
382
+
383
+ // src/actions/governance/constants.ts
384
+ var CANCELLER_ROLE = "0xfd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f783";
385
+
386
+ // src/hooks/governance/useIsCanceller.ts
387
+ var useIsCanceller = ({
388
+ account,
389
+ ...baseArgs
390
+ }) => {
391
+ const publicClient = usePublicClient4();
392
+ const { config: chainConfig } = parseBaseArgs(baseArgs);
393
+ const QUERY_KEY = account && publicClient ? ["useCancellerRole", account] : null;
394
+ return useSWR2(
395
+ QUERY_KEY,
396
+ async ([, account2]) => {
397
+ assertPublicClient(publicClient);
398
+ const canceller = await publicClient.readContract({
399
+ abi: governanceTimelockAbi,
400
+ address: chainConfig.governance.timelock,
401
+ functionName: "hasRole",
402
+ args: [CANCELLER_ROLE, account2]
403
+ });
404
+ return canceller;
405
+ },
406
+ {
407
+ refreshInterval: 18e4 /* SLOW */,
408
+ revalidateOnFocus: false
409
+ }
410
+ );
411
+ };
412
+
413
+ // src/hooks/governance/usePollAllProposals.ts
414
+ import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
415
+ import useSWRInfinite from "swr/infinite";
416
+ import {
417
+ Proposal_OrderBy,
418
+ ProposalStatus
419
+ } from "@berachain/graphql/governance";
420
+ var DEFAULT_PER_PAGE = 10;
421
+ var fromUiStatusToSubgraphStatuses = (status) => {
422
+ switch (status) {
423
+ case ProposalStatus.QuorumNotReached:
424
+ return [ProposalStatus.Active, ProposalStatus.Pending];
425
+ case ProposalStatus.PendingQueue:
426
+ case ProposalStatus.Defeated:
427
+ return [ProposalStatus.Active];
428
+ case ProposalStatus.PendingExecution:
429
+ return [ProposalStatus.InQueue];
430
+ default:
431
+ return [status];
432
+ }
433
+ };
434
+ function usePollAllProposalsQueryKey(topic, args = {}) {
435
+ const subgraphPageSize = 2 * (args.perPage ?? DEFAULT_PER_PAGE);
436
+ return (pageIndex, previousPageData) => {
437
+ if (pageIndex !== 0 && previousPageData && previousPageData.length < subgraphPageSize) {
438
+ return null;
439
+ }
440
+ const statuses = args.status_in?.flatMap(fromUiStatusToSubgraphStatuses).filter((s, i, arr) => arr.indexOf(s) === i);
441
+ return [
442
+ "usePollAllProposals",
443
+ pageIndex,
444
+ topic,
445
+ args.where,
446
+ statuses,
447
+ args.orderBy,
448
+ args.orderDirection,
449
+ subgraphPageSize,
450
+ args.text
451
+ ];
452
+ };
453
+ }
454
+ function usePollAllProposals(args, options) {
455
+ const autoRefreshProposals = options?.autoRefresh ?? false;
456
+ const perPage = args.perPage ?? DEFAULT_PER_PAGE;
457
+ const subgraphPageSize = 2 * perPage;
458
+ const getKey = usePollAllProposalsQueryKey(args.topic, args);
459
+ async function fetcher(key) {
460
+ if (!key) return [];
461
+ const [
462
+ ,
463
+ pageIndex,
464
+ topic,
465
+ where,
466
+ statuses,
467
+ orderBy,
468
+ orderDirection,
469
+ pageSize,
470
+ text
471
+ ] = key;
472
+ const proposals = await getAllProposals({
473
+ where: {
474
+ topics_contains: [topic],
475
+ status_in: statuses?.length ? statuses : void 0,
476
+ ...where
477
+ },
478
+ orderBy,
479
+ orderDirection,
480
+ text,
481
+ perPage: pageSize,
482
+ offset: pageIndex * pageSize
483
+ });
484
+ return (proposals ?? []).filter(Boolean);
485
+ }
486
+ const swr = useSWRInfinite(
487
+ getKey,
488
+ fetcher,
489
+ {
490
+ // Increase initialSize in order to prefetch more proposals at a time.
491
+ initialSize: 1,
492
+ refreshInterval: options?.opts?.refreshInterval ?? 18e4 /* SLOW */,
493
+ ...options?.opts
494
+ }
495
+ );
496
+ const data = useMemo(() => {
497
+ if (!swr.data) return [];
498
+ const flattened = swr.data.flat().filter((p) => {
499
+ if (!p) return false;
500
+ if (!args.status_in?.length) return true;
501
+ return args.status_in.includes(p.status);
502
+ }).sort((a, b) => {
503
+ if (!args.text) return 0;
504
+ if (args.orderBy === Proposal_OrderBy.CreatedAt) {
505
+ const result = Number(b.createdAt) - Number(a.createdAt);
506
+ return args.orderDirection === "asc" ? result : -result;
507
+ }
508
+ return 0;
509
+ });
510
+ const chunked = [];
511
+ for (let i = 0; i < flattened.length; i += perPage) {
512
+ chunked.push(flattened.slice(i, i + perPage));
513
+ }
514
+ return chunked;
515
+ }, [swr.data, args, perPage]);
516
+ const lastPage = swr.data?.[swr.data.length - 1];
517
+ const hasMore = !!lastPage && lastPage.length === subgraphPageSize;
518
+ const [timestamp, setTimestamp] = useState2(Date.now() / 1e3);
519
+ useEffect2(() => {
520
+ if (!autoRefreshProposals) return;
521
+ const interval = setInterval(() => {
522
+ setTimestamp(Date.now() / 1e3);
523
+ }, 1e4 /* FAST */);
524
+ return () => clearInterval(interval);
525
+ }, [autoRefreshProposals]);
526
+ useEffect2(() => {
527
+ if (!swr.data) return;
528
+ let shouldMutate = false;
529
+ for (const proposal of swr.data.flat()) {
530
+ switch (proposal.status) {
531
+ case ProposalStatus.Pending:
532
+ if (timestamp >= Number(proposal.voteStartAt)) {
533
+ shouldMutate = true;
534
+ }
535
+ break;
536
+ case ProposalStatus.Active:
537
+ if (timestamp >= Number(proposal.voteEndAt)) {
538
+ shouldMutate = true;
539
+ }
540
+ break;
541
+ case ProposalStatus.InQueue:
542
+ if (Date.now() / 1e3 + 1 >= Number(proposal.queueEnd)) {
543
+ shouldMutate = true;
544
+ }
545
+ break;
546
+ default:
547
+ break;
548
+ }
549
+ if (shouldMutate) break;
550
+ }
551
+ if (shouldMutate) {
552
+ swr.mutate();
553
+ }
554
+ }, [swr.data, timestamp]);
555
+ return {
556
+ ...swr,
557
+ data,
558
+ hasMore
559
+ };
560
+ }
561
+
562
+ // src/hooks/governance/usePollProposal.ts
563
+ import { useEffect as useEffect3, useState as useState3 } from "react";
564
+ import useSWR3 from "swr";
565
+ import {
566
+ ProposalStatus as ProposalStatus2
567
+ } from "@berachain/graphql/governance";
568
+ import { usePublicClient as usePublicClient5 } from "@berachain/wagmi/hooks";
569
+ var usePollProposal = (proposalId, options) => {
570
+ const autoRefreshProposal = options?.autoRefresh ?? false;
571
+ const publicClient = usePublicClient5();
572
+ const QUERY_KEY = proposalId && publicClient ? ["usePollProposal", proposalId] : null;
573
+ const swrResponse = useSWR3(
574
+ QUERY_KEY,
575
+ ([, proposalId2]) => {
576
+ assertPublicClient(publicClient);
577
+ return getProposalDetails({ proposalId: proposalId2, client: publicClient });
578
+ },
579
+ {
580
+ ...options?.opts,
581
+ refreshInterval: options?.opts?.refreshInterval ?? 18e4 /* SLOW */
582
+ }
583
+ );
584
+ const [timestamp, setTimestamp] = useState3(Date.now());
585
+ useEffect3(() => {
586
+ if (!autoRefreshProposal) return;
587
+ const interval = setInterval(() => {
588
+ setTimestamp(Date.now() / 1e3);
589
+ }, 1e4 /* FAST */);
590
+ return () => clearInterval(interval);
591
+ }, []);
592
+ useEffect3(() => {
593
+ if (swrResponse.data === void 0) return;
594
+ switch (swrResponse.data.status) {
595
+ case ProposalStatus2.Pending:
596
+ if (timestamp >= Number(swrResponse.data.voteStartAt)) {
597
+ swrResponse.mutate();
598
+ }
599
+ break;
600
+ case ProposalStatus2.Active:
601
+ if (timestamp >= Number(swrResponse.data.voteEndAt)) {
602
+ swrResponse.mutate();
603
+ }
604
+ break;
605
+ case ProposalStatus2.InQueue:
606
+ if (Date.now() / 1e3 + 1 >= Number(swrResponse.data.queueEnd)) {
607
+ swrResponse.mutate();
608
+ }
609
+ break;
610
+ }
611
+ }, [swrResponse.data?.status, timestamp]);
612
+ return {
613
+ ...swrResponse,
614
+ refresh: () => swrResponse?.mutate?.()
615
+ };
616
+ };
617
+
618
+ // src/hooks/governance/usePollProposalThreshold.ts
619
+ import useSWR4 from "swr";
620
+ import { formatEther } from "viem";
621
+ import { berachainGovernanceAbi as governanceAbi3 } from "@berachain/abis/gov/berachainGovernance";
622
+ import { usePublicClient as usePublicClient6 } from "@berachain/wagmi/hooks";
623
+ var usePollProposalThreshold = (governorAddress) => {
624
+ const publicClient = usePublicClient6();
625
+ const QUERY_KEY = publicClient ? ["usePollProposalThreshold", governorAddress] : null;
626
+ const swrResponse = useSWR4(
627
+ QUERY_KEY,
628
+ async ([, governorAddress2]) => {
629
+ assertPublicClient(publicClient);
630
+ const votesThreshold = await publicClient.readContract({
631
+ address: governorAddress2,
632
+ abi: governanceAbi3,
633
+ functionName: "proposalThreshold"
634
+ });
635
+ return { votesThreshold: formatEther(votesThreshold) };
636
+ },
637
+ {
638
+ refreshInterval: 18e4 /* SLOW */
639
+ }
640
+ );
641
+ return {
642
+ ...swrResponse,
643
+ refresh: swrResponse.mutate
644
+ };
645
+ };
646
+
647
+ // src/hooks/governance/usePollProposalVotes.ts
648
+ import useSWRInfinite2 from "swr/infinite";
649
+ var DEFAULT_LIMIT = 1e3;
650
+ var usePollProposalVotes = (args, total) => {
651
+ return useSWRInfinite2(
652
+ usePollProposalVotesQueryKey(args, total),
653
+ async ([_key, page]) => {
654
+ return getProposalVotes({
655
+ variables: {
656
+ ...args,
657
+ limit: DEFAULT_LIMIT,
658
+ offset: DEFAULT_LIMIT * page
659
+ }
660
+ });
661
+ },
662
+ {
663
+ parallel: true,
664
+ // Fetches all the data at once, we limit the number of pages by providing a total
665
+ initialSize: Number.POSITIVE_INFINITY
666
+ }
667
+ );
668
+ };
669
+ var usePollProposalVotesQueryKey = ({ ...args }, total) => (pageIndex) => {
670
+ if (pageIndex > Math.floor(total / DEFAULT_LIMIT)) {
671
+ return null;
672
+ }
673
+ return [
674
+ "usePollProposalVotes",
675
+ pageIndex,
676
+ DEFAULT_LIMIT,
677
+ args.proposalId,
678
+ args.orderBy,
679
+ args.orderDirection
680
+ ];
681
+ };
682
+
683
+ // src/hooks/governance/usePollUserDelegates.ts
684
+ import useSWR5 from "swr";
685
+ import { formatEther as formatEther2 } from "viem";
686
+ import { bgtAbi as bgtAbi2 } from "@berachain/abis/pol/bgt";
687
+ import { useBeraWallet as useBeraWallet3, usePublicClient as usePublicClient7 } from "@berachain/wagmi/hooks";
688
+ var usePollUserDelegates = (options) => {
689
+ const { address: account } = useBeraWallet3();
690
+ const publicClient = usePublicClient7();
691
+ const QUERY_KEY = account ? ["usePollUserDelegates", account] : null;
692
+ const swrResponse = useSWR5(
693
+ QUERY_KEY,
694
+ async ([, account2]) => {
695
+ assertPublicClient(publicClient);
696
+ const { config } = parseBaseArgs({
697
+ chainId: publicClient.chain.id
698
+ });
699
+ if (!publicClient || !account2) {
700
+ throw new Error("usePollUserDelegates needs publicClient and account");
701
+ }
702
+ const [delegate, currentVotes] = await Promise.all([
703
+ publicClient.readContract({
704
+ address: config.tokens.bgt,
705
+ abi: bgtAbi2,
706
+ functionName: "delegates",
707
+ args: [account2]
708
+ }),
709
+ publicClient.readContract({
710
+ address: config.tokens.bgt,
711
+ abi: bgtAbi2,
712
+ functionName: "getVotes",
713
+ args: [account2]
714
+ })
715
+ ]);
716
+ return {
717
+ delegate,
718
+ currentVotes: formatEther2(currentVotes)
719
+ };
720
+ },
721
+ {
722
+ ...options?.opts,
723
+ refreshInterval: options?.opts?.refreshInterval ?? 18e4 /* SLOW */
724
+ }
725
+ );
726
+ return {
727
+ ...swrResponse,
728
+ refresh: () => swrResponse?.mutate?.()
729
+ };
730
+ };
731
+
732
+ // src/hooks/governance/useProposalFromTx.ts
733
+ import useSWR6 from "swr";
734
+ import { usePublicClient as usePublicClient8, useTransactionReceipt } from "@berachain/wagmi/hooks";
735
+ var useProposalFromTx = (txHash) => {
736
+ const { data: tx } = useTransactionReceipt({
737
+ hash: txHash
738
+ });
739
+ const publicClient = usePublicClient8();
740
+ const QUERY_KEY = tx && publicClient ? ["useProposalFromTx", txHash] : null;
741
+ const swrResponse = useSWR6(QUERY_KEY, async ([, txHash2]) => {
742
+ if (!tx) {
743
+ throw new Error("Transaction not found");
744
+ }
745
+ if (tx.transactionHash !== txHash2) {
746
+ throw new Error("Transaction hash mismatch");
747
+ }
748
+ return getProposalFromTx({ tx, publicClient });
749
+ });
750
+ return swrResponse;
751
+ };
752
+
753
+ // src/hooks/governance/useProposalState.ts
754
+ import useSWRImmutable3 from "swr/immutable";
755
+ import { berachainGovernanceAbi as governanceAbi4 } from "@berachain/abis/gov/berachainGovernance";
756
+ import { usePublicClient as usePublicClient9 } from "@berachain/wagmi/hooks";
757
+ var ProposalStateMap = {
758
+ [0 /* Pending */]: "pending",
759
+ [1 /* Active */]: "active",
760
+ [2 /* Canceled */]: "canceled",
761
+ [3 /* Defeated */]: "defeated",
762
+ [4 /* Succeeded */]: "succeeded",
763
+ [5 /* Queued */]: "queued",
764
+ [6 /* Expired */]: "expired",
765
+ [7 /* Executed */]: "executed"
766
+ };
767
+ var useProposalState = ({
768
+ proposalId,
769
+ governorAddress
770
+ }) => {
771
+ const publicClient = usePublicClient9();
772
+ const QUERY_KEY = governorAddress && publicClient && proposalId ? ["useProposalState", proposalId] : null;
773
+ return useSWRImmutable3(QUERY_KEY, async ([, proposalId2]) => {
774
+ assertPublicClient(publicClient);
775
+ const snapshot = await publicClient.readContract({
776
+ abi: governanceAbi4,
777
+ address: governorAddress,
778
+ functionName: "state",
779
+ args: [BigInt(proposalId2)]
780
+ });
781
+ return ProposalStateMap[snapshot];
782
+ });
783
+ };
784
+
785
+ // src/hooks/governance/useProposalTimelockState.ts
786
+ import useSWR7 from "swr";
787
+ import { timeLockAbi as governanceTimelockAbi2 } from "@berachain/abis/gov/timeLock";
788
+ import { usePublicClient as usePublicClient10 } from "@berachain/wagmi/hooks";
789
+ var TimelockOperationState = {
790
+ 0: "unset",
791
+ 1: "waiting",
792
+ 2: "ready",
793
+ 3: "done"
794
+ };
795
+ function useProposalTimelockState({
796
+ proposalTimelockId,
797
+ timelockAddress
798
+ }) {
799
+ const publicClient = usePublicClient10();
800
+ const QUERY_KEY = timelockAddress && publicClient && proposalTimelockId ? [
801
+ "useProposalTimelockState",
802
+ proposalTimelockId,
803
+ timelockAddress
804
+ ] : null;
805
+ return useSWR7(
806
+ QUERY_KEY,
807
+ async ([, proposalTimelockId2, timelockAddress2]) => {
808
+ assertPublicClient(publicClient);
809
+ const snapshot = await publicClient.readContract({
810
+ abi: governanceTimelockAbi2,
811
+ address: timelockAddress2,
812
+ functionName: "getOperationState",
813
+ args: [proposalTimelockId2]
814
+ });
815
+ return TimelockOperationState[snapshot];
816
+ },
817
+ {
818
+ refreshInterval: 18e4 /* SLOW */
819
+ }
820
+ );
821
+ }
822
+
823
+ // src/hooks/governance/useQuorum.ts
824
+ import useSWR8 from "swr";
825
+ import { usePublicClient as usePublicClient11 } from "@berachain/wagmi/hooks";
826
+
827
+ // src/actions/governance/getQuorum.ts
828
+ import { formatEther as formatEther3 } from "viem";
829
+ import { berachainGovernanceAbi as governanceAbi5 } from "@berachain/abis/gov/berachainGovernance";
830
+ async function getQuorum({
831
+ at,
832
+ publicClient,
833
+ ...args
834
+ }) {
835
+ const { config } = parseBaseArgs(args);
836
+ assertPublicClient(publicClient);
837
+ const quorum = await publicClient.readContract({
838
+ address: config.governance.governor,
839
+ abi: governanceAbi5,
840
+ functionName: "quorum",
841
+ // Needs to be pending or you'll get a ERC5805FutureLookup error when reading current quorum
842
+ // this is because now will always be in the future compared to the latest block
843
+ blockTag: "pending",
844
+ args: [BigInt(at ?? Math.floor(Date.now() / 1e3))]
845
+ });
846
+ return formatEther3(quorum);
847
+ }
848
+
849
+ // src/hooks/governance/useQuorum.ts
850
+ function useQuorum({ at }, {
851
+ isEnabled = true
852
+ }) {
853
+ const now = Math.floor(Date.now() / 1e3);
854
+ const publicClient = usePublicClient11();
855
+ const QUERY_KEY = isEnabled && publicClient ? [
856
+ "useQuorum",
857
+ // Using Now because we cannot query quorum in the future, so no need to have different query keys.
858
+ Number(at) > now ? "now" : at
859
+ ] : null;
860
+ const response = useSWR8(QUERY_KEY, async ([, at2]) => {
861
+ if (at2 === "now") {
862
+ return getQuorum({ publicClient });
863
+ }
864
+ return getQuorum({ at: at2, publicClient });
865
+ });
866
+ return {
867
+ ...response,
868
+ data: response.data ? Number(response.data) : void 0
869
+ };
870
+ }
871
+ export {
872
+ useCreateProposal,
873
+ useGetPastVotes,
874
+ useHasVoted,
875
+ useIsCanceller,
876
+ usePollAllProposals,
877
+ usePollAllProposalsQueryKey,
878
+ usePollProposal,
879
+ usePollProposalThreshold,
880
+ usePollProposalVotes,
881
+ usePollProposalVotesQueryKey,
882
+ usePollUserDelegates,
883
+ useProposalFromTx,
884
+ useProposalSnapshot,
885
+ useProposalState,
886
+ useProposalTimelockState,
887
+ useQuorum
888
+ };