@berachain/berajs 0.2.10 → 0.2.11
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.
- package/dist/{HoneyConfigProvider-Dkj-_a5x.d.ts → HoneyConfigProvider-COOuDNra.d.ts} +1 -1
- package/dist/actions/clients/exports.mjs +1 -1
- package/dist/actions/exports.d.ts +67 -17
- package/dist/actions/exports.mjs +60 -19
- package/dist/actions/governance/exports.d.ts +3 -11
- package/dist/{chunk-P5WXXULM.mjs → chunk-MRQGHXAN.mjs} +1 -1
- package/dist/{chunk-WNBWX23Q.mjs → chunk-SXUNCX5E.mjs} +5 -4
- package/dist/chunk-UD5IUNCW.mjs +34 -0
- package/dist/{chunk-QBBOWFMH.mjs → chunk-VAA2FVPP.mjs} +58 -12
- package/dist/contexts/exports.d.ts +2 -2
- package/dist/contexts/exports.mjs +4 -2
- package/dist/enum/exports.d.ts +8 -2
- package/dist/getProposalVotes-DAUrdX2n.d.ts +12 -0
- package/dist/{getValidatorQueuedOperatorAddress-DphU3qhE.d.ts → getValidatorQueuedOperatorAddress-Cxt-DlL_.d.ts} +2 -2
- package/dist/{global.d-BuGDKh4k.d.ts → global.d-q_LQWQqs.d.ts} +2 -4
- package/dist/hooks/exports.d.ts +100 -149
- package/dist/hooks/exports.mjs +468 -484
- package/dist/hooks/governance/exports.d.ts +20 -15
- package/dist/hooks/governance/exports.mjs +39 -37
- package/dist/{pol.d-Dw5SQcRX.d.ts → pol.d-CeRgXBL8.d.ts} +18 -4
- package/dist/types/exports.d.ts +5 -5
- package/dist/{useHoneySwapState-vFmuFF0g.d.ts → useHoneySwapState-twi7NTaO.d.ts} +1 -1
- package/dist/utils/exports.d.ts +2 -2
- package/dist/utils/exports.mjs +4 -0
- package/package.json +8 -7
- package/src/actions/bend/getMaxDeposit.ts +28 -2
- package/src/actions/clients/fetchOpenApi.ts +6 -2
- package/src/actions/clients/fetchOpenApi.unit.test.ts +24 -2
- package/src/actions/exports.ts +1 -0
- package/src/actions/honey/getChartData.ts +53 -12
- package/src/actions/honey/getHoney24hVolume.ts +34 -6
- package/src/actions/honey/getHoneyTxns.ts +93 -0
- package/src/actions/validators/getValidatorIncentiveDistribution.ts +64 -12
- package/src/contexts/SwrFallback.tsx +2 -1
- package/src/data/contracts.ts +4 -0
- package/src/errors/getRevertReason.integration.test.ts +5 -1
- package/src/hooks/bend/useGetConvertToAssets.ts +2 -3
- package/src/hooks/dex/useAggregatorsQuotes.ts +10 -10
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +1 -1
- package/src/hooks/dex/useAllUserPools.ts +7 -5
- package/src/hooks/dex/useApiPool.ts +1 -1
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +1 -1
- package/src/hooks/dex/useOnChainPoolData.ts +1 -1
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +2 -2
- package/src/hooks/dex/usePoolEvents.ts +1 -2
- package/src/hooks/dex/usePoolHistoricalData.ts +2 -3
- package/src/hooks/dex/usePools.ts +4 -2
- package/src/hooks/dex/useSingleAggregatorQuote.ts +6 -18
- package/src/hooks/enso/useBendDemultiply.ts +3 -4
- package/src/hooks/enso/useBendMultiply.ts +3 -4
- package/src/hooks/enso/useBendZapSupply.ts +3 -4
- package/src/hooks/enso/useEnsoSwapBundle.ts +1 -1
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +3 -5
- package/src/hooks/enso/useEnsoWalletV2Address.ts +1 -1
- package/src/hooks/enso/useIsBendAuthorized.ts +1 -1
- package/src/hooks/enso/useZapStakeBera.ts +2 -2
- package/src/hooks/exports.ts +1 -0
- package/src/hooks/governance/useGetPastVotes.ts +1 -1
- package/src/hooks/governance/useHasVoted.ts +1 -1
- package/src/hooks/governance/useIsCanceller.ts +1 -1
- package/src/hooks/governance/usePollAllProposals.ts +13 -12
- package/src/hooks/governance/usePollProposal.ts +3 -3
- package/src/hooks/governance/usePollProposalThreshold.ts +1 -1
- package/src/hooks/governance/usePollProposalVotes.ts +23 -5
- package/src/hooks/governance/usePollUserDelegates.ts +3 -3
- package/src/hooks/governance/useProposalFromTx.ts +2 -1
- package/src/hooks/governance/useProposalSnapshot.ts +2 -3
- package/src/hooks/governance/useProposalState.ts +2 -2
- package/src/hooks/governance/useProposalTimelockState.ts +2 -1
- package/src/hooks/governance/useQuorum.ts +1 -2
- package/src/hooks/honey/useCappedGlobally.ts +3 -6
- package/src/hooks/honey/useCappedRelatively.ts +2 -2
- package/src/hooks/honey/useCollateralWeights.ts +3 -3
- package/src/hooks/honey/useHoney24hVolume.ts +1 -1
- package/src/hooks/honey/useHoneyBalances.ts +1 -1
- package/src/hooks/honey/useHoneyChartData.ts +1 -1
- package/src/hooks/honey/useHoneyVaultsBalance.ts +2 -3
- package/src/hooks/honey/useIsBadCollateralAsset.ts +4 -7
- package/src/hooks/honey/useIsBasketModeEnabled.ts +4 -7
- package/src/hooks/honey/usePythLatestPrices.ts +13 -9
- package/src/hooks/perps/usePythUpdateFee.ts +13 -11
- package/src/hooks/pol/useAutoclaimedIncentives.ts +1 -2
- package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +1 -2
- package/src/hooks/pol/useBgtIncentiveDistributorPaused.ts +39 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +2 -2
- package/src/hooks/pol/useClaimableFees.ts +1 -1
- package/src/hooks/pol/useHighestVaultsAPR.ts +4 -6
- package/src/hooks/pol/useOnChainRewardVault.ts +77 -72
- package/src/hooks/pol/usePollGlobalData.ts +2 -3
- package/src/hooks/pol/usePollMarkets.ts +2 -2
- package/src/hooks/pol/useQueuedBeraUnlock.ts +2 -2
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +2 -2
- package/src/hooks/pol/useRewardVault.ts +7 -6
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +4 -4
- package/src/hooks/pol/useRewardVaultFromToken.ts +1 -1
- package/src/hooks/pol/useRewardVaultIncentives.ts +1 -1
- package/src/hooks/pol/useRewardVaultRewards.ts +2 -2
- package/src/hooks/pol/useRewardVaults.ts +3 -6
- package/src/hooks/pol/useStakedAPR.ts +1 -2
- package/src/hooks/pol/useStakedData.ts +90 -41
- package/src/hooks/pol/useStakedSnapshots.ts +1 -1
- package/src/hooks/pol/useStakingVaultsMetadata.ts +1 -1
- package/src/hooks/pol/useTotalStakedAmount.ts +1 -2
- package/src/hooks/pol/useUserVaultInfo.ts +2 -2
- package/src/hooks/pol/useUserVaults.ts +2 -3
- package/src/hooks/pol/useVaultAddress.ts +1 -1
- package/src/hooks/pol/useVaultHistory.ts +1 -2
- package/src/hooks/pol/useVaultValidators.ts +2 -2
- package/src/hooks/tokens/useMultipleTokenInformation.ts +2 -2
- package/src/hooks/tokens/usePollAllowances.ts +3 -4
- package/src/hooks/tokens/usePollBalance.ts +2 -2
- package/src/hooks/tokens/usePollWalletBalances.ts +2 -2
- package/src/hooks/tokens/useStakingTokenInformation.ts +2 -2
- package/src/hooks/tokens/useTokenCurrentPrices.ts +11 -13
- package/src/hooks/tokens/useTokenInformation.ts +2 -2
- package/src/hooks/tokens/useTokenPrice.ts +2 -1
- package/src/hooks/tokens/useTokenPrices.ts +3 -4
- package/src/hooks/tokens/useTotalSupply.ts +1 -1
- package/src/hooks/tokens/useUnderlyingAsset.ts +1 -2
- package/src/hooks/useBlockToTimestamp.ts +1 -2
- package/src/hooks/useGetVerifiedAbi.ts +2 -1
- package/src/hooks/validators/useAllValidators.ts +2 -3
- package/src/hooks/validators/useApiEnrichedAllocation.ts +1 -1
- package/src/hooks/validators/useApiValidator.ts +3 -6
- package/src/hooks/validators/useBaselineRewardAllocation.ts +1 -2
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +1 -1
- package/src/hooks/validators/useDefaultRewardAllocation.ts +2 -3
- package/src/hooks/validators/useManagedValidatorRole.ts +2 -2
- package/src/hooks/validators/useOnChainValidator.ts +3 -3
- package/src/hooks/validators/useStakingPoolBatch.ts +3 -4
- package/src/hooks/validators/useUserActiveValidators.ts +2 -3
- package/src/hooks/validators/useUserBoostsOnValidator.ts +1 -1
- package/src/hooks/validators/useUserClaimableIncentives.ts +1 -1
- package/src/hooks/validators/useUserStakingPositions.ts +2 -1
- package/src/hooks/validators/useValidatorAnalytics.ts +1 -1
- package/src/hooks/validators/useValidatorCommission.ts +2 -2
- package/src/hooks/validators/useValidatorIncentiveDistribution.ts +3 -3
- package/src/hooks/validators/useValidatorQueuedCommission.ts +2 -2
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +2 -2
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +2 -2
- package/src/hooks/validators/useValidatorRewardAllocation.ts +2 -2
- package/src/types/global.d.ts +3 -4
- package/src/types/pol.d.ts +17 -3
- package/dist/polling-BKnyavLI.d.ts +0 -8
|
@@ -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 {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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 =
|
|
170
|
-
|
|
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
|
|
208
|
+
apr,
|
|
175
209
|
stakedAmount: stakedAmount.toNumber(),
|
|
176
210
|
earnedAmount: earnedAmount.toNumber(),
|
|
177
|
-
stakedAmountUsd
|
|
178
|
-
earnedAmountUsd
|
|
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,7 +1,7 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
1
|
import type { Address } from "viem";
|
|
3
2
|
|
|
4
3
|
import type { VaultStatsByDayResponse } from "@berachain/graphql/api";
|
|
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";
|
|
@@ -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";
|
|
@@ -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";
|
|
@@ -38,7 +38,7 @@ export const useUserVaultInfo = (
|
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
...options,
|
|
41
|
-
refreshInterval: options?.
|
|
41
|
+
refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
|
|
42
42
|
},
|
|
43
43
|
);
|
|
44
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,
|
|
@@ -32,7 +31,7 @@ export const useUserVaults = (
|
|
|
32
31
|
},
|
|
33
32
|
{
|
|
34
33
|
...options,
|
|
35
|
-
refreshInterval: options?.
|
|
34
|
+
refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
|
|
36
35
|
keepPreviousData: true,
|
|
37
36
|
},
|
|
38
37
|
);
|
|
@@ -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,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 {
|
|
@@ -25,7 +25,7 @@ export const useVaultValidators = (
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
...options
|
|
28
|
+
...options,
|
|
29
29
|
},
|
|
30
30
|
);
|
|
31
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";
|
|
@@ -64,7 +64,7 @@ export function useMultipleTokenInformation(
|
|
|
64
64
|
}),
|
|
65
65
|
);
|
|
66
66
|
},
|
|
67
|
-
{ ...options
|
|
67
|
+
{ ...options },
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
|
-
|
|
3
1
|
import { useBeraWallet, useConfig } from "@berachain/wagmi/hooks";
|
|
2
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
4
3
|
|
|
5
4
|
import { getAllowances } from "../../actions/tokens/getAllowances";
|
|
6
5
|
import { POLLING } from "../../enum/polling";
|
|
@@ -46,8 +45,8 @@ export function usePollAllowances(
|
|
|
46
45
|
});
|
|
47
46
|
},
|
|
48
47
|
{
|
|
49
|
-
...options
|
|
50
|
-
refreshInterval: options?.
|
|
48
|
+
...options,
|
|
49
|
+
refreshInterval: options?.refreshInterval ?? POLLING.NORMAL,
|
|
51
50
|
},
|
|
52
51
|
);
|
|
53
52
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
1
|
import {
|
|
3
2
|
type Address,
|
|
4
3
|
erc20Abi,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
import { defaultChainId } from "@berachain/config/internal";
|
|
12
11
|
|
|
13
12
|
import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
|
|
13
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
14
14
|
|
|
15
15
|
import { POLLING } from "../../enum/polling";
|
|
16
16
|
import { assertPublicClient } from "../../errors/assert";
|
|
@@ -47,7 +47,6 @@ export function usePollBalance(
|
|
|
47
47
|
const assetOwner = owner ?? account;
|
|
48
48
|
|
|
49
49
|
const QUERY_KEY =
|
|
50
|
-
(options?.opts?.isEnabled ?? true) &&
|
|
51
50
|
publicClient &&
|
|
52
51
|
assetOwner &&
|
|
53
52
|
isAddress(assetOwner) &&
|
|
@@ -80,6 +79,7 @@ export function usePollBalance(
|
|
|
80
79
|
},
|
|
81
80
|
{
|
|
82
81
|
refreshInterval: POLLING.FAST,
|
|
82
|
+
...options,
|
|
83
83
|
},
|
|
84
84
|
);
|
|
85
85
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import useSWR from "swr";
|
|
3
2
|
import type { Address } from "viem";
|
|
4
3
|
|
|
5
4
|
import {
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
useConfig,
|
|
8
7
|
usePublicClient,
|
|
9
8
|
} from "@berachain/wagmi/hooks";
|
|
9
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
10
10
|
|
|
11
11
|
import { getWalletBalances } from "../../actions/tokens/getWalletBalances";
|
|
12
12
|
import { POLLING } from "../../enum/polling";
|
|
@@ -67,7 +67,7 @@ export function usePollWalletBalances(
|
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
refreshInterval: POLLING.NORMAL,
|
|
70
|
-
...options
|
|
70
|
+
...options,
|
|
71
71
|
},
|
|
72
72
|
);
|
|
73
73
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import useSWRImmutable from "swr/immutable";
|
|
2
1
|
import { isAddress, zeroAddress } 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 { getStakingTokenInformation } from "../../actions/pol/getStakingTokenInformation";
|
|
7
7
|
import type { Token } from "../../types/dex";
|
|
@@ -48,7 +48,7 @@ export const useStakingTokenInformation = (
|
|
|
48
48
|
publicClient,
|
|
49
49
|
});
|
|
50
50
|
},
|
|
51
|
-
{ ...options
|
|
51
|
+
{ ...options },
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
return {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import useSWR from "swr";
|
|
3
2
|
import { type Address, isAddress, zeroAddress } from "viem";
|
|
4
3
|
|
|
5
4
|
import { defaultChainId } from "@berachain/config/internal";
|
|
6
5
|
|
|
6
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
7
|
+
|
|
7
8
|
import { getTokenCurrentPrices } from "../../actions/prices/getTokenCurrentPrices";
|
|
8
9
|
import { POLLING } from "../../enum/polling";
|
|
9
10
|
import type { TokenCurrentPriceMap, TokenWithPrice } from "../../types/dex";
|
|
@@ -21,10 +22,8 @@ export function useTokenCurrentPrices(
|
|
|
21
22
|
addressIn?: string[] | readonly string[];
|
|
22
23
|
} = {},
|
|
23
24
|
options: DefaultHookOptions = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
revalidateOnFocus: true,
|
|
27
|
-
},
|
|
25
|
+
refreshInterval: POLLING.NORMAL,
|
|
26
|
+
revalidateOnFocus: true,
|
|
28
27
|
},
|
|
29
28
|
) {
|
|
30
29
|
const { tokenList, ensoTokens } = useTokens();
|
|
@@ -65,13 +64,12 @@ export function useTokenCurrentPrices(
|
|
|
65
64
|
? beraAddresses
|
|
66
65
|
: tokenList.map((token) => token.address);
|
|
67
66
|
|
|
68
|
-
const QUERY_KEY =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: null;
|
|
67
|
+
const QUERY_KEY = addresses
|
|
68
|
+
? ([
|
|
69
|
+
"useTokenCurrentPrices",
|
|
70
|
+
addresses.map((a) => a.toLowerCase() as Address),
|
|
71
|
+
] as const)
|
|
72
|
+
: null;
|
|
75
73
|
|
|
76
74
|
const apiResponse = useSWR(
|
|
77
75
|
QUERY_KEY,
|
|
@@ -79,7 +77,7 @@ export function useTokenCurrentPrices(
|
|
|
79
77
|
// this only works for Berachain tokens
|
|
80
78
|
return getTokenCurrentPrices({ addressIn: addresses });
|
|
81
79
|
},
|
|
82
|
-
options
|
|
80
|
+
options,
|
|
83
81
|
);
|
|
84
82
|
|
|
85
83
|
const ensoMatchingPrices = useMemo<TokenCurrentPriceMap>(() => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import useSWRImmutable from "swr/immutable";
|
|
2
1
|
import { isAddress, zeroAddress } 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";
|
|
@@ -57,7 +57,7 @@ export function useTokenInformation(
|
|
|
57
57
|
chainId,
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
|
-
{ ...options
|
|
60
|
+
{ ...options },
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
return {
|
|
@@ -7,7 +7,7 @@ export function useTokenPrice(
|
|
|
7
7
|
{ token }: { token: TokenPriceInput | undefined },
|
|
8
8
|
options?: DefaultHookOptions,
|
|
9
9
|
) {
|
|
10
|
-
const { isLoading, priceMap } = useTokenPrices(
|
|
10
|
+
const { isLoading, error, priceMap } = useTokenPrices(
|
|
11
11
|
{ tokens: token ? [token] : undefined },
|
|
12
12
|
options,
|
|
13
13
|
);
|
|
@@ -17,5 +17,6 @@ export function useTokenPrice(
|
|
|
17
17
|
? priceMap[token.chainId]?.[token.address.toLowerCase() as Address]
|
|
18
18
|
: undefined,
|
|
19
19
|
isLoading,
|
|
20
|
+
error,
|
|
20
21
|
};
|
|
21
22
|
}
|
|
@@ -23,10 +23,8 @@ export function useTokenPrices(
|
|
|
23
23
|
tokens?: TokenPriceInput[];
|
|
24
24
|
} = {},
|
|
25
25
|
options: DefaultHookOptions = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
revalidateOnFocus: true,
|
|
29
|
-
},
|
|
26
|
+
refreshInterval: POLLING.NORMAL,
|
|
27
|
+
revalidateOnFocus: true,
|
|
30
28
|
},
|
|
31
29
|
) {
|
|
32
30
|
const { ensoTokens } = useTokens();
|
|
@@ -126,6 +124,7 @@ export function useTokenPrices(
|
|
|
126
124
|
|
|
127
125
|
return {
|
|
128
126
|
isLoading: apiResponse.isLoading,
|
|
127
|
+
error: apiResponse.error,
|
|
129
128
|
data,
|
|
130
129
|
priceMap,
|
|
131
130
|
getTokenPrice,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import useSWRImmutable from "swr/immutable";
|
|
2
|
-
|
|
3
1
|
import { useConfig } from "@berachain/wagmi/hooks";
|
|
2
|
+
import { useSWRImmutable } from "@berachain/utils/pkg/swr";
|
|
4
3
|
|
|
5
4
|
import { getUnderlyingToken } from "../../actions/tokens/getUnderlyingToken";
|
|
6
5
|
import type { MinimalERC20 } from "../../types/dex";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import useSWRImmutable from "swr/immutable";
|
|
2
|
-
|
|
3
1
|
import { useBlockNumber, usePublicClient } from "@berachain/wagmi/hooks";
|
|
2
|
+
import { useSWRImmutable } from "@berachain/utils/pkg/swr";
|
|
4
3
|
|
|
5
4
|
import { getBlockTimestamp } from "../actions/misc/getBlockTimestamp";
|
|
6
5
|
import { useBlockTime } from "../contexts/block-time-provider";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import useSWRImmutable from "swr/immutable";
|
|
2
1
|
import { isAddress, zeroAddress } from "viem";
|
|
3
2
|
|
|
4
3
|
import { chainId } from "@berachain/config/internal";
|
|
5
4
|
|
|
5
|
+
import { useSWRImmutable } from "@berachain/utils/pkg/swr";
|
|
6
|
+
|
|
6
7
|
import { beraFetchJson } from "../utils/beraFetch";
|
|
7
8
|
|
|
8
9
|
interface SuccessResponse {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
GetValidatorsQuery,
|
|
5
3
|
GetValidatorsQueryVariables,
|
|
6
4
|
GqlChain,
|
|
7
5
|
} from "@berachain/graphql/pol/api";
|
|
6
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
8
7
|
|
|
9
8
|
import { getAllValidators } from "../../actions/validators/getAllValidators";
|
|
10
9
|
import { POLLING } from "../../enum/polling";
|
|
@@ -40,7 +39,7 @@ export const useAllValidators = (
|
|
|
40
39
|
},
|
|
41
40
|
{
|
|
42
41
|
refreshInterval: POLLING.SLOW,
|
|
43
|
-
...options
|
|
42
|
+
...options,
|
|
44
43
|
},
|
|
45
44
|
);
|
|
46
45
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
1
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
2
2
|
|
|
3
3
|
import { getApiEnrichedAllocation } from "../../actions/validators/getApiEnrichedAllocation";
|
|
4
4
|
import type { ValidatorRewardAllocation } from "../../actions/validators/getValidatorRewardAllocation";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
1
|
import { type Address, isHex } from "viem";
|
|
3
2
|
|
|
4
3
|
import type { GetValidatorQuery } from "@berachain/graphql/pol/api";
|
|
4
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
5
5
|
|
|
6
6
|
import { getApiValidator } from "../../actions/validators/getApiValidator";
|
|
7
7
|
import type {
|
|
@@ -20,17 +20,14 @@ export const useApiValidator = (
|
|
|
20
20
|
options?: DefaultHookOptions,
|
|
21
21
|
): UsePollValidatorInfoResponse => {
|
|
22
22
|
const QUERY_KEY = useApiValidatorQueryKey(id);
|
|
23
|
-
const isEnabled = options?.opts?.isEnabled ?? true;
|
|
24
23
|
const swrResponse = useSWR(
|
|
25
|
-
|
|
24
|
+
id ? QUERY_KEY : null,
|
|
26
25
|
async ([, id]) => {
|
|
27
26
|
if (!id || !isHex(id)) throw new Error(`Invalid validator ID: ${id}`);
|
|
28
27
|
|
|
29
28
|
return getApiValidator({ id });
|
|
30
29
|
},
|
|
31
|
-
|
|
32
|
-
...options?.opts,
|
|
33
|
-
},
|
|
30
|
+
options,
|
|
34
31
|
);
|
|
35
32
|
|
|
36
33
|
return {
|
|
@@ -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 { getBaselineRewardAllocation } from "../../actions/validators/getBaselineRewardAllocation";
|
|
6
5
|
import { assertPublicClient } from "../../errors/assert";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
1
|
import type { Address } from "viem";
|
|
3
2
|
|
|
4
3
|
import type { GetValidatorBlockStatsQuery } from "@berachain/graphql/pol/subgraph";
|
|
4
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
5
5
|
|
|
6
6
|
import { getDailyValidatorBlockStats } from "../../actions/validators/getDailyValidatorBlockStats";
|
|
7
7
|
import { POLLING } from "../../enum/polling";
|
|
@@ -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 { getDefaultRewardAllocation } from "../../actions/validators/getDefaultRewardAllocation";
|
|
6
5
|
import type { ValidatorRewardAllocation } from "../../actions/validators/getValidatorRewardAllocation";
|
|
@@ -21,7 +20,7 @@ export function useDefaultRewardAllocation(options?: DefaultHookOptions) {
|
|
|
21
20
|
});
|
|
22
21
|
},
|
|
23
22
|
{
|
|
24
|
-
...options
|
|
23
|
+
...options,
|
|
25
24
|
},
|
|
26
25
|
);
|
|
27
26
|
|