@berachain/berajs 0.2.8-beta.1 → 0.2.8-beta.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/RequestError-BRIiJgHk.d.ts +144 -0
- package/dist/RequestError-DSUzJ1Iy.d.cts +144 -0
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/abi/exports.mjs +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +22 -105
- package/dist/actions/exports.d.ts +22 -105
- package/dist/actions/exports.mjs +1 -1
- package/dist/actions/exports.mjs.map +1 -1
- package/dist/actions/governance/exports.cjs +2 -0
- package/dist/actions/governance/exports.cjs.map +1 -0
- package/dist/actions/governance/exports.d.cts +140 -0
- package/dist/actions/governance/exports.d.ts +140 -0
- package/dist/actions/governance/exports.mjs +2 -0
- package/dist/actions/governance/exports.mjs.map +1 -0
- package/dist/chunk-33XNWMPP.cjs +2 -0
- package/dist/chunk-33XNWMPP.cjs.map +1 -0
- package/dist/chunk-4TALWNXE.cjs +2 -0
- package/dist/chunk-4TALWNXE.cjs.map +1 -0
- package/dist/chunk-54BTOQE3.cjs +2 -0
- package/dist/chunk-54BTOQE3.cjs.map +1 -0
- package/dist/chunk-5QAFKFM5.mjs +2 -0
- package/dist/chunk-5QAFKFM5.mjs.map +1 -0
- package/dist/chunk-6DIA6PXV.cjs +2 -0
- package/dist/chunk-6DIA6PXV.cjs.map +1 -0
- package/dist/{chunk-NMH7LHPW.cjs → chunk-6JJIZCVY.cjs} +2 -2
- package/dist/chunk-6JJIZCVY.cjs.map +1 -0
- package/dist/chunk-BE6B4PQF.cjs +2 -0
- package/dist/chunk-BE6B4PQF.cjs.map +1 -0
- package/dist/chunk-CHFETMC6.cjs +4 -0
- package/dist/chunk-CHFETMC6.cjs.map +1 -0
- package/dist/{chunk-I7M43BB4.cjs → chunk-D6L7LTA2.cjs} +2 -2
- package/dist/chunk-D6L7LTA2.cjs.map +1 -0
- package/dist/chunk-DDEQFR3M.cjs.map +1 -1
- package/dist/chunk-ENT2OSXT.mjs +2 -0
- package/dist/chunk-ENT2OSXT.mjs.map +1 -0
- package/dist/{chunk-74QD4JAH.mjs → chunk-GXV2JA36.mjs} +2 -2
- package/dist/chunk-GXV2JA36.mjs.map +1 -0
- package/dist/chunk-H6ZO4SLB.mjs +4 -0
- package/dist/chunk-H6ZO4SLB.mjs.map +1 -0
- package/dist/chunk-JDDRTHFG.mjs +2 -0
- package/dist/chunk-JDDRTHFG.mjs.map +1 -0
- package/dist/{chunk-T5FSQ3YE.mjs → chunk-JDZGYU5T.mjs} +2 -2
- package/dist/{chunk-T5FSQ3YE.mjs.map → chunk-JDZGYU5T.mjs.map} +1 -1
- package/dist/chunk-JIPSTWKO.mjs +2 -0
- package/dist/{chunk-KI66MQ43.mjs.map → chunk-JIPSTWKO.mjs.map} +1 -1
- package/dist/chunk-JSTCUTXP.cjs +2 -0
- package/dist/chunk-JSTCUTXP.cjs.map +1 -0
- package/dist/{chunk-MJZHJFZO.mjs → chunk-JXM5S4IU.mjs} +2 -2
- package/dist/chunk-K5L2B4DU.mjs +2 -0
- package/dist/{chunk-EFG3OYYQ.mjs.map → chunk-K5L2B4DU.mjs.map} +1 -1
- package/dist/chunk-KUQEX7H3.mjs +2 -0
- package/dist/chunk-KUQEX7H3.mjs.map +1 -0
- package/dist/chunk-NXXMW2O7.mjs +2 -0
- package/dist/chunk-NXXMW2O7.mjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-OUD27MU7.cjs.map +1 -1
- package/dist/chunk-PRLVZIKD.mjs +2 -0
- package/dist/chunk-PRLVZIKD.mjs.map +1 -0
- package/dist/chunk-QVIAMSZ6.cjs +2 -0
- package/dist/chunk-QVIAMSZ6.cjs.map +1 -0
- package/dist/chunk-RCWM55DE.cjs +2 -0
- package/dist/chunk-RCWM55DE.cjs.map +1 -0
- package/dist/chunk-REWME3FY.cjs +2 -0
- package/dist/chunk-REWME3FY.cjs.map +1 -0
- package/dist/chunk-RJN36GBU.mjs +2 -0
- package/dist/chunk-RJN36GBU.mjs.map +1 -0
- package/dist/chunk-RWOICHRW.cjs.map +1 -1
- package/dist/chunk-S4CDSVLK.cjs +2 -0
- package/dist/chunk-S4CDSVLK.cjs.map +1 -0
- package/dist/chunk-WLJHFHKF.mjs +2 -0
- package/dist/chunk-WLJHFHKF.mjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/chunk-XZC34BHM.cjs +2 -0
- package/dist/chunk-XZC34BHM.cjs.map +1 -0
- package/dist/chunk-Y2FETC6T.cjs +2 -0
- package/dist/chunk-Y2FETC6T.cjs.map +1 -0
- package/dist/chunk-ZW2N63FI.mjs +2 -0
- package/dist/chunk-ZW2N63FI.mjs.map +1 -0
- package/dist/contexts/exports.cjs +1 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/contexts/exports.mjs +1 -1
- package/dist/contexts/exports.mjs.map +1 -1
- package/dist/enum/exports.cjs +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/exports.d.cts +1 -1
- package/dist/enum/exports.d.ts +1 -1
- package/dist/enum/exports.mjs +1 -1
- package/dist/enum/exports.mjs.map +1 -1
- package/dist/enum/governance/exports.cjs +2 -0
- package/dist/enum/governance/exports.cjs.map +1 -0
- package/dist/enum/governance/exports.d.cts +60 -0
- package/dist/enum/governance/exports.d.ts +60 -0
- package/dist/enum/governance/exports.mjs +2 -0
- package/dist/enum/governance/exports.mjs.map +1 -0
- package/dist/errors/exports.cjs +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.d.cts +3 -89
- package/dist/errors/exports.d.ts +3 -89
- package/dist/errors/exports.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-BQXkSFd9.d.cts → getValidatorQueuedOperatorAddress-CPuIw7n5.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-DUZOmxLV.d.ts → getValidatorQueuedOperatorAddress-CbZQ0kv2.d.ts} +2 -2
- package/dist/{global.d-6aSWIkV_.d.cts → global.d-B9nLZ7ul.d.cts} +3 -239
- package/dist/{global.d-SU9Epq0M.d.ts → global.d-ylUk_etZ.d.ts} +3 -239
- package/dist/hooks/exports.cjs +3 -3
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +19 -198
- package/dist/hooks/exports.d.ts +19 -198
- package/dist/hooks/exports.mjs +3 -3
- package/dist/hooks/exports.mjs.map +1 -1
- package/dist/hooks/governance/exports.cjs +2 -0
- package/dist/hooks/governance/exports.cjs.map +1 -0
- package/dist/hooks/governance/exports.d.cts +181 -0
- package/dist/hooks/governance/exports.d.ts +181 -0
- package/dist/hooks/governance/exports.mjs +2 -0
- package/dist/hooks/governance/exports.mjs.map +1 -0
- package/dist/pol.d-o6Iw75bK.d.cts +134 -0
- package/dist/pol.d-qR8bGEP5.d.ts +134 -0
- package/dist/{txnEnum-CCuQUFlh.d.cts → txnEnum-CwAJN4zV.d.cts} +3 -60
- package/dist/{txnEnum-CCuQUFlh.d.ts → txnEnum-CwAJN4zV.d.ts} +3 -60
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +7 -7
- package/dist/types/exports.d.ts +7 -7
- package/dist/types/governance/exports.cjs +1 -0
- package/dist/types/governance/exports.cjs.map +1 -0
- package/dist/types/governance/exports.d.cts +109 -0
- package/dist/types/governance/exports.d.ts +109 -0
- package/dist/types/governance/exports.mjs +1 -0
- package/dist/types/governance/exports.mjs.map +1 -0
- package/dist/utils/exports.cjs +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.d.cts +10 -2
- package/dist/utils/exports.d.ts +10 -2
- package/dist/utils/exports.mjs +1 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +49 -8
- package/src/actions/clients/BeraApolloClient.ts +9 -0
- package/src/actions/clients/getApolloClient.ts +23 -6
- package/src/actions/dex/getOnChainPool.ts +1 -1
- package/src/actions/enso/getBendMultiplyBundle.ts +9 -2
- package/src/actions/enso/util.ts +6 -8
- package/src/actions/exports.ts +1 -10
- package/src/actions/governance/checkProposalField.ts +108 -54
- package/src/actions/governance/computeActualStatus.ts +7 -3
- package/src/actions/governance/exports.ts +9 -0
- package/src/actions/governance/getAllProposals.ts +15 -8
- package/src/actions/governance/getBodyErrors.ts +13 -5
- package/src/actions/governance/getDecodedFunctionData.ts +31 -22
- package/src/actions/governance/getProposalDetails.ts +8 -4
- package/src/actions/governance/getProposalFromTx.ts +19 -10
- package/src/actions/governance/getProposalParams.ts +17 -17
- package/src/actions/governance/getProposalVotes.ts +7 -3
- package/src/actions/governance/getQuorum.ts +7 -7
- package/src/actions/governance/parseProposalBody.ts +19 -9
- package/src/actions/honey/getChartData.ts +5 -5
- package/src/actions/honey/getHoney24hVolume.ts +30 -0
- package/src/actions/honey/getHoneyPythPriceOracle.ts +1 -1
- package/src/actions/honey/getHoneyRootPriceOracle.ts +1 -1
- package/src/actions/pol/getEarnedStakedBeraVault.ts +12 -2
- package/src/actions/pol/getRewardVaultBeaconImplementation.ts +1 -1
- package/src/actions/pol/getRewardVaultIncentives.ts +2 -2
- package/src/actions/pol/getStakingDailyAssets.ts +7 -1
- package/src/actions/pol/getTotalStakedAmount.ts +1 -1
- package/src/actions/pol/getUserClaimableIncentives.ts +1 -1
- package/src/actions/pol/getUserVaultsReward.ts +1 -1
- package/src/actions/tokens/getTokenInformation.ts +8 -15
- package/src/actions/tokens/getUnderlyingToken.ts +1 -1
- package/src/actions/validators/getUserBoosts.ts +1 -1
- package/src/enum/exports.ts +0 -1
- package/src/enum/governance/exports.ts +1 -0
- package/src/enum/txnEnum.ts +2 -0
- package/src/errors/BeraError.ts +7 -2
- package/src/errors/RequestError.ts +2 -1
- package/src/hooks/dex/usePoolHistoricalData.ts +1 -1
- package/src/hooks/enso/useBendZapSupply.ts +1 -1
- package/src/hooks/exports.ts +1 -15
- package/src/hooks/governance/exports.ts +14 -0
- package/src/hooks/honey/useHoney24hVolume.ts +16 -0
- package/src/hooks/perps/usePythUpdateFee.ts +1 -1
- package/src/hooks/validators/useValidatorRewardAllocation.ts +1 -1
- package/src/types/exports.ts +0 -1
- package/src/types/governance/exports.ts +1 -0
- package/src/utils/beraFetch.ts +70 -15
- package/src/utils/getErrorResponse.ts +1 -1
- package/dist/RequestError-A8XJ6QR9.d.cts +0 -57
- package/dist/RequestError-Dk97z8rm.d.ts +0 -57
- package/dist/chunk-2EN6PPAW.cjs +0 -2
- package/dist/chunk-2EN6PPAW.cjs.map +0 -1
- package/dist/chunk-2YBHAMDV.cjs +0 -2
- package/dist/chunk-2YBHAMDV.cjs.map +0 -1
- package/dist/chunk-57RINXU6.cjs +0 -2
- package/dist/chunk-57RINXU6.cjs.map +0 -1
- package/dist/chunk-74QD4JAH.mjs.map +0 -1
- package/dist/chunk-74WA35RI.cjs +0 -2
- package/dist/chunk-74WA35RI.cjs.map +0 -1
- package/dist/chunk-7ITWLMO7.cjs +0 -4
- package/dist/chunk-7ITWLMO7.cjs.map +0 -1
- package/dist/chunk-BEKH5EYT.mjs +0 -2
- package/dist/chunk-BEKH5EYT.mjs.map +0 -1
- package/dist/chunk-DK42F2ZM.cjs +0 -2
- package/dist/chunk-DK42F2ZM.cjs.map +0 -1
- package/dist/chunk-EFG3OYYQ.mjs +0 -2
- package/dist/chunk-GO5E7UUD.cjs +0 -2
- package/dist/chunk-GO5E7UUD.cjs.map +0 -1
- package/dist/chunk-I7M43BB4.cjs.map +0 -1
- package/dist/chunk-IDFMLLDY.mjs +0 -2
- package/dist/chunk-IDFMLLDY.mjs.map +0 -1
- package/dist/chunk-JE5GI2OC.mjs +0 -4
- package/dist/chunk-JE5GI2OC.mjs.map +0 -1
- package/dist/chunk-KI66MQ43.mjs +0 -2
- package/dist/chunk-NMH7LHPW.cjs.map +0 -1
- package/dist/chunk-NVHV2LDK.cjs +0 -2
- package/dist/chunk-NVHV2LDK.cjs.map +0 -1
- package/dist/chunk-PLIH6KQM.mjs +0 -2
- package/dist/chunk-PLIH6KQM.mjs.map +0 -1
- package/dist/chunk-QRAIGQF2.mjs +0 -2
- package/dist/chunk-QRAIGQF2.mjs.map +0 -1
- package/src/actions/honey/getHoneyGlobalData.ts +0 -21
- package/src/hooks/honey/useHoneyGlobalData.ts +0 -23
- /package/dist/{chunk-MJZHJFZO.mjs.map → chunk-JXM5S4IU.mjs.map} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Aggregation_Interval,
|
|
3
|
+
GetSnapshots,
|
|
4
|
+
type GetSnapshotsQuery,
|
|
5
|
+
type GetSnapshotsQueryVariables,
|
|
6
|
+
} from "@berachain/graphql/honey";
|
|
7
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
8
|
+
|
|
9
|
+
import { getApolloClient } from "../clients/getApolloClient";
|
|
10
|
+
|
|
11
|
+
export async function getHoney24hVolume({
|
|
12
|
+
...args
|
|
13
|
+
}: BeraJS.BaseFunctionArgs = {}) {
|
|
14
|
+
const client = getApolloClient("honey.subgraph", args);
|
|
15
|
+
const result = await client.query<
|
|
16
|
+
GetSnapshotsQuery,
|
|
17
|
+
GetSnapshotsQueryVariables
|
|
18
|
+
>({
|
|
19
|
+
query: GetSnapshots,
|
|
20
|
+
variables: {
|
|
21
|
+
interval: Aggregation_Interval.Hour,
|
|
22
|
+
first: 24,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return result.data?.honeySnapshots.reduce(
|
|
27
|
+
(acc, curr) => new BigNumber(curr.totalVolume).plus(acc),
|
|
28
|
+
new BigNumber(0),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -13,7 +13,7 @@ export async function getHoneyPythOracle({
|
|
|
13
13
|
publicClient: PublicClient;
|
|
14
14
|
pythOracle: Address;
|
|
15
15
|
}) {
|
|
16
|
-
return
|
|
16
|
+
return publicClient.readContract({
|
|
17
17
|
address: pythOracle,
|
|
18
18
|
abi: honeyRootOracleAbi,
|
|
19
19
|
functionName: "pythOracle",
|
|
@@ -16,7 +16,7 @@ export async function getHoneyRootPriceOracle({
|
|
|
16
16
|
factory?: Address;
|
|
17
17
|
}): Promise<Address> {
|
|
18
18
|
const { config } = parseBaseArgs(args);
|
|
19
|
-
return
|
|
19
|
+
return publicClient.readContract({
|
|
20
20
|
address: factory ?? config.honey.factory,
|
|
21
21
|
abi: honeyFactoryAbi,
|
|
22
22
|
functionName: "priceOracle",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
|
|
3
|
+
import { getUriFromLink } from "@berachain/config";
|
|
4
|
+
|
|
3
5
|
import { beraFetchJson } from "../../utils/beraFetch";
|
|
4
6
|
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
5
7
|
|
|
@@ -26,6 +28,14 @@ export async function getEarnedStakedBeraVault({
|
|
|
26
28
|
}: BeraJS.BaseFunctionArgs &
|
|
27
29
|
GetEarnedStakedBeraVaultArgs): Promise<StakingHistoryData> {
|
|
28
30
|
const { config } = parseBaseArgs(args);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
const url = `${getUriFromLink(config.staking)}/vaults/${address}/earnings/${account}`;
|
|
33
|
+
return beraFetchJson<StakingHistoryData>({
|
|
34
|
+
url,
|
|
35
|
+
name:
|
|
36
|
+
typeof config.staking === "string"
|
|
37
|
+
? "backend-railway"
|
|
38
|
+
: config.staking.name,
|
|
39
|
+
type: "rest",
|
|
40
|
+
});
|
|
31
41
|
}
|
|
@@ -28,7 +28,7 @@ export async function getRewardVaultBeaconImplementation({
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// from the beacon contract, we get the current implementation address
|
|
31
|
-
return
|
|
31
|
+
return publicClient.readContract({
|
|
32
32
|
address: beacon,
|
|
33
33
|
abi: upgradableBeaconAbi,
|
|
34
34
|
functionName: "implementation",
|
|
@@ -132,11 +132,11 @@ export async function getRewardVaultIncentives({
|
|
|
132
132
|
decimals: decimalsResult,
|
|
133
133
|
pendingAmount: isSameAddress(stakingToken, token)
|
|
134
134
|
? formatUnits(
|
|
135
|
-
(totalBalance
|
|
135
|
+
multicallResult(totalBalance, 0n) - totalSupply - remainingAmount,
|
|
136
136
|
decimalsResult,
|
|
137
137
|
)
|
|
138
138
|
: formatUnits(
|
|
139
|
-
(totalBalance
|
|
139
|
+
multicallResult(totalBalance, 0n) - remainingAmount,
|
|
140
140
|
decimalsResult,
|
|
141
141
|
),
|
|
142
142
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
|
|
3
|
+
import { getUriFromLink } from "@berachain/config";
|
|
4
|
+
|
|
3
5
|
import { beraFetchJson } from "../../utils/beraFetch";
|
|
4
6
|
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
5
7
|
|
|
@@ -16,9 +18,13 @@ export async function getStakingDailyAssets({
|
|
|
16
18
|
);
|
|
17
19
|
|
|
18
20
|
const { config } = parseBaseArgs({});
|
|
19
|
-
const url = `${config.staking}/vaults/${address}/total-assets-by-day?start=${startDayDate.toISOString().split("T")[0]}`;
|
|
21
|
+
const url = `${getUriFromLink(config.staking)}/vaults/${address}/total-assets-by-day?start=${startDayDate.toISOString().split("T")[0]}`;
|
|
20
22
|
return beraFetchJson<{ _timestamp: number; total_assets: string }[]>({
|
|
21
23
|
url,
|
|
24
|
+
name:
|
|
25
|
+
typeof config.staking === "string"
|
|
26
|
+
? "backend-railway"
|
|
27
|
+
: config.staking.name,
|
|
22
28
|
type: "rest",
|
|
23
29
|
});
|
|
24
30
|
}
|
|
@@ -24,7 +24,7 @@ export async function getTotalStakedAmount({
|
|
|
24
24
|
try {
|
|
25
25
|
const totalAssets = await Promise.all(
|
|
26
26
|
vaultAddresses.map(async (address) => {
|
|
27
|
-
return
|
|
27
|
+
return publicClient.readContract({
|
|
28
28
|
address,
|
|
29
29
|
abi: stakeBeraVaultAbi,
|
|
30
30
|
functionName: "totalAssets",
|
|
@@ -23,7 +23,7 @@ export async function getUserVaultsReward({
|
|
|
23
23
|
if (!account) throw new Error("Missing user account");
|
|
24
24
|
if (!vaultAddress) throw new Error("Missing vault address");
|
|
25
25
|
|
|
26
|
-
return
|
|
26
|
+
return publicClient.readContract({
|
|
27
27
|
address: vaultAddress,
|
|
28
28
|
abi: rewardVaultAbi,
|
|
29
29
|
functionName: "earned",
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type Address, erc20Abi, type PublicClient } from "viem";
|
|
2
2
|
|
|
3
|
+
import type { ChainId } from "@berachain/config";
|
|
4
|
+
|
|
5
|
+
import { assertPublicClient } from "../../errors/assert";
|
|
3
6
|
import { initBeraError } from "../../errors/initBeraError";
|
|
4
7
|
import type { MinimalERC20 } from "../../types/dex";
|
|
5
8
|
|
|
6
9
|
export interface GetTokenInformation {
|
|
7
10
|
address: Address;
|
|
8
11
|
publicClient: PublicClient;
|
|
9
|
-
chainId:
|
|
12
|
+
chainId: ChainId;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export type GetTokenInformationResponse = MinimalERC20
|
|
15
|
+
export type GetTokenInformationResponse = MinimalERC20;
|
|
13
16
|
|
|
14
17
|
export async function getTokenInformation({
|
|
15
18
|
address,
|
|
@@ -17,9 +20,7 @@ export async function getTokenInformation({
|
|
|
17
20
|
chainId,
|
|
18
21
|
}: GetTokenInformation): Promise<GetTokenInformationResponse> {
|
|
19
22
|
try {
|
|
20
|
-
|
|
21
|
-
throw new Error("Public client not found");
|
|
22
|
-
}
|
|
23
|
+
assertPublicClient(publicClient);
|
|
23
24
|
|
|
24
25
|
const [decimals, name, symbol] = await Promise.all([
|
|
25
26
|
publicClient.readContract({
|
|
@@ -39,22 +40,14 @@ export async function getTokenInformation({
|
|
|
39
40
|
}),
|
|
40
41
|
]);
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
return {
|
|
43
44
|
address,
|
|
44
45
|
decimals,
|
|
45
46
|
name,
|
|
46
47
|
symbol,
|
|
47
48
|
chainId,
|
|
48
|
-
};
|
|
49
|
-
if (
|
|
50
|
-
typeof token.decimals !== "number" ||
|
|
51
|
-
typeof token.name !== "string" ||
|
|
52
|
-
typeof token.symbol !== "string"
|
|
53
|
-
)
|
|
54
|
-
throw new Error(`Invalid ERC20 token. Address: ${address}`);
|
|
55
|
-
return token satisfies MinimalERC20;
|
|
49
|
+
} satisfies MinimalERC20;
|
|
56
50
|
} catch (e) {
|
|
57
|
-
console.error(e);
|
|
58
51
|
throw initBeraError({ cause: e });
|
|
59
52
|
}
|
|
60
53
|
}
|
|
@@ -19,7 +19,7 @@ export async function getUserBoosts({
|
|
|
19
19
|
const { config } = parseBaseArgs(args);
|
|
20
20
|
const apiClient = getApolloClient("api", args);
|
|
21
21
|
|
|
22
|
-
return
|
|
22
|
+
return apiClient.query<
|
|
23
23
|
GetUserValidatorInformationQuery,
|
|
24
24
|
GetUserValidatorInformationQueryVariables
|
|
25
25
|
>({
|
package/src/enum/exports.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../governance";
|
package/src/enum/txnEnum.ts
CHANGED
|
@@ -94,6 +94,8 @@ export enum TransactionActionType {
|
|
|
94
94
|
// BEND
|
|
95
95
|
BEND_MARKET_REPAY_AND_WITHDRAW_COLLATERAL = "Bend Market Repay and Withdraw Collateral",
|
|
96
96
|
BEND_MARKET_SUPPLY_COLLATERAL_AND_BORROW = "Bend Market Supply Collateral and Borrow",
|
|
97
|
+
BEND_MARKET_MULTIPLY = "Bend Market Multiply",
|
|
98
|
+
BEND_MARKET_DEMULTIPLY = "Bend Market Demultiply",
|
|
97
99
|
BEND_VAULT_SUPPLY = "Bend Vault Supply",
|
|
98
100
|
BEND_VAULT_WITHDRAW = "Bend Vault Withdraw",
|
|
99
101
|
|
package/src/errors/BeraError.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Abi, BaseError } from "viem";
|
|
2
2
|
|
|
3
|
-
import { appConfig } from "@berachain/config/internal";
|
|
3
|
+
import { appConfig, currentDapp } from "@berachain/config/internal";
|
|
4
4
|
|
|
5
5
|
import { GENERAL_ERROR } from "./errorMap";
|
|
6
6
|
import { findMatchingError } from "./getErrorMessage";
|
|
@@ -237,7 +237,12 @@ export class BeraError extends Error {
|
|
|
237
237
|
...tags,
|
|
238
238
|
};
|
|
239
239
|
// Useful for debugging in development or on vercel preview links
|
|
240
|
-
if (
|
|
240
|
+
if (
|
|
241
|
+
!appConfig.env.isProduction &&
|
|
242
|
+
// skip debug logs on consumer of the berajs package
|
|
243
|
+
(process.env.NEXT_PUBLIC_IS_MONOBERA === "true" || currentDapp) &&
|
|
244
|
+
process.env.NODE_ENV !== "test"
|
|
245
|
+
) {
|
|
241
246
|
console.group("BeraError thrown");
|
|
242
247
|
console.debug("Level", this.level);
|
|
243
248
|
console.debug("Reason", this.reason);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ErrorLike } from "@apollo/client";
|
|
2
2
|
|
|
3
|
+
import { getUriFromLink } from "@berachain/config";
|
|
3
4
|
import { mainnet } from "@berachain/config/mainnet";
|
|
4
5
|
|
|
5
6
|
import { BeraError, type IBeraErrorArgs } from "./BeraError";
|
|
@@ -148,7 +149,7 @@ export class RequestError extends BeraError {
|
|
|
148
149
|
|
|
149
150
|
if (
|
|
150
151
|
this.queryRichfulDomains.some((domain) =>
|
|
151
|
-
this.endpoint.url.includes(domain),
|
|
152
|
+
this.endpoint.url.includes(getUriFromLink(domain)),
|
|
152
153
|
)
|
|
153
154
|
) {
|
|
154
155
|
// remove query params if it's an aggregator url
|
|
@@ -198,7 +198,7 @@ export function useBendZapSupplyHelper(
|
|
|
198
198
|
assertAddress(tokenIn?.address, "tokenInAddress");
|
|
199
199
|
assertDefined(tokenIn?.chainId, "tokenInChainId");
|
|
200
200
|
|
|
201
|
-
return
|
|
201
|
+
return ensoErc4626.getQuote({
|
|
202
202
|
tokenIn,
|
|
203
203
|
tokenOut: bendVault,
|
|
204
204
|
underlyingToken: loanToken,
|
package/src/hooks/exports.ts
CHANGED
|
@@ -36,27 +36,13 @@ export * from "./enso/useBendZapSupply";
|
|
|
36
36
|
export * from "./enso/useEnsoSwapBundle";
|
|
37
37
|
export * from "./enso/useEnsoUserTokensWithBalances";
|
|
38
38
|
export * from "./enso/useZapStakeBera";
|
|
39
|
-
export { useCreateProposal } from "./governance/useCreateProposal";
|
|
40
|
-
export * from "./governance/useGetPastVotes";
|
|
41
|
-
export * from "./governance/useHasVoted";
|
|
42
|
-
export * from "./governance/useIsCanceller";
|
|
43
|
-
export * from "./governance/usePollAllProposals";
|
|
44
|
-
export * from "./governance/usePollProposal";
|
|
45
|
-
export * from "./governance/usePollProposalThreshold";
|
|
46
|
-
export * from "./governance/usePollProposalVotes";
|
|
47
|
-
export * from "./governance/usePollUserDelegates";
|
|
48
|
-
export * from "./governance/useProposalFromTx";
|
|
49
|
-
export * from "./governance/useProposalSnapshot";
|
|
50
|
-
export * from "./governance/useProposalState";
|
|
51
|
-
export * from "./governance/useProposalTimelockState";
|
|
52
|
-
export * from "./governance/useQuorum";
|
|
53
39
|
export * from "./honey/useCappedGlobally";
|
|
54
40
|
export * from "./honey/useCappedRelatively";
|
|
55
41
|
export * from "./honey/useCollateralWeights";
|
|
42
|
+
export * from "./honey/useHoney24hVolume";
|
|
56
43
|
export * from "./honey/useHoneyAlerts";
|
|
57
44
|
export * from "./honey/useHoneyBalances";
|
|
58
45
|
export * from "./honey/useHoneyChartData";
|
|
59
|
-
export * from "./honey/useHoneyGlobalData";
|
|
60
46
|
export * from "./honey/useHoneySwapState";
|
|
61
47
|
export * from "./honey/useHoneyVaultsBalance";
|
|
62
48
|
export * from "./honey/useIsBadCollateralAsset";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { useCreateProposal } from "./useCreateProposal";
|
|
2
|
+
export * from "./useGetPastVotes";
|
|
3
|
+
export * from "./useHasVoted";
|
|
4
|
+
export * from "./useIsCanceller";
|
|
5
|
+
export * from "./usePollAllProposals";
|
|
6
|
+
export * from "./usePollProposal";
|
|
7
|
+
export * from "./usePollProposalThreshold";
|
|
8
|
+
export * from "./usePollProposalVotes";
|
|
9
|
+
export * from "./usePollUserDelegates";
|
|
10
|
+
export * from "./useProposalFromTx";
|
|
11
|
+
export * from "./useProposalSnapshot";
|
|
12
|
+
export * from "./useProposalState";
|
|
13
|
+
export * from "./useProposalTimelockState";
|
|
14
|
+
export * from "./useQuorum";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
|
|
3
|
+
import { getHoney24hVolume } from "../../actions/honey/getHoney24hVolume";
|
|
4
|
+
import { POLLING } from "../../enum/polling";
|
|
5
|
+
|
|
6
|
+
export function useHoney24hVolume() {
|
|
7
|
+
const response = useSWR(["useHoney24hVolume"], () => getHoney24hVolume(), {
|
|
8
|
+
refreshInterval: POLLING.SLOW,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
...response,
|
|
13
|
+
|
|
14
|
+
refresh: () => response.mutate(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -29,7 +29,7 @@ export const usePythUpdateFee = (
|
|
|
29
29
|
useSWRImmutable(QUERY_KEY, async ([_, pythPriceFeedCalldata]) => {
|
|
30
30
|
assertPublicClient(publicClient);
|
|
31
31
|
|
|
32
|
-
return
|
|
32
|
+
return getPythUpdateFee({
|
|
33
33
|
client: publicClient,
|
|
34
34
|
priceFeedId: pythPriceFeedCalldata,
|
|
35
35
|
});
|
|
@@ -19,7 +19,7 @@ export function useValidatorRewardAllocation(
|
|
|
19
19
|
const swrResponse = useSWR(
|
|
20
20
|
QUERY_KEY,
|
|
21
21
|
async ([, pubKey]) => {
|
|
22
|
-
return
|
|
22
|
+
return getValidatorRewardAllocation({
|
|
23
23
|
client: publicClient as PublicClient,
|
|
24
24
|
pubKey,
|
|
25
25
|
});
|
package/src/types/exports.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../governance.d";
|
package/src/utils/beraFetch.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BeraTracing, type SpanContext } from "../errors/BeraTracing";
|
|
1
2
|
import { RequestError } from "../errors/RequestError";
|
|
2
3
|
import { getErrorResponse } from "./getErrorResponse";
|
|
3
4
|
|
|
@@ -6,27 +7,81 @@ type RequestOptions = RequestInit;
|
|
|
6
7
|
export async function beraFetch(
|
|
7
8
|
endpoint: ConstructorParameters<typeof RequestError>[0]["endpoint"],
|
|
8
9
|
options?: RequestOptions,
|
|
10
|
+
spanContext?: SpanContext & {
|
|
11
|
+
/**
|
|
12
|
+
* If true, keep all query params in the span URL.
|
|
13
|
+
* If an array of strings, keep only the query params in the array.
|
|
14
|
+
* If false, remove all query params from the span URL.
|
|
15
|
+
* If not provided, remove all query params from the span URL.
|
|
16
|
+
*/
|
|
17
|
+
keepQueryParams?: boolean | string[];
|
|
18
|
+
},
|
|
9
19
|
) {
|
|
10
20
|
try {
|
|
11
|
-
|
|
21
|
+
let spanUrl = (
|
|
12
22
|
typeof endpoint === "string" || endpoint instanceof URL
|
|
13
|
-
? endpoint
|
|
14
|
-
: endpoint.url
|
|
23
|
+
? endpoint.toString()
|
|
24
|
+
: endpoint.url.toString()
|
|
25
|
+
).replace(/0x[a-fA-F0-9]{40}/g, ":address");
|
|
26
|
+
|
|
27
|
+
if (spanContext?.keepQueryParams !== true && URL.canParse(spanUrl)) {
|
|
28
|
+
const queryParams = new URL(spanUrl).searchParams;
|
|
29
|
+
if (Array.isArray(spanContext?.keepQueryParams)) {
|
|
30
|
+
const searchParams = new URLSearchParams();
|
|
31
|
+
|
|
32
|
+
for (const param of spanContext.keepQueryParams) {
|
|
33
|
+
searchParams.set(param, queryParams.get(param) ?? "");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const newUrl = new URL(spanUrl);
|
|
37
|
+
newUrl.search = searchParams.toString();
|
|
38
|
+
spanUrl = newUrl.toString();
|
|
39
|
+
} else {
|
|
40
|
+
const newUrl = new URL(spanUrl);
|
|
41
|
+
newUrl.search = "";
|
|
42
|
+
spanUrl = newUrl.toString();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return await BeraTracing.startSpan(
|
|
15
47
|
{
|
|
16
|
-
|
|
48
|
+
op: "beraFetch",
|
|
49
|
+
name: "beraFetch",
|
|
50
|
+
attributes:
|
|
51
|
+
typeof endpoint === "string" || endpoint instanceof URL
|
|
52
|
+
? {
|
|
53
|
+
"operation.source.url": spanUrl,
|
|
54
|
+
...spanContext?.attributes,
|
|
55
|
+
}
|
|
56
|
+
: ({
|
|
57
|
+
"operation.source.url": spanUrl,
|
|
58
|
+
"operation.source.type": endpoint.type,
|
|
59
|
+
"operation.source.name": endpoint.name,
|
|
60
|
+
...spanContext?.attributes,
|
|
61
|
+
} satisfies SpanContext["attributes"]),
|
|
62
|
+
},
|
|
63
|
+
async () => {
|
|
64
|
+
const response = await fetch(
|
|
65
|
+
typeof endpoint === "string" || endpoint instanceof URL
|
|
66
|
+
? endpoint
|
|
67
|
+
: endpoint.url,
|
|
68
|
+
{
|
|
69
|
+
...options,
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const error = await getErrorResponse(response);
|
|
74
|
+
throw new RequestError({
|
|
75
|
+
cause: error,
|
|
76
|
+
// @to-do import getErrorResponse logic in this function
|
|
77
|
+
// when it's removed from other places
|
|
78
|
+
response: response,
|
|
79
|
+
endpoint,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return response;
|
|
17
83
|
},
|
|
18
84
|
);
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
const error = await getErrorResponse(response);
|
|
21
|
-
throw new RequestError({
|
|
22
|
-
cause: error,
|
|
23
|
-
// @to-do import getErrorResponse logic in this function
|
|
24
|
-
// when it's removed from other places
|
|
25
|
-
response: response,
|
|
26
|
-
endpoint,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return response;
|
|
30
85
|
} catch (error) {
|
|
31
86
|
if (error instanceof RequestError) {
|
|
32
87
|
throw error;
|
|
@@ -5,7 +5,7 @@ export async function getErrorResponse(response: Response) {
|
|
|
5
5
|
const contentType = response.headers.get("content-type");
|
|
6
6
|
|
|
7
7
|
if (contentType?.includes("application/json")) {
|
|
8
|
-
return
|
|
8
|
+
return response.json();
|
|
9
9
|
} else {
|
|
10
10
|
const text = await response.text();
|
|
11
11
|
try {
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ErrorLike } from '@apollo/client';
|
|
2
|
-
import { B as BeraError, I as IBeraErrorArgs } from './BeraError-_mQdkanr.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This is an error class that should be used to handle errors from fetch requests.
|
|
6
|
-
*/
|
|
7
|
-
declare class RequestError extends BeraError {
|
|
8
|
-
/**
|
|
9
|
-
* The error response from the request.
|
|
10
|
-
*/
|
|
11
|
-
response: Response | ErrorLike | undefined;
|
|
12
|
-
static isCorsError(error: Error): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The endpoint that was requested.
|
|
15
|
-
*/
|
|
16
|
-
endpoint: {
|
|
17
|
-
name?: string;
|
|
18
|
-
url: string;
|
|
19
|
-
type?: "rest" | "graphql" | "rpc";
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* A list of domains that should have their query params removed.
|
|
23
|
-
*/
|
|
24
|
-
private queryRichfulDomains;
|
|
25
|
-
statusCode: number | undefined;
|
|
26
|
-
payload?: object;
|
|
27
|
-
static readonly REASON_MAP: {
|
|
28
|
-
readonly 429: "RATE_LIMITED_429";
|
|
29
|
-
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
30
|
-
readonly CORS_ERROR: "CORS";
|
|
31
|
-
};
|
|
32
|
-
constructor(args: IBeraErrorArgs & {
|
|
33
|
-
response: Response | ErrorLike | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* The payload sent to the request.
|
|
36
|
-
*/
|
|
37
|
-
payload?: object;
|
|
38
|
-
endpoint: string | URL | {
|
|
39
|
-
name?: string;
|
|
40
|
-
url: string | URL;
|
|
41
|
-
type: "rest" | "graphql" | "rpc";
|
|
42
|
-
};
|
|
43
|
-
statusCode?: number;
|
|
44
|
-
});
|
|
45
|
-
setEndpoint(endpoint: string | URL | {
|
|
46
|
-
name?: string;
|
|
47
|
-
url: string | URL;
|
|
48
|
-
type?: "rest" | "graphql" | "rpc";
|
|
49
|
-
}): {
|
|
50
|
-
name?: string;
|
|
51
|
-
url: string;
|
|
52
|
-
type?: "rest" | "graphql" | "rpc";
|
|
53
|
-
};
|
|
54
|
-
private tryMatchNetworkError;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { RequestError as R };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ErrorLike } from '@apollo/client';
|
|
2
|
-
import { B as BeraError, I as IBeraErrorArgs } from './BeraError-_mQdkanr.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This is an error class that should be used to handle errors from fetch requests.
|
|
6
|
-
*/
|
|
7
|
-
declare class RequestError extends BeraError {
|
|
8
|
-
/**
|
|
9
|
-
* The error response from the request.
|
|
10
|
-
*/
|
|
11
|
-
response: Response | ErrorLike | undefined;
|
|
12
|
-
static isCorsError(error: Error): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The endpoint that was requested.
|
|
15
|
-
*/
|
|
16
|
-
endpoint: {
|
|
17
|
-
name?: string;
|
|
18
|
-
url: string;
|
|
19
|
-
type?: "rest" | "graphql" | "rpc";
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* A list of domains that should have their query params removed.
|
|
23
|
-
*/
|
|
24
|
-
private queryRichfulDomains;
|
|
25
|
-
statusCode: number | undefined;
|
|
26
|
-
payload?: object;
|
|
27
|
-
static readonly REASON_MAP: {
|
|
28
|
-
readonly 429: "RATE_LIMITED_429";
|
|
29
|
-
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
30
|
-
readonly CORS_ERROR: "CORS";
|
|
31
|
-
};
|
|
32
|
-
constructor(args: IBeraErrorArgs & {
|
|
33
|
-
response: Response | ErrorLike | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* The payload sent to the request.
|
|
36
|
-
*/
|
|
37
|
-
payload?: object;
|
|
38
|
-
endpoint: string | URL | {
|
|
39
|
-
name?: string;
|
|
40
|
-
url: string | URL;
|
|
41
|
-
type: "rest" | "graphql" | "rpc";
|
|
42
|
-
};
|
|
43
|
-
statusCode?: number;
|
|
44
|
-
});
|
|
45
|
-
setEndpoint(endpoint: string | URL | {
|
|
46
|
-
name?: string;
|
|
47
|
-
url: string | URL;
|
|
48
|
-
type?: "rest" | "graphql" | "rpc";
|
|
49
|
-
}): {
|
|
50
|
-
name?: string;
|
|
51
|
-
url: string;
|
|
52
|
-
type?: "rest" | "graphql" | "rpc";
|
|
53
|
-
};
|
|
54
|
-
private tryMatchNetworkError;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { RequestError as R };
|
package/dist/chunk-2EN6PPAW.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkGO5E7UUDcjs = require('./chunk-GO5E7UUD.cjs');var _chunkDDEQFR3Mcjs = require('./chunk-DDEQFR3M.cjs');var _chunk74WA35RIcjs = require('./chunk-74WA35RI.cjs');var _chunk2YBHAMDVcjs = require('./chunk-2YBHAMDV.cjs');var _chunkNMH7LHPWcjs = require('./chunk-NMH7LHPW.cjs');var _react = require('react');var _edgeconfig = require('@berachain/config/internal/edge-config');var _jsxruntime = require('react/jsx-runtime');var W=_react.createContext.call(void 0, void 0);function pe({children:e,flags:t,aggregators:a,swberaAprWindow:n="DAY"}){return _jsxruntime.jsx.call(void 0, W.Provider,{value:{..._chunkDDEQFR3Mcjs.a,...t,aggregators:a?Object.entries(a).filter(([,r])=>_edgeconfig.isFlagEnabled.call(void 0, r)).map(([r])=>r):void 0,swberaAprWindow:n},children:e})}function D(){let e=_react.useContext.call(void 0, W);if(!e)throw new Error("BeraFlagsProvider not found");return e}function fe(e){return D()[e]}var w=_react.createContext.call(void 0, {protocol:{isPaused:!1,factories:{composableStable:"enabled",weighted:"enabled",allPaused:!1}},onPoolChange:()=>{},pool:void 0});function Te(){let e=_react.useContext.call(void 0, w);if(!e)throw new (0, _chunkNMH7LHPWcjs.f)({level:"fatal",message:"BexStateContext is not defined"});return e}function he({children:e,isVaultPaused:t,labels:a,factories:n}){let[r,u]=_react.useState.call(void 0, ),s=_nullishCoalesce((_optionalChain([r, 'optionalAccess', _2 => _2.isPaused])&&!_optionalChain([r, 'optionalAccess', _3 => _3.isInRecoveryMode])), () => (!1)),l=t||_optionalChain([r, 'optionalAccess', _4 => _4.isPaused]);return _jsxruntime.jsx.call(void 0, w.Provider,{value:{protocol:{isPaused:t,factories:{...n,allPaused:n.composableStable==="paused"&&n.weighted==="paused"}},labels:a,onPoolChange:u,pool:r?{...r,disablePoolWithdrawals:!!s,disablePoolDeposits:!!l}:void 0},children:e})}var _mainnet = require('@berachain/config/mainnet');function ve(){return _react.useContext.call(void 0, F)}var F=_react.createContext.call(void 0, _mainnet.mainnet.averageBlockTime);function Ee({children:e,blockTime:t,...a}){let{config:n}=_chunk74WA35RIcjs.a.call(void 0, a);return _jsxruntime.jsx.call(void 0, F.Provider,{value:_nullishCoalesce(t, () => (n.averageBlockTime)),children:e})}var L=_react.createContext.call(void 0, void 0);function Fe({children:e,...t}){return _jsxruntime.jsx.call(void 0, L.Provider,{value:t,children:e})}function Le(){let e=_react.useContext.call(void 0, L);if(!e)throw new Error("useHoneyConfig must be used within a HoneyConfigProvider");return e}var _swr = require('swr'); var _swr2 = _interopRequireDefault(_swr);var _hooks = require('@berachain/wagmi/hooks');var _core = require('@wagmi/core');var _viem = require('viem');async function R({account:e,wagmiConfig:t,chainId:a,ensoClient:n}){let u=(await n.getBalances({useEoa:!0,chainId:_nullishCoalesce(a, () => ("all")),eoaAddress:e})).map(o=>({name:o.name,symbol:o.symbol,decimals:o.decimals,address:_chunk74WA35RIcjs.e.call(void 0, o.token,"ETH")?_chunk74WA35RIcjs.b.address:o.token,logoURI:o.logoUri,balance:{raw:o.amount.toString(),formatted:_viem.formatUnits.call(void 0, BigInt(o.amount),o.decimals)},chainId:Number(o.chainId),price:Number(o.price)})),s=Object.groupBy(u,o=>_nullishCoalesce(o.chainId, () => (0))),l=await Promise.allSettled(Object.entries(s).map(async([o,i])=>{if(!i)return;let p=_core.getChains.call(void 0, t).find(d=>d.id===Number(o));if(!p)return;let k=_optionalChain([p, 'access', _5 => _5.contracts, 'optionalAccess', _6 => _6.multicall3, 'optionalAccess', _7 => _7.address]);if(!k)return _chunk2YBHAMDVcjs.g.captureException(new (0, _chunkNMH7LHPWcjs.h)({property:"multicallAddress",value:k,expected:"Address",chainId:Number(o)})),i;let f=await _core.multicall.call(void 0, t,{chainId:Number(o),contracts:i.map(d=>_chunkGO5E7UUDcjs.b.call(void 0, {token:d,account:e,multicallAddress:k})),allowFailure:!0}),x=[];for(let d=0;d<i.length;d++){let T=i[d];if(f[d].status==="success"){let C=f[d].result;x.push({...T,balance:{raw:_nullishCoalesce(_optionalChain([C, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]), () => ("0")),formatted:_viem.formatUnits.call(void 0, _nullishCoalesce(C, () => (0n)),T.decimals)}})}else console.error("error getting balance",f[d].error),_chunk2YBHAMDVcjs.g.captureException(_chunk2YBHAMDVcjs.a.call(void 0, {cause:f[d].error})),x.push(T)}return x})),c=[];for(let o of l)o.status==="fulfilled"?c.push(..._nullishCoalesce(o.value, () => ([]))):_chunk2YBHAMDVcjs.g.captureException(_chunk2YBHAMDVcjs.a.call(void 0, {cause:o.reason}));return c.sort((o,i)=>{let p=Number(o.balance.formatted)*(_nullishCoalesce(o.price, () => (0)));return Number(i.balance.formatted)*(_nullishCoalesce(i.price, () => (0)))-p})}function A({chainId:e}={},t){let{address:a}=_hooks.useBeraWallet.call(void 0, ),n=_hooks.useConfig.call(void 0, ),r=!!a&&(_nullishCoalesce(_optionalChain([t, 'optionalAccess', _10 => _10.opts, 'optionalAccess', _11 => _11.isEnabled]), () => (!0))),s=_swr2.default.call(void 0, r&&n?["useEnsoUserTokensWithBalances",a,e]:null,async([,l,c])=>R({account:l,wagmiConfig:n,chainId:_nullishCoalesce(c, () => ("all")),ensoClient:_chunkGO5E7UUDcjs.a.call(void 0, )}),{refreshInterval:1e5,isEnabled:r,..._optionalChain([t, 'optionalAccess', _12 => _12.opts])});return{...s,refresh:()=>s.mutate()}}function H({defaultTokenList:e=[],externalList:t=[]}){if(e.length===0)return{tokenList:t,customTokenList:t,featuredTokenList:[]};let a=e.map(s=>({...s,default:!0})),n=a.filter(s=>_optionalChain([s, 'access', _13 => _13.tags, 'optionalAccess', _14 => _14.some, 'call', _15 => _15(l=>l==="featured")])),r=[...a,...t];return{tokenList:r.filter((s,l)=>r.findIndex(c=>_chunk74WA35RIcjs.e.call(void 0, c,s))===l),customTokenList:t,featuredTokenList:n}}var ie=_react.createContext.call(void 0, void 0);function je({children:e,defaultTokens:t,edgeConfigTokenList:a,userTokens:n,onAddToken:r,onRemoveToken:u}){let{data:s,refresh:l}=A(),{tokenList:c=[],featuredTokenList:o=[]}=_react.useMemo.call(void 0, ()=>H({defaultTokenList:[...t,..._optionalChain([a, 'optionalAccess', _16 => _16.filter, 'call', _17 => _17(i=>_edgeconfig.isFlagEnabled.call(void 0, i.enabled))])],externalList:[...n,...(_nullishCoalesce(s, () => ([]))).map(i=>({...i,balance:void 0,price:void 0}))]}),[t,n,a,s]);return _jsxruntime.jsx.call(void 0, ie.Provider,{value:{tokenList:c,userTokens:n,featuredTokens:o,ensoTokens:s,onAddToken(i){r(i,{defaultTokens:t,userTokens:n,tokenList:c})},onRemoveToken:u,refresh:()=>{l()}},children:e})}exports.a = pe; exports.b = D; exports.c = fe; exports.d = w; exports.e = Te; exports.f = he; exports.g = ve; exports.h = F; exports.i = Ee; exports.j = L; exports.k = Fe; exports.l = Le; exports.m = A; exports.n = ie; exports.o = je;
|
|
2
|
-
//# sourceMappingURL=chunk-2EN6PPAW.cjs.map
|