@kamino-finance/klend-sdk 3.2.25 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +1 -0
- package/dist/classes/action.d.ts.map +1 -0
- package/dist/classes/action.js +1130 -1186
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/curve.d.ts +1 -0
- package/dist/classes/curve.d.ts.map +1 -0
- package/dist/classes/curve.js +1 -1
- package/dist/classes/curve.js.map +1 -1
- package/dist/classes/fraction.d.ts +1 -0
- package/dist/classes/fraction.d.ts.map +1 -0
- package/dist/classes/fraction.js +7 -6
- package/dist/classes/fraction.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/jupiterPerps.d.ts +1 -0
- package/dist/classes/jupiterPerps.d.ts.map +1 -0
- package/dist/classes/jupiterPerps.js +7 -18
- package/dist/classes/jupiterPerps.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -0
- package/dist/classes/manager.d.ts.map +1 -0
- package/dist/classes/manager.js +131 -158
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +1 -0
- package/dist/classes/market.d.ts.map +1 -0
- package/dist/classes/market.js +620 -714
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -0
- package/dist/classes/obligation.d.ts.map +1 -0
- package/dist/classes/obligation.js +60 -62
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -0
- package/dist/classes/reserve.d.ts.map +1 -0
- package/dist/classes/reserve.js +135 -138
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -0
- package/dist/classes/shared.d.ts.map +1 -0
- package/dist/classes/shared.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -0
- package/dist/classes/utils.d.ts.map +1 -0
- package/dist/classes/utils.js +3 -3
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -0
- package/dist/classes/vault.js +334 -354
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts +1 -0
- package/dist/client_kamino_manager.d.ts.map +1 -0
- package/dist/client_kamino_manager.js +323 -326
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.js +89 -55
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +1 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Obligation.js +87 -56
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.js +22 -33
- package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js +35 -37
- package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Reserve.js +60 -49
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen/accounts/ShortUrl.d.ts +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.js +22 -33
- package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -1
- package/dist/idl_codegen/accounts/UserMetadata.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.js +34 -37
- package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -1
- package/dist/idl_codegen/accounts/UserState.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserState.js +77 -48
- package/dist/idl_codegen/accounts/UserState.js.map +1 -1
- package/dist/idl_codegen/accounts/index.d.ts +1 -0
- package/dist/idl_codegen/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/index.js.map +1 -1
- package/dist/idl_codegen/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen/errors/anchor.js +270 -216
- package/dist/idl_codegen/errors/anchor.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +1 -0
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen/errors/custom.js +560 -448
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/errors/index.d.ts +1 -0
- package/dist/idl_codegen/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen/errors/index.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +1 -0
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -1
- package/dist/idl_codegen/instructions/socializeLoss.d.ts +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -1
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/programId.d.ts +1 -0
- package/dist/idl_codegen/programId.d.ts.map +1 -0
- package/dist/idl_codegen/programId.js.map +1 -1
- package/dist/idl_codegen/types/AssetTier.d.ts +1 -0
- package/dist/idl_codegen/types/AssetTier.d.ts.map +1 -0
- package/dist/idl_codegen/types/AssetTier.js +12 -18
- package/dist/idl_codegen/types/AssetTier.js.map +1 -1
- package/dist/idl_codegen/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen/types/CurvePoint.js +2 -0
- package/dist/idl_codegen/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen/types/ElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/types/ElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/types/ElevationGroup.js +10 -0
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -1
- package/dist/idl_codegen/types/FeeCalculation.d.ts +1 -0
- package/dist/idl_codegen/types/FeeCalculation.d.ts.map +1 -0
- package/dist/idl_codegen/types/FeeCalculation.js +8 -12
- package/dist/idl_codegen/types/FeeCalculation.js.map +1 -1
- package/dist/idl_codegen/types/InitObligationArgs.d.ts +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.d.ts.map +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.js +2 -0
- package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -1
- package/dist/idl_codegen/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen/types/LastUpdate.js +7 -0
- package/dist/idl_codegen/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +14 -0
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +17 -1
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.js +78 -5
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js +8 -12
- package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFees.js +16 -0
- package/dist/idl_codegen/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js +43 -1
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/ReserveStatus.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveStatus.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveStatus.js +12 -18
- package/dist/idl_codegen/types/ReserveStatus.js.map +1 -1
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen/types/TokenInfo.js +27 -4
- package/dist/idl_codegen/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +188 -282
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +41 -33
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +72 -108
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +1 -0
- package/dist/idl_codegen/types/index.d.ts.map +1 -0
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js +83 -54
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/index.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +39 -42
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/programId.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js +9 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +58 -47
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +51 -47
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +270 -216
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js +120 -96
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +7 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +77 -5
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +16 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +41 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +27 -4
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.js +15 -24
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -0
- package/dist/leverage/calcs.d.ts.map +1 -0
- package/dist/leverage/calcs.js +119 -132
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/index.d.ts +1 -0
- package/dist/leverage/index.d.ts.map +1 -0
- package/dist/leverage/index.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -0
- package/dist/leverage/instructions.d.ts.map +1 -0
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +1 -0
- package/dist/leverage/operations.d.ts.map +1 -0
- package/dist/leverage/operations.js +75 -84
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/utils.d.ts +1 -0
- package/dist/leverage/utils.d.ts.map +1 -0
- package/dist/leverage/utils.js +73 -88
- package/dist/leverage/utils.js.map +1 -1
- package/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/referrals/index.d.ts +1 -0
- package/dist/referrals/index.d.ts.map +1 -0
- package/dist/referrals/index.js.map +1 -1
- package/dist/referrals/instructions.d.ts +1 -0
- package/dist/referrals/instructions.d.ts.map +1 -0
- package/dist/referrals/instructions.js +8 -17
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/referrals/operations.d.ts +2 -1
- package/dist/referrals/operations.d.ts.map +1 -0
- package/dist/referrals/operations.js +119 -143
- package/dist/referrals/operations.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -0
- package/dist/utils/ObligationType.d.ts.map +1 -0
- package/dist/utils/ObligationType.js +16 -7
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +1 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +10 -21
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -0
- package/dist/utils/ata.d.ts.map +1 -0
- package/dist/utils/ata.js +25 -38
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/idl.d.ts +1 -0
- package/dist/utils/idl.d.ts.map +1 -0
- package/dist/utils/idl.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -0
- package/dist/utils/instruction.js +116 -143
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/kamino.d.ts +1 -0
- package/dist/utils/kamino.d.ts.map +1 -0
- package/dist/utils/kamino.js +4 -15
- package/dist/utils/kamino.js.map +1 -1
- package/dist/utils/layout.d.ts +1 -0
- package/dist/utils/layout.d.ts.map +1 -0
- package/dist/utils/layout.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +1 -0
- package/dist/utils/lookupTable.d.ts.map +1 -0
- package/dist/utils/lookupTable.js +14 -27
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -0
- package/dist/utils/managerTypes.js +31 -2
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +1 -0
- package/dist/utils/oracle.d.ts.map +1 -0
- package/dist/utils/oracle.js +70 -83
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/pubkey.d.ts +1 -0
- package/dist/utils/pubkey.d.ts.map +1 -0
- package/dist/utils/pubkey.js +7 -9
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/rpc.d.ts +1 -0
- package/dist/utils/rpc.d.ts.map +1 -0
- package/dist/utils/rpc.js +48 -70
- package/dist/utils/rpc.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -0
- package/dist/utils/seeds.d.ts.map +1 -0
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sendTransactionsUtils.d.ts +1 -0
- package/dist/utils/sendTransactionsUtils.d.ts.map +1 -0
- package/dist/utils/sendTransactionsUtils.js +82 -82
- package/dist/utils/sendTransactionsUtils.js.map +1 -1
- package/dist/utils/slots.d.ts +1 -0
- package/dist/utils/slots.d.ts.map +1 -0
- package/dist/utils/slots.js.map +1 -1
- package/dist/utils/syncNative.d.ts +1 -0
- package/dist/utils/syncNative.d.ts.map +1 -0
- package/dist/utils/syncNative.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +1 -0
- package/dist/utils/userMetadata.d.ts.map +1 -0
- package/dist/utils/userMetadata.js +40 -52
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +9 -3
- package/src/classes/action.ts +2884 -0
- package/src/classes/curve.ts +29 -0
- package/src/classes/fraction.ts +65 -0
- package/src/classes/index.ts +10 -0
- package/src/classes/jupiterPerps.ts +14 -0
- package/src/classes/manager.ts +746 -0
- package/src/classes/market.ts +1459 -0
- package/src/classes/obligation.ts +1315 -0
- package/src/classes/reserve.ts +1980 -0
- package/src/classes/shared.ts +57 -0
- package/src/classes/utils.ts +192 -0
- package/src/classes/vault.ts +808 -0
- package/src/client.ts +446 -0
- package/src/client_kamino_manager.ts +791 -0
- package/src/global.d.ts +1 -0
- package/src/idl_codegen/accounts/LendingMarket.ts +364 -0
- package/src/idl_codegen/accounts/Obligation.ts +349 -0
- package/src/idl_codegen/accounts/ReferrerState.ts +97 -0
- package/src/idl_codegen/accounts/ReferrerTokenState.ts +145 -0
- package/src/idl_codegen/accounts/Reserve.ts +248 -0
- package/src/idl_codegen/accounts/ShortUrl.ts +97 -0
- package/src/idl_codegen/accounts/UserMetadata.ts +142 -0
- package/src/idl_codegen/accounts/UserState.ts +301 -0
- package/src/idl_codegen/accounts/index.ts +19 -0
- package/src/idl_codegen/errors/anchor.ts +773 -0
- package/src/idl_codegen/errors/custom.ts +1633 -0
- package/src/idl_codegen/errors/index.ts +62 -0
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/deleteReferrerStateAndShortUrl.ts +30 -0
- package/src/idl_codegen/instructions/depositObligationCollateral.ts +62 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +90 -0
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +98 -0
- package/src/idl_codegen/instructions/flashBorrowReserveLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/flashRepayReserveLiquidity.ts +83 -0
- package/src/idl_codegen/instructions/idlMissingTypes.ts +62 -0
- package/src/idl_codegen/instructions/index.ts +138 -0
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/initLendingMarket.ts +50 -0
- package/src/idl_codegen/instructions/initObligation.ts +52 -0
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +60 -0
- package/src/idl_codegen/instructions/initReferrerStateAndShortUrl.ts +50 -0
- package/src/idl_codegen/instructions/initReferrerTokenState.ts +46 -0
- package/src/idl_codegen/instructions/initReserve.ts +74 -0
- package/src/idl_codegen/instructions/initUserMetadata.ts +50 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +139 -0
- package/src/idl_codegen/instructions/redeemFees.ts +50 -0
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +94 -0
- package/src/idl_codegen/instructions/refreshObligation.ts +24 -0
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/refreshReserve.ts +40 -0
- package/src/idl_codegen/instructions/refreshReservesBatch.ts +29 -0
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +64 -0
- package/src/idl_codegen/instructions/requestElevationGroup.ts +40 -0
- package/src/idl_codegen/instructions/socializeLoss.ts +48 -0
- package/src/idl_codegen/instructions/updateEntireReserveConfig.ts +45 -0
- package/src/idl_codegen/instructions/updateLendingMarket.ts +43 -0
- package/src/idl_codegen/instructions/updateLendingMarketOwner.ts +28 -0
- package/src/idl_codegen/instructions/updateReserveConfig.ts +52 -0
- package/src/idl_codegen/instructions/updateSingleReserveConfig.ts +48 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateral.ts +68 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +102 -0
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +62 -0
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +54 -0
- package/src/idl_codegen/programId.ts +13 -0
- package/src/idl_codegen/types/AssetTier.ts +118 -0
- package/src/idl_codegen/types/BigFractionBytes.ts +67 -0
- package/src/idl_codegen/types/BorrowRateCurve.ts +60 -0
- package/src/idl_codegen/types/CurvePoint.ts +64 -0
- package/src/idl_codegen/types/ElevationGroup.ts +133 -0
- package/src/idl_codegen/types/FeeCalculation.ts +90 -0
- package/src/idl_codegen/types/InitObligationArgs.ts +61 -0
- package/src/idl_codegen/types/LastUpdate.ts +95 -0
- package/src/idl_codegen/types/ObligationCollateral.ts +128 -0
- package/src/idl_codegen/types/ObligationLiquidity.ts +159 -0
- package/src/idl_codegen/types/PriceHeuristic.ts +81 -0
- package/src/idl_codegen/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen/types/ReserveConfig.ts +467 -0
- package/src/idl_codegen/types/ReserveFarmKind.ts +90 -0
- package/src/idl_codegen/types/ReserveFees.ts +122 -0
- package/src/idl_codegen/types/ReserveLiquidity.ts +286 -0
- package/src/idl_codegen/types/ReserveStatus.ts +120 -0
- package/src/idl_codegen/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen/types/SwitchboardConfiguration.ts +67 -0
- package/src/idl_codegen/types/TokenInfo.ts +190 -0
- package/src/idl_codegen/types/UpdateConfigMode.ts +1440 -0
- package/src/idl_codegen/types/UpdateLendingMarketConfigValue.ts +376 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +570 -0
- package/src/idl_codegen/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen/types/index.ts +276 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +186 -0
- package/src/idl_codegen/zero_padding/index.ts +1 -0
- package/src/idl_codegen_jupiter_perps/accounts/Pool.ts +155 -0
- package/src/idl_codegen_jupiter_perps/accounts/index.ts +2 -0
- package/src/idl_codegen_jupiter_perps/programId.ts +7 -0
- package/src/idl_codegen_jupiter_perps/types/Fees.ts +130 -0
- package/src/idl_codegen_jupiter_perps/types/Limit.ts +72 -0
- package/src/idl_codegen_jupiter_perps/types/PoolApr.ts +69 -0
- package/src/idl_codegen_jupiter_perps/types/index.ts +6 -0
- package/src/idl_codegen_kamino_vault/accounts/Reserve.ts +221 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +214 -0
- package/src/idl_codegen_kamino_vault/accounts/index.ts +4 -0
- package/src/idl_codegen_kamino_vault/errors/anchor.ts +764 -0
- package/src/idl_codegen_kamino_vault/errors/custom.ts +344 -0
- package/src/idl_codegen_kamino_vault/errors/index.ts +49 -0
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +54 -0
- package/src/idl_codegen_kamino_vault/instructions/index.ts +10 -0
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +35 -0
- package/src/idl_codegen_kamino_vault/instructions/invest.ts +60 -0
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +58 -0
- package/src/idl_codegen_kamino_vault/instructions/withdraw.ts +81 -0
- package/src/idl_codegen_kamino_vault/programId.ts +7 -0
- package/src/idl_codegen_kamino_vault/types/BigFractionBytes.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/BorrowRateCurve.ts +55 -0
- package/src/idl_codegen_kamino_vault/types/CurvePoint.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/LastUpdate.ts +90 -0
- package/src/idl_codegen_kamino_vault/types/PriceHeuristic.ts +78 -0
- package/src/idl_codegen_kamino_vault/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen_kamino_vault/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen_kamino_vault/types/ReserveConfig.ts +426 -0
- package/src/idl_codegen_kamino_vault/types/ReserveFees.ts +118 -0
- package/src/idl_codegen_kamino_vault/types/ReserveLiquidity.ts +268 -0
- package/src/idl_codegen_kamino_vault/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen_kamino_vault/types/SwitchboardConfiguration.ts +64 -0
- package/src/idl_codegen_kamino_vault/types/TokenInfo.ts +172 -0
- package/src/idl_codegen_kamino_vault/types/VaultAllocation.ts +115 -0
- package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +30 -0
- package/src/index.ts +1 -0
- package/src/lending_operations/index.ts +2 -0
- package/src/lending_operations/repay_with_collateral_calcs.ts +71 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +318 -0
- package/src/leverage/calcs.ts +465 -0
- package/src/leverage/index.ts +4 -0
- package/src/leverage/instructions.ts +144 -0
- package/src/leverage/operations.ts +1814 -0
- package/src/leverage/utils.ts +273 -0
- package/src/lib.ts +9 -0
- package/src/referrals/index.ts +2 -0
- package/src/referrals/instructions.ts +114 -0
- package/src/referrals/operations.ts +325 -0
- package/src/utils/ObligationType.ts +171 -0
- package/src/utils/api.ts +59 -0
- package/src/utils/ata.ts +195 -0
- package/src/utils/constants.ts +81 -0
- package/src/utils/idl.ts +4 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/instruction.ts +258 -0
- package/src/utils/kamino.ts +12 -0
- package/src/utils/layout.ts +118 -0
- package/src/utils/lookupTable.ts +55 -0
- package/src/utils/managerTypes.ts +456 -0
- package/src/utils/oracle.ts +338 -0
- package/src/utils/pubkey.ts +261 -0
- package/src/utils/rpc.ts +108 -0
- package/src/utils/seeds.ts +183 -0
- package/src/utils/sendTransactionsUtils.ts +207 -0
- package/src/utils/slots.ts +28 -0
- package/src/utils/syncNative.ts +22 -0
- package/src/utils/userMetadata.ts +401 -0
package/dist/classes/market.js
CHANGED
|
@@ -22,28 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
35
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
36
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
37
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
38
|
-
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
39
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
40
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
41
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
42
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
43
|
-
function fulfill(value) { resume("next", value); }
|
|
44
|
-
function reject(value) { resume("throw", value); }
|
|
45
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
46
|
-
};
|
|
47
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
27
|
};
|
|
@@ -71,6 +49,14 @@ const utils_2 = require("./utils");
|
|
|
71
49
|
const sbv2_lite_1 = __importDefault(require("@switchboard-xyz/sbv2-lite"));
|
|
72
50
|
const zero_padding_1 = require("../idl_codegen/zero_padding");
|
|
73
51
|
class KaminoMarket {
|
|
52
|
+
connection;
|
|
53
|
+
address;
|
|
54
|
+
state;
|
|
55
|
+
reserves;
|
|
56
|
+
reservesActive;
|
|
57
|
+
programId;
|
|
58
|
+
scope;
|
|
59
|
+
recentSlotDurationMs;
|
|
74
60
|
constructor(connection, state, marketAddress, reserves, scope, recentSlotDurationMs, programId = programId_1.PROGRAM_ID) {
|
|
75
61
|
this.address = marketAddress;
|
|
76
62
|
this.connection = connection;
|
|
@@ -88,42 +74,36 @@ class KaminoMarket {
|
|
|
88
74
|
* @param programId
|
|
89
75
|
* @param setupLocalTest
|
|
90
76
|
*/
|
|
91
|
-
static load(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.state = market;
|
|
117
|
-
this.reserves = yield getReservesForMarket(this.getAddress(), this.connection, this.programId, this.recentSlotDurationMs);
|
|
118
|
-
this.reservesActive = getReservesActive(this.reserves);
|
|
119
|
-
});
|
|
77
|
+
static async load(connection, marketAddress, recentSlotDurationMs, programId = programId_1.PROGRAM_ID, setupLocalTest = false, withReserves = true) {
|
|
78
|
+
const market = await accounts_1.LendingMarket.fetch(connection, marketAddress, programId);
|
|
79
|
+
if (market === null) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
let scope;
|
|
83
|
+
if (!setupLocalTest) {
|
|
84
|
+
scope = new scope_sdk_1.Scope('mainnet-beta', connection);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
scope = new scope_sdk_1.Scope('localnet', connection);
|
|
88
|
+
}
|
|
89
|
+
const reserves = withReserves
|
|
90
|
+
? await getReservesForMarket(marketAddress, connection, programId, recentSlotDurationMs)
|
|
91
|
+
: new Map();
|
|
92
|
+
return new KaminoMarket(connection, market, marketAddress.toString(), reserves, scope, recentSlotDurationMs, programId);
|
|
93
|
+
}
|
|
94
|
+
async reload() {
|
|
95
|
+
const market = await accounts_1.LendingMarket.fetch(this.connection, this.getAddress(), this.programId);
|
|
96
|
+
if (market === null) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.state = market;
|
|
100
|
+
this.reserves = await getReservesForMarket(this.getAddress(), this.connection, this.programId, this.recentSlotDurationMs);
|
|
101
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
120
102
|
}
|
|
121
|
-
reloadSingleReserve(reservePk, accountData) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.reservesActive.set(reservePk, reserve);
|
|
126
|
-
});
|
|
103
|
+
async reloadSingleReserve(reservePk, accountData) {
|
|
104
|
+
const reserve = await getSingleReserve(reservePk, this.connection, this.recentSlotDurationMs, accountData);
|
|
105
|
+
this.reserves.set(reservePk, reserve);
|
|
106
|
+
this.reservesActive.set(reservePk, reserve);
|
|
127
107
|
}
|
|
128
108
|
/**
|
|
129
109
|
* Get the address of this market
|
|
@@ -151,19 +131,13 @@ class KaminoMarket {
|
|
|
151
131
|
getLendingMarketAuthority() {
|
|
152
132
|
return (0, utils_1.lendingMarketAuthPda)(this.getAddress(), this.programId)[0];
|
|
153
133
|
}
|
|
154
|
-
getObligationDepositByWallet(owner, mint, obligationType) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const obligation = yield this.getObligationByWallet(owner, obligationType);
|
|
158
|
-
return (_b = (_a = obligation === null || obligation === void 0 ? void 0 : obligation.getDepositByMint(mint)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : new decimal_js_1.default(0);
|
|
159
|
-
});
|
|
134
|
+
async getObligationDepositByWallet(owner, mint, obligationType) {
|
|
135
|
+
const obligation = await this.getObligationByWallet(owner, obligationType);
|
|
136
|
+
return obligation?.getDepositByMint(mint)?.amount ?? new decimal_js_1.default(0);
|
|
160
137
|
}
|
|
161
|
-
getObligationBorrowByWallet(owner, mint, obligationType) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const obligation = yield this.getObligationByWallet(owner, obligationType);
|
|
165
|
-
return (_b = (_a = obligation === null || obligation === void 0 ? void 0 : obligation.getBorrowByMint(mint)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : new decimal_js_1.default(0);
|
|
166
|
-
});
|
|
138
|
+
async getObligationBorrowByWallet(owner, mint, obligationType) {
|
|
139
|
+
const obligation = await this.getObligationByWallet(owner, obligationType);
|
|
140
|
+
return obligation?.getBorrowByMint(mint)?.amount ?? new decimal_js_1.default(0);
|
|
167
141
|
}
|
|
168
142
|
getTotalDepositTVL() {
|
|
169
143
|
let tvl = new decimal_js_1.default(0);
|
|
@@ -206,102 +180,90 @@ class KaminoMarket {
|
|
|
206
180
|
: this.state.elevationGroups
|
|
207
181
|
.filter((e) => commonElevationGroups.includes(e.id))
|
|
208
182
|
.reduce((acc, elem) => Math.max(acc, elem.liquidationThresholdPct), 0);
|
|
209
|
-
const borrowFactor = commonElevationGroups.length === 0 ?
|
|
183
|
+
const borrowFactor = commonElevationGroups.length === 0 ? debtReserve?.state.config.borrowFactorPct.toNumber() / 100 : 1;
|
|
210
184
|
return { maxLtv: maxCollateralLtv / 100, liquidationLtv: liquidationLtv / 100, borrowFactor };
|
|
211
185
|
}
|
|
212
|
-
getTotalProductTvl(productType) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return { tvl: deposits.sub(borrows), deposits, borrows, avgLeverage: avgLeverage.div(obligations.length) };
|
|
238
|
-
});
|
|
186
|
+
async getTotalProductTvl(productType) {
|
|
187
|
+
let obligations = (await this.getAllObligationsForMarket(productType.toArgs().tag)).filter((obligation) => obligation.refreshedStats.userTotalBorrow.gt(0) || obligation.refreshedStats.userTotalDeposit.gt(0));
|
|
188
|
+
switch (productType.toArgs().tag) {
|
|
189
|
+
case utils_1.VanillaObligation.tag: {
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case utils_1.LendingObligation.tag: {
|
|
193
|
+
const mint = productType.toArgs().seed1;
|
|
194
|
+
obligations = obligations.filter((obligation) => obligation.getDepositByMint(mint) !== undefined);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case utils_1.MultiplyObligation.tag:
|
|
198
|
+
case utils_1.LeverageObligation.tag: {
|
|
199
|
+
const collMint = productType.toArgs().seed1;
|
|
200
|
+
const debtMint = productType.toArgs().seed2;
|
|
201
|
+
obligations = obligations.filter((obligation) => obligation.getDepositByMint(collMint) !== undefined && obligation.getBorrowByMint(debtMint) !== undefined);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
default:
|
|
205
|
+
throw new Error('Invalid obligation type');
|
|
206
|
+
}
|
|
207
|
+
const deposits = obligations.reduce((acc, obligation) => acc.plus(obligation.refreshedStats.userTotalDeposit), new decimal_js_1.default(0));
|
|
208
|
+
const borrows = obligations.reduce((acc, obligation) => acc.plus(obligation.refreshedStats.userTotalBorrow), new decimal_js_1.default(0));
|
|
209
|
+
const avgLeverage = obligations.reduce((acc, obligations) => acc.plus(obligations.refreshedStats.leverage), new decimal_js_1.default(0));
|
|
210
|
+
return { tvl: deposits.sub(borrows), deposits, borrows, avgLeverage: avgLeverage.div(obligations.length) };
|
|
239
211
|
}
|
|
240
212
|
/**
|
|
241
213
|
*
|
|
242
214
|
* @returns Number of active obligations in the market
|
|
243
215
|
*/
|
|
244
|
-
getNumberOfObligations() {
|
|
245
|
-
return
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
const obligationAddress = obligationType.toPda(this.getAddress(), publicKey);
|
|
258
|
-
return obligation_1.KaminoObligation.load(this, obligationAddress);
|
|
259
|
-
});
|
|
216
|
+
async getNumberOfObligations() {
|
|
217
|
+
return (await this.getAllObligationsForMarket())
|
|
218
|
+
.filter((obligation) => obligation.refreshedStats.userTotalBorrow.gt(0) || obligation.refreshedStats.userTotalDeposit.gt(0))
|
|
219
|
+
.reduce((acc, _obligation) => acc + 1, 0);
|
|
220
|
+
}
|
|
221
|
+
async getObligationByWallet(publicKey, obligationType) {
|
|
222
|
+
const { address } = this;
|
|
223
|
+
if (!address) {
|
|
224
|
+
throw Error('Market must be initialized to call initialize.');
|
|
225
|
+
}
|
|
226
|
+
const obligationAddress = obligationType.toPda(this.getAddress(), publicKey);
|
|
227
|
+
return obligation_1.KaminoObligation.load(this, obligationAddress);
|
|
260
228
|
}
|
|
261
229
|
/**
|
|
262
230
|
* @returns The max borrowable amount for leverage positions
|
|
263
231
|
*/
|
|
264
|
-
getMaxLeverageBorrowableAmount(collReserve, debtReserve, slot, requestElevationGroup, obligation) {
|
|
265
|
-
return
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
232
|
+
async getMaxLeverageBorrowableAmount(collReserve, debtReserve, slot, requestElevationGroup, obligation) {
|
|
233
|
+
return obligation
|
|
234
|
+
? obligation.getMaxBorrowAmount(this, debtReserve.getLiquidityMint(), slot, requestElevationGroup)
|
|
235
|
+
: debtReserve.getMaxBorrowAmountWithCollReserve(this, collReserve, slot);
|
|
236
|
+
}
|
|
237
|
+
async loadReserves() {
|
|
238
|
+
const addresses = [...this.reserves.keys()];
|
|
239
|
+
const reserveAccounts = await this.connection.getMultipleAccountsInfo(addresses, 'processed');
|
|
240
|
+
const deserializedReserves = reserveAccounts.map((reserve, i) => {
|
|
241
|
+
if (reserve === null) {
|
|
242
|
+
// maybe reuse old here
|
|
243
|
+
throw new Error(`Reserve account ${addresses[i].toBase58()} was not found`);
|
|
244
|
+
}
|
|
245
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.data);
|
|
246
|
+
if (!reserveAccount) {
|
|
247
|
+
throw Error(`Could not parse reserve ${addresses[i].toBase58()}`);
|
|
248
|
+
}
|
|
249
|
+
return reserveAccount;
|
|
269
250
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
throw new Error(`Reserve account ${addresses[i].toBase58()} was not found`);
|
|
279
|
-
}
|
|
280
|
-
const reserveAccount = accounts_1.Reserve.decode(reserve.data);
|
|
281
|
-
if (!reserveAccount) {
|
|
282
|
-
throw Error(`Could not parse reserve ${addresses[i].toBase58()}`);
|
|
283
|
-
}
|
|
284
|
-
return reserveAccount;
|
|
285
|
-
});
|
|
286
|
-
const reservesAndOracles = yield (0, utils_1.getTokenOracleData)(this.connection, deserializedReserves);
|
|
287
|
-
const kaminoReserves = new utils_1.PubkeyHashMap();
|
|
288
|
-
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
289
|
-
if (!oracle) {
|
|
290
|
-
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
291
|
-
}
|
|
292
|
-
const kaminoReserve = reserve_1.KaminoReserve.initialize(reserveAccounts[index], addresses[index], reserve, oracle, this.connection, this.recentSlotDurationMs);
|
|
293
|
-
kaminoReserves.set(kaminoReserve.address, kaminoReserve);
|
|
294
|
-
});
|
|
295
|
-
this.reserves = kaminoReserves;
|
|
296
|
-
this.reservesActive = getReservesActive(this.reserves);
|
|
251
|
+
const reservesAndOracles = await (0, utils_1.getTokenOracleData)(this.connection, deserializedReserves);
|
|
252
|
+
const kaminoReserves = new utils_1.PubkeyHashMap();
|
|
253
|
+
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
254
|
+
if (!oracle) {
|
|
255
|
+
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
256
|
+
}
|
|
257
|
+
const kaminoReserve = reserve_1.KaminoReserve.initialize(reserveAccounts[index], addresses[index], reserve, oracle, this.connection, this.recentSlotDurationMs);
|
|
258
|
+
kaminoReserves.set(kaminoReserve.address, kaminoReserve);
|
|
297
259
|
});
|
|
260
|
+
this.reserves = kaminoReserves;
|
|
261
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
298
262
|
}
|
|
299
|
-
refreshAll() {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this.reservesActive = getReservesActive(this.reserves);
|
|
304
|
-
});
|
|
263
|
+
async refreshAll() {
|
|
264
|
+
const promises = [this.getReserves().every((reserve) => reserve.stats) ? this.loadReserves() : null].filter((x) => x);
|
|
265
|
+
await Promise.all(promises);
|
|
266
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
305
267
|
}
|
|
306
268
|
getReserveByAddress(address) {
|
|
307
269
|
return this.reserves.get(address);
|
|
@@ -323,79 +285,74 @@ class KaminoMarket {
|
|
|
323
285
|
return undefined;
|
|
324
286
|
}
|
|
325
287
|
getReserveMintBySymbol(symbol) {
|
|
326
|
-
|
|
327
|
-
return (_a = this.getReserveBySymbol(symbol)) === null || _a === void 0 ? void 0 : _a.getLiquidityMint();
|
|
328
|
-
}
|
|
329
|
-
getReserveFarmInfo(mint, getRewardPrice) {
|
|
330
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
-
const { address } = this;
|
|
332
|
-
if (!address) {
|
|
333
|
-
throw Error('Market must be initialized to call initialize.');
|
|
334
|
-
}
|
|
335
|
-
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
336
|
-
yield this.loadReserves();
|
|
337
|
-
}
|
|
338
|
-
// Find the reserve
|
|
339
|
-
const kaminoReserve = this.getReserveByMint(mint);
|
|
340
|
-
if (!kaminoReserve) {
|
|
341
|
-
throw Error(`Could not find reserve. ${mint}`);
|
|
342
|
-
}
|
|
343
|
-
const totalDepositAmount = lamportsToNumberDecimal(kaminoReserve.getLiquidityAvailableAmount(), kaminoReserve.stats.decimals);
|
|
344
|
-
const totalBorrowAmount = lamportsToNumberDecimal(kaminoReserve.getBorrowedAmount(), kaminoReserve.stats.decimals);
|
|
345
|
-
const collateralFarmAddress = kaminoReserve.state.farmCollateral;
|
|
346
|
-
const debtFarmAddress = kaminoReserve.state.farmDebt;
|
|
347
|
-
const result = {
|
|
348
|
-
borrowingRewards: {
|
|
349
|
-
rewardsPerSecond: new decimal_js_1.default(0),
|
|
350
|
-
rewardsRemaining: new decimal_js_1.default(0),
|
|
351
|
-
rewardApr: new decimal_js_1.default(0),
|
|
352
|
-
rewardMint: web3_js_1.PublicKey.default,
|
|
353
|
-
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
354
|
-
rewardPrice: 0,
|
|
355
|
-
},
|
|
356
|
-
depositingRewards: {
|
|
357
|
-
rewardsPerSecond: new decimal_js_1.default(0),
|
|
358
|
-
rewardsRemaining: new decimal_js_1.default(0),
|
|
359
|
-
rewardApr: new decimal_js_1.default(0),
|
|
360
|
-
rewardMint: web3_js_1.PublicKey.default,
|
|
361
|
-
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
362
|
-
rewardPrice: 0,
|
|
363
|
-
},
|
|
364
|
-
};
|
|
365
|
-
if ((0, utils_1.isNotNullPubkey)(collateralFarmAddress)) {
|
|
366
|
-
result.depositingRewards = yield this.getRewardInfoForFarm(collateralFarmAddress, totalDepositAmount, getRewardPrice);
|
|
367
|
-
}
|
|
368
|
-
if ((0, utils_1.isNotNullPubkey)(debtFarmAddress)) {
|
|
369
|
-
result.depositingRewards = yield this.getRewardInfoForFarm(debtFarmAddress, totalBorrowAmount, getRewardPrice);
|
|
370
|
-
}
|
|
371
|
-
return result;
|
|
372
|
-
});
|
|
288
|
+
return this.getReserveBySymbol(symbol)?.getLiquidityMint();
|
|
373
289
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
290
|
+
async getReserveFarmInfo(mint, getRewardPrice) {
|
|
291
|
+
const { address } = this;
|
|
292
|
+
if (!address) {
|
|
293
|
+
throw Error('Market must be initialized to call initialize.');
|
|
294
|
+
}
|
|
295
|
+
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
296
|
+
await this.loadReserves();
|
|
297
|
+
}
|
|
298
|
+
// Find the reserve
|
|
299
|
+
const kaminoReserve = this.getReserveByMint(mint);
|
|
300
|
+
if (!kaminoReserve) {
|
|
301
|
+
throw Error(`Could not find reserve. ${mint}`);
|
|
302
|
+
}
|
|
303
|
+
const totalDepositAmount = lamportsToNumberDecimal(kaminoReserve.getLiquidityAvailableAmount(), kaminoReserve.stats.decimals);
|
|
304
|
+
const totalBorrowAmount = lamportsToNumberDecimal(kaminoReserve.getBorrowedAmount(), kaminoReserve.stats.decimals);
|
|
305
|
+
const collateralFarmAddress = kaminoReserve.state.farmCollateral;
|
|
306
|
+
const debtFarmAddress = kaminoReserve.state.farmDebt;
|
|
307
|
+
const result = {
|
|
308
|
+
borrowingRewards: {
|
|
309
|
+
rewardsPerSecond: new decimal_js_1.default(0),
|
|
310
|
+
rewardsRemaining: new decimal_js_1.default(0),
|
|
311
|
+
rewardApr: new decimal_js_1.default(0),
|
|
312
|
+
rewardMint: web3_js_1.PublicKey.default,
|
|
313
|
+
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
314
|
+
rewardPrice: 0,
|
|
315
|
+
},
|
|
316
|
+
depositingRewards: {
|
|
317
|
+
rewardsPerSecond: new decimal_js_1.default(0),
|
|
318
|
+
rewardsRemaining: new decimal_js_1.default(0),
|
|
319
|
+
rewardApr: new decimal_js_1.default(0),
|
|
320
|
+
rewardMint: web3_js_1.PublicKey.default,
|
|
321
|
+
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
322
|
+
rewardPrice: 0,
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
if ((0, utils_1.isNotNullPubkey)(collateralFarmAddress)) {
|
|
326
|
+
result.depositingRewards = await this.getRewardInfoForFarm(collateralFarmAddress, totalDepositAmount, getRewardPrice);
|
|
327
|
+
}
|
|
328
|
+
if ((0, utils_1.isNotNullPubkey)(debtFarmAddress)) {
|
|
329
|
+
result.depositingRewards = await this.getRewardInfoForFarm(debtFarmAddress, totalBorrowAmount, getRewardPrice);
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
async getRewardInfoForFarm(farmAddress, totalInvestmentUsd, getRewardPrice) {
|
|
334
|
+
const farmState = await farms_sdk_1.FarmState.fetch(this.connection, farmAddress);
|
|
335
|
+
if (!farmState) {
|
|
336
|
+
throw Error(`Could not parse farm state. ${farmAddress}`);
|
|
337
|
+
}
|
|
338
|
+
const { token, rewardsAvailable, rewardScheduleCurve } = farmState.rewardInfos[0];
|
|
339
|
+
// TODO: marius fix
|
|
340
|
+
const rewardPerSecondLamports = rewardScheduleCurve.points[0].rewardPerTimeUnit.toNumber();
|
|
341
|
+
const { mint, decimals: rewardDecimals } = token;
|
|
342
|
+
const rewardPriceUsd = await getRewardPrice(mint);
|
|
343
|
+
const rewardApr = this.calculateRewardAPR(rewardPerSecondLamports, rewardPriceUsd, totalInvestmentUsd, rewardDecimals.toNumber());
|
|
344
|
+
return {
|
|
345
|
+
rewardsPerSecond: new decimal_js_1.default(rewardPerSecondLamports).dividedBy(10 ** rewardDecimals.toNumber()),
|
|
346
|
+
rewardsRemaining: new decimal_js_1.default(rewardsAvailable.toNumber()).dividedBy(10 ** rewardDecimals.toNumber()),
|
|
347
|
+
rewardApr: rewardsAvailable.toNumber() > 0 ? rewardApr : new decimal_js_1.default(0),
|
|
348
|
+
rewardMint: mint,
|
|
349
|
+
totalInvestmentUsd,
|
|
350
|
+
rewardPrice: rewardPriceUsd,
|
|
351
|
+
};
|
|
395
352
|
}
|
|
396
353
|
calculateRewardAPR(rewardPerSecondLamports, rewardPriceUsd, totalInvestmentUsd, rewardDecimals) {
|
|
397
354
|
const rewardsPerYear = new decimal_js_1.default(rewardPerSecondLamports)
|
|
398
|
-
.dividedBy(
|
|
355
|
+
.dividedBy(10 ** rewardDecimals)
|
|
399
356
|
.times(365 * 24 * 60 * 60)
|
|
400
357
|
.times(rewardPriceUsd);
|
|
401
358
|
return rewardsPerYear.dividedBy(totalInvestmentUsd);
|
|
@@ -406,50 +363,47 @@ class KaminoMarket {
|
|
|
406
363
|
*
|
|
407
364
|
* @param tag
|
|
408
365
|
*/
|
|
409
|
-
getAllObligationsForMarket(tag) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
366
|
+
async getAllObligationsForMarket(tag) {
|
|
367
|
+
const { getProgramAccounts } = await Promise.resolve().then(() => __importStar(require('../utils/rpc')));
|
|
368
|
+
const filters = [
|
|
369
|
+
{
|
|
370
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
memcmp: {
|
|
374
|
+
offset: 32,
|
|
375
|
+
bytes: this.address,
|
|
416
376
|
},
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
if (tag !== undefined) {
|
|
380
|
+
filters.push({
|
|
381
|
+
memcmp: {
|
|
382
|
+
offset: 8,
|
|
383
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
422
384
|
},
|
|
423
|
-
];
|
|
424
|
-
if (tag !== undefined) {
|
|
425
|
-
filters.push({
|
|
426
|
-
memcmp: {
|
|
427
|
-
offset: 8,
|
|
428
|
-
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
433
|
-
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
434
|
-
const [slot, obligations] = yield Promise.all([
|
|
435
|
-
this.connection.getSlot(),
|
|
436
|
-
getProgramAccounts(this.connection, this.programId, {
|
|
437
|
-
commitment: (_a = this.connection.commitment) !== null && _a !== void 0 ? _a : 'processed',
|
|
438
|
-
filters,
|
|
439
|
-
dataSlice: { offset: 0, length: zero_padding_1.ObligationZP.layout.span + 8 }, // truncate the padding
|
|
440
|
-
}),
|
|
441
|
-
]);
|
|
442
|
-
return obligations.map((obligation) => {
|
|
443
|
-
if (obligation.account === null) {
|
|
444
|
-
throw new Error('Invalid account');
|
|
445
|
-
}
|
|
446
|
-
const obligationAccount = zero_padding_1.ObligationZP.decode(obligation.account.data);
|
|
447
|
-
if (!obligationAccount) {
|
|
448
|
-
throw Error('Could not parse obligation.');
|
|
449
|
-
}
|
|
450
|
-
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
451
|
-
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
452
385
|
});
|
|
386
|
+
}
|
|
387
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
388
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
389
|
+
const [slot, obligations] = await Promise.all([
|
|
390
|
+
this.connection.getSlot(),
|
|
391
|
+
getProgramAccounts(this.connection, this.programId, {
|
|
392
|
+
commitment: this.connection.commitment ?? 'processed',
|
|
393
|
+
filters,
|
|
394
|
+
dataSlice: { offset: 0, length: zero_padding_1.ObligationZP.layout.span + 8 }, // truncate the padding
|
|
395
|
+
}),
|
|
396
|
+
]);
|
|
397
|
+
return obligations.map((obligation) => {
|
|
398
|
+
if (obligation.account === null) {
|
|
399
|
+
throw new Error('Invalid account');
|
|
400
|
+
}
|
|
401
|
+
const obligationAccount = zero_padding_1.ObligationZP.decode(obligation.account.data);
|
|
402
|
+
if (!obligationAccount) {
|
|
403
|
+
throw Error('Could not parse obligation.');
|
|
404
|
+
}
|
|
405
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
406
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
453
407
|
});
|
|
454
408
|
}
|
|
455
409
|
/**
|
|
@@ -461,195 +415,185 @@ class KaminoMarket {
|
|
|
461
415
|
* console.log('got a batch of # obligations:', obligations.length);
|
|
462
416
|
* }
|
|
463
417
|
*/
|
|
464
|
-
batchGetAllObligationsForMarket(tag) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
418
|
+
async *batchGetAllObligationsForMarket(tag) {
|
|
419
|
+
const filters = [
|
|
420
|
+
{
|
|
421
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
memcmp: {
|
|
425
|
+
offset: 32,
|
|
426
|
+
bytes: this.address,
|
|
469
427
|
},
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
428
|
+
},
|
|
429
|
+
];
|
|
430
|
+
if (tag !== undefined) {
|
|
431
|
+
filters.push({
|
|
432
|
+
memcmp: {
|
|
433
|
+
offset: 8,
|
|
434
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
475
435
|
},
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const obligationAccounts = yield __await(this.connection.getMultipleAccountsInfo(batch));
|
|
496
|
-
const obligationsBatch = [];
|
|
497
|
-
for (let i = 0; i < obligationAccounts.length; i++) {
|
|
498
|
-
const obligation = obligationAccounts[i];
|
|
499
|
-
const pubkey = batch[i];
|
|
500
|
-
if (obligation === null) {
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
const obligationAccount = accounts_1.Obligation.decode(obligation.data);
|
|
504
|
-
if (!obligationAccount) {
|
|
505
|
-
throw Error(`Could not decode obligation ${pubkey.toString()}`);
|
|
506
|
-
}
|
|
507
|
-
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
508
|
-
obligationsBatch.push(new obligation_1.KaminoObligation(this, pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates));
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
439
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
440
|
+
const [obligationPubkeys, slot] = await Promise.all([
|
|
441
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
442
|
+
filters,
|
|
443
|
+
dataSlice: { offset: 0, length: 0 },
|
|
444
|
+
}),
|
|
445
|
+
this.connection.getSlot(),
|
|
446
|
+
]);
|
|
447
|
+
for (const batch of (0, kliquidity_sdk_1.chunks)(obligationPubkeys.map((x) => x.pubkey), 100)) {
|
|
448
|
+
const obligationAccounts = await this.connection.getMultipleAccountsInfo(batch);
|
|
449
|
+
const obligationsBatch = [];
|
|
450
|
+
for (let i = 0; i < obligationAccounts.length; i++) {
|
|
451
|
+
const obligation = obligationAccounts[i];
|
|
452
|
+
const pubkey = batch[i];
|
|
453
|
+
if (obligation === null) {
|
|
454
|
+
continue;
|
|
509
455
|
}
|
|
510
|
-
|
|
456
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.data);
|
|
457
|
+
if (!obligationAccount) {
|
|
458
|
+
throw Error(`Could not decode obligation ${pubkey.toString()}`);
|
|
459
|
+
}
|
|
460
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
461
|
+
obligationsBatch.push(new obligation_1.KaminoObligation(this, pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates));
|
|
511
462
|
}
|
|
512
|
-
|
|
463
|
+
yield obligationsBatch;
|
|
464
|
+
}
|
|
513
465
|
}
|
|
514
|
-
getAllObligationsByTag(tag, market) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
{
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
527
|
-
},
|
|
466
|
+
async getAllObligationsByTag(tag, market) {
|
|
467
|
+
const [slot, obligations] = await Promise.all([
|
|
468
|
+
this.connection.getSlot(),
|
|
469
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
470
|
+
filters: [
|
|
471
|
+
{
|
|
472
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
memcmp: {
|
|
476
|
+
offset: 8,
|
|
477
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
528
478
|
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
memcmp: {
|
|
482
|
+
offset: 32,
|
|
483
|
+
bytes: market.toBase58(),
|
|
534
484
|
},
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
}),
|
|
488
|
+
]);
|
|
489
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
490
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
491
|
+
return obligations.map((obligation) => {
|
|
492
|
+
if (obligation.account === null) {
|
|
493
|
+
throw new Error('Invalid account');
|
|
494
|
+
}
|
|
495
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
496
|
+
throw new Error("account doesn't belong to this program");
|
|
497
|
+
}
|
|
498
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
499
|
+
if (!obligationAccount) {
|
|
500
|
+
throw Error('Could not parse obligation.');
|
|
501
|
+
}
|
|
502
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
503
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
554
504
|
});
|
|
555
505
|
}
|
|
556
|
-
getAllUserObligations(user) {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
{
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
bytes: bs58_2.default.encode(accounts_1.Obligation.discriminator),
|
|
569
|
-
},
|
|
506
|
+
async getAllUserObligations(user) {
|
|
507
|
+
const [currentSlot, obligations] = await Promise.all([
|
|
508
|
+
this.connection.getSlot(),
|
|
509
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
510
|
+
filters: [
|
|
511
|
+
{
|
|
512
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
memcmp: {
|
|
516
|
+
offset: 0,
|
|
517
|
+
bytes: bs58_2.default.encode(accounts_1.Obligation.discriminator),
|
|
570
518
|
},
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
memcmp: {
|
|
522
|
+
offset: 64,
|
|
523
|
+
bytes: user.toBase58(),
|
|
576
524
|
},
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
memcmp: {
|
|
528
|
+
offset: 32,
|
|
529
|
+
bytes: this.address,
|
|
582
530
|
},
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
}),
|
|
534
|
+
]);
|
|
535
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
536
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
537
|
+
return obligations.map((obligation) => {
|
|
538
|
+
if (obligation.account === null) {
|
|
539
|
+
throw new Error('Invalid account');
|
|
540
|
+
}
|
|
541
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
542
|
+
throw new Error("account doesn't belong to this program");
|
|
543
|
+
}
|
|
544
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
545
|
+
if (!obligationAccount) {
|
|
546
|
+
throw Error('Could not parse obligation.');
|
|
547
|
+
}
|
|
548
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, currentSlot);
|
|
549
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
602
550
|
});
|
|
603
551
|
}
|
|
604
|
-
getAllUserObligationsForReserve(user, reserve) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
continue;
|
|
616
|
-
}
|
|
617
|
-
obligationAddresses.push(new utils_1.MultiplyObligation(targetReserve.getLiquidityMint(), kaminoReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
618
|
-
obligationAddresses.push(new utils_1.MultiplyObligation(kaminoReserve.getLiquidityMint(), targetReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
619
|
-
obligationAddresses.push(new utils_1.LeverageObligation(targetReserve.getLiquidityMint(), kaminoReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
620
|
-
obligationAddresses.push(new utils_1.LeverageObligation(kaminoReserve.getLiquidityMint(), targetReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
552
|
+
async getAllUserObligationsForReserve(user, reserve) {
|
|
553
|
+
const obligationAddresses = [];
|
|
554
|
+
obligationAddresses.push(new utils_1.VanillaObligation(this.programId).toPda(this.getAddress(), user));
|
|
555
|
+
const targetReserve = new utils_1.PubkeyHashMap(Array.from(this.reserves.entries())).get(reserve);
|
|
556
|
+
if (!targetReserve) {
|
|
557
|
+
throw Error('Could not find reserve.');
|
|
558
|
+
}
|
|
559
|
+
for (const [key, kaminoReserve] of this.reserves) {
|
|
560
|
+
if (targetReserve.address.equals(key)) {
|
|
561
|
+
// skip target reserve
|
|
562
|
+
continue;
|
|
621
563
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
564
|
+
obligationAddresses.push(new utils_1.MultiplyObligation(targetReserve.getLiquidityMint(), kaminoReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
565
|
+
obligationAddresses.push(new utils_1.MultiplyObligation(kaminoReserve.getLiquidityMint(), targetReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
566
|
+
obligationAddresses.push(new utils_1.LeverageObligation(targetReserve.getLiquidityMint(), kaminoReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
567
|
+
obligationAddresses.push(new utils_1.LeverageObligation(kaminoReserve.getLiquidityMint(), targetReserve.getLiquidityMint(), this.programId).toPda(this.getAddress(), user));
|
|
568
|
+
}
|
|
569
|
+
const batchSize = 100;
|
|
570
|
+
const finalObligations = [];
|
|
571
|
+
for (let batchStart = 0; batchStart < obligationAddresses.length; batchStart += batchSize) {
|
|
572
|
+
const obligations = await this.getMultipleObligationsByAddress(obligationAddresses.slice(batchStart, batchStart + batchSize));
|
|
573
|
+
obligations.forEach((obligation) => {
|
|
574
|
+
if (obligation !== null) {
|
|
575
|
+
for (const deposits of obligation.deposits.keys()) {
|
|
576
|
+
if (deposits.equals(reserve)) {
|
|
577
|
+
finalObligations.push(obligation);
|
|
632
578
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
579
|
+
}
|
|
580
|
+
for (const borrows of obligation.borrows.keys()) {
|
|
581
|
+
if (borrows.equals(reserve)) {
|
|
582
|
+
finalObligations.push(obligation);
|
|
637
583
|
}
|
|
638
584
|
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return finalObligations;
|
|
643
589
|
}
|
|
644
|
-
getUserVanillaObligation(user) {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
return obligation;
|
|
652
|
-
});
|
|
590
|
+
async getUserVanillaObligation(user) {
|
|
591
|
+
const vanillaObligationAddress = new utils_1.VanillaObligation(this.programId).toPda(this.getAddress(), user);
|
|
592
|
+
const obligation = await this.getObligationByAddress(vanillaObligationAddress);
|
|
593
|
+
if (!obligation) {
|
|
594
|
+
throw new Error('Could not find vanilla obligation.');
|
|
595
|
+
}
|
|
596
|
+
return obligation;
|
|
653
597
|
}
|
|
654
598
|
isReserveInObligation(obligation, reserve) {
|
|
655
599
|
for (const deposits of obligation.deposits.keys()) {
|
|
@@ -664,169 +608,141 @@ class KaminoMarket {
|
|
|
664
608
|
}
|
|
665
609
|
return false;
|
|
666
610
|
}
|
|
667
|
-
getUserObligationsByTag(tag, user) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
{
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
680
|
-
},
|
|
611
|
+
async getUserObligationsByTag(tag, user) {
|
|
612
|
+
const [currentSlot, obligations] = await Promise.all([
|
|
613
|
+
this.connection.getSlot(),
|
|
614
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
615
|
+
filters: [
|
|
616
|
+
{
|
|
617
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
memcmp: {
|
|
621
|
+
offset: 8,
|
|
622
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
681
623
|
},
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
memcmp: {
|
|
627
|
+
offset: 32,
|
|
628
|
+
bytes: this.address,
|
|
687
629
|
},
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
memcmp: {
|
|
633
|
+
offset: 64,
|
|
634
|
+
bytes: user.toBase58(),
|
|
693
635
|
},
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
if (!obligation.account.owner.equals(this.programId)) {
|
|
704
|
-
throw new Error("account doesn't belong to this program");
|
|
705
|
-
}
|
|
706
|
-
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
707
|
-
if (!obligationAccount) {
|
|
708
|
-
throw Error('Could not parse obligation.');
|
|
709
|
-
}
|
|
710
|
-
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, currentSlot);
|
|
711
|
-
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
getObligationByAddress(address) {
|
|
716
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
717
|
-
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
718
|
-
yield this.loadReserves();
|
|
636
|
+
},
|
|
637
|
+
],
|
|
638
|
+
}),
|
|
639
|
+
]);
|
|
640
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
641
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
642
|
+
return obligations.map((obligation) => {
|
|
643
|
+
if (obligation.account === null) {
|
|
644
|
+
throw new Error('Invalid account');
|
|
719
645
|
}
|
|
720
|
-
|
|
646
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
647
|
+
throw new Error("account doesn't belong to this program");
|
|
648
|
+
}
|
|
649
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
650
|
+
if (!obligationAccount) {
|
|
651
|
+
throw Error('Could not parse obligation.');
|
|
652
|
+
}
|
|
653
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, currentSlot);
|
|
654
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
721
655
|
});
|
|
722
656
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
657
|
+
async getObligationByAddress(address) {
|
|
658
|
+
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
659
|
+
await this.loadReserves();
|
|
660
|
+
}
|
|
661
|
+
return obligation_1.KaminoObligation.load(this, address);
|
|
662
|
+
}
|
|
663
|
+
async getMultipleObligationsByAddress(addresses) {
|
|
664
|
+
return obligation_1.KaminoObligation.loadAll(this, addresses);
|
|
727
665
|
}
|
|
728
666
|
/**
|
|
729
667
|
* Get the user metadata PDA and fetch and return the user metadata state if it exists
|
|
730
668
|
* @return [address, userMetadataState] - The address of the user metadata PDA and the user metadata state, or null if it doesn't exist
|
|
731
669
|
*/
|
|
732
|
-
getUserMetadata(user) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
return
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
},
|
|
753
|
-
{
|
|
754
|
-
memcmp: {
|
|
755
|
-
offset: 8,
|
|
756
|
-
bytes: referrer.toBase58(),
|
|
757
|
-
},
|
|
670
|
+
async getUserMetadata(user) {
|
|
671
|
+
const [address, _bump] = (0, utils_1.userMetadataPda)(user, this.programId);
|
|
672
|
+
const userMetadata = await accounts_1.UserMetadata.fetch(this.connection, address, this.programId);
|
|
673
|
+
return [address, userMetadata];
|
|
674
|
+
}
|
|
675
|
+
async getReferrerTokenStateForReserve(referrer, reserve) {
|
|
676
|
+
const [address, _bump] = (0, utils_1.referrerTokenStatePda)(referrer, reserve, this.programId);
|
|
677
|
+
const referrerTokenState = await accounts_1.ReferrerTokenState.fetch(this.connection, address, this.programId);
|
|
678
|
+
return [address, referrerTokenState];
|
|
679
|
+
}
|
|
680
|
+
async getAllReferrerTokenStates(referrer) {
|
|
681
|
+
const referrerTokenStates = await this.connection.getProgramAccounts(this.programId, {
|
|
682
|
+
filters: [
|
|
683
|
+
{
|
|
684
|
+
dataSize: accounts_1.ReferrerTokenState.layout.span + 8,
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
memcmp: {
|
|
688
|
+
offset: 8,
|
|
689
|
+
bytes: referrer.toBase58(),
|
|
758
690
|
},
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const referrerTokenStatesForMints = new utils_1.PubkeyHashMap();
|
|
762
|
-
referrerTokenStates.forEach((referrerTokenState) => {
|
|
763
|
-
if (referrerTokenState.account === null) {
|
|
764
|
-
throw new Error('Invalid account');
|
|
765
|
-
}
|
|
766
|
-
if (!referrerTokenState.account.owner.equals(this.programId)) {
|
|
767
|
-
throw new Error("account doesn't belong to this program");
|
|
768
|
-
}
|
|
769
|
-
const referrerTokenStateDecoded = accounts_1.ReferrerTokenState.decode(referrerTokenState.account.data);
|
|
770
|
-
if (!referrerTokenStateDecoded) {
|
|
771
|
-
throw Error('Could not parse obligation.');
|
|
772
|
-
}
|
|
773
|
-
referrerTokenStatesForMints.set(referrerTokenStateDecoded.mint, referrerTokenStateDecoded);
|
|
774
|
-
});
|
|
775
|
-
return referrerTokenStatesForMints;
|
|
691
|
+
},
|
|
692
|
+
],
|
|
776
693
|
});
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const referrerFeesUnclaimedForMints = new utils_1.PubkeyHashMap();
|
|
782
|
-
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
783
|
-
referrerFeesUnclaimedForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
694
|
+
const referrerTokenStatesForMints = new utils_1.PubkeyHashMap();
|
|
695
|
+
referrerTokenStates.forEach((referrerTokenState) => {
|
|
696
|
+
if (referrerTokenState.account === null) {
|
|
697
|
+
throw new Error('Invalid account');
|
|
784
698
|
}
|
|
785
|
-
|
|
699
|
+
if (!referrerTokenState.account.owner.equals(this.programId)) {
|
|
700
|
+
throw new Error("account doesn't belong to this program");
|
|
701
|
+
}
|
|
702
|
+
const referrerTokenStateDecoded = accounts_1.ReferrerTokenState.decode(referrerTokenState.account.data);
|
|
703
|
+
if (!referrerTokenStateDecoded) {
|
|
704
|
+
throw Error('Could not parse obligation.');
|
|
705
|
+
}
|
|
706
|
+
referrerTokenStatesForMints.set(referrerTokenStateDecoded.mint, referrerTokenStateDecoded);
|
|
786
707
|
});
|
|
708
|
+
return referrerTokenStatesForMints;
|
|
787
709
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
710
|
+
async getAllReferrerFeesUnclaimed(referrer) {
|
|
711
|
+
const referrerTokenStatesForMints = await this.getAllReferrerTokenStates(referrer);
|
|
712
|
+
const referrerFeesUnclaimedForMints = new utils_1.PubkeyHashMap();
|
|
713
|
+
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
714
|
+
referrerFeesUnclaimedForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
715
|
+
}
|
|
716
|
+
return referrerFeesUnclaimedForMints;
|
|
793
717
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
return referrerTokenState ? new fraction_1.Fraction(referrerTokenState.amountCumulativeSf).toDecimal() : new decimal_js_1.default(0);
|
|
798
|
-
});
|
|
718
|
+
async getReferrerFeesUnclaimedForReserve(referrer, reserve) {
|
|
719
|
+
const [, referrerTokenState] = await this.getReferrerTokenStateForReserve(referrer, reserve.address);
|
|
720
|
+
return referrerTokenState ? new fraction_1.Fraction(referrerTokenState.amountUnclaimedSf).toDecimal() : new decimal_js_1.default(0);
|
|
799
721
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
const referrerFeesCumulativeForMints = new utils_1.PubkeyHashMap();
|
|
804
|
-
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
805
|
-
referrerFeesCumulativeForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
806
|
-
}
|
|
807
|
-
return referrerFeesCumulativeForMints;
|
|
808
|
-
});
|
|
722
|
+
async getReferrerFeesCumulativeForReserve(referrer, reserve) {
|
|
723
|
+
const [, referrerTokenState] = await this.getReferrerTokenStateForReserve(referrer, reserve.address);
|
|
724
|
+
return referrerTokenState ? new fraction_1.Fraction(referrerTokenState.amountCumulativeSf).toDecimal() : new decimal_js_1.default(0);
|
|
809
725
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
726
|
+
async getAllReferrerFeesCumulative(referrer) {
|
|
727
|
+
const referrerTokenStatesForMints = await this.getAllReferrerTokenStates(referrer);
|
|
728
|
+
const referrerFeesCumulativeForMints = new utils_1.PubkeyHashMap();
|
|
729
|
+
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
730
|
+
referrerFeesCumulativeForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
731
|
+
}
|
|
732
|
+
return referrerFeesCumulativeForMints;
|
|
814
733
|
}
|
|
815
|
-
|
|
816
|
-
return
|
|
817
|
-
return this.decodeReferrer(url.split(baseUrl)[1]);
|
|
818
|
-
});
|
|
734
|
+
async getReferrerUrl(baseUrl, referrer) {
|
|
735
|
+
return baseUrl + this.encodeReferrer(referrer);
|
|
819
736
|
}
|
|
820
|
-
|
|
821
|
-
return
|
|
822
|
-
return bs58_2.default.encode(referrer.toBuffer());
|
|
823
|
-
});
|
|
737
|
+
async getReferrerFromUrl(baseUrl, url) {
|
|
738
|
+
return this.decodeReferrer(url.split(baseUrl)[1]);
|
|
824
739
|
}
|
|
825
|
-
|
|
826
|
-
return
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
740
|
+
async encodeReferrer(referrer) {
|
|
741
|
+
return bs58_2.default.encode(referrer.toBuffer());
|
|
742
|
+
}
|
|
743
|
+
async decodeReferrer(encoded_referrer) {
|
|
744
|
+
const referrer_buffer = bs58_2.default.decode(encoded_referrer);
|
|
745
|
+
return new web3_js_1.PublicKey(referrer_buffer.toString());
|
|
830
746
|
}
|
|
831
747
|
/**
|
|
832
748
|
* Get the underlying connection passed when instantiating this market
|
|
@@ -838,78 +754,74 @@ class KaminoMarket {
|
|
|
838
754
|
/**
|
|
839
755
|
* Get all Scope prices used by all the market reserves
|
|
840
756
|
*/
|
|
841
|
-
getAllScopePrices(oraclePrices) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
twaps[tokenMint] = { price: twap.price, name: tokenName };
|
|
861
|
-
}
|
|
757
|
+
async getAllScopePrices(oraclePrices) {
|
|
758
|
+
if (!oraclePrices) {
|
|
759
|
+
oraclePrices = await this.scope.getOraclePrices();
|
|
760
|
+
}
|
|
761
|
+
const spot = {};
|
|
762
|
+
const twaps = {};
|
|
763
|
+
for (const reserve of this.reserves.values()) {
|
|
764
|
+
const tokenMint = reserve.getLiquidityMint().toString();
|
|
765
|
+
const tokenName = reserve.getTokenSymbol();
|
|
766
|
+
const oracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
767
|
+
const chain = reserve.state.config.tokenInfo.scopeConfiguration.priceChain;
|
|
768
|
+
const twapChain = reserve.state.config.tokenInfo.scopeConfiguration.twapChain.filter((x) => x > 0);
|
|
769
|
+
if (oracle && (0, utils_1.isNotNullPubkey)(oracle) && chain && scope_sdk_1.Scope.isScopeChainValid(chain)) {
|
|
770
|
+
const spotPrice = await this.scope.getPriceFromChain(chain, oraclePrices);
|
|
771
|
+
spot[tokenMint] = { price: spotPrice.price, name: tokenName };
|
|
772
|
+
}
|
|
773
|
+
if (oracle && (0, utils_1.isNotNullPubkey)(oracle) && twapChain && scope_sdk_1.Scope.isScopeChainValid(twapChain)) {
|
|
774
|
+
const twap = await this.scope.getPriceFromChain(twapChain, oraclePrices);
|
|
775
|
+
twaps[tokenMint] = { price: twap.price, name: tokenName };
|
|
862
776
|
}
|
|
863
|
-
|
|
864
|
-
}
|
|
777
|
+
}
|
|
778
|
+
return { spot, twap: twaps };
|
|
865
779
|
}
|
|
866
780
|
/**
|
|
867
781
|
* Get all Scope/Pyth/Switchboard prices used by all the market reserves
|
|
868
782
|
*/
|
|
869
|
-
getAllPrices() {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
this.setPriceIfExist(klendPrices.switchboard, switchboardPrices.spot, switchboardPrices.twap, tokenMint, tokenName);
|
|
909
|
-
}
|
|
783
|
+
async getAllPrices() {
|
|
784
|
+
const klendPrices = {
|
|
785
|
+
scope: { spot: {}, twap: {} },
|
|
786
|
+
pyth: { spot: {}, twap: {} },
|
|
787
|
+
switchboard: { spot: {}, twap: {} },
|
|
788
|
+
};
|
|
789
|
+
const allOracleAccounts = await (0, utils_1.getAllOracleAccounts)(this.connection, this.getReserves().map((x) => x.state));
|
|
790
|
+
const pythCache = new utils_1.PubkeyHashMap();
|
|
791
|
+
const switchboardCache = new utils_1.PubkeyHashMap();
|
|
792
|
+
const scopeCache = new utils_1.PubkeyHashMap();
|
|
793
|
+
const switchboardV2 = await sbv2_lite_1.default.loadMainnet(this.connection);
|
|
794
|
+
for (const reserve of this.reserves.values()) {
|
|
795
|
+
const tokenMint = reserve.getLiquidityMint().toString();
|
|
796
|
+
const tokenName = reserve.getTokenSymbol();
|
|
797
|
+
const scopeOracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
798
|
+
const spotChain = reserve.state.config.tokenInfo.scopeConfiguration.priceChain;
|
|
799
|
+
const twapChain = reserve.state.config.tokenInfo.scopeConfiguration.twapChain.filter((x) => x > 0);
|
|
800
|
+
const pythOracle = reserve.state.config.tokenInfo.pythConfiguration.price;
|
|
801
|
+
const switchboardSpotOracle = reserve.state.config.tokenInfo.switchboardConfiguration.priceAggregator;
|
|
802
|
+
const switchboardTwapOracle = reserve.state.config.tokenInfo.switchboardConfiguration.twapAggregator;
|
|
803
|
+
if ((0, utils_1.isNotNullPubkey)(scopeOracle)) {
|
|
804
|
+
const scopePrices = {
|
|
805
|
+
spot: (0, utils_1.cacheOrGetScopePrice)(scopeOracle, scopeCache, allOracleAccounts, spotChain),
|
|
806
|
+
twap: (0, utils_1.cacheOrGetScopePrice)(scopeOracle, scopeCache, allOracleAccounts, twapChain),
|
|
807
|
+
};
|
|
808
|
+
this.setPriceIfExist(klendPrices.scope, scopePrices.spot, scopePrices.twap, tokenMint, tokenName);
|
|
809
|
+
}
|
|
810
|
+
if ((0, utils_1.isNotNullPubkey)(pythOracle)) {
|
|
811
|
+
const pythPrices = (0, utils_1.cacheOrGetPythPrices)(pythOracle, pythCache, allOracleAccounts);
|
|
812
|
+
this.setPriceIfExist(klendPrices.pyth, pythPrices?.spot, pythPrices?.twap, tokenMint, tokenName);
|
|
813
|
+
}
|
|
814
|
+
if ((0, utils_1.isNotNullPubkey)(switchboardSpotOracle)) {
|
|
815
|
+
const switchboardPrices = {
|
|
816
|
+
spot: (0, utils_1.cacheOrGetSwitchboardPrice)(switchboardSpotOracle, switchboardCache, allOracleAccounts, switchboardV2),
|
|
817
|
+
twap: (0, utils_1.isNotNullPubkey)(switchboardTwapOracle)
|
|
818
|
+
? (0, utils_1.cacheOrGetSwitchboardPrice)(switchboardTwapOracle, switchboardCache, allOracleAccounts, switchboardV2)
|
|
819
|
+
: null,
|
|
820
|
+
};
|
|
821
|
+
this.setPriceIfExist(klendPrices.switchboard, switchboardPrices.spot, switchboardPrices.twap, tokenMint, tokenName);
|
|
910
822
|
}
|
|
911
|
-
|
|
912
|
-
|
|
823
|
+
}
|
|
824
|
+
return klendPrices;
|
|
913
825
|
}
|
|
914
826
|
getCumulativeBorrowRatesByReserve(slot) {
|
|
915
827
|
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
@@ -996,62 +908,58 @@ class KaminoMarket {
|
|
|
996
908
|
}
|
|
997
909
|
}
|
|
998
910
|
exports.KaminoMarket = KaminoMarket;
|
|
999
|
-
function getReservesForMarket(marketAddress, connection, programId, recentSlotDurationMs) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
911
|
+
async function getReservesForMarket(marketAddress, connection, programId, recentSlotDurationMs) {
|
|
912
|
+
const reserves = await connection.getProgramAccounts(programId, {
|
|
913
|
+
filters: [
|
|
914
|
+
{
|
|
915
|
+
dataSize: accounts_1.Reserve.layout.span + 8,
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
memcmp: {
|
|
919
|
+
offset: 32,
|
|
920
|
+
bytes: marketAddress.toBase58(),
|
|
1005
921
|
},
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
offset: 32,
|
|
1009
|
-
bytes: marketAddress.toBase58(),
|
|
1010
|
-
},
|
|
1011
|
-
},
|
|
1012
|
-
],
|
|
1013
|
-
});
|
|
1014
|
-
const deserializedReserves = reserves.map((reserve) => {
|
|
1015
|
-
if (reserve.account === null) {
|
|
1016
|
-
throw new Error(`Reserve account ${reserve.pubkey.toBase58()} does not exist`);
|
|
1017
|
-
}
|
|
1018
|
-
const reserveAccount = accounts_1.Reserve.decode(reserve.account.data);
|
|
1019
|
-
if (!reserveAccount) {
|
|
1020
|
-
throw Error(`Could not parse reserve ${reserve.pubkey.toBase58()}`);
|
|
1021
|
-
}
|
|
1022
|
-
return reserveAccount;
|
|
1023
|
-
});
|
|
1024
|
-
const allBuffers = reserves.map((reserve) => reserve.account);
|
|
1025
|
-
const reservesAndOracles = yield (0, utils_1.getTokenOracleData)(connection, deserializedReserves);
|
|
1026
|
-
const reservesByAddress = new utils_1.PubkeyHashMap();
|
|
1027
|
-
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
1028
|
-
if (!oracle) {
|
|
1029
|
-
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
1030
|
-
}
|
|
1031
|
-
const kaminoReserve = reserve_1.KaminoReserve.initialize(allBuffers[index], reserves[index].pubkey, reserve, oracle, connection, recentSlotDurationMs);
|
|
1032
|
-
reservesByAddress.set(kaminoReserve.address, kaminoReserve);
|
|
1033
|
-
});
|
|
1034
|
-
return reservesByAddress;
|
|
922
|
+
},
|
|
923
|
+
],
|
|
1035
924
|
});
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
const reserve = accountData ? accountData : yield connection.getAccountInfo(reservePk);
|
|
1040
|
-
if (reserve === null) {
|
|
1041
|
-
throw new Error(`Reserve account ${reservePk.toBase58()} does not exist`);
|
|
925
|
+
const deserializedReserves = reserves.map((reserve) => {
|
|
926
|
+
if (reserve.account === null) {
|
|
927
|
+
throw new Error(`Reserve account ${reserve.pubkey.toBase58()} does not exist`);
|
|
1042
928
|
}
|
|
1043
|
-
const reserveAccount = accounts_1.Reserve.decode(reserve.data);
|
|
929
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.account.data);
|
|
1044
930
|
if (!reserveAccount) {
|
|
1045
|
-
throw Error(`Could not parse reserve ${
|
|
931
|
+
throw Error(`Could not parse reserve ${reserve.pubkey.toBase58()}`);
|
|
1046
932
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
933
|
+
return reserveAccount;
|
|
934
|
+
});
|
|
935
|
+
const allBuffers = reserves.map((reserve) => reserve.account);
|
|
936
|
+
const reservesAndOracles = await (0, utils_1.getTokenOracleData)(connection, deserializedReserves);
|
|
937
|
+
const reservesByAddress = new utils_1.PubkeyHashMap();
|
|
938
|
+
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
1049
939
|
if (!oracle) {
|
|
1050
|
-
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(
|
|
940
|
+
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
1051
941
|
}
|
|
1052
|
-
const kaminoReserve = reserve_1.KaminoReserve.initialize(
|
|
1053
|
-
|
|
942
|
+
const kaminoReserve = reserve_1.KaminoReserve.initialize(allBuffers[index], reserves[index].pubkey, reserve, oracle, connection, recentSlotDurationMs);
|
|
943
|
+
reservesByAddress.set(kaminoReserve.address, kaminoReserve);
|
|
1054
944
|
});
|
|
945
|
+
return reservesByAddress;
|
|
946
|
+
}
|
|
947
|
+
async function getSingleReserve(reservePk, connection, recentSlotDurationMs, accountData) {
|
|
948
|
+
const reserve = accountData ? accountData : await connection.getAccountInfo(reservePk);
|
|
949
|
+
if (reserve === null) {
|
|
950
|
+
throw new Error(`Reserve account ${reservePk.toBase58()} does not exist`);
|
|
951
|
+
}
|
|
952
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.data);
|
|
953
|
+
if (!reserveAccount) {
|
|
954
|
+
throw Error(`Could not parse reserve ${reservePk.toBase58()}`);
|
|
955
|
+
}
|
|
956
|
+
const reservesAndOracles = await (0, utils_1.getTokenOracleData)(connection, [reserveAccount]);
|
|
957
|
+
const [reserveState, oracle] = reservesAndOracles[0];
|
|
958
|
+
if (!oracle) {
|
|
959
|
+
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserveState.config.tokenInfo.name)} reserve`);
|
|
960
|
+
}
|
|
961
|
+
const kaminoReserve = reserve_1.KaminoReserve.initialize(reserve, reservePk, reserveState, oracle, connection, recentSlotDurationMs);
|
|
962
|
+
return kaminoReserve;
|
|
1055
963
|
}
|
|
1056
964
|
function getReservesActive(reserves) {
|
|
1057
965
|
const reservesActive = new utils_1.PubkeyHashMap();
|
|
@@ -1062,38 +970,36 @@ function getReservesActive(reserves) {
|
|
|
1062
970
|
}
|
|
1063
971
|
return reservesActive;
|
|
1064
972
|
}
|
|
1065
|
-
function getReserveFromMintAndMarket(
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
973
|
+
async function getReserveFromMintAndMarket(connection, market, mint, programId = programId_1.PROGRAM_ID) {
|
|
974
|
+
const reserve = (await connection.getProgramAccounts(programId, {
|
|
975
|
+
filters: [
|
|
976
|
+
{
|
|
977
|
+
dataSize: accounts_1.Reserve.layout.span + 8,
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
memcmp: {
|
|
981
|
+
offset: 32,
|
|
982
|
+
bytes: market.address,
|
|
1071
983
|
},
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
memcmp: {
|
|
987
|
+
offset: 128,
|
|
988
|
+
bytes: mint,
|
|
1077
989
|
},
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
if (!reserve.account.owner.equals(programId)) {
|
|
1090
|
-
throw new Error("Account doesn't belong to this program");
|
|
1091
|
-
}
|
|
1092
|
-
return [reserve.pubkey, reserve.account];
|
|
1093
|
-
});
|
|
990
|
+
},
|
|
991
|
+
],
|
|
992
|
+
}))[0];
|
|
993
|
+
if (reserve.account === null) {
|
|
994
|
+
throw new Error('Invalid account');
|
|
995
|
+
}
|
|
996
|
+
if (!reserve.account.owner.equals(programId)) {
|
|
997
|
+
throw new Error("Account doesn't belong to this program");
|
|
998
|
+
}
|
|
999
|
+
return [reserve.pubkey, reserve.account];
|
|
1094
1000
|
}
|
|
1095
1001
|
const lamportsToNumberDecimal = (amount, decimals) => {
|
|
1096
|
-
const factor =
|
|
1002
|
+
const factor = 10 ** decimals;
|
|
1097
1003
|
return new decimal_js_1.default(amount).div(factor);
|
|
1098
1004
|
};
|
|
1099
1005
|
//# sourceMappingURL=market.js.map
|