@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
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
1
|
import { type Address, formatEther, isAddressEqual } from "viem";
|
|
3
2
|
|
|
4
3
|
import type { MinimalPoolFragment } from "@berachain/graphql/dex/api";
|
|
4
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
5
5
|
|
|
6
6
|
import { useRewardVaultBalanceFromStakingToken } from "~/hooks/pol/useRewardVaultBalanceFromStakingToken";
|
|
7
7
|
import { usePollBalance } from "~/hooks/tokens/usePollBalance";
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
DefaultHookReturnType,
|
|
11
|
-
IUserPosition,
|
|
12
|
-
} from "~/types";
|
|
8
|
+
import type { IUserPosition } from "~/types/dex";
|
|
9
|
+
import type { DefaultHookOptions, DefaultHookReturnType } from "~/types/global";
|
|
13
10
|
|
|
14
11
|
type IUseLpPositionArgs = {
|
|
15
12
|
pool: MinimalPoolFragment | undefined;
|
|
@@ -63,7 +60,7 @@ export const useLpPosition = (
|
|
|
63
60
|
? {
|
|
64
61
|
...userPosition,
|
|
65
62
|
usdValue: userPosition
|
|
66
|
-
? Number(userPosition.
|
|
63
|
+
? Number(userPosition.balance.formatted) * lpTokenPrice
|
|
67
64
|
: undefined,
|
|
68
65
|
}
|
|
69
66
|
: undefined,
|
|
@@ -74,21 +71,23 @@ export const useLpPosition = (
|
|
|
74
71
|
)?.ratio ?? 0;
|
|
75
72
|
|
|
76
73
|
const userBalance = tokenRatio
|
|
77
|
-
? BigNumber(userPosition?.
|
|
74
|
+
? BigNumber(userPosition?.balance.formatted ?? "0").times(tokenRatio)
|
|
78
75
|
: BigNumber(0);
|
|
79
76
|
const price = Number(token.balanceUSD) / Number(token.balance);
|
|
80
77
|
|
|
81
78
|
return {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
...token,
|
|
80
|
+
|
|
81
|
+
balance: {
|
|
82
|
+
raw: userBalance?.isGreaterThan(0)
|
|
83
|
+
? userBalance
|
|
85
84
|
.times(10 ** token.decimals!)
|
|
86
85
|
.toFixed(0)
|
|
87
|
-
.toString()
|
|
88
|
-
|
|
89
|
-
:
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
.toString()
|
|
87
|
+
: "0",
|
|
88
|
+
formatted: userBalance.toString(),
|
|
89
|
+
},
|
|
90
|
+
price,
|
|
92
91
|
usdValue:
|
|
93
92
|
Number.isNaN(price) || !userBalance
|
|
94
93
|
? undefined
|
|
@@ -97,10 +96,12 @@ export const useLpPosition = (
|
|
|
97
96
|
}),
|
|
98
97
|
stakedBalance: userVaultTokenBalance?.address
|
|
99
98
|
? {
|
|
100
|
-
|
|
101
|
-
balance:
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
...userVaultTokenBalance,
|
|
100
|
+
balance: {
|
|
101
|
+
raw: userVaultTokenBalance.balance.toString(),
|
|
102
|
+
// Pools always use the 18 decimals
|
|
103
|
+
formatted: formatEther(userVaultTokenBalance.balance),
|
|
104
|
+
},
|
|
104
105
|
usdValue:
|
|
105
106
|
Number(formatEther(userVaultTokenBalance.balance)) * lpTokenPrice,
|
|
106
107
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
4
|
+
import { parseUnits, zeroAddress } from "viem";
|
|
5
|
+
|
|
6
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
7
7
|
|
|
8
8
|
import { BeraError } from "~/errors/BeraError";
|
|
9
9
|
import { usePollAllowances } from "~/hooks/tokens/usePollAllowances";
|
|
10
|
-
import type {
|
|
10
|
+
import type { AllowanceQueryItem, AllowanceToken } from "~/types/dex";
|
|
11
|
+
import { isToken } from "~/utils/tokens";
|
|
11
12
|
|
|
12
13
|
type NeedsApprovalToken = AllowanceToken & {
|
|
13
14
|
maxAmountIn: bigint;
|
|
@@ -18,28 +19,27 @@ function calculateMaxAmountIn({
|
|
|
18
19
|
decimals,
|
|
19
20
|
slippage,
|
|
20
21
|
}: {
|
|
21
|
-
amount:
|
|
22
|
+
amount: bigint;
|
|
22
23
|
decimals: number;
|
|
23
24
|
slippage: number | undefined;
|
|
24
25
|
}) {
|
|
25
|
-
const amountInWei = parseUnits(amount, decimals);
|
|
26
26
|
const slippageInWei = parseUnits((slippage ?? 0).toString(), decimals);
|
|
27
|
-
return (
|
|
28
|
-
amountInWei + (amountInWei * slippageInWei) / BigInt(100 * 10 ** decimals)
|
|
29
|
-
);
|
|
27
|
+
return amount + (amount * slippageInWei) / BigInt(100 * 10 ** decimals);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
export
|
|
33
|
-
tokenInput:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
export function useMultipleTokenApprovalsWithSlippage(
|
|
31
|
+
tokenInput: AllowanceQueryItem[],
|
|
32
|
+
options?: {
|
|
33
|
+
slippage?: number;
|
|
34
|
+
},
|
|
35
|
+
) {
|
|
36
|
+
const { slippage } = options ?? {};
|
|
37
|
+
|
|
38
|
+
const items = useMemo(
|
|
38
39
|
() =>
|
|
39
40
|
tokenInput
|
|
40
|
-
.filter((token) => token.address !==
|
|
41
|
-
.filter((token
|
|
42
|
-
.filter((token) => BigNumber(token.amount).gt(0)),
|
|
41
|
+
.filter((token) => token.token.address !== zeroAddress)
|
|
42
|
+
.filter((token) => BigNumber(token.amount.formatted).gt(0)),
|
|
43
43
|
[tokenInput],
|
|
44
44
|
);
|
|
45
45
|
|
|
@@ -48,40 +48,51 @@ export const useMultipleTokenApprovalsWithSlippage = (
|
|
|
48
48
|
refresh,
|
|
49
49
|
isLoading,
|
|
50
50
|
} = usePollAllowances({
|
|
51
|
-
|
|
52
|
-
tokens,
|
|
51
|
+
items,
|
|
53
52
|
});
|
|
54
53
|
|
|
55
54
|
const needsApproval = useMemo<NeedsApprovalToken[]>(
|
|
56
55
|
() =>
|
|
57
56
|
allowances
|
|
58
57
|
?.map<NeedsApprovalToken | undefined>((allowance) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
58
|
+
const item = items.find((item) =>
|
|
59
|
+
isToken(item.token.address, allowance.token),
|
|
61
60
|
);
|
|
62
61
|
|
|
63
|
-
if (!
|
|
62
|
+
if (!item) {
|
|
64
63
|
// Since we're checking the allowances, the tokens should be present
|
|
65
64
|
throw new BeraError({
|
|
66
65
|
message:
|
|
67
66
|
"Token not found when matching allowance in useMultipleTokenApprovalsWithSlippage",
|
|
68
67
|
cause: {
|
|
69
68
|
allowance,
|
|
70
|
-
|
|
69
|
+
items,
|
|
71
70
|
},
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
const maxAmountIn = calculateMaxAmountIn({
|
|
74
|
+
const maxAmountIn = calculateMaxAmountIn({
|
|
75
|
+
decimals: item.token.decimals,
|
|
76
|
+
amount: BigInt(item.amount.raw),
|
|
77
|
+
slippage,
|
|
78
|
+
});
|
|
76
79
|
|
|
77
|
-
if (allowance.allowance
|
|
78
|
-
return {
|
|
80
|
+
if (BigNumber(allowance.allowance.raw).lt(maxAmountIn)) {
|
|
81
|
+
return {
|
|
82
|
+
...item,
|
|
83
|
+
needsApproval: true,
|
|
84
|
+
maxAmountIn,
|
|
85
|
+
allowance: {
|
|
86
|
+
raw: allowance.allowance.raw,
|
|
87
|
+
formatted: allowance.allowance.formatted,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
return undefined;
|
|
82
93
|
})
|
|
83
94
|
.filter((token) => token !== undefined) ?? [],
|
|
84
|
-
[allowances, slippage,
|
|
95
|
+
[allowances, slippage, items],
|
|
85
96
|
);
|
|
86
97
|
|
|
87
98
|
return {
|
|
@@ -89,4 +100,4 @@ export const useMultipleTokenApprovalsWithSlippage = (
|
|
|
89
100
|
refresh,
|
|
90
101
|
isLoading,
|
|
91
102
|
};
|
|
92
|
-
}
|
|
103
|
+
}
|
|
@@ -5,7 +5,7 @@ import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
|
|
|
5
5
|
|
|
6
6
|
import { balancerVaultAbi } from "~/abi/bex/balancerVault";
|
|
7
7
|
import { assertPublicClient } from "~/errors/assert";
|
|
8
|
-
import type { DefaultHookOptions } from "~/types";
|
|
8
|
+
import type { DefaultHookOptions } from "~/types/global";
|
|
9
9
|
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -3,7 +3,7 @@ import useSWRImmutable from "swr/immutable";
|
|
|
3
3
|
import type { GqlPoolEventType } from "@berachain/graphql/dex/api";
|
|
4
4
|
|
|
5
5
|
import { getPoolEvents } from "~/actions/dex/getPoolEvents";
|
|
6
|
-
import { POLLING } from "~/enum";
|
|
6
|
+
import { POLLING } from "~/enum/polling";
|
|
7
7
|
|
|
8
8
|
export const usePoolEvents = ({
|
|
9
9
|
poolId,
|
|
@@ -6,7 +6,7 @@ import { useBeraWallet } from "@berachain/wagmi/hooks";
|
|
|
6
6
|
|
|
7
7
|
import { getAllPools } from "~/actions/dex/getAllPools";
|
|
8
8
|
import { POLLING } from "~/enum/polling";
|
|
9
|
-
import type { DefaultHookOptions } from "~/types";
|
|
9
|
+
import type { DefaultHookOptions } from "~/types/global";
|
|
10
10
|
import { useAllUserPools } from "./useAllUserPools";
|
|
11
11
|
|
|
12
12
|
export const usePoolsQueryKey = ({
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
import type { Token } from "~/types/dex";
|
|
4
|
+
import { computePriceImpact } from "~/utils/math";
|
|
5
|
+
import { useTokenPrices } from "../tokens/useTokenPrices";
|
|
6
|
+
|
|
7
|
+
export function usePriceImpact({
|
|
8
|
+
tokenIn,
|
|
9
|
+
tokenOut,
|
|
10
|
+
formattedAmountIn,
|
|
11
|
+
formattedAmountOut,
|
|
12
|
+
}: {
|
|
13
|
+
tokenIn: Token | undefined;
|
|
14
|
+
tokenOut: Token | undefined;
|
|
15
|
+
formattedAmountIn: string | undefined;
|
|
16
|
+
formattedAmountOut: string | undefined;
|
|
17
|
+
}) {
|
|
18
|
+
const { getTokenPrice, isLoading } = useTokenPrices({
|
|
19
|
+
tokens: tokenIn && tokenOut ? [tokenIn, tokenOut] : undefined,
|
|
20
|
+
});
|
|
21
|
+
const priceImpact = useMemo(() => {
|
|
22
|
+
if (!tokenIn || !tokenOut || !formattedAmountIn || !formattedAmountOut)
|
|
23
|
+
return undefined;
|
|
24
|
+
|
|
25
|
+
const tokenInPrice = getTokenPrice(tokenIn);
|
|
26
|
+
const tokenOutPrice = getTokenPrice(tokenOut);
|
|
27
|
+
|
|
28
|
+
if (!tokenInPrice || !tokenOutPrice) return null;
|
|
29
|
+
return computePriceImpact(
|
|
30
|
+
tokenInPrice.toString(),
|
|
31
|
+
tokenOutPrice.toString(),
|
|
32
|
+
formattedAmountIn,
|
|
33
|
+
formattedAmountOut,
|
|
34
|
+
);
|
|
35
|
+
}, [tokenIn, tokenOut, formattedAmountIn, formattedAmountOut]);
|
|
36
|
+
return {
|
|
37
|
+
data: priceImpact,
|
|
38
|
+
isLoading,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import useSWR, { type SWRConfiguration } from "swr";
|
|
2
|
+
import { type Address, type PublicClient, parseUnits, zeroAddress } from "viem";
|
|
3
|
+
|
|
4
|
+
import { useBeraWallet, usePublicClient } from "@berachain/wagmi/hooks";
|
|
5
|
+
|
|
6
|
+
import { BaseAggregator } from "~/actions/dex/aggregators/base";
|
|
7
|
+
import { useBeraFlag } from "~/contexts/BeraFlags/BeraFlags";
|
|
8
|
+
import type {
|
|
9
|
+
HoneyConfigContextReturn,
|
|
10
|
+
TokenWithOrder,
|
|
11
|
+
} from "~/contexts/HoneyConfigProvider";
|
|
12
|
+
import { Aggregators, type SwapReferrer } from "~/enum/dex";
|
|
13
|
+
import { POLLING } from "~/enum/polling";
|
|
14
|
+
import { BeraError } from "~/errors/BeraError";
|
|
15
|
+
import { RequestError } from "~/errors/RequestError";
|
|
16
|
+
import { useAggregatorsRouterFeeBps } from "~/hooks/dex/useAggregatorsRouterFeeBps";
|
|
17
|
+
import type { MinimalERC20 } from "~/types/dex";
|
|
18
|
+
import type { DefaultHookOptions } from "~/types/global";
|
|
19
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
20
|
+
import { seconds } from "~/utils/time";
|
|
21
|
+
import { isToken } from "~/utils/tokens";
|
|
22
|
+
|
|
23
|
+
export type IUseAggregatorsQuotesArgs = BeraJS.BaseFunctionArgs & {
|
|
24
|
+
tokenIn: MinimalERC20;
|
|
25
|
+
tokenOut: MinimalERC20;
|
|
26
|
+
amount: string;
|
|
27
|
+
slippage: number;
|
|
28
|
+
referrer?: SwapReferrer;
|
|
29
|
+
rewardVault?: Address;
|
|
30
|
+
/**
|
|
31
|
+
* Useful cause the collaterals are provided byt he honeyContext and this way we can
|
|
32
|
+
* use the Provider only in the swap page where is needed.
|
|
33
|
+
*
|
|
34
|
+
* The collaterals for the honey mint/redeem aggregator.
|
|
35
|
+
*/
|
|
36
|
+
honeyNativeState?: Pick<
|
|
37
|
+
HoneyConfigContextReturn,
|
|
38
|
+
"collateralList" | "protocol"
|
|
39
|
+
>;
|
|
40
|
+
underlyingToken?: MinimalERC20 | null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type IQueryKey = readonly [
|
|
44
|
+
string, // "useAggregatorsQuotes
|
|
45
|
+
string, // name
|
|
46
|
+
MinimalERC20, // tokenIn
|
|
47
|
+
MinimalERC20, // tokenOut
|
|
48
|
+
string, // parsedAmount
|
|
49
|
+
number, // slippage
|
|
50
|
+
Address | undefined, // account
|
|
51
|
+
number | undefined, // feeBps
|
|
52
|
+
SwapReferrer | undefined, // referrer
|
|
53
|
+
Address | undefined, // rewardVault
|
|
54
|
+
MinimalERC20 | null | undefined, // underlyingToken
|
|
55
|
+
TokenWithOrder[] | undefined, // collateralList
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
export const USE_AGGREGATORS_QUOTES_QUERY_KEY = "useAggregatorsQuotes";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Builds the SWR cache key for a single aggregator quote request.
|
|
62
|
+
* Returns `null` (disabling the query) when the aggregator is unsupported,
|
|
63
|
+
* disabled via config flags, or missing required dependencies like feeBps.
|
|
64
|
+
*/
|
|
65
|
+
function getQueryKey({
|
|
66
|
+
aggregator,
|
|
67
|
+
account,
|
|
68
|
+
args,
|
|
69
|
+
feeBps,
|
|
70
|
+
options,
|
|
71
|
+
activeAggregators,
|
|
72
|
+
isMAEnabled,
|
|
73
|
+
}: {
|
|
74
|
+
aggregator: BaseAggregator;
|
|
75
|
+
account: Address | undefined;
|
|
76
|
+
args: IUseAggregatorsQuotesArgs;
|
|
77
|
+
feeBps: number | undefined;
|
|
78
|
+
options?: DefaultHookOptions;
|
|
79
|
+
/**
|
|
80
|
+
* List of active aggregators fetched from edge config flags.
|
|
81
|
+
*
|
|
82
|
+
* If undefined, all aggregators are enabled.
|
|
83
|
+
*/
|
|
84
|
+
activeAggregators: string[] | undefined;
|
|
85
|
+
isMAEnabled: boolean;
|
|
86
|
+
}): IQueryKey | null {
|
|
87
|
+
if (options?.opts?.isEnabled !== undefined && !options?.opts?.isEnabled) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!Number(args.amount)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
!aggregator.checkChainSupport({
|
|
96
|
+
tokenIn: args.tokenIn,
|
|
97
|
+
tokenOut: args.tokenOut,
|
|
98
|
+
underlyingToken: args.underlyingToken,
|
|
99
|
+
honeyNativeState: args.honeyNativeState,
|
|
100
|
+
})
|
|
101
|
+
) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const name = aggregator.name;
|
|
106
|
+
|
|
107
|
+
const usesMAContract = ![
|
|
108
|
+
Aggregators.HubPools,
|
|
109
|
+
Aggregators.Honey,
|
|
110
|
+
Aggregators.Wrap,
|
|
111
|
+
Aggregators.Unwrap,
|
|
112
|
+
Aggregators.ERC4626,
|
|
113
|
+
].includes(name);
|
|
114
|
+
|
|
115
|
+
if (!isMAEnabled && usesMAContract) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const { tokenIn, tokenOut, amount, slippage, referrer, rewardVault } = args;
|
|
119
|
+
|
|
120
|
+
const parsedAmount = parseUnits(amount, tokenIn.decimals).toString();
|
|
121
|
+
|
|
122
|
+
const isEnabledOnConfig =
|
|
123
|
+
// always enable wrap and unwrap
|
|
124
|
+
aggregator.name === Aggregators.Wrap ||
|
|
125
|
+
aggregator.name === Aggregators.RedeemBgt ||
|
|
126
|
+
aggregator.name === Aggregators.Honey ||
|
|
127
|
+
!activeAggregators ||
|
|
128
|
+
activeAggregators.includes(name.toLowerCase().replaceAll(" ", ""));
|
|
129
|
+
|
|
130
|
+
if (!isEnabledOnConfig) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (
|
|
134
|
+
aggregator.name === Aggregators.Honey &&
|
|
135
|
+
args.honeyNativeState?.protocol.isPaused
|
|
136
|
+
) {
|
|
137
|
+
// if the honey protocol is paused, don't query any quotes
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const needsUnderlyingToken =
|
|
142
|
+
aggregator.name === Aggregators.ERC4626 ||
|
|
143
|
+
aggregator.name === Aggregators.EnsoErc4626;
|
|
144
|
+
|
|
145
|
+
if (usesMAContract && feeBps === undefined) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return [
|
|
150
|
+
USE_AGGREGATORS_QUOTES_QUERY_KEY,
|
|
151
|
+
name,
|
|
152
|
+
tokenIn,
|
|
153
|
+
tokenOut,
|
|
154
|
+
parsedAmount,
|
|
155
|
+
slippage,
|
|
156
|
+
aggregator.needsAccountForQuote ? account : undefined,
|
|
157
|
+
usesMAContract ? feeBps : 0,
|
|
158
|
+
referrer,
|
|
159
|
+
rewardVault,
|
|
160
|
+
needsUnderlyingToken ? args.underlyingToken : undefined,
|
|
161
|
+
aggregator.name === Aggregators.Honey
|
|
162
|
+
? args.honeyNativeState?.collateralList
|
|
163
|
+
: undefined,
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Creates the SWR fetcher that calls `aggregator.getQuote()` with
|
|
169
|
+
* the parameters extracted from the query key tuple.
|
|
170
|
+
*/
|
|
171
|
+
function getQueryFn({
|
|
172
|
+
aggregator,
|
|
173
|
+
publicClient,
|
|
174
|
+
proxyAggregatorsThroughVercel,
|
|
175
|
+
}: {
|
|
176
|
+
aggregator: BaseAggregator;
|
|
177
|
+
publicClient?: PublicClient;
|
|
178
|
+
proxyAggregatorsThroughVercel?: boolean;
|
|
179
|
+
}) {
|
|
180
|
+
return async ([
|
|
181
|
+
,
|
|
182
|
+
,
|
|
183
|
+
tokenIn,
|
|
184
|
+
tokenOut,
|
|
185
|
+
amount,
|
|
186
|
+
slippage,
|
|
187
|
+
account,
|
|
188
|
+
aggregatorsFeeBps,
|
|
189
|
+
referrer,
|
|
190
|
+
rewardVault,
|
|
191
|
+
underlyingToken,
|
|
192
|
+
honeyCollaterals,
|
|
193
|
+
]: IQueryKey) =>
|
|
194
|
+
aggregator.getQuote({
|
|
195
|
+
tokenIn,
|
|
196
|
+
tokenOut,
|
|
197
|
+
amount,
|
|
198
|
+
slippage,
|
|
199
|
+
account,
|
|
200
|
+
aggregatorsFeeBps,
|
|
201
|
+
publicClient,
|
|
202
|
+
proxyAggregatorsThroughVercel,
|
|
203
|
+
referrer,
|
|
204
|
+
rewardVault,
|
|
205
|
+
underlyingToken,
|
|
206
|
+
honeyNativeState: {
|
|
207
|
+
collateralList: honeyCollaterals ?? [],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* this hook is used internally to avoid caling the same hook and checks
|
|
214
|
+
* on every useSingleAggregatorQuote call, when called inside useAggregatorsQuotes.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
export function raw_useSingleAggregatorQuote(
|
|
219
|
+
{
|
|
220
|
+
feeBps,
|
|
221
|
+
publicClient,
|
|
222
|
+
account,
|
|
223
|
+
proxyAggregatorsThroughVercel,
|
|
224
|
+
activeAggregators,
|
|
225
|
+
isMAEnabled,
|
|
226
|
+
...args
|
|
227
|
+
}: IUseAggregatorsQuotesArgs & {
|
|
228
|
+
account: Address | undefined;
|
|
229
|
+
aggregator: BaseAggregator;
|
|
230
|
+
feeBps: number | undefined;
|
|
231
|
+
activeAggregators: string[] | undefined;
|
|
232
|
+
isMAEnabled: boolean;
|
|
233
|
+
publicClient: PublicClient | undefined;
|
|
234
|
+
proxyAggregatorsThroughVercel: boolean | undefined;
|
|
235
|
+
},
|
|
236
|
+
options?: DefaultHookOptions,
|
|
237
|
+
) {
|
|
238
|
+
// we're using independent useSWRs so we can show quotes as they come
|
|
239
|
+
// instead of waiting for all of them to load
|
|
240
|
+
return useSWR(
|
|
241
|
+
getQueryKey({
|
|
242
|
+
aggregator: args.aggregator,
|
|
243
|
+
account,
|
|
244
|
+
args,
|
|
245
|
+
feeBps,
|
|
246
|
+
options,
|
|
247
|
+
activeAggregators,
|
|
248
|
+
isMAEnabled,
|
|
249
|
+
}),
|
|
250
|
+
getQueryFn({
|
|
251
|
+
aggregator: args.aggregator,
|
|
252
|
+
proxyAggregatorsThroughVercel,
|
|
253
|
+
publicClient,
|
|
254
|
+
}),
|
|
255
|
+
options?.opts,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Returns shared SWR options for aggregator quote polling, including
|
|
261
|
+
* custom error retry logic that stops retrying on "path not found" and 403 errors.
|
|
262
|
+
*/
|
|
263
|
+
export function getAggregatorsSWROptions(
|
|
264
|
+
options?: DefaultHookOptions,
|
|
265
|
+
): SWRConfiguration {
|
|
266
|
+
return {
|
|
267
|
+
refreshInterval: POLLING.FAST, // every 10s
|
|
268
|
+
errorRetryCount: 3,
|
|
269
|
+
...options?.opts,
|
|
270
|
+
// biome-ignore lint/nursery/useMaxParams: the function is defined in the SWRConfiguration type
|
|
271
|
+
onErrorRetry(err, key, config, revalidate, revalidateOpts) {
|
|
272
|
+
options?.opts?.onErrorRetry?.(
|
|
273
|
+
err,
|
|
274
|
+
key,
|
|
275
|
+
config,
|
|
276
|
+
revalidate,
|
|
277
|
+
revalidateOpts,
|
|
278
|
+
);
|
|
279
|
+
if (err instanceof BeraError) {
|
|
280
|
+
if (err.reason === BaseAggregator.PATH_NOT_FOUND_REASON) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (err instanceof RequestError && err.statusCode === 403) {
|
|
286
|
+
console.warn(key[1], "returned error 403, stopping retries");
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (revalidateOpts.retryCount > (config.errorRetryCount ?? 3)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
revalidate();
|
|
296
|
+
}, config.errorRetryInterval ?? seconds(10));
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Standalone hook for fetching a quote from a single aggregator.
|
|
303
|
+
* Resolves wallet, fee, and feature flag context internally — use this
|
|
304
|
+
* when you need a quote outside of the `useAggregatorsQuotes` multi-quote flow.
|
|
305
|
+
*/
|
|
306
|
+
export function useSingleAggregatorQuote(
|
|
307
|
+
args: IUseAggregatorsQuotesArgs & { aggregator: BaseAggregator },
|
|
308
|
+
options?: DefaultHookOptions,
|
|
309
|
+
) {
|
|
310
|
+
const { address: account } = useBeraWallet();
|
|
311
|
+
const proxyAggregatorsThroughVercel = useBeraFlag(
|
|
312
|
+
"proxyAggregatorsThroughVercel",
|
|
313
|
+
);
|
|
314
|
+
const activeAggregators = useBeraFlag("aggregators");
|
|
315
|
+
const publicClient = usePublicClient();
|
|
316
|
+
|
|
317
|
+
const { data: feeBps } = useAggregatorsRouterFeeBps();
|
|
318
|
+
|
|
319
|
+
if (args.aggregator.name !== Aggregators.Wrap) {
|
|
320
|
+
const isWrapOrUnwrap =
|
|
321
|
+
(isToken(args.tokenIn.address, "BERA") ||
|
|
322
|
+
isToken(args.tokenIn.address, "WBERA")) &&
|
|
323
|
+
(isToken(args.tokenOut.address, "BERA") ||
|
|
324
|
+
isToken(args.tokenOut.address, "WBERA"));
|
|
325
|
+
|
|
326
|
+
if (!isWrapOrUnwrap) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const { config } = parseBaseArgs(args);
|
|
332
|
+
|
|
333
|
+
const isMAEnabled = config.bex.aggregatorsRouter !== zeroAddress;
|
|
334
|
+
|
|
335
|
+
// we're using independent useSWRs so we can show quotes as they come
|
|
336
|
+
// instead of waiting for all of them to load
|
|
337
|
+
return raw_useSingleAggregatorQuote(
|
|
338
|
+
{
|
|
339
|
+
...args,
|
|
340
|
+
aggregator: args.aggregator,
|
|
341
|
+
feeBps,
|
|
342
|
+
activeAggregators,
|
|
343
|
+
account,
|
|
344
|
+
isMAEnabled,
|
|
345
|
+
publicClient,
|
|
346
|
+
proxyAggregatorsThroughVercel,
|
|
347
|
+
},
|
|
348
|
+
{ ...options, opts: getAggregatorsSWROptions(options) },
|
|
349
|
+
);
|
|
350
|
+
}
|