@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,9 +1,9 @@
1
- import useSWR from "swr";
2
1
  import { type Address, isAddress, zeroAddress } from "viem";
3
2
 
4
3
  import { rewardVaultAbi } from "@berachain/abis/pol/rewards/rewardVault";
5
4
 
6
5
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
6
+ import { useSWR } from "@berachain/utils/pkg/swr";
7
7
 
8
8
  import { assertPublicClient } from "../../errors/assert";
9
9
  import type { DefaultHookOptions } from "../../types/global";
@@ -23,11 +23,11 @@ export const useRewardVaultBalanceFromStakingToken = (
23
23
  const { address: account } = useBeraWallet();
24
24
  const publicClient = usePublicClient();
25
25
 
26
- const isEnabled = options?.opts?.isEnabled ?? true;
26
+ const isEnabled = options?.isEnabled ?? true;
27
27
  const {
28
28
  data: rewardVaultAddress = _rewardVaultAddress,
29
29
  error,
30
- mutate: mutateRewardVaultAddress,
30
+ refresh: mutateRewardVaultAddress,
31
31
  isLoading: isLoadingRewardVaultAddress,
32
32
  } = useRewardVaultFromToken(
33
33
  {
@@ -43,8 +43,7 @@ export const useRewardVaultBalanceFromStakingToken = (
43
43
  account &&
44
44
  publicClient &&
45
45
  isAddress(rewardVaultAddress) &&
46
- isAddress(account) &&
47
- isEnabled
46
+ isAddress(account)
48
47
  ? ["useVaultBalanceFromStakingToken", rewardVaultAddress, account]
49
48
  : null,
50
49
 
@@ -70,13 +69,14 @@ export const useRewardVaultBalanceFromStakingToken = (
70
69
  balance: balance,
71
70
  };
72
71
  },
72
+ options,
73
73
  );
74
74
 
75
75
  return {
76
76
  ...swrResponse,
77
77
  refresh: () => {
78
78
  mutateRewardVaultAddress();
79
- swrResponse.mutate();
79
+ swrResponse.refresh();
80
80
  },
81
81
  isLoading: swrResponse.isLoading || isLoadingRewardVaultAddress,
82
82
  };
@@ -1,9 +1,9 @@
1
- import useSWRImmutable from "swr/immutable";
2
1
  import { type Address, isAddress, zeroAddress } from "viem";
3
2
 
4
3
  import { rewardVaultFactoryAbi } from "@berachain/abis/pol/rewards/rewardVaultFactory";
5
4
 
6
5
  import { usePublicClient } from "@berachain/wagmi/hooks";
6
+ import { useSWRImmutable } from "@berachain/utils/pkg/swr";
7
7
 
8
8
  import { assertPublicClient } from "../../errors/assert";
9
9
  import { parseBaseArgs } from "../../utils/parseBaseArgs";
@@ -27,33 +27,27 @@ export const useRewardVaultFromToken = (
27
27
  ? ["useRewardVaultFromToken", tokenAddress]
28
28
  : null;
29
29
 
30
- const swrResponse = useSWRImmutable<
31
- Address | undefined,
32
- any,
33
- typeof QUERY_KEY
34
- >(QUERY_KEY, async ([, tokenAddress]) => {
35
- if (!tokenAddress) {
36
- throw new Error("useRewardVaultFromToken needs a valid token address");
37
- }
38
-
39
- assertPublicClient(publicClient);
40
-
41
- const { config } = parseBaseArgs({
42
- chainId: publicClient.chain.id,
43
- });
44
-
45
- const res = await publicClient.readContract({
46
- address: config.pol.factory,
47
- abi: rewardVaultFactoryAbi,
48
- functionName: "getVault",
49
- args: [tokenAddress],
50
- });
51
-
52
- return res === zeroAddress ? undefined : res;
53
- });
54
-
55
- return {
56
- ...swrResponse,
57
- refresh: () => swrResponse.mutate(),
58
- };
30
+ return useSWRImmutable<Address | undefined, any, typeof QUERY_KEY>(
31
+ QUERY_KEY,
32
+ async ([, tokenAddress]) => {
33
+ if (!tokenAddress) {
34
+ throw new Error("useRewardVaultFromToken needs a valid token address");
35
+ }
36
+
37
+ assertPublicClient(publicClient);
38
+
39
+ const { config } = parseBaseArgs({
40
+ chainId: publicClient.chain.id,
41
+ });
42
+
43
+ const res = await publicClient.readContract({
44
+ address: config.pol.factory,
45
+ abi: rewardVaultFactoryAbi,
46
+ functionName: "getVault",
47
+ args: [tokenAddress],
48
+ });
49
+
50
+ return res === zeroAddress ? undefined : res;
51
+ },
52
+ );
59
53
  };
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getRewardVaultIncentives } from "../../actions/pol/getRewardVaultIncentives";
7
7
  import { assertPublicClient } from "../../errors/assert";
@@ -20,7 +20,7 @@ export function useRewardVaultIncentives({
20
20
  ? (["useRewardVaultIncentives", address, stakingToken] as const)
21
21
  : null;
22
22
 
23
- const swrResponse = useSWR(QUERY_KEY, async ([, address, stakingToken]) => {
23
+ return useSWR(QUERY_KEY, async ([, address, stakingToken]) => {
24
24
  assertPublicClient(publicClient);
25
25
 
26
26
  return await getRewardVaultIncentives({
@@ -29,9 +29,4 @@ export function useRewardVaultIncentives({
29
29
  publicClient,
30
30
  });
31
31
  });
32
-
33
- return {
34
- ...swrResponse,
35
- refresh: () => swrResponse?.mutate?.(),
36
- };
37
32
  }
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getRewardVaultRewards } from "../../actions/pol/getRewardVaultRewards";
7
7
  import { assertPublicClient } from "../../errors/assert";
@@ -18,7 +18,7 @@ export const useRewardVaultRewards = (
18
18
  ? (["useRewardVaultRewards", address] as const)
19
19
  : null;
20
20
 
21
- const swrResponse = useSWR(
21
+ return useSWR(
22
22
  QUERY_KEY,
23
23
  async ([, address]) => {
24
24
  assertPublicClient(publicClient);
@@ -26,12 +26,7 @@ export const useRewardVaultRewards = (
26
26
  return await getRewardVaultRewards(address, publicClient);
27
27
  },
28
28
  {
29
- ...options?.opts,
29
+ ...options,
30
30
  },
31
31
  );
32
-
33
- return {
34
- ...swrResponse,
35
- refresh: () => swrResponse?.mutate?.(),
36
- };
37
32
  };
@@ -1,7 +1,6 @@
1
- import useSWR from "swr";
2
-
3
1
  import type { GetVaultsQueryVariables } from "@berachain/graphql/pol/api";
4
2
  import { usePublicClient } from "@berachain/wagmi/hooks";
3
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
4
 
6
5
  import { getRewardVaults } from "../../actions/pol/getRewardVaults";
7
6
  import type { DefaultHookOptions } from "../../types/global";
@@ -25,21 +24,14 @@ export const useRewardVaults = (
25
24
  args.onChainIncentives,
26
25
  );
27
26
  const publicClient = usePublicClient();
28
- const swrResponse = useSWR(
29
- (options?.opts?.isEnabled ?? true) ? QUERY_KEY : null,
27
+ return useSWR(
28
+ QUERY_KEY,
30
29
  async ([, filter, onChainIncentives]) => {
31
30
  return await getRewardVaults({
32
31
  filter: filter,
33
32
  publicClient: onChainIncentives ? publicClient : undefined,
34
33
  });
35
34
  },
36
- {
37
- ...options?.opts,
38
- },
35
+ options,
39
36
  );
40
-
41
- return {
42
- ...swrResponse,
43
- refresh: swrResponse.mutate,
44
- };
45
37
  };
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import type { GqlVaultSnapshotDataRange } from "@berachain/graphql/dex/api";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import { getStakedBeraSnapshots } from "../../actions/pol/getStakedBeraSnapshots";
6
5
  import type { DefaultHookReturnType } from "../../types/global";
@@ -16,7 +15,7 @@ export function useStakedAPR({
16
15
  range: GqlVaultSnapshotDataRange;
17
16
  }): DefaultHookReturnType<UseStakedAPR> {
18
17
  const QUERY_KEY = range ? (["useStakedAPR", range] as const) : null;
19
- const swrResponse = useSWR(QUERY_KEY, async ([, range]) => {
18
+ return useSWR(QUERY_KEY, async ([, range]) => {
20
19
  const unsortedStakedBeraSnapshots = await getStakedBeraSnapshots({
21
20
  range,
22
21
  });
@@ -30,9 +29,4 @@ export function useStakedAPR({
30
29
  apr: item.apr,
31
30
  }));
32
31
  });
33
-
34
- return {
35
- ...swrResponse,
36
- refresh: () => swrResponse.mutate(),
37
- };
38
32
  }
@@ -1,8 +1,8 @@
1
1
  import { useMemo } from "react";
2
- import useSWR from "swr";
3
2
 
4
3
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
5
4
  import BigNumber from "@berachain/utils/pkg/bignumber.js";
5
+ import { useSWR } from "@berachain/utils/pkg/swr";
6
6
 
7
7
  import { getEarnedStakedBeraVault } from "../../actions/pol/getEarnedStakedBeraVault";
8
8
  import { getRewardTokenToBeraRate } from "../../actions/pol/getRewardTokenToBeraRate";
@@ -50,11 +50,18 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
50
50
  { refreshInterval: POLLING.NORMAL },
51
51
  );
52
52
 
53
- const { data: walletBalances, isLoading: isLoadingBalances } =
54
- usePollWalletBalances({ tokens: receiptTokens });
55
-
56
- // NOT BERA PRICE, INPUT TOKEN PRICE
57
- const { getTokenPrice } = useTokenPrices({ tokens: inputTokens });
53
+ const {
54
+ data: walletBalances,
55
+ isLoading: isLoadingBalances,
56
+ error: walletBalancesError,
57
+ } = usePollWalletBalances({ tokens: receiptTokens });
58
+
59
+ // NOT BERA PRICE, INPUT TOKEN PRICE.
60
+ // A price-backend failure is handled gracefully (USD values become `undefined`
61
+ // → rendered as "—"), so it deliberately does NOT feed the hard `error` state.
62
+ const { getTokenPrice } = useTokenPrices({
63
+ tokens: inputTokens,
64
+ });
58
65
 
59
66
  // exchange rates from receipt token → input token (on-chain reads)
60
67
  const exchangeRatesKey =
@@ -62,7 +69,7 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
62
69
  ? (["useStakedData:exchangeRates", receiptTokens] as const)
63
70
  : null;
64
71
 
65
- const { data: exchangeRates } = useSWR(
72
+ const { data: exchangeRates, error: exchangeRatesError } = useSWR(
66
73
  exchangeRatesKey,
67
74
  async ([, receiptTokens]) => {
68
75
  assertPublicClient(publicClient);
@@ -78,34 +85,6 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
78
85
  { refreshInterval: POLLING.NORMAL },
79
86
  );
80
87
 
81
- // balances (fast path) — derived from hooks above, no extra requests
82
- const balances = useMemo<StakedBeraAsset[] | undefined>(() => {
83
- if (!walletBalances || !exchangeRates) return undefined;
84
-
85
- return stakingConfigs.map((config, i): StakedBeraAsset => {
86
- const inputToken = config.inputTokens[0];
87
- const stakedBalance =
88
- walletBalances.find((b) => b.address === config.receiptToken.address)
89
- ?.balance.raw ?? "0";
90
- const exchangeRate = exchangeRates[i] ?? 0;
91
- const inputTokenPrice = getTokenPrice(inputToken) ?? 0;
92
-
93
- const total = new BigNumber(stakedBalance).multipliedBy(exchangeRate);
94
- const stakedAmount = total.dividedBy(10 ** inputToken.decimals);
95
- const stakedAmountUsd = stakedAmount.multipliedBy(inputTokenPrice);
96
-
97
- return {
98
- token: inputToken,
99
- apr: apr ?? 0,
100
- stakedAmount: stakedAmount.toNumber(),
101
- stakedAmountUsd: stakedAmountUsd.toNumber(),
102
- earnedAmount: 0,
103
- earnedAmountUsd: 0,
104
- isLoadingEarnings: true,
105
- };
106
- });
107
- }, [walletBalances, exchangeRates, stakingConfigs, apr, getTokenPrice]);
108
-
109
88
  // positions (slow path) — fetch earnings and exchange rates from the vault
110
89
  const positionsKey =
111
90
  account && publicClient && stakingConfigs.length > 0
@@ -114,6 +93,7 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
114
93
 
115
94
  const {
116
95
  data: positionsRaw,
96
+ error: positionsError,
117
97
  isLoading: isLoadingPositions,
118
98
  isValidating: isValidatingPositions,
119
99
  } = useSWR(
@@ -143,6 +123,52 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
143
123
  { refreshInterval: POLLING.FAST },
144
124
  );
145
125
 
126
+ // Earnings come from the backend (slow path). Once that request settles —
127
+ // whether it resolved or errored — stop showing the "loading earnings"
128
+ // skeleton on the fast path, so a backend outage degrades to "—" rather
129
+ // than a spinner that never resolves.
130
+ const earningsSettled = !!positionsRaw || !!positionsError;
131
+
132
+ // balances (fast path) — derived from hooks above, no extra requests
133
+ const balances = useMemo<StakedBeraAsset[] | undefined>(() => {
134
+ if (!walletBalances || !exchangeRates) return undefined;
135
+
136
+ return stakingConfigs.map((config, i): StakedBeraAsset => {
137
+ const inputToken = config.inputTokens[0];
138
+ const stakedBalance =
139
+ walletBalances.find((b) => b.address === config.receiptToken.address)
140
+ ?.balance.raw ?? "0";
141
+ const exchangeRate = exchangeRates[i] ?? 0;
142
+ // `undefined` (not 0) when the price backend is unavailable, so USD
143
+ // values render as "—" instead of a misleading "$0.00".
144
+ const inputTokenPrice = getTokenPrice(inputToken);
145
+
146
+ const total = new BigNumber(stakedBalance).multipliedBy(exchangeRate);
147
+ const stakedAmount = total.dividedBy(10 ** inputToken.decimals);
148
+ const stakedAmountUsd =
149
+ inputTokenPrice === undefined
150
+ ? undefined
151
+ : stakedAmount.multipliedBy(inputTokenPrice).toNumber();
152
+
153
+ return {
154
+ token: inputToken,
155
+ apr,
156
+ stakedAmount: stakedAmount.toNumber(),
157
+ stakedAmountUsd,
158
+ earnedAmount: 0,
159
+ earnedAmountUsd: earningsSettled ? undefined : 0,
160
+ isLoadingEarnings: !earningsSettled,
161
+ };
162
+ });
163
+ }, [
164
+ walletBalances,
165
+ exchangeRates,
166
+ stakingConfigs,
167
+ apr,
168
+ getTokenPrice,
169
+ earningsSettled,
170
+ ]);
171
+
146
172
  // derive full StakedBeraAsset[] from raw positions + shared hooks
147
173
  const data = useMemo<StakedBeraAsset[] | undefined>(() => {
148
174
  if (!positionsRaw || !walletBalances) return undefined;
@@ -152,7 +178,9 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
152
178
  const stakingToken = config.receiptToken;
153
179
  const { earnings, exchangeRate: exchangeRateRaw } = positionsRaw[i];
154
180
 
155
- const inputTokenPrice = getTokenPrice(inputToken) ?? 0;
181
+ // `undefined` (not 0) when the price backend is unavailable, so USD
182
+ // values render as "—" instead of a misleading "$0.00".
183
+ const inputTokenPrice = getTokenPrice(inputToken);
156
184
  const stakedBalance =
157
185
  walletBalances.find((b) => b.address === stakingToken.address)?.balance
158
186
  .raw ?? "0";
@@ -166,16 +194,22 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
166
194
 
167
195
  const stakedAmount = deposited.dividedBy(10 ** inputToken.decimals);
168
196
  const earnedAmount = unrealisedGains.dividedBy(10 ** inputToken.decimals);
169
- const stakedAmountUsd = stakedAmount.multipliedBy(inputTokenPrice);
170
- const earnedAmountUsd = earnedAmount.multipliedBy(inputTokenPrice);
197
+ const stakedAmountUsd =
198
+ inputTokenPrice === undefined
199
+ ? undefined
200
+ : stakedAmount.multipliedBy(inputTokenPrice).toNumber();
201
+ const earnedAmountUsd =
202
+ inputTokenPrice === undefined
203
+ ? undefined
204
+ : earnedAmount.multipliedBy(inputTokenPrice).toNumber();
171
205
 
172
206
  return {
173
207
  token: inputToken,
174
- apr: apr ?? 0,
208
+ apr,
175
209
  stakedAmount: stakedAmount.toNumber(),
176
210
  earnedAmount: earnedAmount.toNumber(),
177
- stakedAmountUsd: stakedAmountUsd.toNumber(),
178
- earnedAmountUsd: earnedAmountUsd.toNumber(),
211
+ stakedAmountUsd,
212
+ earnedAmountUsd,
179
213
  };
180
214
  });
181
215
  }, [positionsRaw, walletBalances, stakingConfigs, apr, getTokenPrice]);
@@ -190,5 +224,20 @@ export const useStakedData = (stakingConfigs: StakingConfig[]) => {
190
224
  isLoadingBalances,
191
225
  isLoadingPositions,
192
226
  isValidatingPositions,
227
+ /**
228
+ * Hard error: the RPC fast-path could not produce staked balances (wallet
229
+ * balances or exchange-rate reads failed). Price and earnings backend
230
+ * failures are intentionally excluded — those degrade gracefully (USD/APR
231
+ * render as "—", earnings stop loading) so RPC-derived amounts still show.
232
+ */
233
+ error: walletBalancesError ?? exchangeRatesError,
234
+ /** Set when the earnings (slow path) request failed. */
235
+ positionsError,
236
+ /**
237
+ * True once the earnings (slow path) request has settled — resolved or
238
+ * errored. Consumers should stop showing an earnings loading state once
239
+ * this is true, even if `data` never arrives (backend outage).
240
+ */
241
+ earningsSettled,
193
242
  };
194
243
  };
@@ -1,13 +1,13 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
- import type { VaultStatsByDayResponse } from "@berachain/graphql/api";
3
+ import type { StakeStatsByDayResponse } from "@berachain/graphql/beep";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getStakingDailyAssets } from "../../actions/pol/getStakingDailyAssets";
7
7
  import type { DefaultHookReturnType } from "../../types/global";
8
8
  import { dailyResolution } from "../../utils/filter";
9
9
 
10
- type UseStakedBeraSnapshot = Record<Address, VaultStatsByDayResponse>;
10
+ type UseStakedBeraSnapshot = Record<Address, StakeStatsByDayResponse>;
11
11
  export function useStakedSnapshots({
12
12
  range,
13
13
  addresses,
@@ -18,7 +18,7 @@ export function useStakedSnapshots({
18
18
  const QUERY_KEY = range
19
19
  ? (["useStakedSnapshots", range, addresses] as const)
20
20
  : null;
21
- const swrResponse = useSWR(QUERY_KEY, async ([, range, addresses]) => {
21
+ return useSWR(QUERY_KEY, async ([, range, addresses]) => {
22
22
  const [...sortedStakingDailyAssetsArray] = await Promise.all([
23
23
  ...addresses.map(async (address) => {
24
24
  const unstakingDailyAssets = await getStakingDailyAssets({
@@ -40,9 +40,4 @@ export function useStakedSnapshots({
40
40
  {} as UseStakedBeraSnapshot,
41
41
  );
42
42
  });
43
-
44
- return {
45
- ...swrResponse,
46
- refresh: () => swrResponse.mutate(),
47
- };
48
43
  }
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getSWBeraVaultMetadata } from "../../actions/pol/getSWBeraVaultMetadata";
7
7
  import { useBlockTime } from "../../contexts/block-time-provider";
@@ -1,8 +1,7 @@
1
- import useSWR from "swr";
2
-
3
1
  import type { Address } from "@berachain/config";
4
2
 
5
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
6
5
 
7
6
  import { getTotalStakedAmount } from "../../actions/pol/getTotalStakedAmount";
8
7
  import type { DefaultHookReturnType } from "../../types/global";
@@ -14,7 +13,7 @@ export function useTotalStakedAmount({
14
13
  }): DefaultHookReturnType<Record<Address, bigint>> {
15
14
  const publicClient = usePublicClient();
16
15
 
17
- const swrResponse = useSWR(
16
+ return useSWR(
18
17
  vaultAddresses && publicClient
19
18
  ? ["useTotalStakedAmount", vaultAddresses]
20
19
  : null,
@@ -22,9 +21,4 @@ export function useTotalStakedAmount({
22
21
  return getTotalStakedAmount({ vaultAddresses, publicClient });
23
22
  },
24
23
  );
25
-
26
- return {
27
- ...swrResponse,
28
- refresh: () => swrResponse.mutate(),
29
- };
30
24
  }
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } 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 { getUserVaultInfo } from "../../actions/pol/getUserVaultInfo";
7
7
  import { POLLING } from "../../enum/polling";
@@ -25,7 +25,7 @@ export const useUserVaultInfo = (
25
25
  ? (["useUserVaultInfo", account, args.vaultAddress] as const)
26
26
  : null;
27
27
 
28
- const swrResponse = useSWR(
28
+ return useSWR(
29
29
  QUERY_KEY,
30
30
  async ([, account, vaultAddress]) => {
31
31
  assertPublicClient(publicClient);
@@ -38,12 +38,7 @@ export const useUserVaultInfo = (
38
38
  },
39
39
  {
40
40
  ...options,
41
- refreshInterval: options?.opts?.refreshInterval ?? POLLING.NORMAL,
41
+ refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
42
42
  },
43
43
  );
44
-
45
- return {
46
- ...swrResponse,
47
- refresh: () => swrResponse.mutate(),
48
- };
49
44
  };
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import {
6
5
  type GetUserVaultsResponse,
@@ -20,7 +19,7 @@ export const useUserVaults = (
20
19
  const publicClient = usePublicClient();
21
20
  const QUERY_KEY =
22
21
  account && publicClient ? (["useUserVaults", account] as const) : null;
23
- const swrResponse = useSWR<GetUserVaultsResponse, unknown, typeof QUERY_KEY>(
22
+ return useSWR<GetUserVaultsResponse, unknown, typeof QUERY_KEY>(
24
23
  QUERY_KEY,
25
24
  async ([, account]) => {
26
25
  assertPublicClient(publicClient);
@@ -32,12 +31,8 @@ export const useUserVaults = (
32
31
  },
33
32
  {
34
33
  ...options,
35
- refreshInterval: options?.opts?.refreshInterval ?? POLLING.NORMAL,
34
+ refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
36
35
  keepPreviousData: true,
37
36
  },
38
37
  );
39
- return {
40
- ...swrResponse,
41
- refresh: () => swrResponse?.mutate?.(),
42
- };
43
38
  };
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import { usePublicClient } from "@berachain/wagmi/hooks";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getRewardVaultStakingToken } from "../../actions/pol/getRewardVaultStakingToken";
7
7
  import { assertPublicClient } from "../../errors/assert";
@@ -1,6 +1,5 @@
1
- import useSWR from "swr";
2
-
3
1
  import type { GetVaultHistoryQuery } from "@berachain/graphql/pol/api";
2
+ import { useSWR } from "@berachain/utils/pkg/swr";
4
3
 
5
4
  import {
6
5
  type GetVaultHistoryArgs,
@@ -18,12 +17,7 @@ export const useVaultHistory = ({
18
17
  const QUERY_KEY = vault
19
18
  ? (["useVaultHistory", vault, range, resolution] as const)
20
19
  : null;
21
- const swrResponse = useSWR(QUERY_KEY, ([, vault, range, resolution]) =>
20
+ return useSWR(QUERY_KEY, ([, vault, range, resolution]) =>
22
21
  getVaultHistory({ vault, range, resolution }),
23
22
  );
24
-
25
- return {
26
- ...swrResponse,
27
- refresh: () => swrResponse.mutate(),
28
- };
29
23
  };
@@ -1,7 +1,7 @@
1
- import useSWR from "swr";
2
1
  import type { Address } from "viem";
3
2
 
4
3
  import type { ApiValidatorFragment } from "@berachain/graphql/pol/api";
4
+ import { useSWR } from "@berachain/utils/pkg/swr";
5
5
 
6
6
  import { getVaultValidators } from "../../actions/pol/getVaultValidators";
7
7
  import type {
@@ -17,7 +17,7 @@ export const useVaultValidators = (
17
17
  options?: DefaultHookOptions,
18
18
  ): UsePollValidatorInfoResponse => {
19
19
  const QUERY_KEY = id ? (["useVaultValidators", id] as const) : null;
20
- const swrResponse = useSWR(
20
+ return useSWR(
21
21
  QUERY_KEY,
22
22
  async ([, address]) => {
23
23
  return await getVaultValidators({
@@ -25,12 +25,7 @@ export const useVaultValidators = (
25
25
  });
26
26
  },
27
27
  {
28
- ...options?.opts,
28
+ ...options,
29
29
  },
30
30
  );
31
-
32
- return {
33
- ...swrResponse,
34
- refresh: () => swrResponse.mutate(),
35
- };
36
31
  };
@@ -1,9 +1,9 @@
1
- import useSWRImmutable from "swr/immutable";
2
1
  import { 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 { useSWRImmutable } from "@berachain/utils/pkg/swr";
7
7
 
8
8
  import { getTokenInformation } from "../../actions/tokens/getTokenInformation";
9
9
  import { assertPublicClient } from "../../errors/assert";
@@ -36,7 +36,7 @@ export function useMultipleTokenInformation(
36
36
  ] as const)
37
37
  : null;
38
38
 
39
- const swrResponse = useSWRImmutable<Token[], unknown, typeof QUERY_KEY>(
39
+ return useSWRImmutable<Token[], unknown, typeof QUERY_KEY>(
40
40
  QUERY_KEY,
41
41
  async ([, addresses, chainId]) => {
42
42
  // We already checked for publicClient in the QUERY_KEY
@@ -64,11 +64,6 @@ export function useMultipleTokenInformation(
64
64
  }),
65
65
  );
66
66
  },
67
- { ...options?.opts },
67
+ { ...options },
68
68
  );
69
-
70
- return {
71
- ...swrResponse,
72
- refresh: () => swrResponse?.mutate?.(),
73
- };
74
69
  }