@kamino-finance/klend-sdk 3.2.26 → 4.0.1

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