@berachain/berajs 0.2.5 → 0.2.6-patch.2
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/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-7SMWQ6SN.mjs → chunk-3ZTAIOHH.mjs} +2 -2
- package/dist/chunk-3ZTAIOHH.mjs.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-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-I4V54RRZ.cjs +4 -0
- package/dist/chunk-I4V54RRZ.cjs.map +1 -0
- package/dist/chunk-I7M43BB4.cjs +2 -0
- package/dist/chunk-I7M43BB4.cjs.map +1 -0
- package/dist/chunk-IDFMLLDY.mjs +2 -0
- package/dist/chunk-IDFMLLDY.mjs.map +1 -0
- package/dist/chunk-KRVNPZLF.mjs +2 -0
- package/dist/chunk-KRVNPZLF.mjs.map +1 -0
- package/dist/{chunk-3YXSUBA5.mjs → chunk-MJZHJFZO.mjs} +2 -2
- 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-PKXAW6MO.cjs → chunk-NVHV2LDK.cjs} +2 -2
- package/dist/chunk-NVHV2LDK.cjs.map +1 -0
- package/dist/{chunk-FCWDGE62.cjs → chunk-NVOJIQUM.cjs} +2 -2
- package/dist/chunk-NVOJIQUM.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-ECRMUMTA.mjs → chunk-PLIH6KQM.mjs} +2 -2
- 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-YZV5LKIP.cjs → chunk-QXNF3YT7.cjs} +2 -2
- package/dist/chunk-QXNF3YT7.cjs.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-WIN4PK2Z.mjs +4 -0
- package/dist/chunk-WIN4PK2Z.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 +6 -7
- package/src/abi/enso/ensoWalletV2Factory.ts +9 -0
- package/src/abi/exports.ts +1 -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/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/getVaultHistory.ts +2 -2
- package/src/actions/pol/getVaultValidators.ts +1 -1
- 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/data/contracts.ts +10 -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/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/types.ts +2 -2
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +5 -6
- package/src/hooks/useGetVerifiedAbi.ts +1 -1
- 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/global.d.ts +3 -3
- package/src/types/governance.d.ts +1 -1
- package/src/types/honeySwap.d.ts +3 -3
- package/src/utils/beraFetch.ts +1 -1
- package/src/utils/createEmitter.ts +1 -1
- package/src/utils/formatIncentivesTokenMap.ts +1 -1
- 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/.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/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-55L7STYD.mjs +0 -2
- package/dist/chunk-55L7STYD.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-BKDBIBVO.mjs +0 -4
- package/dist/chunk-BKDBIBVO.mjs.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-ECRMUMTA.mjs.map +0 -1
- package/dist/chunk-FCWDGE62.cjs.map +0 -1
- package/dist/chunk-P2Q7CMUD.cjs +0 -2
- package/dist/chunk-P2Q7CMUD.cjs.map +0 -1
- package/dist/chunk-PKXAW6MO.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-UXGB54NE.cjs +0 -4
- package/dist/chunk-UXGB54NE.cjs.map +0 -1
- package/dist/chunk-VXL2ZZ4X.cjs +0 -2
- package/dist/chunk-VXL2ZZ4X.cjs.map +0 -1
- 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
- /package/dist/{chunk-3YXSUBA5.mjs.map → chunk-MJZHJFZO.mjs.map} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import type { BundleAction, EnsoClient } from "@ensofinance/sdk";
|
|
2
|
+
import { type Address, formatUnits, type Hex, type PublicClient } from "viem";
|
|
3
|
+
|
|
4
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
5
|
+
|
|
6
|
+
import { assertAddress, assertPositive } from "../../errors/assert";
|
|
7
|
+
import { InvalidArgumentError } from "../../errors/InvalidArgumentError";
|
|
8
|
+
import type { Token } from "../../types/dex";
|
|
9
|
+
import type { BendDemultiplyBundleResponse } from "../../types/enso";
|
|
10
|
+
import { assembleBendFlashloanTransactions } from "./flashloan";
|
|
11
|
+
import { computeSwapOutputRatio, toEnsoAddress } from "./util";
|
|
12
|
+
|
|
13
|
+
// full-repay cleanup needs a non-trivial leftover debt balance after `repay`.
|
|
14
|
+
// without this proportional buffer, enso may fail to route near-zero dust.
|
|
15
|
+
const FULL_REPAY_CLEANUP_BUFFER_BPS = 25n; // 0.25%
|
|
16
|
+
const BPS_DIVISOR = 10_000n;
|
|
17
|
+
|
|
18
|
+
export interface GetBendDemultiplyBundleArgs {
|
|
19
|
+
fromAddress: Address;
|
|
20
|
+
repayAmount: string;
|
|
21
|
+
collateralToken: Token;
|
|
22
|
+
loanToken: Token;
|
|
23
|
+
marketId: Hex;
|
|
24
|
+
primaryAddress: Address;
|
|
25
|
+
chainId: number;
|
|
26
|
+
ensoClient: EnsoClient;
|
|
27
|
+
slippage: number;
|
|
28
|
+
publicClient: PublicClient;
|
|
29
|
+
collateralPriceInLoanAsset: string;
|
|
30
|
+
currentCollateral: string;
|
|
31
|
+
currentDebt: string;
|
|
32
|
+
ensoWalletV2Address: Address;
|
|
33
|
+
isAuthorized: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Calculate the collateral amount to flashloan and sell in order to repay
|
|
38
|
+
* the target debt amount.
|
|
39
|
+
*
|
|
40
|
+
* collateralNeeded = repayAmount / (collateralPrice * swapOutputRatio)
|
|
41
|
+
*
|
|
42
|
+
* This is the inverse of the multiply direction: we need enough collateral
|
|
43
|
+
* that, after swapping to the loan token with slippage, covers the repay
|
|
44
|
+
* amount. The result is clamped to `currentCollateral` (can't withdraw
|
|
45
|
+
* more than exists in the position).
|
|
46
|
+
*/
|
|
47
|
+
export function calculateDemultiplyCollateralAmount({
|
|
48
|
+
repayAmount,
|
|
49
|
+
collateralPriceInLoanAsset,
|
|
50
|
+
collateralToken,
|
|
51
|
+
loanToken,
|
|
52
|
+
slippage,
|
|
53
|
+
currentCollateral,
|
|
54
|
+
}: {
|
|
55
|
+
repayAmount: string;
|
|
56
|
+
collateralPriceInLoanAsset: string;
|
|
57
|
+
collateralToken: Token;
|
|
58
|
+
loanToken: Token;
|
|
59
|
+
slippage: number;
|
|
60
|
+
currentCollateral: string;
|
|
61
|
+
}): string {
|
|
62
|
+
const swapOutputRatio = computeSwapOutputRatio(slippage);
|
|
63
|
+
const collateralPrice = new BigNumber(collateralPriceInLoanAsset);
|
|
64
|
+
|
|
65
|
+
if (collateralPrice.lte(0)) {
|
|
66
|
+
throw new InvalidArgumentError({
|
|
67
|
+
property: "collateralPriceInLoanAsset",
|
|
68
|
+
value: collateralPriceInLoanAsset,
|
|
69
|
+
expected: "a value greater than zero",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const loanDecimalsMul = new BigNumber(10).pow(loanToken.decimals);
|
|
74
|
+
const collateralDecimalsMul = new BigNumber(10).pow(collateralToken.decimals);
|
|
75
|
+
|
|
76
|
+
const repayAmountHuman = new BigNumber(repayAmount).dividedBy(
|
|
77
|
+
loanDecimalsMul,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const flashloanCollateralHuman = repayAmountHuman
|
|
81
|
+
.dividedBy(collateralPrice)
|
|
82
|
+
.dividedBy(swapOutputRatio);
|
|
83
|
+
|
|
84
|
+
const flashloanCollateralRaw = flashloanCollateralHuman
|
|
85
|
+
.multipliedBy(collateralDecimalsMul)
|
|
86
|
+
.integerValue(BigNumber.ROUND_UP);
|
|
87
|
+
|
|
88
|
+
if (flashloanCollateralRaw.lte(0)) return "0";
|
|
89
|
+
|
|
90
|
+
return BigNumber.minimum(
|
|
91
|
+
flashloanCollateralRaw,
|
|
92
|
+
new BigNumber(currentCollateral),
|
|
93
|
+
).toFixed(0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Estimate the position change after executing a demultiply.
|
|
98
|
+
*
|
|
99
|
+
* Unlike multiply, these values represent *reductions* from the current
|
|
100
|
+
* position — the caller subtracts them to get the new totals.
|
|
101
|
+
* Returns human-readable (formatted) values for display.
|
|
102
|
+
*/
|
|
103
|
+
export function getPositionEstimate({
|
|
104
|
+
repayAmount,
|
|
105
|
+
collateralToWithdraw,
|
|
106
|
+
collateralToken,
|
|
107
|
+
loanToken,
|
|
108
|
+
}: {
|
|
109
|
+
repayAmount: string;
|
|
110
|
+
collateralToWithdraw: string;
|
|
111
|
+
collateralToken: Token;
|
|
112
|
+
loanToken: Token;
|
|
113
|
+
}): BendDemultiplyBundleResponse["positionEstimate"] {
|
|
114
|
+
return {
|
|
115
|
+
finalCollateral: formatUnits(
|
|
116
|
+
BigInt(collateralToWithdraw),
|
|
117
|
+
collateralToken.decimals,
|
|
118
|
+
),
|
|
119
|
+
totalBorrow: formatUnits(BigInt(repayAmount), loanToken.decimals),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function getBendDemultiplyBundle({
|
|
124
|
+
fromAddress,
|
|
125
|
+
repayAmount,
|
|
126
|
+
collateralToken,
|
|
127
|
+
loanToken,
|
|
128
|
+
marketId,
|
|
129
|
+
primaryAddress,
|
|
130
|
+
chainId,
|
|
131
|
+
ensoClient,
|
|
132
|
+
slippage,
|
|
133
|
+
publicClient,
|
|
134
|
+
collateralPriceInLoanAsset,
|
|
135
|
+
currentCollateral,
|
|
136
|
+
currentDebt,
|
|
137
|
+
ensoWalletV2Address,
|
|
138
|
+
isAuthorized,
|
|
139
|
+
}: GetBendDemultiplyBundleArgs): Promise<BendDemultiplyBundleResponse> {
|
|
140
|
+
assertAddress(fromAddress, "fromAddress");
|
|
141
|
+
assertPositive(repayAmount, "repayAmount");
|
|
142
|
+
assertPositive(currentDebt, "currentDebt");
|
|
143
|
+
|
|
144
|
+
const rawRepayAmount = BigInt(repayAmount);
|
|
145
|
+
const rawCurrentDebt = BigInt(currentDebt);
|
|
146
|
+
const isFullRepayment = rawRepayAmount >= rawCurrentDebt;
|
|
147
|
+
|
|
148
|
+
const collateralAddress = toEnsoAddress(collateralToken.address);
|
|
149
|
+
const loanAddress = toEnsoAddress(loanToken.address);
|
|
150
|
+
|
|
151
|
+
// proportional extra debt amount (in raw units) reserved for full-repay cleanup.
|
|
152
|
+
const rawCleanupDebtAmountFromBps =
|
|
153
|
+
(rawRepayAmount * FULL_REPAY_CLEANUP_BUFFER_BPS + (BPS_DIVISOR - 1n)) /
|
|
154
|
+
BPS_DIVISOR;
|
|
155
|
+
const rawFullRepaymentCleanupDebtAmount = isFullRepayment
|
|
156
|
+
? rawCleanupDebtAmountFromBps
|
|
157
|
+
: 0n;
|
|
158
|
+
// on full repay, quote flashloan collateral against repay + cleanup buffer.
|
|
159
|
+
// this intentionally creates remaining debt token in the callback so it can
|
|
160
|
+
// be swapped back to collateral and re-deposited.
|
|
161
|
+
const rawTargetRepayForFlashloanQuote = (
|
|
162
|
+
rawRepayAmount + rawFullRepaymentCleanupDebtAmount
|
|
163
|
+
).toString();
|
|
164
|
+
|
|
165
|
+
const collateralToWithdraw = calculateDemultiplyCollateralAmount({
|
|
166
|
+
repayAmount: rawTargetRepayForFlashloanQuote,
|
|
167
|
+
collateralPriceInLoanAsset,
|
|
168
|
+
collateralToken,
|
|
169
|
+
loanToken,
|
|
170
|
+
slippage,
|
|
171
|
+
currentCollateral,
|
|
172
|
+
});
|
|
173
|
+
const isFlashloanCollateralClamped =
|
|
174
|
+
BigInt(collateralToWithdraw) >= BigInt(currentCollateral);
|
|
175
|
+
// if flashloan collateral is clamped by current collateral, skip cleanup to
|
|
176
|
+
// avoid adding extra callback steps when there is no safe collateral headroom.
|
|
177
|
+
const shouldRunFullRepaymentCleanup =
|
|
178
|
+
isFullRepayment &&
|
|
179
|
+
rawFullRepaymentCleanupDebtAmount > 0n &&
|
|
180
|
+
!isFlashloanCollateralClamped;
|
|
181
|
+
|
|
182
|
+
if (BigInt(collateralToWithdraw) <= 0n) {
|
|
183
|
+
throw new InvalidArgumentError({
|
|
184
|
+
property: "collateralToWithdraw",
|
|
185
|
+
value: collateralToWithdraw,
|
|
186
|
+
expected: "positive amount",
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const baseCallbackActions = [
|
|
191
|
+
// [0] Swap flashloaned collateral into loan tokens
|
|
192
|
+
{
|
|
193
|
+
protocol: "enso",
|
|
194
|
+
action: "route",
|
|
195
|
+
args: {
|
|
196
|
+
tokenIn: collateralAddress,
|
|
197
|
+
tokenOut: loanAddress,
|
|
198
|
+
amountIn: collateralToWithdraw,
|
|
199
|
+
slippage: slippage * 100,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
// [1] Repay debt using the swapped loan tokens
|
|
203
|
+
{
|
|
204
|
+
protocol: "bend",
|
|
205
|
+
action: "repay",
|
|
206
|
+
args: {
|
|
207
|
+
primaryAddress,
|
|
208
|
+
positionId: marketId,
|
|
209
|
+
tokenIn: loanAddress,
|
|
210
|
+
amountIn: { useOutputOfCallAt: 0 },
|
|
211
|
+
onBehalfOf: fromAddress,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
// On full repayment: swap leftover debt-token dust back to collateral and
|
|
217
|
+
// re-deposit it, so dust isn't left in the user's wallet.
|
|
218
|
+
// Cleanup indices are computed dynamically from baseCallbackActions length.
|
|
219
|
+
const cleanupStartIdx = baseCallbackActions.length;
|
|
220
|
+
const fullRepaymentCleanupActions = shouldRunFullRepaymentCleanup
|
|
221
|
+
? [
|
|
222
|
+
// Read remaining debt token balance after repay
|
|
223
|
+
{
|
|
224
|
+
protocol: "enso",
|
|
225
|
+
action: "balance",
|
|
226
|
+
args: {
|
|
227
|
+
token: loanAddress,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
// Swap remaining debt tokens back to collateral
|
|
231
|
+
{
|
|
232
|
+
protocol: "enso",
|
|
233
|
+
action: "route",
|
|
234
|
+
args: {
|
|
235
|
+
tokenIn: loanAddress,
|
|
236
|
+
tokenOut: collateralAddress,
|
|
237
|
+
amountIn: {
|
|
238
|
+
useOutputOfCallAt: cleanupStartIdx,
|
|
239
|
+
},
|
|
240
|
+
slippage: slippage * 100,
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
// Re-deposit recovered collateral into Bend
|
|
244
|
+
{
|
|
245
|
+
protocol: "bend",
|
|
246
|
+
action: "deposit",
|
|
247
|
+
args: {
|
|
248
|
+
primaryAddress,
|
|
249
|
+
positionId: marketId,
|
|
250
|
+
tokenIn: collateralAddress,
|
|
251
|
+
amountIn: {
|
|
252
|
+
useOutputOfCallAt: cleanupStartIdx + 1,
|
|
253
|
+
},
|
|
254
|
+
onBehalfOf: fromAddress,
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
]
|
|
258
|
+
: [];
|
|
259
|
+
|
|
260
|
+
const callbackActions = [
|
|
261
|
+
...baseCallbackActions,
|
|
262
|
+
...fullRepaymentCleanupActions,
|
|
263
|
+
// Final action: withdraw collateral to repay the flashloan
|
|
264
|
+
{
|
|
265
|
+
protocol: "bend",
|
|
266
|
+
action: "withdraw",
|
|
267
|
+
args: {
|
|
268
|
+
primaryAddress,
|
|
269
|
+
positionId: marketId,
|
|
270
|
+
tokenOut: collateralAddress,
|
|
271
|
+
amountOut: collateralToWithdraw,
|
|
272
|
+
onBehalfOf: fromAddress,
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
const flashloanActions = [
|
|
278
|
+
{
|
|
279
|
+
protocol: "bend",
|
|
280
|
+
action: "flashloan",
|
|
281
|
+
args: {
|
|
282
|
+
flashloanToken: collateralAddress,
|
|
283
|
+
flashloanAmount: collateralToWithdraw,
|
|
284
|
+
tokenOut: loanAddress,
|
|
285
|
+
callback: callbackActions,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
// @ts-expect-error Enso SDK BundleAction typing does not include Bend flashloan action shape yet.
|
|
291
|
+
const bundleActions: BundleAction[] = flashloanActions;
|
|
292
|
+
|
|
293
|
+
const bundle = await ensoClient.getBundleData(
|
|
294
|
+
{
|
|
295
|
+
fromAddress,
|
|
296
|
+
receiver: fromAddress,
|
|
297
|
+
spender: fromAddress,
|
|
298
|
+
chainId,
|
|
299
|
+
routingStrategy: "ensowallet-v2",
|
|
300
|
+
},
|
|
301
|
+
bundleActions,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const { transactions } = await assembleBendFlashloanTransactions({
|
|
305
|
+
fromAddress,
|
|
306
|
+
amountIn: "0",
|
|
307
|
+
tokenIn: collateralToken,
|
|
308
|
+
primaryAddress,
|
|
309
|
+
bundle,
|
|
310
|
+
publicClient,
|
|
311
|
+
ensoWalletV2Address,
|
|
312
|
+
isAuthorized,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
bundle,
|
|
317
|
+
transactions,
|
|
318
|
+
positionEstimate: getPositionEstimate({
|
|
319
|
+
repayAmount,
|
|
320
|
+
collateralToWithdraw,
|
|
321
|
+
collateralToken,
|
|
322
|
+
loanToken,
|
|
323
|
+
}),
|
|
324
|
+
};
|
|
325
|
+
}
|