@berachain/berajs 0.1.1 → 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-BaNHEuck.d.cts → HoneyConfigProvider-6PXZJMSU.d.cts} +171 -171
- package/dist/{dex-D6IK-4D9.d.ts → HoneyConfigProvider-CwDFrt02.d.ts} +171 -171
- package/dist/abi/index.cjs +1 -1
- package/dist/abi/index.cjs.map +1 -1
- package/dist/abi/index.mjs +1 -1
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.d.cts +7 -7
- package/dist/actions/index.d.ts +7 -7
- package/dist/actions/index.mjs +1 -1
- 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-GZ5YA2AZ.cjs → chunk-6VF3RF53.cjs} +3 -3
- package/dist/{chunk-GZ5YA2AZ.cjs.map → chunk-6VF3RF53.cjs.map} +1 -1
- package/dist/{chunk-3WCYP277.mjs → chunk-AMRJ4B36.mjs} +2 -2
- package/dist/chunk-EU4WFADK.cjs +2 -0
- package/dist/chunk-EU4WFADK.cjs.map +1 -0
- package/dist/{chunk-ZLCBHOSV.mjs → chunk-KMKUXP2S.mjs} +3 -3
- package/dist/chunk-OJXJ6CZ4.mjs +4 -0
- package/dist/{chunk-M5GUTM7K.mjs.map → chunk-OJXJ6CZ4.mjs.map} +1 -1
- package/dist/{chunk-V3PCHP2D.cjs → chunk-REDXXUK7.cjs} +2 -2
- package/dist/{chunk-V3PCHP2D.cjs.map → chunk-REDXXUK7.cjs.map} +1 -1
- package/dist/chunk-VYWYJR63.mjs +2 -0
- package/dist/chunk-VYWYJR63.mjs.map +1 -0
- package/dist/{chunk-GWBENQEV.cjs → chunk-XFPTQMAK.cjs} +3 -3
- package/dist/{chunk-GWBENQEV.cjs.map → chunk-XFPTQMAK.cjs.map} +1 -1
- package/dist/contexts/index.cjs +1 -1
- package/dist/contexts/index.d.cts +3 -3
- package/dist/contexts/index.d.ts +3 -3
- package/dist/contexts/index.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-BhPVMCTj.d.ts → getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-Cmd7rgYK.d.cts → getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts} +2 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +6 -6
- package/dist/hooks/index.d.ts +6 -6
- package/dist/hooks/index.mjs +2 -2
- package/dist/{staking-Bcb8DhoZ.d.cts → staking-F9Nx9TKD.d.ts} +1 -1
- package/dist/{staking-DvJOnMJG.d.ts → staking-f4BpYH7l.d.cts} +1 -1
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/{useHoneySwapState-DfmXCavx.d.cts → useHoneySwapState-C-9BV4VB.d.cts} +1 -1
- package/dist/{useHoneySwapState-AKDZI2MT.d.ts → useHoneySwapState-CUY5Sm1b.d.ts} +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -4
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/index.mjs +1 -1
- package/package.json +3 -2
- 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-5OAABMMU.mjs +0 -2
- package/dist/chunk-5OAABMMU.mjs.map +0 -1
- package/dist/chunk-EODAKI5K.cjs +0 -2
- package/dist/chunk-EODAKI5K.cjs.map +0 -1
- package/dist/chunk-IZDT74H4.mjs +0 -2
- package/dist/chunk-IZDT74H4.mjs.map +0 -1
- package/dist/chunk-M5GUTM7K.mjs +0 -4
- package/dist/chunk-YRJAQDEO.cjs +0 -2
- package/dist/chunk-YRJAQDEO.cjs.map +0 -1
- /package/dist/{chunk-3WCYP277.mjs.map → chunk-AMRJ4B36.mjs.map} +0 -0
- /package/dist/{chunk-ZLCBHOSV.mjs.map → chunk-KMKUXP2S.mjs.map} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetBlocksTimeStamp,
|
|
3
|
+
type GetBlocksTimeStampQuery,
|
|
4
|
+
type GetBlocksTimeStampQueryVariables,
|
|
5
|
+
} from "@berachain/graphql/chain";
|
|
6
|
+
|
|
7
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
8
|
+
import { hoursInSeconds, msToSeconds } from "~/utils/time";
|
|
9
|
+
import { getApolloClient } from "../clients/getApolloClient";
|
|
10
|
+
|
|
11
|
+
export async function getBlockTime({
|
|
12
|
+
defaultBlockTime,
|
|
13
|
+
blocksSpan,
|
|
14
|
+
...args
|
|
15
|
+
}: {
|
|
16
|
+
defaultBlockTime?: number;
|
|
17
|
+
blocksSpan?: number;
|
|
18
|
+
} & BeraJS.BaseFunctionArgs = {}): Promise<number> {
|
|
19
|
+
const { config } = parseBaseArgs(args);
|
|
20
|
+
|
|
21
|
+
const blocksClient = getApolloClient("blocks.subgraph", args);
|
|
22
|
+
|
|
23
|
+
const blockTime = defaultBlockTime ?? config.averageBlockTime;
|
|
24
|
+
const span = blocksSpan ?? Math.floor(hoursInSeconds(1) / blockTime);
|
|
25
|
+
|
|
26
|
+
const res = await blocksClient.query<
|
|
27
|
+
GetBlocksTimeStampQuery,
|
|
28
|
+
GetBlocksTimeStampQueryVariables
|
|
29
|
+
>({
|
|
30
|
+
query: GetBlocksTimeStamp,
|
|
31
|
+
variables: {
|
|
32
|
+
skip: span,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const data = res.data;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
// we need to use current timestamp as the latest block might not have been minted (chain halted)
|
|
40
|
+
(msToSeconds(Date.now()) - Number(data?.oldest[0]?.timestamp)) /
|
|
41
|
+
(Number(data?.newest[0]?.number) - Number(data?.oldest[0]?.number))
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ApiVaultFragment,
|
|
3
|
+
GqlRewardVaultOrderBy,
|
|
4
|
+
GqlRewardVaultOrderDirection,
|
|
5
|
+
} from "@berachain/graphql/pol/api";
|
|
6
|
+
|
|
7
|
+
import { getRewardVaults } from "./getRewardVaults";
|
|
8
|
+
|
|
9
|
+
export async function getGlobalCuttingBoard(
|
|
10
|
+
threshold: number,
|
|
11
|
+
): Promise<ApiVaultFragment[]> {
|
|
12
|
+
const { gaugeList } = await getRewardVaults({
|
|
13
|
+
filter: {
|
|
14
|
+
// TODO sort by bgt capture percentage
|
|
15
|
+
orderBy: GqlRewardVaultOrderBy.Apr,
|
|
16
|
+
orderDirection: GqlRewardVaultOrderDirection.Desc,
|
|
17
|
+
pageSize: threshold,
|
|
18
|
+
where: {
|
|
19
|
+
includeNonWhitelisted: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return gaugeList;
|
|
25
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as Sentry from "@sentry/nextjs";
|
|
2
|
+
import type { PublicClient } from "viem";
|
|
3
|
+
|
|
4
|
+
import type { ApiVaultFragment } from "@berachain/graphql/pol/api";
|
|
5
|
+
|
|
6
|
+
import { type GlobalInfo, getBGTGlobalInfo } from "./getBGTGlobalInfo";
|
|
7
|
+
import { getBgtTokenTotalBoosts } from "./getBgtTokenTotalBoosts";
|
|
8
|
+
import { getBgtTokenTotalSupply } from "./getBgtTokenTotalSupply";
|
|
9
|
+
import { getGlobalCuttingBoard } from "./getGlobalCuttingBoard";
|
|
10
|
+
|
|
11
|
+
export interface GlobalData extends GlobalInfo {
|
|
12
|
+
globalCuttingBoard: ApiVaultFragment[] | undefined;
|
|
13
|
+
bgtTotalSupply: string | undefined;
|
|
14
|
+
bgtTotalBoosts: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
export async function getGlobalData(
|
|
17
|
+
publicClient: PublicClient,
|
|
18
|
+
): Promise<GlobalData> {
|
|
19
|
+
const [
|
|
20
|
+
globalDataRes,
|
|
21
|
+
globalCuttingBoardRes,
|
|
22
|
+
bgtTotalSupplyRes,
|
|
23
|
+
bgtTotalBoostsRes,
|
|
24
|
+
] = await Promise.allSettled([
|
|
25
|
+
getBGTGlobalInfo(),
|
|
26
|
+
getGlobalCuttingBoard(300),
|
|
27
|
+
getBgtTokenTotalSupply({
|
|
28
|
+
publicClient,
|
|
29
|
+
}),
|
|
30
|
+
getBgtTokenTotalBoosts({
|
|
31
|
+
publicClient,
|
|
32
|
+
}),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
if (globalDataRes.status === "rejected") {
|
|
36
|
+
Sentry.captureException(globalDataRes.reason, {
|
|
37
|
+
level: "warning",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (globalCuttingBoardRes.status === "rejected") {
|
|
42
|
+
Sentry.captureException(globalCuttingBoardRes.reason, {
|
|
43
|
+
level: "warning",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (bgtTotalSupplyRes.status === "rejected") {
|
|
48
|
+
Sentry.captureException(bgtTotalSupplyRes.reason, {
|
|
49
|
+
level: "warning",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (bgtTotalBoostsRes.status === "rejected") {
|
|
54
|
+
Sentry.captureException(bgtTotalBoostsRes.reason, {
|
|
55
|
+
level: "warning",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
bgtTotalSupply:
|
|
61
|
+
bgtTotalSupplyRes.status === "fulfilled"
|
|
62
|
+
? bgtTotalSupplyRes.value
|
|
63
|
+
: undefined,
|
|
64
|
+
globalCuttingBoard:
|
|
65
|
+
globalCuttingBoardRes.status === "fulfilled"
|
|
66
|
+
? globalCuttingBoardRes.value
|
|
67
|
+
: [],
|
|
68
|
+
bgtTotalBoosts:
|
|
69
|
+
bgtTotalBoostsRes.status === "fulfilled"
|
|
70
|
+
? bgtTotalBoostsRes.value
|
|
71
|
+
: undefined,
|
|
72
|
+
...(globalDataRes.status === "fulfilled" ? globalDataRes.value : {}),
|
|
73
|
+
} satisfies GlobalData;
|
|
74
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetIncentiveFeeClaimStats,
|
|
3
|
+
type GetIncentiveFeeClaimStatsQuery,
|
|
4
|
+
type GetIncentiveFeeClaimStatsQueryVariables,
|
|
5
|
+
} from "@berachain/graphql/pol/subgraph";
|
|
6
|
+
|
|
7
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
8
|
+
import { days } from "~/utils/time";
|
|
9
|
+
|
|
10
|
+
export async function getIncentiveFeeClaimStats({
|
|
11
|
+
...args
|
|
12
|
+
}: BeraJS.BaseFunctionArgs) {
|
|
13
|
+
const bgtClient = getApolloClient("pol.subgraph", args);
|
|
14
|
+
const { data } = await bgtClient.query<
|
|
15
|
+
GetIncentiveFeeClaimStatsQuery,
|
|
16
|
+
GetIncentiveFeeClaimStatsQueryVariables
|
|
17
|
+
>({
|
|
18
|
+
query: GetIncentiveFeeClaimStats,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (data.incentiveFeeClaims.length > 0) {
|
|
22
|
+
const sumAllClaims = data?.incentiveFeeClaims.reduce(
|
|
23
|
+
(acc, curr) => acc + Number(curr.payoutAmount),
|
|
24
|
+
30_000, // this is due to a bug in the subgraph, where the first claim of 50_000 was counted as 20_000, once hunter pushed the fix we can upgrade it.
|
|
25
|
+
);
|
|
26
|
+
const claimsInLast24Hours = data?.incentiveFeeClaims.filter(
|
|
27
|
+
(claim) => Number(claim.timestamp) / 1000 > Date.now() - days(1),
|
|
28
|
+
);
|
|
29
|
+
const sumClaimsInLast24Hours = claimsInLast24Hours.reduce(
|
|
30
|
+
(acc, curr) => acc + Number(curr.payoutAmount),
|
|
31
|
+
0,
|
|
32
|
+
);
|
|
33
|
+
return {
|
|
34
|
+
sumAllClaims,
|
|
35
|
+
sumClaimsInLast24Hours,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
sumAllClaims: 0,
|
|
41
|
+
sumClaimsInLast24Hours: 0,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProtocolMetadata } from "~/types";
|
|
2
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
3
|
+
|
|
4
|
+
export interface GetMarkets {
|
|
5
|
+
marketList: ProtocolMetadata[];
|
|
6
|
+
marketDictionary: { [key: string]: ProtocolMetadata };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function getMarkets(
|
|
10
|
+
args: BeraJS.BaseFunctionArgs = {},
|
|
11
|
+
): Promise<GetMarkets> {
|
|
12
|
+
const { config } = parseBaseArgs(args);
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const markets = await fetch(config.lists.rewardVaultList);
|
|
16
|
+
const temp = await markets.json();
|
|
17
|
+
|
|
18
|
+
if (!temp.protocols) {
|
|
19
|
+
throw new Error("Missing protocols in market list");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
marketList: temp.protocols,
|
|
24
|
+
marketDictionary: temp.protocols.reduce(
|
|
25
|
+
(acc: { [key: string]: ProtocolMetadata }, item: ProtocolMetadata) => {
|
|
26
|
+
acc[item.name] = item;
|
|
27
|
+
return acc;
|
|
28
|
+
},
|
|
29
|
+
{},
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error("Error fetching validator information", error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
import { BeraError } from "~/errors/BeraError";
|
|
4
|
+
import type { BribeBoostRewardProof } from "~/types";
|
|
5
|
+
import { getErrorResponse } from "~/utils/getErrorResponse";
|
|
6
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
7
|
+
|
|
8
|
+
export async function getRewardProofsByValidator({
|
|
9
|
+
account,
|
|
10
|
+
validator,
|
|
11
|
+
page = 1,
|
|
12
|
+
perPage = 1000,
|
|
13
|
+
...args
|
|
14
|
+
}: {
|
|
15
|
+
account: Address;
|
|
16
|
+
validator: Address;
|
|
17
|
+
page?: number;
|
|
18
|
+
perPage?: number;
|
|
19
|
+
} & BeraJS.BaseFunctionArgs): Promise<BribeBoostRewardProof> {
|
|
20
|
+
const { config } = parseBaseArgs(args);
|
|
21
|
+
|
|
22
|
+
// We'll try to revalidate on the client side by using the cache: "no-store" and swrImmutable
|
|
23
|
+
// In the future, we can look at using cache and tags to invalidate the cache on the server side to prevent stale data
|
|
24
|
+
const result = await fetch(
|
|
25
|
+
`${
|
|
26
|
+
config.pol.bribeBoostApi
|
|
27
|
+
}/api/v1/wallets/${account.toLowerCase()}/proofs/validator/${validator.toLowerCase()}?page=${page}&per_page=${perPage}`,
|
|
28
|
+
{
|
|
29
|
+
cache: "no-store",
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (!result.ok) {
|
|
34
|
+
const error = await getErrorResponse(result);
|
|
35
|
+
throw new BeraError({
|
|
36
|
+
message: "Failed to fetch proofs on server",
|
|
37
|
+
cause: {
|
|
38
|
+
error,
|
|
39
|
+
result: result,
|
|
40
|
+
account,
|
|
41
|
+
validator,
|
|
42
|
+
},
|
|
43
|
+
reason: error?.reason,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const data = await result.json();
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Address, formatUnits, type PublicClient, parseUnits } from "viem";
|
|
2
|
+
|
|
3
|
+
import { stakeBeraVaultAbi } from "~/abi/pol/stakeBeraVault";
|
|
4
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param address - The address of the vault
|
|
9
|
+
* @throws {Error} If the vault is not found
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export async function getRewardTokenToBeraRate({
|
|
13
|
+
address,
|
|
14
|
+
publicClient,
|
|
15
|
+
}: {
|
|
16
|
+
address: Address;
|
|
17
|
+
publicClient?: PublicClient;
|
|
18
|
+
}): Promise<number> {
|
|
19
|
+
assertPublicClient(publicClient);
|
|
20
|
+
|
|
21
|
+
return publicClient
|
|
22
|
+
.readContract({
|
|
23
|
+
address,
|
|
24
|
+
abi: stakeBeraVaultAbi,
|
|
25
|
+
functionName: "previewRedeem" as const,
|
|
26
|
+
args: [parseUnits("1", 18)],
|
|
27
|
+
})
|
|
28
|
+
.then((rate) => Number(formatUnits(rate, 18)))
|
|
29
|
+
.catch(() => 0);
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ApiVaultFragment,
|
|
5
|
+
GetRewardVault,
|
|
6
|
+
type GetRewardVaultQuery,
|
|
7
|
+
type GetRewardVaultQueryVariables,
|
|
8
|
+
type GqlChain,
|
|
9
|
+
} from "@berachain/graphql/pol/api";
|
|
10
|
+
|
|
11
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
12
|
+
import { NotFoundError } from "~/errors/NotFoundError";
|
|
13
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param address - The address of the vault
|
|
18
|
+
* @throws {Error} If the vault is not found
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export async function getRewardVault({
|
|
22
|
+
address,
|
|
23
|
+
chainName,
|
|
24
|
+
...args
|
|
25
|
+
}: {
|
|
26
|
+
address: Address;
|
|
27
|
+
chainName?: GqlChain;
|
|
28
|
+
} & BeraJS.BaseFunctionArgs): Promise<ApiVaultFragment> {
|
|
29
|
+
const { config } = parseBaseArgs(args);
|
|
30
|
+
const resolvedChainName = chainName ?? (config.bex.chainName as GqlChain);
|
|
31
|
+
|
|
32
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
33
|
+
|
|
34
|
+
const { data } = await bexApiGraphqlClient.query<
|
|
35
|
+
GetRewardVaultQuery,
|
|
36
|
+
GetRewardVaultQueryVariables
|
|
37
|
+
>({
|
|
38
|
+
query: GetRewardVault,
|
|
39
|
+
variables: {
|
|
40
|
+
vaultId: address,
|
|
41
|
+
chain: resolvedChainName,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!data?.rewardVault) {
|
|
46
|
+
throw new NotFoundError({
|
|
47
|
+
resource: "Reward vault",
|
|
48
|
+
id: address,
|
|
49
|
+
chainId: config.chainId,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return data.rewardVault;
|
|
54
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAddress, zeroAddress } from "viem";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { getServerSidePublicClient } from "~/utils/getServerSideClient";
|
|
5
|
+
import { getRewardVaultBeaconImplementation } from "./getRewardVaultBeaconImplementation";
|
|
6
|
+
|
|
7
|
+
describe("getRewardVaultBeaconImplementation", () => {
|
|
8
|
+
const publicClient = getServerSidePublicClient();
|
|
9
|
+
it("should return the beacon implementation", async () => {
|
|
10
|
+
const beaconImplementation = await getRewardVaultBeaconImplementation({
|
|
11
|
+
publicClient,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(beaconImplementation).toBeDefined();
|
|
15
|
+
expect(isAddress(beaconImplementation)).toBe(true);
|
|
16
|
+
expect(beaconImplementation).not.toBe(zeroAddress);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Address, PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { rewardVaultFactoryAbi } from "~/abi/pol/rewardVaultFactory";
|
|
4
|
+
import { upgradableBeaconAbi } from "~/abi/utils/upgradableBeacon";
|
|
5
|
+
import { assertAddress, assertDefined } from "~/errors/assert";
|
|
6
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns the beacon implementation address for all reward vaults.
|
|
10
|
+
*/
|
|
11
|
+
export async function getRewardVaultBeaconImplementation({
|
|
12
|
+
publicClient,
|
|
13
|
+
...args
|
|
14
|
+
}: BeraJS.BaseFunctionArgs & {
|
|
15
|
+
publicClient: PublicClient;
|
|
16
|
+
}): Promise<Address> {
|
|
17
|
+
const { config } = parseBaseArgs(args);
|
|
18
|
+
const factoryAddress = config.pol.factory;
|
|
19
|
+
assertDefined(publicClient, "publicClient");
|
|
20
|
+
assertAddress(config.pol.factory, "factoryAddress");
|
|
21
|
+
|
|
22
|
+
// from the factory contract, we get the beacon address
|
|
23
|
+
const beacon = await publicClient.readContract({
|
|
24
|
+
address: factoryAddress,
|
|
25
|
+
abi: rewardVaultFactoryAbi,
|
|
26
|
+
functionName: "beacon",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// from the beacon contract, we get the current implementation address
|
|
30
|
+
return await publicClient.readContract({
|
|
31
|
+
address: beacon,
|
|
32
|
+
abi: upgradableBeaconAbi,
|
|
33
|
+
functionName: "implementation",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { getServerSidePublicClient } from "~/utils/getServerSideClient";
|
|
4
|
+
import { getRewardVaultDurationConstants } from "./getRewardVaultDurationConstants";
|
|
5
|
+
|
|
6
|
+
describe("getRewardVaultDurationConstants", () => {
|
|
7
|
+
it("should return the reward vault duration constants", async () => {
|
|
8
|
+
const publicClient = getServerSidePublicClient();
|
|
9
|
+
const rewardVaultDurationConstants = await getRewardVaultDurationConstants({
|
|
10
|
+
publicClient,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(rewardVaultDurationConstants).toBeDefined();
|
|
14
|
+
expect(rewardVaultDurationConstants.minRewardDuration).toBeTypeOf("number");
|
|
15
|
+
expect(rewardVaultDurationConstants.minRewardDuration).toBeGreaterThan(0);
|
|
16
|
+
|
|
17
|
+
expect(rewardVaultDurationConstants.maxRewardDuration).toBeTypeOf("number");
|
|
18
|
+
expect(rewardVaultDurationConstants.maxRewardDuration).toBeGreaterThan(0);
|
|
19
|
+
|
|
20
|
+
expect(rewardVaultDurationConstants.minRewardDuration).toBeLessThan(
|
|
21
|
+
rewardVaultDurationConstants.maxRewardDuration,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
4
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
5
|
+
import { getRewardVaultBeaconImplementation } from "./getRewardVaultBeaconImplementation";
|
|
6
|
+
|
|
7
|
+
export interface RewardVaultDurationConstants {
|
|
8
|
+
minRewardDuration: number;
|
|
9
|
+
maxRewardDuration: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the minimum and maximum reward duration constants for all reward vaults.
|
|
14
|
+
*/
|
|
15
|
+
export async function getRewardVaultDurationConstants({
|
|
16
|
+
publicClient,
|
|
17
|
+
...baseArgs
|
|
18
|
+
}: BeraJS.BaseFunctionArgs & {
|
|
19
|
+
publicClient: PublicClient;
|
|
20
|
+
}): Promise<RewardVaultDurationConstants> {
|
|
21
|
+
assertPublicClient(publicClient);
|
|
22
|
+
|
|
23
|
+
const beaconImplementation = await getRewardVaultBeaconImplementation({
|
|
24
|
+
publicClient,
|
|
25
|
+
...baseArgs,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const [minRewardDuration, maxRewardDuration] = await Promise.all([
|
|
29
|
+
publicClient.readContract({
|
|
30
|
+
address: beaconImplementation,
|
|
31
|
+
abi: rewardVaultAbi,
|
|
32
|
+
functionName: "MIN_REWARD_DURATION",
|
|
33
|
+
}),
|
|
34
|
+
publicClient.readContract({
|
|
35
|
+
address: beaconImplementation,
|
|
36
|
+
abi: rewardVaultAbi,
|
|
37
|
+
functionName: "MAX_REWARD_DURATION",
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
minRewardDuration: Number(minRewardDuration),
|
|
43
|
+
maxRewardDuration: Number(maxRewardDuration),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Address, type PublicClient, zeroAddress } from "viem";
|
|
2
|
+
|
|
3
|
+
import { rewardVaultFactoryAbi } from "~/abi/pol/rewardVaultFactory";
|
|
4
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
5
|
+
|
|
6
|
+
export async function getRewardVaultFromToken({
|
|
7
|
+
tokenAddress,
|
|
8
|
+
publicClient,
|
|
9
|
+
factoryAddress,
|
|
10
|
+
...args
|
|
11
|
+
}: {
|
|
12
|
+
tokenAddress: Address;
|
|
13
|
+
publicClient: PublicClient;
|
|
14
|
+
factoryAddress?: Address;
|
|
15
|
+
} & BeraJS.BaseFunctionArgs) {
|
|
16
|
+
const { config } = parseBaseArgs(args);
|
|
17
|
+
|
|
18
|
+
const vaultAddress = await publicClient.readContract({
|
|
19
|
+
address: factoryAddress ?? config.pol.factory,
|
|
20
|
+
abi: rewardVaultFactoryAbi,
|
|
21
|
+
functionName: "getVault",
|
|
22
|
+
args: [tokenAddress],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (vaultAddress === zeroAddress) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return vaultAddress;
|
|
30
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isSameAddress } from "@berachain-foundation/berancer-sdk";
|
|
2
|
+
import * as Sentry from "@sentry/nextjs";
|
|
3
|
+
import { type Address, erc20Abi, formatUnits, type PublicClient } from "viem";
|
|
4
|
+
|
|
5
|
+
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
6
|
+
import { BeraError } from "~/errors/BeraError";
|
|
7
|
+
|
|
8
|
+
export interface RewardVaultIncentive {
|
|
9
|
+
token: Address;
|
|
10
|
+
manager: Address;
|
|
11
|
+
minIncentiveRate: string;
|
|
12
|
+
incentiveRate: string;
|
|
13
|
+
remainingAmount: string;
|
|
14
|
+
symbol?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Amount of tokens that needs approval before they can be added to the incentive.
|
|
17
|
+
*
|
|
18
|
+
* Anyone can just `transfer` ERC20 to the vault, but incentive manager need to send accountIncentives to turn on distribution.
|
|
19
|
+
*/
|
|
20
|
+
pendingAmount: string;
|
|
21
|
+
decimals: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getRewardVaultIncentives({
|
|
25
|
+
address,
|
|
26
|
+
stakingToken,
|
|
27
|
+
publicClient,
|
|
28
|
+
}: {
|
|
29
|
+
address: Address;
|
|
30
|
+
stakingToken: Address;
|
|
31
|
+
publicClient: PublicClient;
|
|
32
|
+
}): Promise<RewardVaultIncentive[]> {
|
|
33
|
+
const whitelistedTokens = await publicClient.readContract({
|
|
34
|
+
address: address,
|
|
35
|
+
abi: rewardVaultAbi,
|
|
36
|
+
functionName: "getWhitelistedTokens",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Only fetch totalSupply if stakingToken is in whitelistedTokens
|
|
40
|
+
const stakingTokenIndex = whitelistedTokens.findIndex((token) =>
|
|
41
|
+
isSameAddress(stakingToken, token),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const totalSupply =
|
|
45
|
+
stakingTokenIndex !== -1
|
|
46
|
+
? await publicClient.readContract({
|
|
47
|
+
address: address,
|
|
48
|
+
abi: rewardVaultAbi,
|
|
49
|
+
functionName: "totalSupply",
|
|
50
|
+
})
|
|
51
|
+
: 0n;
|
|
52
|
+
|
|
53
|
+
const incentives = await Promise.allSettled(
|
|
54
|
+
whitelistedTokens.map(async (token) => {
|
|
55
|
+
const [incentiveInfo, decimals, symbol, totalBalance] = await Promise.all(
|
|
56
|
+
[
|
|
57
|
+
publicClient.readContract({
|
|
58
|
+
address: address,
|
|
59
|
+
abi: rewardVaultAbi,
|
|
60
|
+
functionName: "incentives",
|
|
61
|
+
args: [token],
|
|
62
|
+
}),
|
|
63
|
+
publicClient.readContract({
|
|
64
|
+
address: token,
|
|
65
|
+
abi: erc20Abi,
|
|
66
|
+
functionName: "decimals",
|
|
67
|
+
}),
|
|
68
|
+
publicClient.readContract({
|
|
69
|
+
address: token,
|
|
70
|
+
abi: erc20Abi,
|
|
71
|
+
functionName: "symbol",
|
|
72
|
+
}),
|
|
73
|
+
publicClient.readContract({
|
|
74
|
+
address: token,
|
|
75
|
+
abi: erc20Abi,
|
|
76
|
+
functionName: "balanceOf",
|
|
77
|
+
args: [address],
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const [minIncentiveRate, incentiveRate, remainingAmount, manager] =
|
|
83
|
+
incentiveInfo;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
token,
|
|
87
|
+
manager,
|
|
88
|
+
minIncentiveRate: formatUnits(minIncentiveRate, decimals),
|
|
89
|
+
incentiveRate: formatUnits(incentiveRate, decimals),
|
|
90
|
+
remainingAmount: formatUnits(remainingAmount, decimals),
|
|
91
|
+
symbol,
|
|
92
|
+
decimals,
|
|
93
|
+
pendingAmount: isSameAddress(stakingToken, token)
|
|
94
|
+
? formatUnits(totalBalance - totalSupply - remainingAmount, decimals)
|
|
95
|
+
: formatUnits(totalBalance - remainingAmount, decimals),
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
incentives.forEach((result, index) => {
|
|
101
|
+
if (result.status === "rejected") {
|
|
102
|
+
Sentry.captureException(
|
|
103
|
+
new BeraError({
|
|
104
|
+
reason: result.reason,
|
|
105
|
+
message: "Incorrect incentives token received.",
|
|
106
|
+
level: "error",
|
|
107
|
+
}),
|
|
108
|
+
{
|
|
109
|
+
extra: {
|
|
110
|
+
token: whitelistedTokens[index],
|
|
111
|
+
address: address,
|
|
112
|
+
error: result.reason,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return incentives
|
|
120
|
+
.map((result) => (result.status === "fulfilled" ? result.value : null))
|
|
121
|
+
.filter((incentive) => incentive !== null);
|
|
122
|
+
}
|