@berachain/berajs 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dist/{HoneyConfigProvider-Dkj-_a5x.d.ts → HoneyConfigProvider-COOuDNra.d.ts} +1 -1
  2. package/dist/actions/clients/exports.d.ts +5 -21
  3. package/dist/actions/clients/exports.mjs +5 -7
  4. package/dist/actions/exports.d.ts +117 -31
  5. package/dist/actions/exports.mjs +36 -25
  6. package/dist/actions/governance/exports.d.ts +3 -11
  7. package/dist/actions/server/exports.mjs +2 -2
  8. package/dist/chunk-4ML4Y6UN.mjs +46 -0
  9. package/dist/{chunk-7YVNSDXG.mjs → chunk-FGION6F6.mjs} +1 -1
  10. package/dist/{chunk-3JJLQ2JX.mjs → chunk-MKSFQIKC.mjs} +1 -4
  11. package/dist/{chunk-ZLTMIFCZ.mjs → chunk-RFJGL4MF.mjs} +3 -3
  12. package/dist/{chunk-Y6THHG77.mjs → chunk-T43JPYQS.mjs} +1 -1
  13. package/dist/{chunk-WNBWX23Q.mjs → chunk-W2VODV76.mjs} +7 -10
  14. package/dist/{chunk-QBBOWFMH.mjs → chunk-XDG26EG6.mjs} +115 -162
  15. package/dist/{chunk-P5WXXULM.mjs → chunk-YLTWPFCJ.mjs} +3 -18
  16. package/dist/contexts/exports.d.ts +2 -2
  17. package/dist/contexts/exports.mjs +6 -4
  18. package/dist/enum/exports.d.ts +8 -2
  19. package/dist/errors/exports.mjs +2 -2
  20. package/dist/{getApolloClient-BcUTGFUb.d.ts → getApolloClient-MWm_iq4u.d.ts} +4 -5
  21. package/dist/getProposalVotes-DAUrdX2n.d.ts +12 -0
  22. package/dist/{getValidatorQueuedOperatorAddress-DphU3qhE.d.ts → getValidatorQueuedOperatorAddress-Cc05dlO3.d.ts} +8 -59
  23. package/dist/{global.d-BuGDKh4k.d.ts → global.d-CR3zicga.d.ts} +3 -10
  24. package/dist/hooks/exports.d.ts +145 -403
  25. package/dist/hooks/exports.mjs +496 -755
  26. package/dist/hooks/governance/exports.d.ts +24 -19
  27. package/dist/hooks/governance/exports.mjs +43 -53
  28. package/dist/{pol.d-Dw5SQcRX.d.ts → pol.d-CeRgXBL8.d.ts} +18 -4
  29. package/dist/types/exports.d.ts +5 -5
  30. package/dist/{useHoneySwapState-vFmuFF0g.d.ts → useHoneySwapState-twi7NTaO.d.ts} +1 -1
  31. package/dist/utils/exports.d.ts +2 -2
  32. package/dist/utils/exports.mjs +6 -2
  33. package/package.json +8 -7
  34. package/src/actions/bend/getMaxDeposit.ts +28 -2
  35. package/src/actions/clients/exports.ts +0 -1
  36. package/src/actions/clients/fetchBeep.ts +0 -7
  37. package/src/actions/clients/fetchOpenApi.ts +10 -6
  38. package/src/actions/clients/fetchOpenApi.unit.test.ts +20 -14
  39. package/src/actions/clients/getApolloClient.ts +4 -9
  40. package/src/actions/exports.ts +1 -1
  41. package/src/actions/honey/getChartData.ts +14 -14
  42. package/src/actions/honey/getHoney24hVolume.ts +17 -8
  43. package/src/actions/honey/getHoneyTxns.ts +45 -0
  44. package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +3 -3
  45. package/src/actions/pol/getEarnedStakedBeraVault.ts +0 -15
  46. package/src/actions/pol/getGlobalData.ts +10 -29
  47. package/src/actions/pol/getRewardVaults.ts +4 -4
  48. package/src/actions/pol/getSWBeraVaultMetadata.ts +0 -7
  49. package/src/actions/pol/getStakingDailyAssets.ts +0 -14
  50. package/src/actions/validators/getApiEnrichedAllocation.ts +1 -1
  51. package/src/actions/validators/getValidatorIncentiveDistribution.ts +43 -13
  52. package/src/contexts/SwrFallback.tsx +2 -1
  53. package/src/data/contracts.ts +4 -0
  54. package/src/errors/RequestError.ts +3 -3
  55. package/src/errors/getRevertReason.integration.test.ts +5 -1
  56. package/src/hooks/bend/useGetConvertToAssets.ts +3 -11
  57. package/src/hooks/dex/useAggregatorsQuotes.ts +13 -11
  58. package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +2 -7
  59. package/src/hooks/dex/useAllUserPools.ts +8 -13
  60. package/src/hooks/dex/useApiPool.ts +2 -9
  61. package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +1 -2
  62. package/src/hooks/dex/useOnChainPoolData.ts +3 -4
  63. package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +3 -9
  64. package/src/hooks/dex/usePoolEvents.ts +1 -2
  65. package/src/hooks/dex/usePoolHistoricalData.ts +3 -9
  66. package/src/hooks/dex/usePools.ts +6 -4
  67. package/src/hooks/dex/useSingleAggregatorQuote.ts +6 -18
  68. package/src/hooks/enso/useBendDemultiply.ts +3 -4
  69. package/src/hooks/enso/useBendMultiply.ts +3 -4
  70. package/src/hooks/enso/useBendZapSupply.ts +4 -5
  71. package/src/hooks/enso/useEnsoSwapBundle.ts +2 -2
  72. package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +4 -10
  73. package/src/hooks/enso/useEnsoWalletV2Address.ts +1 -1
  74. package/src/hooks/enso/useIsBendAuthorized.ts +1 -1
  75. package/src/hooks/enso/useZapStakeBera.ts +2 -5
  76. package/src/hooks/exports.ts +1 -0
  77. package/src/hooks/governance/useGetPastVotes.ts +1 -1
  78. package/src/hooks/governance/useHasVoted.ts +1 -1
  79. package/src/hooks/governance/useIsCanceller.ts +1 -1
  80. package/src/hooks/governance/usePollAllProposals.ts +13 -12
  81. package/src/hooks/governance/usePollProposal.ts +7 -10
  82. package/src/hooks/governance/usePollProposalThreshold.ts +2 -7
  83. package/src/hooks/governance/usePollProposalVotes.ts +23 -5
  84. package/src/hooks/governance/usePollUserDelegates.ts +4 -9
  85. package/src/hooks/governance/useProposalFromTx.ts +4 -5
  86. package/src/hooks/governance/useProposalSnapshot.ts +3 -4
  87. package/src/hooks/governance/useProposalState.ts +3 -3
  88. package/src/hooks/governance/useProposalTimelockState.ts +3 -2
  89. package/src/hooks/governance/useQuorum.ts +1 -2
  90. package/src/hooks/honey/useCappedGlobally.ts +4 -12
  91. package/src/hooks/honey/useCappedRelatively.ts +3 -8
  92. package/src/hooks/honey/useCollateralWeights.ts +4 -9
  93. package/src/hooks/honey/useHoney24hVolume.ts +2 -6
  94. package/src/hooks/honey/useHoneyBalances.ts +2 -7
  95. package/src/hooks/honey/useHoneyChartData.ts +4 -12
  96. package/src/hooks/honey/useHoneyVaultsBalance.ts +3 -9
  97. package/src/hooks/honey/useIsBadCollateralAsset.ts +5 -13
  98. package/src/hooks/honey/useIsBasketModeEnabled.ts +5 -13
  99. package/src/hooks/honey/usePythLatestPrices.ts +15 -13
  100. package/src/hooks/perps/usePythUpdateFee.ts +13 -11
  101. package/src/hooks/pol/useAutoclaimedIncentives.ts +2 -8
  102. package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +2 -8
  103. package/src/hooks/pol/useBgtIncentiveDistributorPaused.ts +34 -0
  104. package/src/hooks/pol/useBgtUnstakedBalance.ts +3 -8
  105. package/src/hooks/pol/useClaimableFees.ts +2 -6
  106. package/src/hooks/pol/useHighestVaultsAPR.ts +6 -11
  107. package/src/hooks/pol/useOnChainRewardVault.ts +77 -72
  108. package/src/hooks/pol/usePollGlobalData.ts +3 -9
  109. package/src/hooks/pol/usePollMarkets.ts +3 -8
  110. package/src/hooks/pol/useQueuedBeraUnlock.ts +3 -12
  111. package/src/hooks/pol/useRewardTokenToBeraRate.ts +2 -2
  112. package/src/hooks/pol/useRewardVault.ts +9 -8
  113. package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +6 -6
  114. package/src/hooks/pol/useRewardVaultFromToken.ts +24 -30
  115. package/src/hooks/pol/useRewardVaultIncentives.ts +2 -7
  116. package/src/hooks/pol/useRewardVaultRewards.ts +3 -8
  117. package/src/hooks/pol/useRewardVaults.ts +4 -12
  118. package/src/hooks/pol/useStakedAPR.ts +2 -8
  119. package/src/hooks/pol/useStakedData.ts +90 -41
  120. package/src/hooks/pol/useStakedSnapshots.ts +4 -9
  121. package/src/hooks/pol/useStakingVaultsMetadata.ts +1 -1
  122. package/src/hooks/pol/useTotalStakedAmount.ts +2 -8
  123. package/src/hooks/pol/useUserVaultInfo.ts +3 -8
  124. package/src/hooks/pol/useUserVaults.ts +3 -8
  125. package/src/hooks/pol/useVaultAddress.ts +1 -1
  126. package/src/hooks/pol/useVaultHistory.ts +2 -8
  127. package/src/hooks/pol/useVaultValidators.ts +3 -8
  128. package/src/hooks/tokens/useMultipleTokenInformation.ts +3 -8
  129. package/src/hooks/tokens/usePollAllowances.ts +4 -11
  130. package/src/hooks/tokens/usePollBalance.ts +2 -5
  131. package/src/hooks/tokens/usePollWalletBalances.ts +3 -3
  132. package/src/hooks/tokens/useStakingTokenInformation.ts +3 -12
  133. package/src/hooks/tokens/useTokenCurrentPrices.ts +11 -13
  134. package/src/hooks/tokens/useTokenInformation.ts +3 -8
  135. package/src/hooks/tokens/useTokenPrice.ts +2 -1
  136. package/src/hooks/tokens/useTokenPrices.ts +3 -4
  137. package/src/hooks/tokens/useTotalSupply.ts +1 -1
  138. package/src/hooks/tokens/useUnderlyingAsset.ts +1 -2
  139. package/src/hooks/useBlockToTimestamp.ts +1 -2
  140. package/src/hooks/useGetVerifiedAbi.ts +2 -1
  141. package/src/hooks/validators/useAllValidators.ts +3 -9
  142. package/src/hooks/validators/useApiEnrichedAllocation.ts +1 -1
  143. package/src/hooks/validators/useApiValidator.ts +4 -12
  144. package/src/hooks/validators/useBaselineRewardAllocation.ts +1 -2
  145. package/src/hooks/validators/useDailyValidatorBlockStats.ts +2 -4
  146. package/src/hooks/validators/useDefaultRewardAllocation.ts +3 -9
  147. package/src/hooks/validators/useManagedValidatorRole.ts +2 -3
  148. package/src/hooks/validators/useOnChainValidator.ts +4 -11
  149. package/src/hooks/validators/useStakingPoolBatch.ts +4 -10
  150. package/src/hooks/validators/useUserActiveValidators.ts +3 -9
  151. package/src/hooks/validators/useUserBoostsOnValidator.ts +2 -4
  152. package/src/hooks/validators/useUserClaimableIncentives.ts +3 -3
  153. package/src/hooks/validators/useUserStakingPositions.ts +3 -9
  154. package/src/hooks/validators/useValidatorAnalytics.ts +2 -4
  155. package/src/hooks/validators/useValidatorCommission.ts +3 -8
  156. package/src/hooks/validators/useValidatorIncentiveDistribution.ts +4 -6
  157. package/src/hooks/validators/useValidatorQueuedCommission.ts +3 -8
  158. package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +3 -8
  159. package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +3 -8
  160. package/src/hooks/validators/useValidatorRewardAllocation.ts +3 -8
  161. package/src/types/global.d.ts +7 -10
  162. package/src/types/pol.d.ts +17 -3
  163. package/dist/polling-BKnyavLI.d.ts +0 -8
  164. package/src/actions/clients/fetchRailwayBackend.ts +0 -34
  165. package/src/actions/pol/getGlobalCuttingBoard.ts +0 -25
  166. package/src/actions/pol/getIncentiveFeeClaimStats.ts +0 -24
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import { usePublicClient } from "@berachain/wagmi/hooks";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import { isBasketModeEnabled } from "../../actions/honey/isBasketModeEnabled";
6
5
  import { useHoneyConfig } from "../../contexts/HoneyConfigProvider";
