@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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createEmitter, type EmitterMixin } from "~/utils/createEmitter";
|
|
2
|
+
import type { BeraError } from "./BeraError";
|
|
3
|
+
import type { SeverityLevel } from "./severity";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Context passed alongside captured exceptions.
|
|
7
|
+
* Mirrors the subset of Sentry's CaptureContext that berajs actually uses.
|
|
8
|
+
*/
|
|
9
|
+
export interface CaptureContext {
|
|
10
|
+
level: SeverityLevel;
|
|
11
|
+
extra?: Record<string, unknown>;
|
|
12
|
+
tags?: Record<string, string | number | boolean | null | undefined>;
|
|
13
|
+
fingerprint?: string[];
|
|
14
|
+
data?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ErrorEvent {
|
|
18
|
+
exception: BeraError;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const _emitter = createEmitter<{ exception: (event: ErrorEvent) => void }>();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A generic error reporter for berajs.
|
|
26
|
+
*
|
|
27
|
+
* Instead of calling Sentry.captureException directly, berajs calls
|
|
28
|
+
* `BeraMonitoring.captureException()`. Consumer apps subscribe via `.on()` and
|
|
29
|
+
* forward events to their monitoring provider (Sentry, Datadog, etc.).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // In berajs code:
|
|
34
|
+
* import { BeraMonitoring } from "~/errors/BeraMonitoring";
|
|
35
|
+
* BeraMonitoring.captureExceptionException(error);
|
|
36
|
+
*
|
|
37
|
+
* // In app instrumentation:
|
|
38
|
+
* import { BeraMonitoring } from "@berachain/berajs/errors";
|
|
39
|
+
* BeraMonitoring.on((event) => {
|
|
40
|
+
* if (event.type === "exception") {
|
|
41
|
+
* Sentry.captureException(event.exception);
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export const BeraMonitoring: {
|
|
47
|
+
captureException: (exception: BeraError) => void;
|
|
48
|
+
} & EmitterMixin<{ exception: (event: ErrorEvent) => void }> = {
|
|
49
|
+
/**
|
|
50
|
+
* Capture an exception. Notifies all subscribers.
|
|
51
|
+
*/
|
|
52
|
+
captureException(exception: BeraError): void {
|
|
53
|
+
const event: ErrorEvent = {
|
|
54
|
+
exception,
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
};
|
|
57
|
+
_emitter.emit("exception", event);
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Subscribe to error events.
|
|
61
|
+
* @returns An unsubscribe function.
|
|
62
|
+
*/
|
|
63
|
+
on(...args) {
|
|
64
|
+
return _emitter.on(...args);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Unsubscribe } from "~/utils/createEmitter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Span context passed to tracing handlers.
|
|
5
|
+
* Compatible with Sentry's StartSpanOptions (name, op, attributes).
|
|
6
|
+
*/
|
|
7
|
+
export type SpanContext = {
|
|
8
|
+
name: string;
|
|
9
|
+
op: string;
|
|
10
|
+
attributes: Record<string, string | number | boolean | undefined>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A function that wraps a callback in a tracing span.
|
|
15
|
+
* Compatible with Sentry.startSpan's signature.
|
|
16
|
+
*/
|
|
17
|
+
type StartSpanFn = <T>(
|
|
18
|
+
context: SpanContext,
|
|
19
|
+
callback: () => Promise<T>,
|
|
20
|
+
) => Promise<T>;
|
|
21
|
+
|
|
22
|
+
const _handlers: StartSpanFn[] = [];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A generic span-tracing module for berajs.
|
|
26
|
+
*
|
|
27
|
+
* Instead of calling Sentry.startSpan directly, berajs calls
|
|
28
|
+
* `BeraTracing.startSpan()`. Consumer apps subscribe via `.on("span", handler)`
|
|
29
|
+
* and forward spans to their tracing provider (Sentry, Datadog, etc.).
|
|
30
|
+
*
|
|
31
|
+
* Multiple handlers are supported and chain in registration order:
|
|
32
|
+
* the first registered handler is the outermost wrapper.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // In berajs code:
|
|
37
|
+
* import { BeraTracing } from "~/errors/BeraTracing";
|
|
38
|
+
* const result = await BeraTracing.startSpan(
|
|
39
|
+
* { name: "GraphQL query", op: "graphql.query", attributes: {} },
|
|
40
|
+
* () => executeQuery(),
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* // In app instrumentation:
|
|
44
|
+
* import { BeraTracing } from "@berachain/berajs/errors";
|
|
45
|
+
* BeraTracing.addSpanHandler(Sentry.startSpan);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const BeraTracing = {
|
|
49
|
+
/**
|
|
50
|
+
* Execute a callback, wrapping it in all registered span handlers.
|
|
51
|
+
*
|
|
52
|
+
* Handlers chain so each wraps the next. First registered = outermost wrapper.
|
|
53
|
+
* If no handlers are registered, the callback is executed directly.
|
|
54
|
+
*/
|
|
55
|
+
startSpan<T>(context: SpanContext, callback: () => Promise<T>): Promise<T> {
|
|
56
|
+
if (_handlers.length === 0) return callback();
|
|
57
|
+
|
|
58
|
+
// Chain: h1(ctx, () => h2(ctx, () => h3(ctx, () => callback())))
|
|
59
|
+
return _handlers.reduceRight<() => Promise<T>>(
|
|
60
|
+
(next, handler) => () => handler(context, next),
|
|
61
|
+
callback,
|
|
62
|
+
)();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Register a span tracing handler.
|
|
67
|
+
*
|
|
68
|
+
* @param _event - Must be "span". Exists for API consistency with BeraMonitoring.
|
|
69
|
+
* @param handler - A StartSpanFn, e.g. Sentry.startSpan.
|
|
70
|
+
* @returns An unsubscribe function to remove the handler.
|
|
71
|
+
*/
|
|
72
|
+
addSpanHandler(handler: StartSpanFn): Unsubscribe {
|
|
73
|
+
_handlers.push(handler);
|
|
74
|
+
return () => {
|
|
75
|
+
const idx = _handlers.indexOf(handler);
|
|
76
|
+
if (idx !== -1) _handlers.splice(idx, 1);
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { BeraTracing } from "./BeraTracing.js";
|
|
4
|
+
|
|
5
|
+
describe("BeraTracing", () => {
|
|
6
|
+
describe("startSpan with no handlers", () => {
|
|
7
|
+
it("executes the callback directly", async () => {
|
|
8
|
+
const callback = vi.fn().mockResolvedValue("result");
|
|
9
|
+
const result = await BeraTracing.startSpan(
|
|
10
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
11
|
+
callback,
|
|
12
|
+
);
|
|
13
|
+
expect(result).toBe("result");
|
|
14
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("startSpan with a single handler", () => {
|
|
19
|
+
it("wraps the callback in the handler", async () => {
|
|
20
|
+
const order: string[] = [];
|
|
21
|
+
|
|
22
|
+
const handler = vi.fn(async (context: any, callback: any) => {
|
|
23
|
+
order.push("handler-start");
|
|
24
|
+
const result = await callback();
|
|
25
|
+
order.push("handler-end");
|
|
26
|
+
return result;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const unsub = BeraTracing.addSpanHandler(handler);
|
|
30
|
+
|
|
31
|
+
const result = await BeraTracing.startSpan(
|
|
32
|
+
{ name: "test", op: "test.op", attributes: { key: "value" } },
|
|
33
|
+
async () => {
|
|
34
|
+
order.push("callback");
|
|
35
|
+
return 42;
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(result).toBe(42);
|
|
40
|
+
expect(order).toEqual(["handler-start", "callback", "handler-end"]);
|
|
41
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
42
|
+
expect(handler.mock.calls[0][0]).toEqual({
|
|
43
|
+
name: "test",
|
|
44
|
+
op: "test.op",
|
|
45
|
+
attributes: { key: "value" },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
unsub();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("startSpan with multiple handlers", () => {
|
|
53
|
+
it("chains handlers so first registered is outermost", async () => {
|
|
54
|
+
const order: string[] = [];
|
|
55
|
+
|
|
56
|
+
const handler1 = async (_ctx: any, cb: () => Promise<any>) => {
|
|
57
|
+
order.push("h1-start");
|
|
58
|
+
const r = await cb();
|
|
59
|
+
order.push("h1-end");
|
|
60
|
+
return r;
|
|
61
|
+
};
|
|
62
|
+
const handler2 = async (_ctx: any, cb: () => Promise<any>) => {
|
|
63
|
+
order.push("h2-start");
|
|
64
|
+
const r = await cb();
|
|
65
|
+
order.push("h2-end");
|
|
66
|
+
return r;
|
|
67
|
+
};
|
|
68
|
+
const handler3 = async (_ctx: any, cb: () => Promise<any>) => {
|
|
69
|
+
order.push("h3-start");
|
|
70
|
+
const r = await cb();
|
|
71
|
+
order.push("h3-end");
|
|
72
|
+
return r;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const unsub1 = BeraTracing.addSpanHandler(handler1);
|
|
76
|
+
const unsub2 = BeraTracing.addSpanHandler(handler2);
|
|
77
|
+
const unsub3 = BeraTracing.addSpanHandler(handler3);
|
|
78
|
+
|
|
79
|
+
await BeraTracing.startSpan(
|
|
80
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
81
|
+
async () => {
|
|
82
|
+
order.push("callback");
|
|
83
|
+
return "done";
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// h1 wraps h2 wraps h3 wraps callback
|
|
88
|
+
expect(order).toEqual([
|
|
89
|
+
"h1-start",
|
|
90
|
+
"h2-start",
|
|
91
|
+
"h3-start",
|
|
92
|
+
"callback",
|
|
93
|
+
"h3-end",
|
|
94
|
+
"h2-end",
|
|
95
|
+
"h1-end",
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
unsub1();
|
|
99
|
+
unsub2();
|
|
100
|
+
unsub3();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("on() returns unsubscribe", () => {
|
|
105
|
+
it("removes the handler when unsubscribe is called", async () => {
|
|
106
|
+
const handler = vi.fn(async (_ctx: any, cb: any) => cb());
|
|
107
|
+
const unsub = BeraTracing.addSpanHandler(handler);
|
|
108
|
+
|
|
109
|
+
await BeraTracing.startSpan(
|
|
110
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
111
|
+
async () => "a",
|
|
112
|
+
);
|
|
113
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
114
|
+
|
|
115
|
+
unsub();
|
|
116
|
+
|
|
117
|
+
await BeraTracing.startSpan(
|
|
118
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
119
|
+
async () => "b",
|
|
120
|
+
);
|
|
121
|
+
// Handler should not have been called again
|
|
122
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("is idempotent (double-unsubscribe does not throw)", () => {
|
|
126
|
+
const handler = vi.fn(async (_ctx: any, cb: any) => cb());
|
|
127
|
+
const unsub = BeraTracing.addSpanHandler(handler);
|
|
128
|
+
|
|
129
|
+
unsub();
|
|
130
|
+
expect(() => unsub()).not.toThrow();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("error propagation", () => {
|
|
135
|
+
it("propagates errors from the callback through handlers", async () => {
|
|
136
|
+
const handler = async (_ctx: any, cb: () => Promise<any>) => cb();
|
|
137
|
+
const unsub = BeraTracing.addSpanHandler(handler);
|
|
138
|
+
|
|
139
|
+
await expect(
|
|
140
|
+
BeraTracing.startSpan(
|
|
141
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
142
|
+
async () => {
|
|
143
|
+
throw new Error("callback error");
|
|
144
|
+
},
|
|
145
|
+
),
|
|
146
|
+
).rejects.toThrow("callback error");
|
|
147
|
+
|
|
148
|
+
unsub();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("propagates errors from a handler", async () => {
|
|
152
|
+
const handler = async () => {
|
|
153
|
+
throw new Error("handler error");
|
|
154
|
+
};
|
|
155
|
+
const unsub = BeraTracing.addSpanHandler(handler);
|
|
156
|
+
|
|
157
|
+
await expect(
|
|
158
|
+
BeraTracing.startSpan(
|
|
159
|
+
{ name: "test", op: "test.op", attributes: {} },
|
|
160
|
+
async () => "ok",
|
|
161
|
+
),
|
|
162
|
+
).rejects.toThrow("handler error");
|
|
163
|
+
|
|
164
|
+
unsub();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("Sentry.startSpan compatibility", () => {
|
|
169
|
+
it("works with a handler that accepts (options, callback) like Sentry.startSpan", async () => {
|
|
170
|
+
// Sentry.startSpan signature: <T>(options, callback: (span) => T) => T
|
|
171
|
+
// When callback returns Promise<T>, the return is Promise<T>
|
|
172
|
+
const mockSentryStartSpan = <T>(
|
|
173
|
+
_options: { name: string },
|
|
174
|
+
callback: (span: unknown) => T,
|
|
175
|
+
): T => {
|
|
176
|
+
// Sentry passes a span object to the callback; our callbacks ignore it
|
|
177
|
+
return callback({ spanId: "mock-span" });
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const unsub = BeraTracing.addSpanHandler(
|
|
181
|
+
mockSentryStartSpan as typeof BeraTracing.startSpan,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const result = await BeraTracing.startSpan(
|
|
185
|
+
{
|
|
186
|
+
name: "GraphQL TestQuery",
|
|
187
|
+
op: "BeraApolloClient.query",
|
|
188
|
+
attributes: {},
|
|
189
|
+
},
|
|
190
|
+
async () => ({ data: { value: 1 } }),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
expect(result).toEqual({ data: { value: 1 } });
|
|
194
|
+
|
|
195
|
+
unsub();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ErrorLike } from "@apollo/client";
|
|
2
2
|
|
|
3
|
-
import mainnet from "@berachain/config/mainnet";
|
|
3
|
+
import { mainnet } from "@berachain/config/mainnet";
|
|
4
4
|
|
|
5
5
|
import { BeraError, type IBeraErrorArgs } from "./BeraError";
|
|
6
6
|
import { errorMsgMap } from "./errorMap";
|
|
@@ -31,10 +31,12 @@ export class RequestError extends BeraError {
|
|
|
31
31
|
*/
|
|
32
32
|
private queryRichfulDomains = [
|
|
33
33
|
mainnet.bex.aggregatorsProxyUrl,
|
|
34
|
-
"https://api.
|
|
34
|
+
"https://api.fly.trade/aggregator/quote",
|
|
35
35
|
"https://open-api.openocean.finance/v4/bera/swap",
|
|
36
36
|
// vercel internal proxy
|
|
37
37
|
"/api/aggregators?aggregator",
|
|
38
|
+
// bonder endpoints have date-based query params (e.g. ?start=2025-11-28)
|
|
39
|
+
mainnet.bonder,
|
|
38
40
|
];
|
|
39
41
|
|
|
40
42
|
statusCode: number | undefined;
|
|
@@ -116,7 +118,10 @@ export class RequestError extends BeraError {
|
|
|
116
118
|
message += `HTTP ${this.statusCode} – `;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
|
|
121
|
+
const endpointLabel = this.endpoint.type
|
|
122
|
+
? `${this.endpoint.type}(${this.endpoint.url})`
|
|
123
|
+
: this.endpoint.url;
|
|
124
|
+
this.message = `${message}${endpointLabel}: ${this.message}`;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
setEndpoint(
|
|
@@ -202,6 +207,27 @@ export class RequestError extends BeraError {
|
|
|
202
207
|
}
|
|
203
208
|
}
|
|
204
209
|
|
|
210
|
+
if (
|
|
211
|
+
typeof this.cause === "object" &&
|
|
212
|
+
this.cause !== null &&
|
|
213
|
+
"message" in this.cause &&
|
|
214
|
+
typeof this.cause.message === "string"
|
|
215
|
+
) {
|
|
216
|
+
const message = this.cause.message as string;
|
|
217
|
+
// this is a postgres error message. found in some bonder errors.
|
|
218
|
+
if (
|
|
219
|
+
message.startsWith(
|
|
220
|
+
"error: canceling statement due to lock timeout occurred in",
|
|
221
|
+
)
|
|
222
|
+
) {
|
|
223
|
+
return {
|
|
224
|
+
reason: RequestError.REASON_MAP.NETWORK_ERROR,
|
|
225
|
+
message: message,
|
|
226
|
+
url: this.endpoint.url,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
205
231
|
return false;
|
|
206
232
|
}
|
|
207
233
|
}
|
package/src/errors/assert.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GetPublicClientReturnType } from "@wagmi/core";
|
|
1
2
|
import { type Address, isAddress, type PublicClient } from "viem";
|
|
2
3
|
|
|
3
4
|
import { InvalidArgumentError } from "./InvalidArgumentError";
|
|
@@ -83,7 +84,8 @@ export function assertPublicClient(
|
|
|
83
84
|
/**
|
|
84
85
|
* The value to assert.
|
|
85
86
|
*/
|
|
86
|
-
value:
|
|
87
|
+
value: // it's important to have both types here because it helps with typescript build performance
|
|
88
|
+
PublicClient | GetPublicClientReturnType | undefined,
|
|
87
89
|
/**
|
|
88
90
|
* The property name.
|
|
89
91
|
*/
|
|
@@ -101,7 +103,7 @@ export function assertAddress(
|
|
|
101
103
|
/**
|
|
102
104
|
* The value to assert.
|
|
103
105
|
*/
|
|
104
|
-
value: string | undefined,
|
|
106
|
+
value: string | undefined | null,
|
|
105
107
|
/**
|
|
106
108
|
* The property name.
|
|
107
109
|
*/
|
|
@@ -61,8 +61,12 @@ describe("assertAddress", () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it("throws InvalidArgumentError for non-string", () => {
|
|
64
|
-
expect(() => assertAddress(123, "addr")).toThrow(
|
|
65
|
-
|
|
64
|
+
expect(() => assertAddress(123 as unknown as string, "addr")).toThrow(
|
|
65
|
+
InvalidArgumentError,
|
|
66
|
+
);
|
|
67
|
+
expect(() => assertAddress({} as unknown as string, "addr")).toThrow(
|
|
68
|
+
InvalidArgumentError,
|
|
69
|
+
);
|
|
66
70
|
});
|
|
67
71
|
|
|
68
72
|
it("throws InvalidArgumentError for invalid address string", () => {
|
package/src/errors/errorMap.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ErrorCategory {
|
|
|
17
17
|
[key: string]: ErrorType;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
interface ErrorMessages {
|
|
21
21
|
[key: string]: ErrorCategory | string;
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -76,13 +76,19 @@ export const errorMsgMap = {
|
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
78
|
RPC: {
|
|
79
|
-
|
|
79
|
+
NOT_ENOUGH_GAS_TOKEN: {
|
|
80
80
|
reasons: ["InsufficientFundsError"],
|
|
81
81
|
keywords: [
|
|
82
|
+
"insufficient funds for gas * price + value:",
|
|
82
83
|
"The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.",
|
|
83
84
|
],
|
|
84
85
|
errorMSG: "Insufficient BERA balance to perform this action.",
|
|
85
86
|
},
|
|
87
|
+
NONCE_TOO_LOW: {
|
|
88
|
+
keywords: ["nonce too low: next nonce"],
|
|
89
|
+
errorMSG:
|
|
90
|
+
"Nonce is too low. Your wallet might have unconfirmed transactions.",
|
|
91
|
+
},
|
|
86
92
|
GAS_PRICE: {
|
|
87
93
|
keywords: ["gasLimit"],
|
|
88
94
|
errorMSG:
|
|
@@ -94,13 +100,8 @@ export const errorMsgMap = {
|
|
|
94
100
|
errorMSG:
|
|
95
101
|
"It seems an RPC error has occurred. Please try your request one more later.",
|
|
96
102
|
},
|
|
97
|
-
// ETH_GETBALANCE: {
|
|
98
|
-
// keywords: "eth_getBalance",
|
|
99
|
-
// err: "An RPC error has been detected. Please attempt your request after a short while.",
|
|
100
|
-
// },
|
|
101
103
|
HASH: {
|
|
102
104
|
keywords: ["hash"],
|
|
103
|
-
|
|
104
105
|
errorMSG:
|
|
105
106
|
"It seems an RPC error has occurred. Please check if your transaction was finalized. If not, please try again.",
|
|
106
107
|
},
|
|
@@ -120,6 +121,16 @@ export const errorMsgMap = {
|
|
|
120
121
|
"Wallet seems to be on the wrong chain, please refresh the page and try again.",
|
|
121
122
|
},
|
|
122
123
|
},
|
|
124
|
+
EIP7702: {
|
|
125
|
+
SESSION_KEY_EXPIRED: {
|
|
126
|
+
reasons: ["SessionKeyExpired"],
|
|
127
|
+
errorMSG: "Session key has expired. Please create a new one.",
|
|
128
|
+
},
|
|
129
|
+
CALL_POLICY_VIOLATED: {
|
|
130
|
+
reasons: ["CallPolicyViolated"],
|
|
131
|
+
errorMSG: "Call policy violated. Please check your call policies.",
|
|
132
|
+
},
|
|
133
|
+
},
|
|
123
134
|
HONEY: {
|
|
124
135
|
BLACKLISTED_WALLET: {
|
|
125
136
|
reasons: ["BlacklistedWallet", "0x265693b4"],
|
|
@@ -136,7 +147,7 @@ export const errorMsgMap = {
|
|
|
136
147
|
// NOTE: descriptions are generated by GPT where not available.
|
|
137
148
|
BEX: {
|
|
138
149
|
SLIPPAGE_EXCEEDED: {
|
|
139
|
-
reasons: ["SlippageExceeded"],
|
|
150
|
+
reasons: ["SlippageExceeded", "TooMuchSlippage"],
|
|
140
151
|
errorMSG:
|
|
141
152
|
"Price changed while executing the transaction and exceeded the allowed slippage.",
|
|
142
153
|
},
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
export * from "./assert";
|
|
2
2
|
export * from "./BeraError";
|
|
3
|
+
export {
|
|
4
|
+
BeraMonitoring,
|
|
5
|
+
type CaptureContext,
|
|
6
|
+
type ErrorEvent,
|
|
7
|
+
} from "./BeraMonitoring";
|
|
8
|
+
export { BeraTracing, type SpanContext } from "./BeraTracing";
|
|
3
9
|
export * from "./getErrorMessage";
|
|
4
10
|
export * from "./InvalidArgumentError";
|
|
5
11
|
export * from "./initBeraError";
|
|
6
12
|
export * from "./NotFoundError";
|
|
7
13
|
export * from "./RequestError";
|
|
14
|
+
export type { SeverityLevel } from "./severity";
|
|
8
15
|
export * from "./TransactionFailedError";
|
|
@@ -1,40 +1,98 @@
|
|
|
1
1
|
import { type ErrorCategory, errorMsgMap, GENERAL_ERROR } from "./errorMap";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface MatchedError {
|
|
4
|
+
/** The error key in the errorMap (e.g. "NOT_ENOUGH_GAS_TOKEN") */
|
|
5
|
+
key: string;
|
|
6
|
+
/** The category in the errorMap (e.g. "RPC", "BEX") */
|
|
7
|
+
category: string;
|
|
8
|
+
/** The user-friendly display message */
|
|
9
|
+
errorMSG: string;
|
|
10
|
+
/** Whether the match was by exact reason (true) or keyword (false) */
|
|
11
|
+
matchedByReason: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Finds the matching error entry in errorMap by reason or message.
|
|
16
|
+
*
|
|
17
|
+
* ## Matching priority:
|
|
18
|
+
* 1. **Exact reason match** (preferred): checks `errorType.reasons` for an exact string match.
|
|
19
|
+
* 2. **Keyword fallback**: checks `errorType.keywords` for case-insensitive substring matches in `message`.
|
|
20
|
+
*
|
|
21
|
+
* @returns The matched error entry with key and category, or null if no match found.
|
|
22
|
+
*/
|
|
23
|
+
export function findMatchingError({
|
|
4
24
|
reason,
|
|
5
25
|
message,
|
|
6
26
|
}: {
|
|
7
27
|
reason?: string | null;
|
|
8
28
|
message?: string;
|
|
9
|
-
}):
|
|
10
|
-
// Check against defined categories
|
|
29
|
+
}): MatchedError | null {
|
|
11
30
|
for (const category in errorMsgMap) {
|
|
12
|
-
// Just for type safety
|
|
13
31
|
const categoryKey = category as keyof typeof errorMsgMap;
|
|
14
|
-
|
|
15
32
|
const errors = errorMsgMap[categoryKey] as ErrorCategory;
|
|
16
33
|
|
|
17
34
|
for (const type in errors) {
|
|
18
35
|
const errorType = errors[type];
|
|
19
36
|
|
|
37
|
+
// Priority 1: Exact reason match (deterministic, preferred for contract revert reasons)
|
|
20
38
|
if (reason) {
|
|
21
39
|
if (
|
|
22
40
|
errorType?.reasons?.some((r) => {
|
|
23
41
|
return r === reason;
|
|
24
42
|
})
|
|
25
43
|
) {
|
|
26
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
key: type,
|
|
46
|
+
category,
|
|
47
|
+
errorMSG: errorType.errorMSG,
|
|
48
|
+
matchedByReason: true,
|
|
49
|
+
};
|
|
27
50
|
}
|
|
28
51
|
}
|
|
52
|
+
|
|
53
|
+
// Priority 2: Keyword substring match on message (case-insensitive fallback, use carefully)
|
|
29
54
|
if (
|
|
30
55
|
errorType?.keywords?.some((keyword) => {
|
|
31
|
-
return message?.includes(keyword.toLowerCase().trim());
|
|
56
|
+
return message?.toLowerCase().includes(keyword.toLowerCase().trim());
|
|
32
57
|
})
|
|
33
58
|
) {
|
|
34
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
key: type,
|
|
61
|
+
category,
|
|
62
|
+
errorMSG: errorType.errorMSG,
|
|
63
|
+
matchedByReason: false,
|
|
64
|
+
};
|
|
35
65
|
}
|
|
36
66
|
}
|
|
37
67
|
}
|
|
38
68
|
|
|
39
|
-
return
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Resolves a user-friendly displayMessage by matching `reason` and `message` against `errorMap.ts`.
|
|
74
|
+
*
|
|
75
|
+
* This is the bridge between the automatic reason detection pipeline (parseViemError) and
|
|
76
|
+
* the user-facing error messages. Called by the BeraError constructor.
|
|
77
|
+
*
|
|
78
|
+
* ## Matching priority:
|
|
79
|
+
* 1. **Exact reason match** (preferred): checks `errorType.reasons` for an exact string match.
|
|
80
|
+
* This is the most reliable path — contract revert reasons like "NotEnoughBalance" or "BAL#508"
|
|
81
|
+
* are matched deterministically.
|
|
82
|
+
* 2. **Keyword fallback**: checks `errorType.keywords` for case-insensitive substring matches in `message`.
|
|
83
|
+
* Use sparingly — keyword matching can cause false positives (e.g. "InsufficientBalance"
|
|
84
|
+
* keyword would also match "InsufficientBalanceToPayPythFee").
|
|
85
|
+
* 3. **GENERAL_ERROR fallback**: "Something went wrong. Please try again later."
|
|
86
|
+
*
|
|
87
|
+
* To ensure new contract errors get good displayMessages, add their reason to `errorMap.ts`.
|
|
88
|
+
* The reason is auto-detected by parseViemError — you only need to map it to a message here.
|
|
89
|
+
*/
|
|
90
|
+
export function getErrorMessage({
|
|
91
|
+
reason,
|
|
92
|
+
message,
|
|
93
|
+
}: {
|
|
94
|
+
reason?: string | null;
|
|
95
|
+
message?: string;
|
|
96
|
+
}): string {
|
|
97
|
+
return findMatchingError({ reason, message })?.errorMSG ?? GENERAL_ERROR;
|
|
40
98
|
}
|