@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,109 @@
|
|
|
1
|
+
import { type Address, formatUnits, type PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
4
|
+
import { msToSeconds } from "~/utils/time";
|
|
5
|
+
|
|
6
|
+
export enum RewardVaultDistributionMode {
|
|
7
|
+
Duration = "duration",
|
|
8
|
+
TargetRate = "targetRate",
|
|
9
|
+
TargetApr = "targetApr",
|
|
10
|
+
}
|
|
11
|
+
export interface GetRewardVaultRewardsReturn {
|
|
12
|
+
rewardsDuration: number;
|
|
13
|
+
manager: Address;
|
|
14
|
+
/**
|
|
15
|
+
* The amount of BGT that will be distributed per second
|
|
16
|
+
*/
|
|
17
|
+
rewardRate: string;
|
|
18
|
+
/**
|
|
19
|
+
* The timestamp when rewards will be depleted
|
|
20
|
+
*/
|
|
21
|
+
periodFinish: number;
|
|
22
|
+
/**
|
|
23
|
+
* The amount of BGT that will be distributed from now until the periodFinish timestamp
|
|
24
|
+
*/
|
|
25
|
+
availableRewards: string;
|
|
26
|
+
/**
|
|
27
|
+
* The amount of BGT that will be distributed per second.
|
|
28
|
+
*
|
|
29
|
+
* If this is 0, the duration mode is active.
|
|
30
|
+
*/
|
|
31
|
+
targetRewardsPerSecond: string;
|
|
32
|
+
/**
|
|
33
|
+
* The minimum reward duration for the target rate
|
|
34
|
+
*/
|
|
35
|
+
minRewardDurationForTargetRate: number;
|
|
36
|
+
/**
|
|
37
|
+
* The current mode of the vault
|
|
38
|
+
*/
|
|
39
|
+
mode:
|
|
40
|
+
| RewardVaultDistributionMode.Duration
|
|
41
|
+
| RewardVaultDistributionMode.TargetRate;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function getRewardVaultRewards(
|
|
45
|
+
address: Address,
|
|
46
|
+
publicClient: PublicClient,
|
|
47
|
+
): Promise<GetRewardVaultRewardsReturn> {
|
|
48
|
+
const [
|
|
49
|
+
rewardsDuration,
|
|
50
|
+
manager,
|
|
51
|
+
rewardRate,
|
|
52
|
+
periodFinish,
|
|
53
|
+
targetRewardsPerSecond,
|
|
54
|
+
minRewardDurationForTargetRate,
|
|
55
|
+
] = await Promise.all([
|
|
56
|
+
publicClient.readContract({
|
|
57
|
+
address: address,
|
|
58
|
+
abi: rewardVaultAbi,
|
|
59
|
+
functionName: "rewardsDuration",
|
|
60
|
+
}),
|
|
61
|
+
publicClient.readContract({
|
|
62
|
+
address: address,
|
|
63
|
+
abi: rewardVaultAbi,
|
|
64
|
+
functionName: "rewardVaultManager",
|
|
65
|
+
}),
|
|
66
|
+
|
|
67
|
+
publicClient.readContract({
|
|
68
|
+
address: address,
|
|
69
|
+
abi: rewardVaultAbi,
|
|
70
|
+
functionName: "rewardRate",
|
|
71
|
+
}),
|
|
72
|
+
publicClient.readContract({
|
|
73
|
+
address: address,
|
|
74
|
+
abi: rewardVaultAbi,
|
|
75
|
+
functionName: "periodFinish",
|
|
76
|
+
}),
|
|
77
|
+
publicClient.readContract({
|
|
78
|
+
address: address,
|
|
79
|
+
abi: rewardVaultAbi,
|
|
80
|
+
functionName: "targetRewardsPerSecond",
|
|
81
|
+
}),
|
|
82
|
+
publicClient.readContract({
|
|
83
|
+
address: address,
|
|
84
|
+
abi: rewardVaultAbi,
|
|
85
|
+
functionName: "minRewardDurationForTargetRate",
|
|
86
|
+
}),
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const availableRewards =
|
|
90
|
+
(rewardRate * (periodFinish - BigInt(msToSeconds(Date.now())))) /
|
|
91
|
+
10n ** 18n;
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
rewardsDuration: Number(rewardsDuration),
|
|
95
|
+
mode:
|
|
96
|
+
targetRewardsPerSecond === 0n
|
|
97
|
+
? RewardVaultDistributionMode.Duration
|
|
98
|
+
: RewardVaultDistributionMode.TargetRate,
|
|
99
|
+
manager,
|
|
100
|
+
|
|
101
|
+
// 36 decimals for the reward rate
|
|
102
|
+
rewardRate: formatUnits(rewardRate, 36),
|
|
103
|
+
periodFinish: Number(periodFinish),
|
|
104
|
+
// 36 decimals for the reward rate
|
|
105
|
+
availableRewards: formatUnits(availableRewards, 18),
|
|
106
|
+
minRewardDurationForTargetRate: Number(minRewardDurationForTargetRate),
|
|
107
|
+
targetRewardsPerSecond: formatUnits(targetRewardsPerSecond, 36),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Address, PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
4
|
+
|
|
5
|
+
export async function getRewardVaultStakingToken({
|
|
6
|
+
address,
|
|
7
|
+
publicClient,
|
|
8
|
+
}: {
|
|
9
|
+
address: Address;
|
|
10
|
+
publicClient: NonNullable<PublicClient>;
|
|
11
|
+
}) {
|
|
12
|
+
const vaultAddress = await publicClient.readContract({
|
|
13
|
+
address: address,
|
|
14
|
+
abi: rewardVaultAbi,
|
|
15
|
+
functionName: "stakeToken",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return vaultAddress;
|
|
19
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { GetPublicClientReturnType } from "@wagmi/core";
|
|
2
|
+
import { type Address, formatUnits } from "viem";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type ApiVaultFragment,
|
|
6
|
+
GetVaults,
|
|
7
|
+
type GetVaultsQuery,
|
|
8
|
+
type GetVaultsQueryVariables,
|
|
9
|
+
} from "@berachain/graphql/pol/api";
|
|
10
|
+
|
|
11
|
+
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
12
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
13
|
+
|
|
14
|
+
export interface GetGaugeData {
|
|
15
|
+
gaugeList: ApiVaultFragment[];
|
|
16
|
+
pagination: {
|
|
17
|
+
currentPage: number;
|
|
18
|
+
totalCount: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function getRewardVaults({
|
|
23
|
+
filter,
|
|
24
|
+
publicClient,
|
|
25
|
+
...args
|
|
26
|
+
}: {
|
|
27
|
+
filter?: GetVaultsQueryVariables;
|
|
28
|
+
publicClient?: GetPublicClientReturnType;
|
|
29
|
+
} & BeraJS.BaseFunctionArgs = {}): Promise<GetGaugeData> {
|
|
30
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
31
|
+
|
|
32
|
+
const res = await bexApiGraphqlClient.query<
|
|
33
|
+
GetVaultsQuery,
|
|
34
|
+
GetVaultsQueryVariables
|
|
35
|
+
>({
|
|
36
|
+
query: GetVaults,
|
|
37
|
+
variables: filter,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const incentives = await Promise.allSettled(
|
|
41
|
+
res.data.polGetRewardVaults.vaults.map(async (vault) => {
|
|
42
|
+
if (!publicClient) return undefined;
|
|
43
|
+
|
|
44
|
+
return Promise.allSettled(
|
|
45
|
+
vault.activeIncentives.map((incentive) =>
|
|
46
|
+
publicClient.readContract({
|
|
47
|
+
abi: rewardVaultAbi,
|
|
48
|
+
address: vault.address as Address,
|
|
49
|
+
functionName: "incentives",
|
|
50
|
+
args: [incentive.tokenAddress as Address],
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const vaults = res.data.polGetRewardVaults.vaults.map((vault, index) => {
|
|
58
|
+
let totalIncentiveInUsdc = 0;
|
|
59
|
+
|
|
60
|
+
const incentivesArray: typeof vault.activeIncentives =
|
|
61
|
+
vault.activeIncentives.map((apiIncentive, incIdx) => {
|
|
62
|
+
const tokenPrice =
|
|
63
|
+
Number(apiIncentive.remainingAmountUsd) &&
|
|
64
|
+
Number(apiIncentive.remainingAmount)
|
|
65
|
+
? Number(apiIncentive.remainingAmountUsd) /
|
|
66
|
+
Number(apiIncentive.remainingAmount)
|
|
67
|
+
: 0;
|
|
68
|
+
|
|
69
|
+
const remainingAmount =
|
|
70
|
+
incentives[index]?.status === "fulfilled" &&
|
|
71
|
+
incentives[index]?.value?.[incIdx]?.status === "fulfilled"
|
|
72
|
+
? formatUnits(
|
|
73
|
+
BigInt(incentives[index].value[incIdx].value[2]),
|
|
74
|
+
apiIncentive.token.decimals,
|
|
75
|
+
)
|
|
76
|
+
: apiIncentive.remainingAmount;
|
|
77
|
+
|
|
78
|
+
totalIncentiveInUsdc += Number(remainingAmount) * Number(tokenPrice);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
...apiIncentive,
|
|
82
|
+
remainingAmount,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
...vault,
|
|
88
|
+
dynamicData: {
|
|
89
|
+
...vault.dynamicData,
|
|
90
|
+
allTimeReceivedBGTAmount:
|
|
91
|
+
vault.dynamicData?.allTimeReceivedBGTAmount ?? "0",
|
|
92
|
+
bgtCapturePercentage: vault.dynamicData?.bgtCapturePercentage ?? "0",
|
|
93
|
+
activeIncentivesValueUsd: totalIncentiveInUsdc.toString(),
|
|
94
|
+
activeIncentivesRateUsd:
|
|
95
|
+
vault.dynamicData?.activeIncentivesRateUsd ?? "0",
|
|
96
|
+
bgtCapturePerBlock: vault.dynamicData?.bgtCapturePerBlock ?? "0",
|
|
97
|
+
},
|
|
98
|
+
activeIncentives: incentivesArray,
|
|
99
|
+
} satisfies typeof vault;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
pagination: res.data.polGetRewardVaults.pagination,
|
|
104
|
+
gaugeList: vaults!,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { type Address, erc20Abi, type PublicClient } from "viem";
|
|
3
|
+
|
|
4
|
+
import { stakeBeraVaultAbi } from "~/abi/pol/stakeBeraVault";
|
|
5
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
6
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
7
|
+
import { getBlockTime } from "./getBlockTime";
|
|
8
|
+
import { getIncentiveFeeClaimStats } from "./getIncentiveFeeClaimStats";
|
|
9
|
+
import { getStakeWithdrawalCooldown } from "./getStakeWithdrawalCooldown";
|
|
10
|
+
|
|
11
|
+
export interface VaultMetadata {
|
|
12
|
+
current: {
|
|
13
|
+
exchangeRate: string;
|
|
14
|
+
totalSupply: string;
|
|
15
|
+
totalAssets: string;
|
|
16
|
+
tvl: string;
|
|
17
|
+
};
|
|
18
|
+
previous: {
|
|
19
|
+
exchangeRate: string;
|
|
20
|
+
totalSupply: string;
|
|
21
|
+
totalAssets: string;
|
|
22
|
+
tvl: string;
|
|
23
|
+
};
|
|
24
|
+
totalWBeraIssued: string;
|
|
25
|
+
lockPeriod?: number;
|
|
26
|
+
totalBuyBacks: number;
|
|
27
|
+
totalBuyBacksInLast24Hours: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param address - The address of the vault
|
|
32
|
+
* @throws {Error} If the vault is not found
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export async function getSWBeraVaultMetadata({
|
|
36
|
+
address,
|
|
37
|
+
publicClient,
|
|
38
|
+
...args
|
|
39
|
+
}: {
|
|
40
|
+
address: Address;
|
|
41
|
+
publicClient?: PublicClient;
|
|
42
|
+
} & BeraJS.BaseFunctionArgs): Promise<VaultMetadata> {
|
|
43
|
+
const { config } = parseBaseArgs(args);
|
|
44
|
+
assertPublicClient(publicClient);
|
|
45
|
+
|
|
46
|
+
const hoursWindow = 26; // 26 hours is the window for the vault to ensure at least 1 claim per APR window.
|
|
47
|
+
try {
|
|
48
|
+
// Get current block number
|
|
49
|
+
const [currentBlock, blockTime] = await Promise.all([
|
|
50
|
+
publicClient.getBlock({ blockTag: "latest" }),
|
|
51
|
+
getBlockTime(),
|
|
52
|
+
]);
|
|
53
|
+
const blocksPerWindow = Math.floor((hoursWindow * 60 * 60) / blockTime); // hoursWindow * 60 minutes * 60 seconds / actual block time
|
|
54
|
+
const blockWindowAgo = currentBlock.number - BigInt(blocksPerWindow);
|
|
55
|
+
|
|
56
|
+
const [
|
|
57
|
+
curretTotalAssets,
|
|
58
|
+
currentTotalSupply,
|
|
59
|
+
currentOneShareWorth,
|
|
60
|
+
currentTVL,
|
|
61
|
+
totalAssets24HoursAgo,
|
|
62
|
+
totalSupply24HoursAgo,
|
|
63
|
+
oneShareWorthWindowAgo,
|
|
64
|
+
tvl24HoursAgo,
|
|
65
|
+
totalWBeraIssued,
|
|
66
|
+
lockPeriod,
|
|
67
|
+
incentiveFeeClaimStats,
|
|
68
|
+
] = await Promise.all([
|
|
69
|
+
publicClient.readContract({
|
|
70
|
+
address,
|
|
71
|
+
abi: stakeBeraVaultAbi,
|
|
72
|
+
functionName: "totalAssets",
|
|
73
|
+
}),
|
|
74
|
+
publicClient.readContract({
|
|
75
|
+
address,
|
|
76
|
+
abi: stakeBeraVaultAbi,
|
|
77
|
+
functionName: "totalSupply",
|
|
78
|
+
}),
|
|
79
|
+
publicClient.readContract({
|
|
80
|
+
address,
|
|
81
|
+
abi: stakeBeraVaultAbi,
|
|
82
|
+
functionName: "previewRedeem",
|
|
83
|
+
args: [10n ** 18n],
|
|
84
|
+
blockNumber: currentBlock.number,
|
|
85
|
+
}),
|
|
86
|
+
publicClient.readContract({
|
|
87
|
+
address: config.tokens.wbera,
|
|
88
|
+
abi: erc20Abi,
|
|
89
|
+
functionName: "balanceOf",
|
|
90
|
+
args: [address],
|
|
91
|
+
}),
|
|
92
|
+
publicClient.readContract({
|
|
93
|
+
address,
|
|
94
|
+
abi: stakeBeraVaultAbi,
|
|
95
|
+
functionName: "totalAssets",
|
|
96
|
+
blockNumber: blockWindowAgo,
|
|
97
|
+
}),
|
|
98
|
+
publicClient.readContract({
|
|
99
|
+
address,
|
|
100
|
+
abi: erc20Abi,
|
|
101
|
+
functionName: "totalSupply",
|
|
102
|
+
blockNumber: blockWindowAgo,
|
|
103
|
+
}),
|
|
104
|
+
publicClient.readContract({
|
|
105
|
+
address,
|
|
106
|
+
abi: stakeBeraVaultAbi,
|
|
107
|
+
functionName: "previewRedeem",
|
|
108
|
+
args: [10n ** 18n],
|
|
109
|
+
blockNumber: blockWindowAgo,
|
|
110
|
+
}),
|
|
111
|
+
publicClient.readContract({
|
|
112
|
+
address: config.tokens.wbera,
|
|
113
|
+
abi: erc20Abi,
|
|
114
|
+
functionName: "balanceOf",
|
|
115
|
+
args: [address],
|
|
116
|
+
blockNumber: blockWindowAgo,
|
|
117
|
+
}),
|
|
118
|
+
publicClient.readContract({
|
|
119
|
+
address: config.tokens.wbera,
|
|
120
|
+
abi: erc20Abi,
|
|
121
|
+
functionName: "totalSupply",
|
|
122
|
+
}),
|
|
123
|
+
getStakeWithdrawalCooldown({
|
|
124
|
+
publicClient: publicClient,
|
|
125
|
+
}),
|
|
126
|
+
getIncentiveFeeClaimStats({}),
|
|
127
|
+
]);
|
|
128
|
+
const exchangeRateWindowAgo = new BigNumber(
|
|
129
|
+
oneShareWorthWindowAgo.toString(),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const currentExchangeRate = new BigNumber(currentOneShareWorth.toString());
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
current: {
|
|
136
|
+
exchangeRate: currentExchangeRate.toString(),
|
|
137
|
+
totalSupply: new BigNumber(currentTotalSupply.toString())
|
|
138
|
+
.dividedBy(1e18)
|
|
139
|
+
.toString(),
|
|
140
|
+
totalAssets: new BigNumber(curretTotalAssets.toString())
|
|
141
|
+
.dividedBy(1e18)
|
|
142
|
+
.toString(),
|
|
143
|
+
tvl: new BigNumber(currentTVL.toString()).dividedBy(1e18).toString(),
|
|
144
|
+
},
|
|
145
|
+
previous: {
|
|
146
|
+
exchangeRate: exchangeRateWindowAgo.toString(),
|
|
147
|
+
totalSupply: new BigNumber(totalSupply24HoursAgo.toString())
|
|
148
|
+
.dividedBy(1e18)
|
|
149
|
+
.toString(),
|
|
150
|
+
totalAssets: new BigNumber(totalAssets24HoursAgo.toString())
|
|
151
|
+
.dividedBy(1e18)
|
|
152
|
+
.toString(),
|
|
153
|
+
tvl: new BigNumber(tvl24HoursAgo.toString()).dividedBy(1e18).toString(),
|
|
154
|
+
},
|
|
155
|
+
totalWBeraIssued: new BigNumber(totalWBeraIssued.toString())
|
|
156
|
+
.dividedBy(1e18)
|
|
157
|
+
.toString(),
|
|
158
|
+
lockPeriod,
|
|
159
|
+
totalBuyBacks: incentiveFeeClaimStats.sumAllClaims,
|
|
160
|
+
totalBuyBacksInLast24Hours: incentiveFeeClaimStats.sumClaimsInLast24Hours,
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error("Failed to get SW Bera Vault Metadata", error);
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Address, PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { stakeBeraVaultAbi } from "~/abi/pol/stakeBeraVault";
|
|
4
|
+
import { getStakeWithdrawalCooldown } from "~/actions";
|
|
5
|
+
import { formatTimeLeft, msToSeconds } from "~/utils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Calculates and returns formatted time remaining until a target date
|
|
9
|
+
* @param targetTime - Unix timestamp in seconds representing the target time
|
|
10
|
+
* @returns Formatted time string (e.g., "2h 30m") or undefined if time has passed
|
|
11
|
+
*/
|
|
12
|
+
function getTimeUntil(targetTime: number): string | undefined {
|
|
13
|
+
const currentTime = Date.now();
|
|
14
|
+
const timeDiff = targetTime * 1000 - currentTime;
|
|
15
|
+
|
|
16
|
+
// If time has already passed, return undefined
|
|
17
|
+
if (timeDiff <= 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Convert milliseconds to seconds for formatTimeLeft function
|
|
22
|
+
const totalSeconds = msToSeconds(timeDiff);
|
|
23
|
+
return formatTimeLeft(totalSeconds, true, true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Interface representing a staked BERA withdrawal request
|
|
28
|
+
*/
|
|
29
|
+
export interface StakedBeraWithdrawal {
|
|
30
|
+
withdrawalAmount?: bigint;
|
|
31
|
+
timeRemaining?: string;
|
|
32
|
+
withdrawalRequestId?: bigint;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Interface representing a withdrawal request for V1
|
|
37
|
+
*/
|
|
38
|
+
type WithdrawalRequestV1 = readonly [
|
|
39
|
+
bigint,
|
|
40
|
+
bigint,
|
|
41
|
+
bigint,
|
|
42
|
+
`0x${string}`,
|
|
43
|
+
`0x${string}`,
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves staked BERA withdrawal information for a given account
|
|
48
|
+
*
|
|
49
|
+
* This function handles both V1 and V2 versions of the stake vault contract:
|
|
50
|
+
* - V1: Uses a single withdrawal request per account
|
|
51
|
+
* - V2: Uses ERC721 tokens to represent multiple withdrawal requests per account
|
|
52
|
+
*
|
|
53
|
+
* @param contractAddress - The address of the stake vault contract
|
|
54
|
+
* @param accountAddress - The address of the account to check withdrawals for
|
|
55
|
+
* @param publicClient - Viem public client for blockchain interactions
|
|
56
|
+
* @param version - The version of the stake vault contract ("V1" or "V2")
|
|
57
|
+
* @returns Promise resolving to an array of withdrawal request information
|
|
58
|
+
*/
|
|
59
|
+
export async function getSWBeraWithdrawal(
|
|
60
|
+
contractAddress: Address,
|
|
61
|
+
accountAddress: Address,
|
|
62
|
+
publicClient: PublicClient,
|
|
63
|
+
version: "V1" | "V2",
|
|
64
|
+
): Promise<StakedBeraWithdrawal[]> {
|
|
65
|
+
const withdrawalRequests: StakedBeraWithdrawal[] = [];
|
|
66
|
+
|
|
67
|
+
function withdrawalRequestV1Helper(
|
|
68
|
+
withdrawalRequest: WithdrawalRequestV1,
|
|
69
|
+
lockPeriod: number,
|
|
70
|
+
): void {
|
|
71
|
+
const [assets, _shares, timestamp] = withdrawalRequest;
|
|
72
|
+
const withdrawalAmount = assets;
|
|
73
|
+
const readyTime = Number(timestamp) + Number(lockPeriod);
|
|
74
|
+
const currentTime = msToSeconds(Date.now());
|
|
75
|
+
const timeLeft = readyTime - currentTime;
|
|
76
|
+
if (withdrawalAmount > 0) {
|
|
77
|
+
const timeRemaining = getTimeUntil(timeLeft <= 0 ? 0 : readyTime);
|
|
78
|
+
withdrawalRequests.push({
|
|
79
|
+
withdrawalAmount,
|
|
80
|
+
timeRemaining,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
switch (version) {
|
|
86
|
+
case "V1": {
|
|
87
|
+
const [withdrawalRequest, lockPeriod] = await Promise.all([
|
|
88
|
+
publicClient.readContract({
|
|
89
|
+
address: contractAddress,
|
|
90
|
+
abi: stakeBeraVaultAbi,
|
|
91
|
+
functionName: "withdrawalRequests" as const,
|
|
92
|
+
args: [accountAddress],
|
|
93
|
+
}),
|
|
94
|
+
getStakeWithdrawalCooldown({
|
|
95
|
+
publicClient,
|
|
96
|
+
}),
|
|
97
|
+
]);
|
|
98
|
+
withdrawalRequestV1Helper(withdrawalRequest, lockPeriod);
|
|
99
|
+
return withdrawalRequests;
|
|
100
|
+
}
|
|
101
|
+
case "V2": {
|
|
102
|
+
const [withdrawalRequestV1, withdrawalRequestIds, lockPeriod] =
|
|
103
|
+
await Promise.all([
|
|
104
|
+
publicClient.readContract({
|
|
105
|
+
address: contractAddress,
|
|
106
|
+
abi: stakeBeraVaultAbi,
|
|
107
|
+
functionName: "withdrawalRequests" as const,
|
|
108
|
+
args: [accountAddress],
|
|
109
|
+
}),
|
|
110
|
+
publicClient.readContract({
|
|
111
|
+
address: contractAddress,
|
|
112
|
+
abi: stakeBeraVaultAbi,
|
|
113
|
+
functionName: "getERC721WithdrawalRequestIds" as const,
|
|
114
|
+
args: [accountAddress],
|
|
115
|
+
}),
|
|
116
|
+
getStakeWithdrawalCooldown({
|
|
117
|
+
publicClient,
|
|
118
|
+
}),
|
|
119
|
+
]);
|
|
120
|
+
withdrawalRequestV1Helper(withdrawalRequestV1, lockPeriod);
|
|
121
|
+
|
|
122
|
+
// Process each withdrawal request ID to get detailed information
|
|
123
|
+
const withdrawalResults = await Promise.all(
|
|
124
|
+
withdrawalRequestIds.map(
|
|
125
|
+
async (withdrawalRequestId): Promise<StakedBeraWithdrawal | null> => {
|
|
126
|
+
const withdrawalRequest = await publicClient.readContract({
|
|
127
|
+
address: contractAddress,
|
|
128
|
+
abi: stakeBeraVaultAbi,
|
|
129
|
+
functionName: "getERC721WithdrawalRequest",
|
|
130
|
+
args: [withdrawalRequestId as bigint],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const { assets, requestTime: timestamp } = withdrawalRequest;
|
|
134
|
+
if (!assets || !timestamp)
|
|
135
|
+
throw new Error("Invalid withdrawal request");
|
|
136
|
+
const withdrawalAmount = assets;
|
|
137
|
+
|
|
138
|
+
// Calculate when this specific withdrawal will be ready
|
|
139
|
+
const readyTime = Number(timestamp) + Number(lockPeriod);
|
|
140
|
+
const currentTime = msToSeconds(Date.now());
|
|
141
|
+
const timeLeft = readyTime - currentTime;
|
|
142
|
+
|
|
143
|
+
// Only include withdrawal if there's an amount to withdraw
|
|
144
|
+
if (withdrawalAmount > 0) {
|
|
145
|
+
const timeRemaining = getTimeUntil(timeLeft <= 0 ? 0 : readyTime);
|
|
146
|
+
return {
|
|
147
|
+
withdrawalAmount,
|
|
148
|
+
timeRemaining,
|
|
149
|
+
withdrawalRequestId,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
},
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
// Filter out null results (withdrawals with no amount)
|
|
158
|
+
const filteredRequests = withdrawalResults.filter(
|
|
159
|
+
(request): request is StakedBeraWithdrawal => request !== null,
|
|
160
|
+
);
|
|
161
|
+
withdrawalRequests.push(...filteredRequests);
|
|
162
|
+
return withdrawalRequests;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { stakeBeraVaultAbi } from "~/abi/pol/stakeBeraVault";
|
|
4
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
5
|
+
|
|
6
|
+
export async function getStakeWithdrawalCooldown({
|
|
7
|
+
publicClient,
|
|
8
|
+
...args
|
|
9
|
+
}: {
|
|
10
|
+
publicClient: PublicClient;
|
|
11
|
+
} & BeraJS.BaseFunctionArgs): Promise<number> {
|
|
12
|
+
const { config } = parseBaseArgs(args);
|
|
13
|
+
|
|
14
|
+
const lockPeriod = await publicClient.readContract({
|
|
15
|
+
address: config.tokens.swbera,
|
|
16
|
+
abi: stakeBeraVaultAbi,
|
|
17
|
+
functionName: "WITHDRAWAL_COOLDOWN" as const,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return Number(lockPeriod);
|
|
21
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetSWberaVaultMetadata,
|
|
3
|
+
type GetSWberaVaultMetadataQuery,
|
|
4
|
+
type GetSWberaVaultMetadataQueryVariables,
|
|
5
|
+
type GqlChain,
|
|
6
|
+
GqlSWberaVaultMetadataResolution,
|
|
7
|
+
} from "@berachain/graphql/pol/api";
|
|
8
|
+
|
|
9
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
10
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
11
|
+
|
|
12
|
+
function getResolution(window: "DAY" | "WEEK") {
|
|
13
|
+
if (window === "DAY") {
|
|
14
|
+
return GqlSWberaVaultMetadataResolution.OneDay;
|
|
15
|
+
}
|
|
16
|
+
return GqlSWberaVaultMetadataResolution.SevenDays;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} If the vault is not found
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export async function getStakedBeraAPR({
|
|
25
|
+
window,
|
|
26
|
+
...args
|
|
27
|
+
}: {
|
|
28
|
+
/**
|
|
29
|
+
* APR might vary depending on the annualized time window (day or week)
|
|
30
|
+
*/
|
|
31
|
+
window: "DAY" | "WEEK";
|
|
32
|
+
} & BeraJS.BaseFunctionArgs): Promise<number> {
|
|
33
|
+
const { config } = parseBaseArgs(args);
|
|
34
|
+
|
|
35
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const data = await bexApiGraphqlClient.query<
|
|
39
|
+
GetSWberaVaultMetadataQuery,
|
|
40
|
+
GetSWberaVaultMetadataQueryVariables
|
|
41
|
+
>({
|
|
42
|
+
query: GetSWberaVaultMetadata,
|
|
43
|
+
variables: {
|
|
44
|
+
chain: config.bex.chainName as GqlChain,
|
|
45
|
+
resolution: getResolution(window ?? "DAY"),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { apr } = data.data.polGetSWberaVaultMetadata;
|
|
50
|
+
|
|
51
|
+
return Number(apr);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("Failed to get SW Bera APR", error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetSWberaVaultSnapshots,
|
|
3
|
+
type GetSWberaVaultSnapshotsQuery,
|
|
4
|
+
type GetSWberaVaultSnapshotsQueryVariables,
|
|
5
|
+
type GqlChain,
|
|
6
|
+
GqlVaultSnapshotDataRange,
|
|
7
|
+
} from "@berachain/graphql/pol/api";
|
|
8
|
+
|
|
9
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
10
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
11
|
+
|
|
12
|
+
export type GetStakedBeraSnapshotsArgs = {
|
|
13
|
+
chain?: GqlChain;
|
|
14
|
+
range?: GqlVaultSnapshotDataRange;
|
|
15
|
+
} & BeraJS.BaseFunctionArgs;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @throws {Error} If the vault is not found
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export async function getStakedBeraSnapshots({
|
|
23
|
+
chain,
|
|
24
|
+
range = GqlVaultSnapshotDataRange.ThirtyDays,
|
|
25
|
+
...args
|
|
26
|
+
}: GetStakedBeraSnapshotsArgs = {}): Promise<
|
|
27
|
+
GetSWberaVaultSnapshotsQuery["polGetSWberaVaultSnapshots"]
|
|
28
|
+
> {
|
|
29
|
+
const { config } = parseBaseArgs(args);
|
|
30
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
31
|
+
try {
|
|
32
|
+
const data = await bexApiGraphqlClient.query<
|
|
33
|
+
GetSWberaVaultSnapshotsQuery,
|
|
34
|
+
GetSWberaVaultSnapshotsQueryVariables
|
|
35
|
+
>({
|
|
36
|
+
query: GetSWberaVaultSnapshots,
|
|
37
|
+
variables: {
|
|
38
|
+
chain: chain ?? (config.bex.chainName as GqlChain),
|
|
39
|
+
range,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return data.data.polGetSWberaVaultSnapshots;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Failed to get SW Bera Snapshots", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|