@kamino-finance/klend-sdk 3.2.26 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +1 -0
- package/dist/classes/action.d.ts.map +1 -0
- package/dist/classes/action.js +1132 -1188
- 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 +132 -159
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +2 -1
- package/dist/classes/market.d.ts.map +1 -0
- package/dist/classes/market.js +622 -716
- 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 +121 -130
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +2 -1
- 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 +32 -3
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +2 -1
- package/dist/utils/oracle.d.ts.map +1 -0
- package/dist/utils/oracle.js +71 -85
- 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 +41 -53
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +14 -8
- 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 +337 -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
package/dist/classes/action.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,21 +12,54 @@ const instructions_1 = require("../idl_codegen/instructions");
|
|
|
21
12
|
const utils_1 = require("../utils");
|
|
22
13
|
const obligation_1 = require("./obligation");
|
|
23
14
|
const types_1 = require("../idl_codegen/types");
|
|
24
|
-
const farms_sdk_1 = require("@
|
|
15
|
+
const farms_sdk_1 = require("@kamino-finance/farms-sdk");
|
|
25
16
|
const ObligationType_1 = require("../utils/ObligationType");
|
|
26
17
|
const lib_1 = require("../lib");
|
|
27
|
-
const scope_sdk_1 = require("@
|
|
18
|
+
const scope_sdk_1 = require("@kamino-finance/scope-sdk");
|
|
28
19
|
exports.POSITION_LIMIT = 10;
|
|
29
20
|
exports.BORROWS_LIMIT = 5;
|
|
30
21
|
exports.DEPOSITS_LIMIT = 8;
|
|
31
22
|
const SOL_PADDING_FOR_INTEREST = new bn_js_1.default('1000000');
|
|
32
23
|
class KaminoAction {
|
|
24
|
+
kaminoMarket;
|
|
25
|
+
reserve;
|
|
26
|
+
outflowReserve;
|
|
27
|
+
owner;
|
|
28
|
+
payer;
|
|
29
|
+
obligation = null;
|
|
30
|
+
referrer;
|
|
31
|
+
userTokenAccountAddress;
|
|
32
|
+
userCollateralAccountAddress;
|
|
33
|
+
additionalTokenAccountAddress;
|
|
34
|
+
/**
|
|
35
|
+
* Null unless the obligation is not passed
|
|
36
|
+
*/
|
|
37
|
+
obligationType = null;
|
|
38
|
+
mint;
|
|
39
|
+
secondaryMint;
|
|
40
|
+
positions;
|
|
41
|
+
amount;
|
|
42
|
+
outflowAmount;
|
|
43
|
+
setupIxs;
|
|
44
|
+
setupIxsLabels;
|
|
45
|
+
inBetweenIxs;
|
|
46
|
+
inBetweenIxsLabels;
|
|
47
|
+
lendingIxs;
|
|
48
|
+
lendingIxsLabels;
|
|
49
|
+
cleanupIxs;
|
|
50
|
+
cleanupIxsLabels;
|
|
51
|
+
preTxnIxs;
|
|
52
|
+
preTxnIxsLabels;
|
|
53
|
+
postTxnIxs;
|
|
54
|
+
postTxnIxsLabels;
|
|
55
|
+
refreshFarmsCleanupTxnIxs;
|
|
56
|
+
refreshFarmsCleanupTxnIxsLabels;
|
|
57
|
+
depositReserves;
|
|
58
|
+
borrowReserves;
|
|
59
|
+
preLoadedDepositReservesSameTx;
|
|
60
|
+
preLoadedBorrowReservesSameTx;
|
|
61
|
+
currentSlot;
|
|
33
62
|
constructor(kaminoMarket, owner, obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, positions, amount, depositReserves, borrowReserves, reserveState, currentSlot, secondaryMint, additionalTokenAccountAddress, outflowReserveState, outflowAmount, referrer, payer) {
|
|
34
|
-
this.obligation = null;
|
|
35
|
-
/**
|
|
36
|
-
* Null unless the obligation is not passed
|
|
37
|
-
*/
|
|
38
|
-
this.obligationType = null;
|
|
39
63
|
if (obligation instanceof obligation_1.KaminoObligation) {
|
|
40
64
|
this.obligation = obligation;
|
|
41
65
|
}
|
|
@@ -44,7 +68,7 @@ class KaminoAction {
|
|
|
44
68
|
}
|
|
45
69
|
this.kaminoMarket = kaminoMarket;
|
|
46
70
|
this.owner = owner;
|
|
47
|
-
this.payer = payer
|
|
71
|
+
this.payer = payer ?? owner;
|
|
48
72
|
this.amount = new bn_js_1.default(amount);
|
|
49
73
|
this.mint = mint;
|
|
50
74
|
this.positions = positions;
|
|
@@ -76,123 +100,113 @@ class KaminoAction {
|
|
|
76
100
|
this.referrer = referrer ? referrer : web3_js_1.PublicKey.default;
|
|
77
101
|
this.currentSlot = currentSlot;
|
|
78
102
|
}
|
|
79
|
-
static initialize(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, undefined, referrerKey, payer);
|
|
89
|
-
});
|
|
103
|
+
static async initialize(action, amount, mint, owner, kaminoMarket, obligation, referrer = web3_js_1.PublicKey.default, currentSlot = 0, payer) {
|
|
104
|
+
const reserve = kaminoMarket.getReserveByMint(mint);
|
|
105
|
+
if (reserve === undefined) {
|
|
106
|
+
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
107
|
+
}
|
|
108
|
+
const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer ?? owner, reserve.state);
|
|
109
|
+
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
|
|
110
|
+
const referrerKey = await this.getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer);
|
|
111
|
+
return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, undefined, referrerKey, payer);
|
|
90
112
|
}
|
|
91
113
|
static getUserAccountAddresses(owner, reserve) {
|
|
92
114
|
const userTokenAccountAddress = (0, utils_1.getAssociatedTokenAddress)(reserve.liquidity.mintPubkey, owner, true, reserve.liquidity.tokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
93
115
|
const userCollateralAccountAddress = (0, utils_1.getAssociatedTokenAddress)(reserve.collateral.mintPubkey, owner, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
94
116
|
return { userTokenAccountAddress, userCollateralAccountAddress };
|
|
95
117
|
}
|
|
96
|
-
static loadObligation(action, kaminoMarket, owner, reserve, obligation, outflowReserve) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
135
|
-
});
|
|
118
|
+
static async loadObligation(action, kaminoMarket, owner, reserve, obligation, outflowReserve) {
|
|
119
|
+
let kaminoObligation;
|
|
120
|
+
const depositReserves = [];
|
|
121
|
+
const borrowReserves = [];
|
|
122
|
+
if (obligation instanceof obligation_1.KaminoObligation) {
|
|
123
|
+
kaminoObligation = obligation;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const obligationAddress = obligation.toPda(kaminoMarket.getAddress(), owner);
|
|
127
|
+
kaminoObligation = await obligation_1.KaminoObligation.load(kaminoMarket, obligationAddress);
|
|
128
|
+
}
|
|
129
|
+
if (kaminoObligation !== null) {
|
|
130
|
+
depositReserves.push(...[...kaminoObligation.deposits.keys()]);
|
|
131
|
+
borrowReserves.push(...[...kaminoObligation.borrows.keys()]);
|
|
132
|
+
}
|
|
133
|
+
if (!outflowReserve && action === 'depositAndBorrow') {
|
|
134
|
+
throw new Error(`Outflow reserve has not been set for depositAndBorrow`);
|
|
135
|
+
}
|
|
136
|
+
// Union of addresses
|
|
137
|
+
const distinctReserveCount = new utils_1.PublicKeySet([
|
|
138
|
+
...borrowReserves.map((e) => e),
|
|
139
|
+
...(action === 'borrow' ? [reserve] : []),
|
|
140
|
+
...(action === 'depositAndBorrow' ? [reserve] : []),
|
|
141
|
+
]).toArray().length +
|
|
142
|
+
new utils_1.PublicKeySet([
|
|
143
|
+
...depositReserves.map((e) => e),
|
|
144
|
+
...(action === 'deposit' ? [reserve] : []),
|
|
145
|
+
...(action === 'depositAndBorrow' ? [outflowReserve] : []),
|
|
146
|
+
]).toArray().length;
|
|
147
|
+
if (distinctReserveCount > exports.POSITION_LIMIT) {
|
|
148
|
+
throw Error(`Obligation already has max number of positions: ${exports.POSITION_LIMIT}`);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
kaminoObligation,
|
|
152
|
+
depositReserves,
|
|
153
|
+
borrowReserves,
|
|
154
|
+
distinctReserveCount,
|
|
155
|
+
};
|
|
136
156
|
}
|
|
137
|
-
static buildRefreshObligationTxns(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return axn;
|
|
152
|
-
});
|
|
157
|
+
static async buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
158
|
+
currentSlot = 0) {
|
|
159
|
+
// placeholder for action initialization
|
|
160
|
+
const firstReserve = obligation.state.deposits[0].depositReserve;
|
|
161
|
+
const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
|
|
162
|
+
if (!firstKaminoReserve) {
|
|
163
|
+
throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
|
|
164
|
+
}
|
|
165
|
+
const axn = await KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve?.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
|
|
166
|
+
if (extraComputeBudget > 0) {
|
|
167
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
168
|
+
}
|
|
169
|
+
axn.addRefreshObligation(payer);
|
|
170
|
+
return axn;
|
|
153
171
|
}
|
|
154
|
-
static buildRequestElevationGroupTxns(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return axn;
|
|
169
|
-
});
|
|
172
|
+
static async buildRequestElevationGroupTxns(kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
173
|
+
currentSlot = 0) {
|
|
174
|
+
const firstReserve = obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
175
|
+
const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
|
|
176
|
+
if (!firstKaminoReserve) {
|
|
177
|
+
throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
|
|
178
|
+
}
|
|
179
|
+
const axn = await KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve?.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
|
|
180
|
+
if (extraComputeBudget > 0) {
|
|
181
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
182
|
+
}
|
|
183
|
+
axn.addRefreshObligation(payer);
|
|
184
|
+
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
185
|
+
return axn;
|
|
170
186
|
}
|
|
171
|
-
static buildDepositTxns(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return axn;
|
|
195
|
-
});
|
|
187
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
188
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
189
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
190
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
191
|
+
) {
|
|
192
|
+
const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
193
|
+
const addInitObligationForFarm = true;
|
|
194
|
+
if (extraComputeBudget > 0) {
|
|
195
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
196
|
+
}
|
|
197
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
198
|
+
...axn.depositReserves,
|
|
199
|
+
...axn.borrowReserves,
|
|
200
|
+
axn.reserve.address,
|
|
201
|
+
]).toArray();
|
|
202
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
203
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
204
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
205
|
+
}
|
|
206
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
207
|
+
axn.addDepositIx();
|
|
208
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
209
|
+
return axn;
|
|
196
210
|
}
|
|
197
211
|
getTokenIdsForScopeRefresh(kaminoMarket, reserves) {
|
|
198
212
|
const tokenIds = [];
|
|
@@ -216,197 +230,181 @@ class KaminoAction {
|
|
|
216
230
|
}
|
|
217
231
|
return tokenIds;
|
|
218
232
|
}
|
|
219
|
-
addScopeRefreshIxs(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}, tokens));
|
|
225
|
-
});
|
|
233
|
+
async addScopeRefreshIxs(tokens, feed = 'hubble') {
|
|
234
|
+
this.preTxnIxsLabels.unshift(`refreshScopePrices`);
|
|
235
|
+
this.preTxnIxs.unshift(await this.kaminoMarket.scope.refreshPriceListIx({
|
|
236
|
+
feed: feed,
|
|
237
|
+
}, tokens));
|
|
226
238
|
}
|
|
227
|
-
static buildBorrowTxns(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return axn;
|
|
251
|
-
});
|
|
239
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
240
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
241
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
242
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
243
|
+
) {
|
|
244
|
+
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
245
|
+
const addInitObligationForFarm = true;
|
|
246
|
+
if (extraComputeBudget > 0) {
|
|
247
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
248
|
+
}
|
|
249
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
250
|
+
...axn.depositReserves,
|
|
251
|
+
...axn.borrowReserves,
|
|
252
|
+
axn.reserve.address,
|
|
253
|
+
]).toArray();
|
|
254
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
255
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
256
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
257
|
+
}
|
|
258
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
|
|
259
|
+
axn.addBorrowIx();
|
|
260
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
261
|
+
return axn;
|
|
252
262
|
}
|
|
253
|
-
static buildDepositReserveLiquidityTxns(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return axn;
|
|
276
|
-
});
|
|
263
|
+
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
264
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
265
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
266
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
267
|
+
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
268
|
+
const addInitObligationForFarm = true;
|
|
269
|
+
if (extraComputeBudget > 0) {
|
|
270
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
271
|
+
}
|
|
272
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
273
|
+
...axn.depositReserves,
|
|
274
|
+
...axn.borrowReserves,
|
|
275
|
+
axn.reserve.address,
|
|
276
|
+
]).toArray();
|
|
277
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
278
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
279
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
280
|
+
}
|
|
281
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
282
|
+
axn.addDepositReserveLiquidityIx();
|
|
283
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
284
|
+
return axn;
|
|
277
285
|
}
|
|
278
|
-
static buildRedeemReserveCollateralTxns(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return axn;
|
|
301
|
-
});
|
|
286
|
+
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
287
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
288
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
289
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
290
|
+
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
291
|
+
const addInitObligationForFarm = true;
|
|
292
|
+
if (extraComputeBudget > 0) {
|
|
293
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
294
|
+
}
|
|
295
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
296
|
+
...axn.depositReserves,
|
|
297
|
+
...axn.borrowReserves,
|
|
298
|
+
axn.reserve.address,
|
|
299
|
+
]).toArray();
|
|
300
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
301
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
302
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
303
|
+
}
|
|
304
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
305
|
+
axn.addRedeemReserveCollateralIx();
|
|
306
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
307
|
+
return axn;
|
|
302
308
|
}
|
|
303
|
-
static buildDepositObligationCollateralTxns(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return axn;
|
|
326
|
-
});
|
|
309
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
310
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
311
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
312
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
313
|
+
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
314
|
+
const addInitObligationForFarm = true;
|
|
315
|
+
if (extraComputeBudget > 0) {
|
|
316
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
317
|
+
}
|
|
318
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
319
|
+
...axn.depositReserves,
|
|
320
|
+
...axn.borrowReserves,
|
|
321
|
+
axn.reserve.address,
|
|
322
|
+
]).toArray();
|
|
323
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
324
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
325
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
326
|
+
}
|
|
327
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
328
|
+
axn.addDepositObligationCollateralIx();
|
|
329
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
330
|
+
return axn;
|
|
327
331
|
}
|
|
328
|
-
static buildDepositAndBorrowTxns(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return axn;
|
|
355
|
-
});
|
|
332
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
333
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
334
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
335
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
336
|
+
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
337
|
+
const addInitObligationForFarmForDeposit = true;
|
|
338
|
+
const addInitObligationForFarmForBorrow = false;
|
|
339
|
+
const twoTokenAction = true;
|
|
340
|
+
if (extraComputeBudget > 0) {
|
|
341
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
342
|
+
}
|
|
343
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
344
|
+
...axn.depositReserves,
|
|
345
|
+
...axn.borrowReserves,
|
|
346
|
+
axn.reserve.address,
|
|
347
|
+
axn.outflowReserve.address,
|
|
348
|
+
]).toArray();
|
|
349
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
350
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
351
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
352
|
+
}
|
|
353
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
|
|
354
|
+
await axn.addDepositAndBorrowIx();
|
|
355
|
+
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow);
|
|
356
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
357
|
+
return axn;
|
|
356
358
|
}
|
|
357
|
-
static buildRepayAndWithdrawTxns(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return axn;
|
|
384
|
-
});
|
|
359
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
360
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
361
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
362
|
+
isClosingPosition = false, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
363
|
+
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
364
|
+
const addInitObligationForFarmForRepay = true;
|
|
365
|
+
const addInitObligationForFarmForWithdraw = false;
|
|
366
|
+
const twoTokenAction = true;
|
|
367
|
+
if (extraComputeBudget > 0) {
|
|
368
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
369
|
+
}
|
|
370
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
371
|
+
...axn.depositReserves,
|
|
372
|
+
...axn.borrowReserves,
|
|
373
|
+
axn.reserve.address,
|
|
374
|
+
axn.outflowReserve.address,
|
|
375
|
+
]).toArray();
|
|
376
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
377
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
378
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
379
|
+
}
|
|
380
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
|
|
381
|
+
await axn.addRepayAndWithdrawIxs();
|
|
382
|
+
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, isClosingPosition);
|
|
383
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
384
|
+
return axn;
|
|
385
385
|
}
|
|
386
|
-
static buildWithdrawTxns(
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return axn;
|
|
409
|
-
});
|
|
386
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
387
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
388
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
389
|
+
referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
390
|
+
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
391
|
+
const addInitObligationForFarm = true;
|
|
392
|
+
if (extraComputeBudget > 0) {
|
|
393
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
394
|
+
}
|
|
395
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
396
|
+
...axn.depositReserves,
|
|
397
|
+
...axn.borrowReserves,
|
|
398
|
+
axn.reserve.address,
|
|
399
|
+
]).toArray();
|
|
400
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
401
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
402
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
403
|
+
}
|
|
404
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
405
|
+
await axn.addWithdrawIx();
|
|
406
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
407
|
+
return axn;
|
|
410
408
|
}
|
|
411
409
|
/**
|
|
412
410
|
*
|
|
@@ -423,131 +421,115 @@ class KaminoAction {
|
|
|
423
421
|
* @param includeUserMetadata - if true it includes user metadata
|
|
424
422
|
* @param referrer
|
|
425
423
|
*/
|
|
426
|
-
static buildRepayTxns(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
return axn;
|
|
446
|
-
});
|
|
424
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
425
|
+
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
426
|
+
const addInitObligationForFarm = true;
|
|
427
|
+
if (extraComputeBudget > 0) {
|
|
428
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
429
|
+
}
|
|
430
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
431
|
+
...axn.depositReserves,
|
|
432
|
+
...axn.borrowReserves,
|
|
433
|
+
axn.reserve.address,
|
|
434
|
+
]).toArray();
|
|
435
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
436
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
437
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
438
|
+
}
|
|
439
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
440
|
+
await axn.addRepayIx();
|
|
441
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
442
|
+
return axn;
|
|
447
443
|
}
|
|
448
|
-
static buildLiquidateTxns(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return axn;
|
|
472
|
-
});
|
|
444
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
445
|
+
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
446
|
+
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
447
|
+
referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
448
|
+
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
449
|
+
const addInitObligationForFarm = true;
|
|
450
|
+
if (extraComputeBudget > 0) {
|
|
451
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
452
|
+
}
|
|
453
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
454
|
+
...axn.depositReserves,
|
|
455
|
+
...axn.borrowReserves,
|
|
456
|
+
axn.reserve.address,
|
|
457
|
+
axn.outflowReserve.address,
|
|
458
|
+
]).toArray();
|
|
459
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
460
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
461
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
462
|
+
}
|
|
463
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
|
|
464
|
+
await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
465
|
+
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
466
|
+
return axn;
|
|
473
467
|
}
|
|
474
|
-
static buildWithdrawReferrerFeeTxns(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return axn;
|
|
482
|
-
});
|
|
468
|
+
static async buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0) {
|
|
469
|
+
const { axn, createAtasIxns } = await KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
|
|
470
|
+
axn.preTxnIxs.push(...createAtasIxns);
|
|
471
|
+
axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
|
|
472
|
+
axn.addRefreshReserveIxs([axn.reserve.address]);
|
|
473
|
+
axn.addWithdrawReferrerFeesIxs();
|
|
474
|
+
return axn;
|
|
483
475
|
}
|
|
484
|
-
getTransactions() {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
return txns;
|
|
516
|
-
});
|
|
476
|
+
async getTransactions() {
|
|
477
|
+
const txns = {
|
|
478
|
+
preLendingTxn: null,
|
|
479
|
+
lendingTxn: null,
|
|
480
|
+
postLendingTxn: null,
|
|
481
|
+
};
|
|
482
|
+
if (this.preTxnIxs.length) {
|
|
483
|
+
txns.preLendingTxn = new web3_js_1.Transaction({
|
|
484
|
+
feePayer: this.owner,
|
|
485
|
+
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
486
|
+
}).add(...this.preTxnIxs);
|
|
487
|
+
}
|
|
488
|
+
if (this.lendingIxs.length === 2) {
|
|
489
|
+
txns.lendingTxn = new web3_js_1.Transaction({
|
|
490
|
+
feePayer: this.owner,
|
|
491
|
+
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
492
|
+
}).add(...this.setupIxs, ...[this.lendingIxs[0]], ...this.inBetweenIxs, ...[this.lendingIxs[1]], ...this.cleanupIxs);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
txns.lendingTxn = new web3_js_1.Transaction({
|
|
496
|
+
feePayer: this.owner,
|
|
497
|
+
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
498
|
+
}).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
|
|
499
|
+
}
|
|
500
|
+
if (this.postTxnIxs.length) {
|
|
501
|
+
txns.postLendingTxn = new web3_js_1.Transaction({
|
|
502
|
+
feePayer: this.owner,
|
|
503
|
+
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
504
|
+
}).add(...this.postTxnIxs);
|
|
505
|
+
}
|
|
506
|
+
return txns;
|
|
517
507
|
}
|
|
518
|
-
sendTransactions(sendTransaction) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
return signature;
|
|
525
|
-
});
|
|
508
|
+
async sendTransactions(sendTransaction) {
|
|
509
|
+
const txns = await this.getTransactions();
|
|
510
|
+
await this.sendSingleTransaction(txns.preLendingTxn, sendTransaction);
|
|
511
|
+
const signature = await this.sendSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
512
|
+
await this.sendSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
513
|
+
return signature;
|
|
526
514
|
}
|
|
527
|
-
sendSingleTransaction(txn, sendTransaction) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
return signature;
|
|
534
|
-
});
|
|
515
|
+
async sendSingleTransaction(txn, sendTransaction) {
|
|
516
|
+
if (!txn)
|
|
517
|
+
return '';
|
|
518
|
+
const signature = await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
519
|
+
await this.kaminoMarket.getConnection().confirmTransaction(signature);
|
|
520
|
+
return signature;
|
|
535
521
|
}
|
|
536
|
-
simulateTransactions(sendTransaction) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return signature;
|
|
543
|
-
});
|
|
522
|
+
async simulateTransactions(sendTransaction) {
|
|
523
|
+
const txns = await this.getTransactions();
|
|
524
|
+
await this.simulateSingleTransaction(txns.preLendingTxn, sendTransaction);
|
|
525
|
+
const signature = await this.simulateSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
526
|
+
await this.simulateSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
527
|
+
return signature;
|
|
544
528
|
}
|
|
545
|
-
simulateSingleTransaction(txn, sendTransaction) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
return yield sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
550
|
-
});
|
|
529
|
+
async simulateSingleTransaction(txn, sendTransaction) {
|
|
530
|
+
if (!txn)
|
|
531
|
+
return '';
|
|
532
|
+
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
551
533
|
}
|
|
552
534
|
addDepositIx() {
|
|
553
535
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
@@ -651,222 +633,210 @@ class KaminoAction {
|
|
|
651
633
|
: borrowIx.keys;
|
|
652
634
|
this.lendingIxs.push(borrowIx);
|
|
653
635
|
}
|
|
654
|
-
addDepositAndBorrowIx() {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
this.
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
691
|
-
});
|
|
692
|
-
const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
|
|
693
|
-
liquidityAmount: this.outflowAmount,
|
|
694
|
-
}, {
|
|
695
|
-
owner: this.owner,
|
|
696
|
-
obligation: this.getObligationPda(),
|
|
697
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
698
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
699
|
-
borrowReserve: this.outflowReserve.address,
|
|
700
|
-
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
701
|
-
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
702
|
-
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
703
|
-
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
704
|
-
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
705
|
-
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
706
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
707
|
-
}, this.kaminoMarket.programId);
|
|
708
|
-
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
709
|
-
this.lendingIxs.push(borrowIx);
|
|
636
|
+
async addDepositAndBorrowIx() {
|
|
637
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
638
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
639
|
+
this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
|
|
640
|
+
liquidityAmount: this.amount,
|
|
641
|
+
}, {
|
|
642
|
+
owner: this.owner,
|
|
643
|
+
obligation: this.getObligationPda(),
|
|
644
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
645
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
646
|
+
reserve: this.reserve.address,
|
|
647
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
648
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
649
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
650
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
651
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
652
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
653
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
654
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
655
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
656
|
+
}, this.kaminoMarket.programId));
|
|
657
|
+
if (!this.outflowReserve) {
|
|
658
|
+
throw new Error(`outflowReserve not set`);
|
|
659
|
+
}
|
|
660
|
+
if (!this.additionalTokenAccountAddress) {
|
|
661
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
662
|
+
}
|
|
663
|
+
if (!this.outflowAmount) {
|
|
664
|
+
throw new Error(`outflowAmount not set`);
|
|
665
|
+
}
|
|
666
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
667
|
+
if (depositReservesList.length === 0) {
|
|
668
|
+
depositReservesList.push(this.reserve.address);
|
|
669
|
+
}
|
|
670
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
671
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
710
672
|
});
|
|
673
|
+
const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
|
|
674
|
+
liquidityAmount: this.outflowAmount,
|
|
675
|
+
}, {
|
|
676
|
+
owner: this.owner,
|
|
677
|
+
obligation: this.getObligationPda(),
|
|
678
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
679
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
680
|
+
borrowReserve: this.outflowReserve.address,
|
|
681
|
+
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
682
|
+
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
683
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
684
|
+
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
685
|
+
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
686
|
+
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
687
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
688
|
+
}, this.kaminoMarket.programId);
|
|
689
|
+
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
690
|
+
this.lendingIxs.push(borrowIx);
|
|
711
691
|
}
|
|
712
|
-
addRepayAndWithdrawIxs() {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
719
|
-
});
|
|
720
|
-
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
721
|
-
liquidityAmount: this.amount,
|
|
722
|
-
}, {
|
|
723
|
-
owner: this.owner,
|
|
724
|
-
obligation: this.getObligationPda(),
|
|
725
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
726
|
-
repayReserve: this.reserve.address,
|
|
727
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
728
|
-
userSourceLiquidity: this.userTokenAccountAddress,
|
|
729
|
-
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
730
|
-
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
731
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
732
|
-
}, this.kaminoMarket.programId);
|
|
733
|
-
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
734
|
-
this.lendingIxs.push(repayIx);
|
|
735
|
-
if (!this.outflowReserve) {
|
|
736
|
-
throw new Error(`outflowReserve not set`);
|
|
737
|
-
}
|
|
738
|
-
if (!this.additionalTokenAccountAddress) {
|
|
739
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
740
|
-
}
|
|
741
|
-
if (!this.outflowAmount) {
|
|
742
|
-
throw new Error(`outflowAmount not set`);
|
|
743
|
-
}
|
|
744
|
-
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
745
|
-
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
746
|
-
collateralAmount: this.outflowAmount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
747
|
-
? this.outflowAmount
|
|
748
|
-
: new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
749
|
-
}, {
|
|
750
|
-
owner: this.owner,
|
|
751
|
-
obligation: this.getObligationPda(),
|
|
752
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
753
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
754
|
-
withdrawReserve: this.outflowReserve.address,
|
|
755
|
-
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
756
|
-
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
757
|
-
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
758
|
-
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
759
|
-
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
760
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
761
|
-
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
762
|
-
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
763
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
764
|
-
}, this.kaminoMarket.programId));
|
|
692
|
+
async addRepayAndWithdrawIxs() {
|
|
693
|
+
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
694
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
695
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
696
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
697
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
765
698
|
});
|
|
699
|
+
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
700
|
+
liquidityAmount: this.amount,
|
|
701
|
+
}, {
|
|
702
|
+
owner: this.owner,
|
|
703
|
+
obligation: this.getObligationPda(),
|
|
704
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
705
|
+
repayReserve: this.reserve.address,
|
|
706
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
707
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
708
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
709
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
710
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
711
|
+
}, this.kaminoMarket.programId);
|
|
712
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
713
|
+
this.lendingIxs.push(repayIx);
|
|
714
|
+
if (!this.outflowReserve) {
|
|
715
|
+
throw new Error(`outflowReserve not set`);
|
|
716
|
+
}
|
|
717
|
+
if (!this.additionalTokenAccountAddress) {
|
|
718
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
719
|
+
}
|
|
720
|
+
if (!this.outflowAmount) {
|
|
721
|
+
throw new Error(`outflowAmount not set`);
|
|
722
|
+
}
|
|
723
|
+
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
724
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
725
|
+
collateralAmount: this.outflowAmount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
726
|
+
? this.outflowAmount
|
|
727
|
+
: new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
728
|
+
}, {
|
|
729
|
+
owner: this.owner,
|
|
730
|
+
obligation: this.getObligationPda(),
|
|
731
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
732
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
733
|
+
withdrawReserve: this.outflowReserve.address,
|
|
734
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
735
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
736
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
737
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
738
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
739
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
740
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
741
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
742
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
743
|
+
}, this.kaminoMarket.programId));
|
|
766
744
|
}
|
|
767
|
-
addWithdrawIx() {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
}, this.kaminoMarket.programId));
|
|
792
|
-
});
|
|
745
|
+
async addWithdrawIx() {
|
|
746
|
+
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
747
|
+
const collateralAmount = this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))
|
|
748
|
+
? this.amount
|
|
749
|
+
: new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
750
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
751
|
+
this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
|
|
752
|
+
collateralAmount,
|
|
753
|
+
}, {
|
|
754
|
+
owner: this.owner,
|
|
755
|
+
obligation: this.getObligationPda(),
|
|
756
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
757
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
758
|
+
withdrawReserve: this.reserve.address,
|
|
759
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
760
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
761
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
762
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
763
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
764
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
765
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
766
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
767
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
768
|
+
}, this.kaminoMarket.programId));
|
|
793
769
|
}
|
|
794
|
-
addRepayIx() {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
800
|
-
});
|
|
801
|
-
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
802
|
-
liquidityAmount: this.amount,
|
|
803
|
-
}, {
|
|
804
|
-
owner: this.payer,
|
|
805
|
-
obligation: this.getObligationPda(),
|
|
806
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
807
|
-
repayReserve: this.reserve.address,
|
|
808
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
809
|
-
userSourceLiquidity: this.userTokenAccountAddress,
|
|
810
|
-
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
811
|
-
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
812
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
813
|
-
}, this.kaminoMarket.programId);
|
|
814
|
-
repayIx.keys =
|
|
815
|
-
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
816
|
-
this.lendingIxs.push(repayIx);
|
|
770
|
+
async addRepayIx() {
|
|
771
|
+
this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
772
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
773
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
774
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
817
775
|
});
|
|
776
|
+
const repayIx = (0, instructions_1.repayObligationLiquidity)({
|
|
777
|
+
liquidityAmount: this.amount,
|
|
778
|
+
}, {
|
|
779
|
+
owner: this.payer,
|
|
780
|
+
obligation: this.getObligationPda(),
|
|
781
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
782
|
+
repayReserve: this.reserve.address,
|
|
783
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
784
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
785
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
786
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
787
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
788
|
+
}, this.kaminoMarket.programId);
|
|
789
|
+
repayIx.keys =
|
|
790
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
791
|
+
this.lendingIxs.push(repayIx);
|
|
818
792
|
}
|
|
819
|
-
addLiquidateIx() {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
831
|
-
});
|
|
832
|
-
const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
|
|
833
|
-
liquidityAmount: this.amount,
|
|
834
|
-
// TODO: Configure this when updating liquidator with new interface
|
|
835
|
-
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
|
|
836
|
-
maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
|
|
837
|
-
}, {
|
|
838
|
-
liquidator: this.owner,
|
|
839
|
-
obligation: this.getObligationPda(),
|
|
840
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
841
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
842
|
-
repayReserve: this.reserve.address,
|
|
843
|
-
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
844
|
-
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
845
|
-
withdrawReserve: this.outflowReserve.address,
|
|
846
|
-
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
847
|
-
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
848
|
-
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
849
|
-
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
850
|
-
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
851
|
-
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
852
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
853
|
-
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
854
|
-
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
855
|
-
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
856
|
-
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
857
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
858
|
-
}, this.kaminoMarket.programId);
|
|
859
|
-
liquidateIx.keys =
|
|
860
|
-
this.obligation.state.elevationGroup > 0
|
|
861
|
-
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
862
|
-
: liquidateIx.keys;
|
|
863
|
-
this.lendingIxs.push(liquidateIx);
|
|
793
|
+
async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
|
|
794
|
+
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
795
|
+
if (!this.outflowReserve) {
|
|
796
|
+
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
797
|
+
}
|
|
798
|
+
if (!this.additionalTokenAccountAddress) {
|
|
799
|
+
throw Error(`Liquidating token account address is not defined`);
|
|
800
|
+
}
|
|
801
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
802
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
803
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
864
804
|
});
|
|
805
|
+
const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
|
|
806
|
+
liquidityAmount: this.amount,
|
|
807
|
+
// TODO: Configure this when updating liquidator with new interface
|
|
808
|
+
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
|
|
809
|
+
maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
|
|
810
|
+
}, {
|
|
811
|
+
liquidator: this.owner,
|
|
812
|
+
obligation: this.getObligationPda(),
|
|
813
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
814
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
815
|
+
repayReserve: this.reserve.address,
|
|
816
|
+
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
817
|
+
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
818
|
+
withdrawReserve: this.outflowReserve.address,
|
|
819
|
+
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
820
|
+
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
821
|
+
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
822
|
+
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
823
|
+
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
824
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
825
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
826
|
+
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
827
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
828
|
+
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
829
|
+
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
830
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
831
|
+
}, this.kaminoMarket.programId);
|
|
832
|
+
liquidateIx.keys =
|
|
833
|
+
this.obligation.state.elevationGroup > 0
|
|
834
|
+
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
835
|
+
: liquidateIx.keys;
|
|
836
|
+
this.lendingIxs.push(liquidateIx);
|
|
865
837
|
}
|
|
866
|
-
addInBetweenIxs(
|
|
867
|
-
|
|
868
|
-
yield this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'inBetween', requestElevationGroup, addInitObligationForFarm, isClosingPosition);
|
|
869
|
-
});
|
|
838
|
+
async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
|
|
839
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'inBetween', requestElevationGroup, addInitObligationForFarm, isClosingPosition);
|
|
870
840
|
}
|
|
871
841
|
addRefreshObligation(crank) {
|
|
872
842
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
@@ -878,253 +848,248 @@ class KaminoAction {
|
|
|
878
848
|
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
|
|
879
849
|
this.addRefreshObligationIx(addAllToSetupIxns, false);
|
|
880
850
|
}
|
|
881
|
-
addSupportIxsWithoutInitObligation(
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
if (
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
if (
|
|
920
|
-
|
|
921
|
-
if (!deposit) {
|
|
922
|
-
this.preLoadedDepositReservesSameTx.push(this.reserve.address);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
else {
|
|
926
|
-
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.equals(this.reserve.address));
|
|
927
|
-
if (!borrow) {
|
|
928
|
-
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
929
|
-
}
|
|
930
|
-
const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
|
|
931
|
-
const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
932
|
-
const fullRepay = obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
933
|
-
.mul(cumulativeBorrowRateReserve)
|
|
934
|
-
.div(cumulativeBorrowRateObligation);
|
|
935
|
-
const amountDecimal = new decimal_js_1.default(this.amount.toString());
|
|
936
|
-
if (fullRepay.lte(amountDecimal)) {
|
|
937
|
-
this.preLoadedBorrowReservesSameTx.push(this.reserve.address);
|
|
938
|
-
}
|
|
851
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
852
|
+
// TODO: why are we not doing this first?
|
|
853
|
+
if (includeAtaIxns) {
|
|
854
|
+
await this.addAtaIxs(action);
|
|
855
|
+
}
|
|
856
|
+
if ([
|
|
857
|
+
'depositCollateral',
|
|
858
|
+
'deposit',
|
|
859
|
+
'withdraw',
|
|
860
|
+
'borrow',
|
|
861
|
+
'liquidate',
|
|
862
|
+
'repay',
|
|
863
|
+
'depositAndBorrow',
|
|
864
|
+
'repayAndWithdraw',
|
|
865
|
+
'refreshObligation',
|
|
866
|
+
].includes(action)) {
|
|
867
|
+
// The support ixns in order are:
|
|
868
|
+
// 0. Init obligation ixn
|
|
869
|
+
// 0. Token Ata ixns
|
|
870
|
+
// 0. Init obligation for farm
|
|
871
|
+
// 1. Ixns to refresh the reserves of the obligation not related to the current action
|
|
872
|
+
// 2. Ixn to refresh the reserve of the current action
|
|
873
|
+
// 3. Ixn to refresh the obligation
|
|
874
|
+
// 4. Ixn to refresh the `debt` farm of the obligation
|
|
875
|
+
// 5. Ixn to refresh the `collateral` farm of the obligation
|
|
876
|
+
// 6. The instruction itself
|
|
877
|
+
// 7. Ixn to refresh the `debt` farm of the obligation
|
|
878
|
+
// 8. Ixn to refresh the `collateral` farm of the obligation
|
|
879
|
+
let currentReserves = [];
|
|
880
|
+
if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
881
|
+
if (!this.outflowReserve) {
|
|
882
|
+
throw new Error('outflowReserve is undefined');
|
|
883
|
+
}
|
|
884
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
885
|
+
currentReserves = [this.reserve, this.outflowReserve];
|
|
886
|
+
if (this.obligation) {
|
|
887
|
+
if (action === 'depositAndBorrow') {
|
|
888
|
+
const deposit = this.obligation.state.deposits.find((deposit) => deposit.depositReserve.equals(this.reserve.address));
|
|
889
|
+
if (!deposit) {
|
|
890
|
+
this.preLoadedDepositReservesSameTx.push(this.reserve.address);
|
|
939
891
|
}
|
|
940
892
|
}
|
|
941
893
|
else {
|
|
942
|
-
|
|
943
|
-
|
|
894
|
+
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.equals(this.reserve.address));
|
|
895
|
+
if (!borrow) {
|
|
896
|
+
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
897
|
+
}
|
|
898
|
+
const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
|
|
899
|
+
const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
900
|
+
const fullRepay = obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
901
|
+
.mul(cumulativeBorrowRateReserve)
|
|
902
|
+
.div(cumulativeBorrowRateObligation);
|
|
903
|
+
const amountDecimal = new decimal_js_1.default(this.amount.toString());
|
|
904
|
+
if (fullRepay.lte(amountDecimal)) {
|
|
905
|
+
this.preLoadedBorrowReservesSameTx.push(this.reserve.address);
|
|
906
|
+
}
|
|
944
907
|
}
|
|
945
908
|
}
|
|
946
|
-
else if (action === 'liquidate' && !this.outflowReserve.address.equals(this.reserve.address)) {
|
|
947
|
-
currentReserves = [this.outflowReserve, this.reserve];
|
|
948
|
-
}
|
|
949
909
|
else {
|
|
950
|
-
|
|
910
|
+
// Obligation doesn't exist yet, so we have to preload the deposit reserve
|
|
911
|
+
this.preLoadedDepositReservesSameTx.push(this.reserve.address);
|
|
951
912
|
}
|
|
952
913
|
}
|
|
914
|
+
else if (action === 'liquidate' && !this.outflowReserve.address.equals(this.reserve.address)) {
|
|
915
|
+
currentReserves = [this.outflowReserve, this.reserve];
|
|
916
|
+
}
|
|
953
917
|
else {
|
|
954
918
|
currentReserves = [this.reserve];
|
|
955
919
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
978
|
-
if (this.outflowReserve) {
|
|
979
|
-
yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
else {
|
|
983
|
-
yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
984
|
-
yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
985
|
-
if (this.outflowReserve) {
|
|
986
|
-
yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
987
|
-
yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
988
|
-
}
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
currentReserves = [this.reserve];
|
|
923
|
+
}
|
|
924
|
+
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves));
|
|
925
|
+
const currentReserveAddresses = new utils_1.PublicKeySet(currentReserves.map((reserve) => reserve.address));
|
|
926
|
+
// Union of addresses
|
|
927
|
+
const allReservesExcludingCurrent = [...uniqueReserveAddresses.toArray()].filter((address) => !currentReserveAddresses.contains(address));
|
|
928
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
929
|
+
if (addInitObligationForFarm) {
|
|
930
|
+
if (action === 'liquidate') {
|
|
931
|
+
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
932
|
+
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
933
|
+
}
|
|
934
|
+
else if (action === 'depositAndBorrow' ||
|
|
935
|
+
action === 'depositCollateral' ||
|
|
936
|
+
action === 'withdraw' ||
|
|
937
|
+
action === 'deposit') {
|
|
938
|
+
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
939
|
+
if (this.outflowReserve) {
|
|
940
|
+
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
989
941
|
}
|
|
990
942
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
this.addRefreshObligationIx(addAsSupportIx, true);
|
|
943
|
+
else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
944
|
+
// todo - probably don't need to add both debt and collateral for everything here
|
|
945
|
+
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
946
|
+
if (this.outflowReserve) {
|
|
947
|
+
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
948
|
+
}
|
|
998
949
|
}
|
|
999
950
|
else {
|
|
1000
|
-
this.
|
|
951
|
+
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
952
|
+
await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
953
|
+
if (this.outflowReserve) {
|
|
954
|
+
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
|
|
955
|
+
await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
|
|
956
|
+
}
|
|
1001
957
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
958
|
+
}
|
|
959
|
+
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
960
|
+
if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween' && isClosingPosition) {
|
|
961
|
+
// addToSetupIxs === addInBetween (same thing)
|
|
962
|
+
// If this is a repay and withdraw, and it's not the first action, and it's closing a position
|
|
963
|
+
// we don't need to include the repay reserve in the refresh obligation
|
|
964
|
+
// I am ashamed of this code, we need to rewrite this entire thing
|
|
965
|
+
this.addRefreshObligationIx(addAsSupportIx, true);
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
this.addRefreshObligationIx(addAsSupportIx, false);
|
|
969
|
+
}
|
|
970
|
+
if (requestElevationGroup) {
|
|
971
|
+
if (action === 'repay') {
|
|
972
|
+
const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
|
|
973
|
+
if (!repayObligationLiquidity) {
|
|
974
|
+
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
975
|
+
}
|
|
976
|
+
if (new decimal_js_1.default(repayObligationLiquidity.amount).lte(new decimal_js_1.default(this.amount.toString())) &&
|
|
977
|
+
this.obligation.borrows.size === 1 &&
|
|
978
|
+
this.obligation?.state.elevationGroup !== 0) {
|
|
979
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
|
|
980
|
+
// Skip the borrow reserve, since we repay in the same tx
|
|
981
|
+
this.addRefreshObligationIx('cleanup', true);
|
|
982
|
+
this.addRequestElevationIx(overrideElevationGroupRequest ?? 0, 'cleanup', true);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
else if (action === 'depositAndBorrow' || action === 'borrow') {
|
|
986
|
+
let newElevationGroup = -1;
|
|
987
|
+
let addAsSupportIx = 'setup';
|
|
988
|
+
if (overrideElevationGroupRequest !== undefined) {
|
|
989
|
+
newElevationGroup = overrideElevationGroupRequest;
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
|
|
993
|
+
let emodeGroupsColl = this.reserve.state.config.elevationGroups;
|
|
994
|
+
let debtReserve = this.reserve.address;
|
|
995
|
+
if (action === 'depositAndBorrow') {
|
|
996
|
+
emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
|
|
997
|
+
debtReserve = this.outflowReserve.address;
|
|
998
|
+
addAsSupportIx = 'inBetween';
|
|
1007
999
|
}
|
|
1008
|
-
if (
|
|
1009
|
-
this.obligation.
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
this.addRefreshObligationIx('cleanup', true);
|
|
1014
|
-
this.addRequestElevationIx(overrideElevationGroupRequest !== null && overrideElevationGroupRequest !== void 0 ? overrideElevationGroupRequest : 0, 'cleanup', true);
|
|
1000
|
+
else if (action === 'borrow') {
|
|
1001
|
+
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1002
|
+
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1003
|
+
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
1004
|
+
addAsSupportIx = 'setup';
|
|
1015
1005
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
newElevationGroup = overrideElevationGroupRequest;
|
|
1006
|
+
const groups = this.kaminoMarket.state.elevationGroups;
|
|
1007
|
+
const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
|
|
1008
|
+
console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
|
|
1009
|
+
if (commonElevationGroups.length === 0) {
|
|
1010
|
+
console.log('No common elevation groups found, staying with default');
|
|
1022
1011
|
}
|
|
1023
1012
|
else {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1034
|
-
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1035
|
-
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
1036
|
-
addAsSupportIx = 'setup';
|
|
1037
|
-
}
|
|
1038
|
-
const groups = this.kaminoMarket.state.elevationGroups;
|
|
1039
|
-
const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
|
|
1040
|
-
console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
|
|
1041
|
-
if (commonElevationGroups.length === 0) {
|
|
1042
|
-
console.log('No common elevation groups found, staying with default');
|
|
1043
|
-
}
|
|
1044
|
-
else {
|
|
1045
|
-
const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
|
|
1046
|
-
const prevGroup = groups.find((group) => group.id === prev);
|
|
1047
|
-
const currGroup = groups.find((group) => group.id === curr);
|
|
1048
|
-
return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
|
|
1049
|
-
});
|
|
1050
|
-
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
|
|
1051
|
-
console.log('Setting eModeGroup to', eModeGroup);
|
|
1052
|
-
if (eModeGroup !== 0 && eModeGroup !== ((_b = this.obligation) === null || _b === void 0 ? void 0 : _b.state.elevationGroup)) {
|
|
1053
|
-
newElevationGroup = eModeGroup;
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
|
|
1058
|
-
if (newElevationGroup >= 0 && newElevationGroup !== ((_c = this.obligation) === null || _c === void 0 ? void 0 : _c.state.elevationGroup)) {
|
|
1059
|
-
this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
|
|
1060
|
-
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1061
|
-
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1062
|
-
this.addRefreshObligationIx(addAsSupportIx);
|
|
1063
|
-
if (action === 'borrow') {
|
|
1064
|
-
this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
|
|
1013
|
+
const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
|
|
1014
|
+
const prevGroup = groups.find((group) => group.id === prev);
|
|
1015
|
+
const currGroup = groups.find((group) => group.id === curr);
|
|
1016
|
+
return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
|
|
1017
|
+
});
|
|
1018
|
+
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
|
|
1019
|
+
console.log('Setting eModeGroup to', eModeGroup);
|
|
1020
|
+
if (eModeGroup !== 0 && eModeGroup !== this.obligation?.state.elevationGroup) {
|
|
1021
|
+
newElevationGroup = eModeGroup;
|
|
1065
1022
|
}
|
|
1066
1023
|
}
|
|
1067
1024
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const addAsSupportIx = 'setup';
|
|
1072
|
-
console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
|
|
1073
|
-
this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
|
|
1025
|
+
console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
|
|
1026
|
+
if (newElevationGroup >= 0 && newElevationGroup !== this.obligation?.state.elevationGroup) {
|
|
1027
|
+
this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
|
|
1074
1028
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1075
1029
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1076
1030
|
this.addRefreshObligationIx(addAsSupportIx);
|
|
1031
|
+
if (action === 'borrow') {
|
|
1032
|
+
this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
|
|
1033
|
+
}
|
|
1077
1034
|
}
|
|
1078
1035
|
}
|
|
1079
|
-
if (
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1036
|
+
else if (action === 'deposit' &&
|
|
1037
|
+
overrideElevationGroupRequest !== undefined &&
|
|
1038
|
+
overrideElevationGroupRequest !== this.obligation?.state.elevationGroup) {
|
|
1039
|
+
const addAsSupportIx = 'setup';
|
|
1040
|
+
console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
|
|
1041
|
+
this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
|
|
1042
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1043
|
+
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1044
|
+
this.addRefreshObligationIx(addAsSupportIx);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (addAsSupportIx === 'setup') {
|
|
1048
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
1049
|
+
// or the first of a two-token-action
|
|
1050
|
+
if (action === 'liquidate') {
|
|
1051
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1052
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1053
|
+
}
|
|
1054
|
+
else if (action === 'depositAndBorrow' ||
|
|
1055
|
+
action === 'depositCollateral' ||
|
|
1056
|
+
action === 'withdraw' ||
|
|
1057
|
+
action === 'deposit') {
|
|
1058
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
|
|
1059
|
+
}
|
|
1060
|
+
else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
1061
|
+
this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
|
|
1098
1062
|
}
|
|
1099
1063
|
else {
|
|
1100
|
-
|
|
1101
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1102
|
-
// add added to 'setup' ixns
|
|
1103
|
-
if (action === 'depositAndBorrow') {
|
|
1104
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1105
|
-
}
|
|
1106
|
-
else if (action === 'repayAndWithdraw') {
|
|
1107
|
-
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1108
|
-
}
|
|
1109
|
-
else {
|
|
1110
|
-
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1111
|
-
}
|
|
1064
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1112
1065
|
}
|
|
1113
1066
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1067
|
+
else {
|
|
1068
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
1069
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1070
|
+
// add added to 'setup' ixns
|
|
1071
|
+
if (action === 'depositAndBorrow') {
|
|
1072
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1073
|
+
}
|
|
1074
|
+
else if (action === 'repayAndWithdraw') {
|
|
1075
|
+
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
1122
1079
|
}
|
|
1123
|
-
yield this.addInitReferrerTokenStateIxs();
|
|
1124
|
-
yield this.addInitObligationIxs();
|
|
1125
1080
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1084
|
+
if (!['mint', 'redeem'].includes(action)) {
|
|
1085
|
+
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1086
|
+
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1087
|
+
await this.addInitUserMetadataIxs();
|
|
1088
|
+
}
|
|
1089
|
+
await this.addInitReferrerTokenStateIxs();
|
|
1090
|
+
await this.addInitObligationIxs();
|
|
1091
|
+
}
|
|
1092
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, false, twoTokenAction, overrideElevationGroupRequest);
|
|
1128
1093
|
}
|
|
1129
1094
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1130
1095
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1331,135 +1296,126 @@ class KaminoAction {
|
|
|
1331
1296
|
this.cleanupIxs.splice(0, 0, ...this.refreshFarmsCleanupTxnIxs);
|
|
1332
1297
|
this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
|
|
1333
1298
|
}
|
|
1334
|
-
addInitObligationForFarm(
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
|
|
1344
|
-
}
|
|
1299
|
+
async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
|
|
1300
|
+
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
1301
|
+
const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
|
|
1302
|
+
const farms = [];
|
|
1303
|
+
if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
|
|
1304
|
+
const pda = getPda(reserve.state.farmCollateral);
|
|
1305
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
1306
|
+
if (!account) {
|
|
1307
|
+
farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
|
|
1345
1308
|
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1309
|
+
}
|
|
1310
|
+
if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
|
|
1311
|
+
const pda = getPda(reserve.state.farmDebt);
|
|
1312
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
1313
|
+
if (!account) {
|
|
1314
|
+
farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, getPda(reserve.state.farmDebt)]);
|
|
1352
1315
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
addInitObligationIxs() {
|
|
1381
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1382
|
-
if (!this.obligation) {
|
|
1383
|
-
const obligationPda = this.getObligationPda();
|
|
1384
|
-
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1385
|
-
const initObligationIx = (0, instructions_1.initObligation)({
|
|
1386
|
-
args: {
|
|
1387
|
-
tag: this.obligationType.toArgs().tag,
|
|
1388
|
-
id: this.obligationType.toArgs().id,
|
|
1389
|
-
},
|
|
1390
|
-
}, {
|
|
1391
|
-
obligationOwner: this.owner,
|
|
1392
|
-
feePayer: this.payer,
|
|
1393
|
-
obligation: obligationPda,
|
|
1394
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1395
|
-
seed1Account: this.obligationType.toArgs().seed1,
|
|
1396
|
-
seed2Account: this.obligationType.toArgs().seed2,
|
|
1397
|
-
ownerUserMetadata: userMetadataAddress,
|
|
1398
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1399
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1400
|
-
}, this.kaminoMarket.programId);
|
|
1401
|
-
this.setupIxs.push(initObligationIx);
|
|
1402
|
-
this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
|
|
1316
|
+
}
|
|
1317
|
+
farms.forEach((arg) => {
|
|
1318
|
+
const args = { mode: arg[0] };
|
|
1319
|
+
const accounts = {
|
|
1320
|
+
owner: this.obligation ? this.obligation.state.owner : this.owner,
|
|
1321
|
+
payer: this.owner,
|
|
1322
|
+
obligation: this.getObligationPda(),
|
|
1323
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1324
|
+
reserve: reserve.address,
|
|
1325
|
+
reserveFarmState: arg[1],
|
|
1326
|
+
obligationFarm: arg[2],
|
|
1327
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1328
|
+
farmsProgram: farms_sdk_1.farmsId,
|
|
1329
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1330
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1331
|
+
};
|
|
1332
|
+
const initObligationForFarm = (0, instructions_1.initObligationFarmsForReserve)(args, accounts, this.kaminoMarket.programId);
|
|
1333
|
+
if (addAsSupportIx === 'setup') {
|
|
1334
|
+
this.setupIxs.push(initObligationForFarm);
|
|
1335
|
+
this.setupIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
|
|
1336
|
+
}
|
|
1337
|
+
else if (addAsSupportIx === 'inBetween') {
|
|
1338
|
+
this.inBetweenIxs.push(initObligationForFarm);
|
|
1339
|
+
this.inBetweenIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
|
|
1403
1340
|
}
|
|
1404
1341
|
});
|
|
1405
1342
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
const
|
|
1409
|
-
this.setupIxs.push(createLutIx);
|
|
1410
|
-
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1343
|
+
async addInitObligationIxs() {
|
|
1344
|
+
if (!this.obligation) {
|
|
1345
|
+
const obligationPda = this.getObligationPda();
|
|
1411
1346
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1347
|
+
const initObligationIx = (0, instructions_1.initObligation)({
|
|
1348
|
+
args: {
|
|
1349
|
+
tag: this.obligationType.toArgs().tag,
|
|
1350
|
+
id: this.obligationType.toArgs().id,
|
|
1351
|
+
},
|
|
1417
1352
|
}, {
|
|
1418
|
-
|
|
1353
|
+
obligationOwner: this.owner,
|
|
1419
1354
|
feePayer: this.payer,
|
|
1420
|
-
|
|
1421
|
-
|
|
1355
|
+
obligation: obligationPda,
|
|
1356
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1357
|
+
seed1Account: this.obligationType.toArgs().seed1,
|
|
1358
|
+
seed2Account: this.obligationType.toArgs().seed2,
|
|
1359
|
+
ownerUserMetadata: userMetadataAddress,
|
|
1422
1360
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1423
1361
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1424
1362
|
}, this.kaminoMarket.programId);
|
|
1425
|
-
this.setupIxs.push(
|
|
1426
|
-
this.setupIxsLabels.push(`
|
|
1427
|
-
}
|
|
1363
|
+
this.setupIxs.push(initObligationIx);
|
|
1364
|
+
this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
|
|
1365
|
+
}
|
|
1428
1366
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1367
|
+
async addInitUserMetadataIxs() {
|
|
1368
|
+
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1369
|
+
this.setupIxs.push(createLutIx);
|
|
1370
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
1371
|
+
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1372
|
+
const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
|
|
1373
|
+
? this.kaminoMarket.programId
|
|
1374
|
+
: (0, utils_1.userMetadataPda)(this.referrer, this.kaminoMarket.programId)[0];
|
|
1375
|
+
const initUserMetadataIx = (0, instructions_1.initUserMetadata)({
|
|
1376
|
+
userLookupTable: lookupTableAddress,
|
|
1377
|
+
}, {
|
|
1378
|
+
owner: this.owner,
|
|
1379
|
+
feePayer: this.payer,
|
|
1380
|
+
userMetadata: userMetadataAddress,
|
|
1381
|
+
referrerUserMetadata: referrerUserMetadataAddress,
|
|
1382
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1383
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1384
|
+
}, this.kaminoMarket.programId);
|
|
1385
|
+
this.setupIxs.push(initUserMetadataIx);
|
|
1386
|
+
this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
|
|
1387
|
+
}
|
|
1388
|
+
async addInitReferrerTokenStateIxs(reservesArr = []) {
|
|
1389
|
+
if (this.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
const outflowReserve = this.outflowReserve?.address ? [this.outflowReserve.address] : [];
|
|
1393
|
+
const reserves = reservesArr.length !== 0
|
|
1394
|
+
? reservesArr.map((reserve) => reserve.address)
|
|
1395
|
+
: new utils_1.PublicKeySet([this.reserve.address, ...outflowReserve]).toArray();
|
|
1396
|
+
const tokenStatesToCreate = [];
|
|
1397
|
+
for (const reserve of reserves) {
|
|
1398
|
+
if (!reserve) {
|
|
1399
|
+
continue;
|
|
1434
1400
|
}
|
|
1435
|
-
const
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
: new utils_1.PublicKeySet([this.reserve.address, ...outflowReserve]).toArray();
|
|
1439
|
-
const tokenStatesToCreate = [];
|
|
1440
|
-
for (const reserve of reserves) {
|
|
1441
|
-
if (!reserve) {
|
|
1442
|
-
continue;
|
|
1443
|
-
}
|
|
1444
|
-
const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.referrer, reserve, this.kaminoMarket.programId)[0];
|
|
1445
|
-
if (!(yield (0, utils_1.checkIfAccountExists)(this.kaminoMarket.getConnection(), referrerTokenStateAddress))) {
|
|
1446
|
-
tokenStatesToCreate.push([referrerTokenStateAddress, reserve]);
|
|
1447
|
-
}
|
|
1401
|
+
const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.referrer, reserve, this.kaminoMarket.programId)[0];
|
|
1402
|
+
if (!(await (0, utils_1.checkIfAccountExists)(this.kaminoMarket.getConnection(), referrerTokenStateAddress))) {
|
|
1403
|
+
tokenStatesToCreate.push([referrerTokenStateAddress, reserve]);
|
|
1448
1404
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
});
|
|
1405
|
+
}
|
|
1406
|
+
tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
|
|
1407
|
+
const initreferrerTokenStateIx = (0, instructions_1.initReferrerTokenState)({
|
|
1408
|
+
referrer: this.referrer,
|
|
1409
|
+
}, {
|
|
1410
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1411
|
+
payer: this.owner,
|
|
1412
|
+
reserve: reserveAddress,
|
|
1413
|
+
referrerTokenState: referrerTokenStateAddress,
|
|
1414
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1415
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1416
|
+
}, this.kaminoMarket.programId);
|
|
1417
|
+
this.setupIxs.unshift(initreferrerTokenStateIx);
|
|
1418
|
+
this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenStateAddress.toString()} res=${reserveAddress}]`);
|
|
1463
1419
|
});
|
|
1464
1420
|
}
|
|
1465
1421
|
addWithdrawReferrerFeesIxs() {
|
|
@@ -1482,242 +1438,232 @@ class KaminoAction {
|
|
|
1482
1438
|
this.setupIxs.push((0, utils_1.buildComputeBudgetIx)(units));
|
|
1483
1439
|
this.setupIxsLabels.push(`AddComputeBudget[${units}]`);
|
|
1484
1440
|
}
|
|
1485
|
-
addAtaIxs(action) {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
if (
|
|
1492
|
-
const
|
|
1493
|
-
if (
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1497
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1498
|
-
}
|
|
1499
|
-
else {
|
|
1500
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1501
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
if (action === 'liquidate') {
|
|
1506
|
-
const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1507
|
-
if (!this.outflowReserve) {
|
|
1508
|
-
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1509
|
-
}
|
|
1510
|
-
if (!userTokenAccountInfo) {
|
|
1511
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1512
|
-
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1513
|
-
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1514
|
-
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1515
|
-
}
|
|
1516
|
-
else {
|
|
1517
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1518
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
const userCollateralAccountInfo = yield this.kaminoMarket
|
|
1522
|
-
.getConnection()
|
|
1523
|
-
.getAccountInfo(this.userCollateralAccountAddress);
|
|
1524
|
-
if (!userCollateralAccountInfo) {
|
|
1525
|
-
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1526
|
-
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1527
|
-
this.preTxnIxs.push(createUserCollateralAccountIx);
|
|
1528
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1529
|
-
}
|
|
1530
|
-
else {
|
|
1531
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1532
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1536
|
-
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
if (action === 'depositAndBorrow' ||
|
|
1540
|
-
(action === 'repayAndWithdraw' && !((_b = this.secondaryMint) === null || _b === void 0 ? void 0 : _b.equals(utils_1.WRAPPED_SOL_MINT)))) {
|
|
1541
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1542
|
-
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1543
|
-
}
|
|
1544
|
-
if (!this.outflowReserve) {
|
|
1545
|
-
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1441
|
+
async addAtaIxs(action) {
|
|
1442
|
+
if (this.mint.equals(utils_1.WRAPPED_SOL_MINT) || this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1443
|
+
await this.updateWSOLAccount(action);
|
|
1444
|
+
}
|
|
1445
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1446
|
+
const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1447
|
+
if (!userTokenAccountInfo) {
|
|
1448
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1449
|
+
if (this.positions === exports.POSITION_LIMIT) {
|
|
1450
|
+
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1451
|
+
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1546
1452
|
}
|
|
1547
|
-
|
|
1548
|
-
.getConnection()
|
|
1549
|
-
.getAccountInfo(this.additionalTokenAccountAddress);
|
|
1550
|
-
if (!additionalUserTokenAccountInfo) {
|
|
1551
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.additionalTokenAccountAddress);
|
|
1453
|
+
else {
|
|
1552
1454
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1553
|
-
this.setupIxsLabels.unshift(`
|
|
1455
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1554
1456
|
}
|
|
1555
1457
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1458
|
+
}
|
|
1459
|
+
if (action === 'liquidate') {
|
|
1460
|
+
const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1461
|
+
if (!this.outflowReserve) {
|
|
1462
|
+
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1463
|
+
}
|
|
1464
|
+
if (!userTokenAccountInfo) {
|
|
1465
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1466
|
+
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1561
1467
|
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1562
1468
|
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1563
1469
|
}
|
|
1470
|
+
else {
|
|
1471
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1472
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1473
|
+
}
|
|
1564
1474
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1578
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1579
|
-
}
|
|
1475
|
+
const userCollateralAccountInfo = await this.kaminoMarket
|
|
1476
|
+
.getConnection()
|
|
1477
|
+
.getAccountInfo(this.userCollateralAccountAddress);
|
|
1478
|
+
if (!userCollateralAccountInfo) {
|
|
1479
|
+
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1480
|
+
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1481
|
+
this.preTxnIxs.push(createUserCollateralAccountIx);
|
|
1482
|
+
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1483
|
+
}
|
|
1484
|
+
else {
|
|
1485
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1486
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1580
1487
|
}
|
|
1581
1488
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
updateWSOLAccount(action) {
|
|
1585
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1586
|
-
var _a, _b;
|
|
1587
|
-
const preIxs = [];
|
|
1588
|
-
const postIxs = [];
|
|
1589
|
-
const preIxsLabels = [];
|
|
1590
|
-
const postIxsLabels = [];
|
|
1591
|
-
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
1592
|
-
return;
|
|
1489
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1490
|
+
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1593
1491
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
}
|
|
1600
|
-
const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
|
|
1601
|
-
const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
1602
|
-
// TODO: shouldn't this calc be added to all other stuff as well?
|
|
1603
|
-
safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
1604
|
-
.mul(cumulativeBorrowRateReserve)
|
|
1605
|
-
.div(cumulativeBorrowRateObligation)
|
|
1606
|
-
.add(new decimal_js_1.default(SOL_PADDING_FOR_INTEREST.toString()))
|
|
1607
|
-
.toNumber()).toString());
|
|
1492
|
+
}
|
|
1493
|
+
if (action === 'depositAndBorrow' ||
|
|
1494
|
+
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT))) {
|
|
1495
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1496
|
+
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1608
1497
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1612
|
-
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1613
|
-
}
|
|
1614
|
-
userTokenAccountAddress = this.additionalTokenAccountAddress;
|
|
1498
|
+
if (!this.outflowReserve) {
|
|
1499
|
+
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1615
1500
|
}
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1501
|
+
const additionalUserTokenAccountInfo = await this.kaminoMarket
|
|
1502
|
+
.getConnection()
|
|
1503
|
+
.getAccountInfo(this.additionalTokenAccountAddress);
|
|
1504
|
+
if (!additionalUserTokenAccountInfo) {
|
|
1505
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.additionalTokenAccountAddress);
|
|
1506
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1507
|
+
this.setupIxsLabels.unshift(`CreateAdditionalUserTokenAta[${this.owner}]`);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (action === 'withdraw' || action === 'mint' || action === 'deposit' || action === 'repayAndWithdraw') {
|
|
1511
|
+
const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
|
|
1512
|
+
// TODO: Might need to remove this
|
|
1513
|
+
if (!userTokenAccountInfo) {
|
|
1514
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
|
|
1515
|
+
this.preTxnIxs.push(createUserTokenAccountIx);
|
|
1516
|
+
this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if (action === 'mint') {
|
|
1520
|
+
const userCollateralAccountInfo = await this.kaminoMarket
|
|
1521
|
+
.getConnection()
|
|
1522
|
+
.getAccountInfo(this.userCollateralAccountAddress);
|
|
1523
|
+
if (!userCollateralAccountInfo) {
|
|
1524
|
+
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
1525
|
+
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1526
|
+
if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1527
|
+
this.preTxnIxs.push(createUserCollateralAccountIx);
|
|
1528
|
+
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1636
1529
|
}
|
|
1637
1530
|
else {
|
|
1638
|
-
|
|
1639
|
-
|
|
1531
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1532
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
1640
1533
|
}
|
|
1641
1534
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
async updateWSOLAccount(action) {
|
|
1538
|
+
const preIxs = [];
|
|
1539
|
+
const postIxs = [];
|
|
1540
|
+
const preIxsLabels = [];
|
|
1541
|
+
const postIxsLabels = [];
|
|
1542
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
let safeRepay = new bn_js_1.default(this.amount);
|
|
1546
|
+
if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
|
|
1547
|
+
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
|
|
1548
|
+
if (!borrow) {
|
|
1549
|
+
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
1550
|
+
}
|
|
1551
|
+
const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
|
|
1552
|
+
const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
|
|
1553
|
+
// TODO: shouldn't this calc be added to all other stuff as well?
|
|
1554
|
+
safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
1555
|
+
.mul(cumulativeBorrowRateReserve)
|
|
1556
|
+
.div(cumulativeBorrowRateObligation)
|
|
1557
|
+
.add(new decimal_js_1.default(SOL_PADDING_FOR_INTEREST.toString()))
|
|
1558
|
+
.toNumber()).toString());
|
|
1559
|
+
}
|
|
1560
|
+
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
1561
|
+
if (this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)) {
|
|
1562
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1563
|
+
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1564
|
+
}
|
|
1565
|
+
userTokenAccountAddress = this.additionalTokenAccountAddress;
|
|
1566
|
+
}
|
|
1567
|
+
const userWSOLAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
|
|
1568
|
+
const rentExempt = await this.kaminoMarket.getConnection().getMinimumBalanceForRentExemption(165);
|
|
1569
|
+
// Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
|
|
1570
|
+
const sendAction = action === 'deposit' ||
|
|
1571
|
+
action === 'repay' ||
|
|
1572
|
+
action === 'mint' ||
|
|
1573
|
+
(action === 'liquidate' && this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
1574
|
+
const transferLamportsIx = web3_js_1.SystemProgram.transfer({
|
|
1575
|
+
fromPubkey: this.owner,
|
|
1576
|
+
toPubkey: userTokenAccountAddress,
|
|
1577
|
+
lamports: (userWSOLAccountInfo ? 0 : rentExempt) + (sendAction ? parseInt(safeRepay.toString(), 10) : 0),
|
|
1578
|
+
});
|
|
1579
|
+
preIxs.push(transferLamportsIx);
|
|
1580
|
+
preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1581
|
+
const closeWSOLAccountIx = (0, spl_token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, [], spl_token_1.TOKEN_PROGRAM_ID);
|
|
1582
|
+
const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
|
|
1583
|
+
if (userWSOLAccountInfo) {
|
|
1584
|
+
if (sendAction) {
|
|
1646
1585
|
preIxs.push(syncIx);
|
|
1647
1586
|
preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1648
1589
|
postIxs.push(closeWSOLAccountIx);
|
|
1649
1590
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1650
1591
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1592
|
+
}
|
|
1593
|
+
else {
|
|
1594
|
+
const [, createUserWSOLAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, spl_token_1.NATIVE_MINT, this.owner, spl_token_1.TOKEN_PROGRAM_ID, userTokenAccountAddress);
|
|
1595
|
+
preIxs.push(createUserWSOLAccountIx);
|
|
1596
|
+
preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1597
|
+
preIxs.push(syncIx);
|
|
1598
|
+
preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1599
|
+
postIxs.push(closeWSOLAccountIx);
|
|
1600
|
+
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
1601
|
+
}
|
|
1602
|
+
// TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
|
|
1603
|
+
// if (this.positions && this.positions >= POSITION_LIMIT) {
|
|
1604
|
+
// this.preTxnIxs.push(...preIxs);
|
|
1605
|
+
// this.preTxnIxsLabels.push(...preIxsLabels);
|
|
1606
|
+
// this.postTxnIxs.push(...postIxs);
|
|
1607
|
+
// this.postTxnIxsLabels.push(...postIxsLabels);
|
|
1608
|
+
// } else {
|
|
1609
|
+
// }
|
|
1610
|
+
this.setupIxs.unshift(...preIxs);
|
|
1611
|
+
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
1612
|
+
this.cleanupIxs.push(...postIxs);
|
|
1613
|
+
this.cleanupIxsLabels.push(...postIxsLabels);
|
|
1664
1614
|
}
|
|
1665
|
-
static initializeMultiTokenAction(
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
|
|
1706
|
-
});
|
|
1615
|
+
static async initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
1616
|
+
const inflowReserve = kaminoMarket.getReserveByMint(inflowTokenMint);
|
|
1617
|
+
const outflowReserve = kaminoMarket.getReserveByMint(outflowTokenMint);
|
|
1618
|
+
if (!outflowReserve || !inflowReserve) {
|
|
1619
|
+
throw new Error('reserve states are not fetched');
|
|
1620
|
+
}
|
|
1621
|
+
const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
|
|
1622
|
+
const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
|
|
1623
|
+
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
|
|
1624
|
+
const referrerKey = await this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
|
|
1625
|
+
let userTokenAccountAddress;
|
|
1626
|
+
let userCollateralAccountAddress;
|
|
1627
|
+
let additionalUserTokenAccountAddress;
|
|
1628
|
+
let secondaryMint;
|
|
1629
|
+
let primaryMint;
|
|
1630
|
+
if (action === 'liquidate') {
|
|
1631
|
+
userTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
1632
|
+
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
1633
|
+
additionalUserTokenAccountAddress = userInflowTokenAccountAddress;
|
|
1634
|
+
primaryMint = outflowTokenMint;
|
|
1635
|
+
secondaryMint = inflowTokenMint;
|
|
1636
|
+
}
|
|
1637
|
+
else if (action === 'depositAndBorrow') {
|
|
1638
|
+
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
1639
|
+
userCollateralAccountAddress = userInflowCollateralAccountAddress;
|
|
1640
|
+
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
1641
|
+
primaryMint = inflowTokenMint;
|
|
1642
|
+
secondaryMint = outflowTokenMint;
|
|
1643
|
+
}
|
|
1644
|
+
else if (action === 'repayAndWithdraw') {
|
|
1645
|
+
primaryMint = inflowTokenMint;
|
|
1646
|
+
secondaryMint = outflowTokenMint;
|
|
1647
|
+
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
1648
|
+
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
1649
|
+
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
1650
|
+
}
|
|
1651
|
+
else {
|
|
1652
|
+
throw new Error('Invalid action');
|
|
1653
|
+
}
|
|
1654
|
+
return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
|
|
1707
1655
|
}
|
|
1708
|
-
static initializeWithdrawReferrerFees(
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
};
|
|
1720
|
-
});
|
|
1656
|
+
static async initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0) {
|
|
1657
|
+
const reserve = kaminoMarket.getReserveByMint(mint);
|
|
1658
|
+
if (reserve === undefined) {
|
|
1659
|
+
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
1660
|
+
}
|
|
1661
|
+
const { atas, createAtasIxns } = await (0, utils_1.getAtasWithCreateIxnsIfMissing)(kaminoMarket.getConnection(), owner, [reserve.getLiquidityMint()], [reserve.getLiquidityTokenProgram()]);
|
|
1662
|
+
const userTokenAccountAddress = atas[0];
|
|
1663
|
+
return {
|
|
1664
|
+
axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), userTokenAccountAddress, web3_js_1.PublicKey.default, mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
|
|
1665
|
+
createAtasIxns,
|
|
1666
|
+
};
|
|
1721
1667
|
}
|
|
1722
1668
|
getObligationPda() {
|
|
1723
1669
|
return this.obligation
|
|
@@ -1741,22 +1687,20 @@ class KaminoAction {
|
|
|
1741
1687
|
}
|
|
1742
1688
|
return depositReservesList;
|
|
1743
1689
|
}
|
|
1744
|
-
static getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer) {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
if (
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
referrerKey = userMetadata.referrer;
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
else {
|
|
1755
|
-
referrerKey = kaminoObligation.state.referrer;
|
|
1690
|
+
static async getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer) {
|
|
1691
|
+
let referrerKey = referrer;
|
|
1692
|
+
if (!referrer || referrer.equals(web3_js_1.PublicKey.default)) {
|
|
1693
|
+
if (kaminoObligation === null) {
|
|
1694
|
+
const [_, userMetadata] = await kaminoMarket.getUserMetadata(owner);
|
|
1695
|
+
if (userMetadata) {
|
|
1696
|
+
referrerKey = userMetadata.referrer;
|
|
1756
1697
|
}
|
|
1757
1698
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1699
|
+
else {
|
|
1700
|
+
referrerKey = kaminoObligation.state.referrer;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
return referrerKey;
|
|
1760
1704
|
}
|
|
1761
1705
|
}
|
|
1762
1706
|
exports.KaminoAction = KaminoAction;
|