@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,140 @@
1
+ import { AbiParameter, Address, PublicClient, AbiFunction, TransactionReceipt } from 'viem';
2
+ import { ProposalErrorCodes, ProposalState } from '../../enum/governance/exports.js';
3
+ import { ProposalStatus, ProposalSelectionFragment, Proposal_Filter, Proposal_OrderBy, OrderDirection, ProposalWithVotesFragment, GetProposalVotesQueryVariables, GetProposalVotesQuery } from '@berachain/graphql/governance';
4
+ import { CustomProposal, GovernanceTopic, CustomProposalErrors } from '../../types/governance/exports.js';
5
+ import graymatter from 'gray-matter';
6
+
7
+ type CheckProposalFieldResultMinimal = ProposalErrorCodes | null;
8
+ type CheckProposalFieldResult = ProposalErrorCodes | null | CheckProposalFieldResultMinimal[] | Record<string, CheckProposalFieldResultMinimal>;
9
+ /**
10
+ * Validates a single proposal field or ABI-typed value.
11
+ * Returns `null` if valid, or a `ProposalErrorCodes` value describing the problem.
12
+ */
13
+ declare function checkProposalField(arg: {
14
+ fieldOrType: "address" | "hex" | "abi" | "string" | "bool" | `uint${string}` | `int${string}` | "action" | "title" | "forumLink" | "description" | "logoURI" | "url";
15
+ value: unknown;
16
+ required?: boolean;
17
+ baseUrl?: string;
18
+ components?: readonly (AbiParameter | readonly AbiParameter[])[];
19
+ }): CheckProposalFieldResultMinimal;
20
+ /**
21
+ * For tuple/tuple[] types, may return nested error structures.
22
+ */
23
+ declare function checkProposalField(arg: {
24
+ fieldOrType: "tuple[]" | "tuple";
25
+ value: unknown;
26
+ required?: boolean;
27
+ baseUrl?: string;
28
+ components?: readonly (AbiParameter | readonly AbiParameter[])[];
29
+ }): CheckProposalFieldResult;
30
+
31
+ declare const MOCKED_PROPOSAL_STATUSES: readonly ProposalStatus[];
32
+ /**
33
+ * Derives the effective `ProposalStatus` by reconciling subgraph data with the
34
+ * on-chain contract state. Falls back to subgraph timestamps when the on-chain
35
+ * state is unavailable.
36
+ */
37
+ declare function computeActualStatus(
38
+ /** Subgraph proposal data */
39
+ proposal: ProposalSelectionFragment,
40
+ /** Value returned by the `state` function of the governance contract */
41
+ proposalOnChainState?: ProposalState): ProposalStatus;
42
+
43
+ type GetAllProposalsArgs = BeraJS.BaseFunctionArgs & {
44
+ /** Subgraph filter applied to the proposals query */
45
+ where: Proposal_Filter;
46
+ /** Number of proposals to skip (for pagination) */
47
+ offset?: number;
48
+ /** Maximum proposals per page; must be ≤ 1000 */
49
+ perPage?: number;
50
+ orderBy?: Proposal_OrderBy;
51
+ orderDirection?: OrderDirection;
52
+ /** Full-text search query; switches to the search endpoint when provided */
53
+ text?: string;
54
+ };
55
+ /** Fetches a paginated list of governance proposals from the subgraph */
56
+ declare function getAllProposals(_args: GetAllProposalsArgs): Promise<ProposalSelectionFragment[] | undefined>;
57
+
58
+ interface GetBodyErrorsArgs {
59
+ /** The proposal to validate */
60
+ proposal: CustomProposal;
61
+ /** The current governance topic, used for forum link base URL validation */
62
+ currentTopic: GovernanceTopic;
63
+ }
64
+ /** Validates the body fields (title, description, forum link) of a proposal */
65
+ declare function getBodyErrors({ proposal, currentTopic, }: GetBodyErrorsArgs): CustomProposalErrors;
66
+
67
+ interface GetDecodedFunctionDataArgs {
68
+ /** Contract address that emitted the calldata */
69
+ address: Address;
70
+ /** Raw calldata to decode */
71
+ callData: `0x${string}`;
72
+ /** @default defaultChainId */
73
+ chainId?: number;
74
+ publicClient: PublicClient;
75
+ }
76
+ /**
77
+ * Decodes the function data from a given contract address and calldata.
78
+ *
79
+ * Attempts to decode using a known set of ABIs first, then falls back to
80
+ * fetching the ABI from the block-explorer API.
81
+ *
82
+ * @returns An object with the decoded ABI item, function signature, function name, and arguments.
83
+ */
84
+ declare function getDecodedFunctionData({ address, callData, chainId, publicClient, }: GetDecodedFunctionDataArgs): Promise<{
85
+ args: never[];
86
+ abiItem?: undefined;
87
+ functionSignature?: undefined;
88
+ functionName?: undefined;
89
+ } | {
90
+ abiItem: AbiFunction | undefined;
91
+ functionSignature: string | undefined;
92
+ functionName: string;
93
+ args: unknown[];
94
+ }>;
95
+
96
+ type GetProposalDetailsArgs = BeraJS.BaseFunctionArgs & {
97
+ /** On-chain proposal ID */
98
+ proposalId: string;
99
+ client?: PublicClient;
100
+ };
101
+ /** Fetches a single proposal with its vote data from the subgraph */
102
+ declare function getProposalDetails(_args: GetProposalDetailsArgs): Promise<ProposalWithVotesFragment | undefined>;
103
+
104
+ type GetProposalFromTxArgs = {
105
+ /** Viem public client used to fetch block and receipt data */
106
+ publicClient: PublicClient | undefined;
107
+ } & ({
108
+ /** Pre-fetched transaction receipt */
109
+ tx: TransactionReceipt;
110
+ } | {
111
+ /** Transaction hash to look up */
112
+ txHash: Address;
113
+ });
114
+ /**
115
+ * Reconstructs a `ProposalWithVotesFragment` from the `ProposalCreated` event
116
+ * emitted in a given transaction. Returns `null` if the event is not found.
117
+ */
118
+ declare function getProposalFromTx(args: GetProposalFromTxArgs): Promise<ProposalWithVotesFragment | null>;
119
+
120
+ type GetProposalVotesArgs = BeraJS.BaseFunctionArgs & {
121
+ /** GraphQL variables forwarded to the GetProposalVotes query */
122
+ variables: GetProposalVotesQueryVariables;
123
+ };
124
+ /** Fetches the votes for a proposal from the subgraph */
125
+ declare function getProposalVotes(_args: GetProposalVotesArgs): Promise<{
126
+ data: GetProposalVotesQuery;
127
+ }>;
128
+
129
+ type ParseProposalBodyResult = graymatter.GrayMatterFile<string> & {
130
+ /** Whether the body uses YAML front-matter (true) or legacy heading format (false) */
131
+ isFrontMatter: boolean;
132
+ };
133
+ /**
134
+ * Parses the body of a governance proposal into structured front-matter and content.
135
+ * Supports YAML front-matter format and a legacy heading-based format.
136
+ * Falls back to raw description on parse failure.
137
+ */
138
+ declare function parseProposalBody(proposal?: Pick<ProposalSelectionFragment, "description">): ParseProposalBodyResult;
139
+
140
+ export { type GetAllProposalsArgs, type GetBodyErrorsArgs, type GetDecodedFunctionDataArgs, type GetProposalDetailsArgs, type GetProposalFromTxArgs, type GetProposalVotesArgs, MOCKED_PROPOSAL_STATUSES, type ParseProposalBodyResult, checkProposalField, computeActualStatus, getAllProposals, getBodyErrors, getDecodedFunctionData, getProposalDetails, getProposalFromTx, getProposalVotes, parseProposalBody };
@@ -0,0 +1,226 @@
1
+ import {
2
+ checkProposalField,
3
+ getAllProposals,
4
+ getBodyErrors,
5
+ getProposalDetails,
6
+ getProposalFromTx,
7
+ getProposalVotes,
8
+ parseProposalBody
9
+ } from "../../chunk-GUURQAME.mjs";
10
+ import "../../chunk-DKMAIU74.mjs";
11
+ import "../../chunk-GY6B3PD5.mjs";
12
+ import "../../chunk-KHXJDYA4.mjs";
13
+
14
+ // src/actions/governance/computeActualStatus.ts
15
+ import {
16
+ ProposalStatus
17
+ } from "@berachain/graphql/governance";
18
+ var GOVERNANCE_ACCELERATE_PROPOSAL = false;
19
+ var MOCKED_PROPOSAL_STATUSES = [
20
+ ProposalStatus.Active,
21
+ ProposalStatus.PendingQueue,
22
+ ProposalStatus.PendingExecution,
23
+ ProposalStatus.Defeated,
24
+ ProposalStatus.QuorumNotReached
25
+ ];
26
+ function computeActualStatus(proposal, proposalOnChainState) {
27
+ const timestampInSeconds = Date.now() / 1e3;
28
+ if (proposalOnChainState !== void 0) {
29
+ if (proposal.status === ProposalStatus.CanceledByGuardian) {
30
+ return ProposalStatus.CanceledByGuardian;
31
+ }
32
+ if (proposalOnChainState === 2 /* Canceled */) {
33
+ if (Number(proposal.voteStartAt) < timestampInSeconds)
34
+ return ProposalStatus.CanceledByUser;
35
+ return ProposalStatus.CanceledByGuardian;
36
+ }
37
+ if (proposalOnChainState === 3 /* Defeated */) {
38
+ if (!proposal.pollResult) {
39
+ return ProposalStatus.QuorumNotReached;
40
+ }
41
+ if (
42
+ // Quorum might be null if no votes were cast.
43
+ !proposal.quorum || BigInt(proposal.quorum) > BigInt(proposal.pollResult.totalTowardsQuorum)
44
+ ) {
45
+ return ProposalStatus.QuorumNotReached;
46
+ }
47
+ return ProposalStatus.Defeated;
48
+ }
49
+ if (proposalOnChainState === 4 /* Succeeded */) {
50
+ return ProposalStatus.PendingQueue;
51
+ }
52
+ if (proposalOnChainState === 5 /* Queued */) {
53
+ if (Number(proposal.queueEnd) < Date.now() / 1e3) {
54
+ return ProposalStatus.PendingExecution;
55
+ }
56
+ return ProposalStatus.InQueue;
57
+ }
58
+ if (proposalOnChainState === 6 /* Expired */) {
59
+ console.warn("Unexpected expired state on proposal id: ", proposal.id);
60
+ return ProposalStatus.Defeated;
61
+ }
62
+ }
63
+ if (proposal.status === ProposalStatus.InQueue) {
64
+ if (Number(proposal.queueEnd) < Date.now() / 1e3) {
65
+ return ProposalStatus.PendingExecution;
66
+ }
67
+ }
68
+ if (GOVERNANCE_ACCELERATE_PROPOSAL && proposalOnChainState === 1 /* Active */ && proposal.quorum && BigInt(proposal.quorum) < BigInt(proposal.pollResult.totalTowardsQuorum) && Number(proposal.pollResult.forPercentage) > Number(proposal.pollResult.againstPercentage)) {
69
+ return ProposalStatus.PendingQueue;
70
+ }
71
+ if (proposal.status === ProposalStatus.Pending) {
72
+ if (Number(proposal.voteStartAt) < timestampInSeconds && Number(proposal.voteEndAt) > timestampInSeconds) {
73
+ return ProposalStatus.Active;
74
+ }
75
+ if (Number(proposal.voteEndAt) < timestampInSeconds) {
76
+ if (!proposal.pollResult) {
77
+ return ProposalStatus.QuorumNotReached;
78
+ }
79
+ if (!proposal.quorum || BigInt(proposal.quorum) > BigInt(proposal.pollResult.totalTowardsQuorum)) {
80
+ return ProposalStatus.QuorumNotReached;
81
+ }
82
+ if (proposal.pollResult?.against > proposal.pollResult?.for) {
83
+ return ProposalStatus.Defeated;
84
+ }
85
+ return ProposalStatus.PendingQueue;
86
+ }
87
+ return ProposalStatus.Pending;
88
+ }
89
+ if (proposal.status === ProposalStatus.Active && Number(proposal.voteEndAt) < timestampInSeconds) {
90
+ if (!proposal.quorum || BigInt(proposal.quorum) > BigInt(proposal.pollResult.totalTowardsQuorum)) {
91
+ return ProposalStatus.QuorumNotReached;
92
+ }
93
+ if (BigInt(proposal.pollResult?.against ?? 0n) > BigInt(proposal.pollResult?.for ?? 0n)) {
94
+ return ProposalStatus.Defeated;
95
+ }
96
+ return ProposalStatus.PendingQueue;
97
+ }
98
+ if (proposal.status === ProposalStatus.InQueue) {
99
+ if (Number(proposal.queueEnd) < Date.now() / 1e3) {
100
+ return ProposalStatus.PendingExecution;
101
+ }
102
+ }
103
+ return proposal.status;
104
+ }
105
+
106
+ // src/actions/governance/getDecodedFunctionData.ts
107
+ import {
108
+ decodeFunctionData,
109
+ erc20Abi,
110
+ pad,
111
+ toFunctionSignature,
112
+ trim
113
+ } from "viem";
114
+ import { appConfig, defaultChainId } from "@berachain/config/internal";
115
+ import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
116
+ import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
117
+ function isProxyABI(abi) {
118
+ return abi.some((item) => {
119
+ const i = item;
120
+ return i.name === "implementation" || i.name === "proxyType" || i.type === "constructor" && i.inputs?.[0]?.name === "implementation";
121
+ });
122
+ }
123
+ async function _getAbi({
124
+ contractAddress,
125
+ chainId,
126
+ publicClient
127
+ }) {
128
+ const url = `https://api.etherscan.io/v2/api?module=contract&action=getabi&address=${contractAddress}&apikey=${appConfig.apiKeys.private.etherscan}&chainId=${chainId}`;
129
+ const response = await fetch(url);
130
+ if (!response.ok) {
131
+ throw new Error(`Failed to fetch ABI: ${response.statusText}`);
132
+ }
133
+ const data = await response.json();
134
+ if (data.status === "0") throw new Error(data.result);
135
+ const abi = JSON.parse(data.result);
136
+ if (!isProxyABI(abi)) return abi;
137
+ const implementationResult = await publicClient.getStorageAt({
138
+ address: contractAddress,
139
+ // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)).
140
+ slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
141
+ });
142
+ if (!implementationResult || trim(implementationResult) === "0x00")
143
+ return abi;
144
+ const implementationAddress = pad(trim(implementationResult), { size: 20 });
145
+ return _getAbi({
146
+ contractAddress: implementationAddress,
147
+ chainId,
148
+ publicClient
149
+ });
150
+ }
151
+ async function _getAbiForCallData({
152
+ address,
153
+ callData,
154
+ knownAbi,
155
+ chainId,
156
+ publicClient
157
+ }) {
158
+ try {
159
+ if (decodeFunctionData({ data: callData, abi: knownAbi })) {
160
+ return knownAbi;
161
+ }
162
+ } catch {
163
+ }
164
+ return _getAbi({ contractAddress: address, chainId, publicClient }).catch(
165
+ () => void 0
166
+ );
167
+ }
168
+ function _decodeCallData(callData, abi) {
169
+ try {
170
+ return decodeFunctionData({ data: callData, abi });
171
+ } catch {
172
+ return void 0;
173
+ }
174
+ }
175
+ function _findAbiItem(abi, functionName) {
176
+ return abi.find(
177
+ (a) => a.type === "function" && a.name === functionName
178
+ );
179
+ }
180
+ function _getFunctionSignature(abiItem) {
181
+ if (!abiItem) return;
182
+ try {
183
+ return toFunctionSignature(abiItem);
184
+ } catch (error) {
185
+ console.error(error);
186
+ }
187
+ }
188
+ async function getDecodedFunctionData({
189
+ address,
190
+ callData,
191
+ chainId = defaultChainId,
192
+ publicClient
193
+ }) {
194
+ const knownAbi = [...beraChefAbi, ...rewardVaultAbi, ...erc20Abi];
195
+ const abi = await _getAbiForCallData({
196
+ address,
197
+ callData,
198
+ knownAbi,
199
+ chainId,
200
+ publicClient
201
+ });
202
+ const decodedData = _decodeCallData(callData, abi);
203
+ if (!abi || !decodedData) {
204
+ return { args: [] };
205
+ }
206
+ const abiItem = _findAbiItem(abi, decodedData.functionName);
207
+ const functionSignature = _getFunctionSignature(abiItem);
208
+ return {
209
+ abiItem,
210
+ functionSignature,
211
+ functionName: decodedData.functionName,
212
+ args: decodedData.args
213
+ };
214
+ }
215
+ export {
216
+ MOCKED_PROPOSAL_STATUSES,
217
+ checkProposalField,
218
+ computeActualStatus,
219
+ getAllProposals,
220
+ getBodyErrors,
221
+ getDecodedFunctionData,
222
+ getProposalDetails,
223
+ getProposalFromTx,
224
+ getProposalVotes,
225
+ parseProposalBody
226
+ };
@@ -0,0 +1,13 @@
1
+ import { Address } from 'viem';
2
+ import { GetValidatorBlockStatsQuery } from '@berachain/graphql/pol/subgraph';
3
+
4
+ /**
5
+ * Server-only RSC variant. Goes directly to the pol subgraph upstream
6
+ * (no auth required) through the shared Apollo client factory.
7
+ */
8
+ declare function getDailyValidatorBlockStats({ pubKey, first, ...args }: BeraJS.BaseFunctionArgs & {
9
+ pubKey: Address;
10
+ first?: number;
11
+ }): Promise<GetValidatorBlockStatsQuery | undefined>;
12
+
13
+ export { getDailyValidatorBlockStats };
@@ -0,0 +1,27 @@
1
+ import {
2
+ getApolloClient
3
+ } from "../../chunk-3JJLQ2JX.mjs";
4
+ import "../../chunk-DQRH5VE3.mjs";
5
+ import "../../chunk-SZ5C44L5.mjs";
6
+ import "../../chunk-ZLTMIFCZ.mjs";
7
+ import "../../chunk-KHXJDYA4.mjs";
8
+
9
+ // src/actions/server/getDailyValidatorBlockStats.ts
10
+ import {
11
+ GetValidatorBlockStats
12
+ } from "@berachain/graphql/pol/subgraph";
13
+ async function getDailyValidatorBlockStats({
14
+ pubKey,
15
+ first = 1,
16
+ ...args
17
+ }) {
18
+ const client = getApolloClient("pol.subgraph", args);
19
+ const result = await client.query({
20
+ query: GetValidatorBlockStats,
21
+ variables: { pubKey, first }
22
+ });
23
+ return result.data;
24
+ }
25
+ export {
26
+ getDailyValidatorBlockStats
27
+ };
@@ -0,0 +1,211 @@
1
+ import {
2
+ parseBaseArgs
3
+ } from "./chunk-DQRH5VE3.mjs";
4
+ import {
5
+ BeraTracing
6
+ } from "./chunk-SZ5C44L5.mjs";
7
+ import {
8
+ RequestError
9
+ } from "./chunk-ZLTMIFCZ.mjs";
10
+ import {
11
+ BeraError
12
+ } from "./chunk-KHXJDYA4.mjs";
13
+
14
+ // src/actions/clients/BeraApolloClient.ts
15
+ import {
16
+ ApolloClient,
17
+ ServerError
18
+ } from "@apollo/client";
19
+ import { appConfig } from "@berachain/config/internal";
20
+ var BeraApolloClient = class extends ApolloClient {
21
+ /**
22
+ * The URL of the endpoint. Used for error reporting only.
23
+ */
24
+ url;
25
+ serviceName;
26
+ constructor(options) {
27
+ super(options);
28
+ this.url = options.url;
29
+ this.serviceName = options.name;
30
+ }
31
+ async query(options) {
32
+ const queryName = getQueryName(options.query);
33
+ const endpoint = {
34
+ url: this.url,
35
+ type: "graphql",
36
+ name: this.serviceName
37
+ };
38
+ const tags = {
39
+ "operation.type": "query",
40
+ "operation.source.name": endpoint.name,
41
+ "operation.source.url": endpoint.url,
42
+ "operation.source.type": endpoint.type,
43
+ "operation.source.queryName": queryName
44
+ };
45
+ try {
46
+ const executeQuery = () => super.query(
47
+ options
48
+ );
49
+ const res = await BeraTracing.startSpan(
50
+ {
51
+ name: `GraphQL ${queryName}`,
52
+ op: "BeraApolloClient.query",
53
+ attributes: tags
54
+ },
55
+ executeQuery
56
+ );
57
+ if (res.error || res.data === void 0) {
58
+ throw new BeraError({
59
+ level: "fatal",
60
+ tags,
61
+ message: "Bera Apollo Client: No data returned from query, but error should be thrown since errorPolicy is none"
62
+ });
63
+ }
64
+ return { data: res.data };
65
+ } catch (error) {
66
+ !appConfig.env.isProduction && console.error("BeraApolloClient error", error);
67
+ if (ServerError.is(error)) {
68
+ throw new RequestError({
69
+ // reason: error,
70
+ response: error.response,
71
+ cause: error,
72
+ statusCode: error.statusCode,
73
+ endpoint,
74
+ tags
75
+ });
76
+ }
77
+ if (error instanceof TypeError) {
78
+ throw new RequestError({
79
+ level: "fatal",
80
+ reason: "TypeError",
81
+ response: error,
82
+ cause: error,
83
+ endpoint,
84
+ tags
85
+ });
86
+ }
87
+ throw new RequestError({
88
+ response: error,
89
+ tags,
90
+ cause: error,
91
+ endpoint
92
+ });
93
+ }
94
+ }
95
+ };
96
+ function getQueryName(queryDefinition) {
97
+ const likelyNode = queryDefinition.definitions.find(
98
+ (def) => def.kind === "OperationDefinition"
99
+ );
100
+ return likelyNode?.name?.value;
101
+ }
102
+
103
+ // src/actions/clients/getApolloClient.ts
104
+ import { InMemoryCache } from "@apollo/client";
105
+ import { HttpLink } from "@apollo/client/link/http";
106
+ import { getUriFromLink } from "@berachain/config";
107
+ import { currentDapp, goldskyBaseUrl } from "@berachain/config/internal";
108
+ import apiResults from "@berachain/graphql/dex/api";
109
+ import { gql } from "@apollo/client";
110
+ function applyStellateClientName(url) {
111
+ const headers = typeof url === "string" ? void 0 : url.headers;
112
+ const isDapp = !!currentDapp;
113
+ const isTest = process.env.VERCEL_ENV === "test";
114
+ const uri = getUriFromLink(url);
115
+ const name = typeof url === "string" ? "unknown" : url.name;
116
+ return {
117
+ uri,
118
+ name,
119
+ headers: {
120
+ ...headers,
121
+ "x-graphql-client-name": `berachain.${isDapp ? "dapps" : isTest ? "test" : (
122
+ // this tracks usage of the berajs package in other packages
123
+ "berajs"
124
+ )}`,
125
+ "x-graphql-client-version": `${process.env.VERCEL_TARGET_ENV}.${process.env.VERCEL_GIT_COMMIT_SHA}`
126
+ }
127
+ };
128
+ }
129
+ function getClient(endpoint, {
130
+ ssrMode,
131
+ inMemoryCacheOptions
132
+ } = {}) {
133
+ const url = getUriFromLink(endpoint);
134
+ const headers = typeof endpoint === "string" ? void 0 : endpoint.headers;
135
+ let name = typeof endpoint === "string" ? void 0 : endpoint.name;
136
+ if (!name && url.includes(goldskyBaseUrl)) {
137
+ name = url.replace(goldskyBaseUrl, "").replace("/gn", "");
138
+ }
139
+ return new BeraApolloClient({
140
+ url,
141
+ name: name ?? "unknown",
142
+ link: new HttpLink({
143
+ uri: url,
144
+ headers
145
+ }),
146
+ defaultOptions: {
147
+ query: {
148
+ // With the default none error policy, an error causes the promise to reject.
149
+ errorPolicy: "none",
150
+ fetchPolicy: "no-cache"
151
+ }
152
+ },
153
+ cache: new InMemoryCache(inMemoryCacheOptions),
154
+ ssrMode
155
+ });
156
+ }
157
+ var SUBGRAPH_CLIENTS = [
158
+ "honey.subgraph",
159
+ "pol.subgraph"
160
+ ];
161
+ function isSubgraphClient(name) {
162
+ return SUBGRAPH_CLIENTS.includes(name);
163
+ }
164
+ var clientCache = /* @__PURE__ */ new Map();
165
+ function store(cacheKey, client) {
166
+ if (cacheKey) clientCache.set(cacheKey, client);
167
+ return client;
168
+ }
169
+ function getApolloClient(clientName, { ...args }) {
170
+ if (typeof window !== "undefined" && isSubgraphClient(clientName)) {
171
+ throw new BeraError({
172
+ message: "Subgraph Apollo client is server-only",
173
+ level: "error"
174
+ });
175
+ }
176
+ const { config, chainId } = parseBaseArgs(args);
177
+ const cacheKey = args.config ? null : `${chainId}:${clientName}`;
178
+ if (cacheKey) {
179
+ const cached = clientCache.get(cacheKey);
180
+ if (cached) return cached;
181
+ }
182
+ switch (clientName) {
183
+ case "api":
184
+ return store(
185
+ cacheKey,
186
+ getClient(applyStellateClientName(config.api), {
187
+ inMemoryCacheOptions: {
188
+ possibleTypes: apiResults.possibleTypes
189
+ }
190
+ })
191
+ );
192
+ case "bend.whisk":
193
+ if (!config.bend.whiskApi) {
194
+ throw new BeraError({
195
+ message: "Bend whisk API is not configured on this chain",
196
+ level: "error"
197
+ });
198
+ }
199
+ return store(cacheKey, getClient(config.bend.whiskApi));
200
+ case "honey.subgraph":
201
+ return store(cacheKey, getClient(config.honey.subgraph));
202
+ case "pol.subgraph":
203
+ return store(cacheKey, getClient(config.pol.subgraph));
204
+ }
205
+ }
206
+
207
+ export {
208
+ BeraApolloClient,
209
+ getApolloClient,
210
+ gql
211
+ };
@@ -0,0 +1,86 @@
1
+ import {
2
+ RequestError
3
+ } from "./chunk-ZLTMIFCZ.mjs";
4
+ import {
5
+ BeraError,
6
+ parseViemError
7
+ } from "./chunk-KHXJDYA4.mjs";
8
+
9
+ // src/errors/initBeraError.ts
10
+ import { BaseError } from "viem";
11
+ function initBeraError({
12
+ cause: error,
13
+ level
14
+ }) {
15
+ if (error instanceof BaseError) {
16
+ const parsed = parseViemError({
17
+ error,
18
+ revertIfUnknown: false
19
+ });
20
+ if (parsed.isRequestError && parsed.rootCause instanceof BaseError && "url" in parsed.rootCause && typeof parsed.rootCause.url === "string") {
21
+ return new RequestError({
22
+ cause: parsed.rootCause,
23
+ response: void 0,
24
+ endpoint: {
25
+ url: parsed.rootCause.url,
26
+ type: "rpc"
27
+ },
28
+ level
29
+ });
30
+ }
31
+ }
32
+ const err = error instanceof BeraError ? error : new BeraError({
33
+ cause: error,
34
+ level
35
+ });
36
+ return err;
37
+ }
38
+
39
+ // src/utils/createEmitter.ts
40
+ function createEmitter() {
41
+ const events = {};
42
+ return {
43
+ emit(event, ...args) {
44
+ for (const callback of events[event] || []) {
45
+ callback(...args);
46
+ }
47
+ },
48
+ events,
49
+ on(event, cb) {
50
+ if (!events[event]) {
51
+ events[event] = [];
52
+ }
53
+ events[event].push(cb);
54
+ return () => {
55
+ events[event] = events[event]?.filter((i) => cb !== i);
56
+ };
57
+ }
58
+ };
59
+ }
60
+
61
+ // src/errors/BeraMonitoring.ts
62
+ var _emitter = createEmitter();
63
+ var BeraMonitoring = {
64
+ /**
65
+ * Capture an exception. Notifies all subscribers.
66
+ */
67
+ captureException(exception) {
68
+ const event = {
69
+ exception,
70
+ timestamp: Date.now()
71
+ };
72
+ _emitter.emit("exception", event);
73
+ },
74
+ /**
75
+ * Subscribe to error events.
76
+ * @returns An unsubscribe function.
77
+ */
78
+ on(...args) {
79
+ return _emitter.on(...args);
80
+ }
81
+ };
82
+
83
+ export {
84
+ initBeraError,
85
+ BeraMonitoring
86
+ };