@@ -24,9 +23,7 @@ export function useIsBasketModeEnabled(
24
23
  priceFeedMap,
25
24
  },
26
25
  {
27
- opts: {
28
- isEnabled: flags.isPythWrapperEnabled && !!collateralList.length,
29
- },
26
+ isEnabled: flags.isPythWrapperEnabled && !!collateralList.length,
30
27
  },
31
28
  );
32
29
  const isMint = state.actionType === "mint";
@@ -45,7 +42,7 @@ export function useIsBasketModeEnabled(
45
42
  ] as const)
46
43
  : null;
47
44
 
48
- const swrResponse = useSWR(
45
+ return useSWR(
49
46
  QUERY_KEY,
50
47
  async ([_, isMint, latestPrices, isPythWrapperEnabled, collateralList]) => {
51
48
  assertPublicClient(publicClient);
@@ -61,13 +58,8 @@ export function useIsBasketModeEnabled(
61
58
  return isActive;
62
59
  },
63
60
  {
64
- ...options?.opts,
65
- refreshInterval: options?.opts?.refreshInterval ?? POLLING.FAST,
61
+ ...options,
62
+ refreshInterval: options?.refreshInterval ?? POLLING.FAST,
66
63
  },
67
64
  );
68
- return {
69
- ...swrResponse,
70
- data: swrResponse.data,
71
- refresh: () => void swrResponse.mutate(),
72
- };
73
65
  }
@@ -1,4 +1,5 @@
1
- import useSWR, { type SWRResponse } from "swr";
1
+ import type { BeraSwrResponse } from "@berachain/utils/pkg/swr";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
2
3
 
3
4
  import type { PythLatestUpdates } from "../../actions/honey/getPythLatestPrices";
4
5
  import { getPythLatestPrices } from "../../actions/honey/getPythLatestPrices";
@@ -9,7 +10,7 @@ import type { PythPriceFeedMap } from "../../types/honeySwap";
9
10
  * Hook to fetch the latest Pyth price updates for specified pair addresses
10
11
  * @param {Object} params - The parameters object
11
12
  * @param {Address[] | undefined} params.pairMainAddress - Array of pair addresses to fetch price updates for
12
- * @returns {SWRResponse<PythLatestUpdates>} SWR response containing the latest Pyth price updates
13
+ * @returns {BeraSwrResponse<PythLatestUpdates>} SWR response containing the latest Pyth price updates
13
14
  * @example
14
15
  * ```ts
15
16
  * const { data, error } = usePythLatestPrices({
@@ -24,18 +25,19 @@ export function usePythLatestPrices(
24
25
  priceFeedMap: PythPriceFeedMap | undefined;
25
26
  },
26
27
  options?: DefaultHookOptions,
27
- ): SWRResponse<PythLatestUpdates> {
28
+ ): BeraSwrResponse<PythLatestUpdates> {
28
29
  const priceFeedIds = priceFeedMap ? Object.values(priceFeedMap) : null;
29
30
 
30
- const QUERY_KEY =
31
- (options?.opts?.isEnabled ?? true) && priceFeedIds
32
- ? (["usePythLatestPrices", priceFeedIds] as const)
33
- : null;
31
+ const QUERY_KEY = priceFeedIds
32
+ ? (["usePythLatestPrices", priceFeedIds] as const)
33
+ : null;
34
34
 
35
- const swrResponse = useSWR(QUERY_KEY, async ([_, priceFeeds]) => {
36
- const data = await getPythLatestPrices({ priceFeedId: priceFeeds });
37
- return data;
38
- });
39
-
40
- return swrResponse;
35
+ return useSWR(
36
+ QUERY_KEY,
37
+ async ([_, priceFeeds]) => {
38
+ const data = await getPythLatestPrices({ priceFeedId: priceFeeds });
39
+ return data;
40
+ },
41
+ options,
42
+ );
41
43
  }
@@ -1,7 +1,7 @@
1
- import useSWRImmutable from "swr/immutable";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWRImmutable } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getPythUpdateFee } from "../../actions/pyth/getUpdateFee";
7
7
  import { assertPublicClient } from "../../errors/assert";
@@ -20,20 +20,22 @@ export const usePythUpdateFee = (
20
20
  ) => {
21
21
  const publicClient = usePublicClient();
22
22
  const QUERY_KEY =
23
- (options?.opts?.isEnabled ?? true) &&
24
- pythPriceFeedCalldata &&
25
- pythPriceFeedCalldata.length > 0
23
+ pythPriceFeedCalldata && pythPriceFeedCalldata.length > 0
26
24
  ? (["usePythUpdateFee", pythPriceFeedCalldata] as const)
27
25
  : null;
28
26
  const { data = getPythDefaultUpdateFee(tokenListLength), isLoading } =
29
- useSWRImmutable(QUERY_KEY, async ([_, pythPriceFeedCalldata]) => {
30
- assertPublicClient(publicClient);
27
+ useSWRImmutable(
28
+ QUERY_KEY,
29
+ async ([_, pythPriceFeedCalldata]) => {
30
+ assertPublicClient(publicClient);
31
31
 
32
- return getPythUpdateFee({
33
- client: publicClient,
34
- priceFeedId: pythPriceFeedCalldata,
35
- });
36
- });
32
+ return getPythUpdateFee({
33
+ client: publicClient,
34
+ priceFeedId: pythPriceFeedCalldata,
35
+ });
36
+ },
37
+ options,
38
+ );
37
39
 
38
40
  return {
39
41
  QUERY_KEY,
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import { useBeraWallet } from "@berachain/wagmi/hooks";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import { getAutoclaimedIncentives } from "../../actions/pol/getAutoclaimedIncentives";
6
5
  import type { AutoclaimedIncentivesResponse } from "../../types/bribe-boost";
@@ -23,7 +22,7 @@ export function useAutoclaimedIncentives({
23
22
  ? (["useAutoclaimedIncentives", account] as const)
24
23
  : null;
25
24
 
26
- const swrResponse = useSWR(
25
+ return useSWR(
27
26
  QUERY_KEY,
28
27
  async ([, account]) => getAutoclaimedIncentives({ account }),
29
28
  {
@@ -32,9 +31,4 @@ export function useAutoclaimedIncentives({
32
31
  revalidateIfStale: false,
33
32
  },
34
33
  );
35
-
36
- return {
37
- ...swrResponse,
38
- refresh: () => swrResponse?.mutate?.(),
39
- };
40
34
  }
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import { useBeraWallet } from "@berachain/wagmi/hooks";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import { getAutoclaimedIncentivesTxHash } from "../../actions/pol/getAutoclaimedIncentivesTxHash";
6
5
  import { POLLING } from "../../enum/polling";
@@ -23,7 +22,7 @@ export function useAutoclaimedIncentivesTxHash({
23
22
  ? (["useAutoclaimedIncentivesTxHash", account] as const)
24
23
  : null;
25
24
 
26
- const swrResponse = useSWR(
25
+ return useSWR(
27
26
  QUERY_KEY,
28
27
  async ([, account]) => getAutoclaimedIncentivesTxHash({ account }),
29
28
  {
@@ -37,9 +36,4 @@ export function useAutoclaimedIncentivesTxHash({
37
36
  revalidateIfStale: false,
38
37
  },
39
38
  );
40
-
41
- return {
42
- ...swrResponse,
43
- refresh: () => swrResponse?.mutate?.(),
44
- };
45
39
  }
@@ -0,0 +1,34 @@
1
+ import { usePublicClient } from "@berachain/wagmi/hooks";
2
+ import useSWR from "@berachain/utils/pkg/swr";
3
+
4
+ import { getBgtIncentiveDistributorPaused } from "../../actions/pol/getBgtIncentiveDistributorPaused";
5
+ import type {
6
+ DefaultHookOptions,
7
+ DefaultHookReturnType,
8
+ } from "../../types/global";
9
+
10
+ /**
11
+ * Client hook around `getBgtIncentiveDistributorPaused`. When `paused()` is
12
+ * true, users can no longer self-claim incentives and the bot distributes them
13
+ * on their behalf. Fails closed (`false`) so a read error never blocks the UI.
14
+ */
15
+ export function useBgtIncentiveDistributorPaused(
16
+ options?: DefaultHookOptions,
17
+ ): DefaultHookReturnType<boolean> {
18
+ const publicClient = usePublicClient();
19
+
20
+ const QUERY_KEY = publicClient
21
+ ? (["useBgtIncentiveDistributorPaused", publicClient.chain?.id] as const)
22
+ : null;
23
+
24
+ return useSWR(
25
+ QUERY_KEY,
26
+ async () =>
27
+ getBgtIncentiveDistributorPaused({ publicClient }).catch(() => false),
28
+ {
29
+ revalidateOnFocus: false,
30
+ revalidateOnReconnect: false,
31
+ ...options,
32
+ },
33
+ );
34
+ }
@@ -1,9 +1,9 @@
1
- import useSWR from "swr";
2
1
  import { formatEther } from "viem";
3
2
 
4
3
  import { bgtAbi } from "@berachain/abis/pol/bgt";
5
4
 
6
5
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
6
+ import { useSWR } from "@berachain/utils/pkg/swr";
7
7
 
8
8
  import { POLLING } from "../../enum/polling";
9
9
  import { assertPublicClient } from "../../errors/assert";
@@ -24,7 +24,7 @@ export const useBgtUnstakedBalance = (
24
24
  ? (["useBgtUnstakedBalance", account] as const)
25
25
  : null;
26
26
 
27
- const swrResponse = useSWR(
27
+ return useSWR(
28
28
  QUERY_KEY,
29
29
  async ([, account]) => {
30
30
  assertPublicClient(publicClient);
@@ -43,12 +43,7 @@ export const useBgtUnstakedBalance = (
43
43
  },
44
44
  {
45
45
  ...options,
46
- refreshInterval: options?.opts?.refreshInterval ?? POLLING.NORMAL,
46
+ refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
47
47
  },
48
48
  );
49
-
50
- return {
51
- ...swrResponse,
52
- refresh: () => swrResponse.mutate(),
53
- };
54
49
  };
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import { formatUnits } from "viem";
3
2
 
4
3
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getUserVaultsReward } from "../../actions/pol/getUserVaultsReward";
7
7
  import { POLLING } from "../../enum/polling";
@@ -13,7 +13,7 @@ export const useClaimableFees = () => {
13
13
  const publicClient = usePublicClient();
14
14
  const QUERY_KEY =
15
15
  account && publicClient ? (["useClaimableFees", account] as const) : null;
16
- const swrResponse = useSWR(
16
+ return useSWR(
17
17
  QUERY_KEY,
18
18
  async ([, account]) => {
19
19
  assertPublicClient(publicClient);
@@ -31,8 +31,4 @@ export const useClaimableFees = () => {
31
31
  refreshInterval: POLLING.SLOW * 2,
32
32
  },
33
33
  );
34
- return {
35
- ...swrResponse,
36
- refresh: () => swrResponse?.mutate?.(),
37
- };
38
34
  };
@@ -14,8 +14,7 @@ import { useRewardVaults } from "./useRewardVaults";
14
14
  *
15
15
  * @returns {Object} An object containing:
16
16
  * - highestApr: The highest APR value from the reward vaults
17
- * - refresh: Function to manually refresh the data
18
- * - ...swrResponse: All properties from the underlying SWR response
17
+ * - isLoading: Loading state
19
18
  *
20
19
  * @example
21
20
  * const { highestApr } = useHighestVaultsAPR({
@@ -28,7 +27,6 @@ export const useHighestVaultsAPR = (
28
27
  ): {
29
28
  highestApr: GqlRewardVaultDynamicData["apr"] | undefined;
30
29
  isLoading: boolean;
31
- refresh: () => void;
32
30
  } => {
33
31
  const swrResponse = useRewardVaults(
34
32
  {
@@ -40,18 +38,15 @@ export const useHighestVaultsAPR = (
40
38
  },
41
39
  },
42
40
  {
43
- opts: {
44
- refreshInterval: 0,
45
- revalidateOnFocus: false,
46
- refreshWhenOffline: false,
47
- isEnabled,
48
- },
41
+ refreshInterval: 0,
42
+ revalidateOnFocus: false,
43
+ refreshWhenOffline: false,
44
+ isEnabled,
49
45
  },
50
46
  );
51
47
 
52
48
  return {
53
49
  isLoading: swrResponse.isLoading,
54
- highestApr: swrResponse.data?.gaugeList[0].dynamicData?.apr,
55
- refresh: swrResponse.mutate,
50
+ highestApr: swrResponse.data?.rewardVaultList[0].dynamicData?.apr,
56
51
  };
57
52
  };
@@ -1,10 +1,10 @@
1
- import useSWR from "swr";
2
1
  import { type Address, erc20Abi, formatUnits, isAddress } from "viem";
3
2
 
4
3
  import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
5
4
 
6
5
  import type { ApiVaultFragment } from "@berachain/graphql/pol/api";
7
6
  import { usePublicClient } from "@berachain/wagmi/hooks";
7
+ import { useSWR } from "@berachain/utils/pkg/swr";
8
8
 
9
9
  import { getRewardVaultIncentives } from "../../actions/pol/getRewardVaultIncentives";
10
10
  import { getRewardVaultStakingToken } from "../../actions/pol/getRewardVaultStakingToken";
@@ -28,7 +28,6 @@ export const useOnChainRewardVault = (
28
28
  opt: DefaultHookOptions,
29
29
  ) => {
30
30
  const publicClient = usePublicClient();
31
- const isEnabled = opt.opts?.isEnabled ?? true;
32
31
 
33
32
  const QUERY_KEY = useOnChainRewardVaultQueryKey(address);
34
33
 
@@ -36,81 +35,87 @@ export const useOnChainRewardVault = (
36
35
  ApiVaultFragment,
37
36
  unknown,
38
37
  ReturnType<typeof useOnChainRewardVaultQueryKey>
39
- >(isEnabled && publicClient ? QUERY_KEY : null, async ([, address]) => {
40
- assertPublicClient(publicClient);
41
- const { config } = parseBaseArgs({
42
- chainId: publicClient.chain.id,
43
- });
38
+ >(
39
+ publicClient ? QUERY_KEY : null,
40
+ async ([, address]) => {
41
+ assertPublicClient(publicClient);
42
+ const { config } = parseBaseArgs({
43
+ chainId: publicClient.chain.id,
44
+ });
44
45
 
45
- const stakingTokenAddress = await getRewardVaultStakingToken({
46
- address,
47
- publicClient: publicClient,
48
- });
49
-
50
- const [incentives, isWhitelisted, stakingTokenAmount] = await Promise.all([
51
- getRewardVaultIncentives({
46
+ const stakingTokenAddress = await getRewardVaultStakingToken({
52
47
  address,
53
- stakingToken: stakingTokenAddress,
54
- publicClient,
55
- }),
56
- publicClient.readContract({
57
- address: config.pol.beraChef,
58
- abi: beraChefAbi,
59
- functionName: "isWhitelistedVault",
60
- args: [address],
61
- }),
62
- publicClient.readContract({
63
- address: stakingTokenAddress,
64
- abi: erc20Abi,
65
- functionName: "balanceOf",
66
- args: [address],
67
- }),
68
- ]);
69
-
70
- const [stakingToken, incentiveTokens] = await Promise.all([
71
- getStakingTokenInformation({
72
- address: stakingTokenAddress,
73
48
  publicClient: publicClient,
74
- }),
75
- Promise.all(
76
- incentives.map((add) =>
77
- getTokenInformation({
78
- address: add.token,
79
- chainId: publicClient.chain.id,
80
- publicClient: publicClient,
49
+ });
50
+
51
+ const [incentives, isWhitelisted, stakingTokenAmount] = await Promise.all(
52
+ [
53
+ getRewardVaultIncentives({
54
+ address,
55
+ stakingToken: stakingTokenAddress,
56
+ publicClient,
57
+ }),
58
+ publicClient.readContract({
59
+ address: config.pol.beraChef,
60
+ abi: beraChefAbi,
61
+ functionName: "isWhitelistedVault",
62
+ args: [address],
81
63
  }),
64
+ publicClient.readContract({
65
+ address: stakingTokenAddress,
66
+ abi: erc20Abi,
67
+ functionName: "balanceOf",
68
+ args: [address],
69
+ }),
70
+ ],
71
+ );
72
+
73
+ const [stakingToken, incentiveTokens] = await Promise.all([
74
+ getStakingTokenInformation({
75
+ address: stakingTokenAddress,
76
+ publicClient: publicClient,
77
+ }),
78
+ Promise.all(
79
+ incentives.map((add) =>
80
+ getTokenInformation({
81
+ address: add.token,
82
+ chainId: publicClient.chain.id,
83
+ publicClient: publicClient,
84
+ }),
85
+ ),
82
86
  ),
83
- ),
84
- ]);
87
+ ]);
85
88
 
86
- if (!stakingToken) {
87
- throw new Error("Staking token not found");
88
- }
89
+ if (!stakingToken) {
90
+ throw new Error("Staking token not found");
91
+ }
89
92
 
90
- return {
91
- id: address,
92
- address,
93
- vaultAddress: address,
94
- stakingToken: {
95
- address: stakingTokenAddress,
96
- name: stakingToken.name ?? "",
97
- symbol: stakingToken.symbol ?? "",
98
- decimals: stakingToken.decimals ?? 0,
99
- },
100
- stakingTokenAmount: formatUnits(
101
- stakingTokenAmount,
102
- stakingToken.decimals ?? 18,
103
- ),
104
- isVaultWhitelisted: isWhitelisted,
105
- activeIncentives: incentives.map((incentive, idx) => ({
106
- active: !!incentive.remainingAmount,
107
- remainingAmount: incentive.remainingAmount,
108
- remainingAmountUsd: "0",
109
- incentiveRate: incentive.incentiveRate,
110
- incentiveRateUsd: "0",
111
- tokenAddress: incentive.token,
112
- token: incentiveTokens[idx]!,
113
- })),
114
- } satisfies ApiVaultFragment;
115
- });
93
+ return {
94
+ id: address,
95
+ address,
96
+ vaultAddress: address,
97
+ stakingToken: {
98
+ address: stakingTokenAddress,
99
+ name: stakingToken.name ?? "",
100
+ symbol: stakingToken.symbol ?? "",
101
+ decimals: stakingToken.decimals ?? 0,
102
+ },
103
+ stakingTokenAmount: formatUnits(
104
+ stakingTokenAmount,
105
+ stakingToken.decimals ?? 18,
106
+ ),
107
+ isVaultWhitelisted: isWhitelisted,
108
+ activeIncentives: incentives.map((incentive, idx) => ({
109
+ active: !!incentive.remainingAmount,
110
+ remainingAmount: incentive.remainingAmount,
111
+ remainingAmountUsd: "0",
112
+ incentiveRate: incentive.incentiveRate,
113
+ incentiveRateUsd: "0",
114
+ tokenAddress: incentive.token,
115
+ token: incentiveTokens[idx]!,
116
+ })),
117
+ } satisfies ApiVaultFragment;
118
+ },
119
+ opt,
120
+ );
116
121
  };
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import { usePublicClient } from "@berachain/wagmi/hooks";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import {
6
5
  type GlobalData,
@@ -17,7 +16,7 @@ export const usePollGlobalData = (
17
16
  ): DefaultHookReturnType<GlobalData> => {
18
17
  const publicClient = usePublicClient();
19
18
 
20
- const swrResponse = useSWR<GlobalData>(
19
+ return useSWR<GlobalData>(
21
20
  publicClient ? "usePollGlobalData" : null,
22
21
  async () => {
23
22
  assertPublicClient(publicClient);
@@ -26,12 +25,7 @@ export const usePollGlobalData = (
26
25
  },
27
26
  {
28
27
  revalidateOnFocus: false,
29
- ...options?.opts,
28
+ ...options,
30
29
  },
31
30
  );
32
-
33
- return {
34
- ...swrResponse,
35
- refresh: swrResponse.mutate,
36
- };
37
31
  };
@@ -1,4 +1,4 @@
1
- import useSWRImmutable from "swr/immutable";
1
+ import { useSWRImmutable } from "@berachain/utils/pkg/swr";
2
2
 
3
3
  import { type GetMarkets, getMarkets } from "../../actions/pol/getMarkets";
4
4
  import type {
@@ -17,19 +17,14 @@ export const usePollMarkets = (
17
17
  options?: DefaultHookOptions,
18
18
  ): UsePollMarketsResponse => {
19
19
  const QUERY_KEY = usePollMarketsQueryKey();
20
- const swrResponse = useSWRImmutable<GetMarkets, any, typeof QUERY_KEY>(
20
+ return useSWRImmutable<GetMarkets, any, typeof QUERY_KEY>(
21
21
  QUERY_KEY,
22
22
  async () => {
23
23
  const res = await getMarkets();
24
24
  return res;
25
25
  },
26
26
  {
27
- ...options?.opts,
27
+ ...options,
28
28
  },
29
29
  );
30
-
31
- return {
32
- ...swrResponse,
33
- refresh: () => swrResponse.mutate(),
34
- };
35
30
  };
@@ -1,7 +1,7 @@
1
- import useSWRImmutable from "swr/immutable";
2
1
  import { type Address, isAddress } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWRImmutable } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import {
7
7
  getSWBeraWithdrawal,
@@ -39,11 +39,7 @@ export function useQueuedBeraUnlock(
39
39
  ] as const)
40
40
  : null;
41
41
 
42
- const swrResponse = useSWRImmutable<
43
- StakedBeraWithdrawal[],
44
- any,
45
- typeof QUERY_KEY
46
- >(
42
+ return useSWRImmutable<StakedBeraWithdrawal[], any, typeof QUERY_KEY>(
47
43
  QUERY_KEY,
48
44
  async ([, receiptTokenAddresses, account, version]) => {
49
45
  assertPublicClient(publicClient);
@@ -61,12 +57,7 @@ export function useQueuedBeraUnlock(
61
57
  },
62
58
  {
63
59
  refreshInterval: POLLING.FAST,
64
- ...options?.opts,
60
+ ...options,
65
61
  },
66
62
  );
67
-
68
- return {
69
- ...swrResponse,
70
- refresh: () => swrResponse.mutate(),
71
- };
72
63
  }
@@ -1,9 +1,9 @@
1
- import useSWR from "swr";
2
1
  import { type Address, isAddress } from "viem";
3
2
 
4
3
  import { defaultChainId } from "@berachain/config/internal";
5
4
 
6
5
  import { usePublicClient } from "@berachain/wagmi/hooks";
6
+ import { useSWR } from "@berachain/utils/pkg/swr";
7
7
 
8
8
  import { getRewardTokenToBeraRate } from "../../actions/pol/getRewardTokenToBeraRate";
9
9
  import { assertPublicClient } from "../../errors/assert";
@@ -42,7 +42,7 @@ export const useRewardTokenToBeraRate = (
42
42
  });
43
43
  },
44
44
  {
45
- ...opt?.opts,
45
+ ...opt,
46
46
  },
47
47
  );
48
48
  };
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import type { ApiVaultFragment } from "@berachain/graphql/pol/api";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getRewardVault } from "../../actions/pol/getRewardVault";
7
7
  import type {
@@ -24,21 +24,22 @@ export const useRewardVault = (
24
24
  ): UseRewardVaultResponse => {
25
25
  const QUERY_KEY = useRewardVaultQueryKey(id);
26
26
 
27
+ // The off-chain fetch is intentionally always enabled; `isEnabled` only gates
28
+ // the on-chain fallback below, so it is stripped from this call's options.
29
+ const { isEnabled: _isEnabled, ...swrOptions } = options ?? {};
27
30
  const swrResponse = useSWR(
28
31
  QUERY_KEY,
29
32
  async ([_, id]) => getRewardVault({ address: id }),
30
- {
31
- ...options?.opts,
32
- },
33
+ swrOptions,
33
34
  );
34
35
 
35
36
  const isOnChainEnabled =
36
- options?.opts?.isEnabled ??
37
+ options?.isEnabled ??
37
38
  ((!!swrResponse.error || !swrResponse.isLoading) && !swrResponse.data);
38
39
 
39
40
  const onChainRewardVault = useOnChainRewardVault(
40
41
  { address: id },
41
- { opts: { ...options?.opts, isEnabled: isOnChainEnabled } },
42
+ { ...options, isEnabled: isOnChainEnabled },
42
43
  );
43
44
 
44
45
  return {
@@ -47,8 +48,8 @@ export const useRewardVault = (
47
48
  isLoading: onChainRewardVault.isLoading || swrResponse.isLoading,
48
49
  isValidating: onChainRewardVault.isValidating ?? swrResponse.isValidating,
49
50
  refresh: () => {
50
- swrResponse.mutate();
51
- onChainRewardVault.mutate();
51
+ swrResponse.refresh();
52
+ onChainRewardVault.refresh();
52
53
  },
53
54
  };
54
55
  };