@berachain/berajs 0.1.2 → 0.2.1
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/{BeraError-D1HS_rbb.d.cts → BeraError-_mQdkanr.d.cts} +35 -10
- package/dist/{BeraError-D1HS_rbb.d.ts → BeraError-_mQdkanr.d.ts} +35 -10
- package/dist/HoneyConfigProvider-CK6mOKFH.d.ts +390 -0
- package/dist/HoneyConfigProvider-Ca3ouozs.d.cts +390 -0
- package/dist/{RequestError-D8AE6xnI.d.cts → RequestError-A8XJ6QR9.d.cts} +1 -1
- package/dist/{RequestError-m4jxyM7D.d.ts → RequestError-Dk97z8rm.d.ts} +1 -1
- package/dist/abi/exports.cjs +2 -0
- package/dist/abi/exports.cjs.map +1 -0
- package/dist/abi/{index.d.cts → exports.d.cts} +12369 -9122
- package/dist/abi/{index.d.ts → exports.d.ts} +12369 -9122
- package/dist/abi/exports.mjs +2 -0
- package/dist/abi/exports.mjs.map +1 -0
- package/dist/actions/exports.cjs +2 -0
- package/dist/actions/exports.cjs.map +1 -0
- package/dist/actions/{index.d.cts → exports.d.cts} +79 -107
- package/dist/actions/{index.d.ts → exports.d.ts} +79 -107
- package/dist/actions/exports.mjs +2 -0
- package/dist/actions/exports.mjs.map +1 -0
- package/dist/chunk-22J3YJDN.cjs +2 -0
- package/dist/chunk-22J3YJDN.cjs.map +1 -0
- package/dist/chunk-2LL3P5PN.mjs +2 -0
- package/dist/chunk-2LL3P5PN.mjs.map +1 -0
- package/dist/chunk-3YXSUBA5.mjs +2 -0
- package/dist/chunk-3YXSUBA5.mjs.map +1 -0
- package/dist/chunk-55L7STYD.mjs +2 -0
- package/dist/chunk-55L7STYD.mjs.map +1 -0
- package/dist/chunk-575OK77P.mjs +2 -0
- package/dist/chunk-575OK77P.mjs.map +1 -0
- package/dist/chunk-6LDOG5RL.cjs +2 -0
- package/dist/chunk-6LDOG5RL.cjs.map +1 -0
- package/dist/chunk-7LNBSOVV.cjs +2 -0
- package/dist/chunk-7LNBSOVV.cjs.map +1 -0
- package/dist/chunk-7SMWQ6SN.mjs +2 -0
- package/dist/chunk-7SMWQ6SN.mjs.map +1 -0
- package/dist/chunk-7WRTK7RJ.mjs +2 -0
- package/dist/chunk-7WRTK7RJ.mjs.map +1 -0
- package/dist/chunk-A4UDYSB6.mjs +4 -0
- package/dist/chunk-A4UDYSB6.mjs.map +1 -0
- package/dist/chunk-AX2YQQFQ.mjs +2 -0
- package/dist/chunk-AX2YQQFQ.mjs.map +1 -0
- package/dist/chunk-C3FHGFLK.mjs +2 -0
- package/dist/chunk-C3FHGFLK.mjs.map +1 -0
- package/dist/chunk-C6ZGUO4H.cjs +2 -0
- package/dist/chunk-C6ZGUO4H.cjs.map +1 -0
- package/dist/chunk-CYKCYPFR.cjs +2 -0
- package/dist/chunk-CYKCYPFR.cjs.map +1 -0
- package/dist/chunk-ECRMUMTA.mjs +2 -0
- package/dist/chunk-ECRMUMTA.mjs.map +1 -0
- package/dist/chunk-F4BKSBEM.mjs +2 -0
- package/dist/chunk-F4BKSBEM.mjs.map +1 -0
- package/dist/chunk-FCWDGE62.cjs +2 -0
- package/dist/chunk-FCWDGE62.cjs.map +1 -0
- package/dist/chunk-FL2N3XHK.cjs +2 -0
- package/dist/chunk-FL2N3XHK.cjs.map +1 -0
- package/dist/chunk-MUCEYO3E.cjs +4 -0
- package/dist/chunk-MUCEYO3E.cjs.map +1 -0
- package/dist/chunk-NAXAZJJY.mjs +2 -0
- package/dist/chunk-NAXAZJJY.mjs.map +1 -0
- package/dist/chunk-OGJMSGB2.mjs +2 -0
- package/dist/chunk-OGJMSGB2.mjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs +2 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -0
- package/dist/chunk-P2Q7CMUD.cjs +2 -0
- package/dist/chunk-P2Q7CMUD.cjs.map +1 -0
- package/dist/chunk-PKXAW6MO.cjs +2 -0
- package/dist/chunk-PKXAW6MO.cjs.map +1 -0
- package/dist/chunk-Q3SCM6WL.mjs +2 -0
- package/dist/chunk-Q3SCM6WL.mjs.map +1 -0
- package/dist/chunk-SWMJQOH6.cjs +2 -0
- package/dist/chunk-SWMJQOH6.cjs.map +1 -0
- package/dist/chunk-TEBJWAVU.mjs +2 -0
- package/dist/chunk-TEBJWAVU.mjs.map +1 -0
- package/dist/chunk-THATXCJK.mjs +2 -0
- package/dist/chunk-THATXCJK.mjs.map +1 -0
- package/dist/chunk-VP7XUOSI.cjs +2 -0
- package/dist/chunk-VP7XUOSI.cjs.map +1 -0
- package/dist/chunk-VXL2ZZ4X.cjs +2 -0
- package/dist/chunk-VXL2ZZ4X.cjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs +2 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -0
- package/dist/chunk-XNJLSA6P.cjs +2 -0
- package/dist/chunk-XNJLSA6P.cjs.map +1 -0
- package/dist/chunk-YXLFOEZN.mjs +2 -0
- package/dist/chunk-YXLFOEZN.mjs.map +1 -0
- package/dist/chunk-YZV5LKIP.cjs +2 -0
- package/dist/chunk-YZV5LKIP.cjs.map +1 -0
- package/dist/contexts/exports.cjs +2 -0
- package/dist/contexts/exports.cjs.map +1 -0
- package/dist/contexts/{index.d.cts → exports.d.cts} +10 -27
- package/dist/contexts/{index.d.ts → exports.d.ts} +10 -27
- package/dist/contexts/exports.mjs +2 -0
- package/dist/contexts/exports.mjs.map +1 -0
- package/dist/{defaultFlags-V-tJs2K8.d.cts → defaultFlags-d0kPbT0i.d.cts} +1 -1
- package/dist/{defaultFlags-V-tJs2K8.d.ts → defaultFlags-d0kPbT0i.d.ts} +1 -1
- package/dist/dex-C_BB0b0O.d.cts +37 -0
- package/dist/dex-C_BB0b0O.d.ts +37 -0
- package/dist/enum/exports.cjs +2 -0
- package/dist/enum/exports.cjs.map +1 -0
- package/dist/enum/exports.d.cts +23 -0
- package/dist/enum/exports.d.ts +23 -0
- package/dist/enum/exports.mjs +2 -0
- package/dist/enum/exports.mjs.map +1 -0
- package/dist/errors/exports.cjs +2 -0
- package/dist/errors/exports.cjs.map +1 -0
- package/dist/errors/exports.d.cts +408 -0
- package/dist/errors/exports.d.ts +408 -0
- package/dist/errors/exports.mjs +2 -0
- package/dist/{getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts → getValidatorQueuedOperatorAddress-Dstyaomr.d.cts} +125 -15
- package/dist/{getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts → getValidatorQueuedOperatorAddress-RW4OMcD1.d.ts} +125 -15
- package/dist/global.d-CN6l2b9E.d.cts +473 -0
- package/dist/global.d-wYu8G8IQ.d.ts +473 -0
- package/dist/honey-CYm0RWf4.d.cts +14 -0
- package/dist/honey-CYm0RWf4.d.ts +14 -0
- package/dist/hooks/exports.cjs +4 -0
- package/dist/hooks/exports.cjs.map +1 -0
- package/dist/hooks/{index.d.cts → exports.d.cts} +218 -176
- package/dist/hooks/{index.d.ts → exports.d.ts} +218 -176
- package/dist/hooks/exports.mjs +4 -0
- package/dist/hooks/exports.mjs.map +1 -0
- package/dist/{txnEnum-BQKDfaeH.d.cts → txnEnum-BlBYhNRl.d.cts} +75 -1
- package/dist/{txnEnum-BQKDfaeH.d.ts → txnEnum-BlBYhNRl.d.ts} +75 -1
- package/dist/types/exports.cjs +1 -0
- package/dist/types/exports.cjs.map +1 -0
- package/dist/types/exports.d.cts +57 -0
- package/dist/types/exports.d.ts +57 -0
- package/dist/types/exports.mjs +1 -0
- package/dist/{useHoneySwapState-C-9BV4VB.d.cts → useHoneySwapState-B-vmIP1b.d.cts} +1 -1
- package/dist/{useHoneySwapState-CUY5Sm1b.d.ts → useHoneySwapState-D1DKG_Of.d.ts} +1 -1
- package/dist/utils/exports.cjs +2 -0
- package/dist/utils/exports.cjs.map +1 -0
- package/dist/utils/{index.d.cts → exports.d.cts} +83 -20
- package/dist/utils/{index.d.ts → exports.d.ts} +83 -20
- package/dist/utils/exports.mjs +2 -0
- package/dist/utils/exports.mjs.map +1 -0
- package/package.json +19 -20
- package/src/abi/{index.ts → exports.ts} +3 -0
- package/src/abi/pol/LSTStakerVault.ts +2032 -0
- package/src/abi/utils/openChainErrors.ts +71 -30
- package/src/abi/utils/thirdwebMinimalAccount.ts +616 -0
- package/src/actions/clients/BeraApolloClient.ts +8 -6
- package/src/actions/dex/__tests__/aggregators.unit.test.ts +2 -5
- package/src/actions/dex/aggregators/base.ts +74 -16
- package/src/actions/dex/aggregators/bex.ts +54 -74
- package/src/actions/dex/aggregators/bgt.ts +31 -8
- package/src/actions/dex/aggregators/{enso.ts → enso/enso.ts} +18 -14
- package/src/actions/dex/aggregators/enso/ensoErc4626.debug.test.ts +37 -0
- package/src/actions/dex/aggregators/enso/ensoErc4626.ts +176 -0
- package/src/actions/dex/aggregators/erc4626.ts +122 -0
- package/src/actions/dex/aggregators/fly.ts +59 -53
- package/src/actions/dex/aggregators/haiku.ts +52 -54
- package/src/actions/dex/aggregators/honey.ts +54 -45
- package/src/actions/dex/aggregators/kyberswap.ts +41 -39
- package/src/actions/dex/aggregators/oogabooga.ts +47 -46
- package/src/actions/dex/aggregators/openOcean.ts +51 -46
- package/src/actions/dex/aggregators/wbera.ts +54 -42
- package/src/actions/dex/b-sdk.ts +5 -2
- package/src/actions/dex/getIsTokenExploited.ts +2 -2
- package/src/actions/enso/{zap.ts → getEnsoSwapBundle.ts} +4 -5
- package/src/actions/enso/getEnsoUserTokensWithBalances.debug.test.ts +73 -0
- package/src/actions/enso/{getEnsoUserToken.ts → getEnsoUserTokensWithBalances.ts} +42 -30
- package/src/actions/enso/util.ts +1 -1
- package/src/actions/{index.ts → exports.ts} +5 -0
- package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +1 -1
- package/src/actions/governance/__tests__/getQuorum.integration.test.ts +1 -1
- package/src/actions/governance/checkProposalField.ts +1 -1
- package/src/actions/governance/computeActualStatus.ts +1 -1
- package/src/actions/governance/getBodyErrors.ts +1 -1
- package/src/actions/governance/getDecodedFunctionData.ts +1 -4
- package/src/actions/governance/getProposalDetails.ts +2 -2
- package/src/actions/governance/getProposalFromTx.ts +1 -2
- package/src/actions/governance/getProposalParams.ts +7 -8
- package/src/actions/governance/getQuorum.ts +1 -2
- package/src/actions/honey/getCollateralWeights.ts +1 -1
- package/src/actions/honey/getHoneyCollaterals.ts +1 -0
- package/src/actions/honey/getHoneyVaultsBalance.ts +51 -55
- package/src/actions/honey/getSwapPayload.ts +37 -35
- package/src/actions/honey/tests/pyth.integration.test.ts +0 -1
- package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +1 -1
- package/src/actions/pol/getEarnedStakedBeraVault.ts +31 -0
- package/src/actions/pol/getGlobalData.ts +14 -13
- package/src/actions/pol/getLSTStakeConfig.ts +67 -0
- package/src/actions/pol/getMarkets.ts +1 -1
- package/src/actions/pol/getRewardProofsByValidator.ts +1 -1
- package/src/actions/pol/getRewardVaultIncentives.ts +3 -5
- package/src/actions/pol/getRewardVaults.ts +2 -3
- package/src/actions/pol/getSWBeraVaultMetadata.ts +7 -5
- package/src/actions/pol/getSWBeraWithdrawal.ts +41 -27
- package/src/actions/pol/getStakeWithdrawalCooldown.ts +5 -7
- package/src/actions/pol/getStakingDailyAssets.ts +24 -0
- package/src/actions/pol/getStakingTokenInformation.ts +3 -4
- package/src/actions/pol/getTotalStakedAmount.ts +47 -0
- package/src/actions/pol/getUserClaimableIncentives.ts +1 -1
- package/src/actions/pol/getUserVaults.ts +8 -6
- package/src/actions/pol/getUserVaultsBalance.ts +4 -16
- package/src/actions/prices/getTokenCurrentPrices.ts +8 -3
- package/src/actions/tokens/getAllowances.ts +68 -41
- package/src/actions/tokens/getTokenInformation.ts +4 -1
- package/src/actions/tokens/getTokens.ts +1 -1
- package/src/actions/tokens/getUnderlyingToken.ts +53 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +53 -14
- package/src/actions/tokens/getWalletBalances.ts +69 -43
- package/src/actions/transactions/beraWriteContract.integration.test.ts +18 -6
- package/src/actions/transactions/beraWriteContract.ts +3 -3
- package/src/actions/validators/getUserActiveValidators.ts +2 -3
- package/src/actions/validators/getUserBoostsOnValidator.ts +2 -3
- package/src/contexts/BeraFlags/defaultFlags.ts +4 -0
- package/src/contexts/SwrFallback.tsx +13 -3
- package/src/contexts/TokensProvider.tsx +35 -8
- package/src/contexts/block-time-provider.tsx +1 -1
- package/src/contexts/{index.ts → exports.ts} +0 -1
- package/src/data/contracts.ts +17 -2
- package/src/enum/contracts.ts +13 -0
- package/src/enum/dex.ts +29 -0
- package/src/enum/{index.ts → exports.ts} +3 -0
- package/src/enum/governance.ts +61 -0
- package/src/enum/honey.ts +12 -0
- package/src/enum/txnEnum.ts +1 -0
- package/src/errors/BeraError.ts +61 -13
- package/src/errors/BeraMonitoring.ts +66 -0
- package/src/errors/BeraTracing.ts +79 -0
- package/src/errors/BeraTracing.unit.test.ts +198 -0
- package/src/errors/RequestError.ts +29 -3
- package/src/errors/assert.ts +4 -2
- package/src/errors/assert.unit.test.ts +6 -2
- package/src/errors/errorMap.ts +19 -8
- package/src/errors/{index.ts → exports.ts} +7 -0
- package/src/errors/getErrorMessage.ts +67 -9
- package/src/errors/getRevertReason.integration.test.ts +18 -6
- package/src/errors/getRevertReason.ts +41 -2
- package/src/errors/initBeraError.ts +52 -7
- package/src/errors/parseViemError.ts +114 -27
- package/src/errors/severity.ts +12 -0
- package/src/hooks/bend/useGetConvertToAssets.ts +3 -2
- package/src/hooks/dex/useAggregatorsQuotes.ts +126 -365
- package/src/hooks/dex/useAllUserPools.ts +1 -1
- package/src/hooks/dex/useApiPool.ts +1 -1
- package/src/hooks/dex/useCreatePool.ts +6 -5
- package/src/hooks/dex/useExploitedTokens.ts +1 -1
- package/src/hooks/dex/useLiquidityMismatch.ts +2 -5
- package/src/hooks/dex/useLpPosition.ts +21 -20
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +40 -29
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +1 -1
- package/src/hooks/dex/usePoolEvents.ts +1 -1
- package/src/hooks/dex/usePools.ts +1 -1
- package/src/hooks/dex/usePriceImpact.ts +40 -0
- package/src/hooks/dex/useSingleAggregatorQuote.ts +350 -0
- package/src/hooks/enso/useBendZapSupply.ts +216 -0
- package/src/hooks/enso/useEnsoSwapBundle.ts +107 -0
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +43 -0
- package/src/hooks/enso/useZapStakeBera.ts +113 -0
- package/src/hooks/{index.ts → exports.ts} +17 -10
- package/src/hooks/governance/useCreateProposal.ts +8 -8
- package/src/hooks/governance/usePollAllProposals.ts +1 -1
- package/src/hooks/governance/usePollProposal.ts +1 -1
- package/src/hooks/governance/usePollProposalThreshold.ts +1 -1
- package/src/hooks/governance/usePollUserDelegates.ts +1 -1
- package/src/hooks/governance/useProposalState.ts +2 -2
- package/src/hooks/honey/useCappedGlobally.ts +2 -1
- package/src/hooks/honey/useCappedRelatively.ts +1 -1
- package/src/hooks/honey/useCollateralWeights.ts +2 -1
- package/src/hooks/honey/useHoneyAlerts.ts +11 -11
- package/src/hooks/honey/useHoneyBalances.ts +7 -3
- package/src/hooks/honey/useHoneyGlobalData.ts +2 -1
- package/src/hooks/honey/useHoneySwapState.ts +2 -1
- package/src/hooks/honey/useHoneyVaultsBalance.ts +1 -1
- package/src/hooks/honey/useIsBadCollateralAsset.ts +2 -1
- package/src/hooks/honey/useIsBasketModeEnabled.ts +1 -1
- package/src/hooks/honey/usePythLatestPrices.ts +1 -1
- package/src/hooks/pol/useOnChainRewardVault.ts +3 -2
- package/src/hooks/pol/usePollGlobalData.ts +1 -1
- package/src/hooks/pol/usePollMarkets.ts +1 -1
- package/src/hooks/pol/useQueuedBeraUnlock.ts +17 -15
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +6 -3
- package/src/hooks/pol/useRewardVault.ts +1 -1
- package/src/hooks/pol/useRewardVaults.ts +1 -1
- package/src/hooks/pol/useSWBeraVaultMetadata.ts +35 -0
- package/src/hooks/pol/useStakedAPR.ts +38 -0
- package/src/hooks/pol/useStakedData.ts +117 -0
- package/src/hooks/pol/useStakedSnapshots.ts +52 -0
- package/src/hooks/pol/useTotalStakedAmount.ts +30 -0
- package/src/hooks/pol/useUserVaultInfo.ts +1 -1
- package/src/hooks/pol/useVaultValidators.ts +1 -1
- package/src/hooks/tokens/useMultipleTokenInformation.ts +15 -6
- package/src/hooks/tokens/usePollAllowances.ts +15 -19
- package/src/hooks/tokens/usePollBalance.ts +8 -4
- package/src/hooks/tokens/usePollWalletBalances.ts +14 -11
- package/src/hooks/tokens/useStakingTokenInformation.ts +2 -1
- package/src/hooks/tokens/useTokenCurrentPrice.ts +4 -2
- package/src/hooks/tokens/useTokenCurrentPrices.ts +92 -13
- package/src/hooks/tokens/useTokenInformation.ts +11 -6
- package/src/hooks/tokens/useTokenPrice.ts +21 -0
- package/src/hooks/tokens/useTokenPrices.ts +133 -0
- package/src/hooks/tokens/useTokens.ts +1 -0
- package/src/hooks/tokens/useUnderlyingAsset.ts +23 -0
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +2 -1
- package/src/hooks/validators/useAllValidators.ts +1 -1
- package/src/hooks/validators/useApiValidator.ts +1 -1
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +1 -1
- package/src/hooks/validators/useManagedValidatorByAccount.ts +1 -1
- package/src/hooks/validators/useManagedValidatorRole.ts +1 -1
- package/src/hooks/validators/useOnChainValidator.ts +1 -1
- package/src/hooks/validators/useStakingPoolBatch.ts +1 -1
- package/src/hooks/validators/useUserActiveValidators.ts +1 -1
- package/src/hooks/validators/useUserBoostsOnValidator.ts +1 -1
- package/src/hooks/validators/useUserClaimableIncentives.ts +8 -8
- package/src/hooks/validators/useValidator.ts +1 -1
- package/src/hooks/validators/useValidatorAnalytics.ts +1 -1
- package/src/hooks/validators/useValidatorCommission.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedCommission.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +1 -1
- package/src/hooks/validators/useValidatorRewardAllocation.ts +1 -1
- package/src/types/{dex.ts → dex.d.ts} +96 -67
- package/src/types/{enso.ts → enso.d.ts} +1 -1
- package/src/types/exports.ts +8 -0
- package/src/types/{global.ts → global.d.ts} +1 -30
- package/src/types/{governance.ts → governance.d.ts} +2 -64
- package/src/types/{honeySwap.ts → honeySwap.d.ts} +1 -13
- package/src/types/{pol.ts → pol.d.ts} +12 -1
- package/src/types/staking.d.ts +22 -0
- package/src/utils/createEmitter.ts +122 -0
- package/src/utils/createEmitter.unit.test.ts +149 -0
- package/src/utils/{index.ts → exports.ts} +3 -2
- package/src/utils/filter.ts +34 -0
- package/src/utils/formatNumber.ts +1 -1
- package/src/utils/formatNumber.unit.test.ts +2 -1
- package/src/utils/formatTokenList.ts +4 -10
- package/src/utils/getHoneySwapMessage.test.ts +1 -2
- package/src/utils/getServerSideClient.ts +4 -5
- package/src/utils/isDifferenceExceedingThreshold.ts +1 -1
- package/src/utils/layerZeroScan.ts +122 -0
- package/src/utils/math.ts +1 -1
- package/src/utils/parseWhiskToken.ts +15 -0
- package/src/utils/poolNamings.ts +1 -1
- package/src/utils/tokens.ts +23 -7
- package/dist/HoneyConfigProvider-6PXZJMSU.d.cts +0 -562
- package/dist/HoneyConfigProvider-CwDFrt02.d.ts +0 -562
- package/dist/abi/index.cjs +0 -2
- package/dist/abi/index.cjs.map +0 -1
- package/dist/abi/index.mjs +0 -2
- package/dist/actions/index.cjs +0 -2
- package/dist/actions/index.cjs.map +0 -1
- package/dist/actions/index.mjs +0 -2
- package/dist/aggregatorsRouter-Cny4B_MB.d.cts +0 -593
- package/dist/aggregatorsRouter-Cny4B_MB.d.ts +0 -593
- package/dist/chunk-22MQVFHP.cjs +0 -2
- package/dist/chunk-22MQVFHP.cjs.map +0 -1
- package/dist/chunk-3TKSVFZ3.mjs +0 -2
- package/dist/chunk-3TKSVFZ3.mjs.map +0 -1
- package/dist/chunk-6VF3RF53.cjs +0 -3
- package/dist/chunk-6VF3RF53.cjs.map +0 -1
- package/dist/chunk-6W22TFYA.mjs +0 -2
- package/dist/chunk-6W22TFYA.mjs.map +0 -1
- package/dist/chunk-AMRJ4B36.mjs +0 -2
- package/dist/chunk-AMRJ4B36.mjs.map +0 -1
- package/dist/chunk-DS2ZDVKU.mjs +0 -2
- package/dist/chunk-DS2ZDVKU.mjs.map +0 -1
- package/dist/chunk-ED43NYSE.cjs +0 -2
- package/dist/chunk-ED43NYSE.cjs.map +0 -1
- package/dist/chunk-EU4WFADK.cjs +0 -2
- package/dist/chunk-EU4WFADK.cjs.map +0 -1
- package/dist/chunk-HCTFDGXL.mjs +0 -2
- package/dist/chunk-HCTFDGXL.mjs.map +0 -1
- package/dist/chunk-IOSYBHKU.mjs +0 -2
- package/dist/chunk-IOSYBHKU.mjs.map +0 -1
- package/dist/chunk-JMKLDDKY.cjs +0 -2
- package/dist/chunk-JMKLDDKY.cjs.map +0 -1
- package/dist/chunk-KMKUXP2S.mjs +0 -3
- package/dist/chunk-KMKUXP2S.mjs.map +0 -1
- package/dist/chunk-OJXJ6CZ4.mjs +0 -4
- package/dist/chunk-OJXJ6CZ4.mjs.map +0 -1
- package/dist/chunk-PHIOKO3A.mjs +0 -2
- package/dist/chunk-PHIOKO3A.mjs.map +0 -1
- package/dist/chunk-QCK474XD.cjs +0 -2
- package/dist/chunk-QCK474XD.cjs.map +0 -1
- package/dist/chunk-REDXXUK7.cjs +0 -2
- package/dist/chunk-REDXXUK7.cjs.map +0 -1
- package/dist/chunk-S74ZMG2G.cjs +0 -2
- package/dist/chunk-S74ZMG2G.cjs.map +0 -1
- package/dist/chunk-TOAXF4YW.cjs +0 -2
- package/dist/chunk-TOAXF4YW.cjs.map +0 -1
- package/dist/chunk-UZ5CB33M.cjs +0 -2
- package/dist/chunk-UZ5CB33M.cjs.map +0 -1
- package/dist/chunk-VYWYJR63.mjs +0 -2
- package/dist/chunk-VYWYJR63.mjs.map +0 -1
- package/dist/chunk-XFPTQMAK.cjs +0 -4
- package/dist/chunk-XFPTQMAK.cjs.map +0 -1
- package/dist/chunk-YK4NINF5.mjs +0 -2
- package/dist/chunk-YK4NINF5.mjs.map +0 -1
- package/dist/contexts/index.cjs +0 -2
- package/dist/contexts/index.cjs.map +0 -1
- package/dist/contexts/index.mjs +0 -2
- package/dist/contexts/index.mjs.map +0 -1
- package/dist/enum/index.cjs +0 -2
- package/dist/enum/index.cjs.map +0 -1
- package/dist/enum/index.d.cts +0 -31
- package/dist/enum/index.d.ts +0 -31
- package/dist/enum/index.mjs +0 -2
- package/dist/enum/index.mjs.map +0 -1
- package/dist/errors/index.cjs +0 -2
- package/dist/errors/index.cjs.map +0 -1
- package/dist/errors/index.d.cts +0 -204
- package/dist/errors/index.d.ts +0 -204
- package/dist/errors/index.mjs +0 -2
- package/dist/errors/index.mjs.map +0 -1
- package/dist/hooks/index.cjs +0 -4
- package/dist/hooks/index.cjs.map +0 -1
- package/dist/hooks/index.mjs +0 -4
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/staking-F9Nx9TKD.d.ts +0 -246
- package/dist/staking-f4BpYH7l.d.cts +0 -246
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -56
- package/dist/types/index.d.ts +0 -56
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.mjs +0 -2
- package/dist/utils/index.mjs.map +0 -1
- package/src/actions/dex/getTransactionCount.ts +0 -29
- package/src/actions/enso/bend.ts +0 -143
- package/src/actions/enso/getEnsoUserToken.debug.test.ts +0 -57
- package/src/contexts/berajsProvider/context.tsx +0 -49
- package/src/contexts/berajsProvider/index.ts +0 -2
- package/src/contexts/berajsProvider/useBeraJs.ts +0 -18
- package/src/hooks/dex/usePollVaultIsPaused.ts +0 -30
- package/src/hooks/enso/useBendTransactionRequests.ts +0 -247
- package/src/hooks/enso/useEnsoZap.ts +0 -166
- package/src/hooks/enso/useZapTransactionRequests.ts +0 -81
- package/src/hooks/pol/useEarnedStakedBeraVault.ts +0 -59
- package/src/hooks/pol/useStakedBeraSnapshots.ts +0 -27
- package/src/hooks/transactions/TransactionStoreContext.tsx +0 -59
- package/src/hooks/transactions/transactionStore.ts +0 -275
- package/src/hooks/transactions/transactionStore.unit.test.ts +0 -508
- package/src/hooks/transactions/useAddRecentTransaction.ts +0 -29
- package/src/hooks/transactions/useRecentTransactions.ts +0 -27
- package/src/hooks/validators/validatorRoleManager.ts +0 -0
- package/src/types/index.ts +0 -8
- package/src/types/staking.ts +0 -7
- package/src/utils/formatAggregatorsQuotes.ts +0 -57
- package/src/utils/formatAggregatorsQuotes.unit.test.ts +0 -191
- package/src/utils/sentryBeforeSend.ts +0 -52
- /package/dist/{abi/index.mjs.map → errors/exports.mjs.map} +0 -0
- /package/dist/{actions/index.mjs.map → types/exports.mjs.map} +0 -0
- /package/src/actions/dex/{__tests__ → aggregators}/haiku.integration.test.ts +0 -0
- /package/src/types/{bribe-boost.ts → bribe-boost.d.ts} +0 -0
|
@@ -17,18 +17,21 @@ import { mnemonicToAccount } from "viem/accounts";
|
|
|
17
17
|
import { assert, describe, expect, it } from "vitest";
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
|
+
appConfig,
|
|
20
21
|
ChainId,
|
|
21
22
|
defaultChainId,
|
|
22
23
|
getRpcUrls,
|
|
23
24
|
} from "@berachain/config/internal";
|
|
24
25
|
|
|
25
|
-
import {
|
|
26
|
+
import { getConfig } from "@berachain/wagmi/config";
|
|
26
27
|
|
|
27
28
|
import { metaMorphoAbi } from "~/abi/bend/metaMorpho";
|
|
28
29
|
import { bgtAbi } from "~/abi/pol/bgt";
|
|
29
30
|
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
30
31
|
import { beraWriteContract } from "~/actions/transactions/beraWriteContract";
|
|
32
|
+
import { ContractName } from "~/enum/contracts";
|
|
31
33
|
import { TransactionActionType } from "~/enum/txnEnum";
|
|
34
|
+
import type { IContractWrite } from "~/types/global";
|
|
32
35
|
import { getServerSidePublicClient } from "~/utils/getServerSideClient";
|
|
33
36
|
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
34
37
|
import { anvilMnemonic } from "~/utils/test-utils";
|
|
@@ -95,7 +98,6 @@ const expectedRevertReasons = [
|
|
|
95
98
|
describe.skipIf(defaultChainId !== ChainId.MAINNET)("getRevertReason", () => {
|
|
96
99
|
const publicClient = getServerSidePublicClient();
|
|
97
100
|
const { config } = parseBaseArgs({});
|
|
98
|
-
|
|
99
101
|
const errors = [
|
|
100
102
|
{
|
|
101
103
|
tx: "0x9c24d3fd3680411c0fada23ed5d1a11df86ea2f452eb9270bbe9cc701199511e",
|
|
@@ -261,7 +263,7 @@ describe("parseViemError", () => {
|
|
|
261
263
|
[
|
|
262
264
|
InsufficientFundsError.name,
|
|
263
265
|
new InsufficientFundsError(),
|
|
264
|
-
errorMsgMap.RPC.
|
|
266
|
+
errorMsgMap.RPC.NOT_ENOUGH_GAS_TOKEN.errorMSG,
|
|
265
267
|
],
|
|
266
268
|
[
|
|
267
269
|
UserRejectedRequestError.name,
|
|
@@ -407,6 +409,14 @@ describe("eip5972 transactions", () => {
|
|
|
407
409
|
account: anvilMockAccount,
|
|
408
410
|
chain: publicClient.chain!,
|
|
409
411
|
});
|
|
412
|
+
const beraWagmiConfig = getConfig({
|
|
413
|
+
transports: {
|
|
414
|
+
[publicClient.chain!.id]: http(getRpcUrls().publicJsonRpcUrl),
|
|
415
|
+
},
|
|
416
|
+
defaultChain: publicClient.chain!,
|
|
417
|
+
thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
|
|
418
|
+
});
|
|
419
|
+
const wagmiConfig = beraWagmiConfig.wagmi;
|
|
410
420
|
|
|
411
421
|
it.concurrent.each(expectedRevertReasons)(
|
|
412
422
|
"should return the expected revert reason on sendCalls for $functionName to be $revertReason",
|
|
@@ -420,16 +430,18 @@ describe("eip5972 transactions", () => {
|
|
|
420
430
|
calls: [
|
|
421
431
|
{
|
|
422
432
|
address: config.tokens.wbera,
|
|
433
|
+
contractName: ContractName.ERC20,
|
|
434
|
+
abi: erc20Abi,
|
|
423
435
|
functionName: "approve",
|
|
424
436
|
params: [zeroAddress, 0n],
|
|
425
|
-
|
|
426
|
-
},
|
|
437
|
+
} as NonNullable<IContractWrite["calls"]>[number],
|
|
427
438
|
{
|
|
439
|
+
contractName: ContractName.ERC20,
|
|
428
440
|
address: "0x47a9E3A4b5a26eEDD0E53BC468bae31c24c9B158",
|
|
429
441
|
abi: testErrorContractAbi,
|
|
430
442
|
functionName,
|
|
431
443
|
params: "args" in rest ? rest.args : undefined,
|
|
432
|
-
},
|
|
444
|
+
} as NonNullable<IContractWrite["calls"]>[number],
|
|
433
445
|
],
|
|
434
446
|
message: "test",
|
|
435
447
|
actionType: TransactionActionType.REDEEM_BGT,
|
|
@@ -35,9 +35,34 @@ export type GetRevertReasonArgs = {
|
|
|
35
35
|
))
|
|
36
36
|
);
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Recovers the revert reason for a transaction that failed **on-chain**.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
40
|
+
* When a transaction is mined but reverts, the revert reason is no longer available in the
|
|
41
|
+
* original viem error (we only get `status: "reverted"` in the receipt). This function
|
|
42
|
+
* recovers the reason by **replaying the transaction** at the same block number.
|
|
43
|
+
*
|
|
44
|
+
* ## How it works
|
|
45
|
+
*
|
|
46
|
+
* 1. **Reconstruct the call:** Either from a `txHash` (fetches tx data from chain) or from
|
|
47
|
+
* explicit `blockNumber + to + account + data/functionName+args`.
|
|
48
|
+
* 2. **Replay via simulateContract:** Calls `publicClient.simulateContract` at the original
|
|
49
|
+
* `blockNumber`, which reproduces the exact revert that happened on-chain.
|
|
50
|
+
* 3. **Parse the revert:** The simulated revert throws a viem error, which is caught and
|
|
51
|
+
* parsed by `parseViemError` to extract the reason.
|
|
52
|
+
*
|
|
53
|
+
* ## Usage context
|
|
54
|
+
*
|
|
55
|
+
* This function is called internally by `beraWriteContract` when a transaction receipt has
|
|
56
|
+
* `status: "reverted"`. The recovered reason is passed into `TransactionFailedError`, which
|
|
57
|
+
* then feeds into the standard pipeline (errorMap → displayMessage → Sentry).
|
|
58
|
+
*
|
|
59
|
+
* ## ABI importance
|
|
60
|
+
*
|
|
61
|
+
* Passing the correct ABI is critical here. Without it, custom error names cannot be decoded
|
|
62
|
+
* and the reason falls back to a hex selector. The ABI is merged with `commonAbiErrors`
|
|
63
|
+
* (which includes `Error(string)` and `Panic(uint256)`) to handle standard reverts.
|
|
64
|
+
*
|
|
65
|
+
* @returns Same shape as parseViemError: `{ reason, rootCause }`
|
|
41
66
|
*/
|
|
42
67
|
export async function getRevertReason({
|
|
43
68
|
publicClient,
|
|
@@ -54,7 +79,9 @@ export async function getRevertReason({
|
|
|
54
79
|
let functionName: string | undefined;
|
|
55
80
|
let args: readonly unknown[] | undefined;
|
|
56
81
|
|
|
82
|
+
// ── Step 1: Reconstruct the original call parameters ──────────────────
|
|
57
83
|
if ("txHash" in params) {
|
|
84
|
+
// Fetch the original transaction from the chain to get its input data, recipient, etc.
|
|
58
85
|
const tx = await publicClient.getTransaction({
|
|
59
86
|
hash: params.txHash,
|
|
60
87
|
});
|
|
@@ -91,8 +118,12 @@ export async function getRevertReason({
|
|
|
91
118
|
}
|
|
92
119
|
}
|
|
93
120
|
|
|
121
|
+
// ── Step 2: Replay the transaction to reproduce the revert ────────────
|
|
122
|
+
// We intentionally call simulateContract/call expecting it to revert.
|
|
123
|
+
// The revert error is then caught and parsed by parseViemError.
|
|
94
124
|
try {
|
|
95
125
|
if (!abi) {
|
|
126
|
+
// No ABI available — use raw call which will revert with raw data
|
|
96
127
|
if (data) {
|
|
97
128
|
await publicClient.call({
|
|
98
129
|
data,
|
|
@@ -106,6 +137,7 @@ export async function getRevertReason({
|
|
|
106
137
|
}
|
|
107
138
|
}
|
|
108
139
|
|
|
140
|
+
// Resolve functionName and args from the raw data if not provided
|
|
109
141
|
if ("functionName" in params && "args" in params && params.functionName) {
|
|
110
142
|
functionName = params.functionName;
|
|
111
143
|
args = params.args;
|
|
@@ -125,6 +157,7 @@ export async function getRevertReason({
|
|
|
125
157
|
);
|
|
126
158
|
}
|
|
127
159
|
try {
|
|
160
|
+
// Decode the raw calldata into function name + args using the ABI
|
|
128
161
|
const decoded = decodeFunctionData({
|
|
129
162
|
abi,
|
|
130
163
|
data,
|
|
@@ -134,6 +167,7 @@ export async function getRevertReason({
|
|
|
134
167
|
args = decoded.args;
|
|
135
168
|
} catch (e) {
|
|
136
169
|
if (e instanceof AbiFunctionSignatureNotFoundError) {
|
|
170
|
+
// Function signature not in ABI — fall back to raw call
|
|
137
171
|
await publicClient.call({
|
|
138
172
|
data,
|
|
139
173
|
to,
|
|
@@ -150,6 +184,8 @@ export async function getRevertReason({
|
|
|
150
184
|
}
|
|
151
185
|
|
|
152
186
|
if (abi && functionName) {
|
|
187
|
+
// Replay with simulateContract — this should revert and throw a viem error
|
|
188
|
+
// containing the decoded revert reason.
|
|
153
189
|
await publicClient.simulateContract({
|
|
154
190
|
functionName,
|
|
155
191
|
args,
|
|
@@ -159,6 +195,7 @@ export async function getRevertReason({
|
|
|
159
195
|
blockNumber,
|
|
160
196
|
});
|
|
161
197
|
|
|
198
|
+
// If we get here, the simulation succeeded (shouldn't happen for a reverted tx)
|
|
162
199
|
throw new TransactionFailedError({
|
|
163
200
|
message: `Getting revert reason for successful simulation`,
|
|
164
201
|
functionName,
|
|
@@ -170,6 +207,8 @@ export async function getRevertReason({
|
|
|
170
207
|
|
|
171
208
|
throw new Error("No data or function name and args provided");
|
|
172
209
|
} catch (error) {
|
|
210
|
+
// ── Step 3: Parse the revert error to extract the reason ──────────
|
|
211
|
+
// The simulated revert throws a viem error chain which parseViemError unwraps.
|
|
173
212
|
if (error instanceof Error) {
|
|
174
213
|
return parseViemError({ error, abi, revertIfUnknown: true });
|
|
175
214
|
}
|
|
@@ -3,14 +3,55 @@ import { BaseError } from "viem";
|
|
|
3
3
|
import { BeraError } from "./BeraError";
|
|
4
4
|
import { parseViemError } from "./parseViemError";
|
|
5
5
|
import { RequestError } from "./RequestError";
|
|
6
|
+
import type { SeverityLevel } from "./severity";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* The preferred way to normalize any unknown error into a BeraError.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* This function acts as a smart factory that picks the correct BeraError subclass:
|
|
12
|
+
*
|
|
13
|
+
* 1. If `cause` is already a `BeraError`, returns it as-is (no double-wrapping).
|
|
14
|
+
* 2. If `cause` is a viem `BaseError`, runs `parseViemError` to classify it:
|
|
15
|
+
* - If the root cause is an `HttpRequestError` (RPC transport failure), wraps it
|
|
16
|
+
* in a `RequestError` with the endpoint URL extracted from the error.
|
|
17
|
+
* 3. Otherwise, wraps in a new `BeraError` — which triggers the automatic reason
|
|
18
|
+
* detection pipeline in the BeraError constructor (parseViemError → errorMap → displayMessage).
|
|
19
|
+
*
|
|
20
|
+
* **Use this instead of `new BeraError({ cause })` when you don't know the error type.**
|
|
21
|
+
* It ensures RequestErrors are correctly classified (important for Sentry filtering
|
|
22
|
+
* and fingerprinting — RequestErrors are skipped from transaction error grouping).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* try {
|
|
27
|
+
* await someOperation();
|
|
28
|
+
* } catch (error) {
|
|
29
|
+
* // Normalizes to the right subclass, reason auto-detected
|
|
30
|
+
* throw initBeraError({ cause: error });
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Reporting to Sentry without rethrowing
|
|
37
|
+
* catch (error) {
|
|
38
|
+
* captureException(initBeraError({ cause: error }));
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
12
41
|
*/
|
|
13
|
-
export function initBeraError({
|
|
42
|
+
export function initBeraError({
|
|
43
|
+
cause: error,
|
|
44
|
+
level,
|
|
45
|
+
}: {
|
|
46
|
+
cause: unknown;
|
|
47
|
+
/**
|
|
48
|
+
* The severity level of the error, only used if the error is not a BeraError.
|
|
49
|
+
*/
|
|
50
|
+
level?: SeverityLevel;
|
|
51
|
+
}): BeraError {
|
|
52
|
+
// ── Step 1: Check if it's a viem BaseError that wraps an RPC transport failure ──
|
|
53
|
+
// parseViemError with revertIfUnknown=false won't throw — it returns { reason: undefined }
|
|
54
|
+
// if the error chain doesn't match any known type.
|
|
14
55
|
if (error instanceof BaseError) {
|
|
15
56
|
const parsed = parseViemError({
|
|
16
57
|
error,
|
|
@@ -22,9 +63,8 @@ export function initBeraError({ cause: error }: { cause: unknown }): BeraError {
|
|
|
22
63
|
"url" in parsed.rootCause &&
|
|
23
64
|
typeof parsed.rootCause.url === "string"
|
|
24
65
|
) {
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// this is mostly supported by `initBeraError()`
|
|
66
|
+
// RPC transport failure (e.g. HTTP 502 from the RPC endpoint).
|
|
67
|
+
// Wrapping in RequestError gives it proper endpoint tagging and level="warning".
|
|
28
68
|
return new RequestError({
|
|
29
69
|
cause: parsed.rootCause,
|
|
30
70
|
response: undefined,
|
|
@@ -32,14 +72,19 @@ export function initBeraError({ cause: error }: { cause: unknown }): BeraError {
|
|
|
32
72
|
url: parsed.rootCause.url as string,
|
|
33
73
|
type: "rpc",
|
|
34
74
|
},
|
|
75
|
+
level,
|
|
35
76
|
});
|
|
36
77
|
}
|
|
37
78
|
}
|
|
79
|
+
|
|
80
|
+
// ── Step 2: Return as-is if already a BeraError, otherwise wrap ──────────
|
|
81
|
+
// The BeraError constructor will run automatic reason detection on the cause.
|
|
38
82
|
const err =
|
|
39
83
|
error instanceof BeraError
|
|
40
84
|
? error
|
|
41
85
|
: new BeraError({
|
|
42
86
|
cause: error,
|
|
87
|
+
level,
|
|
43
88
|
});
|
|
44
89
|
|
|
45
90
|
return err;
|
|
@@ -15,6 +15,14 @@ import {
|
|
|
15
15
|
|
|
16
16
|
import { commonAbiErrors } from "~/abi/utils/commonAbiErrors";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Duck-type check for viem's BaseError.
|
|
20
|
+
*
|
|
21
|
+
* We can't always rely on `instanceof BaseError` because viem errors may originate
|
|
22
|
+
* from a different version of the `viem` package (e.g. in dependency tree mismatches).
|
|
23
|
+
* The duck-type fallback checks for the structural shape that all viem errors share:
|
|
24
|
+
* `shortMessage`, `message`, and `details`.
|
|
25
|
+
*/
|
|
18
26
|
function isBaseError(error: unknown): error is BaseError {
|
|
19
27
|
if (error instanceof BaseError) {
|
|
20
28
|
return true;
|
|
@@ -32,6 +40,12 @@ function isBaseError(error: unknown): error is BaseError {
|
|
|
32
40
|
return false;
|
|
33
41
|
}
|
|
34
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Type-guard for specific viem error types.
|
|
45
|
+
*
|
|
46
|
+
* Uses both `instanceof` and `error.name` to handle cases where the error
|
|
47
|
+
* was created by a different viem version (name-based fallback).
|
|
48
|
+
*/
|
|
35
49
|
function isViemError<T extends Error>(
|
|
36
50
|
error: Error,
|
|
37
51
|
name: T["name"],
|
|
@@ -48,6 +62,18 @@ function isViemError<T extends Error>(
|
|
|
48
62
|
return false;
|
|
49
63
|
}
|
|
50
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Extracts a human-readable reason string from a decoded Solidity error.
|
|
67
|
+
*
|
|
68
|
+
* Solidity has two kinds of revert errors:
|
|
69
|
+
* - `revert("some message")` → decoded as `Error(string)` where the message is in `args[0]`.
|
|
70
|
+
* In this case we return the string argument (e.g. `"BAL#508"`).
|
|
71
|
+
* - `revert CustomError(...)` → decoded as `CustomError(...)` where `errorName` is the
|
|
72
|
+
* custom error name. In this case we return `errorName` (e.g. `"NotEnoughBalance"`).
|
|
73
|
+
*
|
|
74
|
+
* The returned string is used as the `reason` field in BeraError and is matched against
|
|
75
|
+
* `errorMap.ts` to resolve a user-friendly `displayMessage`.
|
|
76
|
+
*/
|
|
51
77
|
export function parseDecodedError<const abi extends Abi | readonly unknown[]>(
|
|
52
78
|
error: DecodeErrorResultReturnType<abi>,
|
|
53
79
|
): string | undefined {
|
|
@@ -56,25 +82,73 @@ export function parseDecodedError<const abi extends Abi | readonly unknown[]>(
|
|
|
56
82
|
Array.isArray(error.args) &&
|
|
57
83
|
error.args?.at(0)
|
|
58
84
|
) {
|
|
59
|
-
//
|
|
60
|
-
// for other errors, we return the error name
|
|
85
|
+
// Solidity `revert("message")` — the message string is the reason
|
|
61
86
|
return error.args?.at(0) as string;
|
|
62
87
|
}
|
|
63
88
|
|
|
89
|
+
// Custom error `revert CustomError(...)` — the error name is the reason
|
|
64
90
|
return error.errorName;
|
|
65
91
|
}
|
|
66
92
|
|
|
67
93
|
/**
|
|
68
|
-
*
|
|
94
|
+
* The reason extraction engine — recursively unwraps viem error chains to extract
|
|
95
|
+
* a machine-readable `reason` string.
|
|
96
|
+
*
|
|
97
|
+
* This function is the core of the automatic reason detection system. It is called by:
|
|
98
|
+
* - `BeraError` constructor (when `reason` is not manually provided)
|
|
99
|
+
* - `initBeraError` (to detect if the error is a RequestError)
|
|
100
|
+
* - `getRevertReason` (after replaying a failed on-chain transaction)
|
|
69
101
|
*
|
|
70
|
-
*
|
|
102
|
+
* ## Viem error chain structure
|
|
103
|
+
*
|
|
104
|
+
* Viem errors are deeply nested. The typical chains look like:
|
|
105
|
+
*
|
|
106
|
+
* **From `simulateContract`:**
|
|
107
|
+
* ```
|
|
108
|
+
* ContractFunctionExecutionError ← wrapper, skipped
|
|
109
|
+
* └── ContractFunctionRevertedError ← reason extracted here (cause.reason / cause.signature)
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* **From `publicClient.call` (raw call):**
|
|
113
|
+
* ```
|
|
114
|
+
* CallExecutionError ← wrapper, skipped
|
|
115
|
+
* └── ExecutionRevertedError ← wrapper, skipped
|
|
116
|
+
* └── RpcRequestError ← reason decoded from cause.data using ABI
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* **From `writeContract` / `sendTransaction`:**
|
|
120
|
+
* ```
|
|
121
|
+
* TransactionExecutionError ← checked for special wallet errors
|
|
122
|
+
* └── UserRejectedRequestError ← "UserRejectedRequestError"
|
|
123
|
+
* └── AtomicReadyWalletRejectedUpgradeError ← "AtomicReadyWalletRejectedUpgradeError"
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* **From RPC transport failures:**
|
|
127
|
+
* ```
|
|
128
|
+
* ContractFunctionExecutionError ← wrapper, skipped
|
|
129
|
+
* └── HttpRequestError ← "HttpRequestError(status:<code>)", isRequestError=true
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* The function walks `cause.cause` in a while loop until it finds an error type it can
|
|
133
|
+
* extract a reason from, or runs out of nested causes.
|
|
134
|
+
*
|
|
135
|
+
* ## Parameters
|
|
136
|
+
*
|
|
137
|
+
* @param error - Any Error instance (typically a viem BaseError).
|
|
138
|
+
* @param abi - Optional contract ABI. Merged with `commonAbiErrors` to decode revert data.
|
|
139
|
+
* Passing the correct ABI enables decoding custom error names (e.g. "SlippageExceeded")
|
|
140
|
+
* instead of falling back to hex selectors (e.g. "0xa3b1e29f").
|
|
141
|
+
* @param revertIfUnknown - If true, throws when the error doesn't match any known pattern.
|
|
142
|
+
* The BeraError constructor calls with `true`; `initBeraError` calls with `false`.
|
|
143
|
+
*
|
|
144
|
+
* @returns `{ reason, rootCause, isRequestError? }` where:
|
|
145
|
+
* - `reason` is the extracted error code/name (matched against errorMap.ts for displayMessage)
|
|
146
|
+
* - `rootCause` is the deepest error in the chain that was identified
|
|
147
|
+
* - `isRequestError` is true if the error is an HTTP/RPC transport failure
|
|
71
148
|
*/
|
|
72
149
|
export function parseViemError({
|
|
73
150
|
error,
|
|
74
151
|
abi,
|
|
75
|
-
/**
|
|
76
|
-
* If true, error is thrown if the revert reason is not a CallExecutionError or ContractFunctionExecutionError
|
|
77
|
-
*/
|
|
78
152
|
revertIfUnknown = true,
|
|
79
153
|
}: {
|
|
80
154
|
error: Error;
|
|
@@ -83,11 +157,9 @@ export function parseViemError({
|
|
|
83
157
|
}): {
|
|
84
158
|
reason: string | undefined;
|
|
85
159
|
rootCause: unknown;
|
|
86
|
-
/**
|
|
87
|
-
* If true, the error is a request error.
|
|
88
|
-
*/
|
|
89
160
|
isRequestError?: boolean;
|
|
90
161
|
} {
|
|
162
|
+
// If it's not a viem-shaped error, either rethrow or return the message as-is
|
|
91
163
|
if (!isBaseError(error)) {
|
|
92
164
|
if (revertIfUnknown) {
|
|
93
165
|
throw error;
|
|
@@ -100,9 +172,16 @@ export function parseViemError({
|
|
|
100
172
|
return { reason: error.message, rootCause: error };
|
|
101
173
|
}
|
|
102
174
|
|
|
175
|
+
// Begin unwrapping the nested error chain
|
|
103
176
|
let cause: unknown = error;
|
|
104
177
|
|
|
178
|
+
// Walk the nested viem error chain from outermost to innermost.
|
|
179
|
+
// Each iteration checks for known error types and either extracts the reason or
|
|
180
|
+
// skips the wrapper to go deeper into `cause.cause`.
|
|
105
181
|
while (isBaseError(cause)) {
|
|
182
|
+
// ── Step 1: Skip wrapper errors that don't carry reason data ────────────
|
|
183
|
+
// ContractFunctionExecutionError is a top-level wrapper from simulateContract/writeContract.
|
|
184
|
+
// The actual revert info is in its nested cause.
|
|
106
185
|
if (
|
|
107
186
|
isViemError(
|
|
108
187
|
cause,
|
|
@@ -110,12 +189,13 @@ export function parseViemError({
|
|
|
110
189
|
ContractFunctionExecutionError,
|
|
111
190
|
)
|
|
112
191
|
) {
|
|
113
|
-
// let's skip to the deeper cause
|
|
114
192
|
cause = cause.cause;
|
|
115
|
-
|
|
116
193
|
continue;
|
|
117
194
|
}
|
|
118
195
|
|
|
196
|
+
// ── Step 2: Check for wallet-level errors ──────────────────────────────
|
|
197
|
+
// TransactionExecutionError wraps errors from wallet interactions (sendTransaction).
|
|
198
|
+
// Check for EIP-7702 smart wallet upgrade rejection specifically.
|
|
119
199
|
if (
|
|
120
200
|
isViemError(cause, "TransactionExecutionError", TransactionExecutionError)
|
|
121
201
|
) {
|
|
@@ -126,27 +206,29 @@ export function parseViemError({
|
|
|
126
206
|
};
|
|
127
207
|
}
|
|
128
208
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*/
|
|
209
|
+
|
|
210
|
+
// ── Step 3: RpcRequestError — from raw `publicClient.call` ─────────────
|
|
211
|
+
// Error chain: CallExecutionError → ExecutionRevertedError → RpcRequestError
|
|
212
|
+
// The revert data is in `cause.data` as raw hex bytes.
|
|
213
|
+
// We decode it using the provided ABI + commonAbiErrors to get the error name.
|
|
135
214
|
if (isViemError(cause, "RpcRequestError", RpcRequestError)) {
|
|
136
215
|
if (!cause.data) {
|
|
216
|
+
// No revert data available — check if there's a nested message (special RPC cases)
|
|
137
217
|
if (
|
|
138
218
|
typeof cause.cause === "object" &&
|
|
139
219
|
cause.cause &&
|
|
140
220
|
"message" in cause.cause &&
|
|
141
221
|
typeof cause.cause.message === "string"
|
|
142
222
|
) {
|
|
143
|
-
// this covers special cases
|
|
144
223
|
return { reason: cause.cause.message, rootCause: cause.cause };
|
|
145
224
|
}
|
|
146
225
|
|
|
147
226
|
throw new Error("No data", { cause });
|
|
148
227
|
}
|
|
149
228
|
|
|
229
|
+
// Decode the raw revert bytes into a structured error using ABI.
|
|
230
|
+
// commonAbiErrors includes Error(string) and Panic(uint256) so standard reverts
|
|
231
|
+
// are always decodable even without a user-provided ABI.
|
|
150
232
|
const decodedError = decodeErrorResult({
|
|
151
233
|
data: cause.data as `0x${string}`,
|
|
152
234
|
abi: [...commonAbiErrors, ...(abi ?? [])],
|
|
@@ -158,12 +240,12 @@ export function parseViemError({
|
|
|
158
240
|
};
|
|
159
241
|
}
|
|
160
242
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
243
|
+
// ── Step 4: ContractFunctionRevertedError — from `simulateContract` ────
|
|
244
|
+
// Error chain: ContractFunctionExecutionError → ContractFunctionRevertedError
|
|
245
|
+
// Viem already decoded the revert using the ABI passed to simulateContract.
|
|
246
|
+
// `cause.reason` is the decoded error name (e.g. "NotEnoughBalance").
|
|
247
|
+
// `cause.signature` is the 4-byte selector fallback (e.g. "0x13be252b").
|
|
248
|
+
// `cause.data?.errorName` is another fallback from the decoded data.
|
|
167
249
|
if (
|
|
168
250
|
isViemError(
|
|
169
251
|
cause,
|
|
@@ -171,8 +253,6 @@ export function parseViemError({
|
|
|
171
253
|
ContractFunctionRevertedError,
|
|
172
254
|
)
|
|
173
255
|
) {
|
|
174
|
-
// If error is not found in the abi, reason is undefined
|
|
175
|
-
// In this case, we return the signature
|
|
176
256
|
return {
|
|
177
257
|
reason:
|
|
178
258
|
cause.reason ??
|
|
@@ -183,12 +263,17 @@ export function parseViemError({
|
|
|
183
263
|
};
|
|
184
264
|
}
|
|
185
265
|
|
|
266
|
+
// ── Step 5: UserRejectedRequestError — wallet popup dismissed ──────────
|
|
267
|
+
// The user clicked "Reject" in their wallet. Level is set to "info" by BeraError constructor.
|
|
186
268
|
if (
|
|
187
269
|
isViemError(cause, "UserRejectedRequestError", UserRejectedRequestError)
|
|
188
270
|
) {
|
|
189
271
|
return { reason: "UserRejectedRequestError", rootCause: cause };
|
|
190
272
|
}
|
|
191
273
|
|
|
274
|
+
// ── Step 6: HttpRequestError — RPC transport failure ───────────────────
|
|
275
|
+
// The RPC endpoint returned an HTTP error (e.g. 502, 503).
|
|
276
|
+
// Flagged as isRequestError so initBeraError can wrap it in a RequestError.
|
|
192
277
|
if (isViemError(cause, "HttpRequestError", HttpRequestError)) {
|
|
193
278
|
return {
|
|
194
279
|
reason: `HttpRequestError(status:${cause.status})`,
|
|
@@ -197,10 +282,12 @@ export function parseViemError({
|
|
|
197
282
|
};
|
|
198
283
|
}
|
|
199
284
|
|
|
285
|
+
// ── Step 7: End of chain — no deeper cause to unwrap ───────────────────
|
|
200
286
|
if (!cause.cause) {
|
|
201
287
|
return { reason: cause.name, rootCause: cause };
|
|
202
288
|
}
|
|
203
289
|
|
|
290
|
+
// Keep unwrapping
|
|
204
291
|
cause = cause.cause;
|
|
205
292
|
}
|
|
206
293
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity levels for error reporting.
|
|
3
|
+
* Mirrors Sentry's SeverityLevel for compatibility, but owned by berajs
|
|
4
|
+
* so we don't depend on @sentry/nextjs.
|
|
5
|
+
*/
|
|
6
|
+
export type SeverityLevel =
|
|
7
|
+
| "fatal"
|
|
8
|
+
| "error"
|
|
9
|
+
| "warning"
|
|
10
|
+
| "log"
|
|
11
|
+
| "info"
|
|
12
|
+
| "debug";
|
|
@@ -2,9 +2,10 @@ import useSWR from "swr";
|
|
|
2
2
|
|
|
3
3
|
import { usePublicClient } from "@berachain/wagmi/hooks";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { GetConvertToAssetsProps } from "~/actions/bend/getConvertToAssets";
|
|
6
|
+
import { getConvertToAssets } from "~/actions/bend/getConvertToAssets";
|
|
6
7
|
import { assertPublicClient } from "~/errors/assert";
|
|
7
|
-
import type { DefaultHookOptions } from "~/types";
|
|
8
|
+
import type { DefaultHookOptions } from "~/types/global";
|
|
8
9
|
|
|
9
10
|
export const useGetConvertToAssets = (
|
|
10
11
|
{
|