@kamino-finance/klend-sdk 3.2.25 → 4.0.0
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/classes/action.d.ts +1 -0
- package/dist/classes/action.d.ts.map +1 -0
- package/dist/classes/action.js +1130 -1186
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/curve.d.ts +1 -0
- package/dist/classes/curve.d.ts.map +1 -0
- package/dist/classes/curve.js +1 -1
- package/dist/classes/curve.js.map +1 -1
- package/dist/classes/fraction.d.ts +1 -0
- package/dist/classes/fraction.d.ts.map +1 -0
- package/dist/classes/fraction.js +7 -6
- package/dist/classes/fraction.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/jupiterPerps.d.ts +1 -0
- package/dist/classes/jupiterPerps.d.ts.map +1 -0
- package/dist/classes/jupiterPerps.js +7 -18
- package/dist/classes/jupiterPerps.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -0
- package/dist/classes/manager.d.ts.map +1 -0
- package/dist/classes/manager.js +131 -158
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +1 -0
- package/dist/classes/market.d.ts.map +1 -0
- package/dist/classes/market.js +620 -714
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -0
- package/dist/classes/obligation.d.ts.map +1 -0
- package/dist/classes/obligation.js +60 -62
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -0
- package/dist/classes/reserve.d.ts.map +1 -0
- package/dist/classes/reserve.js +135 -138
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -0
- package/dist/classes/shared.d.ts.map +1 -0
- package/dist/classes/shared.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -0
- package/dist/classes/utils.d.ts.map +1 -0
- package/dist/classes/utils.js +3 -3
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -0
- package/dist/classes/vault.js +334 -354
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts +1 -0
- package/dist/client_kamino_manager.d.ts.map +1 -0
- package/dist/client_kamino_manager.js +323 -326
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.js +89 -55
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +1 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Obligation.js +87 -56
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.js +22 -33
- package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js +35 -37
- package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Reserve.js +60 -49
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen/accounts/ShortUrl.d.ts +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.js +22 -33
- package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -1
- package/dist/idl_codegen/accounts/UserMetadata.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.js +34 -37
- package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -1
- package/dist/idl_codegen/accounts/UserState.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserState.js +77 -48
- package/dist/idl_codegen/accounts/UserState.js.map +1 -1
- package/dist/idl_codegen/accounts/index.d.ts +1 -0
- package/dist/idl_codegen/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/index.js.map +1 -1
- package/dist/idl_codegen/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen/errors/anchor.js +270 -216
- package/dist/idl_codegen/errors/anchor.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +1 -0
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen/errors/custom.js +560 -448
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/errors/index.d.ts +1 -0
- package/dist/idl_codegen/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen/errors/index.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +1 -0
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -1
- package/dist/idl_codegen/instructions/socializeLoss.d.ts +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -1
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/programId.d.ts +1 -0
- package/dist/idl_codegen/programId.d.ts.map +1 -0
- package/dist/idl_codegen/programId.js.map +1 -1
- package/dist/idl_codegen/types/AssetTier.d.ts +1 -0
- package/dist/idl_codegen/types/AssetTier.d.ts.map +1 -0
- package/dist/idl_codegen/types/AssetTier.js +12 -18
- package/dist/idl_codegen/types/AssetTier.js.map +1 -1
- package/dist/idl_codegen/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen/types/CurvePoint.js +2 -0
- package/dist/idl_codegen/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen/types/ElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/types/ElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/types/ElevationGroup.js +10 -0
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -1
- package/dist/idl_codegen/types/FeeCalculation.d.ts +1 -0
- package/dist/idl_codegen/types/FeeCalculation.d.ts.map +1 -0
- package/dist/idl_codegen/types/FeeCalculation.js +8 -12
- package/dist/idl_codegen/types/FeeCalculation.js.map +1 -1
- package/dist/idl_codegen/types/InitObligationArgs.d.ts +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.d.ts.map +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.js +2 -0
- package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -1
- package/dist/idl_codegen/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen/types/LastUpdate.js +7 -0
- package/dist/idl_codegen/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +14 -0
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +17 -1
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.js +78 -5
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js +8 -12
- package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFees.js +16 -0
- package/dist/idl_codegen/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js +43 -1
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/ReserveStatus.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveStatus.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveStatus.js +12 -18
- package/dist/idl_codegen/types/ReserveStatus.js.map +1 -1
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen/types/TokenInfo.js +27 -4
- package/dist/idl_codegen/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +188 -282
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +41 -33
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +72 -108
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +1 -0
- package/dist/idl_codegen/types/index.d.ts.map +1 -0
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js +83 -54
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/index.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +39 -42
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/programId.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js +9 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +58 -47
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +51 -47
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +270 -216
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js +120 -96
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +7 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +77 -5
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +16 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +41 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +27 -4
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.js +15 -24
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -0
- package/dist/leverage/calcs.d.ts.map +1 -0
- package/dist/leverage/calcs.js +119 -132
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/index.d.ts +1 -0
- package/dist/leverage/index.d.ts.map +1 -0
- package/dist/leverage/index.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -0
- package/dist/leverage/instructions.d.ts.map +1 -0
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +1 -0
- package/dist/leverage/operations.d.ts.map +1 -0
- package/dist/leverage/operations.js +75 -84
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/utils.d.ts +1 -0
- package/dist/leverage/utils.d.ts.map +1 -0
- package/dist/leverage/utils.js +73 -88
- package/dist/leverage/utils.js.map +1 -1
- package/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/referrals/index.d.ts +1 -0
- package/dist/referrals/index.d.ts.map +1 -0
- package/dist/referrals/index.js.map +1 -1
- package/dist/referrals/instructions.d.ts +1 -0
- package/dist/referrals/instructions.d.ts.map +1 -0
- package/dist/referrals/instructions.js +8 -17
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/referrals/operations.d.ts +2 -1
- package/dist/referrals/operations.d.ts.map +1 -0
- package/dist/referrals/operations.js +119 -143
- package/dist/referrals/operations.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -0
- package/dist/utils/ObligationType.d.ts.map +1 -0
- package/dist/utils/ObligationType.js +16 -7
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +1 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +10 -21
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -0
- package/dist/utils/ata.d.ts.map +1 -0
- package/dist/utils/ata.js +25 -38
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/idl.d.ts +1 -0
- package/dist/utils/idl.d.ts.map +1 -0
- package/dist/utils/idl.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -0
- package/dist/utils/instruction.js +116 -143
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/kamino.d.ts +1 -0
- package/dist/utils/kamino.d.ts.map +1 -0
- package/dist/utils/kamino.js +4 -15
- package/dist/utils/kamino.js.map +1 -1
- package/dist/utils/layout.d.ts +1 -0
- package/dist/utils/layout.d.ts.map +1 -0
- package/dist/utils/layout.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +1 -0
- package/dist/utils/lookupTable.d.ts.map +1 -0
- package/dist/utils/lookupTable.js +14 -27
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -0
- package/dist/utils/managerTypes.js +31 -2
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +1 -0
- package/dist/utils/oracle.d.ts.map +1 -0
- package/dist/utils/oracle.js +70 -83
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/pubkey.d.ts +1 -0
- package/dist/utils/pubkey.d.ts.map +1 -0
- package/dist/utils/pubkey.js +7 -9
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/rpc.d.ts +1 -0
- package/dist/utils/rpc.d.ts.map +1 -0
- package/dist/utils/rpc.js +48 -70
- package/dist/utils/rpc.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -0
- package/dist/utils/seeds.d.ts.map +1 -0
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sendTransactionsUtils.d.ts +1 -0
- package/dist/utils/sendTransactionsUtils.d.ts.map +1 -0
- package/dist/utils/sendTransactionsUtils.js +82 -82
- package/dist/utils/sendTransactionsUtils.js.map +1 -1
- package/dist/utils/slots.d.ts +1 -0
- package/dist/utils/slots.d.ts.map +1 -0
- package/dist/utils/slots.js.map +1 -1
- package/dist/utils/syncNative.d.ts +1 -0
- package/dist/utils/syncNative.d.ts.map +1 -0
- package/dist/utils/syncNative.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +1 -0
- package/dist/utils/userMetadata.d.ts.map +1 -0
- package/dist/utils/userMetadata.js +40 -52
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +9 -3
- package/src/classes/action.ts +2884 -0
- package/src/classes/curve.ts +29 -0
- package/src/classes/fraction.ts +65 -0
- package/src/classes/index.ts +10 -0
- package/src/classes/jupiterPerps.ts +14 -0
- package/src/classes/manager.ts +746 -0
- package/src/classes/market.ts +1459 -0
- package/src/classes/obligation.ts +1315 -0
- package/src/classes/reserve.ts +1980 -0
- package/src/classes/shared.ts +57 -0
- package/src/classes/utils.ts +192 -0
- package/src/classes/vault.ts +808 -0
- package/src/client.ts +446 -0
- package/src/client_kamino_manager.ts +791 -0
- package/src/global.d.ts +1 -0
- package/src/idl_codegen/accounts/LendingMarket.ts +364 -0
- package/src/idl_codegen/accounts/Obligation.ts +349 -0
- package/src/idl_codegen/accounts/ReferrerState.ts +97 -0
- package/src/idl_codegen/accounts/ReferrerTokenState.ts +145 -0
- package/src/idl_codegen/accounts/Reserve.ts +248 -0
- package/src/idl_codegen/accounts/ShortUrl.ts +97 -0
- package/src/idl_codegen/accounts/UserMetadata.ts +142 -0
- package/src/idl_codegen/accounts/UserState.ts +301 -0
- package/src/idl_codegen/accounts/index.ts +19 -0
- package/src/idl_codegen/errors/anchor.ts +773 -0
- package/src/idl_codegen/errors/custom.ts +1633 -0
- package/src/idl_codegen/errors/index.ts +62 -0
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/deleteReferrerStateAndShortUrl.ts +30 -0
- package/src/idl_codegen/instructions/depositObligationCollateral.ts +62 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +90 -0
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +98 -0
- package/src/idl_codegen/instructions/flashBorrowReserveLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/flashRepayReserveLiquidity.ts +83 -0
- package/src/idl_codegen/instructions/idlMissingTypes.ts +62 -0
- package/src/idl_codegen/instructions/index.ts +138 -0
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/initLendingMarket.ts +50 -0
- package/src/idl_codegen/instructions/initObligation.ts +52 -0
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +60 -0
- package/src/idl_codegen/instructions/initReferrerStateAndShortUrl.ts +50 -0
- package/src/idl_codegen/instructions/initReferrerTokenState.ts +46 -0
- package/src/idl_codegen/instructions/initReserve.ts +74 -0
- package/src/idl_codegen/instructions/initUserMetadata.ts +50 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +139 -0
- package/src/idl_codegen/instructions/redeemFees.ts +50 -0
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +94 -0
- package/src/idl_codegen/instructions/refreshObligation.ts +24 -0
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/refreshReserve.ts +40 -0
- package/src/idl_codegen/instructions/refreshReservesBatch.ts +29 -0
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +64 -0
- package/src/idl_codegen/instructions/requestElevationGroup.ts +40 -0
- package/src/idl_codegen/instructions/socializeLoss.ts +48 -0
- package/src/idl_codegen/instructions/updateEntireReserveConfig.ts +45 -0
- package/src/idl_codegen/instructions/updateLendingMarket.ts +43 -0
- package/src/idl_codegen/instructions/updateLendingMarketOwner.ts +28 -0
- package/src/idl_codegen/instructions/updateReserveConfig.ts +52 -0
- package/src/idl_codegen/instructions/updateSingleReserveConfig.ts +48 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateral.ts +68 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +102 -0
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +62 -0
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +54 -0
- package/src/idl_codegen/programId.ts +13 -0
- package/src/idl_codegen/types/AssetTier.ts +118 -0
- package/src/idl_codegen/types/BigFractionBytes.ts +67 -0
- package/src/idl_codegen/types/BorrowRateCurve.ts +60 -0
- package/src/idl_codegen/types/CurvePoint.ts +64 -0
- package/src/idl_codegen/types/ElevationGroup.ts +133 -0
- package/src/idl_codegen/types/FeeCalculation.ts +90 -0
- package/src/idl_codegen/types/InitObligationArgs.ts +61 -0
- package/src/idl_codegen/types/LastUpdate.ts +95 -0
- package/src/idl_codegen/types/ObligationCollateral.ts +128 -0
- package/src/idl_codegen/types/ObligationLiquidity.ts +159 -0
- package/src/idl_codegen/types/PriceHeuristic.ts +81 -0
- package/src/idl_codegen/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen/types/ReserveConfig.ts +467 -0
- package/src/idl_codegen/types/ReserveFarmKind.ts +90 -0
- package/src/idl_codegen/types/ReserveFees.ts +122 -0
- package/src/idl_codegen/types/ReserveLiquidity.ts +286 -0
- package/src/idl_codegen/types/ReserveStatus.ts +120 -0
- package/src/idl_codegen/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen/types/SwitchboardConfiguration.ts +67 -0
- package/src/idl_codegen/types/TokenInfo.ts +190 -0
- package/src/idl_codegen/types/UpdateConfigMode.ts +1440 -0
- package/src/idl_codegen/types/UpdateLendingMarketConfigValue.ts +376 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +570 -0
- package/src/idl_codegen/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen/types/index.ts +276 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +186 -0
- package/src/idl_codegen/zero_padding/index.ts +1 -0
- package/src/idl_codegen_jupiter_perps/accounts/Pool.ts +155 -0
- package/src/idl_codegen_jupiter_perps/accounts/index.ts +2 -0
- package/src/idl_codegen_jupiter_perps/programId.ts +7 -0
- package/src/idl_codegen_jupiter_perps/types/Fees.ts +130 -0
- package/src/idl_codegen_jupiter_perps/types/Limit.ts +72 -0
- package/src/idl_codegen_jupiter_perps/types/PoolApr.ts +69 -0
- package/src/idl_codegen_jupiter_perps/types/index.ts +6 -0
- package/src/idl_codegen_kamino_vault/accounts/Reserve.ts +221 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +214 -0
- package/src/idl_codegen_kamino_vault/accounts/index.ts +4 -0
- package/src/idl_codegen_kamino_vault/errors/anchor.ts +764 -0
- package/src/idl_codegen_kamino_vault/errors/custom.ts +344 -0
- package/src/idl_codegen_kamino_vault/errors/index.ts +49 -0
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +54 -0
- package/src/idl_codegen_kamino_vault/instructions/index.ts +10 -0
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +35 -0
- package/src/idl_codegen_kamino_vault/instructions/invest.ts +60 -0
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +58 -0
- package/src/idl_codegen_kamino_vault/instructions/withdraw.ts +81 -0
- package/src/idl_codegen_kamino_vault/programId.ts +7 -0
- package/src/idl_codegen_kamino_vault/types/BigFractionBytes.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/BorrowRateCurve.ts +55 -0
- package/src/idl_codegen_kamino_vault/types/CurvePoint.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/LastUpdate.ts +90 -0
- package/src/idl_codegen_kamino_vault/types/PriceHeuristic.ts +78 -0
- package/src/idl_codegen_kamino_vault/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen_kamino_vault/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen_kamino_vault/types/ReserveConfig.ts +426 -0
- package/src/idl_codegen_kamino_vault/types/ReserveFees.ts +118 -0
- package/src/idl_codegen_kamino_vault/types/ReserveLiquidity.ts +268 -0
- package/src/idl_codegen_kamino_vault/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen_kamino_vault/types/SwitchboardConfiguration.ts +64 -0
- package/src/idl_codegen_kamino_vault/types/TokenInfo.ts +172 -0
- package/src/idl_codegen_kamino_vault/types/VaultAllocation.ts +115 -0
- package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +30 -0
- package/src/index.ts +1 -0
- package/src/lending_operations/index.ts +2 -0
- package/src/lending_operations/repay_with_collateral_calcs.ts +71 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +318 -0
- package/src/leverage/calcs.ts +465 -0
- package/src/leverage/index.ts +4 -0
- package/src/leverage/instructions.ts +144 -0
- package/src/leverage/operations.ts +1814 -0
- package/src/leverage/utils.ts +273 -0
- package/src/lib.ts +9 -0
- package/src/referrals/index.ts +2 -0
- package/src/referrals/instructions.ts +114 -0
- package/src/referrals/operations.ts +325 -0
- package/src/utils/ObligationType.ts +171 -0
- package/src/utils/api.ts +59 -0
- package/src/utils/ata.ts +195 -0
- package/src/utils/constants.ts +81 -0
- package/src/utils/idl.ts +4 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/instruction.ts +258 -0
- package/src/utils/kamino.ts +12 -0
- package/src/utils/layout.ts +118 -0
- package/src/utils/lookupTable.ts +55 -0
- package/src/utils/managerTypes.ts +456 -0
- package/src/utils/oracle.ts +338 -0
- package/src/utils/pubkey.ts +261 -0
- package/src/utils/rpc.ts +108 -0
- package/src/utils/seeds.ts +183 -0
- package/src/utils/sendTransactionsUtils.ts +207 -0
- package/src/utils/slots.ts +28 -0
- package/src/utils/syncNative.ts +22 -0
- package/src/utils/userMetadata.ts +401 -0
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
2
|
+
import {
|
|
3
|
+
AccountMeta,
|
|
4
|
+
Connection,
|
|
5
|
+
Keypair,
|
|
6
|
+
PublicKey,
|
|
7
|
+
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
8
|
+
SYSVAR_RENT_PUBKEY,
|
|
9
|
+
SystemProgram,
|
|
10
|
+
TransactionInstruction,
|
|
11
|
+
} from '@solana/web3.js';
|
|
12
|
+
import { TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
|
|
13
|
+
import {
|
|
14
|
+
getAssociatedTokenAddress,
|
|
15
|
+
getAtasWithCreateIxnsIfMissing,
|
|
16
|
+
getDepositWsolIxns,
|
|
17
|
+
getTokenOracleData,
|
|
18
|
+
KaminoReserve,
|
|
19
|
+
LendingMarket,
|
|
20
|
+
MarketWithAddress,
|
|
21
|
+
PubkeyHashMap,
|
|
22
|
+
Reserve,
|
|
23
|
+
WRAPPED_SOL_MINT,
|
|
24
|
+
} from '../lib';
|
|
25
|
+
import {
|
|
26
|
+
DepositAccounts,
|
|
27
|
+
DepositArgs,
|
|
28
|
+
initVault,
|
|
29
|
+
InitVaultAccounts,
|
|
30
|
+
invest,
|
|
31
|
+
InvestAccounts,
|
|
32
|
+
updateReserveAllocation,
|
|
33
|
+
UpdateReserveAllocationAccounts,
|
|
34
|
+
UpdateReserveAllocationArgs,
|
|
35
|
+
WithdrawAccounts,
|
|
36
|
+
WithdrawArgs,
|
|
37
|
+
} from '../idl_codegen_kamino_vault/instructions';
|
|
38
|
+
import { VaultState } from '../idl_codegen_kamino_vault/accounts';
|
|
39
|
+
import Decimal from 'decimal.js';
|
|
40
|
+
import { numberToLamportsDecimal, parseTokenSymbol } from './utils';
|
|
41
|
+
import { deposit } from '../idl_codegen_kamino_vault/instructions/deposit';
|
|
42
|
+
import { withdraw } from '../idl_codegen_kamino_vault/instructions/withdraw';
|
|
43
|
+
import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
44
|
+
import { DEFAULT_RECENT_SLOT_DURATION_MS, ReserveWithAddress } from './reserve';
|
|
45
|
+
import { Fraction } from './fraction';
|
|
46
|
+
import { lendingMarketAuthPda } from '../utils/seeds';
|
|
47
|
+
|
|
48
|
+
export const kaminoVaultId = new PublicKey('kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr');
|
|
49
|
+
|
|
50
|
+
const TOKEN_VAULT_SEED = 'token_vault';
|
|
51
|
+
const CTOKEN_VAULT_SEED = 'ctoken_vault';
|
|
52
|
+
const BASE_VAULT_AUTHORITY_SEED = 'authority';
|
|
53
|
+
const SHARES_SEEDS = 'shares';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program.
|
|
57
|
+
*/
|
|
58
|
+
export class KaminoVaultClient {
|
|
59
|
+
private readonly _connection: Connection;
|
|
60
|
+
private readonly _kaminoVaultProgramId: PublicKey;
|
|
61
|
+
private readonly _kaminoLendProgramId: PublicKey;
|
|
62
|
+
recentSlotDurationMs: number;
|
|
63
|
+
|
|
64
|
+
constructor(
|
|
65
|
+
connection: Connection,
|
|
66
|
+
kaminoVaultprogramId?: PublicKey,
|
|
67
|
+
kaminoLendProgramId?: PublicKey,
|
|
68
|
+
recentSlotDurationMs?: number
|
|
69
|
+
) {
|
|
70
|
+
this._connection = connection;
|
|
71
|
+
this._kaminoVaultProgramId = kaminoVaultprogramId ? kaminoVaultprogramId : kaminoVaultId;
|
|
72
|
+
this._kaminoLendProgramId = kaminoLendProgramId ? kaminoLendProgramId : PROGRAM_ID;
|
|
73
|
+
this.recentSlotDurationMs = recentSlotDurationMs ? recentSlotDurationMs : DEFAULT_RECENT_SLOT_DURATION_MS;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getConnection() {
|
|
77
|
+
return this._connection;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getProgramID() {
|
|
81
|
+
return this._kaminoVaultProgramId;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
|
|
86
|
+
* @param vaultConfig - the config object used to create a vault
|
|
87
|
+
* @returns vault - keypair, should be used to sign the transaction which creates the vault account
|
|
88
|
+
* @returns ixns - an array of instructions to create the vault
|
|
89
|
+
*/
|
|
90
|
+
async createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{ vault: Keypair; ixns: TransactionInstruction[] }> {
|
|
91
|
+
const vaultState = Keypair.generate();
|
|
92
|
+
const size = VaultState.layout.span + 8;
|
|
93
|
+
|
|
94
|
+
const createVaultIx = SystemProgram.createAccount({
|
|
95
|
+
fromPubkey: vaultConfig.admin,
|
|
96
|
+
newAccountPubkey: vaultState.publicKey,
|
|
97
|
+
lamports: await this._connection.getMinimumBalanceForRentExemption(size),
|
|
98
|
+
space: size,
|
|
99
|
+
programId: this._kaminoVaultProgramId,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const tokenVault = PublicKey.findProgramAddressSync(
|
|
103
|
+
[Buffer.from(TOKEN_VAULT_SEED), vaultState.publicKey.toBytes()],
|
|
104
|
+
this._kaminoVaultProgramId
|
|
105
|
+
)[0];
|
|
106
|
+
|
|
107
|
+
const baseVaultAuthority = PublicKey.findProgramAddressSync(
|
|
108
|
+
[Buffer.from(BASE_VAULT_AUTHORITY_SEED), vaultState.publicKey.toBytes()],
|
|
109
|
+
this._kaminoVaultProgramId
|
|
110
|
+
)[0];
|
|
111
|
+
|
|
112
|
+
const sharesMint = PublicKey.findProgramAddressSync(
|
|
113
|
+
[Buffer.from(SHARES_SEEDS), vaultState.publicKey.toBytes()],
|
|
114
|
+
this._kaminoVaultProgramId
|
|
115
|
+
)[0];
|
|
116
|
+
|
|
117
|
+
const initVaultAccounts: InitVaultAccounts = {
|
|
118
|
+
adminAuthority: vaultConfig.admin,
|
|
119
|
+
vaultState: vaultState.publicKey,
|
|
120
|
+
tokenMint: vaultConfig.tokenMint,
|
|
121
|
+
tokenVault,
|
|
122
|
+
baseVaultAuthority,
|
|
123
|
+
sharesMint,
|
|
124
|
+
systemProgram: SystemProgram.programId,
|
|
125
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
126
|
+
tokenProgram: vaultConfig.tokenMintProgramId,
|
|
127
|
+
};
|
|
128
|
+
const initVaultIx = initVault(initVaultAccounts, this._kaminoVaultProgramId);
|
|
129
|
+
|
|
130
|
+
// TODO: Add logic to update vault based on vaultConfig
|
|
131
|
+
|
|
132
|
+
return { vault: vaultState, ixns: [createVaultIx, initVaultIx] };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
|
|
137
|
+
* @param vault - vault to be updated
|
|
138
|
+
* @param reserveAllocationConfig - new reserve allocation config
|
|
139
|
+
* @returns - a list of instructions
|
|
140
|
+
*/
|
|
141
|
+
async updateReserveAllocationIxs(
|
|
142
|
+
vault: KaminoVault,
|
|
143
|
+
reserveAllocationConfig: ReserveAllocationConfig
|
|
144
|
+
): Promise<TransactionInstruction> {
|
|
145
|
+
const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
146
|
+
const reserveState: Reserve = reserveAllocationConfig.getReserveState();
|
|
147
|
+
|
|
148
|
+
const cTokenVault = getCTokenVaultPda(reserveAllocationConfig.getReserveAddress(), this._kaminoVaultProgramId);
|
|
149
|
+
|
|
150
|
+
const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
|
|
151
|
+
adminAuthority: vaultState.adminAuthority,
|
|
152
|
+
vaultState: vault.address,
|
|
153
|
+
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
154
|
+
reserveCollateralMint: reserveState.collateral.mintPubkey,
|
|
155
|
+
reserve: reserveAllocationConfig.getReserveAddress(),
|
|
156
|
+
ctokenVault: cTokenVault,
|
|
157
|
+
systemProgram: SystemProgram.programId,
|
|
158
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
159
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const updateReserveAllocationArgs: UpdateReserveAllocationArgs = {
|
|
163
|
+
weight: new BN(reserveAllocationConfig.targetAllocationWeight),
|
|
164
|
+
cap: new BN(reserveAllocationConfig.getAllocationCapLamports().floor().toString()),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return updateReserveAllocation(
|
|
168
|
+
updateReserveAllocationArgs,
|
|
169
|
+
updateReserveAllocationAccounts,
|
|
170
|
+
this._kaminoVaultProgramId
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
|
|
176
|
+
* @param user - user to deposit
|
|
177
|
+
* @param vault - vault to deposit into
|
|
178
|
+
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
179
|
+
* @returns - an array of instructions to be used to be executed
|
|
180
|
+
*/
|
|
181
|
+
async depositIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal): Promise<TransactionInstruction[]> {
|
|
182
|
+
const vaultState = await vault.getState(this._connection);
|
|
183
|
+
|
|
184
|
+
const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user);
|
|
185
|
+
const createAtasIxns: TransactionInstruction[] = [];
|
|
186
|
+
const closeAtasIxns: TransactionInstruction[] = [];
|
|
187
|
+
if (vaultState.tokenMint.equals(WRAPPED_SOL_MINT)) {
|
|
188
|
+
const {
|
|
189
|
+
atas: wsolAta,
|
|
190
|
+
createAtasIxns: createWsolAtaIxns,
|
|
191
|
+
closeAtasIxns: closeWsolAtaIxns,
|
|
192
|
+
} = await getAtasWithCreateIxnsIfMissing(this._connection, user, [WRAPPED_SOL_MINT], [TOKEN_PROGRAM_ID]);
|
|
193
|
+
createAtasIxns.push(...createWsolAtaIxns);
|
|
194
|
+
const depositWsolixn = getDepositWsolIxns(
|
|
195
|
+
user,
|
|
196
|
+
wsolAta[0],
|
|
197
|
+
numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).ceil()
|
|
198
|
+
);
|
|
199
|
+
createAtasIxns.push(...depositWsolixn);
|
|
200
|
+
closeAtasIxns.push(...closeWsolAtaIxns);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const { atas, createAtasIxns: createSharesAtaIxns } = await getAtasWithCreateIxnsIfMissing(
|
|
204
|
+
this._connection,
|
|
205
|
+
user,
|
|
206
|
+
[vaultState.sharesMint],
|
|
207
|
+
[TOKEN_PROGRAM_ID]
|
|
208
|
+
);
|
|
209
|
+
createAtasIxns.push(...createSharesAtaIxns);
|
|
210
|
+
|
|
211
|
+
const userSharesAta = atas[0];
|
|
212
|
+
|
|
213
|
+
const depoistAccounts: DepositAccounts = {
|
|
214
|
+
user: user,
|
|
215
|
+
vaultState: vault.address,
|
|
216
|
+
tokenVault: vaultState.tokenVault,
|
|
217
|
+
tokenMint: vaultState.tokenMint,
|
|
218
|
+
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
219
|
+
sharesMint: vaultState.sharesMint,
|
|
220
|
+
tokenAta: userTokenAta,
|
|
221
|
+
userSharesAta: userSharesAta,
|
|
222
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
223
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const depositArgs: DepositArgs = {
|
|
227
|
+
maxAmount: new BN(numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).toString()),
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const depositIx = deposit(depositArgs, depoistAccounts, this._kaminoVaultProgramId);
|
|
231
|
+
|
|
232
|
+
const vaultReserves = this.getVaultReserves(vaultState);
|
|
233
|
+
|
|
234
|
+
const vaultReservesAccountMetas: AccountMeta[] = vaultReserves.map((reserve) => {
|
|
235
|
+
return { pubkey: reserve, isSigner: false, isWritable: false };
|
|
236
|
+
});
|
|
237
|
+
depositIx.keys = depositIx.keys.concat(vaultReservesAccountMetas);
|
|
238
|
+
|
|
239
|
+
return [...createAtasIxns, depositIx, ...closeAtasIxns];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* This function will return the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
244
|
+
* @param user - user to withdraw
|
|
245
|
+
* @param vault - vault to withdraw from
|
|
246
|
+
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
247
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
248
|
+
* @returns an array of instructions to be executed
|
|
249
|
+
*/
|
|
250
|
+
async withdrawIxs(
|
|
251
|
+
user: PublicKey,
|
|
252
|
+
vault: KaminoVault,
|
|
253
|
+
shareAmount: Decimal,
|
|
254
|
+
slot: number
|
|
255
|
+
): Promise<TransactionInstruction[]> {
|
|
256
|
+
const vaultState = await vault.getState(this._connection);
|
|
257
|
+
|
|
258
|
+
const userSharesAta = getAssociatedTokenAddress(vaultState.sharesMint, user);
|
|
259
|
+
const { atas, createAtasIxns } = await getAtasWithCreateIxnsIfMissing(
|
|
260
|
+
this._connection,
|
|
261
|
+
user,
|
|
262
|
+
[vaultState.tokenMint],
|
|
263
|
+
[TOKEN_PROGRAM_ID]
|
|
264
|
+
);
|
|
265
|
+
const userTokenAta = atas[0];
|
|
266
|
+
|
|
267
|
+
const tokensToWithdraw = shareAmount.div(await this.getTokensPerShareSingleVault(vault, slot));
|
|
268
|
+
let tokenLeftToWithdraw = tokensToWithdraw;
|
|
269
|
+
|
|
270
|
+
tokenLeftToWithdraw = tokenLeftToWithdraw.sub(new Decimal(vaultState.tokenAvailable.toString()));
|
|
271
|
+
|
|
272
|
+
const reservesToWithdraw: PublicKey[] = [];
|
|
273
|
+
const amountToWithdraw: Decimal[] = [];
|
|
274
|
+
amountToWithdraw.push(new Decimal(vaultState.tokenAvailable.toString()));
|
|
275
|
+
|
|
276
|
+
if (tokenLeftToWithdraw.lte(0)) {
|
|
277
|
+
// Availabe enough to withdraw all - using first reserve as it does not matter
|
|
278
|
+
reservesToWithdraw.push(vaultState.vaultAllocationStrategy[0].reserve);
|
|
279
|
+
} else {
|
|
280
|
+
// Get decreasing order sorted available liquidity to withdraw from each reserve allocated to
|
|
281
|
+
const reserveAllocationAvailableLiquidityToWithdraw = await this.getReserveAllocationAvailableLiquidityToWithdraw(
|
|
282
|
+
vault,
|
|
283
|
+
slot
|
|
284
|
+
);
|
|
285
|
+
// sort
|
|
286
|
+
const reserveAllocationAvailableLiquidityToWithdrawSorted = new PubkeyHashMap(
|
|
287
|
+
[...reserveAllocationAvailableLiquidityToWithdraw.entries()].sort((a, b) => b[1].sub(a[1]).toNumber())
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
reserveAllocationAvailableLiquidityToWithdrawSorted.forEach((availableLiquidityToWithdraw, key) => {
|
|
291
|
+
if (tokenLeftToWithdraw.gt(0)) {
|
|
292
|
+
reservesToWithdraw.push(key);
|
|
293
|
+
tokenLeftToWithdraw = tokenLeftToWithdraw.sub(availableLiquidityToWithdraw);
|
|
294
|
+
amountToWithdraw.push(Decimal.min(tokenLeftToWithdraw, availableLiquidityToWithdraw));
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const reserveStates = await Reserve.fetchMultiple(this._connection, reservesToWithdraw, this._kaminoLendProgramId);
|
|
300
|
+
const withdrawIxns: TransactionInstruction[] = await Promise.all(
|
|
301
|
+
reservesToWithdraw.map(async (reserve, index) => {
|
|
302
|
+
if (reserveStates[index] === null) {
|
|
303
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const reserveState = reserveStates[index]!;
|
|
307
|
+
|
|
308
|
+
const market = reserveState.lendingMarket;
|
|
309
|
+
const marketState = await LendingMarket.fetch(this._connection, market, this._kaminoLendProgramId);
|
|
310
|
+
if (marketState === null) {
|
|
311
|
+
throw new Error(`Market ${market.toBase58()} not found`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const marketWithAddress = {
|
|
315
|
+
address: market,
|
|
316
|
+
state: marketState,
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
return this.withdrawIxn(
|
|
320
|
+
user,
|
|
321
|
+
vault,
|
|
322
|
+
vaultState,
|
|
323
|
+
marketWithAddress,
|
|
324
|
+
{ address: reserve, state: reserveState },
|
|
325
|
+
userSharesAta,
|
|
326
|
+
userTokenAta,
|
|
327
|
+
amountToWithdraw[index]
|
|
328
|
+
);
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
return [...createAtasIxns, ...withdrawIxns];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
|
|
337
|
+
* @param kaminoVault - vault to invest from
|
|
338
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
339
|
+
*/
|
|
340
|
+
async investAllReservesIxs(vault: KaminoVault): Promise<TransactionInstruction[]> {
|
|
341
|
+
//TODO: Order invest ixns by - invest that removes first, then invest that adds
|
|
342
|
+
|
|
343
|
+
const vaultState = await vault.getState(this._connection);
|
|
344
|
+
const vaultReserves = this.getVaultReserves(vaultState);
|
|
345
|
+
const investIxns: TransactionInstruction[] = [];
|
|
346
|
+
for (const reserve of vaultReserves) {
|
|
347
|
+
const reserveState = await Reserve.fetch(this._connection, reserve, this._kaminoLendProgramId);
|
|
348
|
+
if (reserveState === null) {
|
|
349
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
350
|
+
}
|
|
351
|
+
investIxns.push(await this.investSingleReserveIxs(vault, { address: reserve, state: reserveState }));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return investIxns;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it
|
|
359
|
+
* @param kaminoVault - vault to invest from
|
|
360
|
+
* @param reserve - reserve to invest into or disinvest from
|
|
361
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
362
|
+
*/
|
|
363
|
+
async investSingleReserveIxs(vault: KaminoVault, reserve: ReserveWithAddress): Promise<TransactionInstruction> {
|
|
364
|
+
const vaultState = await vault.getState(this._connection);
|
|
365
|
+
|
|
366
|
+
const cTokenVault = getCTokenVaultPda(reserve.address, this._kaminoVaultProgramId);
|
|
367
|
+
const lendingMarketAuth = lendingMarketAuthPda(reserve.state.lendingMarket, this._kaminoLendProgramId)[0];
|
|
368
|
+
|
|
369
|
+
const investAccounts: InvestAccounts = {
|
|
370
|
+
adminAuthority: vaultState.adminAuthority,
|
|
371
|
+
vaultState: vault.address,
|
|
372
|
+
tokenVault: vaultState.tokenVault,
|
|
373
|
+
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
374
|
+
ctokenVault: cTokenVault,
|
|
375
|
+
reserve: reserve.address,
|
|
376
|
+
/** CPI accounts */
|
|
377
|
+
lendingMarket: reserve.state.lendingMarket,
|
|
378
|
+
lendingMarketAuthority: lendingMarketAuth,
|
|
379
|
+
reserveLiquiditySupply: reserve.state.liquidity.supplyVault,
|
|
380
|
+
reserveCollateralMint: reserve.state.collateral.mintPubkey,
|
|
381
|
+
klendProgram: this._kaminoLendProgramId,
|
|
382
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
383
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const investIx = invest(investAccounts, this._kaminoVaultProgramId);
|
|
387
|
+
|
|
388
|
+
const vaultReserves = this.getVaultReserves(vaultState);
|
|
389
|
+
const vaultReservesAccountMetas: AccountMeta[] = vaultReserves.map((reserve) => {
|
|
390
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
391
|
+
});
|
|
392
|
+
investIx.keys = investIx.keys.concat(vaultReservesAccountMetas);
|
|
393
|
+
|
|
394
|
+
return investIx;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private withdrawIxn(
|
|
398
|
+
user: PublicKey,
|
|
399
|
+
vault: KaminoVault,
|
|
400
|
+
vaultState: VaultState,
|
|
401
|
+
marketWithAddress: MarketWithAddress,
|
|
402
|
+
reserve: ReserveWithAddress,
|
|
403
|
+
userSharesAta: PublicKey,
|
|
404
|
+
userTokenAta: PublicKey,
|
|
405
|
+
shareAmountLamports: Decimal
|
|
406
|
+
): TransactionInstruction {
|
|
407
|
+
const lendingMarketAuth = lendingMarketAuthPda(marketWithAddress.address, this._kaminoLendProgramId)[0];
|
|
408
|
+
|
|
409
|
+
const withdrawAccounts: WithdrawAccounts = {
|
|
410
|
+
user: user,
|
|
411
|
+
vaultState: vault.address,
|
|
412
|
+
tokenVault: vaultState.tokenVault,
|
|
413
|
+
tokenMint: vaultState.tokenMint,
|
|
414
|
+
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
415
|
+
sharesMint: vaultState.sharesMint,
|
|
416
|
+
userSharesAta: userSharesAta,
|
|
417
|
+
tokenAta: userTokenAta,
|
|
418
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
419
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
420
|
+
reserve: reserve.address,
|
|
421
|
+
ctokenVault: getCTokenVaultPda(reserve.address, this._kaminoVaultProgramId),
|
|
422
|
+
/** CPI accounts */
|
|
423
|
+
lendingMarket: marketWithAddress.address,
|
|
424
|
+
lendingMarketAuthority: lendingMarketAuth,
|
|
425
|
+
reserveLiquiditySupply: reserve.state.liquidity.supplyVault,
|
|
426
|
+
reserveCollateralMint: reserve.state.collateral.mintPubkey,
|
|
427
|
+
klendProgram: this._kaminoLendProgramId,
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const withdrawArgs: WithdrawArgs = {
|
|
431
|
+
sharesAmount: new BN(shareAmountLamports.toString()),
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const withdrawIxn = withdraw(withdrawArgs, withdrawAccounts, this._kaminoVaultProgramId);
|
|
435
|
+
|
|
436
|
+
const vaultReserves = this.getVaultReserves(vaultState);
|
|
437
|
+
const vaultReservesAccountMetas: AccountMeta[] = vaultReserves.map((reserve) => {
|
|
438
|
+
return { pubkey: reserve, isSigner: false, isWritable: false };
|
|
439
|
+
});
|
|
440
|
+
withdrawIxn.keys = withdrawIxn.keys.concat(vaultReservesAccountMetas);
|
|
441
|
+
|
|
442
|
+
return withdrawIxn;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* This method returns the user shares balance for a given vault
|
|
447
|
+
* @param user - user to calculate the shares balance for
|
|
448
|
+
* @param vault - vault to calculate shares balance for
|
|
449
|
+
* @returns - user share balance in decimal (not lamports)
|
|
450
|
+
*/
|
|
451
|
+
async getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<Decimal> {
|
|
452
|
+
const vaultState = await vault.getState(this._connection);
|
|
453
|
+
const userSharesAta = getAssociatedTokenAddress(vaultState.sharesMint, user);
|
|
454
|
+
const userSharesAccountInfo = await this._connection.getAccountInfo(userSharesAta);
|
|
455
|
+
if (!userSharesAccountInfo) {
|
|
456
|
+
return new Decimal(0);
|
|
457
|
+
}
|
|
458
|
+
const userSharesAccount = unpackAccount(userSharesAta, userSharesAccountInfo);
|
|
459
|
+
|
|
460
|
+
return new Decimal(new Decimal(userSharesAccount.amount.toString()).toNumber()).div(
|
|
461
|
+
new Decimal(10).pow(vaultState.sharesMintDecimals.toNumber())
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* This method returns the user shares balance for all existing vaults
|
|
467
|
+
* @param user - user to calculate the shares balance for
|
|
468
|
+
* @param vaultsOverride - the kamino vaults if already fetched, in order to reduce rpc calls
|
|
469
|
+
* @returns - hash map with keyh as vault address and value as user share balance in decimal (not lamports)
|
|
470
|
+
*/
|
|
471
|
+
async getUserSharesBalanceAllVaults(
|
|
472
|
+
user: PublicKey,
|
|
473
|
+
vaultsOverride?: Array<KaminoVault>
|
|
474
|
+
): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
475
|
+
const vaults = vaultsOverride ? vaultsOverride : await this.getAllVaults();
|
|
476
|
+
// stores vault address for each userSharesAta
|
|
477
|
+
const vaultUserShareBalance = new PubkeyHashMap<PublicKey, Decimal>();
|
|
478
|
+
const userSharesAtaArray: PublicKey[] = [];
|
|
479
|
+
vaults.forEach((vault) => {
|
|
480
|
+
const state = vault.state;
|
|
481
|
+
if (!state) {
|
|
482
|
+
throw new Error(`Vault ${vault.address.toBase58()} not fetched`);
|
|
483
|
+
}
|
|
484
|
+
const userSharesAta = getAssociatedTokenAddress(state.sharesMint, user);
|
|
485
|
+
userSharesAtaArray.push(userSharesAta);
|
|
486
|
+
});
|
|
487
|
+
const userSharesAtaAccounts = await this._connection.getMultipleAccountsInfo(userSharesAtaArray);
|
|
488
|
+
|
|
489
|
+
userSharesAtaAccounts.forEach((userShareAtaAccount, index) => {
|
|
490
|
+
if (!userShareAtaAccount) {
|
|
491
|
+
vaultUserShareBalance.set(vaults[index].address, new Decimal(0));
|
|
492
|
+
} else {
|
|
493
|
+
vaultUserShareBalance.set(
|
|
494
|
+
vaults[index].address,
|
|
495
|
+
new Decimal(userShareAtaAccount.lamports).div(
|
|
496
|
+
new Decimal(10).pow(vaults[index].state!.sharesMintDecimals.toNumber())
|
|
497
|
+
)
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
return vaultUserShareBalance;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* This method calculates the token per shar value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
|
|
507
|
+
* @param vault - vault to calculate tokensPerShare for
|
|
508
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
509
|
+
* @returns - token per share value
|
|
510
|
+
*/
|
|
511
|
+
async getTokensPerShareSingleVault(vault: KaminoVault, slot: number): Promise<Decimal> {
|
|
512
|
+
const vaultState = await vault.getState(this._connection);
|
|
513
|
+
const reserves = await this.loadVaultReserves(vaultState);
|
|
514
|
+
|
|
515
|
+
const totalVaultLiquidityAmount = new Decimal(vaultState.tokenAvailable.toString());
|
|
516
|
+
vaultState.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
517
|
+
if (!allocationStrategy.reserve.equals(PublicKey.default)) {
|
|
518
|
+
const reserve = reserves.get(allocationStrategy.reserve);
|
|
519
|
+
if (reserve === undefined) {
|
|
520
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
521
|
+
}
|
|
522
|
+
const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(
|
|
523
|
+
slot,
|
|
524
|
+
new Fraction(reserve.state.liquidity.absoluteReferralRateSf)
|
|
525
|
+
.toDecimal()
|
|
526
|
+
.div(reserve.state.config.protocolTakeRatePct / 100)
|
|
527
|
+
.floor()
|
|
528
|
+
.toNumber()
|
|
529
|
+
);
|
|
530
|
+
const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.cTokenAllocation.toString()).div(
|
|
531
|
+
reserveCollExchangeRate
|
|
532
|
+
);
|
|
533
|
+
totalVaultLiquidityAmount.add(reserveAllocationLiquidityAmount);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
return new Decimal(vaultState.sharesIssued.toString()).div(totalVaultLiquidityAmount);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
|
|
542
|
+
* @param vault - vault to calculate tokensPerShare for
|
|
543
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
544
|
+
* @returns - token per share value
|
|
545
|
+
*/
|
|
546
|
+
async getTokensPerShareAllVaults(
|
|
547
|
+
slot: number,
|
|
548
|
+
vaultsOverride?: Array<KaminoVault>
|
|
549
|
+
): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
550
|
+
const vaults = vaultsOverride ? vaultsOverride : await this.getAllVaults();
|
|
551
|
+
const vaultTokensPerShare = new PubkeyHashMap<PublicKey, Decimal>();
|
|
552
|
+
vaults.forEach(async (vault) => {
|
|
553
|
+
const vaultState = vault.state;
|
|
554
|
+
if (!vaultState) {
|
|
555
|
+
throw new Error(`Vault ${vault.address.toBase58()} not fetched`);
|
|
556
|
+
}
|
|
557
|
+
const reserves = await this.loadVaultReserves(vaultState);
|
|
558
|
+
|
|
559
|
+
const totalVaultLiquidityAmount = new Decimal(vaultState.tokenAvailable.toString());
|
|
560
|
+
vaultState.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
561
|
+
if (!allocationStrategy.reserve.equals(PublicKey.default)) {
|
|
562
|
+
const reserve = reserves.get(allocationStrategy.reserve);
|
|
563
|
+
if (reserve === undefined) {
|
|
564
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
565
|
+
}
|
|
566
|
+
const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(
|
|
567
|
+
slot,
|
|
568
|
+
new Fraction(reserve.state.liquidity.absoluteReferralRateSf)
|
|
569
|
+
.toDecimal()
|
|
570
|
+
.div(reserve.state.config.protocolTakeRatePct / 100)
|
|
571
|
+
.floor()
|
|
572
|
+
.toNumber()
|
|
573
|
+
);
|
|
574
|
+
const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.cTokenAllocation.toString()).div(
|
|
575
|
+
reserveCollExchangeRate
|
|
576
|
+
);
|
|
577
|
+
totalVaultLiquidityAmount.add(reserveAllocationLiquidityAmount);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
vaultTokensPerShare.set(
|
|
581
|
+
vault.address,
|
|
582
|
+
new Decimal(vaultState.sharesIssued.toString()).div(totalVaultLiquidityAmount)
|
|
583
|
+
);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
return vaultTokensPerShare;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* This will return an unsorted hash map of all reserves that the given vault has allocations for, toghether with the amount that can be withdrawn from each of the reserves
|
|
591
|
+
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
592
|
+
* @param slot - current slot
|
|
593
|
+
* @returns an HashMap of reserves (key) with the amount available to withdraw for each (value)
|
|
594
|
+
*/
|
|
595
|
+
private async getReserveAllocationAvailableLiquidityToWithdraw(
|
|
596
|
+
vault: KaminoVault,
|
|
597
|
+
slot: number
|
|
598
|
+
): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
599
|
+
const vaultState = await vault.getState(this._connection);
|
|
600
|
+
const reserves = await this.loadVaultReserves(vaultState);
|
|
601
|
+
|
|
602
|
+
const reserveAllocationAvailableLiquidityToWithdraw = new PubkeyHashMap<PublicKey, Decimal>();
|
|
603
|
+
vaultState.vaultAllocationStrategy.forEach((allocationStrategy) => {
|
|
604
|
+
const reserve = reserves.get(allocationStrategy.reserve);
|
|
605
|
+
if (reserve === undefined) {
|
|
606
|
+
throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
|
|
607
|
+
}
|
|
608
|
+
const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(
|
|
609
|
+
slot,
|
|
610
|
+
new Fraction(reserve.state.liquidity.absoluteReferralRateSf)
|
|
611
|
+
.toDecimal()
|
|
612
|
+
.div(reserve.state.config.protocolTakeRatePct / 100)
|
|
613
|
+
.floor()
|
|
614
|
+
.toNumber()
|
|
615
|
+
);
|
|
616
|
+
const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.cTokenAllocation.toString()).div(
|
|
617
|
+
reserveCollExchangeRate
|
|
618
|
+
);
|
|
619
|
+
const reserveAvailableLiquidityAmount = reserve.getLiquidityAvailableAmount();
|
|
620
|
+
reserveAllocationAvailableLiquidityToWithdraw.set(
|
|
621
|
+
allocationStrategy.reserve,
|
|
622
|
+
Decimal.min(reserveAllocationLiquidityAmount, reserveAvailableLiquidityAmount)
|
|
623
|
+
);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
return reserveAllocationAvailableLiquidityToWithdraw;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
private getVaultReserves(vault: VaultState): PublicKey[] {
|
|
630
|
+
return vault.vaultAllocationStrategy
|
|
631
|
+
.filter((vaultAllocation) => !vaultAllocation.reserve.equals(PublicKey.default))
|
|
632
|
+
.map((vaultAllocation) => vaultAllocation.reserve);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
private async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
|
|
636
|
+
const vaultReservesAddresses = this.getVaultReserves(vaultState);
|
|
637
|
+
const reserveAccounts = await this._connection.getMultipleAccountsInfo(vaultReservesAddresses, 'processed');
|
|
638
|
+
|
|
639
|
+
const deserializedReserves = reserveAccounts.map((reserve, i) => {
|
|
640
|
+
if (reserve === null) {
|
|
641
|
+
// maybe reuse old here
|
|
642
|
+
throw new Error(`Reserve account ${vaultReservesAddresses[i].toBase58()} was not found`);
|
|
643
|
+
}
|
|
644
|
+
const reserveAccount = Reserve.decode(reserve.data);
|
|
645
|
+
if (!reserveAccount) {
|
|
646
|
+
throw Error(`Could not parse reserve ${vaultReservesAddresses[i].toBase58()}`);
|
|
647
|
+
}
|
|
648
|
+
return reserveAccount;
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
const reservesAndOracles = await getTokenOracleData(this._connection, deserializedReserves);
|
|
652
|
+
|
|
653
|
+
const kaminoReserves = new PubkeyHashMap<PublicKey, KaminoReserve>();
|
|
654
|
+
|
|
655
|
+
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
656
|
+
if (!oracle) {
|
|
657
|
+
throw Error(`Could not find oracle for ${parseTokenSymbol(reserve.config.tokenInfo.name)} reserve`);
|
|
658
|
+
}
|
|
659
|
+
const kaminoReserve = KaminoReserve.initialize(
|
|
660
|
+
reserveAccounts[index]!,
|
|
661
|
+
vaultReservesAddresses[index],
|
|
662
|
+
reserve,
|
|
663
|
+
oracle,
|
|
664
|
+
this._connection,
|
|
665
|
+
this.recentSlotDurationMs
|
|
666
|
+
);
|
|
667
|
+
kaminoReserves.set(kaminoReserve.address, kaminoReserve);
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
return kaminoReserves;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Get all vaults
|
|
675
|
+
* @returns an array of all vaults
|
|
676
|
+
*/
|
|
677
|
+
async getAllVaults(): Promise<KaminoVault[]> {
|
|
678
|
+
const { getProgramAccounts } = await import('../utils/rpc');
|
|
679
|
+
const filters = [
|
|
680
|
+
{
|
|
681
|
+
dataSize: VaultState.layout.span + 8,
|
|
682
|
+
},
|
|
683
|
+
];
|
|
684
|
+
|
|
685
|
+
const [, kaminoVaults] = await Promise.all([
|
|
686
|
+
this._connection.getSlot(),
|
|
687
|
+
getProgramAccounts(this._connection, this._kaminoVaultProgramId, {
|
|
688
|
+
commitment: this._connection.commitment ?? 'processed',
|
|
689
|
+
filters,
|
|
690
|
+
}),
|
|
691
|
+
]);
|
|
692
|
+
|
|
693
|
+
return kaminoVaults.map((kaminoVault) => {
|
|
694
|
+
if (kaminoVault.account === null) {
|
|
695
|
+
throw new Error('Invalid account');
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const kaminoVaultAccount = VaultState.decode(kaminoVault.account.data);
|
|
699
|
+
if (!kaminoVaultAccount) {
|
|
700
|
+
throw Error('Could not parse obligation.');
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return new KaminoVault(kaminoVault.pubkey, kaminoVaultAccount, this._kaminoVaultProgramId);
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
} // KaminoVaultClient
|
|
707
|
+
|
|
708
|
+
export class KaminoVault {
|
|
709
|
+
readonly address: PublicKey;
|
|
710
|
+
state: VaultState | undefined | null;
|
|
711
|
+
programId: PublicKey;
|
|
712
|
+
|
|
713
|
+
constructor(vaultAddress: PublicKey, state?: VaultState, programId: PublicKey = kaminoVaultId) {
|
|
714
|
+
this.address = vaultAddress;
|
|
715
|
+
this.state = state;
|
|
716
|
+
this.programId = programId;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
async getState(connection: Connection): Promise<VaultState> {
|
|
720
|
+
if (!this.state) {
|
|
721
|
+
const res = await VaultState.fetch(connection, this.address, this.programId);
|
|
722
|
+
if (!res) {
|
|
723
|
+
throw new Error('Invalid vault');
|
|
724
|
+
}
|
|
725
|
+
this.state = res;
|
|
726
|
+
return res;
|
|
727
|
+
} else {
|
|
728
|
+
return this.state;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
async reloadState(connection: Connection): Promise<VaultState> {
|
|
733
|
+
this.state = await VaultState.fetch(connection, this.address, this.programId);
|
|
734
|
+
if (!this.state) {
|
|
735
|
+
throw new Error('Could not fetch vault');
|
|
736
|
+
}
|
|
737
|
+
return this.state;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Used to initialize a Kamino Vault
|
|
743
|
+
*/
|
|
744
|
+
export class KaminoVaultConfig {
|
|
745
|
+
/** The admin of the vault */
|
|
746
|
+
readonly admin: PublicKey;
|
|
747
|
+
/** The token mint for the vault */
|
|
748
|
+
readonly tokenMint: PublicKey;
|
|
749
|
+
/** The token mint program id */
|
|
750
|
+
readonly tokenMintProgramId: PublicKey;
|
|
751
|
+
/** The performance fee rate of the vault, expressed as a decimal */
|
|
752
|
+
readonly performanceFeeRate: Decimal;
|
|
753
|
+
/** The management fee rate of the vault, expressed as a decimal */
|
|
754
|
+
readonly managementFeeRate: Decimal;
|
|
755
|
+
|
|
756
|
+
constructor(args: {
|
|
757
|
+
admin: PublicKey;
|
|
758
|
+
tokenMint: PublicKey;
|
|
759
|
+
tokenMintProgramId: PublicKey;
|
|
760
|
+
performanceFeeRate: Decimal;
|
|
761
|
+
managementFeeRate: Decimal;
|
|
762
|
+
}) {
|
|
763
|
+
this.admin = args.admin;
|
|
764
|
+
this.tokenMint = args.tokenMint;
|
|
765
|
+
this.performanceFeeRate = args.performanceFeeRate;
|
|
766
|
+
this.managementFeeRate = args.managementFeeRate;
|
|
767
|
+
this.tokenMintProgramId = args.tokenMintProgramId;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
getPerformanceFeeBps(): number {
|
|
771
|
+
return this.performanceFeeRate.mul(10000).toNumber();
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
getManagementFeeRate(): number {
|
|
775
|
+
return this.managementFeeRate.mul(10000).toNumber();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export class ReserveAllocationConfig {
|
|
780
|
+
readonly reserve: ReserveWithAddress;
|
|
781
|
+
readonly targetAllocationWeight: number;
|
|
782
|
+
readonly allocationCapDecimal: Decimal;
|
|
783
|
+
|
|
784
|
+
constructor(reserve: ReserveWithAddress, targetAllocationWeight: number, allocationCapDecimal: Decimal) {
|
|
785
|
+
this.reserve = reserve;
|
|
786
|
+
this.targetAllocationWeight = targetAllocationWeight;
|
|
787
|
+
this.allocationCapDecimal = allocationCapDecimal;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
getAllocationCapLamports(): Decimal {
|
|
791
|
+
return numberToLamportsDecimal(this.allocationCapDecimal, this.reserve.state.liquidity.mintDecimals.toNumber());
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
getReserveState(): Reserve {
|
|
795
|
+
return this.reserve.state;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
getReserveAddress(): PublicKey {
|
|
799
|
+
return this.reserve.address;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
export function getCTokenVaultPda(reserveAddress: PublicKey, kaminoVaultProgramId: PublicKey) {
|
|
804
|
+
return PublicKey.findProgramAddressSync(
|
|
805
|
+
[Buffer.from(CTOKEN_VAULT_SEED), reserveAddress.toBytes()],
|
|
806
|
+
kaminoVaultProgramId
|
|
807
|
+
)[0];
|
|
808
|
+
}
|