@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
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import type { BundleAction, EnsoClient } from "@ensofinance/sdk";
|
|
2
|
+
import type { Address, Hex, PublicClient } from "viem";
|
|
3
|
+
|
|
4
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
5
|
+
|
|
6
|
+
import { assertAddress } from "../../errors/assert";
|
|
7
|
+
import { InvalidArgumentError } from "../../errors/InvalidArgumentError";
|
|
8
|
+
import type { Token } from "../../types/dex";
|
|
9
|
+
import type { BendMultiplyBundleResponse } from "../../types/enso";
|
|
10
|
+
import { assembleBendFlashloanTransactions } from "./flashloan";
|
|
11
|
+
import {
|
|
12
|
+
computeRawCollateralToLoanPrice,
|
|
13
|
+
computeSwapOutputRatio,
|
|
14
|
+
toEnsoAddress,
|
|
15
|
+
} from "./util";
|
|
16
|
+
|
|
17
|
+
export interface GetBendMultiplyBundleArgs {
|
|
18
|
+
fromAddress: Address;
|
|
19
|
+
rawSupplyCollateralAmount: string;
|
|
20
|
+
rawCurrentCollateralAmount: string;
|
|
21
|
+
rawCurrentBorrowAmount: string;
|
|
22
|
+
collateralToken: Token;
|
|
23
|
+
loanToken: Token;
|
|
24
|
+
marketId: Hex;
|
|
25
|
+
primaryAddress: Address;
|
|
26
|
+
chainId: number;
|
|
27
|
+
ensoClient: EnsoClient;
|
|
28
|
+
slippage: number;
|
|
29
|
+
leverageMultiplier: number;
|
|
30
|
+
publicClient: PublicClient;
|
|
31
|
+
formattedCollateralPriceInLoanAsset: string;
|
|
32
|
+
ensoWalletV2Address: Address;
|
|
33
|
+
isAuthorized: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Calculate the loan amount needed to reach a target leverage multiplier.
|
|
38
|
+
*
|
|
39
|
+
* The closed-form formula accounts for the recursive nature of leveraged
|
|
40
|
+
* looping: each borrowed amount is swapped to collateral (losing value to
|
|
41
|
+
* slippage), then deposited, which increases borrowing capacity.
|
|
42
|
+
*
|
|
43
|
+
* targetLtv = 1 - 1/leverage
|
|
44
|
+
* rawPrice = collateral-to-loan price in raw token units
|
|
45
|
+
* denominator = 1 - targetLtv * swapOutputRatio
|
|
46
|
+
*
|
|
47
|
+
* borrowAmount = (targetLtv * collateralBase * rawPrice - currentBorrow)
|
|
48
|
+
* / denominator
|
|
49
|
+
*
|
|
50
|
+
* The denominator corrects for the recursive loop: each unit of loan token
|
|
51
|
+
* that survives the swap (after slippage) becomes new collateral that
|
|
52
|
+
* enables further borrowing. When denominator <= 0, the leverage target is
|
|
53
|
+
* unreachable at the current slippage tolerance.
|
|
54
|
+
*/
|
|
55
|
+
export function calculateMultiplyBorrowAmount({
|
|
56
|
+
rawSupplyCollateralAmount,
|
|
57
|
+
rawCurrentCollateralAmount,
|
|
58
|
+
rawCurrentBorrowAmount,
|
|
59
|
+
formattedCollateralPriceInLoanAsset,
|
|
60
|
+
collateralToken,
|
|
61
|
+
loanToken,
|
|
62
|
+
leverageMultiplier,
|
|
63
|
+
slippage,
|
|
64
|
+
}: {
|
|
65
|
+
rawSupplyCollateralAmount: string;
|
|
66
|
+
rawCurrentCollateralAmount: string;
|
|
67
|
+
rawCurrentBorrowAmount: string;
|
|
68
|
+
formattedCollateralPriceInLoanAsset: string;
|
|
69
|
+
collateralToken: Token;
|
|
70
|
+
loanToken: Token;
|
|
71
|
+
leverageMultiplier: number;
|
|
72
|
+
slippage: number;
|
|
73
|
+
}): string {
|
|
74
|
+
const normalizedLeverage = Math.max(leverageMultiplier, 1);
|
|
75
|
+
if (normalizedLeverage <= 1) return "0";
|
|
76
|
+
|
|
77
|
+
const swapOutputRatio = computeSwapOutputRatio(slippage);
|
|
78
|
+
const formattedCollateralPrice = new BigNumber(
|
|
79
|
+
formattedCollateralPriceInLoanAsset,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (formattedCollateralPrice.lte(0)) {
|
|
83
|
+
throw new InvalidArgumentError({
|
|
84
|
+
property: "formattedCollateralPriceInLoanAsset",
|
|
85
|
+
value: formattedCollateralPriceInLoanAsset,
|
|
86
|
+
expected: "a value greater than zero",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const rawCollateralToLoanPrice = computeRawCollateralToLoanPrice(
|
|
91
|
+
formattedCollateralPrice,
|
|
92
|
+
collateralToken,
|
|
93
|
+
loanToken,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const targetLtv = new BigNumber(1).minus(
|
|
97
|
+
new BigNumber(1).dividedBy(normalizedLeverage),
|
|
98
|
+
);
|
|
99
|
+
const rawCollateralBase = new BigNumber(rawCurrentCollateralAmount).plus(
|
|
100
|
+
rawSupplyCollateralAmount,
|
|
101
|
+
);
|
|
102
|
+
const rawCurrentBorrow = new BigNumber(rawCurrentBorrowAmount);
|
|
103
|
+
|
|
104
|
+
// Denominator accounts for the recursive multiplier effect of re-deposited
|
|
105
|
+
// swap proceeds. A non-positive value means slippage eats all new collateral.
|
|
106
|
+
const denominator = new BigNumber(1).minus(
|
|
107
|
+
targetLtv.multipliedBy(swapOutputRatio),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (denominator.lte(0)) {
|
|
111
|
+
throw new InvalidArgumentError({
|
|
112
|
+
property: "leverageMultiplier",
|
|
113
|
+
value: leverageMultiplier,
|
|
114
|
+
expected: "a lower leverage target for current slippage",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const requiredRawBorrow = targetLtv
|
|
119
|
+
.multipliedBy(rawCollateralBase)
|
|
120
|
+
.multipliedBy(rawCollateralToLoanPrice)
|
|
121
|
+
.minus(rawCurrentBorrow)
|
|
122
|
+
.dividedBy(denominator);
|
|
123
|
+
|
|
124
|
+
if (requiredRawBorrow.lte(0)) return "0";
|
|
125
|
+
|
|
126
|
+
const rawBorrowAmount = requiredRawBorrow.integerValue(BigNumber.ROUND_UP);
|
|
127
|
+
if (rawBorrowAmount.lte(0)) return "0";
|
|
128
|
+
|
|
129
|
+
return rawBorrowAmount.toFixed(0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Estimate the position after executing a multiply loop.
|
|
134
|
+
*
|
|
135
|
+
* For a deposit-only (rawBorrowAmount = 0) scenario, final collateral is just
|
|
136
|
+
* the supplied amount. When borrowing, the loan is swapped to collateral
|
|
137
|
+
* (accounting for slippage) and added to the supplied amount.
|
|
138
|
+
*
|
|
139
|
+
* Returns human-readable (formatted) values for display.
|
|
140
|
+
*/
|
|
141
|
+
export function getPositionEstimate({
|
|
142
|
+
rawSupplyCollateralAmount,
|
|
143
|
+
collateralToken,
|
|
144
|
+
loanToken,
|
|
145
|
+
rawBorrowAmount,
|
|
146
|
+
formattedCollateralPriceInLoanAsset,
|
|
147
|
+
slippage,
|
|
148
|
+
}: {
|
|
149
|
+
rawSupplyCollateralAmount: string;
|
|
150
|
+
collateralToken: Token;
|
|
151
|
+
loanToken: Token;
|
|
152
|
+
rawBorrowAmount: string;
|
|
153
|
+
formattedCollateralPriceInLoanAsset: string;
|
|
154
|
+
slippage: number;
|
|
155
|
+
}): BendMultiplyBundleResponse["positionEstimate"] {
|
|
156
|
+
const collateralDecimalsMul = new BigNumber(10).pow(collateralToken.decimals);
|
|
157
|
+
const loanDecimalsMul = new BigNumber(10).pow(loanToken.decimals);
|
|
158
|
+
const rawSupplyCollateral = new BigNumber(rawSupplyCollateralAmount);
|
|
159
|
+
const rawBorrow = new BigNumber(rawBorrowAmount);
|
|
160
|
+
|
|
161
|
+
if (rawBorrow.lte(0)) {
|
|
162
|
+
return {
|
|
163
|
+
finalCollateral: rawSupplyCollateral
|
|
164
|
+
.dividedBy(collateralDecimalsMul)
|
|
165
|
+
.toFixed(),
|
|
166
|
+
totalBorrow: "0",
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const swapOutputRatio = computeSwapOutputRatio(slippage);
|
|
171
|
+
const rawCollateralToLoanPrice = computeRawCollateralToLoanPrice(
|
|
172
|
+
new BigNumber(formattedCollateralPriceInLoanAsset),
|
|
173
|
+
collateralToken,
|
|
174
|
+
loanToken,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// Collateral gained from swapping the borrowed loan tokens (after slippage)
|
|
178
|
+
const rawLoopCollateral = rawCollateralToLoanPrice.lte(0)
|
|
179
|
+
? new BigNumber(0)
|
|
180
|
+
: rawBorrow
|
|
181
|
+
.multipliedBy(swapOutputRatio)
|
|
182
|
+
.dividedBy(rawCollateralToLoanPrice);
|
|
183
|
+
|
|
184
|
+
const finalFormattedCollateral = rawSupplyCollateral
|
|
185
|
+
.plus(rawLoopCollateral)
|
|
186
|
+
.dividedBy(collateralDecimalsMul);
|
|
187
|
+
const totalFormattedBorrow = rawBorrow.dividedBy(loanDecimalsMul);
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
finalCollateral: finalFormattedCollateral.toFixed(),
|
|
191
|
+
totalBorrow: totalFormattedBorrow.toFixed(),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function getBendMultiplyBundle({
|
|
196
|
+
fromAddress,
|
|
197
|
+
rawSupplyCollateralAmount,
|
|
198
|
+
rawCurrentCollateralAmount,
|
|
199
|
+
rawCurrentBorrowAmount,
|
|
200
|
+
collateralToken,
|
|
201
|
+
loanToken,
|
|
202
|
+
marketId,
|
|
203
|
+
primaryAddress,
|
|
204
|
+
chainId,
|
|
205
|
+
ensoClient,
|
|
206
|
+
slippage,
|
|
207
|
+
leverageMultiplier,
|
|
208
|
+
publicClient,
|
|
209
|
+
formattedCollateralPriceInLoanAsset,
|
|
210
|
+
ensoWalletV2Address,
|
|
211
|
+
isAuthorized,
|
|
212
|
+
}: GetBendMultiplyBundleArgs): Promise<BendMultiplyBundleResponse> {
|
|
213
|
+
assertAddress(fromAddress, "fromAddress");
|
|
214
|
+
|
|
215
|
+
const collateralAddress = toEnsoAddress(collateralToken.address);
|
|
216
|
+
const loanAddress = toEnsoAddress(loanToken.address);
|
|
217
|
+
|
|
218
|
+
const rawBorrowAmount = calculateMultiplyBorrowAmount({
|
|
219
|
+
rawSupplyCollateralAmount,
|
|
220
|
+
rawCurrentCollateralAmount,
|
|
221
|
+
rawCurrentBorrowAmount,
|
|
222
|
+
formattedCollateralPriceInLoanAsset,
|
|
223
|
+
collateralToken,
|
|
224
|
+
loanToken,
|
|
225
|
+
leverageMultiplier,
|
|
226
|
+
slippage,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// -- Callback action indices for `useOutputOfCallAt` references.
|
|
230
|
+
// These MUST match the array position of each action in the callback below.
|
|
231
|
+
const CALLBACK_IDX_ROUTE_LOAN_TO_COLLATERAL = 0;
|
|
232
|
+
const CALLBACK_IDX_BALANCE_COLLATERAL = 1;
|
|
233
|
+
|
|
234
|
+
const depositOnlyActions = [
|
|
235
|
+
{
|
|
236
|
+
protocol: "bend",
|
|
237
|
+
action: "deposit",
|
|
238
|
+
args: {
|
|
239
|
+
primaryAddress,
|
|
240
|
+
positionId: marketId,
|
|
241
|
+
tokenIn: collateralAddress,
|
|
242
|
+
amountIn: rawSupplyCollateralAmount,
|
|
243
|
+
onBehalfOf: fromAddress,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
const flashloanActions = [
|
|
249
|
+
{
|
|
250
|
+
protocol: "bend",
|
|
251
|
+
action: "flashloan",
|
|
252
|
+
args: {
|
|
253
|
+
flashloanToken: loanAddress,
|
|
254
|
+
flashloanAmount: rawBorrowAmount,
|
|
255
|
+
tokenIn: collateralAddress,
|
|
256
|
+
amountIn: rawSupplyCollateralAmount,
|
|
257
|
+
tokenOut: loanAddress,
|
|
258
|
+
callback: [
|
|
259
|
+
// [0] Swap the flashloaned loan tokens into collateral
|
|
260
|
+
{
|
|
261
|
+
protocol: "enso",
|
|
262
|
+
action: "route",
|
|
263
|
+
args: {
|
|
264
|
+
tokenIn: loanAddress,
|
|
265
|
+
tokenOut: collateralAddress,
|
|
266
|
+
amountIn: rawBorrowAmount,
|
|
267
|
+
slippage: slippage * 100,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
// [1] Check collateral balance after swap
|
|
271
|
+
{
|
|
272
|
+
protocol: "enso",
|
|
273
|
+
action: "balance",
|
|
274
|
+
args: {
|
|
275
|
+
token: collateralAddress,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
// [2] Deposit all collateral (from balance check) into Bend
|
|
279
|
+
{
|
|
280
|
+
protocol: "bend",
|
|
281
|
+
action: "deposit",
|
|
282
|
+
args: {
|
|
283
|
+
primaryAddress,
|
|
284
|
+
positionId: marketId,
|
|
285
|
+
tokenIn: collateralAddress,
|
|
286
|
+
amountIn: {
|
|
287
|
+
useOutputOfCallAt: CALLBACK_IDX_BALANCE_COLLATERAL,
|
|
288
|
+
},
|
|
289
|
+
onBehalfOf: fromAddress,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
// [3] Borrow loan tokens to repay the flashloan
|
|
293
|
+
{
|
|
294
|
+
protocol: "bend",
|
|
295
|
+
action: "borrow",
|
|
296
|
+
args: {
|
|
297
|
+
primaryAddress,
|
|
298
|
+
positionId: marketId,
|
|
299
|
+
collateral: collateralAddress,
|
|
300
|
+
tokenOut: loanAddress,
|
|
301
|
+
amountOut: rawBorrowAmount,
|
|
302
|
+
onBehalfOf: fromAddress,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
// @ts-expect-error Enso SDK BundleAction typing does not include Bend flashloan action shape yet.
|
|
311
|
+
const bundleActions: BundleAction[] =
|
|
312
|
+
rawBorrowAmount === "0" ? depositOnlyActions : flashloanActions;
|
|
313
|
+
|
|
314
|
+
const bundle = await ensoClient.getBundleData(
|
|
315
|
+
{
|
|
316
|
+
fromAddress,
|
|
317
|
+
receiver: fromAddress,
|
|
318
|
+
spender: fromAddress,
|
|
319
|
+
chainId,
|
|
320
|
+
routingStrategy: "ensowallet-v2",
|
|
321
|
+
},
|
|
322
|
+
bundleActions,
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const { transactions } = await assembleBendFlashloanTransactions({
|
|
326
|
+
fromAddress,
|
|
327
|
+
amountIn: rawSupplyCollateralAmount,
|
|
328
|
+
tokenIn: collateralToken,
|
|
329
|
+
primaryAddress,
|
|
330
|
+
bundle,
|
|
331
|
+
publicClient,
|
|
332
|
+
ensoWalletV2Address,
|
|
333
|
+
isAuthorized,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
bundle,
|
|
338
|
+
transactions,
|
|
339
|
+
positionEstimate: getPositionEstimate({
|
|
340
|
+
rawSupplyCollateralAmount,
|
|
341
|
+
collateralToken,
|
|
342
|
+
loanToken,
|
|
343
|
+
rawBorrowAmount,
|
|
344
|
+
formattedCollateralPriceInLoanAsset,
|
|
345
|
+
slippage,
|
|
346
|
+
}),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BundleAction } from "@ensofinance/sdk";
|
|
2
2
|
import { ethAddress, zeroAddress } from "viem";
|
|
3
3
|
|
|
4
|
-
import { InvalidArgumentError } from "
|
|
4
|
+
import { InvalidArgumentError } from "../../errors/InvalidArgumentError";
|
|
5
5
|
import type {
|
|
6
6
|
GetEnsoSwapBundleArgs,
|
|
7
7
|
GetZapTransactionResponse,
|
|
8
|
-
} from "
|
|
8
|
+
} from "../../types/enso";
|
|
9
9
|
import { getTransactionsFromBundle } from "./util";
|
|
10
10
|
|
|
11
11
|
export async function getEnsoSwapBundle({
|
|
@@ -2,11 +2,11 @@ import type { EnsoClient } from "@ensofinance/sdk";
|
|
|
2
2
|
import { type Config, getChains, multicall } from "@wagmi/core";
|
|
3
3
|
import { type Address, formatUnits } from "viem";
|
|
4
4
|
|
|
5
|
-
import { BeraMonitoring } from "
|
|
6
|
-
import { InvalidArgumentError } from "
|
|
7
|
-
import { initBeraError } from "
|
|
8
|
-
import type { BalanceToken } from "
|
|
9
|
-
import { beraToken, isToken } from "
|
|
5
|
+
import { BeraMonitoring } from "../../errors/BeraMonitoring";
|
|
6
|
+
import { InvalidArgumentError } from "../../errors/InvalidArgumentError";
|
|
7
|
+
import { initBeraError } from "../../errors/initBeraError";
|
|
8
|
+
import type { BalanceToken } from "../../types/dex";
|
|
9
|
+
import { beraToken, isToken } from "../../utils/tokens";
|
|
10
10
|
import { getBalanceCall } from "../tokens/getWalletBalances";
|
|
11
11
|
|
|
12
12
|
/**
|
package/src/actions/enso/util.ts
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Address,
|
|
3
|
+
encodeFunctionData,
|
|
4
|
+
erc20Abi,
|
|
5
|
+
ethAddress,
|
|
6
|
+
formatUnits,
|
|
7
|
+
getAddress,
|
|
8
|
+
zeroAddress,
|
|
9
|
+
} from "viem";
|
|
2
10
|
|
|
3
|
-
import
|
|
11
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
12
|
+
|
|
13
|
+
import { InvalidArgumentError } from "../../errors/InvalidArgumentError";
|
|
14
|
+
import type { AllowanceQueryItem, Token } from "../../types/dex";
|
|
15
|
+
import type {
|
|
16
|
+
GetEnsoWalletTransactionsWithApprovalArgs,
|
|
17
|
+
GetZapTransactions,
|
|
18
|
+
GetZapTransactionsArgs,
|
|
19
|
+
} from "../../types/enso";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Convert a token address to Enso-compatible format.
|
|
23
|
+
* Enso uses the special `ethAddress` sentinel for native tokens instead of `zeroAddress`.
|
|
24
|
+
*/
|
|
25
|
+
export function toEnsoAddress(address: Address): Address {
|
|
26
|
+
return address === zeroAddress ? ethAddress : address;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function toBigIntOrUndefined(
|
|
30
|
+
value: string | number | bigint | null | undefined,
|
|
31
|
+
): bigint | undefined {
|
|
32
|
+
if (value === null || value === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return typeof value === "bigint" ? value : BigInt(value);
|
|
36
|
+
}
|
|
4
37
|
|
|
5
38
|
/**
|
|
6
39
|
* Get the zap transactions for a given bundle.
|
|
7
40
|
* @param args - The arguments for the zap transactions.
|
|
8
|
-
* @returns The
|
|
41
|
+
* @returns The zap transaction & approval transaction if required.
|
|
9
42
|
*/
|
|
10
43
|
export const getTransactionsFromBundle = async ({
|
|
11
44
|
fromAddress,
|
|
@@ -42,19 +75,131 @@ export const getTransactionsFromBundle = async ({
|
|
|
42
75
|
|
|
43
76
|
// Only add approval transaction if it's actually required
|
|
44
77
|
if (requiresApproval) {
|
|
78
|
+
const approvalValue = toBigIntOrUndefined(approvalRequest.tx.value) ?? 0n;
|
|
45
79
|
transactions.push({
|
|
46
80
|
to: approvalRequest.tx.to,
|
|
47
81
|
data: approvalRequest.tx.data as `0x${string}`,
|
|
48
|
-
value:
|
|
82
|
+
value: approvalValue,
|
|
49
83
|
gasLimit: BigInt(approvalRequest.gas),
|
|
50
84
|
});
|
|
51
85
|
}
|
|
52
86
|
}
|
|
87
|
+
const bundleValue = toBigIntOrUndefined(bundle.tx.value) ?? 0n;
|
|
53
88
|
transactions.push({
|
|
54
89
|
to: bundle.tx.to,
|
|
55
90
|
data: bundle.tx.data as `0x${string}`,
|
|
56
|
-
value:
|
|
91
|
+
value: bundleValue,
|
|
57
92
|
gasLimit: BigInt(bundle.gas),
|
|
58
93
|
});
|
|
59
94
|
return transactions;
|
|
60
95
|
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get ensowallet transactions for a bundle with approval handling.
|
|
99
|
+
* Checks allowance on the ensowallet spender and prepends approval when needed.
|
|
100
|
+
* @param args - The arguments for transaction generation.
|
|
101
|
+
* @returns The bundle transaction and optional approval transaction.
|
|
102
|
+
*/
|
|
103
|
+
export const getEnsoWalletTransactionsWithApproval = async ({
|
|
104
|
+
fromAddress,
|
|
105
|
+
amountIn,
|
|
106
|
+
tokenIn,
|
|
107
|
+
bundle,
|
|
108
|
+
publicClient,
|
|
109
|
+
}: GetEnsoWalletTransactionsWithApprovalArgs): Promise<{
|
|
110
|
+
transactions: GetZapTransactions;
|
|
111
|
+
approval: AllowanceQueryItem | null;
|
|
112
|
+
}> => {
|
|
113
|
+
const transactions: GetZapTransactions = [];
|
|
114
|
+
const spender = getAddress(bundle.tx.to);
|
|
115
|
+
let approval: AllowanceQueryItem | null = null;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* If the token is not the native token, we need to check if approval is required.
|
|
119
|
+
*/
|
|
120
|
+
const tokenInAddress = toEnsoAddress(tokenIn.address);
|
|
121
|
+
if (tokenInAddress !== ethAddress) {
|
|
122
|
+
// Check current allowance
|
|
123
|
+
const currentAllowance = await publicClient.readContract({
|
|
124
|
+
address: tokenIn.address as Address,
|
|
125
|
+
abi: erc20Abi,
|
|
126
|
+
functionName: "allowance",
|
|
127
|
+
args: [fromAddress, spender],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const amountInBigInt = BigInt(amountIn);
|
|
131
|
+
const requiresApproval = currentAllowance < amountInBigInt;
|
|
132
|
+
|
|
133
|
+
// Only add approval transaction if it's actually required
|
|
134
|
+
if (requiresApproval) {
|
|
135
|
+
const raw = amountInBigInt.toString();
|
|
136
|
+
approval = {
|
|
137
|
+
token: tokenIn,
|
|
138
|
+
amount: {
|
|
139
|
+
raw,
|
|
140
|
+
formatted: formatUnits(amountInBigInt, tokenIn.decimals),
|
|
141
|
+
},
|
|
142
|
+
spender,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const approvalData = encodeFunctionData({
|
|
146
|
+
abi: erc20Abi,
|
|
147
|
+
functionName: "approve",
|
|
148
|
+
args: [spender, amountInBigInt],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
transactions.push({
|
|
152
|
+
to: tokenIn.address,
|
|
153
|
+
data: approvalData,
|
|
154
|
+
value: 0n,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const bundleValue = toBigIntOrUndefined(bundle.tx.value) ?? 0n;
|
|
159
|
+
transactions.push({
|
|
160
|
+
to: bundle.tx.to,
|
|
161
|
+
data: bundle.tx.data as `0x${string}`,
|
|
162
|
+
value: bundleValue,
|
|
163
|
+
gasLimit: bundle.gas ? BigInt(bundle.gas) : undefined,
|
|
164
|
+
});
|
|
165
|
+
return { transactions, approval };
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Compute the fraction of swap output retained after accounting for slippage.
|
|
170
|
+
*
|
|
171
|
+
* @param slippage Slippage tolerance as a percentage (e.g. 0.5 means 0.5%).
|
|
172
|
+
* @returns `1 - slippage/100`. Throws if the result is non-positive.
|
|
173
|
+
*/
|
|
174
|
+
export function computeSwapOutputRatio(slippage: number): BigNumber {
|
|
175
|
+
const slippageRatio = new BigNumber(slippage).dividedBy(100);
|
|
176
|
+
const ratio = new BigNumber(1).minus(slippageRatio);
|
|
177
|
+
|
|
178
|
+
if (ratio.lte(0)) {
|
|
179
|
+
throw new InvalidArgumentError({
|
|
180
|
+
property: "slippage",
|
|
181
|
+
value: slippage,
|
|
182
|
+
expected: "a value lower than 100",
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return ratio;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Convert a human-readable collateral-to-loan price into a raw-unit ratio.
|
|
191
|
+
*
|
|
192
|
+
* The result expresses how many raw loan-token units correspond to one raw
|
|
193
|
+
* collateral-token unit:
|
|
194
|
+
*
|
|
195
|
+
* rawPrice = formattedPrice * (10^loanDecimals) / (10^collateralDecimals)
|
|
196
|
+
*/
|
|
197
|
+
export function computeRawCollateralToLoanPrice(
|
|
198
|
+
formattedPrice: BigNumber,
|
|
199
|
+
collateralToken: Token,
|
|
200
|
+
loanToken: Token,
|
|
201
|
+
): BigNumber {
|
|
202
|
+
return formattedPrice
|
|
203
|
+
.multipliedBy(new BigNumber(10).pow(loanToken.decimals))
|
|
204
|
+
.dividedBy(new BigNumber(10).pow(collateralToken.decimals));
|
|
205
|
+
}
|
package/src/actions/exports.ts
CHANGED
|
@@ -24,7 +24,6 @@ export * from "./dex/getPoolEvents";
|
|
|
24
24
|
export * from "./dex/getPoolHistoricalData";
|
|
25
25
|
export * from "./dex/getPoolPausedState";
|
|
26
26
|
export * from "./dex/getPoolWithState";
|
|
27
|
-
export * from "./dex/getSubgraphPool";
|
|
28
27
|
export * from "./dex/getVaultPausedState";
|
|
29
28
|
export * from "./governance/checkProposalField";
|
|
30
29
|
export * from "./governance/computeActualStatus";
|
|
@@ -94,7 +93,6 @@ export * from "./validators/getApiEnrichedAllocation";
|
|
|
94
93
|
export * from "./validators/getApiValidator";
|
|
95
94
|
export * from "./validators/getDailyValidatorBlockStats";
|
|
96
95
|
export * from "./validators/getDefaultRewardAllocation";
|
|
97
|
-
export * from "./validators/getManagedValidatorByAccount";
|
|
98
96
|
export * from "./validators/getStakingPoolBatch";
|
|
99
97
|
export * from "./validators/getUserActiveValidators";
|
|
100
98
|
export * from "./validators/getUserBoostsOnValidator";
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
|
|
4
4
|
|
|
5
|
-
import { ProposalErrorCodes } from "
|
|
6
|
-
import { parseBaseArgs } from "
|
|
5
|
+
import { ProposalErrorCodes } from "../../../enum/governance";
|
|
6
|
+
import { parseBaseArgs } from "../../../utils/parseBaseArgs";
|
|
7
7
|
import { checkProposalField } from "../checkProposalField";
|
|
8
8
|
|
|
9
9
|
describe("checkProposalField", () => {
|
|
@@ -5,8 +5,8 @@ import { ChainId, defaultChainId } from "@berachain/config/internal";
|
|
|
5
5
|
|
|
6
6
|
import { beraChefAbi } from "@berachain/abis/pol/rewards/beraChef";
|
|
7
7
|
|
|
8
|
-
import { getServerSidePublicClient } from "
|
|
9
|
-
import { parseBaseArgs } from "
|
|
8
|
+
import { getServerSidePublicClient } from "../../../utils/getServerSideClient";
|
|
9
|
+
import { parseBaseArgs } from "../../../utils/parseBaseArgs";
|
|
10
10
|
import { getDecodedFunctionData } from "../getDecodedFunctionData";
|
|
11
11
|
|
|
12
12
|
describe.skipIf(defaultChainId !== ChainId.MAINNET)(
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import { ChainId, defaultChainId } from "@berachain/config/internal";
|
|
4
4
|
|
|
5
|
-
import { getServerSidePublicClient } from "
|
|
6
|
-
import { getTestClient } from "
|
|
5
|
+
import { getServerSidePublicClient } from "../../../utils/getServerSideClient";
|
|
6
|
+
import { getTestClient } from "../../../utils/getTestClient";
|
|
7
7
|
import { getQuorum } from "../getQuorum";
|
|
8
8
|
|
|
9
9
|
describe("getQuorum", () => {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type SearchProposalsQueryVariables,
|
|
12
12
|
} from "@berachain/graphql/governance";
|
|
13
13
|
|
|
14
|
-
import { getApolloClient } from "
|
|
14
|
+
import { getApolloClient } from "../clients/getApolloClient";
|
|
15
15
|
import { computeActualStatus } from "./computeActualStatus";
|
|
16
16
|
|
|
17
17
|
export async function getAllProposals({
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type ProposalWithVotesFragment,
|
|
8
8
|
} from "@berachain/graphql/governance";
|
|
9
9
|
|
|
10
|
-
import { getApolloClient } from "
|
|
10
|
+
import { getApolloClient } from "../clients/getApolloClient";
|
|
11
11
|
import { computeActualStatus } from "./computeActualStatus";
|
|
12
12
|
|
|
13
13
|
export async function getProposalDetails({
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
type ProposalWithVotesFragment,
|
|
14
14
|
} from "@berachain/graphql/governance";
|
|
15
15
|
|
|
16
|
-
import { assertPublicClient } from "
|
|
16
|
+
import { assertPublicClient } from "../../errors/assert";
|
|
17
17
|
import { parseProposalBody } from "./parseProposalBody";
|
|
18
18
|
|
|
19
19
|
export async function getProposalFromTx(
|