@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.
Files changed (369) hide show
  1. package/README.md +85 -0
  2. package/dist/classes/action.d.ts +154 -0
  3. package/dist/classes/action.js +1505 -0
  4. package/dist/classes/action.js.map +1 -0
  5. package/dist/classes/curve.d.ts +15 -0
  6. package/dist/classes/curve.js +32 -0
  7. package/dist/classes/curve.js.map +1 -0
  8. package/dist/classes/fraction.d.ts +23 -0
  9. package/dist/classes/fraction.js +60 -0
  10. package/dist/classes/fraction.js.map +1 -0
  11. package/dist/classes/index.d.ts +8 -0
  12. package/dist/classes/index.js +25 -0
  13. package/dist/classes/index.js.map +1 -0
  14. package/dist/classes/jupiterPerps.d.ts +2 -0
  15. package/dist/classes/jupiterPerps.js +25 -0
  16. package/dist/classes/jupiterPerps.js.map +1 -0
  17. package/dist/classes/market.d.ts +140 -0
  18. package/dist/classes/market.js +901 -0
  19. package/dist/classes/market.js.map +1 -0
  20. package/dist/classes/obligation.d.ts +170 -0
  21. package/dist/classes/obligation.js +610 -0
  22. package/dist/classes/obligation.js.map +1 -0
  23. package/dist/classes/reserve.d.ts +161 -0
  24. package/dist/classes/reserve.js +474 -0
  25. package/dist/classes/reserve.js.map +1 -0
  26. package/dist/classes/shared.d.ts +41 -0
  27. package/dist/classes/shared.js +10 -0
  28. package/dist/classes/shared.js.map +1 -0
  29. package/dist/classes/utils.d.ts +40 -0
  30. package/dist/classes/utils.js +129 -0
  31. package/dist/classes/utils.js.map +1 -0
  32. package/dist/idl.json +4102 -0
  33. package/dist/idl_codegen/accounts/LendingMarket.d.ts +153 -0
  34. package/dist/idl_codegen/accounts/LendingMarket.js +204 -0
  35. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -0
  36. package/dist/idl_codegen/accounts/Obligation.d.ts +139 -0
  37. package/dist/idl_codegen/accounts/Obligation.js +193 -0
  38. package/dist/idl_codegen/accounts/Obligation.js.map +1 -0
  39. package/dist/idl_codegen/accounts/ReferrerState.d.ts +22 -0
  40. package/dist/idl_codegen/accounts/ReferrerState.js +101 -0
  41. package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -0
  42. package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +51 -0
  43. package/dist/idl_codegen/accounts/ReferrerTokenState.js +126 -0
  44. package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -0
  45. package/dist/idl_codegen/accounts/Reserve.d.ts +72 -0
  46. package/dist/idl_codegen/accounts/Reserve.js +156 -0
  47. package/dist/idl_codegen/accounts/Reserve.js.map +1 -0
  48. package/dist/idl_codegen/accounts/ShortUrl.d.ts +22 -0
  49. package/dist/idl_codegen/accounts/ShortUrl.js +101 -0
  50. package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -0
  51. package/dist/idl_codegen/accounts/UserMetadata.d.ts +48 -0
  52. package/dist/idl_codegen/accounts/UserMetadata.js +126 -0
  53. package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -0
  54. package/dist/idl_codegen/accounts/UserState.d.ts +143 -0
  55. package/dist/idl_codegen/accounts/UserState.js +180 -0
  56. package/dist/idl_codegen/accounts/UserState.js.map +1 -0
  57. package/dist/idl_codegen/accounts/index.d.ts +16 -0
  58. package/dist/idl_codegen/accounts/index.js +20 -0
  59. package/dist/idl_codegen/accounts/index.js.map +1 -0
  60. package/dist/idl_codegen/errors/anchor.d.ts +434 -0
  61. package/dist/idl_codegen/errors/anchor.js +713 -0
  62. package/dist/idl_codegen/errors/anchor.js.map +1 -0
  63. package/dist/idl_codegen/errors/custom.d.ts +730 -0
  64. package/dist/idl_codegen/errors/custom.js +1194 -0
  65. package/dist/idl_codegen/errors/custom.js.map +1 -0
  66. package/dist/idl_codegen/errors/index.d.ts +5 -0
  67. package/dist/idl_codegen/errors/index.js +71 -0
  68. package/dist/idl_codegen/errors/index.js.map +1 -0
  69. package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +20 -0
  70. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +75 -0
  71. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -0
  72. package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +9 -0
  73. package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js +20 -0
  74. package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -0
  75. package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +17 -0
  76. package/dist/idl_codegen/instructions/depositObligationCollateral.js +64 -0
  77. package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -0
  78. package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +19 -0
  79. package/dist/idl_codegen/instructions/depositReserveLiquidity.js +74 -0
  80. package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -0
  81. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +21 -0
  82. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +80 -0
  83. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -0
  84. package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +20 -0
  85. package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js +75 -0
  86. package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -0
  87. package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +21 -0
  88. package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js +75 -0
  89. package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -0
  90. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +18 -0
  91. package/dist/idl_codegen/instructions/idlMissingTypes.js +62 -0
  92. package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -0
  93. package/dist/idl_codegen/instructions/index.d.ts +66 -0
  94. package/dist/idl_codegen/instructions/index.js +70 -0
  95. package/dist/idl_codegen/instructions/index.js.map +1 -0
  96. package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +19 -0
  97. package/dist/idl_codegen/instructions/initFarmsForReserve.js +63 -0
  98. package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -0
  99. package/dist/idl_codegen/instructions/initLendingMarket.d.ts +13 -0
  100. package/dist/idl_codegen/instructions/initLendingMarket.js +55 -0
  101. package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -0
  102. package/dist/idl_codegen/instructions/initObligation.d.ts +19 -0
  103. package/dist/idl_codegen/instructions/initObligation.js +55 -0
  104. package/dist/idl_codegen/instructions/initObligation.js.map +1 -0
  105. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +20 -0
  106. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +60 -0
  107. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -0
  108. package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +14 -0
  109. package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js +54 -0
  110. package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -0
  111. package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +14 -0
  112. package/dist/idl_codegen/instructions/initReferrerTokenState.js +50 -0
  113. package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -0
  114. package/dist/idl_codegen/instructions/initReserve.d.ts +16 -0
  115. package/dist/idl_codegen/instructions/initReserve.js +47 -0
  116. package/dist/idl_codegen/instructions/initReserve.js.map +1 -0
  117. package/dist/idl_codegen/instructions/initUserMetadata.d.ts +14 -0
  118. package/dist/idl_codegen/instructions/initUserMetadata.js +54 -0
  119. package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -0
  120. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +27 -0
  121. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +102 -0
  122. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -0
  123. package/dist/idl_codegen/instructions/redeemFees.d.ts +10 -0
  124. package/dist/idl_codegen/instructions/redeemFees.js +33 -0
  125. package/dist/idl_codegen/instructions/redeemFees.js.map +1 -0
  126. package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +19 -0
  127. package/dist/idl_codegen/instructions/redeemReserveCollateral.js +78 -0
  128. package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -0
  129. package/dist/idl_codegen/instructions/refreshObligation.d.ts +6 -0
  130. package/dist/idl_codegen/instructions/refreshObligation.js +17 -0
  131. package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -0
  132. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +19 -0
  133. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +63 -0
  134. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -0
  135. package/dist/idl_codegen/instructions/refreshReserve.d.ts +10 -0
  136. package/dist/idl_codegen/instructions/refreshReserve.js +29 -0
  137. package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -0
  138. package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +17 -0
  139. package/dist/idl_codegen/instructions/repayObligationLiquidity.js +60 -0
  140. package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -0
  141. package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +11 -0
  142. package/dist/idl_codegen/instructions/requestElevationGroup.js +47 -0
  143. package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -0
  144. package/dist/idl_codegen/instructions/socializeLoss.d.ts +14 -0
  145. package/dist/idl_codegen/instructions/socializeLoss.js +53 -0
  146. package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -0
  147. package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +13 -0
  148. package/dist/idl_codegen/instructions/updateEntireReserveConfig.js +51 -0
  149. package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -0
  150. package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +12 -0
  151. package/dist/idl_codegen/instructions/updateLendingMarket.js +50 -0
  152. package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -0
  153. package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +6 -0
  154. package/dist/idl_codegen/instructions/updateLendingMarketOwner.js +21 -0
  155. package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -0
  156. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +13 -0
  157. package/dist/idl_codegen/instructions/updateReserveConfig.js +51 -0
  158. package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -0
  159. package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +13 -0
  160. package/dist/idl_codegen/instructions/updateSingleReserveConfig.js +51 -0
  161. package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -0
  162. package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +18 -0
  163. package/dist/idl_codegen/instructions/withdrawObligationCollateral.js +69 -0
  164. package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -0
  165. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +21 -0
  166. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +84 -0
  167. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -0
  168. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +16 -0
  169. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +59 -0
  170. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -0
  171. package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +12 -0
  172. package/dist/idl_codegen/instructions/withdrawReferrerFees.js +35 -0
  173. package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -0
  174. package/dist/idl_codegen/programId.d.ts +4 -0
  175. package/dist/idl_codegen/programId.js +13 -0
  176. package/dist/idl_codegen/programId.js.map +1 -0
  177. package/dist/idl_codegen/types/AssetTier.d.ts +44 -0
  178. package/dist/idl_codegen/types/AssetTier.js +128 -0
  179. package/dist/idl_codegen/types/AssetTier.js.map +1 -0
  180. package/dist/idl_codegen/types/BigFractionBytes.d.ts +27 -0
  181. package/dist/idl_codegen/types/BigFractionBytes.js +73 -0
  182. package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -0
  183. package/dist/idl_codegen/types/BorrowRateCurve.d.ts +27 -0
  184. package/dist/idl_codegen/types/BorrowRateCurve.js +62 -0
  185. package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -0
  186. package/dist/idl_codegen/types/CurvePoint.d.ts +26 -0
  187. package/dist/idl_codegen/types/CurvePoint.js +66 -0
  188. package/dist/idl_codegen/types/CurvePoint.js.map +1 -0
  189. package/dist/idl_codegen/types/ElevationGroup.d.ts +52 -0
  190. package/dist/idl_codegen/types/ElevationGroup.js +103 -0
  191. package/dist/idl_codegen/types/ElevationGroup.js.map +1 -0
  192. package/dist/idl_codegen/types/FeeCalculation.d.ts +31 -0
  193. package/dist/idl_codegen/types/FeeCalculation.js +102 -0
  194. package/dist/idl_codegen/types/FeeCalculation.js.map +1 -0
  195. package/dist/idl_codegen/types/InitObligationArgs.d.ts +26 -0
  196. package/dist/idl_codegen/types/InitObligationArgs.js +66 -0
  197. package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -0
  198. package/dist/idl_codegen/types/LastUpdate.d.ts +47 -0
  199. package/dist/idl_codegen/types/LastUpdate.js +86 -0
  200. package/dist/idl_codegen/types/LastUpdate.js.map +1 -0
  201. package/dist/idl_codegen/types/ObligationCollateral.d.ts +48 -0
  202. package/dist/idl_codegen/types/ObligationCollateral.js +87 -0
  203. package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -0
  204. package/dist/idl_codegen/types/ObligationLiquidity.d.ts +75 -0
  205. package/dist/idl_codegen/types/ObligationLiquidity.js +107 -0
  206. package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -0
  207. package/dist/idl_codegen/types/PriceHeuristic.d.ts +41 -0
  208. package/dist/idl_codegen/types/PriceHeuristic.js +75 -0
  209. package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -0
  210. package/dist/idl_codegen/types/PythConfiguration.d.ts +25 -0
  211. package/dist/idl_codegen/types/PythConfiguration.js +62 -0
  212. package/dist/idl_codegen/types/PythConfiguration.js.map +1 -0
  213. package/dist/idl_codegen/types/ReserveCollateral.d.ts +53 -0
  214. package/dist/idl_codegen/types/ReserveCollateral.js +93 -0
  215. package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -0
  216. package/dist/idl_codegen/types/ReserveConfig.d.ts +304 -0
  217. package/dist/idl_codegen/types/ReserveConfig.js +209 -0
  218. package/dist/idl_codegen/types/ReserveConfig.js.map +1 -0
  219. package/dist/idl_codegen/types/ReserveFarmKind.d.ts +31 -0
  220. package/dist/idl_codegen/types/ReserveFarmKind.js +102 -0
  221. package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -0
  222. package/dist/idl_codegen/types/ReserveFees.d.ts +78 -0
  223. package/dist/idl_codegen/types/ReserveFees.js +86 -0
  224. package/dist/idl_codegen/types/ReserveFees.js.map +1 -0
  225. package/dist/idl_codegen/types/ReserveLiquidity.d.ts +173 -0
  226. package/dist/idl_codegen/types/ReserveLiquidity.js +166 -0
  227. package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -0
  228. package/dist/idl_codegen/types/ReserveStatus.d.ts +44 -0
  229. package/dist/idl_codegen/types/ReserveStatus.js +128 -0
  230. package/dist/idl_codegen/types/ReserveStatus.js.map +1 -0
  231. package/dist/idl_codegen/types/ScopeConfiguration.d.ts +41 -0
  232. package/dist/idl_codegen/types/ScopeConfiguration.js +76 -0
  233. package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -0
  234. package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +30 -0
  235. package/dist/idl_codegen/types/SwitchboardConfiguration.js +67 -0
  236. package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -0
  237. package/dist/idl_codegen/types/TokenInfo.d.ts +109 -0
  238. package/dist/idl_codegen/types/TokenInfo.js +116 -0
  239. package/dist/idl_codegen/types/TokenInfo.js.map +1 -0
  240. package/dist/idl_codegen/types/UpdateConfigMode.d.ts +538 -0
  241. package/dist/idl_codegen/types/UpdateConfigMode.js +1116 -0
  242. package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -0
  243. package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +155 -0
  244. package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +273 -0
  245. package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -0
  246. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +200 -0
  247. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +440 -0
  248. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -0
  249. package/dist/idl_codegen/types/WithdrawalCaps.d.ts +38 -0
  250. package/dist/idl_codegen/types/WithdrawalCaps.js +86 -0
  251. package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -0
  252. package/dist/idl_codegen/types/index.d.ts +65 -0
  253. package/dist/idl_codegen/types/index.js +77 -0
  254. package/dist/idl_codegen/types/index.js.map +1 -0
  255. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +53 -0
  256. package/dist/idl_codegen/zero_padding/ObligationZP.js +140 -0
  257. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -0
  258. package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
  259. package/dist/idl_codegen/zero_padding/index.js +6 -0
  260. package/dist/idl_codegen/zero_padding/index.js.map +1 -0
  261. package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +48 -0
  262. package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +144 -0
  263. package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -0
  264. package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +2 -0
  265. package/dist/idl_codegen_jupiter_perps/accounts/index.js +6 -0
  266. package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -0
  267. package/dist/idl_codegen_jupiter_perps/programId.d.ts +3 -0
  268. package/dist/idl_codegen_jupiter_perps/programId.js +9 -0
  269. package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -0
  270. package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +62 -0
  271. package/dist/idl_codegen_jupiter_perps/types/Fees.js +115 -0
  272. package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -0
  273. package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +32 -0
  274. package/dist/idl_codegen_jupiter_perps/types/Limit.js +75 -0
  275. package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -0
  276. package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +32 -0
  277. package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +75 -0
  278. package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -0
  279. package/dist/idl_codegen_jupiter_perps/types/index.d.ts +6 -0
  280. package/dist/idl_codegen_jupiter_perps/types/index.js +10 -0
  281. package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -0
  282. package/dist/index.d.ts +1 -0
  283. package/dist/index.js +18 -0
  284. package/dist/index.js.map +1 -0
  285. package/dist/lending_operations/index.d.ts +2 -0
  286. package/dist/lending_operations/index.js +19 -0
  287. package/dist/lending_operations/index.js.map +1 -0
  288. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +5 -0
  289. package/dist/lending_operations/repay_with_collateral_calcs.js +26 -0
  290. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -0
  291. package/dist/lending_operations/repay_with_collateral_operations.d.ts +47 -0
  292. package/dist/lending_operations/repay_with_collateral_operations.js +163 -0
  293. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -0
  294. package/dist/leverage/calcs.d.ts +132 -0
  295. package/dist/leverage/calcs.js +291 -0
  296. package/dist/leverage/calcs.js.map +1 -0
  297. package/dist/leverage/index.d.ts +4 -0
  298. package/dist/leverage/index.js +21 -0
  299. package/dist/leverage/index.js.map +1 -0
  300. package/dist/leverage/instructions.d.ts +43 -0
  301. package/dist/leverage/instructions.js +103 -0
  302. package/dist/leverage/instructions.js.map +1 -0
  303. package/dist/leverage/operations.d.ts +231 -0
  304. package/dist/leverage/operations.js +1058 -0
  305. package/dist/leverage/operations.js.map +1 -0
  306. package/dist/leverage/utils.d.ts +22 -0
  307. package/dist/leverage/utils.js +144 -0
  308. package/dist/leverage/utils.js.map +1 -0
  309. package/dist/lib.d.ts +9 -0
  310. package/dist/lib.js +26 -0
  311. package/dist/lib.js.map +1 -0
  312. package/dist/referrals/index.d.ts +2 -0
  313. package/dist/referrals/index.js +19 -0
  314. package/dist/referrals/index.js.map +1 -0
  315. package/dist/referrals/instructions.d.ts +16 -0
  316. package/dist/referrals/instructions.js +76 -0
  317. package/dist/referrals/instructions.js.map +1 -0
  318. package/dist/referrals/operations.d.ts +97 -0
  319. package/dist/referrals/operations.js +258 -0
  320. package/dist/referrals/operations.js.map +1 -0
  321. package/dist/utils/ObligationType.d.ts +49 -0
  322. package/dist/utils/ObligationType.js +129 -0
  323. package/dist/utils/ObligationType.js.map +1 -0
  324. package/dist/utils/api.d.ts +6 -0
  325. package/dist/utils/api.js +61 -0
  326. package/dist/utils/api.js.map +1 -0
  327. package/dist/utils/ata.d.ts +25 -0
  328. package/dist/utils/ata.js +155 -0
  329. package/dist/utils/ata.js.map +1 -0
  330. package/dist/utils/constants.d.ts +48 -0
  331. package/dist/utils/constants.js +75 -0
  332. package/dist/utils/constants.js.map +1 -0
  333. package/dist/utils/idl.d.ts +2 -0
  334. package/dist/utils/idl.js +9 -0
  335. package/dist/utils/idl.js.map +1 -0
  336. package/dist/utils/index.d.ts +14 -0
  337. package/dist/utils/index.js +31 -0
  338. package/dist/utils/index.js.map +1 -0
  339. package/dist/utils/instruction.d.ts +22 -0
  340. package/dist/utils/instruction.js +202 -0
  341. package/dist/utils/instruction.js.map +1 -0
  342. package/dist/utils/kamino.d.ts +3 -0
  343. package/dist/utils/kamino.js +45 -0
  344. package/dist/utils/kamino.js.map +1 -0
  345. package/dist/utils/layout.d.ts +13 -0
  346. package/dist/utils/layout.js +123 -0
  347. package/dist/utils/layout.js.map +1 -0
  348. package/dist/utils/lookupTable.d.ts +5 -0
  349. package/dist/utils/lookupTable.js +57 -0
  350. package/dist/utils/lookupTable.js.map +1 -0
  351. package/dist/utils/oracle.d.ts +51 -0
  352. package/dist/utils/oracle.js +295 -0
  353. package/dist/utils/oracle.js.map +1 -0
  354. package/dist/utils/pubkey.d.ts +74 -0
  355. package/dist/utils/pubkey.js +229 -0
  356. package/dist/utils/pubkey.js.map +1 -0
  357. package/dist/utils/seeds.d.ts +122 -0
  358. package/dist/utils/seeds.js +153 -0
  359. package/dist/utils/seeds.js.map +1 -0
  360. package/dist/utils/slots.d.ts +18 -0
  361. package/dist/utils/slots.js +32 -0
  362. package/dist/utils/slots.js.map +1 -0
  363. package/dist/utils/syncNative.d.ts +10 -0
  364. package/dist/utils/syncNative.js +46 -0
  365. package/dist/utils/syncNative.js.map +1 -0
  366. package/dist/utils/userMetadata.d.ts +15 -0
  367. package/dist/utils/userMetadata.js +259 -0
  368. package/dist/utils/userMetadata.js.map +1 -0
  369. 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,CAAC,CAAC,EAAE,CAAC,EAAE;QACnE,aAAa,EAAE,CAA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AAG,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"]}