@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,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.calculateAPYFromAPR = exports.positiveOrZero = exports.isEmptyObject = exports.valueOrZero = exports.isSolMint = exports.lamportsToNumberDecimal = exports.numberToLamportsDecimal = exports.sleep = exports.parseTokenSymbol = exports.getBorrowRate = exports.interpolate = exports.estimateCurrentScore = exports.calculateNewScore = void 0;
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
|
+
const lib_1 = require("../lib");
|
|
10
|
+
function getLatestRewardRate(rewardRates, slot) {
|
|
11
|
+
return rewardRates
|
|
12
|
+
.filter((rr) => slot >= rr.beginningSlot)
|
|
13
|
+
.reduce((v1, v2) => (v1.beginningSlot > v2.beginningSlot ? v1 : v2), {
|
|
14
|
+
beginningSlot: 0,
|
|
15
|
+
rewardRate: '0',
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const calculateNewScore = (rewardStat, pool, rewardRate, endSlot, startSlot) => {
|
|
19
|
+
const { balance, debt, score } = pool;
|
|
20
|
+
const { rewardsPerShare, totalBalance } = rewardStat;
|
|
21
|
+
const oldDebt = new decimal_js_1.default(debt);
|
|
22
|
+
const oldScore = new decimal_js_1.default(score);
|
|
23
|
+
const oldRewardsPerShare = new decimal_js_1.default(rewardsPerShare);
|
|
24
|
+
const oldBalance = new decimal_js_1.default(balance);
|
|
25
|
+
const totalBalanceVal = new decimal_js_1.default(totalBalance);
|
|
26
|
+
const newRewardsPerShare = !totalBalanceVal.isZero()
|
|
27
|
+
? oldRewardsPerShare.plus(new decimal_js_1.default(endSlot)
|
|
28
|
+
.minus(new decimal_js_1.default(startSlot.toString()))
|
|
29
|
+
.times(new decimal_js_1.default(rewardRate))
|
|
30
|
+
.div(totalBalanceVal)
|
|
31
|
+
.div(new decimal_js_1.default(utils_1.SLOTS_PER_YEAR)))
|
|
32
|
+
: new decimal_js_1.default(0);
|
|
33
|
+
return oldScore.plus(newRewardsPerShare.times(oldBalance).minus(oldDebt));
|
|
34
|
+
};
|
|
35
|
+
exports.calculateNewScore = calculateNewScore;
|
|
36
|
+
const estimateCurrentScore = (rewardStat, rewardScore, mostRecentSlot, mostRecentSlotTime) => {
|
|
37
|
+
const { lastSlot, rewardRates } = rewardStat;
|
|
38
|
+
const estimatedCurrentSlot = mostRecentSlot + utils_1.SLOTS_PER_SECOND * (Date.now() / 1000 - mostRecentSlotTime);
|
|
39
|
+
const { rewardRate } = getLatestRewardRate(rewardRates, estimatedCurrentSlot);
|
|
40
|
+
const currentScore = (0, exports.calculateNewScore)(rewardStat, rewardScore, rewardRate, estimatedCurrentSlot, lastSlot);
|
|
41
|
+
return currentScore;
|
|
42
|
+
};
|
|
43
|
+
exports.estimateCurrentScore = estimateCurrentScore;
|
|
44
|
+
const interpolate = (x, x0, x1, y0, y1) => {
|
|
45
|
+
if (x > x1) {
|
|
46
|
+
throw 'Cannot do extrapolation';
|
|
47
|
+
}
|
|
48
|
+
return y0 + ((x - x0) * (y1 - y0)) / (x1 - x0);
|
|
49
|
+
};
|
|
50
|
+
exports.interpolate = interpolate;
|
|
51
|
+
const getBorrowRate = (currentUtilization, curve) => {
|
|
52
|
+
let [x0, y0, x1, y1] = [0, 0, 0, 0];
|
|
53
|
+
if (curve.length < 2) {
|
|
54
|
+
throw 'Invalid borrow rate curve, only one point';
|
|
55
|
+
}
|
|
56
|
+
if (currentUtilization > 1) {
|
|
57
|
+
currentUtilization = 1;
|
|
58
|
+
}
|
|
59
|
+
for (let i = 1; i < curve.length; i++) {
|
|
60
|
+
const [pointUtilization, pointRate] = curve[i];
|
|
61
|
+
if (pointUtilization === currentUtilization) {
|
|
62
|
+
return pointRate;
|
|
63
|
+
}
|
|
64
|
+
if (currentUtilization <= pointUtilization) {
|
|
65
|
+
x0 = curve[i - 1][0];
|
|
66
|
+
y0 = curve[i - 1][1];
|
|
67
|
+
x1 = curve[i][0];
|
|
68
|
+
y1 = curve[i][1];
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (x0 === 0 && y0 === 0 && x1 === 0 && y1 === 0) {
|
|
73
|
+
console.log('All are 0');
|
|
74
|
+
throw 'Invalid borrow rate curve, could not identify the interpolation points.';
|
|
75
|
+
}
|
|
76
|
+
if (x0 >= x1 || y0 > y1) {
|
|
77
|
+
console.log('(x0, y0), (x1, y1)', x0, y0, x1, y1);
|
|
78
|
+
throw 'Invalid borrow rate curve, curve is not uniformly increasing';
|
|
79
|
+
}
|
|
80
|
+
return (0, exports.interpolate)(currentUtilization, x0, x1, y0, y1);
|
|
81
|
+
};
|
|
82
|
+
exports.getBorrowRate = getBorrowRate;
|
|
83
|
+
const parseTokenSymbol = (tokenSymbol) => {
|
|
84
|
+
return String.fromCharCode(...tokenSymbol.filter((x) => x > 0));
|
|
85
|
+
};
|
|
86
|
+
exports.parseTokenSymbol = parseTokenSymbol;
|
|
87
|
+
function sleep(ms) {
|
|
88
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
89
|
+
}
|
|
90
|
+
exports.sleep = sleep;
|
|
91
|
+
function numberToLamportsDecimal(amount, decimals) {
|
|
92
|
+
const factor = Math.pow(10, decimals);
|
|
93
|
+
return new decimal_js_1.default(amount).mul(factor);
|
|
94
|
+
}
|
|
95
|
+
exports.numberToLamportsDecimal = numberToLamportsDecimal;
|
|
96
|
+
function lamportsToNumberDecimal(amount, decimals) {
|
|
97
|
+
const factor = Math.pow(10, decimals);
|
|
98
|
+
return new decimal_js_1.default(amount).div(factor);
|
|
99
|
+
}
|
|
100
|
+
exports.lamportsToNumberDecimal = lamportsToNumberDecimal;
|
|
101
|
+
const isSolMint = (mint) => {
|
|
102
|
+
return lib_1.SOL_MINTS.filter((m) => m.equals(mint)).length > 0;
|
|
103
|
+
};
|
|
104
|
+
exports.isSolMint = isSolMint;
|
|
105
|
+
const valueOrZero = (value) => {
|
|
106
|
+
const zero = new decimal_js_1.default(0);
|
|
107
|
+
if (value.isNaN() || !value.isFinite()) {
|
|
108
|
+
return zero;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
exports.valueOrZero = valueOrZero;
|
|
115
|
+
const isEmptyObject = (obj) => {
|
|
116
|
+
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
117
|
+
};
|
|
118
|
+
exports.isEmptyObject = isEmptyObject;
|
|
119
|
+
const positiveOrZero = (value) => {
|
|
120
|
+
const zero = new decimal_js_1.default(0);
|
|
121
|
+
return decimal_js_1.default.max(value, zero);
|
|
122
|
+
};
|
|
123
|
+
exports.positiveOrZero = positiveOrZero;
|
|
124
|
+
function calculateAPYFromAPR(apr) {
|
|
125
|
+
const apy = Math.pow(new decimal_js_1.default(1).plus(new decimal_js_1.default(apr).dividedBy(utils_1.SLOTS_PER_YEAR)).toNumber(), utils_1.SLOTS_PER_YEAR) - 1;
|
|
126
|
+
return apy;
|
|
127
|
+
}
|
|
128
|
+
exports.calculateAPYFromAPR = calculateAPYFromAPR;
|
|
129
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/classes/utils.ts"],"names":[],"mappings":";;;;;;AAAA,oCAA4D;AAC5D,4DAAiC;AAEjC,gCAAmC;AAkBnC,SAAS,mBAAmB,CAC1B,WAIE,EACF,IAAY;IAEZ,OAAO,WAAW;SACf,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,aAAa,CAAC;SACxC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAA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AC;AAPW,QAAA,WAAW,eAOtB;AAEK,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAE,EAAE;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC;AACrE,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB;AAEK,MAAM,cAAc,GAAG,CAAC,KAAc,EAAW,EAAE;IACxD,MAAM,IAAI,GAAG,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,oBAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,MAAM,GAAG,GAAG,SAAA,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,sBAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAI,sBAAc,CAAA,GAAG,CAAC,CAAC;IAC7G,OAAO,GAAG,CAAC;AACb,CAAC;AAHD,kDAGC","sourcesContent":["import { SLOTS_PER_SECOND, SLOTS_PER_YEAR } from '../utils';\nimport Decimal from 'decimal.js';\nimport { PublicKey } from '@solana/web3.js';\nimport { SOL_MINTS } from '../lib';\n\ntype ObligationFarmScoreType = {\n obligationId: string;\n balance: string;\n debt: string;\n score: string;\n lastSlot: number;\n tokenMint: string;\n side: 'supply' | 'borrow';\n};\n\ntype RewardRate = {\n beginningSlot: number;\n rewardRate: string;\n name?: string;\n};\n\nfunction getLatestRewardRate(\n rewardRates: Array<{\n beginningSlot: number;\n rewardRate: string;\n name?: string;\n }>,\n slot: number\n) {\n return rewardRates\n .filter((rr) => slot >= rr.beginningSlot)\n .reduce((v1, v2) => (v1.beginningSlot > v2.beginningSlot ? v1 : v2), {\n beginningSlot: 0,\n rewardRate: '0',\n });\n}\n\nexport const calculateNewScore = (\n rewardStat: {\n lastSlot: number;\n rewardRates: Array<RewardRate>;\n rewardsPerShare: string;\n totalBalance: string;\n },\n pool: ObligationFarmScoreType,\n rewardRate: string,\n endSlot: number,\n startSlot: number\n) => {\n const { balance, debt, score } = pool;\n const { rewardsPerShare, totalBalance } = rewardStat;\n\n const oldDebt = new Decimal(debt);\n const oldScore = new Decimal(score);\n const oldRewardsPerShare = new Decimal(rewardsPerShare);\n const oldBalance = new Decimal(balance);\n const totalBalanceVal = new Decimal(totalBalance);\n\n const newRewardsPerShare = !totalBalanceVal.isZero()\n ? oldRewardsPerShare.plus(\n new Decimal(endSlot)\n .minus(new Decimal(startSlot.toString()))\n .times(new Decimal(rewardRate))\n .div(totalBalanceVal)\n .div(new Decimal(SLOTS_PER_YEAR))\n )\n : new Decimal(0);\n\n return oldScore.plus(newRewardsPerShare.times(oldBalance).minus(oldDebt));\n};\n\nexport const estimateCurrentScore = (\n rewardStat: {\n lastSlot: number;\n rewardRates: Array<RewardRate>;\n rewardsPerShare: string;\n totalBalance: string;\n },\n rewardScore: ObligationFarmScoreType,\n mostRecentSlot: number,\n mostRecentSlotTime: number\n) => {\n const { lastSlot, rewardRates } = rewardStat;\n\n const estimatedCurrentSlot = mostRecentSlot + SLOTS_PER_SECOND * (Date.now() / 1000 - mostRecentSlotTime);\n\n const { rewardRate } = getLatestRewardRate(rewardRates, estimatedCurrentSlot);\n\n const currentScore = calculateNewScore(rewardStat, rewardScore, rewardRate, estimatedCurrentSlot, lastSlot);\n\n return currentScore;\n};\n\nexport const interpolate = (x: number, x0: number, x1: number, y0: number, y1: number) => {\n if (x > x1) {\n throw 'Cannot do extrapolation';\n }\n\n return y0 + ((x - x0) * (y1 - y0)) / (x1 - x0);\n};\n\nexport const getBorrowRate = (currentUtilization: number, curve: [number, number][]): number => {\n let [x0, y0, x1, y1] = [0, 0, 0, 0];\n\n if (curve.length < 2) {\n throw 'Invalid borrow rate curve, only one point';\n }\n\n if (currentUtilization > 1) {\n currentUtilization = 1;\n }\n\n for (let i = 1; i < curve.length; i++) {\n const [pointUtilization, pointRate] = curve[i];\n if (pointUtilization === currentUtilization) {\n return pointRate;\n }\n\n if (currentUtilization <= pointUtilization) {\n x0 = curve[i - 1][0];\n y0 = curve[i - 1][1];\n x1 = curve[i][0];\n y1 = curve[i][1];\n break;\n }\n }\n\n if (x0 === 0 && y0 === 0 && x1 === 0 && y1 === 0) {\n console.log('All are 0');\n throw 'Invalid borrow rate curve, could not identify the interpolation points.';\n }\n\n if (x0 >= x1 || y0 > y1) {\n console.log('(x0, y0), (x1, y1)', x0, y0, x1, y1);\n throw 'Invalid borrow rate curve, curve is not uniformly increasing';\n }\n\n return interpolate(currentUtilization, x0, x1, y0, y1);\n};\n\nexport const parseTokenSymbol = (tokenSymbol: number[]): string => {\n return String.fromCharCode(...tokenSymbol.filter((x) => x > 0));\n};\n\nexport function sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function numberToLamportsDecimal(amount: Decimal.Value, decimals: number): Decimal {\n const factor = 10 ** decimals;\n return new Decimal(amount).mul(factor);\n}\n\nexport function lamportsToNumberDecimal(amount: Decimal.Value, decimals: number): Decimal {\n const factor = 10 ** decimals;\n return new Decimal(amount).div(factor);\n}\n\nexport const isSolMint = (mint: PublicKey): boolean => {\n return SOL_MINTS.filter((m) => m.equals(mint)).length > 0;\n};\n\nexport const valueOrZero = (value: Decimal): Decimal => {\n const zero = new Decimal(0);\n if (value.isNaN() || !value.isFinite()) {\n return zero;\n } else {\n return value;\n }\n};\n\nexport const isEmptyObject = (obj: any) => {\n return Object.keys(obj).length === 0 && obj.constructor === Object;\n};\n\nexport const positiveOrZero = (value: Decimal): Decimal => {\n const zero = new Decimal(0);\n return Decimal.max(value, zero);\n};\n\nexport function calculateAPYFromAPR(apr: number) {\n const apy = new Decimal(1).plus(new Decimal(apr).dividedBy(SLOTS_PER_YEAR)).toNumber() ** SLOTS_PER_YEAR - 1;\n return apy;\n}\n"]}
|