@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.
- package/dist/{HoneyConfigProvider-Dkj-_a5x.d.ts → HoneyConfigProvider-COOuDNra.d.ts} +1 -1
- package/dist/actions/clients/exports.d.ts +5 -21
- package/dist/actions/clients/exports.mjs +5 -7
- package/dist/actions/exports.d.ts +117 -31
- package/dist/actions/exports.mjs +36 -25
- package/dist/actions/governance/exports.d.ts +3 -11
- package/dist/actions/server/exports.mjs +2 -2
- package/dist/chunk-4ML4Y6UN.mjs +46 -0
- package/dist/{chunk-7YVNSDXG.mjs → chunk-FGION6F6.mjs} +1 -1
- package/dist/{chunk-3JJLQ2JX.mjs → chunk-MKSFQIKC.mjs} +1 -4
- package/dist/{chunk-ZLTMIFCZ.mjs → chunk-RFJGL4MF.mjs} +3 -3
- package/dist/{chunk-Y6THHG77.mjs → chunk-T43JPYQS.mjs} +1 -1
- package/dist/{chunk-WNBWX23Q.mjs → chunk-W2VODV76.mjs} +7 -10
- package/dist/{chunk-QBBOWFMH.mjs → chunk-XDG26EG6.mjs} +115 -162
- package/dist/{chunk-P5WXXULM.mjs → chunk-YLTWPFCJ.mjs} +3 -18
- package/dist/contexts/exports.d.ts +2 -2
- package/dist/contexts/exports.mjs +6 -4
- package/dist/enum/exports.d.ts +8 -2
- package/dist/errors/exports.mjs +2 -2
- package/dist/{getApolloClient-BcUTGFUb.d.ts → getApolloClient-MWm_iq4u.d.ts} +4 -5
- package/dist/getProposalVotes-DAUrdX2n.d.ts +12 -0
- package/dist/{getValidatorQueuedOperatorAddress-DphU3qhE.d.ts → getValidatorQueuedOperatorAddress-Cc05dlO3.d.ts} +8 -59
- package/dist/{global.d-BuGDKh4k.d.ts → global.d-CR3zicga.d.ts} +3 -10
- package/dist/hooks/exports.d.ts +145 -403
- package/dist/hooks/exports.mjs +496 -755
- package/dist/hooks/governance/exports.d.ts +24 -19
- package/dist/hooks/governance/exports.mjs +43 -53
- 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 +6 -2
- package/package.json +8 -7
- package/src/actions/bend/getMaxDeposit.ts +28 -2
- package/src/actions/clients/exports.ts +0 -1
- package/src/actions/clients/fetchBeep.ts +0 -7
- package/src/actions/clients/fetchOpenApi.ts +10 -6
- package/src/actions/clients/fetchOpenApi.unit.test.ts +20 -14
- package/src/actions/clients/getApolloClient.ts +4 -9
- package/src/actions/exports.ts +1 -1
- package/src/actions/honey/getChartData.ts +14 -14
- package/src/actions/honey/getHoney24hVolume.ts +17 -8
- package/src/actions/honey/getHoneyTxns.ts +45 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +3 -3
- package/src/actions/pol/getEarnedStakedBeraVault.ts +0 -15
- package/src/actions/pol/getGlobalData.ts +10 -29
- package/src/actions/pol/getRewardVaults.ts +4 -4
- package/src/actions/pol/getSWBeraVaultMetadata.ts +0 -7
- package/src/actions/pol/getStakingDailyAssets.ts +0 -14
- package/src/actions/validators/getApiEnrichedAllocation.ts +1 -1
- package/src/actions/validators/getValidatorIncentiveDistribution.ts +43 -13
- package/src/contexts/SwrFallback.tsx +2 -1
- package/src/data/contracts.ts +4 -0
- package/src/errors/RequestError.ts +3 -3
- package/src/errors/getRevertReason.integration.test.ts +5 -1
- package/src/hooks/bend/useGetConvertToAssets.ts +3 -11
- package/src/hooks/dex/useAggregatorsQuotes.ts +13 -11
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +2 -7
- package/src/hooks/dex/useAllUserPools.ts +8 -13
- package/src/hooks/dex/useApiPool.ts +2 -9
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +1 -2
- package/src/hooks/dex/useOnChainPoolData.ts +3 -4
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +3 -9
- package/src/hooks/dex/usePoolEvents.ts +1 -2
- package/src/hooks/dex/usePoolHistoricalData.ts +3 -9
- package/src/hooks/dex/usePools.ts +6 -4
- 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 +4 -5
- package/src/hooks/enso/useEnsoSwapBundle.ts +2 -2
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +4 -10
- package/src/hooks/enso/useEnsoWalletV2Address.ts +1 -1
- package/src/hooks/enso/useIsBendAuthorized.ts +1 -1
- package/src/hooks/enso/useZapStakeBera.ts +2 -5
- 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 +7 -10
- package/src/hooks/governance/usePollProposalThreshold.ts +2 -7
- package/src/hooks/governance/usePollProposalVotes.ts +23 -5
- package/src/hooks/governance/usePollUserDelegates.ts +4 -9
- package/src/hooks/governance/useProposalFromTx.ts +4 -5
- package/src/hooks/governance/useProposalSnapshot.ts +3 -4
- package/src/hooks/governance/useProposalState.ts +3 -3
- package/src/hooks/governance/useProposalTimelockState.ts +3 -2
- package/src/hooks/governance/useQuorum.ts +1 -2
- package/src/hooks/honey/useCappedGlobally.ts +4 -12
- package/src/hooks/honey/useCappedRelatively.ts +3 -8
- package/src/hooks/honey/useCollateralWeights.ts +4 -9
- package/src/hooks/honey/useHoney24hVolume.ts +2 -6
- package/src/hooks/honey/useHoneyBalances.ts +2 -7
- package/src/hooks/honey/useHoneyChartData.ts +4 -12
- package/src/hooks/honey/useHoneyVaultsBalance.ts +3 -9
- package/src/hooks/honey/useIsBadCollateralAsset.ts +5 -13
- package/src/hooks/honey/useIsBasketModeEnabled.ts +5 -13
- package/src/hooks/honey/usePythLatestPrices.ts +15 -13
- package/src/hooks/perps/usePythUpdateFee.ts +13 -11
- package/src/hooks/pol/useAutoclaimedIncentives.ts +2 -8
- package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +2 -8
- package/src/hooks/pol/useBgtIncentiveDistributorPaused.ts +34 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +3 -8
- package/src/hooks/pol/useClaimableFees.ts +2 -6
- package/src/hooks/pol/useHighestVaultsAPR.ts +6 -11
- package/src/hooks/pol/useOnChainRewardVault.ts +77 -72
- package/src/hooks/pol/usePollGlobalData.ts +3 -9
- package/src/hooks/pol/usePollMarkets.ts +3 -8
- package/src/hooks/pol/useQueuedBeraUnlock.ts +3 -12
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +2 -2
- package/src/hooks/pol/useRewardVault.ts +9 -8
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +6 -6
- package/src/hooks/pol/useRewardVaultFromToken.ts +24 -30
- package/src/hooks/pol/useRewardVaultIncentives.ts +2 -7
- package/src/hooks/pol/useRewardVaultRewards.ts +3 -8
- package/src/hooks/pol/useRewardVaults.ts +4 -12
- package/src/hooks/pol/useStakedAPR.ts +2 -8
- package/src/hooks/pol/useStakedData.ts +90 -41
- package/src/hooks/pol/useStakedSnapshots.ts +4 -9
- package/src/hooks/pol/useStakingVaultsMetadata.ts +1 -1
- package/src/hooks/pol/useTotalStakedAmount.ts +2 -8
- package/src/hooks/pol/useUserVaultInfo.ts +3 -8
- package/src/hooks/pol/useUserVaults.ts +3 -8
- package/src/hooks/pol/useVaultAddress.ts +1 -1
- package/src/hooks/pol/useVaultHistory.ts +2 -8
- package/src/hooks/pol/useVaultValidators.ts +3 -8
- package/src/hooks/tokens/useMultipleTokenInformation.ts +3 -8
- package/src/hooks/tokens/usePollAllowances.ts +4 -11
- package/src/hooks/tokens/usePollBalance.ts +2 -5
- package/src/hooks/tokens/usePollWalletBalances.ts +3 -3
- package/src/hooks/tokens/useStakingTokenInformation.ts +3 -12
- package/src/hooks/tokens/useTokenCurrentPrices.ts +11 -13
- package/src/hooks/tokens/useTokenInformation.ts +3 -8
- 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 +3 -9
- package/src/hooks/validators/useApiEnrichedAllocation.ts +1 -1
- package/src/hooks/validators/useApiValidator.ts +4 -12
- package/src/hooks/validators/useBaselineRewardAllocation.ts +1 -2
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +2 -4
- package/src/hooks/validators/useDefaultRewardAllocation.ts +3 -9
- package/src/hooks/validators/useManagedValidatorRole.ts +2 -3
- package/src/hooks/validators/useOnChainValidator.ts +4 -11
- package/src/hooks/validators/useStakingPoolBatch.ts +4 -10
- package/src/hooks/validators/useUserActiveValidators.ts +3 -9
- package/src/hooks/validators/useUserBoostsOnValidator.ts +2 -4
- package/src/hooks/validators/useUserClaimableIncentives.ts +3 -3
- package/src/hooks/validators/useUserStakingPositions.ts +3 -9
- package/src/hooks/validators/useValidatorAnalytics.ts +2 -4
- package/src/hooks/validators/useValidatorCommission.ts +3 -8
- package/src/hooks/validators/useValidatorIncentiveDistribution.ts +4 -6
- package/src/hooks/validators/useValidatorQueuedCommission.ts +3 -8
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +3 -8
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +3 -8
- package/src/hooks/validators/useValidatorRewardAllocation.ts +3 -8
- package/src/types/global.d.ts +7 -10
- package/src/types/pol.d.ts +17 -3
- package/dist/polling-BKnyavLI.d.ts +0 -8
- package/src/actions/clients/fetchRailwayBackend.ts +0 -34
- package/src/actions/pol/getGlobalCuttingBoard.ts +0 -25
- 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
|
-
|
|
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
|
-
|
|
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
|
|
65
|
-
refreshInterval: options?.
|
|
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
|
|
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 {
|
|
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
|
-
):
|
|
28
|
+
): BeraSwrResponse<PythLatestUpdates> {
|
|
28
29
|
const priceFeedIds = priceFeedMap ? Object.values(priceFeedMap) : null;
|
|
29
30
|
|
|
30
|
-
const QUERY_KEY =
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
: null;
|
|
31
|
+
const QUERY_KEY = priceFeedIds
|
|
32
|
+
? (["usePythLatestPrices", priceFeedIds] as const)
|
|
33
|
+
: null;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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(
|
|
30
|
-
|
|
27
|
+
useSWRImmutable(
|
|
28
|
+
QUERY_KEY,
|
|
29
|
+
async ([_, pythPriceFeedCalldata]) => {
|
|
30
|
+
assertPublicClient(publicClient);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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?.
|
|
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
|
-
|
|
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
|
-
* -
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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?.
|
|
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
|
-
>(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
if (!stakingToken) {
|
|
90
|
+
throw new Error("Staking token not found");
|
|
91
|
+
}
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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?.
|
|
37
|
+
options?.isEnabled ??
|
|
37
38
|
((!!swrResponse.error || !swrResponse.isLoading) && !swrResponse.data);
|
|
38
39
|
|
|
39
40
|
const onChainRewardVault = useOnChainRewardVault(
|
|
40
41
|
{ address: id },
|
|
41
|
-
{
|
|
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.
|
|
51
|
-
onChainRewardVault.
|
|
51
|
+
swrResponse.refresh();
|
|
52
|
+
onChainRewardVault.refresh();
|
|
52
53
|
},
|
|
53
54
|
};
|
|
54
55
|
};
|