@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,191 @@
|
|
|
1
|
+
import { zeroAddress } from "viem";
|
|
2
|
+
import { describe, expect, expectTypeOf, test } from "vitest";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Aggregators,
|
|
6
|
+
type IAggregatorQuote,
|
|
7
|
+
type IRawAggregatorQuote,
|
|
8
|
+
type Token,
|
|
9
|
+
} from "~/types/dex";
|
|
10
|
+
import { formatAggregatorsQuotes } from "./formatAggregatorsQuotes";
|
|
11
|
+
|
|
12
|
+
const mockToken = (symbol: string, decimals: number): Token => ({
|
|
13
|
+
symbol,
|
|
14
|
+
decimals,
|
|
15
|
+
address: zeroAddress,
|
|
16
|
+
name: symbol,
|
|
17
|
+
chainId: 1,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const mockCalldata = {
|
|
21
|
+
params: [],
|
|
22
|
+
functionName: "",
|
|
23
|
+
abi: [],
|
|
24
|
+
address: zeroAddress,
|
|
25
|
+
value: BigInt(0),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const mockQuotes: IRawAggregatorQuote<false>[] = [
|
|
29
|
+
{
|
|
30
|
+
amountOut: "1000000000000000000", // 1 token
|
|
31
|
+
amountIn: "2000000000000000000", // 2 tokens
|
|
32
|
+
name: Aggregators.Fly,
|
|
33
|
+
spender: zeroAddress,
|
|
34
|
+
calldata: mockCalldata,
|
|
35
|
+
swapFeeBps: 10,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
amountOut: "1200000000000000000", // 1.2 tokens
|
|
39
|
+
amountIn: "2000000000000000000", // 2 tokens
|
|
40
|
+
name: Aggregators.HubPools,
|
|
41
|
+
spender: zeroAddress,
|
|
42
|
+
calldata: mockCalldata,
|
|
43
|
+
swapFeeBps: 10,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
amountOut: "800000000000000000", // 0.8 tokens
|
|
47
|
+
amountIn: "2000000000000000000", // 2 tokens
|
|
48
|
+
name: Aggregators.Oogabooga,
|
|
49
|
+
spender: zeroAddress,
|
|
50
|
+
calldata: mockCalldata,
|
|
51
|
+
swapFeeBps: 10,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
describe("formatAggregatorsQuotes", () => {
|
|
56
|
+
test("should return an empty array if no quotes are provided", () => {
|
|
57
|
+
expect(formatAggregatorsQuotes([], undefined, undefined, 0, 0)).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("should return the correct type", () => {
|
|
61
|
+
const results = formatAggregatorsQuotes(
|
|
62
|
+
mockQuotes,
|
|
63
|
+
undefined,
|
|
64
|
+
undefined,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
);
|
|
68
|
+
expectTypeOf(results).toEqualTypeOf<IAggregatorQuote[]>();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("should sort quotes by amountOut in descending order", () => {
|
|
72
|
+
const tokenIn = mockToken("TOKEN_IN", 18);
|
|
73
|
+
const tokenOut = mockToken("TOKEN_OUT", 18);
|
|
74
|
+
|
|
75
|
+
const results = formatAggregatorsQuotes(
|
|
76
|
+
mockQuotes,
|
|
77
|
+
tokenIn,
|
|
78
|
+
tokenOut,
|
|
79
|
+
1,
|
|
80
|
+
1,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(results[0].amountOut).toBe("1.2");
|
|
84
|
+
expect(results[1].amountOut).toBe("1");
|
|
85
|
+
expect(results[2].amountOut).toBe("0.8");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("should calculate relative loss percentage correctly", () => {
|
|
89
|
+
const tokenIn = mockToken("ABC", 18);
|
|
90
|
+
const tokenOut = mockToken("XYZ", 18);
|
|
91
|
+
|
|
92
|
+
const results = formatAggregatorsQuotes(
|
|
93
|
+
mockQuotes,
|
|
94
|
+
tokenIn,
|
|
95
|
+
tokenOut,
|
|
96
|
+
1,
|
|
97
|
+
1,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// best quote has 0% loss
|
|
101
|
+
expect(results[0].relativeLossPercentage).toBe(0);
|
|
102
|
+
|
|
103
|
+
// other quotes show percentage loss relative to best quote
|
|
104
|
+
expect(results[1].relativeLossPercentage).toBeCloseTo(0.166);
|
|
105
|
+
expect(results[2].relativeLossPercentage).toBeCloseTo(0.333);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("should handle tokens with different decimals", () => {
|
|
109
|
+
const tokenIn = mockToken("USDC", 6);
|
|
110
|
+
const tokenOut = mockToken("ETH", 18);
|
|
111
|
+
|
|
112
|
+
const quotesWithDifferentDecimals: IRawAggregatorQuote<false>[] = [
|
|
113
|
+
{
|
|
114
|
+
amountOut: "1000000000000000000", // 1 ETH
|
|
115
|
+
amountIn: "2000000", // 2 USDC
|
|
116
|
+
name: Aggregators.Fly,
|
|
117
|
+
spender: zeroAddress,
|
|
118
|
+
calldata: mockCalldata,
|
|
119
|
+
swapFeeBps: 10,
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
const results = formatAggregatorsQuotes(
|
|
124
|
+
quotesWithDifferentDecimals,
|
|
125
|
+
tokenIn,
|
|
126
|
+
tokenOut,
|
|
127
|
+
1,
|
|
128
|
+
1,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(results[0].amountIn).toBe("2");
|
|
132
|
+
expect(results[0].amountOut).toBe("1");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("should calculate amountOutUsd correctly", () => {
|
|
136
|
+
const tokenIn = mockToken("ABC", 18);
|
|
137
|
+
const tokenOut = mockToken("XYZ", 18);
|
|
138
|
+
const tokenOutPrice = 100; // $100 per token
|
|
139
|
+
|
|
140
|
+
const results = formatAggregatorsQuotes(
|
|
141
|
+
mockQuotes,
|
|
142
|
+
tokenIn,
|
|
143
|
+
tokenOut,
|
|
144
|
+
1,
|
|
145
|
+
tokenOutPrice,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// amountOutUsd = amountOut * tokenOutPrice
|
|
149
|
+
expect(results[0].amountOutUsd).toBe("120"); // 1.2 * $100
|
|
150
|
+
expect(results[1].amountOutUsd).toBe("100"); // 1.0 * $100
|
|
151
|
+
expect(results[2].amountOutUsd).toBe("80"); // 0.8 * $100
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("should calculate amountOutUsd correctly with different decimals", () => {
|
|
155
|
+
const tokenIn = mockToken("USDC", 6);
|
|
156
|
+
const tokenOut = mockToken("ETH", 18);
|
|
157
|
+
const tokenOutPrice = 100.5; // $100.50 per token
|
|
158
|
+
|
|
159
|
+
const results = formatAggregatorsQuotes(
|
|
160
|
+
mockQuotes,
|
|
161
|
+
tokenIn,
|
|
162
|
+
tokenOut,
|
|
163
|
+
1,
|
|
164
|
+
tokenOutPrice,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// amountOutUsd = amountOut * tokenOutPrice
|
|
168
|
+
expect(results[0].amountOutUsd).toBe("120.6"); // 1.2 * $100.50
|
|
169
|
+
expect(results[1].amountOutUsd).toBe("100.5"); // 1.0 * $100.50
|
|
170
|
+
expect(results[2].amountOutUsd).toBe("80.4"); // 0.8 * $100.50
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("should calculate price impact when token prices provided", () => {
|
|
174
|
+
const tokenIn = mockToken("ABC", 18);
|
|
175
|
+
const tokenOut = mockToken("XYZ", 18);
|
|
176
|
+
|
|
177
|
+
const results = formatAggregatorsQuotes(
|
|
178
|
+
mockQuotes,
|
|
179
|
+
tokenIn,
|
|
180
|
+
tokenOut,
|
|
181
|
+
100, // $100 per token in
|
|
182
|
+
50, // $50 per token out
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// For best quote (1.2 out for 2 in):
|
|
186
|
+
// USD in = 2 * $100 = $200
|
|
187
|
+
// USD out = 1.2 * $50 = $60
|
|
188
|
+
// Price impact = 1 - (60/200) = 0.7 = 70%
|
|
189
|
+
expect(results[0].priceImpactPercentage).toBe(0.7);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BribeBoostRewardItem } from "~/types/bribe-boost";
|
|
2
|
+
|
|
3
|
+
export const formatIncentivesTokenMap = (
|
|
4
|
+
allRewards: BribeBoostRewardItem[],
|
|
5
|
+
) => {
|
|
6
|
+
const tokenMap = new Set<string>();
|
|
7
|
+
|
|
8
|
+
allRewards.forEach((item: BribeBoostRewardItem) => {
|
|
9
|
+
if (Array.isArray(item.rewards)) {
|
|
10
|
+
item.rewards.forEach((reward) => {
|
|
11
|
+
if (reward.token) {
|
|
12
|
+
tokenMap.add(reward.token);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return tokenMap;
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const formatInputTokenValue = (inputValue: string) => {
|
|
2
|
+
if (inputValue === "0") return inputValue;
|
|
3
|
+
// Remove all non-numeric characters except for the decimal point, and remove leading zeros
|
|
4
|
+
let filteredValue = inputValue.replace(/^0+/, "").replaceAll(/[^0-9.]/g, "");
|
|
5
|
+
|
|
6
|
+
// Keep the 0
|
|
7
|
+
if (filteredValue.startsWith(".")) {
|
|
8
|
+
filteredValue = `0${filteredValue}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return filteredValue;
|
|
12
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
export type BigNumberValue = string | number | BigNumber;
|
|
4
|
+
|
|
5
|
+
export interface FormatNumberOptions {
|
|
6
|
+
/** Number of visible decimal places */
|
|
7
|
+
visibleDecimals?: number;
|
|
8
|
+
/** Whether to use compact notation (K, M, B, etc.) */
|
|
9
|
+
compact?: boolean;
|
|
10
|
+
/** Show as percentage */
|
|
11
|
+
percent?: boolean;
|
|
12
|
+
/** Round down instead of normal rounding */
|
|
13
|
+
roundDown?: boolean;
|
|
14
|
+
/** Round up instead of normal rounding */
|
|
15
|
+
roundUp?: boolean;
|
|
16
|
+
/** Threshold above which compact notation is used */
|
|
17
|
+
compactThreshold?: number;
|
|
18
|
+
/** Maximum value to display (shows ∞ if exceeded) */
|
|
19
|
+
maxValue?: number;
|
|
20
|
+
/** Currency symbol (e.g., "USD" for $) */
|
|
21
|
+
symbol?: string;
|
|
22
|
+
/** Prefix text */
|
|
23
|
+
prefixText?: string;
|
|
24
|
+
/** Suffix text */
|
|
25
|
+
suffixText?: string;
|
|
26
|
+
/** Show "< min" or "> min" indicators for very small values */
|
|
27
|
+
showIsSmallerThanMin?: boolean;
|
|
28
|
+
/** Text to show if value is null/undefined */
|
|
29
|
+
ifNullish?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const POSTFIXES = ["", "K", "M", "B", "T", "P", "E", "Z", "Y"];
|
|
33
|
+
|
|
34
|
+
function valueToBigNumber(amount: BigNumberValue): BigNumber {
|
|
35
|
+
if (amount instanceof BigNumber) return amount;
|
|
36
|
+
return new BigNumber(amount);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeBN(n: BigNumberValue, decimals: number): BigNumber {
|
|
40
|
+
return valueToBigNumber(n).shiftedBy(decimals * -1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatNumber(
|
|
44
|
+
value: BigNumberValue | undefined | null,
|
|
45
|
+
options: FormatNumberOptions | number = {},
|
|
46
|
+
): string {
|
|
47
|
+
if (typeof options === "number") {
|
|
48
|
+
const decimals = options;
|
|
49
|
+
if (value === undefined || value === null) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof value === "object") {
|
|
54
|
+
throw new Error("Value must be a number if using deprecated version");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Convert to string with up to 8 decimal places
|
|
58
|
+
let formatted = Number(value).toFixed(decimals);
|
|
59
|
+
// Remove trailing zeros and decimal point if not needed
|
|
60
|
+
formatted = formatted.replace(/(\.\d*?[1-9])0+$|\.0*$/, "$1");
|
|
61
|
+
return formatted;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const {
|
|
65
|
+
visibleDecimals,
|
|
66
|
+
compact = true,
|
|
67
|
+
percent = false,
|
|
68
|
+
roundDown = false,
|
|
69
|
+
roundUp = false,
|
|
70
|
+
compactThreshold,
|
|
71
|
+
maxValue,
|
|
72
|
+
symbol,
|
|
73
|
+
prefixText = "",
|
|
74
|
+
suffixText = "",
|
|
75
|
+
showIsSmallerThanMin = true,
|
|
76
|
+
ifNullish = "",
|
|
77
|
+
} = options || {};
|
|
78
|
+
|
|
79
|
+
// Handle null/undefined values
|
|
80
|
+
if (value === undefined || value === null) {
|
|
81
|
+
return ifNullish;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const number = percent ? Number(value) * 100 : Number(value);
|
|
85
|
+
|
|
86
|
+
// Handle special numeric values
|
|
87
|
+
if (Number.isNaN(number)) {
|
|
88
|
+
return "NaN";
|
|
89
|
+
}
|
|
90
|
+
if (number === Number.POSITIVE_INFINITY) {
|
|
91
|
+
return "Infinity";
|
|
92
|
+
}
|
|
93
|
+
if (number === Number.NEGATIVE_INFINITY) {
|
|
94
|
+
return "-Infinity";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Determine decimal places
|
|
98
|
+
let decimals: number = visibleDecimals ?? 0;
|
|
99
|
+
if (number === 0) {
|
|
100
|
+
decimals = 0;
|
|
101
|
+
} else if (visibleDecimals === undefined) {
|
|
102
|
+
if (Math.abs(number) > 1 || percent || symbol === "USD") {
|
|
103
|
+
decimals = 2;
|
|
104
|
+
} else {
|
|
105
|
+
decimals = 7;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const minValue = 10 ** -(decimals as number);
|
|
110
|
+
const isSmallerThanMin =
|
|
111
|
+
number !== 0 && Math.abs(number) < Math.abs(minValue);
|
|
112
|
+
const isNegative = number < 0;
|
|
113
|
+
const isBiggerThanMax = maxValue ? Math.abs(number) > maxValue : false;
|
|
114
|
+
|
|
115
|
+
let formattedNumber = isSmallerThanMin ? minValue : number;
|
|
116
|
+
const forceCompact =
|
|
117
|
+
compact && (!compactThreshold || Math.abs(number) > compactThreshold);
|
|
118
|
+
|
|
119
|
+
// Apply rounding for non-compact numbers
|
|
120
|
+
if (roundDown && !forceCompact) {
|
|
121
|
+
formattedNumber =
|
|
122
|
+
Math.trunc(Number(formattedNumber) * 10 ** decimals) / 10 ** decimals;
|
|
123
|
+
} else if (roundUp && !forceCompact) {
|
|
124
|
+
formattedNumber =
|
|
125
|
+
Math.ceil(Number(formattedNumber) * 10 ** decimals) / 10 ** decimals;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let formattedValue: string;
|
|
129
|
+
|
|
130
|
+
if (isBiggerThanMax) {
|
|
131
|
+
formattedValue = number > maxValue! ? "∞" : "-∞";
|
|
132
|
+
} else if (!forceCompact) {
|
|
133
|
+
const absFormatted = new Intl.NumberFormat("en-US", {
|
|
134
|
+
maximumFractionDigits: decimals,
|
|
135
|
+
minimumFractionDigits: decimals,
|
|
136
|
+
}).format(Math.abs(formattedNumber));
|
|
137
|
+
formattedValue = `${isNegative ? "-" : ""}${absFormatted}`;
|
|
138
|
+
} else {
|
|
139
|
+
// Compact number formatting
|
|
140
|
+
const bnValue = valueToBigNumber(formattedNumber);
|
|
141
|
+
let integerPlaces = bnValue.abs().toFixed(0).length;
|
|
142
|
+
if (compactThreshold && Math.abs(number) <= compactThreshold) {
|
|
143
|
+
integerPlaces = 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const significantDigitsGroup = Math.min(
|
|
147
|
+
Math.floor(integerPlaces ? (integerPlaces - 1) / 3 : 0),
|
|
148
|
+
POSTFIXES.length - 1,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const postfix = POSTFIXES[significantDigitsGroup];
|
|
152
|
+
let compactValue = normalizeBN(
|
|
153
|
+
bnValue,
|
|
154
|
+
3 * significantDigitsGroup,
|
|
155
|
+
).toNumber();
|
|
156
|
+
|
|
157
|
+
if (roundDown) {
|
|
158
|
+
compactValue =
|
|
159
|
+
Math.trunc(Number(compactValue) * 10 ** decimals) / 10 ** decimals;
|
|
160
|
+
} else if (roundUp) {
|
|
161
|
+
compactValue =
|
|
162
|
+
Math.ceil(Number(compactValue) * 10 ** decimals) / 10 ** decimals;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const prefix = new Intl.NumberFormat("en-US", {
|
|
166
|
+
maximumFractionDigits: decimals,
|
|
167
|
+
minimumFractionDigits: decimals,
|
|
168
|
+
}).format(compactValue);
|
|
169
|
+
|
|
170
|
+
formattedValue = `${prefix}${postfix}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Build the final formatted string
|
|
174
|
+
const parts: string[] = [];
|
|
175
|
+
|
|
176
|
+
// Add prefix text
|
|
177
|
+
if (prefixText) {
|
|
178
|
+
parts.push(prefixText);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Add smaller than indicator
|
|
182
|
+
if (isSmallerThanMin && showIsSmallerThanMin) {
|
|
183
|
+
parts.push(number < 0 ? ">" : "<");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Add USD symbol
|
|
187
|
+
if (symbol?.toLowerCase() === "usd" && !percent) {
|
|
188
|
+
parts.push("$");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Add the formatted number
|
|
192
|
+
parts.push(formattedValue);
|
|
193
|
+
|
|
194
|
+
// Add percentage symbol
|
|
195
|
+
if (percent) {
|
|
196
|
+
parts.push("%");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Add other symbols
|
|
200
|
+
if (symbol?.toLowerCase() !== "usd" && typeof symbol !== "undefined") {
|
|
201
|
+
parts.push(" ", symbol);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Add suffix text
|
|
205
|
+
if (suffixText) {
|
|
206
|
+
parts.push(suffixText);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return parts.join("");
|
|
210
|
+
}
|
|
211
|
+
export const getSafeNumber = (value: string | undefined): number => {
|
|
212
|
+
if (!value) return 0;
|
|
213
|
+
return Number(value) > Number.MAX_SAFE_INTEGER
|
|
214
|
+
? Number.MAX_SAFE_INTEGER
|
|
215
|
+
: (Number(value) ?? 0);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const truncateDecimal = (
|
|
219
|
+
value: string | number | undefined,
|
|
220
|
+
maxDecimal: number,
|
|
221
|
+
): string => {
|
|
222
|
+
if (!value) return "0";
|
|
223
|
+
const [integerPart = "0", decimalPart = "0"] = `${value}`.split(".");
|
|
224
|
+
return `${integerPart}.${decimalPart.substring(0, maxDecimal)}`;
|
|
225
|
+
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { formatNumber } from "./formatNumber";
|
|
5
|
+
|
|
6
|
+
describe("formatNumber", () => {
|
|
7
|
+
it("should return empty string for null input by default", () => {
|
|
8
|
+
const result = formatNumber(null);
|
|
9
|
+
expect(result).toBe("");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should return empty string for undefined input by default", () => {
|
|
13
|
+
const result = formatNumber(undefined);
|
|
14
|
+
expect(result).toBe("");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should return ifNullish text for null/undefined when provided", () => {
|
|
18
|
+
const result1 = formatNumber(null, { ifNullish: "N/A" });
|
|
19
|
+
expect(result1).toBe("N/A");
|
|
20
|
+
|
|
21
|
+
const result2 = formatNumber(undefined, { ifNullish: "No data" });
|
|
22
|
+
expect(result2).toBe("No data");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should format basic numbers", () => {
|
|
26
|
+
const result = formatNumber(123.456);
|
|
27
|
+
expect(result).toBe("123.46");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should format negative numbers", () => {
|
|
31
|
+
const result = formatNumber(-123.456);
|
|
32
|
+
expect(result).toBe("-123.46");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should format percentages", () => {
|
|
36
|
+
const result = formatNumber(0.1234, { percent: true });
|
|
37
|
+
expect(result).toBe("12.34%");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should handle zero", () => {
|
|
41
|
+
const result = formatNumber(0);
|
|
42
|
+
expect(result).toBe("0");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should detect and show smaller than minimum values", () => {
|
|
46
|
+
const result = formatNumber(0.000001, { visibleDecimals: 2 });
|
|
47
|
+
expect(result).toBe("<0.01");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should detect and show bigger than maximum values", () => {
|
|
51
|
+
const result = formatNumber(1000000, { maxValue: 100000 });
|
|
52
|
+
expect(result).toBe("∞");
|
|
53
|
+
|
|
54
|
+
const result2 = formatNumber(-1000000, { maxValue: 100000 });
|
|
55
|
+
expect(result2).toBe("-∞");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should use compact notation by default", () => {
|
|
59
|
+
const result = formatNumber(1500);
|
|
60
|
+
expect(result).toBe("1.50K");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should not use compact notation when disabled", () => {
|
|
64
|
+
const result = formatNumber(1500, { compact: false });
|
|
65
|
+
expect(result).toBe("1,500.00");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should respect compact threshold", () => {
|
|
69
|
+
const result = formatNumber(500, { compactThreshold: 1000 });
|
|
70
|
+
expect(result).toBe("500.00");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should handle rounding down", () => {
|
|
74
|
+
const result = formatNumber(123.789, {
|
|
75
|
+
visibleDecimals: 2,
|
|
76
|
+
roundDown: true,
|
|
77
|
+
compact: false,
|
|
78
|
+
});
|
|
79
|
+
expect(result).toBe("123.78");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should handle rounding up", () => {
|
|
83
|
+
const result = formatNumber(123.781, {
|
|
84
|
+
visibleDecimals: 2,
|
|
85
|
+
roundUp: true,
|
|
86
|
+
compact: false,
|
|
87
|
+
});
|
|
88
|
+
expect(result).toBe("123.79");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should auto-determine decimals for large numbers", () => {
|
|
92
|
+
const result = formatNumber(1000, { compact: false });
|
|
93
|
+
expect(result).toBe("1,000.00");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should auto-determine decimals for small numbers", () => {
|
|
97
|
+
const result = formatNumber(0.123456789, { compact: false });
|
|
98
|
+
expect(result).toBe("0.1234568");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should handle USD symbol", () => {
|
|
102
|
+
const result = formatNumber(123.45, { symbol: "USD", compact: false });
|
|
103
|
+
expect(result).toBe("$123.45");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should handle other symbols", () => {
|
|
107
|
+
const result = formatNumber(123.45, { symbol: "ETH", compact: false });
|
|
108
|
+
expect(result).toBe("123.45 ETH");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should handle BigNumber input", () => {
|
|
112
|
+
const input = new BigNumber("123.456");
|
|
113
|
+
const result = formatNumber(input);
|
|
114
|
+
expect(result).toBe("123.46");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should handle string input", () => {
|
|
118
|
+
const result = formatNumber("123.456");
|
|
119
|
+
expect(result).toBe("123.46");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should handle prefix text", () => {
|
|
123
|
+
const result = formatNumber(123.45, {
|
|
124
|
+
prefixText: "Value: ",
|
|
125
|
+
compact: false,
|
|
126
|
+
});
|
|
127
|
+
expect(result).toBe("Value: 123.45");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should handle suffix text", () => {
|
|
131
|
+
const result = formatNumber(123.45, { suffixText: " USD", compact: false });
|
|
132
|
+
expect(result).toBe("123.45 USD");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should handle percentage with symbol", () => {
|
|
136
|
+
const result = formatNumber(0.1234, { percent: true, compact: false });
|
|
137
|
+
expect(result).toBe("12.34%");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should handle USD symbol with percentage (no $ shown)", () => {
|
|
141
|
+
const result = formatNumber(0.1234, {
|
|
142
|
+
symbol: "USD",
|
|
143
|
+
percent: true,
|
|
144
|
+
compact: false,
|
|
145
|
+
});
|
|
146
|
+
expect(result).toBe("12.34%");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should show smaller than indicator for positive small values", () => {
|
|
150
|
+
const result = formatNumber(0.000001, {
|
|
151
|
+
visibleDecimals: 2,
|
|
152
|
+
compact: false,
|
|
153
|
+
});
|
|
154
|
+
expect(result).toBe("<0.01");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should show greater than indicator for negative small values", () => {
|
|
158
|
+
const result = formatNumber(-0.000001, {
|
|
159
|
+
visibleDecimals: 2,
|
|
160
|
+
compact: false,
|
|
161
|
+
});
|
|
162
|
+
expect(result).toBe(">-0.01");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should not show smaller than indicator when disabled", () => {
|
|
166
|
+
const result = formatNumber(0.000001, {
|
|
167
|
+
visibleDecimals: 2,
|
|
168
|
+
compact: false,
|
|
169
|
+
showIsSmallerThanMin: false,
|
|
170
|
+
});
|
|
171
|
+
expect(result).toBe("0.01");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should handle all options together", () => {
|
|
175
|
+
const result = formatNumber(123.45, {
|
|
176
|
+
prefixText: "Price: ",
|
|
177
|
+
suffixText: " total",
|
|
178
|
+
symbol: "USD",
|
|
179
|
+
compact: false,
|
|
180
|
+
});
|
|
181
|
+
expect(result).toBe("Price: $123.45 total");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should format compact numbers with K postfix", () => {
|
|
185
|
+
const result = formatNumber(1500, { visibleDecimals: 2 });
|
|
186
|
+
expect(result).toBe("1.50K");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should not use compact when not needed", () => {
|
|
190
|
+
const result = formatNumber(900, { visibleDecimals: 2 });
|
|
191
|
+
expect(result).toBe("900.00");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should format compact numbers with M postfix", () => {
|
|
195
|
+
const result = formatNumber(1500000, { visibleDecimals: 2 });
|
|
196
|
+
expect(result).toBe("1.50M");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("should format compact numbers with B postfix", () => {
|
|
200
|
+
const result = formatNumber(1500000000, { visibleDecimals: 2 });
|
|
201
|
+
expect(result).toBe("1.50B");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should handle compact rounding down", () => {
|
|
205
|
+
const result = formatNumber(1237, { visibleDecimals: 2, roundDown: true });
|
|
206
|
+
expect(result).toBe("1.23K");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("should handle compact rounding up", () => {
|
|
210
|
+
const result = formatNumber(1232, { visibleDecimals: 2, roundUp: true });
|
|
211
|
+
expect(result).toBe("1.24K");
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("FormatNumber Edge cases", () => {
|
|
216
|
+
it("should handle very large numbers", () => {
|
|
217
|
+
const result = formatNumber(1e21);
|
|
218
|
+
expect(result).toContain("Z");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should handle very small positive numbers", () => {
|
|
222
|
+
const result = formatNumber(1e-10, { compact: false });
|
|
223
|
+
expect(result).toContain("<");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("should handle very small negative numbers", () => {
|
|
227
|
+
const result = formatNumber(-1e-10, { compact: false });
|
|
228
|
+
expect(result).toContain(">");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("should handle infinity", () => {
|
|
232
|
+
const result = formatNumber(Number.POSITIVE_INFINITY);
|
|
233
|
+
expect(result).toBe("Infinity");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("should handle negative infinity", () => {
|
|
237
|
+
const result = formatNumber(Number.NEGATIVE_INFINITY);
|
|
238
|
+
expect(result).toBe("-Infinity");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should handle NaN", () => {
|
|
242
|
+
const result = formatNumber(Number.NaN);
|
|
243
|
+
expect(result).toBe("NaN");
|
|
244
|
+
});
|
|
245
|
+
});
|