@kamino-finance/klend-sdk 2.10.6
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/README.md +85 -0
- package/dist/classes/action.d.ts +154 -0
- package/dist/classes/action.js +1505 -0
- package/dist/classes/action.js.map +1 -0
- package/dist/classes/curve.d.ts +15 -0
- package/dist/classes/curve.js +32 -0
- package/dist/classes/curve.js.map +1 -0
- package/dist/classes/fraction.d.ts +23 -0
- package/dist/classes/fraction.js +60 -0
- package/dist/classes/fraction.js.map +1 -0
- package/dist/classes/index.d.ts +8 -0
- package/dist/classes/index.js +25 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/classes/jupiterPerps.d.ts +2 -0
- package/dist/classes/jupiterPerps.js +25 -0
- package/dist/classes/jupiterPerps.js.map +1 -0
- package/dist/classes/market.d.ts +140 -0
- package/dist/classes/market.js +901 -0
- package/dist/classes/market.js.map +1 -0
- package/dist/classes/obligation.d.ts +170 -0
- package/dist/classes/obligation.js +610 -0
- package/dist/classes/obligation.js.map +1 -0
- package/dist/classes/reserve.d.ts +161 -0
- package/dist/classes/reserve.js +474 -0
- package/dist/classes/reserve.js.map +1 -0
- package/dist/classes/shared.d.ts +41 -0
- package/dist/classes/shared.js +10 -0
- package/dist/classes/shared.js.map +1 -0
- package/dist/classes/utils.d.ts +40 -0
- package/dist/classes/utils.js +129 -0
- package/dist/classes/utils.js.map +1 -0
- package/dist/idl.json +4102 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +153 -0
- package/dist/idl_codegen/accounts/LendingMarket.js +204 -0
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts +139 -0
- package/dist/idl_codegen/accounts/Obligation.js +193 -0
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.d.ts +22 -0
- package/dist/idl_codegen/accounts/ReferrerState.js +101 -0
- package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +51 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js +126 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -0
- package/dist/idl_codegen/accounts/Reserve.d.ts +72 -0
- package/dist/idl_codegen/accounts/Reserve.js +156 -0
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.d.ts +22 -0
- package/dist/idl_codegen/accounts/ShortUrl.js +101 -0
- package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.d.ts +48 -0
- package/dist/idl_codegen/accounts/UserMetadata.js +126 -0
- package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -0
- package/dist/idl_codegen/accounts/UserState.d.ts +143 -0
- package/dist/idl_codegen/accounts/UserState.js +180 -0
- package/dist/idl_codegen/accounts/UserState.js.map +1 -0
- package/dist/idl_codegen/accounts/index.d.ts +16 -0
- package/dist/idl_codegen/accounts/index.js +20 -0
- package/dist/idl_codegen/accounts/index.js.map +1 -0
- package/dist/idl_codegen/errors/anchor.d.ts +434 -0
- package/dist/idl_codegen/errors/anchor.js +713 -0
- package/dist/idl_codegen/errors/anchor.js.map +1 -0
- package/dist/idl_codegen/errors/custom.d.ts +730 -0
- package/dist/idl_codegen/errors/custom.js +1194 -0
- package/dist/idl_codegen/errors/custom.js.map +1 -0
- package/dist/idl_codegen/errors/index.d.ts +5 -0
- package/dist/idl_codegen/errors/index.js +71 -0
- package/dist/idl_codegen/errors/index.js.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +20 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +9 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js +20 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +17 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js +64 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +19 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +74 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +21 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +80 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +20 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +21 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +18 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js +62 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -0
- package/dist/idl_codegen/instructions/index.d.ts +66 -0
- package/dist/idl_codegen/instructions/index.js +70 -0
- package/dist/idl_codegen/instructions/index.js.map +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +19 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +63 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts +13 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js +55 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -0
- package/dist/idl_codegen/instructions/initObligation.d.ts +19 -0
- package/dist/idl_codegen/instructions/initObligation.js +55 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +20 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +60 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +14 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js +54 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +14 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js +50 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts +16 -0
- package/dist/idl_codegen/instructions/initReserve.js +47 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts +14 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js +54 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +27 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +102 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/redeemFees.d.ts +10 -0
- package/dist/idl_codegen/instructions/redeemFees.js +33 -0
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +19 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +78 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.d.ts +6 -0
- package/dist/idl_codegen/instructions/refreshObligation.js +17 -0
- package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +19 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +63 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.d.ts +10 -0
- package/dist/idl_codegen/instructions/refreshReserve.js +29 -0
- package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +17 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +60 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +11 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js +47 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.d.ts +14 -0
- package/dist/idl_codegen/instructions/socializeLoss.js +53 -0
- package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +12 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js +50 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +6 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js +21 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +18 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js +69 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +21 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +84 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +16 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +59 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +12 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +35 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -0
- package/dist/idl_codegen/programId.d.ts +4 -0
- package/dist/idl_codegen/programId.js +13 -0
- package/dist/idl_codegen/programId.js.map +1 -0
- package/dist/idl_codegen/types/AssetTier.d.ts +44 -0
- package/dist/idl_codegen/types/AssetTier.js +128 -0
- package/dist/idl_codegen/types/AssetTier.js.map +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.d.ts +27 -0
- package/dist/idl_codegen/types/BigFractionBytes.js +73 -0
- package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts +27 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js +62 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -0
- package/dist/idl_codegen/types/CurvePoint.d.ts +26 -0
- package/dist/idl_codegen/types/CurvePoint.js +66 -0
- package/dist/idl_codegen/types/CurvePoint.js.map +1 -0
- package/dist/idl_codegen/types/ElevationGroup.d.ts +52 -0
- package/dist/idl_codegen/types/ElevationGroup.js +103 -0
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -0
- package/dist/idl_codegen/types/FeeCalculation.d.ts +31 -0
- package/dist/idl_codegen/types/FeeCalculation.js +102 -0
- package/dist/idl_codegen/types/FeeCalculation.js.map +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.d.ts +26 -0
- package/dist/idl_codegen/types/InitObligationArgs.js +66 -0
- package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -0
- package/dist/idl_codegen/types/LastUpdate.d.ts +47 -0
- package/dist/idl_codegen/types/LastUpdate.js +86 -0
- package/dist/idl_codegen/types/LastUpdate.js.map +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +48 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +87 -0
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +75 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +107 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.d.ts +41 -0
- package/dist/idl_codegen/types/PriceHeuristic.js +75 -0
- package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -0
- package/dist/idl_codegen/types/PythConfiguration.d.ts +25 -0
- package/dist/idl_codegen/types/PythConfiguration.js +62 -0
- package/dist/idl_codegen/types/PythConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.d.ts +53 -0
- package/dist/idl_codegen/types/ReserveCollateral.js +93 -0
- package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts +304 -0
- package/dist/idl_codegen/types/ReserveConfig.js +209 -0
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts +31 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js +102 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -0
- package/dist/idl_codegen/types/ReserveFees.d.ts +78 -0
- package/dist/idl_codegen/types/ReserveFees.js +86 -0
- package/dist/idl_codegen/types/ReserveFees.js.map +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +173 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js +166 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/types/ReserveStatus.d.ts +44 -0
- package/dist/idl_codegen/types/ReserveStatus.js +128 -0
- package/dist/idl_codegen/types/ReserveStatus.js.map +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts +41 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js +76 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +30 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js +67 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/TokenInfo.d.ts +109 -0
- package/dist/idl_codegen/types/TokenInfo.js +116 -0
- package/dist/idl_codegen/types/TokenInfo.js.map +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +538 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +1116 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +155 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +273 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +200 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +440 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts +38 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js +86 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -0
- package/dist/idl_codegen/types/index.d.ts +65 -0
- package/dist/idl_codegen/types/index.js +77 -0
- package/dist/idl_codegen/types/index.js.map +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +53 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js +140 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -0
- package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/index.js +6 -0
- package/dist/idl_codegen/zero_padding/index.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +48 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +144 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +2 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js +6 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.d.ts +3 -0
- package/dist/idl_codegen_jupiter_perps/programId.js +9 -0
- package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +62 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js +115 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +32 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js +75 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +32 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +75 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts +6 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js +10 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lending_operations/index.d.ts +2 -0
- package/dist/lending_operations/index.js +19 -0
- package/dist/lending_operations/index.js.map +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js +26 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +47 -0
- package/dist/lending_operations/repay_with_collateral_operations.js +163 -0
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -0
- package/dist/leverage/calcs.d.ts +132 -0
- package/dist/leverage/calcs.js +291 -0
- package/dist/leverage/calcs.js.map +1 -0
- package/dist/leverage/index.d.ts +4 -0
- package/dist/leverage/index.js +21 -0
- package/dist/leverage/index.js.map +1 -0
- package/dist/leverage/instructions.d.ts +43 -0
- package/dist/leverage/instructions.js +103 -0
- package/dist/leverage/instructions.js.map +1 -0
- package/dist/leverage/operations.d.ts +231 -0
- package/dist/leverage/operations.js +1058 -0
- package/dist/leverage/operations.js.map +1 -0
- package/dist/leverage/utils.d.ts +22 -0
- package/dist/leverage/utils.js +144 -0
- package/dist/leverage/utils.js.map +1 -0
- package/dist/lib.d.ts +9 -0
- package/dist/lib.js +26 -0
- package/dist/lib.js.map +1 -0
- package/dist/referrals/index.d.ts +2 -0
- package/dist/referrals/index.js +19 -0
- package/dist/referrals/index.js.map +1 -0
- package/dist/referrals/instructions.d.ts +16 -0
- package/dist/referrals/instructions.js +76 -0
- package/dist/referrals/instructions.js.map +1 -0
- package/dist/referrals/operations.d.ts +97 -0
- package/dist/referrals/operations.js +258 -0
- package/dist/referrals/operations.js.map +1 -0
- package/dist/utils/ObligationType.d.ts +49 -0
- package/dist/utils/ObligationType.js +129 -0
- package/dist/utils/ObligationType.js.map +1 -0
- package/dist/utils/api.d.ts +6 -0
- package/dist/utils/api.js +61 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/ata.d.ts +25 -0
- package/dist/utils/ata.js +155 -0
- package/dist/utils/ata.js.map +1 -0
- package/dist/utils/constants.d.ts +48 -0
- package/dist/utils/constants.js +75 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/idl.d.ts +2 -0
- package/dist/utils/idl.js +9 -0
- package/dist/utils/idl.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/instruction.d.ts +22 -0
- package/dist/utils/instruction.js +202 -0
- package/dist/utils/instruction.js.map +1 -0
- package/dist/utils/kamino.d.ts +3 -0
- package/dist/utils/kamino.js +45 -0
- package/dist/utils/kamino.js.map +1 -0
- package/dist/utils/layout.d.ts +13 -0
- package/dist/utils/layout.js +123 -0
- package/dist/utils/layout.js.map +1 -0
- package/dist/utils/lookupTable.d.ts +5 -0
- package/dist/utils/lookupTable.js +57 -0
- package/dist/utils/lookupTable.js.map +1 -0
- package/dist/utils/oracle.d.ts +51 -0
- package/dist/utils/oracle.js +295 -0
- package/dist/utils/oracle.js.map +1 -0
- package/dist/utils/pubkey.d.ts +74 -0
- package/dist/utils/pubkey.js +229 -0
- package/dist/utils/pubkey.js.map +1 -0
- package/dist/utils/seeds.d.ts +122 -0
- package/dist/utils/seeds.js +153 -0
- package/dist/utils/seeds.js.map +1 -0
- package/dist/utils/slots.d.ts +18 -0
- package/dist/utils/slots.js +32 -0
- package/dist/utils/slots.js.map +1 -0
- package/dist/utils/syncNative.d.ts +10 -0
- package/dist/utils/syncNative.js +46 -0
- package/dist/utils/syncNative.js.map +1 -0
- package/dist/utils/userMetadata.d.ts +15 -0
- package/dist/utils/userMetadata.js +259 -0
- package/dist/utils/userMetadata.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
17
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
18
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
19
|
+
function fulfill(value) { resume("next", value); }
|
|
20
|
+
function reject(value) { resume("throw", value); }
|
|
21
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
22
|
+
};
|
|
23
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports._getReserveFromMintAndMarket = exports.getReservesActive = exports.getReservesForMarket = exports.KaminoMarket = void 0;
|
|
28
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
+
const obligation_1 = require("./obligation");
|
|
30
|
+
const reserve_1 = require("./reserve");
|
|
31
|
+
const accounts_1 = require("../idl_codegen/accounts");
|
|
32
|
+
const utils_1 = require("../utils");
|
|
33
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
34
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
35
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
36
|
+
const farms_sdk_1 = require("@hubbleprotocol/farms-sdk");
|
|
37
|
+
const programId_1 = require("../idl_codegen/programId");
|
|
38
|
+
const bs58_2 = __importDefault(require("bs58"));
|
|
39
|
+
const scope_sdk_1 = require("@hubbleprotocol/scope-sdk");
|
|
40
|
+
const fraction_1 = require("./fraction");
|
|
41
|
+
const kamino_sdk_1 = require("@hubbleprotocol/kamino-sdk");
|
|
42
|
+
const utils_2 = require("./utils");
|
|
43
|
+
const sbv2_lite_1 = __importDefault(require("@switchboard-xyz/sbv2-lite"));
|
|
44
|
+
class KaminoMarket {
|
|
45
|
+
constructor(connection, state, marketAddress, reserves, scope, programId = programId_1.PROGRAM_ID) {
|
|
46
|
+
this.address = marketAddress;
|
|
47
|
+
this.connection = connection;
|
|
48
|
+
this.state = state;
|
|
49
|
+
this.reserves = reserves;
|
|
50
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
51
|
+
this.programId = programId;
|
|
52
|
+
this.scope = scope;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Load a new market with all of its associated reserves
|
|
56
|
+
* @param connection
|
|
57
|
+
* @param marketAddress
|
|
58
|
+
* @param programId
|
|
59
|
+
* @param setupLocalTest
|
|
60
|
+
*/
|
|
61
|
+
static load(connection, marketAddress, programId = programId_1.PROGRAM_ID, setupLocalTest = false, withReserves = true) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const market = yield accounts_1.LendingMarket.fetch(connection, marketAddress, programId);
|
|
64
|
+
if (market === null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
let scope;
|
|
68
|
+
if (!setupLocalTest) {
|
|
69
|
+
scope = new scope_sdk_1.Scope('mainnet-beta', connection);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
scope = new scope_sdk_1.Scope('localnet', connection);
|
|
73
|
+
}
|
|
74
|
+
const reserves = withReserves
|
|
75
|
+
? yield getReservesForMarket(marketAddress, connection, programId)
|
|
76
|
+
: new Map();
|
|
77
|
+
return new KaminoMarket(connection, market, marketAddress.toString(), reserves, scope, programId);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
reload() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const market = yield accounts_1.LendingMarket.fetch(this.connection, this.getAddress(), this.programId);
|
|
83
|
+
if (market === null) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.state = market;
|
|
87
|
+
this.reserves = yield getReservesForMarket(this.getAddress(), this.connection, this.programId);
|
|
88
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the address of this market
|
|
93
|
+
* @return market address public key
|
|
94
|
+
*/
|
|
95
|
+
getAddress() {
|
|
96
|
+
return new web3_js_1.PublicKey(this.address);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get a list of reserves for this market
|
|
100
|
+
*/
|
|
101
|
+
getReserves() {
|
|
102
|
+
return [...this.reserves.values()];
|
|
103
|
+
}
|
|
104
|
+
getElevationGroup(elevationGroup) {
|
|
105
|
+
return this.state.elevationGroups[elevationGroup - 1];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the authority PDA of this market
|
|
109
|
+
* @return market authority public key
|
|
110
|
+
*/
|
|
111
|
+
getLendingMarketAuthority() {
|
|
112
|
+
return (0, utils_1.lendingMarketAuthPda)(this.getAddress(), this.programId)[0];
|
|
113
|
+
}
|
|
114
|
+
getObligationDepositByWallet(owner, mint, obligationType) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const obligation = yield this.getObligationByWallet(owner, obligationType);
|
|
118
|
+
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);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getObligationBorrowByWallet(owner, mint, obligationType) {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const obligation = yield this.getObligationByWallet(owner, obligationType);
|
|
125
|
+
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);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getTotalDepositTVL() {
|
|
129
|
+
const tvl = new decimal_js_1.default(0);
|
|
130
|
+
for (const reserve of this.reserves.values()) {
|
|
131
|
+
tvl.add(reserve.getDepositTvl());
|
|
132
|
+
}
|
|
133
|
+
return tvl;
|
|
134
|
+
}
|
|
135
|
+
getTotalBorrowTVL() {
|
|
136
|
+
const tvl = new decimal_js_1.default(0);
|
|
137
|
+
for (const reserve of this.reserves.values()) {
|
|
138
|
+
tvl.add(reserve.getBorrowTvl());
|
|
139
|
+
}
|
|
140
|
+
return tvl;
|
|
141
|
+
}
|
|
142
|
+
getMaxLeverageForPair(collTokenMint, debtTokenMint) {
|
|
143
|
+
const { maxLtv: maxCollateralLtv, borrowFactor } = this.getMaxAndLiquidationLtvAndBorrowFactorForPair(collTokenMint, debtTokenMint);
|
|
144
|
+
const maxLeverage =
|
|
145
|
+
// const ltv = (coll * ltv_factor) / (debt * borrow_factor);
|
|
146
|
+
1 / (1 - (maxCollateralLtv * 100) / (borrowFactor * 100));
|
|
147
|
+
return maxLeverage;
|
|
148
|
+
}
|
|
149
|
+
getMaxAndLiquidationLtvAndBorrowFactorForPair(collTokenMint, debtTokenMint) {
|
|
150
|
+
const collReserve = this.getReserveByMint(collTokenMint);
|
|
151
|
+
const debtReserve = this.getReserveByMint(debtTokenMint);
|
|
152
|
+
if (!collReserve || !debtReserve) {
|
|
153
|
+
throw Error('Could not find one of the reserves.');
|
|
154
|
+
}
|
|
155
|
+
const groupsColl = new Set(collReserve.state.config.elevationGroups);
|
|
156
|
+
const groupsDebt = new Set(debtReserve.state.config.elevationGroups);
|
|
157
|
+
const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.has(item) && item !== 0);
|
|
158
|
+
// Ltv factor for coll token
|
|
159
|
+
const maxCollateralLtv = commonElevationGroups.length === 0
|
|
160
|
+
? collReserve.state.config.loanToValuePct
|
|
161
|
+
: this.state.elevationGroups
|
|
162
|
+
.filter((e) => commonElevationGroups.includes(e.id))
|
|
163
|
+
.reduce((acc, elem) => Math.max(acc, elem.ltvPct), 0);
|
|
164
|
+
const liquidationLtv = commonElevationGroups.length === 0
|
|
165
|
+
? collReserve.state.config.liquidationThresholdPct
|
|
166
|
+
: this.state.elevationGroups
|
|
167
|
+
.filter((e) => commonElevationGroups.includes(e.id))
|
|
168
|
+
.reduce((acc, elem) => Math.max(acc, elem.liquidationThresholdPct), 0);
|
|
169
|
+
const borrowFactor = commonElevationGroups.length === 0 ? (debtReserve === null || debtReserve === void 0 ? void 0 : debtReserve.state.config.borrowFactorPct.toNumber()) / 100 : 1;
|
|
170
|
+
return { maxLtv: maxCollateralLtv / 100, liquidationLtv: liquidationLtv / 100, borrowFactor };
|
|
171
|
+
}
|
|
172
|
+
getTotalProductTvl(productType) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
let obligations = (yield this.getAllObligationsForMarket(productType.toArgs().tag)).filter((obligation) => obligation.refreshedStats.userTotalBorrow.gt(0) || obligation.refreshedStats.userTotalDeposit.gt(0));
|
|
175
|
+
switch (productType.toArgs().tag) {
|
|
176
|
+
case utils_1.VanillaObligation.tag: {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case utils_1.LendingObligation.tag: {
|
|
180
|
+
const mint = productType.toArgs().seed1;
|
|
181
|
+
obligations = obligations.filter((obligation) => obligation.getDepositByMint(mint) !== undefined);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case utils_1.MultiplyObligation.tag:
|
|
185
|
+
case utils_1.LeverageObligation.tag: {
|
|
186
|
+
const collMint = productType.toArgs().seed1;
|
|
187
|
+
const debtMint = productType.toArgs().seed2;
|
|
188
|
+
obligations = obligations.filter((obligation) => obligation.getDepositByMint(collMint) !== undefined && obligation.getBorrowByMint(debtMint) !== undefined);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
default:
|
|
192
|
+
throw new Error('Invalid obligation type');
|
|
193
|
+
}
|
|
194
|
+
const deposits = obligations.reduce((acc, obligation) => acc.plus(obligation.refreshedStats.userTotalDeposit), new decimal_js_1.default(0));
|
|
195
|
+
const borrows = obligations.reduce((acc, obligation) => acc.plus(obligation.refreshedStats.userTotalBorrow), new decimal_js_1.default(0));
|
|
196
|
+
const avgLeverage = obligations.reduce((acc, obligations) => acc.plus(obligations.refreshedStats.leverage), new decimal_js_1.default(0));
|
|
197
|
+
return { tvl: deposits.sub(borrows), deposits, borrows, avgLeverage: avgLeverage.div(obligations.length) };
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
*
|
|
202
|
+
* @returns Number of active obligations in the market
|
|
203
|
+
*/
|
|
204
|
+
getNumberOfObligations() {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
return (yield this.getAllObligationsForMarket())
|
|
207
|
+
.filter((obligation) => obligation.refreshedStats.userTotalBorrow.gt(0) || obligation.refreshedStats.userTotalDeposit.gt(0))
|
|
208
|
+
.reduce((acc, _obligation) => acc + 1, 0);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
getObligationByWallet(publicKey, obligationType) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const { address } = this;
|
|
214
|
+
if (!address) {
|
|
215
|
+
throw Error('Market must be initialized to call initialize.');
|
|
216
|
+
}
|
|
217
|
+
const obligationAddress = obligationType.toPda(this.getAddress(), publicKey);
|
|
218
|
+
return obligation_1.KaminoObligation.load(this, obligationAddress);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
loadReserves() {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const addresses = [...this.reserves.keys()];
|
|
224
|
+
const reserveAccounts = yield this.connection.getMultipleAccountsInfo(addresses, 'processed');
|
|
225
|
+
const deserializedReserves = reserveAccounts.map((reserve, i) => {
|
|
226
|
+
if (reserve === null) {
|
|
227
|
+
// maybe reuse old here
|
|
228
|
+
throw new Error(`Reserve account ${addresses[i].toBase58()} was not found`);
|
|
229
|
+
}
|
|
230
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.data);
|
|
231
|
+
if (!reserveAccount) {
|
|
232
|
+
throw Error(`Could not parse reserve ${addresses[i].toBase58()}`);
|
|
233
|
+
}
|
|
234
|
+
return reserveAccount;
|
|
235
|
+
});
|
|
236
|
+
const reservesAndOracles = yield (0, utils_1.getTokenOracleData)(this.connection, deserializedReserves);
|
|
237
|
+
const kaminoReserves = new utils_1.PubkeyHashMap();
|
|
238
|
+
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
239
|
+
if (!oracle) {
|
|
240
|
+
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
241
|
+
}
|
|
242
|
+
const kaminoReserve = reserve_1.KaminoReserve.initialize(reserveAccounts[index], addresses[index], reserve, oracle, this.connection);
|
|
243
|
+
kaminoReserves.set(kaminoReserve.address, kaminoReserve);
|
|
244
|
+
});
|
|
245
|
+
this.reserves = kaminoReserves;
|
|
246
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
refreshAll() {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
const promises = [this.getReserves().every((reserve) => reserve.stats) ? this.loadReserves() : null].filter((x) => x);
|
|
252
|
+
yield Promise.all(promises);
|
|
253
|
+
this.reservesActive = getReservesActive(this.reserves);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
getReserveByAddress(address) {
|
|
257
|
+
return this.reserves.get(address);
|
|
258
|
+
}
|
|
259
|
+
getReserveByMint(address) {
|
|
260
|
+
for (const reserve of this.reserves.values()) {
|
|
261
|
+
if (reserve.getLiquidityMint().equals(address)) {
|
|
262
|
+
return reserve;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
getReserveBySymbol(symbol) {
|
|
268
|
+
for (const reserve of this.reserves.values()) {
|
|
269
|
+
if (reserve.symbol === symbol) {
|
|
270
|
+
return reserve;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
getReserveMintBySymbol(symbol) {
|
|
276
|
+
var _a;
|
|
277
|
+
return (_a = this.getReserveBySymbol(symbol)) === null || _a === void 0 ? void 0 : _a.getLiquidityMint();
|
|
278
|
+
}
|
|
279
|
+
getReserveFarmInfo(mint, getRewardPrice) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
const { address } = this;
|
|
282
|
+
if (!address) {
|
|
283
|
+
throw Error('Market must be initialized to call initialize.');
|
|
284
|
+
}
|
|
285
|
+
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
286
|
+
yield this.loadReserves();
|
|
287
|
+
}
|
|
288
|
+
// Find the reserve
|
|
289
|
+
const kaminoReserve = this.getReserveByMint(mint);
|
|
290
|
+
if (!kaminoReserve) {
|
|
291
|
+
throw Error(`Could not find reserve. ${mint}`);
|
|
292
|
+
}
|
|
293
|
+
const totalDepositAmount = lamportsToNumberDecimal(kaminoReserve.getLiquidityAvailableAmount(), kaminoReserve.stats.decimals);
|
|
294
|
+
const totalBorrowAmount = lamportsToNumberDecimal(kaminoReserve.getBorrowedAmount(), kaminoReserve.stats.decimals);
|
|
295
|
+
const collateralFarmAddress = kaminoReserve.state.farmCollateral;
|
|
296
|
+
const debtFarmAddress = kaminoReserve.state.farmDebt;
|
|
297
|
+
const result = {
|
|
298
|
+
borrowingRewards: {
|
|
299
|
+
rewardsPerSecond: new decimal_js_1.default(0),
|
|
300
|
+
rewardsRemaining: new decimal_js_1.default(0),
|
|
301
|
+
rewardApr: new decimal_js_1.default(0),
|
|
302
|
+
rewardMint: web3_js_1.PublicKey.default,
|
|
303
|
+
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
304
|
+
rewardPrice: 0,
|
|
305
|
+
},
|
|
306
|
+
depositingRewards: {
|
|
307
|
+
rewardsPerSecond: new decimal_js_1.default(0),
|
|
308
|
+
rewardsRemaining: new decimal_js_1.default(0),
|
|
309
|
+
rewardApr: new decimal_js_1.default(0),
|
|
310
|
+
rewardMint: web3_js_1.PublicKey.default,
|
|
311
|
+
totalInvestmentUsd: new decimal_js_1.default(0),
|
|
312
|
+
rewardPrice: 0,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
if ((0, utils_1.isNotNullPubkey)(collateralFarmAddress)) {
|
|
316
|
+
result.depositingRewards = yield this.getRewardInfoForFarm(collateralFarmAddress, totalDepositAmount, getRewardPrice);
|
|
317
|
+
}
|
|
318
|
+
if ((0, utils_1.isNotNullPubkey)(debtFarmAddress)) {
|
|
319
|
+
result.depositingRewards = yield this.getRewardInfoForFarm(debtFarmAddress, totalBorrowAmount, getRewardPrice);
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
getRewardInfoForFarm(farmAddress, totalInvestmentUsd, getRewardPrice) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
const farmState = yield farms_sdk_1.FarmState.fetch(this.connection, farmAddress);
|
|
327
|
+
if (!farmState) {
|
|
328
|
+
throw Error(`Could not parse farm state. ${farmAddress}`);
|
|
329
|
+
}
|
|
330
|
+
const { token, rewardsAvailable, rewardScheduleCurve } = farmState.rewardInfos[0];
|
|
331
|
+
// TODO: marius fix
|
|
332
|
+
const rewardPerSecondLamports = rewardScheduleCurve.points[0].rewardPerTimeUnit.toNumber();
|
|
333
|
+
const { mint, decimals: rewardDecimals } = token;
|
|
334
|
+
const rewardPriceUsd = yield getRewardPrice(mint);
|
|
335
|
+
const rewardApr = this.calculateRewardAPR(rewardPerSecondLamports, rewardPriceUsd, totalInvestmentUsd, rewardDecimals.toNumber());
|
|
336
|
+
return {
|
|
337
|
+
rewardsPerSecond: new decimal_js_1.default(rewardPerSecondLamports).dividedBy(Math.pow(10, rewardDecimals.toNumber())),
|
|
338
|
+
rewardsRemaining: new decimal_js_1.default(rewardsAvailable.toNumber()).dividedBy(Math.pow(10, rewardDecimals.toNumber())),
|
|
339
|
+
rewardApr: rewardsAvailable.toNumber() > 0 ? rewardApr : new decimal_js_1.default(0),
|
|
340
|
+
rewardMint: mint,
|
|
341
|
+
totalInvestmentUsd,
|
|
342
|
+
rewardPrice: rewardPriceUsd,
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
calculateRewardAPR(rewardPerSecondLamports, rewardPriceUsd, totalInvestmentUsd, rewardDecimals) {
|
|
347
|
+
const rewardsPerYear = new decimal_js_1.default(rewardPerSecondLamports)
|
|
348
|
+
.dividedBy(Math.pow(10, rewardDecimals))
|
|
349
|
+
.times(365 * 24 * 60 * 60)
|
|
350
|
+
.times(rewardPriceUsd);
|
|
351
|
+
return rewardsPerYear.dividedBy(totalInvestmentUsd);
|
|
352
|
+
}
|
|
353
|
+
getAllObligationsForMarket(tag) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
+
const filters = [
|
|
356
|
+
{
|
|
357
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
memcmp: {
|
|
361
|
+
offset: 32,
|
|
362
|
+
bytes: this.address,
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
];
|
|
366
|
+
if (tag !== undefined) {
|
|
367
|
+
filters.push({
|
|
368
|
+
memcmp: {
|
|
369
|
+
offset: 8,
|
|
370
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
375
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
376
|
+
const [slot, obligations] = yield Promise.all([
|
|
377
|
+
this.connection.getSlot(),
|
|
378
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
379
|
+
filters,
|
|
380
|
+
}),
|
|
381
|
+
]);
|
|
382
|
+
return obligations.map((obligation) => {
|
|
383
|
+
if (obligation.account === null) {
|
|
384
|
+
throw new Error('Invalid account');
|
|
385
|
+
}
|
|
386
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
387
|
+
if (!obligationAccount) {
|
|
388
|
+
throw Error('Could not parse obligation.');
|
|
389
|
+
}
|
|
390
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
391
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get all obligations for lending market from an async generator filled with batches of 100 obligations each
|
|
397
|
+
* @param tag
|
|
398
|
+
* @example
|
|
399
|
+
* const obligationsGenerator = market.batchGetAllObligationsForMarket();
|
|
400
|
+
* for await (const obligations of obligationsGenerator) {
|
|
401
|
+
* console.log('got a batch of # obligations:', obligations.length);
|
|
402
|
+
* }
|
|
403
|
+
*/
|
|
404
|
+
batchGetAllObligationsForMarket(tag) {
|
|
405
|
+
return __asyncGenerator(this, arguments, function* batchGetAllObligationsForMarket_1() {
|
|
406
|
+
const filters = [
|
|
407
|
+
{
|
|
408
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
memcmp: {
|
|
412
|
+
offset: 32,
|
|
413
|
+
bytes: this.address,
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
if (tag !== undefined) {
|
|
418
|
+
filters.push({
|
|
419
|
+
memcmp: {
|
|
420
|
+
offset: 8,
|
|
421
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
const slot = yield __await(this.connection.getSlot());
|
|
426
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
427
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
428
|
+
const obligationPubkeys = yield __await(this.connection.getProgramAccounts(this.programId, {
|
|
429
|
+
filters,
|
|
430
|
+
dataSlice: { offset: 0, length: 0 },
|
|
431
|
+
}));
|
|
432
|
+
for (const batch of (0, kamino_sdk_1.chunks)(obligationPubkeys.map((x) => x.pubkey), 100)) {
|
|
433
|
+
const obligationAccounts = yield __await(this.connection.getMultipleAccountsInfo(batch));
|
|
434
|
+
const obligationsBatch = [];
|
|
435
|
+
for (let i = 0; i < obligationAccounts.length; i++) {
|
|
436
|
+
const obligation = obligationAccounts[i];
|
|
437
|
+
const pubkey = batch[i];
|
|
438
|
+
if (obligation === null) {
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.data);
|
|
442
|
+
if (!obligationAccount) {
|
|
443
|
+
throw Error(`Could not decode obligation ${pubkey.toString()}`);
|
|
444
|
+
}
|
|
445
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
446
|
+
obligationsBatch.push(new obligation_1.KaminoObligation(this, pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates));
|
|
447
|
+
}
|
|
448
|
+
yield yield __await(obligationsBatch);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
getAllObligationsByTag(tag, market) {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
const [slot, obligations] = yield Promise.all([
|
|
455
|
+
this.connection.getSlot(),
|
|
456
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
457
|
+
filters: [
|
|
458
|
+
{
|
|
459
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
memcmp: {
|
|
463
|
+
offset: 8,
|
|
464
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
memcmp: {
|
|
469
|
+
offset: 32,
|
|
470
|
+
bytes: market.toBase58(),
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
}),
|
|
475
|
+
]);
|
|
476
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
477
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
478
|
+
return obligations.map((obligation) => {
|
|
479
|
+
if (obligation.account === null) {
|
|
480
|
+
throw new Error('Invalid account');
|
|
481
|
+
}
|
|
482
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
483
|
+
throw new Error("account doesn't belong to this program");
|
|
484
|
+
}
|
|
485
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
486
|
+
if (!obligationAccount) {
|
|
487
|
+
throw Error('Could not parse obligation.');
|
|
488
|
+
}
|
|
489
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, slot);
|
|
490
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
getAllUserObligations(user) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
const [currentSlot, obligations] = yield Promise.all([
|
|
497
|
+
this.connection.getSlot(),
|
|
498
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
499
|
+
filters: [
|
|
500
|
+
{
|
|
501
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
memcmp: {
|
|
505
|
+
offset: 0,
|
|
506
|
+
bytes: bs58_2.default.encode(accounts_1.Obligation.discriminator),
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
memcmp: {
|
|
511
|
+
offset: 64,
|
|
512
|
+
bytes: user.toBase58(),
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
memcmp: {
|
|
517
|
+
offset: 32,
|
|
518
|
+
bytes: this.address,
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
}),
|
|
523
|
+
]);
|
|
524
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
525
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
526
|
+
return obligations.map((obligation) => {
|
|
527
|
+
if (obligation.account === null) {
|
|
528
|
+
throw new Error('Invalid account');
|
|
529
|
+
}
|
|
530
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
531
|
+
throw new Error("account doesn't belong to this program");
|
|
532
|
+
}
|
|
533
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
534
|
+
if (!obligationAccount) {
|
|
535
|
+
throw Error('Could not parse obligation.');
|
|
536
|
+
}
|
|
537
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, currentSlot);
|
|
538
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
getUserObligationsByTag(tag, user) {
|
|
543
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
544
|
+
const [currentSlot, obligations] = yield Promise.all([
|
|
545
|
+
this.connection.getSlot(),
|
|
546
|
+
this.connection.getProgramAccounts(this.programId, {
|
|
547
|
+
filters: [
|
|
548
|
+
{
|
|
549
|
+
dataSize: accounts_1.Obligation.layout.span + 8,
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
memcmp: {
|
|
553
|
+
offset: 8,
|
|
554
|
+
bytes: bs58_1.default.encode(new anchor_1.BN(tag).toBuffer()),
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
memcmp: {
|
|
559
|
+
offset: 32,
|
|
560
|
+
bytes: this.address,
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
memcmp: {
|
|
565
|
+
offset: 64,
|
|
566
|
+
bytes: user.toBase58(),
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
}),
|
|
571
|
+
]);
|
|
572
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
573
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
574
|
+
return obligations.map((obligation) => {
|
|
575
|
+
if (obligation.account === null) {
|
|
576
|
+
throw new Error('Invalid account');
|
|
577
|
+
}
|
|
578
|
+
if (!obligation.account.owner.equals(this.programId)) {
|
|
579
|
+
throw new Error("account doesn't belong to this program");
|
|
580
|
+
}
|
|
581
|
+
const obligationAccount = accounts_1.Obligation.decode(obligation.account.data);
|
|
582
|
+
if (!obligationAccount) {
|
|
583
|
+
throw Error('Could not parse obligation.');
|
|
584
|
+
}
|
|
585
|
+
obligation_1.KaminoObligation.addRatesForObligation(this, obligationAccount, collateralExchangeRates, cumulativeBorrowRates, currentSlot);
|
|
586
|
+
return new obligation_1.KaminoObligation(this, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates);
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
getObligationByAddress(address) {
|
|
591
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
592
|
+
if (!this.getReserves().every((reserve) => reserve.stats)) {
|
|
593
|
+
yield this.loadReserves();
|
|
594
|
+
}
|
|
595
|
+
return obligation_1.KaminoObligation.load(this, address);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
getMultipleObligationsByAddress(addresses) {
|
|
599
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
600
|
+
return obligation_1.KaminoObligation.loadAll(this, addresses);
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Get the user metadata PDA and fetch and return the user metadata state if it exists
|
|
605
|
+
* @return [address, userMetadataState] - The address of the user metadata PDA and the user metadata state, or null if it doesn't exist
|
|
606
|
+
*/
|
|
607
|
+
getUserMetadata(user) {
|
|
608
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
609
|
+
const [address, _bump] = (0, utils_1.userMetadataPda)(user, this.programId);
|
|
610
|
+
const userMetadata = yield accounts_1.UserMetadata.fetch(this.connection, address, this.programId);
|
|
611
|
+
return [address, userMetadata];
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
getReferrerTokenStateForReserve(referrer, reserve) {
|
|
615
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
616
|
+
const [address, _bump] = (0, utils_1.referrerTokenStatePda)(referrer, reserve, this.programId);
|
|
617
|
+
const referrerTokenState = yield accounts_1.ReferrerTokenState.fetch(this.connection, address, this.programId);
|
|
618
|
+
return [address, referrerTokenState];
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
getAllReferrerTokenStates(referrer) {
|
|
622
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
623
|
+
const referrerTokenStates = yield this.connection.getProgramAccounts(this.programId, {
|
|
624
|
+
filters: [
|
|
625
|
+
{
|
|
626
|
+
dataSize: accounts_1.ReferrerTokenState.layout.span + 8,
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
memcmp: {
|
|
630
|
+
offset: 8,
|
|
631
|
+
bytes: referrer.toBase58(),
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
],
|
|
635
|
+
});
|
|
636
|
+
const referrerTokenStatesForMints = new utils_1.PubkeyHashMap();
|
|
637
|
+
referrerTokenStates.forEach((referrerTokenState) => {
|
|
638
|
+
if (referrerTokenState.account === null) {
|
|
639
|
+
throw new Error('Invalid account');
|
|
640
|
+
}
|
|
641
|
+
if (!referrerTokenState.account.owner.equals(this.programId)) {
|
|
642
|
+
throw new Error("account doesn't belong to this program");
|
|
643
|
+
}
|
|
644
|
+
const referrerTokenStateDecoded = accounts_1.ReferrerTokenState.decode(referrerTokenState.account.data);
|
|
645
|
+
if (!referrerTokenStateDecoded) {
|
|
646
|
+
throw Error('Could not parse obligation.');
|
|
647
|
+
}
|
|
648
|
+
referrerTokenStatesForMints.set(referrerTokenStateDecoded.mint, referrerTokenStateDecoded);
|
|
649
|
+
});
|
|
650
|
+
return referrerTokenStatesForMints;
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
getAllReferrerFeesUnclaimed(referrer) {
|
|
654
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
655
|
+
const referrerTokenStatesForMints = yield this.getAllReferrerTokenStates(referrer);
|
|
656
|
+
const referrerFeesUnclaimedForMints = new utils_1.PubkeyHashMap();
|
|
657
|
+
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
658
|
+
referrerFeesUnclaimedForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
659
|
+
}
|
|
660
|
+
return referrerFeesUnclaimedForMints;
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
getReferrerFeesUnclaimedForReserve(referrer, reserve) {
|
|
664
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
665
|
+
const [, referrerTokenState] = yield this.getReferrerTokenStateForReserve(referrer, reserve.address);
|
|
666
|
+
return referrerTokenState ? new fraction_1.Fraction(referrerTokenState.amountUnclaimedSf).toDecimal() : new decimal_js_1.default(0);
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
getReferrerFeesCumulativeForReserve(referrer, reserve) {
|
|
670
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
671
|
+
const [, referrerTokenState] = yield this.getReferrerTokenStateForReserve(referrer, reserve.address);
|
|
672
|
+
return referrerTokenState ? new fraction_1.Fraction(referrerTokenState.amountCumulativeSf).toDecimal() : new decimal_js_1.default(0);
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
getAllReferrerFeesCumulative(referrer) {
|
|
676
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
677
|
+
const referrerTokenStatesForMints = yield this.getAllReferrerTokenStates(referrer);
|
|
678
|
+
const referrerFeesCumulativeForMints = new utils_1.PubkeyHashMap();
|
|
679
|
+
for (const mint of referrerTokenStatesForMints.keys()) {
|
|
680
|
+
referrerFeesCumulativeForMints.set(mint, new fraction_1.Fraction(referrerTokenStatesForMints.get(mint).amountUnclaimedSf).toDecimal());
|
|
681
|
+
}
|
|
682
|
+
return referrerFeesCumulativeForMints;
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
getReferrerUrl(baseUrl, referrer) {
|
|
686
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
687
|
+
return baseUrl + this.encodeReferrer(referrer);
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
getReferrerFromUrl(baseUrl, url) {
|
|
691
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
692
|
+
return this.decodeReferrer(url.split(baseUrl)[1]);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
encodeReferrer(referrer) {
|
|
696
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
697
|
+
return bs58_2.default.encode(referrer.toBuffer());
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
decodeReferrer(encoded_referrer) {
|
|
701
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
702
|
+
const referrer_buffer = bs58_2.default.decode(encoded_referrer);
|
|
703
|
+
return new web3_js_1.PublicKey(referrer_buffer.toString());
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Get the underlying connection passed when instantiating this market
|
|
708
|
+
* @return connection
|
|
709
|
+
*/
|
|
710
|
+
getConnection() {
|
|
711
|
+
return this.connection;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Get all Scope prices used by all the market reserves
|
|
715
|
+
*/
|
|
716
|
+
getAllScopePrices(oraclePrices) {
|
|
717
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
718
|
+
if (!oraclePrices) {
|
|
719
|
+
oraclePrices = yield this.scope.getOraclePrices();
|
|
720
|
+
}
|
|
721
|
+
const spot = {};
|
|
722
|
+
const twaps = {};
|
|
723
|
+
for (const reserve of this.reserves.values()) {
|
|
724
|
+
const tokenMint = reserve.getLiquidityMint().toString();
|
|
725
|
+
const tokenName = reserve.getTokenSymbol();
|
|
726
|
+
const oracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
727
|
+
const chain = reserve.state.config.tokenInfo.scopeConfiguration.priceChain;
|
|
728
|
+
const twapChain = reserve.state.config.tokenInfo.scopeConfiguration.twapChain.filter((x) => x > 0);
|
|
729
|
+
if (oracle && (0, utils_1.isNotNullPubkey)(oracle) && chain && scope_sdk_1.Scope.isScopeChainValid(chain)) {
|
|
730
|
+
const spotPrice = yield this.scope.getPriceFromChain(chain, oraclePrices);
|
|
731
|
+
spot[tokenMint] = { price: spotPrice.price, name: tokenName };
|
|
732
|
+
}
|
|
733
|
+
if (oracle && (0, utils_1.isNotNullPubkey)(oracle) && twapChain && scope_sdk_1.Scope.isScopeChainValid(twapChain)) {
|
|
734
|
+
const twap = yield this.scope.getPriceFromChain(twapChain, oraclePrices);
|
|
735
|
+
twaps[tokenMint] = { price: twap.price, name: tokenName };
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return { spot, twap: twaps };
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Get all Scope/Pyth/Switchboard prices used by all the market reserves
|
|
743
|
+
*/
|
|
744
|
+
getAllPrices() {
|
|
745
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
746
|
+
const klendPrices = {
|
|
747
|
+
scope: { spot: {}, twap: {} },
|
|
748
|
+
pyth: { spot: {}, twap: {} },
|
|
749
|
+
switchboard: { spot: {}, twap: {} },
|
|
750
|
+
};
|
|
751
|
+
const allOracleAccounts = yield (0, utils_1.getAllOracleAccounts)(this.connection, this.getReserves().map((x) => x.state));
|
|
752
|
+
const pythCache = new utils_1.PubkeyHashMap();
|
|
753
|
+
const switchboardCache = new utils_1.PubkeyHashMap();
|
|
754
|
+
const scopeCache = new utils_1.PubkeyHashMap();
|
|
755
|
+
const switchboardV2 = yield sbv2_lite_1.default.loadMainnet(this.connection);
|
|
756
|
+
for (const reserve of this.reserves.values()) {
|
|
757
|
+
const tokenMint = reserve.getLiquidityMint().toString();
|
|
758
|
+
const tokenName = reserve.getTokenSymbol();
|
|
759
|
+
const scopeOracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
760
|
+
const spotChain = reserve.state.config.tokenInfo.scopeConfiguration.priceChain;
|
|
761
|
+
const twapChain = reserve.state.config.tokenInfo.scopeConfiguration.twapChain.filter((x) => x > 0);
|
|
762
|
+
const pythOracle = reserve.state.config.tokenInfo.pythConfiguration.price;
|
|
763
|
+
const switchboardSpotOracle = reserve.state.config.tokenInfo.switchboardConfiguration.priceAggregator;
|
|
764
|
+
const switchboardTwapOracle = reserve.state.config.tokenInfo.switchboardConfiguration.twapAggregator;
|
|
765
|
+
if ((0, utils_1.isNotNullPubkey)(scopeOracle)) {
|
|
766
|
+
const scopePrices = {
|
|
767
|
+
spot: (0, utils_1.cacheOrGetScopePrice)(scopeOracle, scopeCache, allOracleAccounts, spotChain),
|
|
768
|
+
twap: (0, utils_1.cacheOrGetScopePrice)(scopeOracle, scopeCache, allOracleAccounts, twapChain),
|
|
769
|
+
};
|
|
770
|
+
this.setPriceIfExist(klendPrices.scope, scopePrices.spot, scopePrices.twap, tokenMint, tokenName);
|
|
771
|
+
}
|
|
772
|
+
if ((0, utils_1.isNotNullPubkey)(pythOracle)) {
|
|
773
|
+
const pythPrices = (0, utils_1.cacheOrGetPythPrices)(pythOracle, pythCache, allOracleAccounts);
|
|
774
|
+
this.setPriceIfExist(klendPrices.pyth, pythPrices === null || pythPrices === void 0 ? void 0 : pythPrices.spot, pythPrices === null || pythPrices === void 0 ? void 0 : pythPrices.twap, tokenMint, tokenName);
|
|
775
|
+
}
|
|
776
|
+
if ((0, utils_1.isNotNullPubkey)(switchboardSpotOracle)) {
|
|
777
|
+
const switchboardPrices = {
|
|
778
|
+
spot: (0, utils_1.cacheOrGetSwitchboardPrice)(switchboardSpotOracle, switchboardCache, allOracleAccounts, switchboardV2),
|
|
779
|
+
twap: (0, utils_1.isNotNullPubkey)(switchboardTwapOracle)
|
|
780
|
+
? (0, utils_1.cacheOrGetSwitchboardPrice)(switchboardTwapOracle, switchboardCache, allOracleAccounts, switchboardV2)
|
|
781
|
+
: null,
|
|
782
|
+
};
|
|
783
|
+
this.setPriceIfExist(klendPrices.switchboard, switchboardPrices.spot, switchboardPrices.twap, tokenMint, tokenName);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return klendPrices;
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
getCumulativeBorrowRatesByReserve(slot) {
|
|
790
|
+
const cumulativeBorrowRates = new utils_1.PubkeyHashMap();
|
|
791
|
+
for (const reserve of this.reserves.values()) {
|
|
792
|
+
cumulativeBorrowRates.set(reserve.address, reserve.getEstimatedCumulativeBorrowRate(slot));
|
|
793
|
+
}
|
|
794
|
+
return cumulativeBorrowRates;
|
|
795
|
+
}
|
|
796
|
+
getCollateralExchangeRatesByReserve(slot) {
|
|
797
|
+
const collateralExchangeRates = new utils_1.PubkeyHashMap();
|
|
798
|
+
for (const reserve of this.reserves.values()) {
|
|
799
|
+
collateralExchangeRates.set(reserve.address, reserve.getEstimatedCollateralExchangeRate(slot, this.state.referralFeeBps));
|
|
800
|
+
}
|
|
801
|
+
return collateralExchangeRates;
|
|
802
|
+
}
|
|
803
|
+
setPriceIfExist(prices, spot, twap, mint, tokenName) {
|
|
804
|
+
if (spot) {
|
|
805
|
+
prices.spot[mint] = { price: spot.price, name: tokenName };
|
|
806
|
+
}
|
|
807
|
+
if (twap) {
|
|
808
|
+
prices.twap[mint] = { price: twap.price, name: tokenName };
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
exports.KaminoMarket = KaminoMarket;
|
|
813
|
+
function getReservesForMarket(marketAddress, connection, programId) {
|
|
814
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
815
|
+
const reserves = yield connection.getProgramAccounts(programId, {
|
|
816
|
+
filters: [
|
|
817
|
+
{
|
|
818
|
+
dataSize: accounts_1.Reserve.layout.span + 8,
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
memcmp: {
|
|
822
|
+
offset: 32,
|
|
823
|
+
bytes: marketAddress.toBase58(),
|
|
824
|
+
},
|
|
825
|
+
},
|
|
826
|
+
],
|
|
827
|
+
});
|
|
828
|
+
const deserializedReserves = reserves.map((reserve) => {
|
|
829
|
+
if (reserve.account === null) {
|
|
830
|
+
throw new Error(`Reserve account ${reserve.pubkey.toBase58()} does not exist`);
|
|
831
|
+
}
|
|
832
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.account.data);
|
|
833
|
+
if (!reserveAccount) {
|
|
834
|
+
throw Error(`Could not parse reserve ${reserve.pubkey.toBase58()}`);
|
|
835
|
+
}
|
|
836
|
+
return reserveAccount;
|
|
837
|
+
});
|
|
838
|
+
const allBuffers = reserves.map((reserve) => reserve.account);
|
|
839
|
+
const reservesAndOracles = yield (0, utils_1.getTokenOracleData)(connection, deserializedReserves);
|
|
840
|
+
const reservesByAddress = new utils_1.PubkeyHashMap();
|
|
841
|
+
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
842
|
+
if (!oracle) {
|
|
843
|
+
throw Error(`Could not find oracle for ${(0, utils_2.parseTokenSymbol)(reserve.config.tokenInfo.name)} reserve`);
|
|
844
|
+
}
|
|
845
|
+
const kaminoReserve = reserve_1.KaminoReserve.initialize(allBuffers[index], reserves[index].pubkey, reserve, oracle, connection);
|
|
846
|
+
reservesByAddress.set(kaminoReserve.address, kaminoReserve);
|
|
847
|
+
});
|
|
848
|
+
return reservesByAddress;
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
exports.getReservesForMarket = getReservesForMarket;
|
|
852
|
+
function getReservesActive(reserves) {
|
|
853
|
+
const reservesActive = new utils_1.PubkeyHashMap();
|
|
854
|
+
for (const [key, reserve] of reserves) {
|
|
855
|
+
if (reserve.state.config.status === 0) {
|
|
856
|
+
reservesActive.set(key, reserve);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return reservesActive;
|
|
860
|
+
}
|
|
861
|
+
exports.getReservesActive = getReservesActive;
|
|
862
|
+
function _getReserveFromMintAndMarket(marketConfig, mint, connection, programId) {
|
|
863
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
864
|
+
const reserve = (yield connection.getProgramAccounts(programId, {
|
|
865
|
+
filters: [
|
|
866
|
+
{
|
|
867
|
+
dataSize: accounts_1.Reserve.layout.span + 8,
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
memcmp: {
|
|
871
|
+
offset: 32,
|
|
872
|
+
bytes: marketConfig.lendingMarket,
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
memcmp: {
|
|
877
|
+
offset: 64,
|
|
878
|
+
bytes: mint,
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
],
|
|
882
|
+
}))[0];
|
|
883
|
+
if (reserve.account === null) {
|
|
884
|
+
throw new Error('Invalid account');
|
|
885
|
+
}
|
|
886
|
+
if (!reserve.account.owner.equals(programId)) {
|
|
887
|
+
throw new Error("Account doesn't belong to this program");
|
|
888
|
+
}
|
|
889
|
+
const reserveAccount = accounts_1.Reserve.decode(reserve.account.data);
|
|
890
|
+
if (!reserveAccount) {
|
|
891
|
+
throw Error('Could not parse reserve.');
|
|
892
|
+
}
|
|
893
|
+
return [reserve.pubkey, reserveAccount];
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
exports._getReserveFromMintAndMarket = _getReserveFromMintAndMarket;
|
|
897
|
+
const lamportsToNumberDecimal = (amount, decimals) => {
|
|
898
|
+
const factor = Math.pow(10, decimals);
|
|
899
|
+
return new decimal_js_1.default(amount).div(factor);
|
|
900
|
+
};
|
|
901
|
+
//# sourceMappingURL=market.js.map
|