@berachain/berajs 0.1.0 → 0.1.2
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/{dex-jD95agMv.d.cts → HoneyConfigProvider-6PXZJMSU.d.cts} +172 -172
- package/dist/{dex-CxzGqVLe.d.ts → HoneyConfigProvider-CwDFrt02.d.ts} +172 -172
- package/dist/abi/index.cjs +2 -1
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.mjs +2 -1
- package/dist/abi/index.mjs.map +1 -0
- package/dist/actions/index.cjs +2 -1
- package/dist/actions/index.cjs.map +1 -0
- package/dist/actions/index.d.cts +8 -8
- package/dist/actions/index.d.ts +8 -8
- package/dist/actions/index.mjs +2 -1
- package/dist/actions/index.mjs.map +1 -0
- package/dist/chunk-22MQVFHP.cjs +2 -0
- package/dist/chunk-22MQVFHP.cjs.map +1 -0
- package/dist/chunk-3TKSVFZ3.mjs +2 -0
- package/dist/chunk-3TKSVFZ3.mjs.map +1 -0
- package/dist/chunk-6VF3RF53.cjs +3 -0
- package/dist/chunk-6VF3RF53.cjs.map +1 -0
- package/dist/{chunk-2422CKAT.mjs → chunk-6W22TFYA.mjs} +2 -1
- package/dist/chunk-6W22TFYA.mjs.map +1 -0
- package/dist/chunk-AMRJ4B36.mjs +2 -0
- package/dist/chunk-AMRJ4B36.mjs.map +1 -0
- package/dist/{chunk-4IBBLGNS.mjs → chunk-DS2ZDVKU.mjs} +1 -0
- package/dist/chunk-DS2ZDVKU.mjs.map +1 -0
- package/dist/{chunk-B47PDJZM.cjs → chunk-ED43NYSE.cjs} +2 -1
- package/dist/chunk-ED43NYSE.cjs.map +1 -0
- package/dist/chunk-EU4WFADK.cjs +2 -0
- package/dist/chunk-EU4WFADK.cjs.map +1 -0
- package/dist/{chunk-ASRHUDAH.mjs → chunk-HCTFDGXL.mjs} +1 -0
- package/dist/chunk-HCTFDGXL.mjs.map +1 -0
- package/dist/{chunk-K4NZIO2Z.mjs → chunk-IOSYBHKU.mjs} +1 -0
- package/dist/chunk-IOSYBHKU.mjs.map +1 -0
- package/dist/{chunk-4GY57XKG.cjs → chunk-JMKLDDKY.cjs} +1 -0
- package/dist/chunk-JMKLDDKY.cjs.map +1 -0
- package/dist/chunk-KMKUXP2S.mjs +3 -0
- package/dist/chunk-KMKUXP2S.mjs.map +1 -0
- package/dist/chunk-OJXJ6CZ4.mjs +4 -0
- package/dist/chunk-OJXJ6CZ4.mjs.map +1 -0
- package/dist/{chunk-VA37UBED.mjs → chunk-PHIOKO3A.mjs} +2 -1
- package/dist/chunk-PHIOKO3A.mjs.map +1 -0
- package/dist/{chunk-IKAE7CQU.cjs → chunk-QCK474XD.cjs} +1 -0
- package/dist/chunk-QCK474XD.cjs.map +1 -0
- package/dist/chunk-REDXXUK7.cjs +2 -0
- package/dist/chunk-REDXXUK7.cjs.map +1 -0
- package/dist/{chunk-K2FCHQHA.cjs → chunk-S74ZMG2G.cjs} +2 -1
- package/dist/chunk-S74ZMG2G.cjs.map +1 -0
- package/dist/{chunk-NOV7UCGA.cjs → chunk-TOAXF4YW.cjs} +1 -0
- package/dist/chunk-TOAXF4YW.cjs.map +1 -0
- package/dist/chunk-UZ5CB33M.cjs +2 -0
- package/dist/chunk-UZ5CB33M.cjs.map +1 -0
- package/dist/chunk-VYWYJR63.mjs +2 -0
- package/dist/chunk-VYWYJR63.mjs.map +1 -0
- package/dist/{chunk-WZLPSG5R.cjs → chunk-XFPTQMAK.cjs} +3 -2
- package/dist/chunk-XFPTQMAK.cjs.map +1 -0
- package/dist/chunk-YK4NINF5.mjs +2 -0
- package/dist/chunk-YK4NINF5.mjs.map +1 -0
- package/dist/contexts/index.cjs +2 -1
- package/dist/contexts/index.cjs.map +1 -0
- package/dist/contexts/index.d.cts +7 -5
- package/dist/contexts/index.d.ts +7 -5
- package/dist/contexts/index.mjs +2 -1
- package/dist/contexts/index.mjs.map +1 -0
- package/dist/enum/index.cjs +2 -1
- package/dist/enum/index.cjs.map +1 -0
- package/dist/enum/index.d.cts +1 -1
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.mjs +2 -1
- package/dist/enum/index.mjs.map +1 -0
- package/dist/errors/index.cjs +2 -1
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.mjs +2 -1
- package/dist/errors/index.mjs.map +1 -0
- package/dist/{getValidatorQueuedOperatorAddress-9jSXlAse.d.ts → getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-BCYlvah3.d.cts → getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts} +2 -2
- package/dist/hooks/index.cjs +3 -2
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +9 -9
- package/dist/hooks/index.d.ts +9 -9
- package/dist/hooks/index.mjs +3 -2
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/{staking-Bw46L2PT.d.ts → staking-F9Nx9TKD.d.ts} +1 -1
- package/dist/{staking-BxYDlMtj.d.cts → staking-f4BpYH7l.d.cts} +1 -1
- package/dist/{txnEnum-Diichv9Z.d.cts → txnEnum-BQKDfaeH.d.cts} +1 -0
- package/dist/{txnEnum-Diichv9Z.d.ts → txnEnum-BQKDfaeH.d.ts} +1 -0
- package/dist/types/index.cjs +2 -1
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +5 -5
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.mjs +2 -1
- package/dist/types/index.mjs.map +1 -0
- package/dist/{useHoneySwapState-YfMSTWY3.d.cts → useHoneySwapState-C-9BV4VB.d.cts} +1 -1
- package/dist/{useHoneySwapState-CD8v6y1k.d.ts → useHoneySwapState-CUY5Sm1b.d.ts} +1 -1
- package/dist/utils/index.cjs +2 -1
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +5 -5
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.mjs +2 -1
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +4 -3
- package/src/abi/bend/bundler.ts +60 -0
- package/src/abi/bend/generalAdapter.ts +362 -0
- package/src/abi/bend/metaMorpho.ts +2584 -0
- package/src/abi/bend/morpho.ts +444 -0
- package/src/abi/bend/morphoVault.ts +1456 -0
- package/src/abi/bend/publicAllocator.ts +355 -0
- package/src/abi/bex/aggregatorsRouter.ts +492 -0
- package/src/abi/bex/balancerComposableStablePoolFactoryV6.ts +283 -0
- package/src/abi/bex/balancerPoolCreationHelper.ts +267 -0
- package/src/abi/bex/balancerVault.ts +757 -0
- package/src/abi/enso/ensoRouterAbi.ts +140 -0
- package/src/abi/governance/governance.ts +1016 -0
- package/src/abi/governance/governanceTimelock.ts +589 -0
- package/src/abi/honey/collateralVault.ts +1144 -0
- package/src/abi/honey/honey.ts +563 -0
- package/src/abi/honey/honeyFactory.ts +1270 -0
- package/src/abi/honey/honeyFactoryReader.ts +894 -0
- package/src/abi/honey/honeyRootOracle.ts +492 -0
- package/src/abi/honey/pythPriceOracle.ts +619 -0
- package/src/abi/honey/pythWrapper.ts +446 -0
- package/src/abi/index.ts +35 -0
- package/src/abi/pol/beaconDeposit.ts +595 -0
- package/src/abi/pol/beraChef.ts +1019 -0
- package/src/abi/pol/bgt.ts +1008 -0
- package/src/abi/pol/bgtIncentiveDistributor.ts +640 -0
- package/src/abi/pol/bgtStaker.ts +1034 -0
- package/src/abi/pol/rewardAllocationFactory.ts +408 -0
- package/src/abi/pol/rewardVault.ts +1928 -0
- package/src/abi/pol/rewardVaultFactory.ts +586 -0
- package/src/abi/pol/rewardVaultHelper.ts +882 -0
- package/src/abi/pol/stakeBeraVault.ts +1116 -0
- package/src/abi/pol/stakeBeraVaultWithdrawalRequest.ts +618 -0
- package/src/abi/pol/wbera.ts +366 -0
- package/src/abi/pyth/pyth.ts +566 -0
- package/src/abi/pyth/pythErrors.ts +72 -0
- package/src/abi/utils/EIP7702StatelessDelegator.ts +523 -0
- package/src/abi/utils/bundler3errors.ts +6 -0
- package/src/abi/utils/commonAbiErrors.ts +9 -0
- package/src/abi/utils/erc20errors.ts +74 -0
- package/src/abi/utils/merkleDistributor.ts +838 -0
- package/src/abi/utils/multicall3.ts +242 -0
- package/src/abi/utils/openChainErrors.ts +139 -0
- package/src/abi/utils/upgradableBeacon.ts +86 -0
- package/src/actions/bend/getConvertToAssets.ts +23 -0
- package/src/actions/bend/getMaxDeposit.ts +21 -0
- package/src/actions/clients/BeraApolloClient.ts +125 -0
- package/src/actions/clients/getApolloClient.ts +109 -0
- package/src/actions/clients/getEnsoClient.ts +24 -0
- package/src/actions/dex/__tests__/aggregators.unit.test.ts +112 -0
- package/src/actions/dex/__tests__/allPools.integration.test.ts +13 -0
- package/src/actions/dex/__tests__/getOnChainPool.unit.test.ts +15 -0
- package/src/actions/dex/__tests__/haiku.integration.test.ts +40 -0
- package/src/actions/dex/aggregators/base.ts +174 -0
- package/src/actions/dex/aggregators/bex.ts +255 -0
- package/src/actions/dex/aggregators/bgt.ts +50 -0
- package/src/actions/dex/aggregators/enso.ts +113 -0
- package/src/actions/dex/aggregators/fly.ts +136 -0
- package/src/actions/dex/aggregators/haiku.ts +171 -0
- package/src/actions/dex/aggregators/honey.ts +245 -0
- package/src/actions/dex/aggregators/kyberswap.ts +142 -0
- package/src/actions/dex/aggregators/oogabooga.ts +110 -0
- package/src/actions/dex/aggregators/openOcean.ts +142 -0
- package/src/actions/dex/aggregators/wbera.ts +72 -0
- package/src/actions/dex/b-sdk.ts +48 -0
- package/src/actions/dex/getAllPools.ts +60 -0
- package/src/actions/dex/getApiPool.ts +47 -0
- package/src/actions/dex/getGlobalLiquidityAndSwapVolume.ts +29 -0
- package/src/actions/dex/getIsTokenExploited.ts +63 -0
- package/src/actions/dex/getOnChainPool.ts +216 -0
- package/src/actions/dex/getPoolEvents.ts +35 -0
- package/src/actions/dex/getPoolHistoricalData.ts +51 -0
- package/src/actions/dex/getPoolPausedState.ts +40 -0
- package/src/actions/dex/getPoolWithState.ts +24 -0
- package/src/actions/dex/getSubgraphPool.ts +30 -0
- package/src/actions/dex/getTransactionCount.ts +29 -0
- package/src/actions/dex/getVaultPausedState.ts +21 -0
- package/src/actions/enso/bend.ts +143 -0
- package/src/actions/enso/getEnsoUserToken.debug.test.ts +57 -0
- package/src/actions/enso/getEnsoUserToken.ts +133 -0
- package/src/actions/enso/util.ts +60 -0
- package/src/actions/enso/zap.ts +78 -0
- package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +108 -0
- package/src/actions/governance/__tests__/getDecodedFunctionData.integration.test.ts +127 -0
- package/src/actions/governance/__tests__/getQuorum.integration.test.ts +39 -0
- package/src/actions/governance/checkProposalField.ts +211 -0
- package/src/actions/governance/computeActualStatus.ts +154 -0
- package/src/actions/governance/constants.ts +7 -0
- package/src/actions/governance/getAllProposals.ts +75 -0
- package/src/actions/governance/getBodyErrors.ts +28 -0
- package/src/actions/governance/getDecodedFunctionData.ts +170 -0
- package/src/actions/governance/getProposalDetails.ts +40 -0
- package/src/actions/governance/getProposalFromTx.ts +101 -0
- package/src/actions/governance/getProposalParams.ts +247 -0
- package/src/actions/governance/getProposalVotes.ts +20 -0
- package/src/actions/governance/getQuorum.ts +38 -0
- package/src/actions/governance/parseProposalBody.ts +73 -0
- package/src/actions/honey/getChartData.ts +27 -0
- package/src/actions/honey/getCollateralWeights.ts +50 -0
- package/src/actions/honey/getGlobalCapLimit.ts +148 -0
- package/src/actions/honey/getHoneyCollaterals.ts +139 -0
- package/src/actions/honey/getHoneyFees.ts +100 -0
- package/src/actions/honey/getHoneyGlobalData.ts +21 -0
- package/src/actions/honey/getHoneyPausedState.ts +25 -0
- package/src/actions/honey/getHoneyPreview.ts +152 -0
- package/src/actions/honey/getHoneyPythPriceOracle.ts +21 -0
- package/src/actions/honey/getHoneyRootPriceOracle.ts +23 -0
- package/src/actions/honey/getHoneyVaultsBalance.ts +86 -0
- package/src/actions/honey/getPythLatestPrices.ts +54 -0
- package/src/actions/honey/getRelativeCapLimit.ts +83 -0
- package/src/actions/honey/getSharesWithoutFees.ts +65 -0
- package/src/actions/honey/getSwapPayload.ts +128 -0
- package/src/actions/honey/isBadCollateralAsset.ts +77 -0
- package/src/actions/honey/isBasketModeEnabled.ts +47 -0
- package/src/actions/honey/tests/pyth.integration.test.ts +63 -0
- package/src/actions/index.ts +105 -0
- package/src/actions/misc/getBlockTimestamp.ts +41 -0
- package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +55 -0
- package/src/actions/pol/__tests__/getValidator.integration.test.ts +32 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +34 -0
- package/src/actions/pol/getBGTGlobalInfo.ts +43 -0
- package/src/actions/pol/getBgtAprSimulation.ts +207 -0
- package/src/actions/pol/getBgtAprSimultaion.unit.test.ts +297 -0
- package/src/actions/pol/getBgtTokenTotalBoosts.ts +30 -0
- package/src/actions/pol/getBgtTokenTotalSupply.ts +29 -0
- package/src/actions/pol/getBlockTime.ts +43 -0
- package/src/actions/pol/getGlobalCuttingBoard.ts +25 -0
- package/src/actions/pol/getGlobalData.ts +74 -0
- package/src/actions/pol/getIncentiveFeeClaimStats.ts +43 -0
- package/src/actions/pol/getMarkets.ts +36 -0
- package/src/actions/pol/getRewardProofsByValidator.ts +49 -0
- package/src/actions/pol/getRewardTokenToBeraRate.ts +30 -0
- package/src/actions/pol/getRewardVault.ts +54 -0
- package/src/actions/pol/getRewardVaultBeaconImplementation.integration.test.ts +18 -0
- package/src/actions/pol/getRewardVaultBeaconImplementation.ts +35 -0
- package/src/actions/pol/getRewardVaultDurationConstants.integration.test.ts +24 -0
- package/src/actions/pol/getRewardVaultDurationConstants.ts +45 -0
- package/src/actions/pol/getRewardVaultFromToken.ts +30 -0
- package/src/actions/pol/getRewardVaultIncentives.ts +122 -0
- package/src/actions/pol/getRewardVaultRewards.ts +109 -0
- package/src/actions/pol/getRewardVaultStakingToken.ts +19 -0
- package/src/actions/pol/getRewardVaults.ts +106 -0
- package/src/actions/pol/getSWBeraVaultMetadata.ts +166 -0
- package/src/actions/pol/getSWBeraWithdrawal.ts +165 -0
- package/src/actions/pol/getStakeWithdrawalCooldown.ts +21 -0
- package/src/actions/pol/getStakedBeraAPR.ts +56 -0
- package/src/actions/pol/getStakedBeraSnapshots.ts +48 -0
- package/src/actions/pol/getStakingTokenInformation.ts +60 -0
- package/src/actions/pol/getUserClaimableIncentives.ts +40 -0
- package/src/actions/pol/getUserVaultInfo.ts +52 -0
- package/src/actions/pol/getUserVaults.ts +185 -0
- package/src/actions/pol/getUserVaultsBalance.ts +54 -0
- package/src/actions/pol/getUserVaultsReward.ts +32 -0
- package/src/actions/pol/getVaultHistory.ts +43 -0
- package/src/actions/pol/getVaultValidators.ts +31 -0
- package/src/actions/pol/getVaultsSupply.ts +28 -0
- package/src/actions/prices/__tests__/prices.integration.test.ts +29 -0
- package/src/actions/prices/getTokenCurrentPrices.ts +79 -0
- package/src/actions/pyth/getHoneyPythFeeds.ts +46 -0
- package/src/actions/pyth/getUpdateFee.ts +27 -0
- package/src/actions/tokens/getAllowances.ts +59 -0
- package/src/actions/tokens/getTokenInformation.ts +57 -0
- package/src/actions/tokens/getTokens.ts +19 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +40 -0
- package/src/actions/tokens/getWalletBalances.ts +123 -0
- package/src/actions/transactions/beraWriteContract.integration.test.ts +251 -0
- package/src/actions/transactions/beraWriteContract.ts +722 -0
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.integration.test.ts +40 -0
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.ts +109 -0
- package/src/actions/validators/getAllValidators.ts +33 -0
- package/src/actions/validators/getApiEnrichedAllocation.ts +33 -0
- package/src/actions/validators/getApiValidator.ts +38 -0
- package/src/actions/validators/getBaselineRewardAllocation.ts +26 -0
- package/src/actions/validators/getDailyValidatorBlockStats.ts +37 -0
- package/src/actions/validators/getDefaultRewardAllocation.ts +39 -0
- package/src/actions/validators/getManagedValidatorByAccount.ts +32 -0
- package/src/actions/validators/getStakingPoolBatch.ts +20 -0
- package/src/actions/validators/getUserActiveValidators.ts +101 -0
- package/src/actions/validators/getUserBoosts.ts +28 -0
- package/src/actions/validators/getUserBoostsOnValidator.ts +70 -0
- package/src/actions/validators/getUserStakingPositions.ts +225 -0
- package/src/actions/validators/getValidatorAnalytics.ts +34 -0
- package/src/actions/validators/getValidatorCommission.ts +24 -0
- package/src/actions/validators/getValidatorEstimatedBgtPerYear.ts +25 -0
- package/src/actions/validators/getValidatorOperatorAddress.ts +27 -0
- package/src/actions/validators/getValidatorQueuedCommission.ts +30 -0
- package/src/actions/validators/getValidatorQueuedOperatorAddress.ts +32 -0
- package/src/actions/validators/getValidatorQueuedRewardAllocation.ts +31 -0
- package/src/actions/validators/getValidatorRewardAllocation.ts +158 -0
- package/src/actions/validators/getValidatorRewardAllocatorAddress.ts +38 -0
- package/src/actions/validators/utils/__tests__/validatorUtils.integration.test.ts +36 -0
- package/src/actions/validators/utils/getValidatorBoostApy.ts +59 -0
- package/src/contexts/BeraFlags/BeraFlags.tsx +69 -0
- package/src/contexts/BeraFlags/defaultFlags.ts +42 -0
- package/src/contexts/BexStatusProvider.tsx +125 -0
- package/src/contexts/HoneyConfigProvider.tsx +73 -0
- package/src/contexts/SwrFallback.tsx +34 -0
- package/src/contexts/TokensProvider.tsx +66 -0
- package/src/contexts/berajsProvider/context.tsx +49 -0
- package/src/contexts/berajsProvider/index.ts +2 -0
- package/src/contexts/berajsProvider/useBeraJs.ts +18 -0
- package/src/contexts/block-time-provider.tsx +34 -0
- package/src/contexts/index.ts +14 -0
- package/src/data/contracts.ts +398 -0
- package/src/enum/dex.ts +10 -0
- package/src/enum/index.ts +4 -0
- package/src/enum/polling.ts +8 -0
- package/src/enum/slippage.ts +19 -0
- package/src/enum/txnEnum.ts +101 -0
- package/src/errors/BeraError.ts +202 -0
- package/src/errors/InvalidArgumentError.ts +81 -0
- package/src/errors/NotFoundError.ts +34 -0
- package/src/errors/RequestError.ts +207 -0
- package/src/errors/TransactionFailedError.ts +93 -0
- package/src/errors/assert.ts +144 -0
- package/src/errors/assert.unit.test.ts +110 -0
- package/src/errors/errorMap.ts +1157 -0
- package/src/errors/getErrorMessage.ts +40 -0
- package/src/errors/getRevertReason.integration.test.ts +449 -0
- package/src/errors/getRevertReason.ts +179 -0
- package/src/errors/index.ts +8 -0
- package/src/errors/initBeraError.ts +46 -0
- package/src/errors/parseViemError.ts +239 -0
- package/src/hooks/bend/useGetConvertToAssets.ts +42 -0
- package/src/hooks/dex/useAggregatorsQuotes.ts +502 -0
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +34 -0
- package/src/hooks/dex/useAllUserPools.ts +38 -0
- package/src/hooks/dex/useApiPool.ts +53 -0
- package/src/hooks/dex/useBexStatus.ts +1 -0
- package/src/hooks/dex/useCreatePool.ts +437 -0
- package/src/hooks/dex/useExploitedTokens.ts +57 -0
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +22 -0
- package/src/hooks/dex/useLiquidityMismatch.ts +195 -0
- package/src/hooks/dex/useLpPosition.ts +115 -0
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +92 -0
- package/src/hooks/dex/useOnChainPoolData.ts +126 -0
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +54 -0
- package/src/hooks/dex/usePollVaultIsPaused.ts +30 -0
- package/src/hooks/dex/usePool.ts +59 -0
- package/src/hooks/dex/usePoolEvents.ts +22 -0
- package/src/hooks/dex/usePoolHistoricalData.ts +44 -0
- package/src/hooks/dex/usePools.ts +83 -0
- package/src/hooks/enso/useBendTransactionRequests.ts +247 -0
- package/src/hooks/enso/useEnsoZap.ts +166 -0
- package/src/hooks/enso/useZapTransactionRequests.ts +81 -0
- package/src/hooks/governance/useCreateProposal.ts +88 -0
- package/src/hooks/governance/useGetPastVotes.ts +63 -0
- package/src/hooks/governance/useHasVoted.ts +38 -0
- package/src/hooks/governance/useIsCanceller.ts +43 -0
- package/src/hooks/governance/usePollAllProposals.ts +232 -0
- package/src/hooks/governance/usePollProposal.ts +96 -0
- package/src/hooks/governance/usePollProposalThreshold.ts +41 -0
- package/src/hooks/governance/usePollProposalVotes.ts +64 -0
- package/src/hooks/governance/usePollUserDelegates.ts +70 -0
- package/src/hooks/governance/useProposalFromTx.ts +37 -0
- package/src/hooks/governance/useProposalSnapshot.ts +44 -0
- package/src/hooks/governance/useProposalState.ts +48 -0
- package/src/hooks/governance/useProposalTimelockState.ts +61 -0
- package/src/hooks/governance/useQuorum.ts +42 -0
- package/src/hooks/honey/useCappedGlobally.ts +92 -0
- package/src/hooks/honey/useCappedRelatively.ts +88 -0
- package/src/hooks/honey/useCollateralWeights.ts +48 -0
- package/src/hooks/honey/useHoneyAlerts.ts +314 -0
- package/src/hooks/honey/useHoneyBalances.ts +79 -0
- package/src/hooks/honey/useHoneyChartData.ts +17 -0
- package/src/hooks/honey/useHoneyGlobalData.ts +22 -0
- package/src/hooks/honey/useHoneySwapState.ts +202 -0
- package/src/hooks/honey/useHoneyVaultsBalance.ts +41 -0
- package/src/hooks/honey/useIsBadCollateralAsset.ts +73 -0
- package/src/hooks/honey/useIsBasketModeEnabled.ts +70 -0
- package/src/hooks/honey/usePythLatestPrices.ts +41 -0
- package/src/hooks/index.ts +124 -0
- package/src/hooks/perps/usePythUpdateFee.ts +43 -0
- package/src/hooks/pol/useBgtAprSimulation.ts +22 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +50 -0
- package/src/hooks/pol/useClaimableFees.ts +38 -0
- package/src/hooks/pol/useEarnedStakedBeraVault.ts +59 -0
- package/src/hooks/pol/useHighestVaultsAPR.ts +57 -0
- package/src/hooks/pol/useOnChainRewardVault.ts +114 -0
- package/src/hooks/pol/usePollGlobalData.ts +31 -0
- package/src/hooks/pol/usePollMarkets.ts +32 -0
- package/src/hooks/pol/useQueuedBeraUnlock.ts +70 -0
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +45 -0
- package/src/hooks/pol/useRewardVault.ts +51 -0
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +82 -0
- package/src/hooks/pol/useRewardVaultFromToken.ts +58 -0
- package/src/hooks/pol/useRewardVaultIncentives.ts +37 -0
- package/src/hooks/pol/useRewardVaultRewards.ts +37 -0
- package/src/hooks/pol/useRewardVaults.ts +45 -0
- package/src/hooks/pol/useStakedBeraSnapshots.ts +27 -0
- package/src/hooks/pol/useUserVaultInfo.ts +46 -0
- package/src/hooks/pol/useUserVaults.ts +40 -0
- package/src/hooks/pol/useVaultAddress.ts +31 -0
- package/src/hooks/pol/useVaultHistory.ts +29 -0
- package/src/hooks/pol/useVaultValidators.ts +33 -0
- package/src/hooks/tokens/useBeraCurrentPrice.ts +12 -0
- package/src/hooks/tokens/useMultipleTokenInformation.ts +62 -0
- package/src/hooks/tokens/usePollAllowances.ts +60 -0
- package/src/hooks/tokens/usePollBalance.ts +113 -0
- package/src/hooks/tokens/usePollWalletBalances.ts +75 -0
- package/src/hooks/tokens/useStakingTokenInformation.ts +54 -0
- package/src/hooks/tokens/useTokenCurrentPrice.ts +19 -0
- package/src/hooks/tokens/useTokenCurrentPrices.ts +57 -0
- package/src/hooks/tokens/useTokenInformation.ts +59 -0
- package/src/hooks/tokens/useTokens.ts +26 -0
- package/src/hooks/tokens/useTotalSupply.ts +22 -0
- package/src/hooks/transactions/TransactionStoreContext.tsx +59 -0
- package/src/hooks/transactions/transactionStore.ts +275 -0
- package/src/hooks/transactions/transactionStore.unit.test.ts +508 -0
- package/src/hooks/transactions/useAddRecentTransaction.ts +29 -0
- package/src/hooks/transactions/useRecentTransactions.ts +27 -0
- package/src/hooks/useBlockToTimestamp.ts +51 -0
- package/src/hooks/useContractWrite/index.ts +2 -0
- package/src/hooks/useContractWrite/stateReducer.ts +60 -0
- package/src/hooks/useContractWrite/types.ts +88 -0
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +137 -0
- package/src/hooks/useGetVerifiedAbi.ts +47 -0
- package/src/hooks/useHistoryState.ts +64 -0
- package/src/hooks/usePrevious.ts +13 -0
- package/src/hooks/validators/useAllValidators.ts +48 -0
- package/src/hooks/validators/useApiEnrichedAllocation.ts +17 -0
- package/src/hooks/validators/useApiValidator.ts +37 -0
- package/src/hooks/validators/useBaselineRewardAllocation.ts +16 -0
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +35 -0
- package/src/hooks/validators/useDefaultRewardAllocation.ts +32 -0
- package/src/hooks/validators/useManagedValidatorByAccount.ts +40 -0
- package/src/hooks/validators/useManagedValidatorRole.ts +119 -0
- package/src/hooks/validators/useOnChainValidator.ts +66 -0
- package/src/hooks/validators/useStakingPoolBatch.ts +45 -0
- package/src/hooks/validators/useSubgraphUserValidators.ts +36 -0
- package/src/hooks/validators/useUserActiveValidators.ts +44 -0
- package/src/hooks/validators/useUserBoostsOnValidator.ts +45 -0
- package/src/hooks/validators/useUserClaimableIncentives.ts +149 -0
- package/src/hooks/validators/useUserStakingPositions.ts +62 -0
- package/src/hooks/validators/useValidator.ts +83 -0
- package/src/hooks/validators/useValidatorAnalytics.ts +36 -0
- package/src/hooks/validators/useValidatorCommission.ts +36 -0
- package/src/hooks/validators/useValidatorEstimatedBgtPerYear.ts +24 -0
- package/src/hooks/validators/useValidatorQueuedCommission.ts +41 -0
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +39 -0
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +37 -0
- package/src/hooks/validators/useValidatorRewardAllocation.ts +36 -0
- package/src/hooks/validators/validatorRoleManager.ts +0 -0
- package/src/types/bribe-boost.ts +50 -0
- package/src/types/dex.ts +196 -0
- package/src/types/enso.ts +42 -0
- package/src/types/global.ts +230 -0
- package/src/types/governance.ts +174 -0
- package/src/types/honeySwap.ts +35 -0
- package/src/types/index.ts +8 -0
- package/src/types/pol.ts +52 -0
- package/src/types/staking.ts +7 -0
- package/src/utils/beraFetch.ts +55 -0
- package/src/utils/constants.ts +35 -0
- package/src/utils/formatAggregatorsQuotes.ts +57 -0
- package/src/utils/formatAggregatorsQuotes.unit.test.ts +191 -0
- package/src/utils/formatIncentivesTokenMap.ts +19 -0
- package/src/utils/formatInputTokenValue.ts +12 -0
- package/src/utils/formatNumber.ts +225 -0
- package/src/utils/formatNumber.unit.test.ts +245 -0
- package/src/utils/formatTimestamps.ts +155 -0
- package/src/utils/formatTimestamps.unit.test.ts +395 -0
- package/src/utils/formatTokenList.ts +61 -0
- package/src/utils/formatUsd.ts +46 -0
- package/src/utils/getContractName.ts +27 -0
- package/src/utils/getContractName.unit.test.ts +64 -0
- package/src/utils/getErrorResponse.ts +20 -0
- package/src/utils/getHoneySwapMessage.test.ts +116 -0
- package/src/utils/getHoneySwapMessage.ts +70 -0
- package/src/utils/getServerSideClient.ts +49 -0
- package/src/utils/getTestClient.ts +19 -0
- package/src/utils/hasAnyTruthyValues.ts +17 -0
- package/src/utils/index.ts +27 -0
- package/src/utils/isDifferenceExceedingThreshold.ts +13 -0
- package/src/utils/isSubgraphStale.ts +10 -0
- package/src/utils/math.ts +28 -0
- package/src/utils/math.unit.test.ts +49 -0
- package/src/utils/parseBaseArgs.ts +23 -0
- package/src/utils/parseBaseArgs.unit.test.ts +55 -0
- package/src/utils/poolNamings.ts +54 -0
- package/src/utils/pythHoneyUtils.ts +3 -0
- package/src/utils/sentryBeforeSend.ts +52 -0
- package/src/utils/test-utils.ts +2 -0
- package/src/utils/time.ts +106 -0
- package/src/utils/time.unit.test.ts +76 -0
- package/src/utils/tokenWrapping.ts +16 -0
- package/src/utils/tokens.ts +106 -0
- package/src/utils/tokens.unit.test.ts +98 -0
- package/src/utils/truncateHash.ts +20 -0
- package/src/utils/truncateHash.unit.test.ts +19 -0
- package/src/utils/validatorUptimeStatus.ts +30 -0
- package/dist/chunk-3V2MGZRD.mjs +0 -2
- package/dist/chunk-4E5JGLUM.cjs +0 -1
- package/dist/chunk-AHAZC5K3.mjs +0 -1
- package/dist/chunk-ELUMRVNE.mjs +0 -1
- package/dist/chunk-JHCSZSJS.mjs +0 -1
- package/dist/chunk-KIA6GUIN.cjs +0 -1
- package/dist/chunk-LX5CM4Y6.cjs +0 -1
- package/dist/chunk-LZPBQLKP.mjs +0 -3
- package/dist/chunk-M5BKM52U.cjs +0 -1
- package/dist/chunk-MTBICGRP.mjs +0 -1
- package/dist/chunk-WDFIETJS.cjs +0 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Abi,
|
|
3
|
+
ContractFunctionArgs,
|
|
4
|
+
ContractFunctionName,
|
|
5
|
+
Hex,
|
|
6
|
+
TransactionReceipt,
|
|
7
|
+
WalletCallReceipt,
|
|
8
|
+
} from "viem";
|
|
9
|
+
|
|
10
|
+
import type { BeraError } from "~/errors/BeraError";
|
|
11
|
+
import type { IContractWrite, IContractWriteFn } from "~/types/global";
|
|
12
|
+
|
|
13
|
+
export interface UseContractWriteApi {
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
isSubmitting: boolean;
|
|
16
|
+
isSuccess: boolean;
|
|
17
|
+
isError: boolean;
|
|
18
|
+
write: IContractWriteFn;
|
|
19
|
+
reset: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type PropagatedArgs<args> = Omit<args, TxnEventKeys | "contractName"> & {
|
|
23
|
+
contractName?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type TxnEventKeys =
|
|
27
|
+
| "onSuccess"
|
|
28
|
+
| "onError"
|
|
29
|
+
| "onLoading"
|
|
30
|
+
| "onSubmission"
|
|
31
|
+
| "onWarning";
|
|
32
|
+
export interface IUseContractWriteArgs<
|
|
33
|
+
abi extends Abi | undefined = undefined,
|
|
34
|
+
functionName extends abi extends Abi
|
|
35
|
+
? ContractFunctionName<abi>
|
|
36
|
+
: never = abi extends Abi ? ContractFunctionName<abi> : never,
|
|
37
|
+
params extends abi extends Abi
|
|
38
|
+
? ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>
|
|
39
|
+
: never = abi extends Abi
|
|
40
|
+
? ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>
|
|
41
|
+
: never,
|
|
42
|
+
> {
|
|
43
|
+
onSuccess?: (
|
|
44
|
+
receipts:
|
|
45
|
+
| TransactionReceipt
|
|
46
|
+
| WalletCallReceipt<bigint, "success" | "reverted">,
|
|
47
|
+
/**
|
|
48
|
+
* Arguments that were used to call the write function.
|
|
49
|
+
*/
|
|
50
|
+
writeArgs: PropagatedArgs<IContractWrite<abi, functionName, params>>,
|
|
51
|
+
) => void;
|
|
52
|
+
onError?: (
|
|
53
|
+
e: BeraError,
|
|
54
|
+
/**
|
|
55
|
+
* Arguments that were used to call the write function.
|
|
56
|
+
*/
|
|
57
|
+
writeArgs: PropagatedArgs<IContractWrite<abi, functionName, params>>,
|
|
58
|
+
) => void;
|
|
59
|
+
onLoading?: (
|
|
60
|
+
/**
|
|
61
|
+
* Arguments that were used to call the write function.
|
|
62
|
+
*/
|
|
63
|
+
writeArgs: PropagatedArgs<IContractWrite<abi, functionName, params>>,
|
|
64
|
+
) => void;
|
|
65
|
+
onSubmission?: (
|
|
66
|
+
/**
|
|
67
|
+
* @param args.id If request is a batch call, this will be the id of the request to the wallet provider
|
|
68
|
+
* @param args.txHash If request is a single transaction, this will be the hash of the transaction to wait for
|
|
69
|
+
*/
|
|
70
|
+
args:
|
|
71
|
+
| { txHash: Hex; id?: never }
|
|
72
|
+
| {
|
|
73
|
+
id: string;
|
|
74
|
+
txHash?: never;
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Arguments that were used to call the write function.
|
|
78
|
+
*/
|
|
79
|
+
writeArgs: PropagatedArgs<IContractWrite<abi, functionName, params>>,
|
|
80
|
+
) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback function executed when a transaction encounters a warning. Transaction will still be submitted.
|
|
83
|
+
*/
|
|
84
|
+
onWarning?: (
|
|
85
|
+
e: BeraError,
|
|
86
|
+
writeArgs: Omit<IContractWrite<abi, functionName, params>, TxnEventKeys>,
|
|
87
|
+
) => void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useCallback, useReducer } from "react";
|
|
2
|
+
import type { Abi, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
3
|
+
|
|
4
|
+
import { useBeraWagmi, useConfig } from "@berachain/wagmi/hooks";
|
|
5
|
+
|
|
6
|
+
import { beraWriteContract } from "~/actions/transactions/beraWriteContract";
|
|
7
|
+
import { useBeraFlag } from "~/contexts/BeraFlags/BeraFlags";
|
|
8
|
+
import { TransactionFailedError } from "~/errors/TransactionFailedError";
|
|
9
|
+
import type { IContractWrite } from "~/types/global";
|
|
10
|
+
import { ActionEnum, initialState, reducer } from "./stateReducer";
|
|
11
|
+
import type { IUseContractWriteArgs, UseContractWriteApi } from "./types";
|
|
12
|
+
|
|
13
|
+
function useBeraContractWrite({
|
|
14
|
+
onlyPermissionless,
|
|
15
|
+
onSuccess,
|
|
16
|
+
onError,
|
|
17
|
+
onLoading,
|
|
18
|
+
onWarning,
|
|
19
|
+
onSubmission,
|
|
20
|
+
}: IUseContractWriteArgs & {
|
|
21
|
+
/**
|
|
22
|
+
* Whether to allow only permissionless transactions.
|
|
23
|
+
*
|
|
24
|
+
* This is useful when UI is reading data for another account compared to the connected account.
|
|
25
|
+
*/
|
|
26
|
+
onlyPermissionless?: boolean;
|
|
27
|
+
} = {}): UseContractWriteApi {
|
|
28
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
29
|
+
|
|
30
|
+
const { account, onSmartAccountRejection } = useBeraWagmi();
|
|
31
|
+
const wagmiConfig = useConfig();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* We are using a longer timeout for wallets with EIP-7702 (safe wallet) because it takes longer to confirm the transaction.
|
|
35
|
+
* 10 minutes for safe wallets
|
|
36
|
+
* 2 minutes for EOA wallets
|
|
37
|
+
* */
|
|
38
|
+
const txConfirmationTimeout = account?.wallet?.isContract
|
|
39
|
+
? 60_000 * 10
|
|
40
|
+
: 120_000;
|
|
41
|
+
|
|
42
|
+
// Reset the state of the hook to the initial state
|
|
43
|
+
const reset = useCallback(() => {
|
|
44
|
+
dispatch({ type: ActionEnum.RESET });
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
const enableSimulateCalls = useBeraFlag("enableSimulateCalls");
|
|
48
|
+
|
|
49
|
+
const write = useCallback(
|
|
50
|
+
<
|
|
51
|
+
abi extends Abi | undefined = undefined,
|
|
52
|
+
functionName extends abi extends Abi
|
|
53
|
+
? ContractFunctionName<abi>
|
|
54
|
+
: never = abi extends Abi ? ContractFunctionName<abi> : never,
|
|
55
|
+
params extends abi extends Abi
|
|
56
|
+
? ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>
|
|
57
|
+
: never = abi extends Abi
|
|
58
|
+
? ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>
|
|
59
|
+
: never,
|
|
60
|
+
>(
|
|
61
|
+
writeArgs: IContractWrite<abi, functionName, params>,
|
|
62
|
+
) => {
|
|
63
|
+
if (onlyPermissionless && !writeArgs.permissionless) {
|
|
64
|
+
const er = new TransactionFailedError({
|
|
65
|
+
message:
|
|
66
|
+
"Trying to send a non-permissionless transaction with an overridden account",
|
|
67
|
+
displayMessage:
|
|
68
|
+
"You can't send this transaction with an overridden account. Please reset the account in the settings popover.",
|
|
69
|
+
level: "info",
|
|
70
|
+
input: writeArgs,
|
|
71
|
+
});
|
|
72
|
+
onWarning?.(er, writeArgs);
|
|
73
|
+
onError?.(er, writeArgs);
|
|
74
|
+
|
|
75
|
+
throw er;
|
|
76
|
+
}
|
|
77
|
+
return beraWriteContract({
|
|
78
|
+
wagmiConfig,
|
|
79
|
+
...(writeArgs as IContractWrite),
|
|
80
|
+
txConfirmationTimeout,
|
|
81
|
+
enableSimulateCalls,
|
|
82
|
+
onLoading(...args) {
|
|
83
|
+
dispatch({ type: ActionEnum.LOADING });
|
|
84
|
+
// can't use ...args because of typing issues
|
|
85
|
+
writeArgs.onLoading?.(writeArgs);
|
|
86
|
+
onLoading?.(...args);
|
|
87
|
+
},
|
|
88
|
+
onWarning(...args) {
|
|
89
|
+
// can't use ...args because of typing issues
|
|
90
|
+
writeArgs.onWarning?.(args[0], writeArgs);
|
|
91
|
+
onWarning?.(...args);
|
|
92
|
+
},
|
|
93
|
+
onSubmission(...args) {
|
|
94
|
+
dispatch({ type: ActionEnum.SUBMITTING });
|
|
95
|
+
// can't use ...args because of typing issues
|
|
96
|
+
writeArgs.onSubmission?.(args[0], writeArgs);
|
|
97
|
+
onSubmission?.(...args);
|
|
98
|
+
},
|
|
99
|
+
onSuccess(...args) {
|
|
100
|
+
dispatch({ type: ActionEnum.SUCCESS });
|
|
101
|
+
// can't use ...args because of typing issues
|
|
102
|
+
writeArgs.onSuccess?.(args[0], writeArgs);
|
|
103
|
+
onSuccess?.(...args);
|
|
104
|
+
},
|
|
105
|
+
onError(...args) {
|
|
106
|
+
dispatch({ type: ActionEnum.ERROR });
|
|
107
|
+
writeArgs.onError?.(args[0], writeArgs);
|
|
108
|
+
if (args[0].reason === "AtomicReadyWalletRejectedUpgradeError") {
|
|
109
|
+
onSmartAccountRejection();
|
|
110
|
+
}
|
|
111
|
+
onError?.(...args);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
[
|
|
116
|
+
wagmiConfig,
|
|
117
|
+
onLoading,
|
|
118
|
+
onWarning,
|
|
119
|
+
onSubmission,
|
|
120
|
+
onSuccess,
|
|
121
|
+
onError,
|
|
122
|
+
onlyPermissionless,
|
|
123
|
+
enableSimulateCalls,
|
|
124
|
+
],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
isLoading: state.confirmState === "loading",
|
|
129
|
+
isSubmitting: state.confirmState === "submitting",
|
|
130
|
+
isSuccess: state.confirmState === "success",
|
|
131
|
+
isError: state.confirmState === "fail",
|
|
132
|
+
write,
|
|
133
|
+
reset,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default useBeraContractWrite;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import useSWRImmutable from "swr/immutable";
|
|
2
|
+
import { isAddress, zeroAddress } from "viem";
|
|
3
|
+
|
|
4
|
+
import { chainId } from "@berachain/config/internal";
|
|
5
|
+
|
|
6
|
+
import { beraFetchJson } from "~/utils/beraFetch";
|
|
7
|
+
|
|
8
|
+
interface SuccessResponse {
|
|
9
|
+
status: "1";
|
|
10
|
+
message: "OK";
|
|
11
|
+
result: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ErrorResponse {
|
|
15
|
+
status: "0";
|
|
16
|
+
message: "NOTOK";
|
|
17
|
+
result: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ApiResponse = SuccessResponse | ErrorResponse;
|
|
21
|
+
|
|
22
|
+
async function fetchVerifiedAbi(address: string): Promise<string> {
|
|
23
|
+
const data = await beraFetchJson<ApiResponse>({
|
|
24
|
+
url: `https://api.routescan.io/v2/network/testnet/evm/${chainId}/etherscan/api?module=contract&action=getabi&address=${address}`,
|
|
25
|
+
type: "rest",
|
|
26
|
+
name: "RouteScan",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (data.status === "0") {
|
|
30
|
+
throw new Error(data.result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return data.result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const useGetVerifiedAbi = (address?: string) => {
|
|
37
|
+
return useSWRImmutable<string>(
|
|
38
|
+
address &&
|
|
39
|
+
isAddress(address) &&
|
|
40
|
+
// Address zero can't be a contract for sure
|
|
41
|
+
address !== zeroAddress
|
|
42
|
+
? (["useGetVerifiedAbi", address] as const)
|
|
43
|
+
: null,
|
|
44
|
+
() => (address ? fetchVerifiedAbi(address) : Promise.resolve("")),
|
|
45
|
+
{},
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
type UseHistoryStateOptions<T> = {
|
|
6
|
+
key: string;
|
|
7
|
+
defaultValue: T;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* useHistoryState is a hook that allows storing state in the browser's history state
|
|
12
|
+
* it is useful for storing state that you want to persist across pages
|
|
13
|
+
* It is indexed by the key parameter to be able to store multiple states on the same page and
|
|
14
|
+
* also to not override nextjs usage of the history state
|
|
15
|
+
* @param {string} key - the key to store the state under
|
|
16
|
+
* @param {T} defaultValue - the default value to use if the state is not found
|
|
17
|
+
* @returns {T} state - the current state
|
|
18
|
+
* @returns {function} setHistoryState - a function to set the state
|
|
19
|
+
*/
|
|
20
|
+
export function useHistoryState<T>({
|
|
21
|
+
key,
|
|
22
|
+
defaultValue,
|
|
23
|
+
}: UseHistoryStateOptions<T>) {
|
|
24
|
+
// function to get current state from history
|
|
25
|
+
const getCurrentState = useCallback((): T => {
|
|
26
|
+
if (typeof window === "undefined") {
|
|
27
|
+
return defaultValue;
|
|
28
|
+
}
|
|
29
|
+
const existing = window.history.state?.[key];
|
|
30
|
+
const state = existing !== undefined ? existing : defaultValue;
|
|
31
|
+
return state;
|
|
32
|
+
}, [key, defaultValue]);
|
|
33
|
+
|
|
34
|
+
// use useState to trigger re-renders
|
|
35
|
+
const [state, setState] = useState<T>(getCurrentState());
|
|
36
|
+
|
|
37
|
+
const setHistoryState = useCallback(
|
|
38
|
+
(value: T | ((prev: T) => T)) => {
|
|
39
|
+
const currentState = getCurrentState();
|
|
40
|
+
|
|
41
|
+
const newValue = value instanceof Function ? value(currentState) : value;
|
|
42
|
+
|
|
43
|
+
const historyState = window.history.state || {};
|
|
44
|
+
const newHistoryState = { ...historyState, [key]: newValue };
|
|
45
|
+
|
|
46
|
+
// always use replaceState for updates to avoid creating new history entries
|
|
47
|
+
window.history.replaceState(newHistoryState, "");
|
|
48
|
+
setState(newValue);
|
|
49
|
+
},
|
|
50
|
+
[key, getCurrentState],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const existing = window.history.state?.[key];
|
|
55
|
+
if (existing === undefined) {
|
|
56
|
+
// if no existing state, create initial history entry
|
|
57
|
+
const currentState = window.history.state || {};
|
|
58
|
+
const newState = { ...currentState, [key]: defaultValue };
|
|
59
|
+
window.history.replaceState(newState, "");
|
|
60
|
+
}
|
|
61
|
+
}, [key, defaultValue]);
|
|
62
|
+
|
|
63
|
+
return [state, setHistoryState] as const;
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the previous value of a variable before the render
|
|
5
|
+
* @param value - the value to return the previous value for
|
|
6
|
+
*/
|
|
7
|
+
export function usePrevious<T>(value: T): T | undefined {
|
|
8
|
+
const ref = useRef<T | undefined>(undefined);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
ref.current = value;
|
|
11
|
+
});
|
|
12
|
+
return ref.current;
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
GetValidatorsQuery,
|
|
5
|
+
GetValidatorsQueryVariables,
|
|
6
|
+
GqlChain,
|
|
7
|
+
} from "@berachain/graphql/pol/api";
|
|
8
|
+
|
|
9
|
+
import { getAllValidators } from "~/actions/validators/getAllValidators";
|
|
10
|
+
import { POLLING } from "~/enum/polling";
|
|
11
|
+
import type { DefaultHookOptions, DefaultHookReturnType } from "~/types";
|
|
12
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
13
|
+
|
|
14
|
+
export const useAllValidatorsQueryKey = ({
|
|
15
|
+
variables,
|
|
16
|
+
}: {
|
|
17
|
+
variables?: GetValidatorsQueryVariables;
|
|
18
|
+
} = {}) => {
|
|
19
|
+
return ["useAllValidators", variables];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const useAllValidators = (
|
|
23
|
+
variables: GetValidatorsQueryVariables & BeraJS.BaseFunctionArgs,
|
|
24
|
+
options?: DefaultHookOptions,
|
|
25
|
+
): DefaultHookReturnType<GetValidatorsQuery | undefined> => {
|
|
26
|
+
const { config } = parseBaseArgs(variables);
|
|
27
|
+
const swrResponse = useSWR<GetValidatorsQuery | undefined>(
|
|
28
|
+
useAllValidatorsQueryKey({ variables }),
|
|
29
|
+
async ([, variables]) => {
|
|
30
|
+
const result = await getAllValidators({
|
|
31
|
+
variables: {
|
|
32
|
+
chain: config.bex.chainName as GqlChain,
|
|
33
|
+
...variables,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return result;
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
refreshInterval: POLLING.SLOW,
|
|
40
|
+
...options?.opts,
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...swrResponse,
|
|
46
|
+
refresh: () => swrResponse.mutate(),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
|
|
3
|
+
import { getApiEnrichedAllocation } from "~/actions/validators/getApiEnrichedAllocation";
|
|
4
|
+
import type { ValidatorRewardAllocation } from "~/actions/validators/getValidatorRewardAllocation";
|
|
5
|
+
|
|
6
|
+
export function useApiEnrichedAllocation({
|
|
7
|
+
allocation,
|
|
8
|
+
}: {
|
|
9
|
+
allocation: ValidatorRewardAllocation | undefined;
|
|
10
|
+
}) {
|
|
11
|
+
return useSWR(
|
|
12
|
+
allocation ? ["useApiEnrichedAllocation", allocation] : null,
|
|
13
|
+
([, allocation]) => {
|
|
14
|
+
return getApiEnrichedAllocation({ allocation });
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
import { type Address, isHex } from "viem";
|
|
3
|
+
|
|
4
|
+
import type { GetValidatorQuery } from "@berachain/graphql/pol/api";
|
|
5
|
+
|
|
6
|
+
import { getApiValidator } from "~/actions/validators/getApiValidator";
|
|
7
|
+
import type { DefaultHookOptions, DefaultHookReturnType } from "~/types";
|
|
8
|
+
|
|
9
|
+
export interface UsePollValidatorInfoResponse
|
|
10
|
+
extends DefaultHookReturnType<GetValidatorQuery> {}
|
|
11
|
+
|
|
12
|
+
export const useApiValidatorQueryKey = (id: Address) =>
|
|
13
|
+
id ? (["useApiValidator", id] as const) : null;
|
|
14
|
+
|
|
15
|
+
export const useApiValidator = (
|
|
16
|
+
id: Address,
|
|
17
|
+
options?: DefaultHookOptions,
|
|
18
|
+
): UsePollValidatorInfoResponse => {
|
|
19
|
+
const QUERY_KEY = useApiValidatorQueryKey(id);
|
|
20
|
+
const isEnabled = options?.opts?.isEnabled ?? true;
|
|
21
|
+
const swrResponse = useSWR(
|
|
22
|
+
isEnabled && id ? QUERY_KEY : null,
|
|
23
|
+
async ([, id]) => {
|
|
24
|
+
if (!id || !isHex(id)) throw new Error(`Invalid validator ID: ${id}`);
|
|
25
|
+
|
|
26
|
+
return getApiValidator({ id });
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
...options?.opts,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
...swrResponse,
|
|
35
|
+
refresh: () => swrResponse.mutate(),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
|
|
3
|
+
import { usePublicClient } from "@berachain/wagmi/hooks";
|
|
4
|
+
|
|
5
|
+
import { getBaselineRewardAllocation } from "~/actions/validators/getBaselineRewardAllocation";
|
|
6
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
7
|
+
|
|
8
|
+
export function useBaselineRewardAllocation() {
|
|
9
|
+
const publicClient = usePublicClient();
|
|
10
|
+
return useSWR(publicClient ? ["baselineRewardAllocation"] : null, () => {
|
|
11
|
+
assertPublicClient(publicClient);
|
|
12
|
+
return getBaselineRewardAllocation({
|
|
13
|
+
publicClient,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
|
|
4
|
+
import type { GetValidatorBlockStatsQuery } from "@berachain/graphql/pol/subgraph";
|
|
5
|
+
|
|
6
|
+
import { getDailyValidatorBlockStats } from "~/actions/validators/getDailyValidatorBlockStats";
|
|
7
|
+
import { POLLING } from "~/enum/polling";
|
|
8
|
+
import type { DefaultHookReturnType } from "~/types";
|
|
9
|
+
|
|
10
|
+
export const useDailyValidatorBlockStats = ({
|
|
11
|
+
pubKey,
|
|
12
|
+
first = 1,
|
|
13
|
+
}: {
|
|
14
|
+
pubKey: Address | undefined;
|
|
15
|
+
first?: number;
|
|
16
|
+
}): DefaultHookReturnType<GetValidatorBlockStatsQuery> => {
|
|
17
|
+
const QUERY_KEY = pubKey
|
|
18
|
+
? (["useDailyValidatorBlockStats", pubKey, first] as const)
|
|
19
|
+
: null;
|
|
20
|
+
|
|
21
|
+
const swrResponse = useSWR(
|
|
22
|
+
QUERY_KEY,
|
|
23
|
+
async ([, pubKey, first]) => {
|
|
24
|
+
return await getDailyValidatorBlockStats({
|
|
25
|
+
pubKey: pubKey,
|
|
26
|
+
first,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
refreshInterval: POLLING.SLOW,
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return { ...swrResponse, refresh: () => swrResponse.mutate() };
|
|
35
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import useSWR from "swr";
|
|
2
|
+
|
|
3
|
+
import { usePublicClient } from "@berachain/wagmi/hooks";
|
|
4
|
+
|
|
5
|
+
import { getDefaultRewardAllocation } from "~/actions/validators/getDefaultRewardAllocation";
|
|
6
|
+
import type { ValidatorRewardAllocation } from "~/actions/validators/getValidatorRewardAllocation";
|
|
7
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
8
|
+
import type { DefaultHookOptions } from "~/types/global";
|
|
9
|
+
|
|
10
|
+
export function useDefaultRewardAllocation(options?: DefaultHookOptions) {
|
|
11
|
+
const publicClient = usePublicClient();
|
|
12
|
+
const QUERY_KEY = publicClient ? ["useDefaultRewardAllocation"] : null;
|
|
13
|
+
|
|
14
|
+
const swrResponse = useSWR<ValidatorRewardAllocation | undefined>(
|
|
15
|
+
QUERY_KEY,
|
|
16
|
+
async () => {
|
|
17
|
+
assertPublicClient(publicClient);
|
|
18
|
+
|
|
19
|
+
return await getDefaultRewardAllocation({
|
|
20
|
+
client: publicClient,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
...options?.opts,
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
...swrResponse,
|
|
30
|
+
refresh: () => swrResponse.mutate(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import useSWRImmutable from "swr/immutable";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
|
|
4
|
+
import { getManagedValidatorByAccount } from "~/actions/validators/getManagedValidatorByAccount";
|
|
5
|
+
import type { DefaultHookOptions } from "~/types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Return the validators managed by the account
|
|
9
|
+
* Roles:
|
|
10
|
+
* - Validator Operator
|
|
11
|
+
* - Validator Reward Allocator
|
|
12
|
+
* @param address
|
|
13
|
+
* @param options
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export const useManagedValidatorByAccount = (
|
|
17
|
+
{ account }: { account: Address | undefined },
|
|
18
|
+
options?: DefaultHookOptions,
|
|
19
|
+
) => {
|
|
20
|
+
const QUERY_KEY = account
|
|
21
|
+
? (["useManagedValidatorByAccount", account] as const)
|
|
22
|
+
: null;
|
|
23
|
+
|
|
24
|
+
const swrResponse = useSWRImmutable(
|
|
25
|
+
QUERY_KEY,
|
|
26
|
+
async ([, account]) => {
|
|
27
|
+
return await getManagedValidatorByAccount({
|
|
28
|
+
account,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
...options?.opts,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...swrResponse,
|
|
38
|
+
refresh: () => swrResponse.mutate(),
|
|
39
|
+
};
|
|
40
|
+
};
|