@berachain/berajs 0.2.4 → 0.2.6-patch.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/README.md +0 -0
- package/dist/abi/exports.cjs +1 -1
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/abi/exports.d.cts +17 -1
- package/dist/abi/exports.d.ts +17 -1
- package/dist/abi/exports.mjs +1 -1
- package/dist/abi/exports.mjs.map +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +9 -38
- package/dist/actions/exports.d.ts +9 -38
- package/dist/actions/exports.mjs +1 -1
- package/dist/actions/exports.mjs.map +1 -1
- package/dist/chunk-2YBHAMDV.cjs +2 -0
- package/dist/chunk-2YBHAMDV.cjs.map +1 -0
- package/dist/chunk-57RINXU6.cjs +2 -0
- package/dist/chunk-57RINXU6.cjs.map +1 -0
- package/dist/{chunk-AX2YQQFQ.mjs → chunk-74QD4JAH.mjs} +2 -2
- package/dist/chunk-74QD4JAH.mjs.map +1 -0
- package/dist/chunk-74WA35RI.cjs +2 -0
- package/dist/chunk-74WA35RI.cjs.map +1 -0
- package/dist/{chunk-7WRTK7RJ.mjs → chunk-BEKH5EYT.mjs} +2 -2
- package/dist/chunk-BEKH5EYT.mjs.map +1 -0
- package/dist/{chunk-FCWDGE62.cjs → chunk-CF3LFNXG.cjs} +2 -2
- package/dist/chunk-CF3LFNXG.cjs.map +1 -0
- package/dist/chunk-COMMLZ3O.mjs +2 -0
- package/dist/chunk-COMMLZ3O.mjs.map +1 -0
- package/dist/chunk-DDEQFR3M.cjs +2 -0
- package/dist/chunk-DDEQFR3M.cjs.map +1 -0
- package/dist/{chunk-6LDOG5RL.cjs → chunk-DK42F2ZM.cjs} +2 -2
- package/dist/chunk-DK42F2ZM.cjs.map +1 -0
- package/dist/{chunk-7SMWQ6SN.mjs → chunk-FM3WDBFH.mjs} +2 -2
- package/dist/chunk-FM3WDBFH.mjs.map +1 -0
- package/dist/chunk-HWOGQSNL.cjs +4 -0
- package/dist/chunk-HWOGQSNL.cjs.map +1 -0
- package/dist/chunk-I7M43BB4.cjs +2 -0
- package/dist/chunk-I7M43BB4.cjs.map +1 -0
- package/dist/chunk-IBJOI5SN.mjs +4 -0
- package/dist/chunk-IBJOI5SN.mjs.map +1 -0
- package/dist/chunk-IDFMLLDY.mjs +2 -0
- package/dist/chunk-IDFMLLDY.mjs.map +1 -0
- package/dist/{chunk-YZV5LKIP.cjs → chunk-LNVR4BW6.cjs} +2 -2
- package/dist/chunk-LNVR4BW6.cjs.map +1 -0
- package/dist/chunk-MJZHJFZO.mjs +2 -0
- package/dist/{chunk-YNO7BCCM.mjs.map → chunk-MJZHJFZO.mjs.map} +1 -1
- package/dist/chunk-MK5NS5B5.mjs +2 -0
- package/dist/chunk-MK5NS5B5.mjs.map +1 -0
- package/dist/{chunk-C6ZGUO4H.cjs → chunk-NMH7LHPW.cjs} +2 -2
- package/dist/chunk-NMH7LHPW.cjs.map +1 -0
- package/dist/chunk-NVHV2LDK.cjs +2 -0
- package/dist/chunk-NVHV2LDK.cjs.map +1 -0
- package/dist/chunk-OGBD5YOG.mjs +2 -0
- package/dist/chunk-OGBD5YOG.mjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-OUD27MU7.cjs.map +1 -1
- package/dist/chunk-PLIH6KQM.mjs +2 -0
- package/dist/chunk-PLIH6KQM.mjs.map +1 -0
- package/dist/chunk-QRAIGQF2.mjs +2 -0
- package/dist/chunk-QRAIGQF2.mjs.map +1 -0
- package/dist/chunk-RWOICHRW.cjs +2 -0
- package/dist/chunk-RWOICHRW.cjs.map +1 -0
- package/dist/chunk-T5FSQ3YE.mjs +2 -0
- package/dist/chunk-T5FSQ3YE.mjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/contexts/exports.cjs +1 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/contexts/exports.d.cts +1 -1
- package/dist/contexts/exports.d.ts +1 -1
- package/dist/contexts/exports.mjs +1 -1
- package/dist/contexts/exports.mjs.map +1 -1
- package/dist/{defaultFlags-d0kPbT0i.d.cts → defaultFlags-D6KfkTZx.d.cts} +1 -1
- package/dist/{defaultFlags-d0kPbT0i.d.ts → defaultFlags-D6KfkTZx.d.ts} +1 -1
- package/dist/enum/exports.cjs +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/exports.d.cts +1 -1
- package/dist/enum/exports.d.ts +1 -1
- package/dist/enum/exports.mjs +1 -1
- package/dist/errors/exports.cjs +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.d.cts +8 -3
- package/dist/errors/exports.d.ts +8 -3
- package/dist/errors/exports.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-DZgrPmZ2.d.cts → getValidatorQueuedOperatorAddress-BdDYHycN.d.cts} +15 -4
- package/dist/{getValidatorQueuedOperatorAddress-CqR6cyqC.d.ts → getValidatorQueuedOperatorAddress-CmiPJmsr.d.ts} +15 -4
- package/dist/{global.d-BeYWDreg.d.ts → global.d-3GQMgC9k.d.ts} +1 -1
- package/dist/{global.d-DghRxpHd.d.cts → global.d-CwT1Phzf.d.cts} +1 -1
- package/dist/hooks/exports.cjs +3 -3
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +54 -75
- package/dist/hooks/exports.d.ts +54 -75
- package/dist/hooks/exports.mjs +3 -3
- package/dist/hooks/exports.mjs.map +1 -1
- package/dist/{txnEnum-DxPRHSJt.d.cts → txnEnum-CCuQUFlh.d.cts} +7 -0
- package/dist/{txnEnum-DxPRHSJt.d.ts → txnEnum-CCuQUFlh.d.ts} +7 -0
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +37 -4
- package/dist/types/exports.d.ts +37 -4
- package/dist/utils/exports.cjs +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.d.cts +2 -2
- package/dist/utils/exports.d.ts +2 -2
- package/dist/utils/exports.mjs +1 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +25 -25
- package/src/abi/enso/ensoWalletV2Factory.ts +9 -0
- package/src/abi/exports.ts +1 -0
- package/src/abi/pyth/pyth.ts +0 -0
- package/src/actions/clients/BeraApolloClient.ts +3 -3
- package/src/actions/clients/getApolloClient.ts +5 -5
- package/src/actions/clients/getEnsoClient.ts +1 -1
- package/src/actions/dex/__tests__/aggregators.unit.test.ts +3 -3
- package/src/actions/dex/__tests__/getOnChainPool.unit.test.ts +1 -1
- package/src/actions/dex/aggregators/base.ts +12 -8
- package/src/actions/dex/aggregators/bex.ts +8 -8
- package/src/actions/dex/aggregators/bgt.ts +4 -4
- package/src/actions/dex/aggregators/enso/enso.ts +28 -20
- package/src/actions/dex/aggregators/enso/ensoErc4626.debug.test.ts +1 -1
- package/src/actions/dex/aggregators/enso/ensoErc4626.ts +7 -4
- package/src/actions/dex/aggregators/erc4626.ts +10 -6
- package/src/actions/dex/aggregators/fly.ts +9 -5
- package/src/actions/dex/aggregators/haiku.integration.test.ts +3 -3
- package/src/actions/dex/aggregators/haiku.ts +9 -5
- package/src/actions/dex/aggregators/honey.ts +15 -15
- package/src/actions/dex/aggregators/kyberswap.ts +8 -4
- package/src/actions/dex/aggregators/oogabooga.ts +8 -4
- package/src/actions/dex/aggregators/openOcean.ts +12 -8
- package/src/actions/dex/aggregators/wbera.ts +8 -4
- package/src/actions/dex/b-sdk.ts +2 -2
- package/src/actions/dex/getAllPools.ts +2 -2
- package/src/actions/dex/getApiPool.ts +2 -2
- package/src/actions/dex/getGlobalLiquidityAndSwapVolume.ts +2 -2
- package/src/actions/dex/getIsTokenExploited.ts +1 -1
- package/src/actions/dex/getOnChainPool.ts +3 -3
- package/src/actions/dex/getPoolEvents.ts +2 -2
- package/src/actions/dex/getPoolHistoricalData.ts +2 -2
- package/src/actions/dex/getVaultPausedState.ts +1 -1
- package/src/actions/enso/__tests__/getBendDemultiplyBundle.action.unit.test.ts +175 -0
- package/src/actions/enso/__tests__/getBendDemultiplyBundle.unit.test.ts +150 -0
- package/src/actions/enso/__tests__/getBendMultiplyBundle.action.unit.test.ts +138 -0
- package/src/actions/enso/__tests__/getBendMultiplyBundle.unit.test.ts +194 -0
- package/src/actions/enso/{getEnsoUserTokensWithBalances.debug.test.ts → __tests__/getEnsoUserTokensWithBalances.debug.test.ts} +3 -3
- package/src/actions/enso/__tests__/helpers.ts +42 -0
- package/src/actions/enso/__tests__/util.unit.test.ts +95 -0
- package/src/actions/enso/flashloan.ts +127 -0
- package/src/actions/enso/getBendDemultiplyBundle.ts +325 -0
- package/src/actions/enso/getBendMultiplyBundle.ts +348 -0
- package/src/actions/enso/getEnsoSwapBundle.ts +2 -2
- package/src/actions/enso/getEnsoUserTokensWithBalances.ts +5 -5
- package/src/actions/enso/util.ts +150 -5
- package/src/actions/exports.ts +0 -2
- package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +2 -2
- package/src/actions/governance/__tests__/getDecodedFunctionData.integration.test.ts +2 -2
- package/src/actions/governance/__tests__/getQuorum.integration.test.ts +2 -2
- package/src/actions/governance/checkProposalField.ts +1 -1
- package/src/actions/governance/computeActualStatus.ts +1 -1
- package/src/actions/governance/getAllProposals.ts +1 -1
- package/src/actions/governance/getBodyErrors.ts +1 -1
- package/src/actions/governance/getProposalDetails.ts +1 -1
- package/src/actions/governance/getProposalFromTx.ts +1 -1
- package/src/actions/governance/getProposalParams.ts +3 -3
- package/src/actions/governance/getProposalVotes.ts +1 -1
- package/src/actions/governance/getQuorum.ts +2 -2
- package/src/actions/honey/getCollateralWeights.ts +2 -2
- package/src/actions/honey/getGlobalCapLimit.ts +4 -4
- package/src/actions/honey/getHoneyCollaterals.ts +5 -5
- package/src/actions/honey/getHoneyFees.ts +1 -1
- package/src/actions/honey/getHoneyPausedState.ts +1 -1
- package/src/actions/honey/getHoneyPreview.ts +3 -3
- package/src/actions/honey/getHoneyRootPriceOracle.ts +1 -1
- package/src/actions/honey/getHoneyVaultsBalance.ts +2 -2
- package/src/actions/honey/getRelativeCapLimit.ts +3 -3
- package/src/actions/honey/getSharesWithoutFees.ts +1 -1
- package/src/actions/honey/getSwapPayload.ts +6 -6
- package/src/actions/honey/isBadCollateralAsset.ts +2 -2
- package/src/actions/honey/isBasketModeEnabled.ts +2 -2
- package/src/actions/honey/tests/pyth.integration.test.ts +3 -3
- package/src/actions/misc/getBlockTimestamp.ts +2 -2
- package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +2 -2
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
- package/src/actions/pol/getBGTGlobalInfo.ts +2 -2
- package/src/actions/pol/getBgtAprSimulation.ts +1 -1
- package/src/actions/pol/getBgtAprSimultaion.unit.test.ts +1 -1
- package/src/actions/pol/getBgtTokenTotalBoosts.ts +2 -2
- package/src/actions/pol/getBgtTokenTotalSupply.ts +2 -2
- package/src/actions/pol/getBlockTime.debug.test.ts +13 -0
- package/src/actions/pol/getBlockTime.ts +14 -23
- package/src/actions/pol/getEarnedStakedBeraVault.ts +3 -3
- package/src/actions/pol/getGlobalCuttingBoard.ts +0 -0
- package/src/actions/pol/getGlobalData.ts +2 -2
- package/src/actions/pol/getIncentiveFeeClaimStats.ts +4 -4
- package/src/actions/pol/getLSTStakeConfig.ts +5 -5
- package/src/actions/pol/getMarkets.ts +2 -2
- package/src/actions/pol/getRewardProofsByValidator.ts +4 -4
- package/src/actions/pol/getRewardTokenToBeraRate.ts +1 -1
- package/src/actions/pol/getRewardVault.ts +3 -3
- package/src/actions/pol/getRewardVaultBeaconImplementation.integration.test.ts +1 -1
- package/src/actions/pol/getRewardVaultBeaconImplementation.ts +3 -3
- package/src/actions/pol/getRewardVaultDurationConstants.integration.test.ts +1 -1
- package/src/actions/pol/getRewardVaultDurationConstants.ts +1 -1
- package/src/actions/pol/getRewardVaultFromToken.ts +1 -1
- package/src/actions/pol/getRewardVaultIncentives.ts +2 -2
- package/src/actions/pol/getRewardVaultRewards.ts +1 -1
- package/src/actions/pol/getRewardVaults.ts +1 -1
- package/src/actions/pol/getSWBeraVaultMetadata.ts +20 -22
- package/src/actions/pol/getSWBeraWithdrawal.ts +4 -4
- package/src/actions/pol/getStakedBeraAPR.ts +2 -2
- package/src/actions/pol/getStakedBeraSnapshots.ts +2 -2
- package/src/actions/pol/getStakingDailyAssets.ts +3 -3
- package/src/actions/pol/getStakingTokenInformation.ts +2 -2
- package/src/actions/pol/getTotalStakedAmount.ts +1 -1
- package/src/actions/pol/getUserClaimableIncentives.ts +4 -4
- package/src/actions/pol/getUserVaultInfo.ts +1 -1
- package/src/actions/pol/getUserVaults.ts +4 -4
- package/src/actions/pol/getUserVaultsBalance.ts +1 -1
- package/src/actions/pol/getUserVaultsReward.ts +0 -0
- package/src/actions/pol/getVaultHistory.ts +2 -2
- package/src/actions/pol/getVaultValidators.ts +1 -1
- package/src/actions/pol/getVaultsSupply.ts +0 -0
- package/src/actions/prices/__tests__/prices.integration.test.ts +2 -2
- package/src/actions/prices/getTokenCurrentPrices.ts +5 -5
- package/src/actions/pyth/getHoneyPythFeeds.ts +2 -2
- package/src/actions/pyth/getUpdateFee.ts +2 -2
- package/src/actions/tokens/getAllowances.ts +2 -2
- package/src/actions/tokens/getTokenInformation.ts +2 -2
- package/src/actions/tokens/getTokens.ts +3 -3
- package/src/actions/tokens/getUnderlyingToken.ts +4 -4
- package/src/actions/tokens/getWalletBalances.integration.test.ts +1 -1
- package/src/actions/tokens/getWalletBalances.ts +4 -4
- package/src/actions/transactions/beraWriteContract.integration.test.ts +6 -6
- package/src/actions/transactions/beraWriteContract.ts +12 -12
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.integration.test.ts +1 -1
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.ts +1 -1
- package/src/actions/validators/getAllValidators.ts +2 -2
- package/src/actions/validators/getApiValidator.ts +2 -2
- package/src/actions/validators/getBaselineRewardAllocation.ts +1 -1
- package/src/actions/validators/getDailyValidatorBlockStats.ts +1 -1
- package/src/actions/validators/getDefaultRewardAllocation.ts +1 -1
- package/src/actions/validators/getUserActiveValidators.ts +31 -33
- package/src/actions/validators/getUserBoosts.ts +12 -8
- package/src/actions/validators/getUserBoostsOnValidator.ts +15 -3
- package/src/actions/validators/getUserStakingPositions.ts +1 -1
- package/src/actions/validators/getValidatorAnalytics.ts +2 -2
- package/src/actions/validators/getValidatorCommission.ts +1 -1
- package/src/actions/validators/getValidatorEstimatedBgtPerYear.ts +1 -1
- package/src/actions/validators/getValidatorOperatorAddress.ts +1 -1
- package/src/actions/validators/getValidatorQueuedCommission.ts +1 -1
- package/src/actions/validators/getValidatorQueuedOperatorAddress.ts +1 -1
- package/src/actions/validators/getValidatorQueuedRewardAllocation.ts +1 -1
- package/src/actions/validators/getValidatorRewardAllocation.ts +1 -1
- package/src/actions/validators/getValidatorRewardAllocatorAddress.ts +1 -1
- package/src/actions/validators/utils/__tests__/validatorUtils.integration.test.ts +4 -4
- package/src/contexts/BeraFlags/defaultFlags.ts +4 -0
- package/src/contexts/BexStatusProvider.tsx +1 -1
- package/src/contexts/HoneyConfigProvider.tsx +3 -3
- package/src/contexts/SwrFallback.tsx +2 -2
- package/src/contexts/TokensProvider.tsx +3 -3
- package/src/contexts/block-time-provider.tsx +1 -1
- package/src/contexts/exports.ts +0 -0
- package/src/data/contracts.ts +10 -0
- package/src/enum/exports.ts +0 -0
- package/src/enum/polling.ts +0 -0
- package/src/enum/txnEnum.ts +9 -0
- package/src/errors/BeraMonitoring.ts +2 -2
- package/src/errors/BeraTracing.ts +2 -2
- package/src/errors/RequestError.ts +1 -1
- package/src/errors/assert.ts +18 -0
- package/src/errors/getErrorMessage.ts +0 -0
- package/src/errors/getRevertReason.integration.test.ts +7 -7
- package/src/errors/getRevertReason.ts +1 -1
- package/src/errors/parseViemError.ts +1 -1
- package/src/hooks/bend/useGetConvertToAssets.ts +4 -4
- package/src/hooks/dex/useAggregatorsQuotes.ts +19 -19
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +2 -2
- package/src/hooks/dex/useAllUserPools.ts +3 -3
- package/src/hooks/dex/useApiPool.ts +3 -3
- package/src/hooks/dex/useBexStatus.ts +1 -1
- package/src/hooks/dex/useCreatePool.ts +9 -9
- package/src/hooks/dex/useExploitedTokens.ts +3 -3
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +1 -1
- package/src/hooks/dex/useLiquidityMismatch.ts +3 -3
- package/src/hooks/dex/useLpPosition.ts +7 -4
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +4 -4
- package/src/hooks/dex/useOnChainPoolData.ts +3 -3
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +3 -3
- package/src/hooks/dex/usePool.ts +7 -40
- package/src/hooks/dex/usePoolEvents.ts +2 -2
- package/src/hooks/dex/usePoolHistoricalData.ts +6 -3
- package/src/hooks/dex/usePools.ts +3 -3
- package/src/hooks/dex/usePriceImpact.ts +2 -2
- package/src/hooks/dex/useSingleAggregatorQuote.ts +13 -13
- package/src/hooks/enso/useBendDemultiply.ts +158 -0
- package/src/hooks/enso/useBendMultiply.ts +163 -0
- package/src/hooks/enso/useBendZapSupply.ts +7 -7
- package/src/hooks/enso/useEnsoSwapBundle.ts +6 -6
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +5 -5
- package/src/hooks/enso/useEnsoWalletV2Address.ts +38 -0
- package/src/hooks/enso/useIsBendAuthorized.ts +47 -0
- package/src/hooks/enso/useZapStakeBera.ts +4 -4
- package/src/hooks/exports.ts +4 -3
- package/src/hooks/governance/useCreateProposal.ts +3 -3
- package/src/hooks/governance/useGetPastVotes.ts +2 -2
- package/src/hooks/governance/useHasVoted.ts +2 -2
- package/src/hooks/governance/useIsCanceller.ts +4 -4
- package/src/hooks/governance/usePollAllProposals.ts +3 -3
- package/src/hooks/governance/usePollProposal.ts +7 -4
- package/src/hooks/governance/usePollProposalThreshold.ts +3 -3
- package/src/hooks/governance/usePollProposalVotes.ts +1 -1
- package/src/hooks/governance/usePollUserDelegates.ts +7 -4
- package/src/hooks/governance/useProposalFromTx.ts +1 -1
- package/src/hooks/governance/useProposalSnapshot.ts +2 -2
- package/src/hooks/governance/useProposalState.ts +2 -2
- package/src/hooks/governance/useProposalTimelockState.ts +2 -2
- package/src/hooks/governance/useQuorum.ts +1 -1
- package/src/hooks/honey/useCappedGlobally.ts +8 -5
- package/src/hooks/honey/useCappedRelatively.ts +7 -4
- package/src/hooks/honey/useCollateralWeights.ts +8 -5
- package/src/hooks/honey/useHoneyAlerts.ts +5 -5
- package/src/hooks/honey/useHoneyBalances.ts +7 -7
- package/src/hooks/honey/useHoneyChartData.ts +1 -1
- package/src/hooks/honey/useHoneySwapState.ts +4 -4
- package/src/hooks/honey/useHoneyVaultsBalance.ts +8 -5
- package/src/hooks/honey/useIsBadCollateralAsset.ts +9 -6
- package/src/hooks/honey/useIsBasketModeEnabled.ts +8 -5
- package/src/hooks/honey/usePythLatestPrices.ts +4 -4
- package/src/hooks/perps/usePythUpdateFee.ts +4 -4
- package/src/hooks/pol/useBgtAprSimulation.ts +1 -1
- package/src/hooks/pol/useBgtUnstakedBalance.ts +7 -4
- package/src/hooks/pol/useClaimableFees.ts +4 -4
- package/src/hooks/pol/useOnChainRewardVault.ts +7 -7
- package/src/hooks/pol/usePollGlobalData.ts +9 -3
- package/src/hooks/pol/usePollMarkets.ts +5 -2
- package/src/hooks/pol/useQueuedBeraUnlock.ts +4 -4
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +4 -4
- package/src/hooks/pol/useRewardVault.ts +5 -2
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +2 -2
- package/src/hooks/pol/useRewardVaultFromToken.ts +2 -2
- package/src/hooks/pol/useRewardVaultIncentives.ts +2 -2
- package/src/hooks/pol/useRewardVaultRewards.ts +3 -3
- package/src/hooks/pol/useRewardVaults.ts +2 -2
- package/src/hooks/pol/useStakedAPR.ts +3 -3
- package/src/hooks/pol/useStakedData.ts +10 -10
- package/src/hooks/pol/useStakedSnapshots.ts +3 -3
- package/src/hooks/pol/useStakingVaultsMetadata.ts +40 -0
- package/src/hooks/pol/useTotalStakedAmount.ts +2 -2
- package/src/hooks/pol/useUserVaultInfo.ts +8 -5
- package/src/hooks/pol/useUserVaults.ts +7 -4
- package/src/hooks/pol/useVaultAddress.ts +2 -2
- package/src/hooks/pol/useVaultHistory.ts +2 -2
- package/src/hooks/pol/useVaultValidators.ts +5 -2
- package/src/hooks/tokens/useBeraCurrentPrice.ts +1 -1
- package/src/hooks/tokens/useMultipleTokenInformation.ts +7 -4
- package/src/hooks/tokens/usePollAllowances.ts +7 -4
- package/src/hooks/tokens/usePollBalance.ts +8 -5
- package/src/hooks/tokens/usePollWalletBalances.ts +8 -5
- package/src/hooks/tokens/useStakingTokenInformation.ts +7 -4
- package/src/hooks/tokens/useTokenCurrentPrice.ts +1 -1
- package/src/hooks/tokens/useTokenCurrentPrices.ts +6 -6
- package/src/hooks/tokens/useTokenInformation.ts +8 -5
- package/src/hooks/tokens/useTokenPrice.ts +1 -1
- package/src/hooks/tokens/useTokenPrices.ts +4 -4
- package/src/hooks/tokens/useTokens.ts +3 -3
- package/src/hooks/tokens/useTotalSupply.ts +1 -1
- package/src/hooks/tokens/useUnderlyingAsset.ts +3 -3
- package/src/hooks/useBlockToTimestamp.ts +5 -5
- package/src/hooks/useContractWrite/index.ts +0 -0
- package/src/hooks/useContractWrite/stateReducer.ts +0 -0
- package/src/hooks/useContractWrite/types.ts +2 -2
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +5 -6
- package/src/hooks/useGetVerifiedAbi.ts +1 -1
- package/src/hooks/usePrevious.ts +0 -0
- package/src/hooks/validators/useAllValidators.ts +7 -4
- package/src/hooks/validators/useApiEnrichedAllocation.ts +2 -2
- package/src/hooks/validators/useApiValidator.ts +5 -2
- package/src/hooks/validators/useBaselineRewardAllocation.ts +2 -2
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +3 -3
- package/src/hooks/validators/useDefaultRewardAllocation.ts +4 -4
- package/src/hooks/validators/useManagedValidatorRole.ts +8 -5
- package/src/hooks/validators/useOnChainValidator.ts +6 -3
- package/src/hooks/validators/useStakingPoolBatch.ts +7 -4
- package/src/hooks/validators/useUserActiveValidators.ts +6 -3
- package/src/hooks/validators/useUserBoostsOnValidator.ts +3 -3
- package/src/hooks/validators/useUserClaimableIncentives.ts +9 -9
- package/src/hooks/validators/useUserStakingPositions.ts +1 -1
- package/src/hooks/validators/useValidator.ts +1 -1
- package/src/hooks/validators/useValidatorAnalytics.ts +3 -3
- package/src/hooks/validators/useValidatorCommission.ts +5 -2
- package/src/hooks/validators/useValidatorEstimatedBgtPerYear.ts +3 -3
- package/src/hooks/validators/useValidatorQueuedCommission.ts +6 -3
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +5 -2
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +6 -3
- package/src/hooks/validators/useValidatorRewardAllocation.ts +2 -2
- package/src/types/dex.d.ts +1 -1
- package/src/types/enso.d.ts +34 -0
- package/src/types/exports.ts +0 -0
- package/src/types/global.d.ts +3 -3
- package/src/types/governance.d.ts +1 -1
- package/src/types/honeySwap.d.ts +3 -3
- package/src/types/staking.d.ts +0 -0
- package/src/utils/beraFetch.ts +1 -1
- package/src/utils/createEmitter.ts +1 -1
- package/src/utils/exports.ts +0 -0
- package/src/utils/filter.ts +0 -0
- package/src/utils/formatIncentivesTokenMap.ts +1 -1
- package/src/utils/formatInputTokenValue.ts +0 -0
- package/src/utils/formatNumber.ts +0 -0
- package/src/utils/getContractName.ts +1 -1
- package/src/utils/getHoneySwapMessage.test.ts +1 -1
- package/src/utils/getHoneySwapMessage.ts +1 -1
- package/src/utils/parseBaseArgs.ts +1 -1
- package/src/utils/parseBaseArgs.unit.test.ts +1 -1
- package/src/utils/parseWhiskToken.ts +1 -1
- package/src/utils/poolNamings.ts +1 -1
- package/src/utils/tokens.ts +2 -2
- package/src/utils/tokens.unit.test.ts +1 -1
- package/src/utils/truncateHash.ts +0 -0
- package/.claude/skills/berajs/SKILL.md +0 -222
- package/.claude/skills/berajs/references/dex.md +0 -235
- package/.claude/skills/berajs/references/pol.md +0 -194
- package/.claude/skills/berajs/references/staking.md +0 -198
- package/.claude/skills/berajs/references/tokens.md +0 -170
- package/LICENSE +0 -21
- package/dist/chunk-22J3YJDN.cjs +0 -2
- package/dist/chunk-22J3YJDN.cjs.map +0 -1
- package/dist/chunk-2LL3P5PN.mjs +0 -2
- package/dist/chunk-2LL3P5PN.mjs.map +0 -1
- package/dist/chunk-4GU2O2OW.cjs +0 -4
- package/dist/chunk-4GU2O2OW.cjs.map +0 -1
- package/dist/chunk-55L7STYD.mjs +0 -2
- package/dist/chunk-55L7STYD.mjs.map +0 -1
- package/dist/chunk-5XWELBWR.mjs +0 -2
- package/dist/chunk-5XWELBWR.mjs.map +0 -1
- package/dist/chunk-6LDOG5RL.cjs.map +0 -1
- package/dist/chunk-7LNBSOVV.cjs +0 -2
- package/dist/chunk-7LNBSOVV.cjs.map +0 -1
- package/dist/chunk-7SMWQ6SN.mjs.map +0 -1
- package/dist/chunk-7WRTK7RJ.mjs.map +0 -1
- package/dist/chunk-AX2YQQFQ.mjs.map +0 -1
- package/dist/chunk-BS6K7HGH.cjs +0 -2
- package/dist/chunk-BS6K7HGH.cjs.map +0 -1
- package/dist/chunk-C3FHGFLK.mjs +0 -2
- package/dist/chunk-C3FHGFLK.mjs.map +0 -1
- package/dist/chunk-C6ZGUO4H.cjs.map +0 -1
- package/dist/chunk-FCWDGE62.cjs.map +0 -1
- package/dist/chunk-RW3JFPED.mjs +0 -4
- package/dist/chunk-RW3JFPED.mjs.map +0 -1
- package/dist/chunk-S3EAKCVM.cjs +0 -2
- package/dist/chunk-S3EAKCVM.cjs.map +0 -1
- package/dist/chunk-SWMJQOH6.cjs +0 -2
- package/dist/chunk-SWMJQOH6.cjs.map +0 -1
- package/dist/chunk-THATXCJK.mjs +0 -2
- package/dist/chunk-THATXCJK.mjs.map +0 -1
- package/dist/chunk-VXL2ZZ4X.cjs +0 -2
- package/dist/chunk-VXL2ZZ4X.cjs.map +0 -1
- package/dist/chunk-YNO7BCCM.mjs +0 -2
- package/dist/chunk-YXLFOEZN.mjs +0 -2
- package/dist/chunk-YXLFOEZN.mjs.map +0 -1
- package/dist/chunk-YZV5LKIP.cjs.map +0 -1
- package/src/actions/dex/getSubgraphPool.ts +0 -30
- package/src/actions/validators/getManagedValidatorByAccount.ts +0 -32
- package/src/hooks/pol/useSWBeraVaultMetadata.ts +0 -35
- package/src/hooks/validators/useManagedValidatorByAccount.ts +0 -40
- package/src/hooks/validators/useSubgraphUserValidators.ts +0 -36
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { parseUnits } from "viem";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { InvalidArgumentError } from "../../../errors/InvalidArgumentError";
|
|
5
|
+
import {
|
|
6
|
+
calculateMultiplyBorrowAmount,
|
|
7
|
+
getPositionEstimate,
|
|
8
|
+
} from "../getBendMultiplyBundle";
|
|
9
|
+
import { collateral6, collateral18, loan6, loan18 } from "./helpers";
|
|
10
|
+
|
|
11
|
+
describe("calculateMultiplyBorrowAmount", () => {
|
|
12
|
+
const baseArgs = {
|
|
13
|
+
rawSupplyCollateralAmount: parseUnits("10", 18).toString(), // 10 ETH
|
|
14
|
+
rawCurrentCollateralAmount: "0",
|
|
15
|
+
rawCurrentBorrowAmount: "0",
|
|
16
|
+
formattedCollateralPriceInLoanAsset: "2000", // 1 ETH = 2000 USDC
|
|
17
|
+
collateralToken: collateral18,
|
|
18
|
+
loanToken: loan6,
|
|
19
|
+
slippage: 0.5,
|
|
20
|
+
leverageMultiplier: 2,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it("returns '0' for leverage <= 1", () => {
|
|
24
|
+
expect(
|
|
25
|
+
calculateMultiplyBorrowAmount({ ...baseArgs, leverageMultiplier: 1 }),
|
|
26
|
+
).toBe("0");
|
|
27
|
+
expect(
|
|
28
|
+
calculateMultiplyBorrowAmount({ ...baseArgs, leverageMultiplier: 0.5 }),
|
|
29
|
+
).toBe("0");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("calculates borrow for 2x leverage on fresh position", () => {
|
|
33
|
+
const result = calculateMultiplyBorrowAmount(baseArgs);
|
|
34
|
+
const borrowUsdc = Number(result) / 1e6;
|
|
35
|
+
|
|
36
|
+
// At 2x leverage: targetLtv = 0.5, denominator = 1 - 0.5*0.995 = 0.5025
|
|
37
|
+
// borrow = (0.5 * 10e18 * rawPrice) / 0.5025 ≈ 19,900 USDC
|
|
38
|
+
// The recursive formula accounts for re-deposited swap proceeds
|
|
39
|
+
expect(borrowUsdc).toBeGreaterThan(19000);
|
|
40
|
+
expect(borrowUsdc).toBeLessThan(21000);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("calculates borrow for 3x leverage", () => {
|
|
44
|
+
const result = calculateMultiplyBorrowAmount({
|
|
45
|
+
...baseArgs,
|
|
46
|
+
leverageMultiplier: 3,
|
|
47
|
+
});
|
|
48
|
+
const borrowUsdc = Number(result) / 1e6;
|
|
49
|
+
|
|
50
|
+
// At 3x: targetLtv = 2/3, denominator ≈ 0.337
|
|
51
|
+
// Higher leverage = more borrowing ≈ 39,600 USDC
|
|
52
|
+
expect(borrowUsdc).toBeGreaterThan(38000);
|
|
53
|
+
expect(borrowUsdc).toBeLessThan(41000);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("accounts for existing borrow by reducing new borrow needed", () => {
|
|
57
|
+
// Same total collateral base (15 ETH) but with existing borrow
|
|
58
|
+
const withExistingBorrow = calculateMultiplyBorrowAmount({
|
|
59
|
+
...baseArgs,
|
|
60
|
+
rawSupplyCollateralAmount: parseUnits("5", 18).toString(),
|
|
61
|
+
rawCurrentCollateralAmount: parseUnits("10", 18).toString(),
|
|
62
|
+
rawCurrentBorrowAmount: parseUnits("10000", 6).toString(),
|
|
63
|
+
});
|
|
64
|
+
const noBorrow = calculateMultiplyBorrowAmount({
|
|
65
|
+
...baseArgs,
|
|
66
|
+
rawSupplyCollateralAmount: parseUnits("5", 18).toString(),
|
|
67
|
+
rawCurrentCollateralAmount: parseUnits("10", 18).toString(),
|
|
68
|
+
rawCurrentBorrowAmount: "0",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// With existing borrow, less additional borrowing is needed
|
|
72
|
+
expect(Number(withExistingBorrow)).toBeLessThan(Number(noBorrow));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("returns '0' when existing borrow already exceeds target", () => {
|
|
76
|
+
const result = calculateMultiplyBorrowAmount({
|
|
77
|
+
...baseArgs,
|
|
78
|
+
leverageMultiplier: 2,
|
|
79
|
+
rawCurrentCollateralAmount: parseUnits("10", 18).toString(),
|
|
80
|
+
rawCurrentBorrowAmount: parseUnits("20000", 6).toString(), // already over-leveraged
|
|
81
|
+
});
|
|
82
|
+
expect(result).toBe("0");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("throws for zero collateral price", () => {
|
|
86
|
+
expect(() =>
|
|
87
|
+
calculateMultiplyBorrowAmount({
|
|
88
|
+
...baseArgs,
|
|
89
|
+
formattedCollateralPriceInLoanAsset: "0",
|
|
90
|
+
}),
|
|
91
|
+
).toThrow(InvalidArgumentError);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("throws for negative collateral price", () => {
|
|
95
|
+
expect(() =>
|
|
96
|
+
calculateMultiplyBorrowAmount({
|
|
97
|
+
...baseArgs,
|
|
98
|
+
formattedCollateralPriceInLoanAsset: "-1",
|
|
99
|
+
}),
|
|
100
|
+
).toThrow(InvalidArgumentError);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("throws when slippage >= 100 (via computeSwapOutputRatio)", () => {
|
|
104
|
+
// slippage >= 100% makes swap output ratio non-positive
|
|
105
|
+
expect(() =>
|
|
106
|
+
calculateMultiplyBorrowAmount({
|
|
107
|
+
...baseArgs,
|
|
108
|
+
slippage: 100,
|
|
109
|
+
}),
|
|
110
|
+
).toThrow(InvalidArgumentError);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("returns integer string (no decimals)", () => {
|
|
114
|
+
const result = calculateMultiplyBorrowAmount(baseArgs);
|
|
115
|
+
expect(result).toMatch(/^\d+$/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("works with reversed decimal pairs (6 -> 18)", () => {
|
|
119
|
+
const result = calculateMultiplyBorrowAmount({
|
|
120
|
+
...baseArgs,
|
|
121
|
+
rawSupplyCollateralAmount: parseUnits("10000", 6).toString(), // 10000 USDC
|
|
122
|
+
formattedCollateralPriceInLoanAsset: "0.0005", // 1 USDC = 0.0005 ETH
|
|
123
|
+
collateralToken: collateral6,
|
|
124
|
+
loanToken: loan18,
|
|
125
|
+
});
|
|
126
|
+
const borrowEth = Number(result) / 1e18;
|
|
127
|
+
// Recursive formula: ~4.975 ETH (close to 5 ETH target at 2x)
|
|
128
|
+
expect(borrowEth).toBeGreaterThan(4.5);
|
|
129
|
+
expect(borrowEth).toBeLessThan(5.5);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("getPositionEstimate (multiply)", () => {
|
|
134
|
+
it("deposit-only: returns supply amount as collateral, zero borrow", () => {
|
|
135
|
+
const result = getPositionEstimate({
|
|
136
|
+
rawSupplyCollateralAmount: parseUnits("10", 18).toString(),
|
|
137
|
+
collateralToken: collateral18,
|
|
138
|
+
loanToken: loan6,
|
|
139
|
+
rawBorrowAmount: "0",
|
|
140
|
+
formattedCollateralPriceInLoanAsset: "2000",
|
|
141
|
+
slippage: 0.5,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(result.finalCollateral).toBe("10");
|
|
145
|
+
expect(result.totalBorrow).toBe("0");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("leveraged: collateral includes supply + swapped borrow proceeds", () => {
|
|
149
|
+
const rawBorrow = parseUnits("10000", 6).toString(); // borrow 10000 USDC
|
|
150
|
+
const result = getPositionEstimate({
|
|
151
|
+
rawSupplyCollateralAmount: parseUnits("10", 18).toString(),
|
|
152
|
+
collateralToken: collateral18,
|
|
153
|
+
loanToken: loan6,
|
|
154
|
+
rawBorrowAmount: rawBorrow,
|
|
155
|
+
formattedCollateralPriceInLoanAsset: "2000", // 1 ETH = 2000 USDC
|
|
156
|
+
slippage: 0.5,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const finalCollateral = Number(result.finalCollateral);
|
|
160
|
+
const totalBorrow = Number(result.totalBorrow);
|
|
161
|
+
|
|
162
|
+
// 10 ETH supplied + (10000 USDC * 0.995 / 2000 USDC_per_ETH) ≈ 10 + 4.975 = ~14.975 ETH
|
|
163
|
+
expect(finalCollateral).toBeGreaterThan(14);
|
|
164
|
+
expect(finalCollateral).toBeLessThan(16);
|
|
165
|
+
expect(totalBorrow).toBe(10000);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("returns formatted (human-readable) values", () => {
|
|
169
|
+
const result = getPositionEstimate({
|
|
170
|
+
rawSupplyCollateralAmount: parseUnits("1", 18).toString(),
|
|
171
|
+
collateralToken: collateral18,
|
|
172
|
+
loanToken: loan6,
|
|
173
|
+
rawBorrowAmount: "0",
|
|
174
|
+
formattedCollateralPriceInLoanAsset: "2000",
|
|
175
|
+
slippage: 1,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Should be "1", not "1000000000000000000"
|
|
179
|
+
expect(Number(result.finalCollateral)).toBe(1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("handles zero borrow as deposit-only", () => {
|
|
183
|
+
const result = getPositionEstimate({
|
|
184
|
+
rawSupplyCollateralAmount: parseUnits("5", 18).toString(),
|
|
185
|
+
collateralToken: collateral18,
|
|
186
|
+
loanToken: loan6,
|
|
187
|
+
rawBorrowAmount: "0",
|
|
188
|
+
formattedCollateralPriceInLoanAsset: "2000",
|
|
189
|
+
slippage: 1,
|
|
190
|
+
});
|
|
191
|
+
expect(result.totalBorrow).toBe("0");
|
|
192
|
+
expect(Number(result.finalCollateral)).toBe(5);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -17,9 +17,9 @@ import {
|
|
|
17
17
|
|
|
18
18
|
import { getConfig } from "@berachain/wagmi/config";
|
|
19
19
|
|
|
20
|
-
import { BeraMonitoring } from "
|
|
21
|
-
import { getEnsoClient } from "
|
|
22
|
-
import { getEnsoUserTokensWithBalances } from "
|
|
20
|
+
import { BeraMonitoring } from "../../../errors/BeraMonitoring";
|
|
21
|
+
import { getEnsoClient } from "../../clients/getEnsoClient";
|
|
22
|
+
import { getEnsoUserTokensWithBalances } from "../getEnsoUserTokensWithBalances";
|
|
23
23
|
|
|
24
24
|
describe("getEnsoUserTokensWithBalances", () => {
|
|
25
25
|
let fetchSpy: MockInstance<typeof global.fetch>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getAddress } from "viem";
|
|
2
|
+
import { vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { ChainId } from "@berachain/config/internal";
|
|
5
|
+
|
|
6
|
+
import type { Token } from "../../../types/dex";
|
|
7
|
+
|
|
8
|
+
export const makeToken = (decimals: number, symbol = "T"): Token =>
|
|
9
|
+
({
|
|
10
|
+
address: "0x0000000000000000000000000000000000000001",
|
|
11
|
+
decimals,
|
|
12
|
+
symbol,
|
|
13
|
+
name: symbol,
|
|
14
|
+
chainId: ChainId.MAINNET,
|
|
15
|
+
}) as Token;
|
|
16
|
+
|
|
17
|
+
export const TEST_ADDRESS = getAddress(
|
|
18
|
+
"0x79f453D56C4bC66586215827FbBc7b34Bc006b33",
|
|
19
|
+
);
|
|
20
|
+
export const TEST_PRIMARY = getAddress(
|
|
21
|
+
"0x1111111111111111111111111111111111111111",
|
|
22
|
+
);
|
|
23
|
+
export const TEST_MARKET_ID =
|
|
24
|
+
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as `0x${string}`;
|
|
25
|
+
|
|
26
|
+
export const collateral18 = makeToken(18, "WETH");
|
|
27
|
+
export const collateral6 = makeToken(6, "USDC");
|
|
28
|
+
export const loan18 = makeToken(18, "WETH");
|
|
29
|
+
export const loan6 = makeToken(6, "USDC");
|
|
30
|
+
|
|
31
|
+
export const MOCK_BUNDLE_RESPONSE = {
|
|
32
|
+
tx: { to: "0xbundle", data: "0x1234", value: "0" },
|
|
33
|
+
gas: "500000",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const makeMockEnsoClient = () => ({
|
|
37
|
+
getBundleData: vi.fn().mockResolvedValue(MOCK_BUNDLE_RESPONSE),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const makeMockPublicClient = () => ({
|
|
41
|
+
readContract: vi.fn(),
|
|
42
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
4
|
+
|
|
5
|
+
import { InvalidArgumentError } from "../../../errors/InvalidArgumentError";
|
|
6
|
+
import {
|
|
7
|
+
computeRawCollateralToLoanPrice,
|
|
8
|
+
computeSwapOutputRatio,
|
|
9
|
+
} from "../util";
|
|
10
|
+
import { makeToken } from "./helpers";
|
|
11
|
+
|
|
12
|
+
describe("computeSwapOutputRatio", () => {
|
|
13
|
+
it("returns 0.995 for 0.5% slippage", () => {
|
|
14
|
+
const ratio = computeSwapOutputRatio(0.5);
|
|
15
|
+
expect(ratio.toNumber()).toBeCloseTo(0.995, 10);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("returns 0.99 for 1% slippage", () => {
|
|
19
|
+
const ratio = computeSwapOutputRatio(1);
|
|
20
|
+
expect(ratio.toNumber()).toBeCloseTo(0.99, 10);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("returns 0.9 for 10% slippage", () => {
|
|
24
|
+
const ratio = computeSwapOutputRatio(10);
|
|
25
|
+
expect(ratio.toNumber()).toBeCloseTo(0.9, 10);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("returns 1 for 0% slippage", () => {
|
|
29
|
+
const ratio = computeSwapOutputRatio(0);
|
|
30
|
+
expect(ratio.toNumber()).toBe(1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("throws for slippage >= 100%", () => {
|
|
34
|
+
expect(() => computeSwapOutputRatio(100)).toThrow(InvalidArgumentError);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("throws for slippage > 100%", () => {
|
|
38
|
+
expect(() => computeSwapOutputRatio(150)).toThrow(InvalidArgumentError);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("computeRawCollateralToLoanPrice", () => {
|
|
43
|
+
it("same decimals: raw price equals formatted price", () => {
|
|
44
|
+
const price = new BigNumber("2000");
|
|
45
|
+
const result = computeRawCollateralToLoanPrice(
|
|
46
|
+
price,
|
|
47
|
+
makeToken(18),
|
|
48
|
+
makeToken(18),
|
|
49
|
+
);
|
|
50
|
+
expect(result.toFixed()).toBe("2000");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("collateral 18 decimals, loan 6 decimals: scales down", () => {
|
|
54
|
+
// rawPrice = 2000 * 10^6 / 10^18 = 2000 * 1e-12 = 2e-9
|
|
55
|
+
const price = new BigNumber("2000");
|
|
56
|
+
const result = computeRawCollateralToLoanPrice(
|
|
57
|
+
price,
|
|
58
|
+
makeToken(18),
|
|
59
|
+
makeToken(6),
|
|
60
|
+
);
|
|
61
|
+
expect(result.toFixed()).toBe("0.000000002");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("collateral 6 decimals, loan 18 decimals: scales up", () => {
|
|
65
|
+
// rawPrice = 2000 * 10^18 / 10^6 = 2000 * 1e12
|
|
66
|
+
const price = new BigNumber("2000");
|
|
67
|
+
const result = computeRawCollateralToLoanPrice(
|
|
68
|
+
price,
|
|
69
|
+
makeToken(6),
|
|
70
|
+
makeToken(18),
|
|
71
|
+
);
|
|
72
|
+
expect(result.toFixed()).toBe("2000000000000000");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("fractional price with mixed decimals", () => {
|
|
76
|
+
// 0.0005 ETH/USDC (collateral=USDC 6dec, loan=ETH 18dec)
|
|
77
|
+
// rawPrice = 0.0005 * 10^18 / 10^6 = 5 * 10^8
|
|
78
|
+
const price = new BigNumber("0.0005");
|
|
79
|
+
const result = computeRawCollateralToLoanPrice(
|
|
80
|
+
price,
|
|
81
|
+
makeToken(6),
|
|
82
|
+
makeToken(18),
|
|
83
|
+
);
|
|
84
|
+
expect(result.toNumber()).toBeCloseTo(500_000_000, 0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("price of zero returns zero", () => {
|
|
88
|
+
const result = computeRawCollateralToLoanPrice(
|
|
89
|
+
new BigNumber(0),
|
|
90
|
+
makeToken(18),
|
|
91
|
+
makeToken(6),
|
|
92
|
+
);
|
|
93
|
+
expect(result.toNumber()).toBe(0);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { BundleData } from "@ensofinance/sdk";
|
|
2
|
+
import {
|
|
3
|
+
type Address,
|
|
4
|
+
encodeFunctionData,
|
|
5
|
+
getAddress,
|
|
6
|
+
type PublicClient,
|
|
7
|
+
} from "viem";
|
|
8
|
+
|
|
9
|
+
import { morphoAbi } from "@berachain/abis/bend/morpho";
|
|
10
|
+
|
|
11
|
+
import { ensoWalletV2FactoryAbi } from "../../abi/enso/ensoWalletV2Factory";
|
|
12
|
+
import { assertDefined } from "../../errors/assert";
|
|
13
|
+
import type { AllowanceQueryItem, MinimalERC20 } from "../../types/dex";
|
|
14
|
+
import type { GetZapTransactions, Quantity } from "../../types/enso";
|
|
15
|
+
import { parseBaseArgs } from "../../utils/parseBaseArgs";
|
|
16
|
+
import { getEnsoWalletTransactionsWithApproval } from "./util";
|
|
17
|
+
|
|
18
|
+
export async function getEnsoWalletV2Address({
|
|
19
|
+
publicClient,
|
|
20
|
+
ensoWalletV2Factory,
|
|
21
|
+
accountAddress,
|
|
22
|
+
}: {
|
|
23
|
+
publicClient: PublicClient;
|
|
24
|
+
ensoWalletV2Factory: Address;
|
|
25
|
+
accountAddress: Address;
|
|
26
|
+
}): Promise<Address> {
|
|
27
|
+
return publicClient.readContract({
|
|
28
|
+
address: ensoWalletV2Factory,
|
|
29
|
+
abi: ensoWalletV2FactoryAbi,
|
|
30
|
+
functionName: "getAddress",
|
|
31
|
+
args: [accountAddress],
|
|
32
|
+
}) as Promise<Address>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getIsBendAuthorized({
|
|
36
|
+
publicClient,
|
|
37
|
+
primaryAddress,
|
|
38
|
+
accountAddress,
|
|
39
|
+
ensoWalletV2Address,
|
|
40
|
+
}: {
|
|
41
|
+
publicClient: PublicClient;
|
|
42
|
+
primaryAddress: Address;
|
|
43
|
+
accountAddress: Address;
|
|
44
|
+
ensoWalletV2Address: Address;
|
|
45
|
+
}): Promise<boolean> {
|
|
46
|
+
return publicClient.readContract({
|
|
47
|
+
address: primaryAddress,
|
|
48
|
+
abi: morphoAbi,
|
|
49
|
+
functionName: "isAuthorized",
|
|
50
|
+
args: [accountAddress, ensoWalletV2Address],
|
|
51
|
+
}) as Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Assemble the final transaction list for a Bend flashloan bundle.
|
|
56
|
+
*
|
|
57
|
+
* Handles:
|
|
58
|
+
* 1. ERC-20 approval for the Enso wallet (if tokenIn is not native and
|
|
59
|
+
* allowance is insufficient)
|
|
60
|
+
* 2. Morpho setAuthorization transaction (if not yet authorized)
|
|
61
|
+
* 3. The bundle execution transaction itself
|
|
62
|
+
*
|
|
63
|
+
* @returns `{ transactions, approvals, ensoWalletFlashloanAdapter }`
|
|
64
|
+
*/
|
|
65
|
+
export async function assembleBendFlashloanTransactions({
|
|
66
|
+
fromAddress,
|
|
67
|
+
amountIn,
|
|
68
|
+
tokenIn,
|
|
69
|
+
primaryAddress,
|
|
70
|
+
bundle,
|
|
71
|
+
publicClient,
|
|
72
|
+
ensoWalletV2Address,
|
|
73
|
+
isAuthorized,
|
|
74
|
+
}: {
|
|
75
|
+
fromAddress: Address;
|
|
76
|
+
amountIn: Quantity;
|
|
77
|
+
tokenIn: MinimalERC20;
|
|
78
|
+
primaryAddress: Address;
|
|
79
|
+
bundle: BundleData;
|
|
80
|
+
publicClient: PublicClient;
|
|
81
|
+
ensoWalletV2Address: Address;
|
|
82
|
+
isAuthorized: boolean;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
transactions: GetZapTransactions;
|
|
85
|
+
approvals: AllowanceQueryItem[];
|
|
86
|
+
ensoWalletFlashloanAdapter: Address;
|
|
87
|
+
}> {
|
|
88
|
+
const { config } = parseBaseArgs({});
|
|
89
|
+
const { walletFlashloanAdapter: ensoWalletFlashloanAdapter } = config.enso;
|
|
90
|
+
assertDefined(
|
|
91
|
+
ensoWalletFlashloanAdapter,
|
|
92
|
+
"config.enso.walletFlashloanAdapter",
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const { transactions: ensoTransactions, approval } =
|
|
96
|
+
await getEnsoWalletTransactionsWithApproval({
|
|
97
|
+
fromAddress,
|
|
98
|
+
amountIn,
|
|
99
|
+
tokenIn,
|
|
100
|
+
bundle,
|
|
101
|
+
publicClient,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const transactions: GetZapTransactions = [];
|
|
105
|
+
|
|
106
|
+
if (!isAuthorized) {
|
|
107
|
+
transactions.push({
|
|
108
|
+
to: primaryAddress,
|
|
109
|
+
data: encodeFunctionData({
|
|
110
|
+
abi: morphoAbi,
|
|
111
|
+
functionName: "setAuthorization",
|
|
112
|
+
args: [ensoWalletV2Address, true],
|
|
113
|
+
}),
|
|
114
|
+
value: 0n,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
transactions.push(...ensoTransactions);
|
|
119
|
+
|
|
120
|
+
const approvals: AllowanceQueryItem[] = approval ? [approval] : [];
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
transactions,
|
|
124
|
+
approvals,
|
|
125
|
+
ensoWalletFlashloanAdapter: getAddress(ensoWalletFlashloanAdapter),
|
|
126
|
+
};
|
|
127
|
+
}
|