@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,474 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KaminoReserve = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const shared_1 = require("./shared");
|
|
19
|
+
const accounts_1 = require("../idl_codegen/accounts");
|
|
20
|
+
const utils_2 = require("./utils");
|
|
21
|
+
const fraction_1 = require("./fraction");
|
|
22
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
23
|
+
class KaminoReserve {
|
|
24
|
+
constructor(state, address, tokenOraclePrice, connection) {
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns the flash loan fee percentage of the reserve
|
|
28
|
+
*/
|
|
29
|
+
this.getFlashLoanFee = () => {
|
|
30
|
+
return new fraction_1.Fraction(this.state.config.fees.flashLoanFeeSf).toDecimal();
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @returns the origination fee percentage of the reserve
|
|
35
|
+
*/
|
|
36
|
+
this.getBorrowFee = () => {
|
|
37
|
+
return new fraction_1.Fraction(this.state.config.fees.borrowFeeSf).toDecimal();
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @returns the total USD value of the existing collateral in the reserve
|
|
42
|
+
*/
|
|
43
|
+
this.getDepositTvl = () => {
|
|
44
|
+
return new decimal_js_1.default(this.getTotalSupply().toString()).mul(this.getOracleMarketPrice()).div(this.getMintFactor());
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* Get the total USD value of the borrowed assets from the reserve
|
|
49
|
+
*/
|
|
50
|
+
this.getBorrowTvl = () => {
|
|
51
|
+
return this.getBorrowedAmount().mul(this.getOracleMarketPrice()).div(this.getMintFactor());
|
|
52
|
+
};
|
|
53
|
+
this.state = state;
|
|
54
|
+
this.address = address;
|
|
55
|
+
this.buffer = null;
|
|
56
|
+
this.tokenOraclePrice = tokenOraclePrice;
|
|
57
|
+
this.stats = {};
|
|
58
|
+
this.connection = connection;
|
|
59
|
+
this.symbol = (0, utils_2.parseTokenSymbol)(state.config.tokenInfo.name);
|
|
60
|
+
}
|
|
61
|
+
static initialize(accountData, address, state, tokenOraclePrice, connection) {
|
|
62
|
+
const reserve = new KaminoReserve(state, address, tokenOraclePrice, connection);
|
|
63
|
+
reserve.setBuffer(accountData);
|
|
64
|
+
reserve.stats = reserve.formatReserveData(state);
|
|
65
|
+
return reserve;
|
|
66
|
+
}
|
|
67
|
+
/// GETTERS
|
|
68
|
+
/**
|
|
69
|
+
* @returns the parsed token symbol of the reserve
|
|
70
|
+
*/
|
|
71
|
+
getTokenSymbol() {
|
|
72
|
+
return (0, utils_2.parseTokenSymbol)(this.state.config.tokenInfo.name);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @returns the total borrowed amount of the reserve
|
|
76
|
+
*/
|
|
77
|
+
getBorrowedAmount() {
|
|
78
|
+
return new fraction_1.Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @returns the available liquidity amount of the reserve
|
|
82
|
+
*/
|
|
83
|
+
getLiquidityAvailableAmount() {
|
|
84
|
+
return new decimal_js_1.default(this.state.liquidity.availableAmount.toString());
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @returns the last cached price stored in the reserve in USD
|
|
89
|
+
*/
|
|
90
|
+
getReserveMarketPrice() {
|
|
91
|
+
return new fraction_1.Fraction(this.state.liquidity.marketPriceSf).toDecimal();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @returns the current market price of the reserve in USD
|
|
95
|
+
*/
|
|
96
|
+
getOracleMarketPrice() {
|
|
97
|
+
return this.tokenOraclePrice.price;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @returns the total accumulated protocol fees of the reserve
|
|
101
|
+
*/
|
|
102
|
+
getAccumulatedProtocolFees() {
|
|
103
|
+
return new fraction_1.Fraction(this.state.liquidity.accumulatedProtocolFeesSf).toDecimal();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @returns the total accumulated referrer fees of the reserve
|
|
107
|
+
*/
|
|
108
|
+
getAccumulatedReferrerFees() {
|
|
109
|
+
return new fraction_1.Fraction(this.state.liquidity.accumulatedReferrerFeesSf).toDecimal();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @returns the total pending referrer fees of the reserve
|
|
113
|
+
*/
|
|
114
|
+
getPendingReferrerFees() {
|
|
115
|
+
return new fraction_1.Fraction(this.state.liquidity.pendingReferrerFeesSf).toDecimal();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Use getEstimatedTotalSupply() for the most accurate value
|
|
119
|
+
* @returns the stale total liquidity supply of the reserve from the last refresh
|
|
120
|
+
*/
|
|
121
|
+
getTotalSupply() {
|
|
122
|
+
return this.getLiquidityAvailableAmount()
|
|
123
|
+
.add(this.getBorrowedAmount())
|
|
124
|
+
.sub(this.getAccumulatedProtocolFees())
|
|
125
|
+
.sub(this.getAccumulatedReferrerFees())
|
|
126
|
+
.sub(this.getPendingReferrerFees());
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Calculates the total liquidity supply of the reserve
|
|
130
|
+
*/
|
|
131
|
+
getEstimatedTotalSupply(slot, referralFeeBps) {
|
|
132
|
+
const { totalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);
|
|
133
|
+
return totalSupply;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Use getEstimatedCumulativeBorrowRate() for the most accurate value
|
|
137
|
+
* @returns the stale cumulative borrow rate of the reserve from the last refresh
|
|
138
|
+
*/
|
|
139
|
+
getCumulativeBorrowRate() {
|
|
140
|
+
let accSf = new bn_js_1.default(0);
|
|
141
|
+
for (const value of this.state.liquidity.cumulativeBorrowRateBsf.value.reverse()) {
|
|
142
|
+
accSf = accSf.add(value);
|
|
143
|
+
accSf.shrn(64);
|
|
144
|
+
}
|
|
145
|
+
return new fraction_1.Fraction(accSf).toDecimal();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @Returns estimated cumulative borrow rate of the reserve
|
|
149
|
+
*/
|
|
150
|
+
getEstimatedCumulativeBorrowRate(currentSlot) {
|
|
151
|
+
const currentBorrowRate = new decimal_js_1.default(this.calculateBorrowAPR());
|
|
152
|
+
const slotsElapsed = Math.max(currentSlot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
153
|
+
const compoundInterest = this.approximateCompoundedInterest(currentBorrowRate, slotsElapsed);
|
|
154
|
+
const previousCumulativeBorrowRate = this.getCumulativeBorrowRate();
|
|
155
|
+
return previousCumulativeBorrowRate.mul(compoundInterest);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Use getEstimatedCollateralExchangeRate() for the most accurate value
|
|
159
|
+
* @returns the stale exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18
|
|
160
|
+
*/
|
|
161
|
+
getCollateralExchangeRate() {
|
|
162
|
+
const totalSupply = this.getTotalSupply();
|
|
163
|
+
const mintTotalSupply = this.state.collateral.mintTotalSupply;
|
|
164
|
+
if (mintTotalSupply.isZero() || totalSupply.isZero()) {
|
|
165
|
+
return utils_1.INITIAL_COLLATERAL_RATE;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return new decimal_js_1.default(mintTotalSupply.toString()).dividedBy(totalSupply.toString());
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @returns the estimated exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18
|
|
174
|
+
*/
|
|
175
|
+
getEstimatedCollateralExchangeRate(slot, referralFeeBps) {
|
|
176
|
+
const totalSupply = this.getEstimatedTotalSupply(slot, referralFeeBps);
|
|
177
|
+
const mintTotalSupply = this.state.collateral.mintTotalSupply;
|
|
178
|
+
if (mintTotalSupply.isZero() || totalSupply.isZero()) {
|
|
179
|
+
return utils_1.INITIAL_COLLATERAL_RATE;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return new decimal_js_1.default(mintTotalSupply.toString()).dividedBy(totalSupply.toString());
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @returns 10^mint_decimals
|
|
187
|
+
*/
|
|
188
|
+
getMintFactor() {
|
|
189
|
+
return new decimal_js_1.default(10).pow(this.state.liquidity.mintDecimals.toNumber());
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @Returns true if the total liquidity supply of the reserve is greater than the deposit limit
|
|
193
|
+
*/
|
|
194
|
+
depositLimitCrossed() {
|
|
195
|
+
return this.getTotalSupply().gt(new decimal_js_1.default(this.state.config.depositLimit.toString()));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @Returns true if the total borrowed amount of the reserve is greater than the borrow limit
|
|
199
|
+
*/
|
|
200
|
+
borrowLimitCrossed() {
|
|
201
|
+
return this.getBorrowedAmount().gt(new decimal_js_1.default(this.state.config.borrowLimit.toString()));
|
|
202
|
+
}
|
|
203
|
+
calculateSupplyAPR() {
|
|
204
|
+
const currentUtilization = this.calculateUtilizationRatio();
|
|
205
|
+
const borrowAPR = this.calculateBorrowAPR();
|
|
206
|
+
const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;
|
|
207
|
+
return currentUtilization * borrowAPR * protocolTakeRatePct;
|
|
208
|
+
}
|
|
209
|
+
getEstimatedDebtAndSupply(slot, referralFeeBps) {
|
|
210
|
+
const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
211
|
+
let totalBorrow;
|
|
212
|
+
let totalSupply;
|
|
213
|
+
if (slotsElapsed === 0) {
|
|
214
|
+
totalBorrow = this.getBorrowedAmount();
|
|
215
|
+
totalSupply = this.getTotalSupply();
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const { newDebt, newAccProtocolFees, pendingReferralFees } = this.compoundInterest(slotsElapsed, referralFeeBps);
|
|
219
|
+
const newTotalSupply = this.getLiquidityAvailableAmount()
|
|
220
|
+
.add(newDebt)
|
|
221
|
+
.sub(newAccProtocolFees)
|
|
222
|
+
.sub(this.getAccumulatedReferrerFees())
|
|
223
|
+
.sub(pendingReferralFees);
|
|
224
|
+
totalBorrow = newDebt;
|
|
225
|
+
totalSupply = newTotalSupply;
|
|
226
|
+
}
|
|
227
|
+
return { totalBorrow, totalSupply };
|
|
228
|
+
}
|
|
229
|
+
calculateUtilizationRatio() {
|
|
230
|
+
const totalBorrows = this.getBorrowedAmount();
|
|
231
|
+
const totalSupply = this.getTotalSupply();
|
|
232
|
+
if (totalSupply.eq(0)) {
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
return totalBorrows.dividedBy(totalSupply).toNumber();
|
|
236
|
+
}
|
|
237
|
+
calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount) {
|
|
238
|
+
const { totalBorrow: previousTotalBorrowed, totalSupply: previousTotalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);
|
|
239
|
+
switch (action) {
|
|
240
|
+
case 'deposit': {
|
|
241
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
242
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
243
|
+
}
|
|
244
|
+
case 'withdraw': {
|
|
245
|
+
const newTotalSupply = previousTotalSupply.sub(amount);
|
|
246
|
+
if (newTotalSupply.eq(0)) {
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
case 'borrow': {
|
|
254
|
+
const newTotalBorrowed = previousTotalBorrowed.add(amount);
|
|
255
|
+
return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();
|
|
256
|
+
}
|
|
257
|
+
case 'repay': {
|
|
258
|
+
const newTotalBorrowed = previousTotalBorrowed.sub(amount);
|
|
259
|
+
return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();
|
|
260
|
+
}
|
|
261
|
+
case 'depositAndBorrow': {
|
|
262
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
263
|
+
const newTotalBorrowed = previousTotalBorrowed.add(outflowAmount);
|
|
264
|
+
return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
265
|
+
}
|
|
266
|
+
case 'repayAndWithdraw': {
|
|
267
|
+
const newTotalBorrowed = previousTotalBorrowed.sub(amount);
|
|
268
|
+
const newTotalSupply = previousTotalSupply.sub(outflowAmount);
|
|
269
|
+
if (newTotalSupply.eq(0)) {
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
273
|
+
}
|
|
274
|
+
case 'mint': {
|
|
275
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
276
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
277
|
+
}
|
|
278
|
+
case 'redeem': {
|
|
279
|
+
const newTotalSupply = previousTotalSupply.sub(amount);
|
|
280
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
281
|
+
}
|
|
282
|
+
default:
|
|
283
|
+
throw Error(`Invalid action type ${action} for simulatedUtilizationRatio`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount) {
|
|
287
|
+
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
288
|
+
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
289
|
+
return (0, utils_2.getBorrowRate)(newUtilization, curve);
|
|
290
|
+
}
|
|
291
|
+
calcSimulatedSupplyAPR(amount, action, slot, referralFeeBps, outflowAmount) {
|
|
292
|
+
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
293
|
+
const simulatedBorrowAPR = this.calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount);
|
|
294
|
+
const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;
|
|
295
|
+
return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;
|
|
296
|
+
}
|
|
297
|
+
calculateBorrowAPR() {
|
|
298
|
+
const currentUtilization = this.calculateUtilizationRatio();
|
|
299
|
+
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
300
|
+
return (0, utils_2.getBorrowRate)(currentUtilization, curve);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @returns the mint of the reserve liquidity token
|
|
304
|
+
*/
|
|
305
|
+
getLiquidityMint() {
|
|
306
|
+
return this.state.liquidity.mintPubkey;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @returns the mint of the reserve collateral token , i.e. the cToken minted for depositing the liquidity token
|
|
310
|
+
*/
|
|
311
|
+
getCTokenMint() {
|
|
312
|
+
return this.state.collateral.mintPubkey;
|
|
313
|
+
}
|
|
314
|
+
setBuffer(buffer) {
|
|
315
|
+
this.buffer = buffer;
|
|
316
|
+
}
|
|
317
|
+
load(tokenOraclePrice) {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
+
if (!this.buffer) {
|
|
320
|
+
this.setBuffer(yield this.connection.getAccountInfo(this.address, 'processed'));
|
|
321
|
+
}
|
|
322
|
+
if (!this.buffer) {
|
|
323
|
+
throw Error(`Error requesting account info for ${this.symbol}`);
|
|
324
|
+
}
|
|
325
|
+
const parsedData = yield accounts_1.Reserve.fetch(this.connection, this.address);
|
|
326
|
+
if (!parsedData) {
|
|
327
|
+
throw Error(`Unable to parse data of reserve ${this.symbol}`);
|
|
328
|
+
}
|
|
329
|
+
this.state = parsedData;
|
|
330
|
+
this.tokenOraclePrice = tokenOraclePrice;
|
|
331
|
+
this.stats = this.formatReserveData(parsedData);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
totalSupplyAPY() {
|
|
335
|
+
const { stats } = this;
|
|
336
|
+
if (!stats) {
|
|
337
|
+
throw Error('KaminoMarket must call loadRewards.');
|
|
338
|
+
}
|
|
339
|
+
const totalAPY = new decimal_js_1.default(stats.supplyInterestAPY).toNumber();
|
|
340
|
+
return {
|
|
341
|
+
interestAPY: stats.supplyInterestAPY,
|
|
342
|
+
totalAPY,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
totalBorrowAPY() {
|
|
346
|
+
const { stats } = this;
|
|
347
|
+
if (!stats) {
|
|
348
|
+
throw Error('KaminoMarket must call loadRewards.');
|
|
349
|
+
}
|
|
350
|
+
const totalAPY = new decimal_js_1.default(stats.borrowInterestAPY).toNumber();
|
|
351
|
+
return {
|
|
352
|
+
interestAPY: stats.borrowInterestAPY,
|
|
353
|
+
totalAPY,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
formatReserveData(parsedData) {
|
|
357
|
+
const mintTotalSupply = new decimal_js_1.default(parsedData.collateral.mintTotalSupply.toString()).div(this.getMintFactor());
|
|
358
|
+
let reserveStatus = shared_1.ReserveStatus.Active;
|
|
359
|
+
switch (parsedData.config.status) {
|
|
360
|
+
case 0:
|
|
361
|
+
reserveStatus = shared_1.ReserveStatus.Active;
|
|
362
|
+
break;
|
|
363
|
+
case 1:
|
|
364
|
+
reserveStatus = shared_1.ReserveStatus.Obsolete;
|
|
365
|
+
break;
|
|
366
|
+
case 2:
|
|
367
|
+
reserveStatus = shared_1.ReserveStatus.Hidden;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
// Reserve config
|
|
372
|
+
status: reserveStatus,
|
|
373
|
+
mintAddress: parsedData.liquidity.mintPubkey,
|
|
374
|
+
borrowCurve: truncateBorrowCurve(parsedData.config.borrowRateCurve.points),
|
|
375
|
+
loanToValuePct: parsedData.config.loanToValuePct / 100,
|
|
376
|
+
maxLiquidationBonus: parsedData.config.maxLiquidationBonusBps / 10000,
|
|
377
|
+
minLiquidationBonus: parsedData.config.minLiquidationBonusBps / 10000,
|
|
378
|
+
liquidationThreshold: parsedData.config.liquidationThresholdPct / 100,
|
|
379
|
+
protocolTakeRate: parsedData.config.protocolTakeRatePct / 100,
|
|
380
|
+
reserveDepositLimit: new decimal_js_1.default(parsedData.config.depositLimit.toString()),
|
|
381
|
+
reserveBorrowLimit: new decimal_js_1.default(parsedData.config.borrowLimit.toString()),
|
|
382
|
+
// Reserve info
|
|
383
|
+
symbol: (0, utils_2.parseTokenSymbol)(parsedData.config.tokenInfo.name),
|
|
384
|
+
decimals: this.state.liquidity.mintDecimals.toNumber(),
|
|
385
|
+
supplyInterestAPY: (0, utils_2.calculateAPYFromAPR)(this.calculateSupplyAPR()),
|
|
386
|
+
borrowInterestAPY: (0, utils_2.calculateAPYFromAPR)(this.calculateBorrowAPR()),
|
|
387
|
+
accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),
|
|
388
|
+
mintTotalSupply,
|
|
389
|
+
depositLimitCrossedSlot: parsedData.liquidity.depositLimitCrossedSlot.toNumber(),
|
|
390
|
+
borrowLimitCrossedSlot: parsedData.liquidity.borrowLimitCrossedSlot.toNumber(),
|
|
391
|
+
borrowFactor: parsedData.config.borrowFactorPct.toNumber(),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Compound current borrow rate over elapsed slots
|
|
396
|
+
*
|
|
397
|
+
* This also calculates protocol fees, which are taken for all obligations that have borrowed from current reserve.
|
|
398
|
+
*
|
|
399
|
+
* This also calculates referral fees, which are taken into pendingReferralFees.
|
|
400
|
+
*
|
|
401
|
+
* https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L517
|
|
402
|
+
*
|
|
403
|
+
* @param slotsElapsed
|
|
404
|
+
* @param referralFeeBps
|
|
405
|
+
*/
|
|
406
|
+
compoundInterest(slotsElapsed, referralFeeBps) {
|
|
407
|
+
const currentBorrowRate = this.calculateBorrowAPR();
|
|
408
|
+
const protocolTakeRate = new decimal_js_1.default(this.state.config.protocolTakeRatePct).div(100);
|
|
409
|
+
const referralRate = new decimal_js_1.default(referralFeeBps).div(10000);
|
|
410
|
+
const compoundInterestRate = this.approximateCompoundedInterest(new decimal_js_1.default(currentBorrowRate), slotsElapsed);
|
|
411
|
+
const previousDebt = this.getBorrowedAmount();
|
|
412
|
+
const newDebt = previousDebt.mul(compoundInterestRate);
|
|
413
|
+
const netNewDebt = newDebt.sub(previousDebt);
|
|
414
|
+
const totalProtocolFee = netNewDebt.mul(protocolTakeRate);
|
|
415
|
+
const absoluteReferralFee = protocolTakeRate.mul(referralRate);
|
|
416
|
+
const maxReferralFees = netNewDebt.mul(absoluteReferralFee);
|
|
417
|
+
const newAccProtocolFees = totalProtocolFee.sub(maxReferralFees).add(this.getAccumulatedProtocolFees());
|
|
418
|
+
const pendingReferralFees = this.getPendingReferrerFees().add(maxReferralFees);
|
|
419
|
+
return {
|
|
420
|
+
newDebt,
|
|
421
|
+
netNewDebt,
|
|
422
|
+
totalProtocolFee,
|
|
423
|
+
absoluteReferralFee,
|
|
424
|
+
maxReferralFees,
|
|
425
|
+
newAccProtocolFees,
|
|
426
|
+
pendingReferralFees,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Approximation to match the smart contract calculation
|
|
431
|
+
* https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L1026
|
|
432
|
+
* @param rate
|
|
433
|
+
* @param elapsedSlots
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
approximateCompoundedInterest(rate, elapsedSlots) {
|
|
437
|
+
const base = rate.div(utils_1.SLOTS_PER_YEAR);
|
|
438
|
+
switch (elapsedSlots) {
|
|
439
|
+
case 0:
|
|
440
|
+
return new decimal_js_1.default(1);
|
|
441
|
+
case 1:
|
|
442
|
+
return base.add(1);
|
|
443
|
+
case 2:
|
|
444
|
+
return base.add(1).mul(base.add(1));
|
|
445
|
+
case 3:
|
|
446
|
+
return base.add(1).mul(base.add(1)).mul(base.add(1));
|
|
447
|
+
case 4:
|
|
448
|
+
// eslint-disable-next-line no-case-declarations
|
|
449
|
+
const pow2 = base.add(1).mul(base.add(1));
|
|
450
|
+
return pow2.mul(pow2);
|
|
451
|
+
}
|
|
452
|
+
const exp = elapsedSlots;
|
|
453
|
+
const expMinus1 = exp - 1;
|
|
454
|
+
const expMinus2 = exp - 2;
|
|
455
|
+
const basePow2 = base.mul(base);
|
|
456
|
+
const basePow3 = basePow2.mul(base);
|
|
457
|
+
const firstTerm = base.mul(exp);
|
|
458
|
+
const secondTerm = basePow2.mul(exp).mul(expMinus1).div(2);
|
|
459
|
+
const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);
|
|
460
|
+
return new decimal_js_1.default(1).add(firstTerm).add(secondTerm).add(thirdTerm);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
exports.KaminoReserve = KaminoReserve;
|
|
464
|
+
const truncateBorrowCurve = (points) => {
|
|
465
|
+
const curve = [];
|
|
466
|
+
for (const { utilizationRateBps, borrowRateBps } of points) {
|
|
467
|
+
curve.push([utilizationRateBps / utils_1.ONE_HUNDRED_PCT_IN_BPS, borrowRateBps / utils_1.ONE_HUNDRED_PCT_IN_BPS]);
|
|
468
|
+
if (utilizationRateBps === utils_1.ONE_HUNDRED_PCT_IN_BPS) {
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return curve;
|
|
473
|
+
};
|
|
474
|
+
//# sourceMappingURL=reserve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reserve.js","sourceRoot":"","sources":["../../src/classes/reserve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,4DAAiC;AACjC,oCAA4G;AAC5G,qCAA0D;AAC1D,sDAAiE;AAEjE,mCAA+E;AAC/E,yCAAsC;AACtC,kDAAuB;AAGvB,MAAa,aAAa;IAWxB,YAAY,KAAc,EAAE,OAAkB,EAAE,gBAAiC,EAAE,UAAsB;QAkFzG;;;WAGG;QACH,oBAAe,GAAG,GAAY,EAAE;YAC9B,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;QACzE,CAAC,CAAC;QAEF;;;WAGG;QACH,iBAAY,GAAG,GAAY,EAAE;YAC3B,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,SAAS,EAAE,CAAC;QACtE,CAAC,CAAC;QA6EF;;;WAGG;QACH,kBAAa,GAAG,GAAY,EAAE;YAC5B,OAAO,IAAI,oBAAO,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,oBAAoB,E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,MAAM,EAAE;QAC1D,KAAK,CAAC,IAAI,CAAC,CAAC,kBAAkB,GAAG,8BAAsB,EAAE,aAAa,GAAG,8BAAsB,CAAC,CAAC,CAAC;QAElG,IAAI,kBAAkB,KAAK,8BAAsB,EAAE;YACjD,MAAM;SACP;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport { AccountInfo, Connection, PublicKey } from '@solana/web3.js';\nimport Decimal from 'decimal.js';\nimport { INITIAL_COLLATERAL_RATE, ONE_HUNDRED_PCT_IN_BPS, SLOTS_PER_YEAR, TokenOracleData } from '../utils';\nimport { ReserveDataType, ReserveStatus } from './shared';\nimport { Reserve, ReserveFields } from '../idl_codegen/accounts';\nimport { CurvePointFields } from '../idl_codegen/types';\nimport { calculateAPYFromAPR, getBorrowRate, parseTokenSymbol } from './utils';\nimport { Fraction } from './fraction';\nimport BN from 'bn.js';\nimport { ActionType } from './action';\n\nexport class KaminoReserve {\n state: Reserve;\n address: PublicKey;\n symbol: string;\n\n tokenOraclePrice: TokenOracleData;\n stats: ReserveDataType;\n\n private buffer: AccountInfo<Buffer> | null;\n private connection: Connection;\n\n constructor(state: Reserve, address: PublicKey, tokenOraclePrice: TokenOracleData, connection: Connection) {\n this.state = state;\n this.address = address;\n this.buffer = null;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = {} as ReserveDataType;\n this.connection = connection;\n this.symbol = parseTokenSymbol(state.config.tokenInfo.name);\n }\n\n static initialize(\n accountData: AccountInfo<Buffer>,\n address: PublicKey,\n state: Reserve,\n tokenOraclePrice: TokenOracleData,\n connection: Connection\n ) {\n const reserve = new KaminoReserve(state, address, tokenOraclePrice, connection);\n reserve.setBuffer(accountData);\n reserve.stats = reserve.formatReserveData(state);\n return reserve;\n }\n\n /// GETTERS\n\n /**\n * @returns the parsed token symbol of the reserve\n */\n getTokenSymbol(): string {\n return parseTokenSymbol(this.state.config.tokenInfo.name);\n }\n\n /**\n * @returns the total borrowed amount of the reserve\n */\n getBorrowedAmount(): Decimal {\n return new Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();\n }\n\n /**\n * @returns the available liquidity amount of the reserve\n */\n getLiquidityAvailableAmount(): Decimal {\n return new Decimal(this.state.liquidity.availableAmount.toString());\n }\n\n /**\n *\n * @returns the last cached price stored in the reserve in USD\n */\n getReserveMarketPrice(): Decimal {\n return new Fraction(this.state.liquidity.marketPriceSf).toDecimal();\n }\n\n /**\n * @returns the current market price of the reserve in USD\n */\n getOracleMarketPrice(): Decimal {\n return this.tokenOraclePrice.price;\n }\n\n /**\n * @returns the total accumulated protocol fees of the reserve\n */\n getAccumulatedProtocolFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedProtocolFeesSf).toDecimal();\n }\n\n /**\n * @returns the total accumulated referrer fees of the reserve\n */\n getAccumulatedReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedReferrerFeesSf).toDecimal();\n }\n\n /**\n * @returns the total pending referrer fees of the reserve\n */\n getPendingReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.pendingReferrerFeesSf).toDecimal();\n }\n\n /**\n *\n * @returns the flash loan fee percentage of the reserve\n */\n getFlashLoanFee = (): Decimal => {\n return new Fraction(this.state.config.fees.flashLoanFeeSf).toDecimal();\n };\n\n /**\n *\n * @returns the origination fee percentage of the reserve\n */\n getBorrowFee = (): Decimal => {\n return new Fraction(this.state.config.fees.borrowFeeSf).toDecimal();\n };\n\n /**\n * Use getEstimatedTotalSupply() for the most accurate value\n * @returns the stale total liquidity supply of the reserve from the last refresh\n */\n getTotalSupply(): Decimal {\n return this.getLiquidityAvailableAmount()\n .add(this.getBorrowedAmount())\n .sub(this.getAccumulatedProtocolFees())\n .sub(this.getAccumulatedReferrerFees())\n .sub(this.getPendingReferrerFees());\n }\n\n /**\n * Calculates the total liquidity supply of the reserve\n */\n getEstimatedTotalSupply(slot: number, referralFeeBps: number): Decimal {\n const { totalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);\n return totalSupply;\n }\n\n /**\n * Use getEstimatedCumulativeBorrowRate() for the most accurate value\n * @returns the stale cumulative borrow rate of the reserve from the last refresh\n */\n getCumulativeBorrowRate(): Decimal {\n let accSf = new BN(0);\n for (const value of this.state.liquidity.cumulativeBorrowRateBsf.value.reverse()) {\n accSf = accSf.add(value);\n accSf.shrn(64);\n }\n return new Fraction(accSf).toDecimal();\n }\n\n /**\n * @Returns estimated cumulative borrow rate of the reserve\n */\n getEstimatedCumulativeBorrowRate(currentSlot: number): Decimal {\n const currentBorrowRate = new Decimal(this.calculateBorrowAPR());\n const slotsElapsed = Math.max(currentSlot - this.state.lastUpdate.slot.toNumber(), 0);\n\n const compoundInterest = this.approximateCompoundedInterest(currentBorrowRate, slotsElapsed);\n\n const previousCumulativeBorrowRate = this.getCumulativeBorrowRate();\n\n return previousCumulativeBorrowRate.mul(compoundInterest);\n }\n\n /**\n * Use getEstimatedCollateralExchangeRate() for the most accurate value\n * @returns the stale exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getCollateralExchangeRate(): Decimal {\n const totalSupply = this.getTotalSupply();\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the estimated exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getEstimatedCollateralExchangeRate(slot: number, referralFeeBps: number): Decimal {\n const totalSupply = this.getEstimatedTotalSupply(slot, referralFeeBps);\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the total USD value of the existing collateral in the reserve\n */\n getDepositTvl = (): Decimal => {\n return new Decimal(this.getTotalSupply().toString()).mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n *\n * Get the total USD value of the borrowed assets from the reserve\n */\n getBorrowTvl = (): Decimal => {\n return this.getBorrowedAmount().mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n * @returns 10^mint_decimals\n */\n getMintFactor(): Decimal {\n return new Decimal(10).pow(this.state.liquidity.mintDecimals.toNumber());\n }\n\n /**\n * @Returns true if the total liquidity supply of the reserve is greater than the deposit limit\n */\n depositLimitCrossed(): boolean {\n return this.getTotalSupply().gt(new Decimal(this.state.config.depositLimit.toString()));\n }\n\n /**\n * @Returns true if the total borrowed amount of the reserve is greater than the borrow limit\n */\n borrowLimitCrossed(): boolean {\n return this.getBorrowedAmount().gt(new Decimal(this.state.config.borrowLimit.toString()));\n }\n\n calculateSupplyAPR() {\n const currentUtilization = this.calculateUtilizationRatio();\n\n const borrowAPR = this.calculateBorrowAPR();\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n return currentUtilization * borrowAPR * protocolTakeRatePct;\n }\n\n getEstimatedDebtAndSupply(slot: number, referralFeeBps: number): { totalBorrow: Decimal; totalSupply: Decimal } {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n let totalBorrow: Decimal;\n let totalSupply: Decimal;\n if (slotsElapsed === 0) {\n totalBorrow = this.getBorrowedAmount();\n totalSupply = this.getTotalSupply();\n } else {\n const { newDebt, newAccProtocolFees, pendingReferralFees } = this.compoundInterest(slotsElapsed, referralFeeBps);\n const newTotalSupply = this.getLiquidityAvailableAmount()\n .add(newDebt)\n .sub(newAccProtocolFees)\n .sub(this.getAccumulatedReferrerFees())\n .sub(pendingReferralFees);\n totalBorrow = newDebt;\n totalSupply = newTotalSupply;\n }\n return { totalBorrow, totalSupply };\n }\n\n calculateUtilizationRatio() {\n const totalBorrows = this.getBorrowedAmount();\n const totalSupply = this.getTotalSupply();\n if (totalSupply.eq(0)) {\n return 0;\n }\n return totalBorrows.dividedBy(totalSupply).toNumber();\n }\n\n calcSimulatedUtilizationRatio(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ): number {\n const { totalBorrow: previousTotalBorrowed, totalSupply: previousTotalSupply } = this.getEstimatedDebtAndSupply(\n slot,\n referralFeeBps\n );\n\n switch (action) {\n case 'deposit': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'withdraw': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n if (newTotalSupply.eq(0)) {\n return 0;\n } else {\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n }\n case 'borrow': {\n const newTotalBorrowed = previousTotalBorrowed.add(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'repay': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'depositAndBorrow': {\n const newTotalSupply = previousTotalSupply.add(amount);\n const newTotalBorrowed = previousTotalBorrowed.add(outflowAmount!);\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'repayAndWithdraw': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n const newTotalSupply = previousTotalSupply.sub(outflowAmount!);\n if (newTotalSupply.eq(0)) {\n return 0;\n }\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'mint': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'redeem': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n default:\n throw Error(`Invalid action type ${action} for simulatedUtilizationRatio`);\n }\n }\n\n calcSimulatedBorrowAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(newUtilization, curve);\n }\n\n calcSimulatedSupplyAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const simulatedBorrowAPR = this.calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount);\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n\n return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;\n }\n\n calculateBorrowAPR() {\n const currentUtilization = this.calculateUtilizationRatio();\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(currentUtilization, curve);\n }\n\n /**\n * @returns the mint of the reserve liquidity token\n */\n getLiquidityMint(): PublicKey {\n return this.state.liquidity.mintPubkey;\n }\n\n /**\n * @returns the mint of the reserve collateral token , i.e. the cToken minted for depositing the liquidity token\n */\n getCTokenMint(): PublicKey {\n return this.state.collateral.mintPubkey;\n }\n\n setBuffer(buffer: AccountInfo<Buffer> | null) {\n this.buffer = buffer;\n }\n\n async load(tokenOraclePrice: TokenOracleData) {\n if (!this.buffer) {\n this.setBuffer(await this.connection.getAccountInfo(this.address, 'processed'));\n }\n\n if (!this.buffer) {\n throw Error(`Error requesting account info for ${this.symbol}`);\n }\n\n const parsedData = await Reserve.fetch(this.connection, this.address);\n if (!parsedData) {\n throw Error(`Unable to parse data of reserve ${this.symbol}`);\n }\n this.state = parsedData;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = this.formatReserveData(parsedData);\n }\n\n totalSupplyAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.supplyInterestAPY).toNumber();\n\n return {\n interestAPY: stats.supplyInterestAPY,\n totalAPY,\n };\n }\n\n totalBorrowAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.borrowInterestAPY).toNumber();\n\n return {\n interestAPY: stats.borrowInterestAPY,\n totalAPY,\n };\n }\n\n private formatReserveData(parsedData: ReserveFields): ReserveDataType {\n const mintTotalSupply = new Decimal(parsedData.collateral.mintTotalSupply.toString()).div(this.getMintFactor());\n let reserveStatus = ReserveStatus.Active;\n switch (parsedData.config.status) {\n case 0:\n reserveStatus = ReserveStatus.Active;\n break;\n case 1:\n reserveStatus = ReserveStatus.Obsolete;\n break;\n case 2:\n reserveStatus = ReserveStatus.Hidden;\n break;\n }\n return {\n // Reserve config\n\n status: reserveStatus,\n mintAddress: parsedData.liquidity.mintPubkey,\n borrowCurve: truncateBorrowCurve(parsedData.config.borrowRateCurve.points),\n loanToValuePct: parsedData.config.loanToValuePct / 100,\n maxLiquidationBonus: parsedData.config.maxLiquidationBonusBps / 10000,\n minLiquidationBonus: parsedData.config.minLiquidationBonusBps / 10000,\n liquidationThreshold: parsedData.config.liquidationThresholdPct / 100,\n protocolTakeRate: parsedData.config.protocolTakeRatePct / 100,\n reserveDepositLimit: new Decimal(parsedData.config.depositLimit.toString()),\n reserveBorrowLimit: new Decimal(parsedData.config.borrowLimit.toString()),\n\n // Reserve info\n symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),\n decimals: this.state.liquidity.mintDecimals.toNumber(),\n supplyInterestAPY: calculateAPYFromAPR(this.calculateSupplyAPR()),\n borrowInterestAPY: calculateAPYFromAPR(this.calculateBorrowAPR()),\n accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),\n mintTotalSupply,\n depositLimitCrossedSlot: parsedData.liquidity.depositLimitCrossedSlot.toNumber(),\n borrowLimitCrossedSlot: parsedData.liquidity.borrowLimitCrossedSlot.toNumber(),\n borrowFactor: parsedData.config.borrowFactorPct.toNumber(),\n };\n }\n\n /**\n * Compound current borrow rate over elapsed slots\n *\n * This also calculates protocol fees, which are taken for all obligations that have borrowed from current reserve.\n *\n * This also calculates referral fees, which are taken into pendingReferralFees.\n *\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L517\n *\n * @param slotsElapsed\n * @param referralFeeBps\n */\n private compoundInterest(\n slotsElapsed: number,\n referralFeeBps: number\n ): {\n newDebt: Decimal;\n netNewDebt: Decimal;\n totalProtocolFee: Decimal;\n absoluteReferralFee: Decimal;\n maxReferralFees: Decimal;\n newAccProtocolFees: Decimal;\n pendingReferralFees: Decimal;\n } {\n const currentBorrowRate = this.calculateBorrowAPR();\n const protocolTakeRate = new Decimal(this.state.config.protocolTakeRatePct).div(100);\n const referralRate = new Decimal(referralFeeBps).div(10_000);\n\n const compoundInterestRate = this.approximateCompoundedInterest(new Decimal(currentBorrowRate), slotsElapsed);\n\n const previousDebt = this.getBorrowedAmount();\n const newDebt = previousDebt.mul(compoundInterestRate);\n const netNewDebt = newDebt.sub(previousDebt);\n\n const totalProtocolFee = netNewDebt.mul(protocolTakeRate);\n const absoluteReferralFee = protocolTakeRate.mul(referralRate);\n const maxReferralFees = netNewDebt.mul(absoluteReferralFee);\n\n const newAccProtocolFees = totalProtocolFee.sub(maxReferralFees).add(this.getAccumulatedProtocolFees());\n\n const pendingReferralFees = this.getPendingReferrerFees().add(maxReferralFees);\n\n return {\n newDebt,\n netNewDebt,\n totalProtocolFee,\n absoluteReferralFee,\n maxReferralFees,\n newAccProtocolFees,\n pendingReferralFees,\n };\n }\n\n /**\n * Approximation to match the smart contract calculation\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L1026\n * @param rate\n * @param elapsedSlots\n * @private\n */\n private approximateCompoundedInterest(rate: Decimal, elapsedSlots: number): Decimal {\n const base = rate.div(SLOTS_PER_YEAR);\n switch (elapsedSlots) {\n case 0:\n return new Decimal(1);\n case 1:\n return base.add(1);\n case 2:\n return base.add(1).mul(base.add(1));\n case 3:\n return base.add(1).mul(base.add(1)).mul(base.add(1));\n case 4:\n // eslint-disable-next-line no-case-declarations\n const pow2 = base.add(1).mul(base.add(1));\n return pow2.mul(pow2);\n }\n const exp = elapsedSlots;\n const expMinus1 = exp - 1;\n const expMinus2 = exp - 2;\n\n const basePow2 = base.mul(base);\n const basePow3 = basePow2.mul(base);\n\n const firstTerm = base.mul(exp);\n const secondTerm = basePow2.mul(exp).mul(expMinus1).div(2);\n const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);\n\n return new Decimal(1).add(firstTerm).add(secondTerm).add(thirdTerm);\n }\n}\n\nconst truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] => {\n const curve: [number, number][] = [];\n for (const { utilizationRateBps, borrowRateBps } of points) {\n curve.push([utilizationRateBps / ONE_HUNDRED_PCT_IN_BPS, borrowRateBps / ONE_HUNDRED_PCT_IN_BPS]);\n\n if (utilizationRateBps === ONE_HUNDRED_PCT_IN_BPS) {\n break;\n }\n }\n return curve;\n};\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
3
|
+
export type ConfigType = Array<MarketConfigType>;
|
|
4
|
+
export type MarketConfigType = {
|
|
5
|
+
name: string;
|
|
6
|
+
isPrimary: boolean;
|
|
7
|
+
description: string;
|
|
8
|
+
lendingMarket: string;
|
|
9
|
+
};
|
|
10
|
+
export type ReserveConfigResponse = {
|
|
11
|
+
liquidityToken: {
|
|
12
|
+
symbol: string;
|
|
13
|
+
mint: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare enum ReserveStatus {
|
|
17
|
+
Active = "Active",
|
|
18
|
+
Obsolete = "Obsolete",
|
|
19
|
+
Hidden = "Hidden"
|
|
20
|
+
}
|
|
21
|
+
export type ReserveDataType = {
|
|
22
|
+
status: ReserveStatus;
|
|
23
|
+
mintAddress: PublicKey;
|
|
24
|
+
borrowCurve: [number, number][];
|
|
25
|
+
loanToValuePct: number;
|
|
26
|
+
maxLiquidationBonus: number;
|
|
27
|
+
minLiquidationBonus: number;
|
|
28
|
+
liquidationThreshold: number;
|
|
29
|
+
reserveDepositLimit: Decimal;
|
|
30
|
+
reserveBorrowLimit: Decimal;
|
|
31
|
+
depositLimitCrossedSlot: number;
|
|
32
|
+
borrowLimitCrossedSlot: number;
|
|
33
|
+
symbol: string;
|
|
34
|
+
decimals: number;
|
|
35
|
+
supplyInterestAPY: number;
|
|
36
|
+
borrowInterestAPY: number;
|
|
37
|
+
protocolTakeRate: number;
|
|
38
|
+
accumulatedProtocolFees: Decimal;
|
|
39
|
+
mintTotalSupply: Decimal;
|
|
40
|
+
borrowFactor: number;
|
|
41
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReserveStatus = void 0;
|
|
4
|
+
var ReserveStatus;
|
|
5
|
+
(function (ReserveStatus) {
|
|
6
|
+
ReserveStatus["Active"] = "Active";
|
|
7
|
+
ReserveStatus["Obsolete"] = "Obsolete";
|
|
8
|
+
ReserveStatus["Hidden"] = "Hidden";
|
|
9
|
+
})(ReserveStatus = exports.ReserveStatus || (exports.ReserveStatus = {}));
|
|
10
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/classes/shared.ts"],"names":[],"mappings":";;;AAmBA,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,sCAAqB,CAAA;IACrB,kCAAiB,CAAA;AACnB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB","sourcesContent":["import { PublicKey } from '@solana/web3.js';\nimport Decimal from 'decimal.js';\n\nexport type ConfigType = Array<MarketConfigType>;\n\nexport type MarketConfigType = {\n name: string;\n isPrimary: boolean;\n description: string;\n lendingMarket: string;\n};\n\nexport type ReserveConfigResponse = {\n liquidityToken: {\n symbol: string;\n mint: string;\n };\n};\n\nexport enum ReserveStatus {\n Active = 'Active',\n Obsolete = 'Obsolete',\n Hidden = 'Hidden',\n}\n\nexport type ReserveDataType = {\n status: ReserveStatus;\n mintAddress: PublicKey;\n borrowCurve: [number, number][];\n loanToValuePct: number;\n maxLiquidationBonus: number;\n minLiquidationBonus: number;\n liquidationThreshold: number;\n reserveDepositLimit: Decimal;\n reserveBorrowLimit: Decimal;\n depositLimitCrossedSlot: number;\n borrowLimitCrossedSlot: number;\n symbol: string;\n decimals: number;\n supplyInterestAPY: number;\n borrowInterestAPY: number;\n protocolTakeRate: number;\n accumulatedProtocolFees: Decimal;\n mintTotalSupply: Decimal;\n borrowFactor: number;\n};\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
type ObligationFarmScoreType = {
|
|
4
|
+
obligationId: string;
|
|
5
|
+
balance: string;
|
|
6
|
+
debt: string;
|
|
7
|
+
score: string;
|
|
8
|
+
lastSlot: number;
|
|
9
|
+
tokenMint: string;
|
|
10
|
+
side: 'supply' | 'borrow';
|
|
11
|
+
};
|
|
12
|
+
type RewardRate = {
|
|
13
|
+
beginningSlot: number;
|
|
14
|
+
rewardRate: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const calculateNewScore: (rewardStat: {
|
|
18
|
+
lastSlot: number;
|
|
19
|
+
rewardRates: Array<RewardRate>;
|
|
20
|
+
rewardsPerShare: string;
|
|
21
|
+
totalBalance: string;
|
|
22
|
+
}, pool: ObligationFarmScoreType, rewardRate: string, endSlot: number, startSlot: number) => Decimal;
|
|
23
|
+
export declare const estimateCurrentScore: (rewardStat: {
|
|
24
|
+
lastSlot: number;
|
|
25
|
+
rewardRates: Array<RewardRate>;
|
|
26
|
+
rewardsPerShare: string;
|
|
27
|
+
totalBalance: string;
|
|
28
|
+
}, rewardScore: ObligationFarmScoreType, mostRecentSlot: number, mostRecentSlotTime: number) => Decimal;
|
|
29
|
+
export declare const interpolate: (x: number, x0: number, x1: number, y0: number, y1: number) => number;
|
|
30
|
+
export declare const getBorrowRate: (currentUtilization: number, curve: [number, number][]) => number;
|
|
31
|
+
export declare const parseTokenSymbol: (tokenSymbol: number[]) => string;
|
|
32
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
33
|
+
export declare function numberToLamportsDecimal(amount: Decimal.Value, decimals: number): Decimal;
|
|
34
|
+
export declare function lamportsToNumberDecimal(amount: Decimal.Value, decimals: number): Decimal;
|
|
35
|
+
export declare const isSolMint: (mint: PublicKey) => boolean;
|
|
36
|
+
export declare const valueOrZero: (value: Decimal) => Decimal;
|
|
37
|
+
export declare const isEmptyObject: (obj: any) => boolean;
|
|
38
|
+
export declare const positiveOrZero: (value: Decimal) => Decimal;
|
|
39
|
+
export declare function calculateAPYFromAPR(apr: number): number;
|
|
40
|
+
export {};
|