@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,22 @@
|
|
|
1
|
+
import type { TokenWithMetadata } from "./dex";
|
|
2
|
+
|
|
3
|
+
export interface ProtocolMetadata {
|
|
4
|
+
name: string;
|
|
5
|
+
logoURI: string;
|
|
6
|
+
url: string;
|
|
7
|
+
description: string;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for a single staking option.
|
|
13
|
+
* Maps receipt tokens to their accepted input tokens.
|
|
14
|
+
*/
|
|
15
|
+
export type StakingConfig = {
|
|
16
|
+
/** Unique identifier for this staking config */
|
|
17
|
+
id: string;
|
|
18
|
+
/** The token received when staking (e.g., sWBERA, siBERA) */
|
|
19
|
+
receiptToken: TokenWithMetadata;
|
|
20
|
+
/** Tokens that can be staked to receive the receipt token */
|
|
21
|
+
inputTokens: TokenWithMetadata[];
|
|
22
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
interface EventsMap {
|
|
2
|
+
[event: string]: any;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
interface DefaultEvents extends EventsMap {
|
|
6
|
+
[event: string]: (...args: any) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type Unsubscribe = () => void;
|
|
10
|
+
|
|
11
|
+
export interface Emitter<Events extends EventsMap = DefaultEvents> {
|
|
12
|
+
/**
|
|
13
|
+
* Calls each of the listeners registered for a given event.
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* ee.emit('tick', tickType, tickDuration)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param event The event name.
|
|
20
|
+
* @param args The arguments for listeners.
|
|
21
|
+
*/
|
|
22
|
+
emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Add a listener for a given event.
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* const unbind = ee.on('tick', (tickType, tickDuration) => {
|
|
29
|
+
* count += 1
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* disable () {
|
|
33
|
+
* unbind()
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param event The event name.
|
|
38
|
+
* @param cb The listener function.
|
|
39
|
+
* @returns Unbind listener from event.
|
|
40
|
+
*/
|
|
41
|
+
on<K extends keyof Events>(event: K, cb: Events[K]): Unsubscribe;
|
|
42
|
+
events: Partial<{ [E in keyof Events]: Events[E][] }>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* An interface for mixins that expose the `on` function (without the emitter
|
|
47
|
+
* bound to `this`)
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* import { createEmitter } from '~utils/createEmitter'
|
|
51
|
+
*
|
|
52
|
+
* class Ticker implements EmitterMixin<Events> {
|
|
53
|
+
* constructor() {
|
|
54
|
+
* this.emitter = createEmitter()
|
|
55
|
+
* }
|
|
56
|
+
* on(...args) {
|
|
57
|
+
* return this.emitter.on(...args)
|
|
58
|
+
* }
|
|
59
|
+
* tick() {
|
|
60
|
+
* this.emitter.emit('tick')
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export interface EmitterMixin<Events extends EventsMap = DefaultEvents> {
|
|
66
|
+
on<K extends keyof Events>(event: K, cb: Events[K]): Unsubscribe;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create event emitter.
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* import { createEmitter } from '~/utils/createEmitter'
|
|
74
|
+
*
|
|
75
|
+
* class Ticker {
|
|
76
|
+
* constructor() {
|
|
77
|
+
* this.emitter = createEmitter()
|
|
78
|
+
* }
|
|
79
|
+
* on(...args) {
|
|
80
|
+
* return this.emitter.on(...args)
|
|
81
|
+
* }
|
|
82
|
+
* tick() {
|
|
83
|
+
* this.emitter.emit('tick')
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* Inspired by {@link https://github.com/ai/nanoevents}
|
|
89
|
+
*/
|
|
90
|
+
export function createEmitter<
|
|
91
|
+
Events extends EventsMap = DefaultEvents,
|
|
92
|
+
>(): Emitter<Events> {
|
|
93
|
+
/**
|
|
94
|
+
* Event names in keys and arrays with listeners in values.
|
|
95
|
+
*
|
|
96
|
+
* ```js
|
|
97
|
+
* emitter1.events = emitter2.events
|
|
98
|
+
* emitter2.events = { }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
const events: Partial<{ [E in keyof Events]: Events[E][] }> = {};
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
emit(event, ...args) {
|
|
105
|
+
for (const callback of events[event] || []) {
|
|
106
|
+
callback(...args);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
events,
|
|
110
|
+
on(event, cb) {
|
|
111
|
+
if (!events[event]) {
|
|
112
|
+
events[event] = [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
events[event].push(cb);
|
|
116
|
+
|
|
117
|
+
return () => {
|
|
118
|
+
events[event] = events[event]?.filter((i) => cb !== i);
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { createEmitter } from "./createEmitter.js";
|
|
4
|
+
|
|
5
|
+
describe("createEmitter", () => {
|
|
6
|
+
it("is empty from the beginning", () => {
|
|
7
|
+
const ee = createEmitter();
|
|
8
|
+
expect(ee.events).toEqual({});
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("adds listeners", () => {
|
|
12
|
+
const ee = createEmitter();
|
|
13
|
+
|
|
14
|
+
ee.on("one", () => true);
|
|
15
|
+
ee.on("two", () => true);
|
|
16
|
+
ee.on("two", () => true);
|
|
17
|
+
|
|
18
|
+
expect(Object.keys(ee.events)).toEqual(["one", "two"]);
|
|
19
|
+
expect(ee.events.one?.length).toEqual(1);
|
|
20
|
+
expect(ee.events.two?.length).toEqual(2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("calls listener", () => {
|
|
24
|
+
const ee = createEmitter();
|
|
25
|
+
const calls: number[][] = [];
|
|
26
|
+
ee.on("event", (...args) => {
|
|
27
|
+
calls.push(args);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
ee.emit("event");
|
|
31
|
+
ee.emit("event", 11);
|
|
32
|
+
ee.emit("event", 21, 22);
|
|
33
|
+
ee.emit("event", 31, 32, 33);
|
|
34
|
+
ee.emit("event", 41, 42, 43, 44);
|
|
35
|
+
|
|
36
|
+
expect(calls).toEqual([[], [11], [21, 22], [31, 32, 33], [41, 42, 43, 44]]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("unbinds listener", () => {
|
|
40
|
+
const ee = createEmitter();
|
|
41
|
+
|
|
42
|
+
const calls1: number[] = [];
|
|
43
|
+
const unbind = ee.on("event", (a) => {
|
|
44
|
+
calls1.push(a);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const calls2: number[] = [];
|
|
48
|
+
ee.on("event", (a) => {
|
|
49
|
+
calls2.push(a);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
ee.emit("event", 1);
|
|
53
|
+
unbind();
|
|
54
|
+
ee.emit("event", 2);
|
|
55
|
+
|
|
56
|
+
expect(calls1).toEqual([1]);
|
|
57
|
+
expect(calls2).toEqual([1, 2]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("calls unbind after cleaning events", () => {
|
|
61
|
+
const ee = createEmitter();
|
|
62
|
+
const unbind = ee.on("event", () => undefined);
|
|
63
|
+
ee.events = {};
|
|
64
|
+
expect(() => {
|
|
65
|
+
unbind();
|
|
66
|
+
}).not.toThrow();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("removes event on no listeners", () => {
|
|
70
|
+
const ee = createEmitter();
|
|
71
|
+
const unbind1 = ee.on("one", () => {});
|
|
72
|
+
const unbind2 = ee.on("one", () => {});
|
|
73
|
+
|
|
74
|
+
unbind1();
|
|
75
|
+
expect(ee.events.one?.length).toEqual(1);
|
|
76
|
+
|
|
77
|
+
unbind1();
|
|
78
|
+
expect(ee.events.one?.length).toEqual(1);
|
|
79
|
+
|
|
80
|
+
unbind2();
|
|
81
|
+
expect(ee.events.one?.length).toEqual(0);
|
|
82
|
+
|
|
83
|
+
unbind2();
|
|
84
|
+
expect(ee.events.one?.length).toEqual(0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("removes listener during event", () => {
|
|
88
|
+
const ee = createEmitter();
|
|
89
|
+
|
|
90
|
+
const calls: number[] = [];
|
|
91
|
+
const remove1 = ee.on("event", () => {
|
|
92
|
+
remove1();
|
|
93
|
+
calls.push(1);
|
|
94
|
+
});
|
|
95
|
+
ee.on("event", () => {
|
|
96
|
+
calls.push(2);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
ee.emit("event");
|
|
100
|
+
expect(calls).toEqual([1, 2]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("allows to use arrow function to bind a context", () => {
|
|
104
|
+
const ee = createEmitter();
|
|
105
|
+
const app = {
|
|
106
|
+
check: ["a"],
|
|
107
|
+
|
|
108
|
+
getListener() {
|
|
109
|
+
return () => {
|
|
110
|
+
this.check = this.value.split("");
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
value: "test",
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const unbind = ee.on("event", app.getListener());
|
|
118
|
+
|
|
119
|
+
expect(() => {
|
|
120
|
+
ee.emit("event");
|
|
121
|
+
}).not.toThrow();
|
|
122
|
+
|
|
123
|
+
expect(app.check).toEqual(["t", "e", "s", "t"]);
|
|
124
|
+
|
|
125
|
+
unbind();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("allows to replace listeners", () => {
|
|
129
|
+
const ee1 = createEmitter<{ A: () => void; B: () => void }>();
|
|
130
|
+
const ee2 = createEmitter<{ A: () => void; B: () => void }>();
|
|
131
|
+
|
|
132
|
+
const aSpy = vi.fn();
|
|
133
|
+
ee1.on("A", aSpy);
|
|
134
|
+
const bSpy = vi.fn();
|
|
135
|
+
ee2.on("B", bSpy);
|
|
136
|
+
|
|
137
|
+
ee1.events = ee2.events;
|
|
138
|
+
|
|
139
|
+
ee1.emit("A");
|
|
140
|
+
expect(aSpy).toHaveBeenCalledTimes(1);
|
|
141
|
+
|
|
142
|
+
ee1.emit("B");
|
|
143
|
+
expect(bSpy).toHaveBeenCalledTimes(0);
|
|
144
|
+
|
|
145
|
+
ee2.emit("B");
|
|
146
|
+
expect(bSpy).toHaveBeenCalledTimes(1);
|
|
147
|
+
expect(aSpy).toHaveBeenCalledTimes(1);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { defaultFlags as defaultBeraFlags } from "../contexts/BeraFlags/defaultFlags";
|
|
2
2
|
export * from "./beraFetch";
|
|
3
3
|
export * from "./constants";
|
|
4
|
-
export * from "./formatAggregatorsQuotes";
|
|
5
4
|
export * from "./formatInputTokenValue";
|
|
6
5
|
export * from "./formatNumber";
|
|
7
6
|
export * from "./formatTimestamps";
|
|
@@ -12,9 +11,11 @@ export * from "./getServerSideClient";
|
|
|
12
11
|
export { getTestClient } from "./getTestClient";
|
|
13
12
|
export * from "./isDifferenceExceedingThreshold";
|
|
14
13
|
export * from "./isSubgraphStale";
|
|
14
|
+
export * from "./layerZeroScan";
|
|
15
|
+
export * from "./math";
|
|
15
16
|
export * from "./parseBaseArgs";
|
|
17
|
+
export * from "./parseWhiskToken";
|
|
16
18
|
export * from "./pythHoneyUtils";
|
|
17
|
-
export { sentryBeforeSend } from "./sentryBeforeSend";
|
|
18
19
|
export * from "./time";
|
|
19
20
|
export {
|
|
20
21
|
beraToken as internal_beraToken,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters data to get one data point per day
|
|
3
|
+
* @param data - The data to filter
|
|
4
|
+
* @returns The filtered data
|
|
5
|
+
*/
|
|
6
|
+
export const dailyResolution = <
|
|
7
|
+
T extends { timestamp?: number; _timestamp?: number },
|
|
8
|
+
>(
|
|
9
|
+
data: T[],
|
|
10
|
+
) => {
|
|
11
|
+
// Filter to get one data point per day
|
|
12
|
+
const dailyData: T[] = [];
|
|
13
|
+
let lastDay = "";
|
|
14
|
+
|
|
15
|
+
for (const item of data) {
|
|
16
|
+
if (!item.timestamp && !item._timestamp) continue;
|
|
17
|
+
// Convert Unix timestamp (seconds) to milliseconds for Date constructor
|
|
18
|
+
const timestampMs = (item?.timestamp ?? item?._timestamp ?? 0) * 1000;
|
|
19
|
+
const currentDay = new Date(timestampMs);
|
|
20
|
+
const currentDayStr = currentDay.toDateString();
|
|
21
|
+
if (currentDayStr !== lastDay) {
|
|
22
|
+
const newTimestamp =
|
|
23
|
+
new Date(currentDay.setHours(0, 0, 0, 0)).getTime() / 1000;
|
|
24
|
+
dailyData.push({
|
|
25
|
+
...item,
|
|
26
|
+
timestamp: newTimestamp,
|
|
27
|
+
_timestamp: newTimestamp,
|
|
28
|
+
});
|
|
29
|
+
lastDay = currentDayStr;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return dailyData;
|
|
34
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Token, TokenWithMetadata } from "../types";
|
|
1
|
+
import type { Token, TokenWithMetadata } from "../types/dex";
|
|
2
2
|
import { isToken } from "./tokens";
|
|
3
3
|
|
|
4
4
|
export interface FormatTokenListReturnType {
|
|
@@ -19,11 +19,9 @@ export interface FormatTokenListReturnType {
|
|
|
19
19
|
function formatTokenList({
|
|
20
20
|
defaultTokenList = [],
|
|
21
21
|
externalList = [],
|
|
22
|
-
chainId,
|
|
23
22
|
}: {
|
|
24
23
|
defaultTokenList: TokenWithMetadata[];
|
|
25
24
|
externalList?: Token[];
|
|
26
|
-
chainId: number;
|
|
27
25
|
}): FormatTokenListReturnType {
|
|
28
26
|
if (defaultTokenList.length === 0) {
|
|
29
27
|
return {
|
|
@@ -33,13 +31,9 @@ function formatTokenList({
|
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
const defaultList = defaultTokenList
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
.map((token) => {
|
|
41
|
-
return { ...token, default: true };
|
|
42
|
-
});
|
|
34
|
+
const defaultList = defaultTokenList.map((token) => {
|
|
35
|
+
return { ...token, default: true };
|
|
36
|
+
});
|
|
43
37
|
|
|
44
38
|
const featuredTokenList = defaultList.filter((token) => {
|
|
45
39
|
return token.tags?.some((tag) => tag === "featured");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
|
-
import type { IHoneySwapState } from "
|
|
4
|
-
|
|
3
|
+
import type { IHoneySwapState } from "~/hooks/honey/useHoneySwapState";
|
|
5
4
|
import { getHoneySwapMessage as getMessage } from "./getHoneySwapMessage";
|
|
6
5
|
|
|
7
6
|
describe("getMessage", () => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { createPublicClient, fallback, http, type PublicClient } from "viem";
|
|
2
|
+
import { berachain, berachainBepolia } from "viem/chains";
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
+
ChainId,
|
|
5
6
|
defaultChainId,
|
|
6
7
|
getRpcUrls,
|
|
7
8
|
} from "@berachain/config/internal";
|
|
8
9
|
|
|
9
|
-
import { defaultBeraNetworkConfig } from "@berachain/wagmi/config";
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* This is a singleton to avoid creating a new client for each request.
|
|
13
12
|
*
|
|
@@ -37,9 +36,9 @@ export const getServerSidePublicClient = (
|
|
|
37
36
|
if (fallbackTransports.length === 0) {
|
|
38
37
|
fallbackTransports.push(http());
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
const chain = chainId === ChainId.MAINNET ? berachain : berachainBepolia;
|
|
41
40
|
const client = createPublicClient({
|
|
42
|
-
chain
|
|
41
|
+
chain,
|
|
43
42
|
transport: fallback(fallbackTransports),
|
|
44
43
|
});
|
|
45
44
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BeraError } from "../errors/BeraError";
|
|
2
|
+
import { InvalidArgumentError } from "../errors/InvalidArgumentError";
|
|
3
|
+
import { RequestError } from "../errors/RequestError";
|
|
4
|
+
import { beraFetchJson } from "./beraFetch";
|
|
5
|
+
|
|
6
|
+
const LAYERZERO_SCAN_MAINNET_URL = "https://api-mainnet.layerzero-scan.com";
|
|
7
|
+
|
|
8
|
+
export enum LayerZeroMessageStatus {
|
|
9
|
+
INFLIGHT = "INFLIGHT",
|
|
10
|
+
DELIVERED = "DELIVERED",
|
|
11
|
+
FAILED = "FAILED",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type LayerZeroMessage = {
|
|
15
|
+
srcUaAddress: string;
|
|
16
|
+
dstUaAddress: string;
|
|
17
|
+
srcChainId: number;
|
|
18
|
+
dstChainId: number;
|
|
19
|
+
dstTxHash?: string;
|
|
20
|
+
dstTxError?: string;
|
|
21
|
+
srcTxHash?: string;
|
|
22
|
+
srcBlockHash?: string;
|
|
23
|
+
srcBlockNumber?: string;
|
|
24
|
+
srcUaNonce: number;
|
|
25
|
+
status: LayerZeroMessageStatus;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type LayerZeroDeliveredMessage = LayerZeroMessage & {
|
|
29
|
+
dstTxHash: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type GetMessagesBySrcTxHashResponse = {
|
|
33
|
+
messages: LayerZeroMessage[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
37
|
+
|
|
38
|
+
async function getMessagesBySrcTxHash(
|
|
39
|
+
srcTxHash: string,
|
|
40
|
+
): Promise<GetMessagesBySrcTxHashResponse> {
|
|
41
|
+
return beraFetchJson<GetMessagesBySrcTxHashResponse>({
|
|
42
|
+
url: `${LAYERZERO_SCAN_MAINNET_URL}/tx/${srcTxHash}`,
|
|
43
|
+
type: "rest",
|
|
44
|
+
name: "LayerZero Scan",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type WaitForMessageReceivedOptions = {
|
|
49
|
+
pollInterval?: number;
|
|
50
|
+
timeout?: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Polls LayerZero scan API until the cross-chain message is delivered or fails.
|
|
55
|
+
* HTTP errors are silently retried until timeout.
|
|
56
|
+
*
|
|
57
|
+
* @param srcTxHash - The source transaction hash to track
|
|
58
|
+
* @param options - Configuration options
|
|
59
|
+
* @param options.pollInterval - Polling interval in ms (default: 3000)
|
|
60
|
+
* @param options.timeout - Timeout in ms (default: 600000 / 10 minutes)
|
|
61
|
+
* @returns The delivered message with destination tx hash
|
|
62
|
+
* @throws InvalidArgumentError if srcTxHash is missing
|
|
63
|
+
* @throws BeraError if message fails, times out, or multiple messages found
|
|
64
|
+
*/
|
|
65
|
+
export async function waitForLayerZeroMessageReceived(
|
|
66
|
+
srcTxHash: string,
|
|
67
|
+
options: WaitForMessageReceivedOptions = {},
|
|
68
|
+
): Promise<LayerZeroDeliveredMessage> {
|
|
69
|
+
const { pollInterval = 3000, timeout = 600_000 } = options;
|
|
70
|
+
|
|
71
|
+
if (!srcTxHash) {
|
|
72
|
+
throw new InvalidArgumentError({
|
|
73
|
+
property: "srcTxHash",
|
|
74
|
+
value: srcTxHash,
|
|
75
|
+
expected: "string",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const startTime = Date.now();
|
|
80
|
+
|
|
81
|
+
while (true) {
|
|
82
|
+
// check timeout
|
|
83
|
+
if (Date.now() - startTime > timeout) {
|
|
84
|
+
throw new BeraError({
|
|
85
|
+
message: `LayerZero message tracking timed out after ${timeout}ms`,
|
|
86
|
+
reason: "LAYERZERO_TIMEOUT",
|
|
87
|
+
level: "warning",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const { messages } = await getMessagesBySrcTxHash(srcTxHash);
|
|
93
|
+
const message = messages[0];
|
|
94
|
+
|
|
95
|
+
if (messages.length > 1) {
|
|
96
|
+
throw new BeraError({
|
|
97
|
+
message: "More than one LayerZero message found for transaction",
|
|
98
|
+
reason: "LAYERZERO_MULTIPLE_MESSAGES",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (message?.status === LayerZeroMessageStatus.FAILED) {
|
|
103
|
+
throw new BeraError({
|
|
104
|
+
message: `LayerZero message failed: ${message.dstTxError}`,
|
|
105
|
+
reason: "LAYERZERO_MESSAGE_FAILED",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (message?.status === LayerZeroMessageStatus.DELIVERED) {
|
|
110
|
+
return message as LayerZeroDeliveredMessage;
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
// re-throw non-retryable errors (validation, timeout, failed message)
|
|
114
|
+
// but allow RequestError to retry (network issues, temporary API errors)
|
|
115
|
+
if (error instanceof BeraError && !(error instanceof RequestError)) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
await sleep(pollInterval);
|
|
121
|
+
}
|
|
122
|
+
}
|
package/src/utils/math.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TokenInfoFragmentFragment } from "@berachain/graphql/bend/whisk";
|
|
2
|
+
|
|
3
|
+
import type { TokenWithMetadata } from "~/types/dex";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a token from the Whisk API into a TokenWithMetadata object.
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function parseWhiskToken(token: TokenInfoFragmentFragment) {
|
|
11
|
+
return {
|
|
12
|
+
...token,
|
|
13
|
+
chainId: token.chain.id,
|
|
14
|
+
} as const satisfies TokenWithMetadata;
|
|
15
|
+
}
|
package/src/utils/poolNamings.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PoolType } from "@berachain-foundation/berancer-sdk";
|
|
2
2
|
import { formatUnits } from "viem";
|
|
3
3
|
|
|
4
|
-
import type { Token } from "~/types";
|
|
4
|
+
import type { Token } from "~/types/dex";
|
|
5
5
|
|
|
6
6
|
// Utility function to sort tokens by their address without modifying the original array
|
|
7
7
|
const sortTokensByAddress = (tokens: Token[]): Token[] => {
|
package/src/utils/tokens.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address, ethAddress, isAddress, zeroAddress } from "viem";
|
|
2
2
|
|
|
3
|
-
import mainnet from "@berachain/config/mainnet";
|
|
3
|
+
import { mainnet } from "@berachain/config/mainnet";
|
|
4
4
|
|
|
5
5
|
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
6
6
|
import type { TokenWithMetadata } from "../types/dex";
|
|
@@ -13,23 +13,24 @@ export const beraToken = {
|
|
|
13
13
|
symbol: "BERA",
|
|
14
14
|
logoURI:
|
|
15
15
|
"https://res.cloudinary.com/duv0g402y/image/upload/v1738720154/brand/berachain-chain-logo.png.png",
|
|
16
|
-
} as const satisfies TokenWithMetadata
|
|
16
|
+
} as const satisfies Omit<TokenWithMetadata, "chainId">;
|
|
17
17
|
|
|
18
18
|
export const wBeraToken = {
|
|
19
19
|
address: mainnet.tokens.wbera,
|
|
20
20
|
decimals: 18,
|
|
21
21
|
name: "WBera",
|
|
22
22
|
symbol: "WBERA",
|
|
23
|
-
} as const satisfies TokenWithMetadata
|
|
23
|
+
} as const satisfies Omit<TokenWithMetadata, "chainId">;
|
|
24
24
|
|
|
25
25
|
export function getHoneyToken(baseArgs: BeraJS.BaseFunctionArgs) {
|
|
26
|
-
const { config } = parseBaseArgs(baseArgs);
|
|
26
|
+
const { config, chainId } = parseBaseArgs(baseArgs);
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
29
|
address: config.honey.token,
|
|
30
30
|
symbol: "HONEY",
|
|
31
31
|
name: "Honey",
|
|
32
32
|
decimals: 18,
|
|
33
|
+
chainId,
|
|
33
34
|
} as const satisfies TokenWithMetadata;
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -46,7 +47,9 @@ type InputToken = BaseToken | string | undefined;
|
|
|
46
47
|
type IsTokenParams =
|
|
47
48
|
| [
|
|
48
49
|
token: InputToken,
|
|
49
|
-
compareTo:
|
|
50
|
+
compareTo:
|
|
51
|
+
| BaseToken
|
|
52
|
+
| Extract<KnownTokens, "BERA" | "WBERA" | "ETH" | "SWBERA">,
|
|
50
53
|
]
|
|
51
54
|
| [
|
|
52
55
|
token: InputToken,
|
|
@@ -61,7 +64,12 @@ export function isToken(...args: IsTokenParams): boolean {
|
|
|
61
64
|
|
|
62
65
|
const tokenAddress = typeof token === "string" ? token : token.address;
|
|
63
66
|
|
|
64
|
-
if (
|
|
67
|
+
if (
|
|
68
|
+
typeof compareTo === "string" &&
|
|
69
|
+
!isAddress(compareTo) &&
|
|
70
|
+
// this is a safeguard against weird inputs from enso. `0x00`
|
|
71
|
+
!compareTo.startsWith("0x")
|
|
72
|
+
) {
|
|
65
73
|
if (compareTo === "BERA") {
|
|
66
74
|
return tokenAddress.toLowerCase() === zeroAddress;
|
|
67
75
|
}
|
|
@@ -74,13 +82,21 @@ export function isToken(...args: IsTokenParams): boolean {
|
|
|
74
82
|
return tokenAddress.toLowerCase() === ethAddress;
|
|
75
83
|
}
|
|
76
84
|
|
|
85
|
+
if (compareTo === "SWBERA") {
|
|
86
|
+
// we are sure that wbera token is the same on all chains because it's checked on the config and forced as types
|
|
87
|
+
return tokenAddress.toLowerCase() === mainnet.tokens.swbera.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
if (baseArgs === undefined) {
|
|
78
91
|
throw new InvalidArgumentError({
|
|
79
92
|
property: "baseArgs",
|
|
80
93
|
value: baseArgs,
|
|
81
94
|
expected: "BeraJS.BaseFunctionArgs",
|
|
82
95
|
message:
|
|
83
|
-
"baseArgs is required when compared to a known token different than BERA or WBERA"
|
|
96
|
+
"baseArgs is required when compared to a known token different than BERA or WBERA. Checking against token: " +
|
|
97
|
+
compareTo +
|
|
98
|
+
" and token address: " +
|
|
99
|
+
tokenAddress,
|
|
84
100
|
});
|
|
85
101
|
}
|
|
86
102
|
const { config } = parseBaseArgs(baseArgs);
|