@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
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -21,21 +12,54 @@ const instructions_1 = require("../idl_codegen/instructions");
21
12
  const utils_1 = require("../utils");
22
13
  const obligation_1 = require("./obligation");
23
14
  const types_1 = require("../idl_codegen/types");
24
- const farms_sdk_1 = require("@hubbleprotocol/farms-sdk");
15
+ const farms_sdk_1 = require("@kamino-finance/farms-sdk");
25
16
  const ObligationType_1 = require("../utils/ObligationType");
26
17
  const lib_1 = require("../lib");
27
- const scope_sdk_1 = require("@hubbleprotocol/scope-sdk");
18
+ const scope_sdk_1 = require("@kamino-finance/scope-sdk");
28
19
  exports.POSITION_LIMIT = 10;
29
20
  exports.BORROWS_LIMIT = 5;
30
21
  exports.DEPOSITS_LIMIT = 8;
31
22
  const SOL_PADDING_FOR_INTEREST = new bn_js_1.default('1000000');
32
23
  class KaminoAction {
24
+ kaminoMarket;
25
+ reserve;
26
+ outflowReserve;
27
+ owner;
28
+ payer;
29
+ obligation = null;
30
+ referrer;
31
+ userTokenAccountAddress;
32
+ userCollateralAccountAddress;
33
+ additionalTokenAccountAddress;
34
+ /**
35
+ * Null unless the obligation is not passed
36
+ */
37
+ obligationType = null;
38
+ mint;
39
+ secondaryMint;
40
+ positions;
41
+ amount;
42
+ outflowAmount;
43
+ setupIxs;
44
+ setupIxsLabels;
45
+ inBetweenIxs;
46
+ inBetweenIxsLabels;
47
+ lendingIxs;
48
+ lendingIxsLabels;
49
+ cleanupIxs;
50
+ cleanupIxsLabels;
51
+ preTxnIxs;
52
+ preTxnIxsLabels;
53
+ postTxnIxs;
54
+ postTxnIxsLabels;
55
+ refreshFarmsCleanupTxnIxs;
56
+ refreshFarmsCleanupTxnIxsLabels;
57
+ depositReserves;
58
+ borrowReserves;
59
+ preLoadedDepositReservesSameTx;
60
+ preLoadedBorrowReservesSameTx;
61
+ currentSlot;
33
62
  constructor(kaminoMarket, owner, obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, positions, amount, depositReserves, borrowReserves, reserveState, currentSlot, secondaryMint, additionalTokenAccountAddress, outflowReserveState, outflowAmount, referrer, payer) {
34
- this.obligation = null;
35
- /**
36
- * Null unless the obligation is not passed
37
- */
38
- this.obligationType = null;
39
63
  if (obligation instanceof obligation_1.KaminoObligation) {
40
64
  this.obligation = obligation;
41
65
  }
@@ -44,7 +68,7 @@ class KaminoAction {
44
68
  }
45
69
  this.kaminoMarket = kaminoMarket;
46
70
  this.owner = owner;
47
- this.payer = payer !== null && payer !== void 0 ? payer : owner;
71
+ this.payer = payer ?? owner;
48
72
  this.amount = new bn_js_1.default(amount);
49
73
  this.mint = mint;
50
74
  this.positions = positions;
@@ -76,123 +100,113 @@ class KaminoAction {
76
100
  this.referrer = referrer ? referrer : web3_js_1.PublicKey.default;
77
101
  this.currentSlot = currentSlot;
78
102
  }
79
- static initialize(action_1, amount_1, mint_1, owner_1, kaminoMarket_1, obligation_2) {
80
- return __awaiter(this, arguments, void 0, function* (action, amount, mint, owner, kaminoMarket, obligation, referrer = web3_js_1.PublicKey.default, currentSlot = 0, payer) {
81
- const reserve = kaminoMarket.getReserveByMint(mint);
82
- if (reserve === undefined) {
83
- throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
84
- }
85
- const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer !== null && payer !== void 0 ? payer : owner, reserve.state);
86
- const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
87
- const referrerKey = yield this.getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer);
88
- return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, undefined, referrerKey, payer);
89
- });
103
+ static async initialize(action, amount, mint, owner, kaminoMarket, obligation, referrer = web3_js_1.PublicKey.default, currentSlot = 0, payer) {
104
+ const reserve = kaminoMarket.getReserveByMint(mint);
105
+ if (reserve === undefined) {
106
+ throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
107
+ }
108
+ const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer ?? owner, reserve.state);
109
+ const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
110
+ const referrerKey = await this.getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer);
111
+ return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, undefined, referrerKey, payer);
90
112
  }
91
113
  static getUserAccountAddresses(owner, reserve) {
92
114
  const userTokenAccountAddress = (0, utils_1.getAssociatedTokenAddress)(reserve.liquidity.mintPubkey, owner, true, reserve.liquidity.tokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
93
115
  const userCollateralAccountAddress = (0, utils_1.getAssociatedTokenAddress)(reserve.collateral.mintPubkey, owner, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
94
116
  return { userTokenAccountAddress, userCollateralAccountAddress };
95
117
  }
96
- static loadObligation(action, kaminoMarket, owner, reserve, obligation, outflowReserve) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- let kaminoObligation;
99
- const depositReserves = [];
100
- const borrowReserves = [];
101
- if (obligation instanceof obligation_1.KaminoObligation) {
102
- kaminoObligation = obligation;
103
- }
104
- else {
105
- const obligationAddress = obligation.toPda(kaminoMarket.getAddress(), owner);
106
- kaminoObligation = yield obligation_1.KaminoObligation.load(kaminoMarket, obligationAddress);
107
- }
108
- if (kaminoObligation !== null) {
109
- depositReserves.push(...[...kaminoObligation.deposits.keys()]);
110
- borrowReserves.push(...[...kaminoObligation.borrows.keys()]);
111
- }
112
- if (!outflowReserve && action === 'depositAndBorrow') {
113
- throw new Error(`Outflow reserve has not been set for depositAndBorrow`);
114
- }
115
- // Union of addresses
116
- const distinctReserveCount = new utils_1.PublicKeySet([
117
- ...borrowReserves.map((e) => e),
118
- ...(action === 'borrow' ? [reserve] : []),
119
- ...(action === 'depositAndBorrow' ? [reserve] : []),
120
- ]).toArray().length +
121
- new utils_1.PublicKeySet([
122
- ...depositReserves.map((e) => e),
123
- ...(action === 'deposit' ? [reserve] : []),
124
- ...(action === 'depositAndBorrow' ? [outflowReserve] : []),
125
- ]).toArray().length;
126
- if (distinctReserveCount > exports.POSITION_LIMIT) {
127
- throw Error(`Obligation already has max number of positions: ${exports.POSITION_LIMIT}`);
128
- }
129
- return {
130
- kaminoObligation,
131
- depositReserves,
132
- borrowReserves,
133
- distinctReserveCount,
134
- };
135
- });
118
+ static async loadObligation(action, kaminoMarket, owner, reserve, obligation, outflowReserve) {
119
+ let kaminoObligation;
120
+ const depositReserves = [];
121
+ const borrowReserves = [];
122
+ if (obligation instanceof obligation_1.KaminoObligation) {
123
+ kaminoObligation = obligation;
124
+ }
125
+ else {
126
+ const obligationAddress = obligation.toPda(kaminoMarket.getAddress(), owner);
127
+ kaminoObligation = await obligation_1.KaminoObligation.load(kaminoMarket, obligationAddress);
128
+ }
129
+ if (kaminoObligation !== null) {
130
+ depositReserves.push(...[...kaminoObligation.deposits.keys()]);
131
+ borrowReserves.push(...[...kaminoObligation.borrows.keys()]);
132
+ }
133
+ if (!outflowReserve && action === 'depositAndBorrow') {
134
+ throw new Error(`Outflow reserve has not been set for depositAndBorrow`);
135
+ }
136
+ // Union of addresses
137
+ const distinctReserveCount = new utils_1.PublicKeySet([
138
+ ...borrowReserves.map((e) => e),
139
+ ...(action === 'borrow' ? [reserve] : []),
140
+ ...(action === 'depositAndBorrow' ? [reserve] : []),
141
+ ]).toArray().length +
142
+ new utils_1.PublicKeySet([
143
+ ...depositReserves.map((e) => e),
144
+ ...(action === 'deposit' ? [reserve] : []),
145
+ ...(action === 'depositAndBorrow' ? [outflowReserve] : []),
146
+ ]).toArray().length;
147
+ if (distinctReserveCount > exports.POSITION_LIMIT) {
148
+ throw Error(`Obligation already has max number of positions: ${exports.POSITION_LIMIT}`);
149
+ }
150
+ return {
151
+ kaminoObligation,
152
+ depositReserves,
153
+ borrowReserves,
154
+ distinctReserveCount,
155
+ };
136
156
  }
137
- static buildRefreshObligationTxns(kaminoMarket_1, payer_1, obligation_2) {
138
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
139
- currentSlot = 0) {
140
- // placeholder for action initialization
141
- const firstReserve = obligation.state.deposits[0].depositReserve;
142
- const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
143
- if (!firstKaminoReserve) {
144
- throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
145
- }
146
- const axn = yield KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
147
- if (extraComputeBudget > 0) {
148
- axn.addComputeBudgetIxn(extraComputeBudget);
149
- }
150
- axn.addRefreshObligation(payer);
151
- return axn;
152
- });
157
+ static async buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
158
+ currentSlot = 0) {
159
+ // placeholder for action initialization
160
+ const firstReserve = obligation.state.deposits[0].depositReserve;
161
+ const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
162
+ if (!firstKaminoReserve) {
163
+ throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
164
+ }
165
+ const axn = await KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve?.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
166
+ if (extraComputeBudget > 0) {
167
+ axn.addComputeBudgetIxn(extraComputeBudget);
168
+ }
169
+ axn.addRefreshObligation(payer);
170
+ return axn;
153
171
  }
154
- static buildRequestElevationGroupTxns(kaminoMarket_1, payer_1, obligation_2, elevationGroup_1) {
155
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1000000, // if > 0 then adds the ixn
156
- currentSlot = 0) {
157
- const firstReserve = obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
158
- const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
159
- if (!firstKaminoReserve) {
160
- throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
161
- }
162
- const axn = yield KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
163
- if (extraComputeBudget > 0) {
164
- axn.addComputeBudgetIxn(extraComputeBudget);
165
- }
166
- axn.addRefreshObligation(payer);
167
- axn.addRequestElevationIx(elevationGroup, 'setup');
168
- return axn;
169
- });
172
+ static async buildRequestElevationGroupTxns(kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
173
+ currentSlot = 0) {
174
+ const firstReserve = obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
175
+ const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
176
+ if (!firstKaminoReserve) {
177
+ throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
178
+ }
179
+ const axn = await KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve?.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
180
+ if (extraComputeBudget > 0) {
181
+ axn.addComputeBudgetIxn(extraComputeBudget);
182
+ }
183
+ axn.addRefreshObligation(payer);
184
+ axn.addRequestElevationIx(elevationGroup, 'setup');
185
+ return axn;
170
186
  }
171
- static buildDepositTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
172
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
173
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
174
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
175
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
176
- ) {
177
- const axn = yield KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
178
- const addInitObligationForFarm = true;
179
- if (extraComputeBudget > 0) {
180
- axn.addComputeBudgetIxn(extraComputeBudget);
181
- }
182
- const allReserves = new utils_1.PublicKeySet([
183
- ...axn.depositReserves,
184
- ...axn.borrowReserves,
185
- axn.reserve.address,
186
- ]).toArray();
187
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
188
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
189
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
190
- }
191
- yield axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
192
- axn.addDepositIx();
193
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
194
- return axn;
195
- });
187
+ static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
188
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
189
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
190
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
191
+ ) {
192
+ const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
193
+ const addInitObligationForFarm = true;
194
+ if (extraComputeBudget > 0) {
195
+ axn.addComputeBudgetIxn(extraComputeBudget);
196
+ }
197
+ const allReserves = new utils_1.PublicKeySet([
198
+ ...axn.depositReserves,
199
+ ...axn.borrowReserves,
200
+ axn.reserve.address,
201
+ ]).toArray();
202
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
203
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
204
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
205
+ }
206
+ await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
207
+ axn.addDepositIx();
208
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
209
+ return axn;
196
210
  }
197
211
  getTokenIdsForScopeRefresh(kaminoMarket, reserves) {
198
212
  const tokenIds = [];
@@ -216,197 +230,181 @@ class KaminoAction {
216
230
  }
217
231
  return tokenIds;
218
232
  }
219
- addScopeRefreshIxs(tokens_1) {
220
- return __awaiter(this, arguments, void 0, function* (tokens, feed = 'hubble') {
221
- this.preTxnIxsLabels.unshift(`refreshScopePrices`);
222
- this.preTxnIxs.unshift(yield this.kaminoMarket.scope.refreshPriceListIx({
223
- feed: feed,
224
- }, tokens));
225
- });
233
+ async addScopeRefreshIxs(tokens, feed = 'hubble') {
234
+ this.preTxnIxsLabels.unshift(`refreshScopePrices`);
235
+ this.preTxnIxs.unshift(await this.kaminoMarket.scope.refreshPriceListIx({
236
+ feed: feed,
237
+ }, tokens));
226
238
  }
227
- static buildBorrowTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
228
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
229
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
230
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
231
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
232
- ) {
233
- const axn = yield KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
234
- const addInitObligationForFarm = true;
235
- if (extraComputeBudget > 0) {
236
- axn.addComputeBudgetIxn(extraComputeBudget);
237
- }
238
- const allReserves = new utils_1.PublicKeySet([
239
- ...axn.depositReserves,
240
- ...axn.borrowReserves,
241
- axn.reserve.address,
242
- ]).toArray();
243
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
244
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
245
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
246
- }
247
- yield axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
248
- axn.addBorrowIx();
249
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
250
- return axn;
251
- });
239
+ static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
240
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
241
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
242
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
243
+ ) {
244
+ const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
245
+ const addInitObligationForFarm = true;
246
+ if (extraComputeBudget > 0) {
247
+ axn.addComputeBudgetIxn(extraComputeBudget);
248
+ }
249
+ const allReserves = new utils_1.PublicKeySet([
250
+ ...axn.depositReserves,
251
+ ...axn.borrowReserves,
252
+ axn.reserve.address,
253
+ ]).toArray();
254
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
255
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
256
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
257
+ }
258
+ await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, undefined, overrideElevationGroupRequest);
259
+ axn.addBorrowIx();
260
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
261
+ return axn;
252
262
  }
253
- static buildDepositReserveLiquidityTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
254
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
255
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
256
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
257
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
258
- const axn = yield KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
259
- const addInitObligationForFarm = true;
260
- if (extraComputeBudget > 0) {
261
- axn.addComputeBudgetIxn(extraComputeBudget);
262
- }
263
- const allReserves = new utils_1.PublicKeySet([
264
- ...axn.depositReserves,
265
- ...axn.borrowReserves,
266
- axn.reserve.address,
267
- ]).toArray();
268
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
269
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
270
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
271
- }
272
- yield axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
273
- axn.addDepositReserveLiquidityIx();
274
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
275
- return axn;
276
- });
263
+ static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
264
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
265
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
266
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
267
+ const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
268
+ const addInitObligationForFarm = true;
269
+ if (extraComputeBudget > 0) {
270
+ axn.addComputeBudgetIxn(extraComputeBudget);
271
+ }
272
+ const allReserves = new utils_1.PublicKeySet([
273
+ ...axn.depositReserves,
274
+ ...axn.borrowReserves,
275
+ axn.reserve.address,
276
+ ]).toArray();
277
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
278
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
279
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
280
+ }
281
+ await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
282
+ axn.addDepositReserveLiquidityIx();
283
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
284
+ return axn;
277
285
  }
278
- static buildRedeemReserveCollateralTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
279
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
280
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
281
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
282
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
283
- const axn = yield KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
284
- const addInitObligationForFarm = true;
285
- if (extraComputeBudget > 0) {
286
- axn.addComputeBudgetIxn(extraComputeBudget);
287
- }
288
- const allReserves = new utils_1.PublicKeySet([
289
- ...axn.depositReserves,
290
- ...axn.borrowReserves,
291
- axn.reserve.address,
292
- ]).toArray();
293
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
294
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
295
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
296
- }
297
- yield axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
298
- axn.addRedeemReserveCollateralIx();
299
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
300
- return axn;
301
- });
286
+ static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
287
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
288
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
289
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
290
+ const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
291
+ const addInitObligationForFarm = true;
292
+ if (extraComputeBudget > 0) {
293
+ axn.addComputeBudgetIxn(extraComputeBudget);
294
+ }
295
+ const allReserves = new utils_1.PublicKeySet([
296
+ ...axn.depositReserves,
297
+ ...axn.borrowReserves,
298
+ axn.reserve.address,
299
+ ]).toArray();
300
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
301
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
302
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
303
+ }
304
+ await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
305
+ axn.addRedeemReserveCollateralIx();
306
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
307
+ return axn;
302
308
  }
303
- static buildDepositObligationCollateralTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
304
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
305
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
306
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
307
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
308
- const axn = yield KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
309
- const addInitObligationForFarm = true;
310
- if (extraComputeBudget > 0) {
311
- axn.addComputeBudgetIxn(extraComputeBudget);
312
- }
313
- const allReserves = new utils_1.PublicKeySet([
314
- ...axn.depositReserves,
315
- ...axn.borrowReserves,
316
- axn.reserve.address,
317
- ]).toArray();
318
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
319
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
320
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
321
- }
322
- yield axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
323
- axn.addDepositObligationCollateralIx();
324
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
325
- return axn;
326
- });
309
+ static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
310
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
311
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
312
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
313
+ const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
314
+ const addInitObligationForFarm = true;
315
+ if (extraComputeBudget > 0) {
316
+ axn.addComputeBudgetIxn(extraComputeBudget);
317
+ }
318
+ const allReserves = new utils_1.PublicKeySet([
319
+ ...axn.depositReserves,
320
+ ...axn.borrowReserves,
321
+ axn.reserve.address,
322
+ ]).toArray();
323
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
324
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
325
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
326
+ }
327
+ await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
328
+ axn.addDepositObligationCollateralIx();
329
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
330
+ return axn;
327
331
  }
328
- static buildDepositAndBorrowTxns(kaminoMarket_1, depositAmount_1, depositMint_1, borrowAmount_1, borrowMint_1, payer_1, obligation_2) {
329
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
330
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
331
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
332
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
333
- const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
334
- const addInitObligationForFarmForDeposit = true;
335
- const addInitObligationForFarmForBorrow = false;
336
- const twoTokenAction = true;
337
- if (extraComputeBudget > 0) {
338
- axn.addComputeBudgetIxn(extraComputeBudget);
339
- }
340
- const allReserves = new utils_1.PublicKeySet([
341
- ...axn.depositReserves,
342
- ...axn.borrowReserves,
343
- axn.reserve.address,
344
- axn.outflowReserve.address,
345
- ]).toArray();
346
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
347
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
348
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
349
- }
350
- yield axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
351
- yield axn.addDepositAndBorrowIx();
352
- yield axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow);
353
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
354
- return axn;
355
- });
332
+ static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
333
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
334
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
335
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
336
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
337
+ const addInitObligationForFarmForDeposit = true;
338
+ const addInitObligationForFarmForBorrow = false;
339
+ const twoTokenAction = true;
340
+ if (extraComputeBudget > 0) {
341
+ axn.addComputeBudgetIxn(extraComputeBudget);
342
+ }
343
+ const allReserves = new utils_1.PublicKeySet([
344
+ ...axn.depositReserves,
345
+ ...axn.borrowReserves,
346
+ axn.reserve.address,
347
+ axn.outflowReserve.address,
348
+ ]).toArray();
349
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
350
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
351
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
352
+ }
353
+ await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, twoTokenAction);
354
+ await axn.addDepositAndBorrowIx();
355
+ await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow);
356
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
357
+ return axn;
356
358
  }
357
- static buildRepayAndWithdrawTxns(kaminoMarket_1, repayAmount_1, repayMint_1, withdrawAmount_1, withdrawMint_1, payer_1, currentSlot_1, obligation_2) {
358
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
359
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
360
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
361
- isClosingPosition = false, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
362
- const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
363
- const addInitObligationForFarmForRepay = true;
364
- const addInitObligationForFarmForWithdraw = false;
365
- const twoTokenAction = true;
366
- if (extraComputeBudget > 0) {
367
- axn.addComputeBudgetIxn(extraComputeBudget);
368
- }
369
- const allReserves = new utils_1.PublicKeySet([
370
- ...axn.depositReserves,
371
- ...axn.borrowReserves,
372
- axn.reserve.address,
373
- axn.outflowReserve.address,
374
- ]).toArray();
375
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
376
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
377
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
378
- }
379
- yield axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
380
- yield axn.addRepayAndWithdrawIxs();
381
- yield axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, isClosingPosition);
382
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
383
- return axn;
384
- });
359
+ static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
360
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
361
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
362
+ isClosingPosition = false, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
363
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
364
+ const addInitObligationForFarmForRepay = true;
365
+ const addInitObligationForFarmForWithdraw = false;
366
+ const twoTokenAction = true;
367
+ if (extraComputeBudget > 0) {
368
+ axn.addComputeBudgetIxn(extraComputeBudget);
369
+ }
370
+ const allReserves = new utils_1.PublicKeySet([
371
+ ...axn.depositReserves,
372
+ ...axn.borrowReserves,
373
+ axn.reserve.address,
374
+ axn.outflowReserve.address,
375
+ ]).toArray();
376
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
377
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
378
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
379
+ }
380
+ await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, twoTokenAction);
381
+ await axn.addRepayAndWithdrawIxs();
382
+ await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, isClosingPosition);
383
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
384
+ return axn;
385
385
  }
386
- static buildWithdrawTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
387
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
388
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
389
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
390
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
391
- const axn = yield KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
392
- const addInitObligationForFarm = true;
393
- if (extraComputeBudget > 0) {
394
- axn.addComputeBudgetIxn(extraComputeBudget);
395
- }
396
- const allReserves = new utils_1.PublicKeySet([
397
- ...axn.depositReserves,
398
- ...axn.borrowReserves,
399
- axn.reserve.address,
400
- ]).toArray();
401
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
402
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
403
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
404
- }
405
- yield axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
406
- yield axn.addWithdrawIx();
407
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
408
- return axn;
409
- });
386
+ static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
387
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
388
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
389
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
390
+ const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
391
+ const addInitObligationForFarm = true;
392
+ if (extraComputeBudget > 0) {
393
+ axn.addComputeBudgetIxn(extraComputeBudget);
394
+ }
395
+ const allReserves = new utils_1.PublicKeySet([
396
+ ...axn.depositReserves,
397
+ ...axn.borrowReserves,
398
+ axn.reserve.address,
399
+ ]).toArray();
400
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
401
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
402
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
403
+ }
404
+ await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
405
+ await axn.addWithdrawIx();
406
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
407
+ return axn;
410
408
  }
411
409
  /**
412
410
  *
@@ -423,131 +421,115 @@ class KaminoAction {
423
421
  * @param includeUserMetadata - if true it includes user metadata
424
422
  * @param referrer
425
423
  */
426
- static buildRepayTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2, currentSlot_1) {
427
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1000000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
428
- const axn = yield KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
429
- const addInitObligationForFarm = true;
430
- if (extraComputeBudget > 0) {
431
- axn.addComputeBudgetIxn(extraComputeBudget);
432
- }
433
- const allReserves = new utils_1.PublicKeySet([
434
- ...axn.depositReserves,
435
- ...axn.borrowReserves,
436
- axn.reserve.address,
437
- ]).toArray();
438
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
439
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
440
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
441
- }
442
- yield axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
443
- yield axn.addRepayIx();
444
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
445
- return axn;
446
- });
424
+ static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
425
+ const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
426
+ const addInitObligationForFarm = true;
427
+ if (extraComputeBudget > 0) {
428
+ axn.addComputeBudgetIxn(extraComputeBudget);
429
+ }
430
+ const allReserves = new utils_1.PublicKeySet([
431
+ ...axn.depositReserves,
432
+ ...axn.borrowReserves,
433
+ axn.reserve.address,
434
+ ]).toArray();
435
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
436
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
437
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
438
+ }
439
+ await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
440
+ await axn.addRepayIx();
441
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
442
+ return axn;
447
443
  }
448
- static buildLiquidateTxns(kaminoMarket_1, amount_1, minCollateralReceiveAmount_1, repayTokenMint_1, withdrawTokenMint_1, liquidator_1, obligationOwner_1, obligation_2) {
449
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
450
- includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
451
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
452
- referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
453
- const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
454
- const addInitObligationForFarm = true;
455
- if (extraComputeBudget > 0) {
456
- axn.addComputeBudgetIxn(extraComputeBudget);
457
- }
458
- const allReserves = new utils_1.PublicKeySet([
459
- ...axn.depositReserves,
460
- ...axn.borrowReserves,
461
- axn.reserve.address,
462
- axn.outflowReserve.address,
463
- ]).toArray();
464
- const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
465
- if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
466
- yield axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
467
- }
468
- yield axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
469
- yield axn.addLiquidateIx(maxAllowedLtvOverridePercent);
470
- axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
471
- return axn;
472
- });
444
+ static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
445
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
446
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
447
+ referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
448
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
449
+ const addInitObligationForFarm = true;
450
+ if (extraComputeBudget > 0) {
451
+ axn.addComputeBudgetIxn(extraComputeBudget);
452
+ }
453
+ const allReserves = new utils_1.PublicKeySet([
454
+ ...axn.depositReserves,
455
+ ...axn.borrowReserves,
456
+ axn.reserve.address,
457
+ axn.outflowReserve.address,
458
+ ]).toArray();
459
+ const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
460
+ if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
461
+ await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
462
+ }
463
+ await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm);
464
+ await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
465
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
466
+ return axn;
473
467
  }
474
- static buildWithdrawReferrerFeeTxns(owner_1, tokenMint_1, kaminoMarket_1) {
475
- return __awaiter(this, arguments, void 0, function* (owner, tokenMint, kaminoMarket, currentSlot = 0) {
476
- const { axn, createAtasIxns } = yield KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
477
- axn.preTxnIxs.push(...createAtasIxns);
478
- axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
479
- axn.addRefreshReserveIxs([axn.reserve.address]);
480
- axn.addWithdrawReferrerFeesIxs();
481
- return axn;
482
- });
468
+ static async buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0) {
469
+ const { axn, createAtasIxns } = await KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
470
+ axn.preTxnIxs.push(...createAtasIxns);
471
+ axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
472
+ axn.addRefreshReserveIxs([axn.reserve.address]);
473
+ axn.addWithdrawReferrerFeesIxs();
474
+ return axn;
483
475
  }
484
- getTransactions() {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- const txns = {
487
- preLendingTxn: null,
488
- lendingTxn: null,
489
- postLendingTxn: null,
490
- };
491
- if (this.preTxnIxs.length) {
492
- txns.preLendingTxn = new web3_js_1.Transaction({
493
- feePayer: this.owner,
494
- recentBlockhash: (yield this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
495
- }).add(...this.preTxnIxs);
496
- }
497
- if (this.lendingIxs.length === 2) {
498
- txns.lendingTxn = new web3_js_1.Transaction({
499
- feePayer: this.owner,
500
- recentBlockhash: (yield this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
501
- }).add(...this.setupIxs, ...[this.lendingIxs[0]], ...this.inBetweenIxs, ...[this.lendingIxs[1]], ...this.cleanupIxs);
502
- }
503
- else {
504
- txns.lendingTxn = new web3_js_1.Transaction({
505
- feePayer: this.owner,
506
- recentBlockhash: (yield this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
507
- }).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
508
- }
509
- if (this.postTxnIxs.length) {
510
- txns.postLendingTxn = new web3_js_1.Transaction({
511
- feePayer: this.owner,
512
- recentBlockhash: (yield this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
513
- }).add(...this.postTxnIxs);
514
- }
515
- return txns;
516
- });
476
+ async getTransactions() {
477
+ const txns = {
478
+ preLendingTxn: null,
479
+ lendingTxn: null,
480
+ postLendingTxn: null,
481
+ };
482
+ if (this.preTxnIxs.length) {
483
+ txns.preLendingTxn = new web3_js_1.Transaction({
484
+ feePayer: this.owner,
485
+ recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
486
+ }).add(...this.preTxnIxs);
487
+ }
488
+ if (this.lendingIxs.length === 2) {
489
+ txns.lendingTxn = new web3_js_1.Transaction({
490
+ feePayer: this.owner,
491
+ recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
492
+ }).add(...this.setupIxs, ...[this.lendingIxs[0]], ...this.inBetweenIxs, ...[this.lendingIxs[1]], ...this.cleanupIxs);
493
+ }
494
+ else {
495
+ txns.lendingTxn = new web3_js_1.Transaction({
496
+ feePayer: this.owner,
497
+ recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
498
+ }).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
499
+ }
500
+ if (this.postTxnIxs.length) {
501
+ txns.postLendingTxn = new web3_js_1.Transaction({
502
+ feePayer: this.owner,
503
+ recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
504
+ }).add(...this.postTxnIxs);
505
+ }
506
+ return txns;
517
507
  }
518
- sendTransactions(sendTransaction) {
519
- return __awaiter(this, void 0, void 0, function* () {
520
- const txns = yield this.getTransactions();
521
- yield this.sendSingleTransaction(txns.preLendingTxn, sendTransaction);
522
- const signature = yield this.sendSingleTransaction(txns.lendingTxn, sendTransaction);
523
- yield this.sendSingleTransaction(txns.postLendingTxn, sendTransaction);
524
- return signature;
525
- });
508
+ async sendTransactions(sendTransaction) {
509
+ const txns = await this.getTransactions();
510
+ await this.sendSingleTransaction(txns.preLendingTxn, sendTransaction);
511
+ const signature = await this.sendSingleTransaction(txns.lendingTxn, sendTransaction);
512
+ await this.sendSingleTransaction(txns.postLendingTxn, sendTransaction);
513
+ return signature;
526
514
  }
527
- sendSingleTransaction(txn, sendTransaction) {
528
- return __awaiter(this, void 0, void 0, function* () {
529
- if (!txn)
530
- return '';
531
- const signature = yield sendTransaction(txn, this.kaminoMarket.getConnection());
532
- yield this.kaminoMarket.getConnection().confirmTransaction(signature);
533
- return signature;
534
- });
515
+ async sendSingleTransaction(txn, sendTransaction) {
516
+ if (!txn)
517
+ return '';
518
+ const signature = await sendTransaction(txn, this.kaminoMarket.getConnection());
519
+ await this.kaminoMarket.getConnection().confirmTransaction(signature);
520
+ return signature;
535
521
  }
536
- simulateTransactions(sendTransaction) {
537
- return __awaiter(this, void 0, void 0, function* () {
538
- const txns = yield this.getTransactions();
539
- yield this.simulateSingleTransaction(txns.preLendingTxn, sendTransaction);
540
- const signature = yield this.simulateSingleTransaction(txns.lendingTxn, sendTransaction);
541
- yield this.simulateSingleTransaction(txns.postLendingTxn, sendTransaction);
542
- return signature;
543
- });
522
+ async simulateTransactions(sendTransaction) {
523
+ const txns = await this.getTransactions();
524
+ await this.simulateSingleTransaction(txns.preLendingTxn, sendTransaction);
525
+ const signature = await this.simulateSingleTransaction(txns.lendingTxn, sendTransaction);
526
+ await this.simulateSingleTransaction(txns.postLendingTxn, sendTransaction);
527
+ return signature;
544
528
  }
545
- simulateSingleTransaction(txn, sendTransaction) {
546
- return __awaiter(this, void 0, void 0, function* () {
547
- if (!txn)
548
- return '';
549
- return yield sendTransaction(txn, this.kaminoMarket.getConnection());
550
- });
529
+ async simulateSingleTransaction(txn, sendTransaction) {
530
+ if (!txn)
531
+ return '';
532
+ return await sendTransaction(txn, this.kaminoMarket.getConnection());
551
533
  }
552
534
  addDepositIx() {
553
535
  this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
@@ -651,222 +633,210 @@ class KaminoAction {
651
633
  : borrowIx.keys;
652
634
  this.lendingIxs.push(borrowIx);
653
635
  }
654
- addDepositAndBorrowIx() {
655
- return __awaiter(this, void 0, void 0, function* () {
656
- this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
657
- this.lendingIxsLabels.push(`borrowObligationLiquidity`);
658
- this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
659
- liquidityAmount: this.amount,
660
- }, {
661
- owner: this.owner,
662
- obligation: this.getObligationPda(),
663
- lendingMarket: this.kaminoMarket.getAddress(),
664
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
665
- reserve: this.reserve.address,
666
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
667
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
668
- reserveCollateralMint: this.reserve.getCTokenMint(),
669
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
670
- userSourceLiquidity: this.userTokenAccountAddress,
671
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
672
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
673
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
674
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
675
- }, this.kaminoMarket.programId));
676
- if (!this.outflowReserve) {
677
- throw new Error(`outflowReserve not set`);
678
- }
679
- if (!this.additionalTokenAccountAddress) {
680
- throw new Error(`additionalTokenAccountAddress not set`);
681
- }
682
- if (!this.outflowAmount) {
683
- throw new Error(`outflowAmount not set`);
684
- }
685
- const depositReservesList = this.getAdditionalDepositReservesList();
686
- if (depositReservesList.length === 0) {
687
- depositReservesList.push(this.reserve.address);
688
- }
689
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
690
- return { pubkey: reserve, isSigner: false, isWritable: true };
691
- });
692
- const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
693
- liquidityAmount: this.outflowAmount,
694
- }, {
695
- owner: this.owner,
696
- obligation: this.getObligationPda(),
697
- lendingMarket: this.kaminoMarket.getAddress(),
698
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
699
- borrowReserve: this.outflowReserve.address,
700
- borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
701
- reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
702
- userDestinationLiquidity: this.additionalTokenAccountAddress,
703
- borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
704
- referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
705
- tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
706
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
707
- }, this.kaminoMarket.programId);
708
- borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
709
- this.lendingIxs.push(borrowIx);
636
+ async addDepositAndBorrowIx() {
637
+ this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
638
+ this.lendingIxsLabels.push(`borrowObligationLiquidity`);
639
+ this.lendingIxs.push((0, instructions_1.depositReserveLiquidityAndObligationCollateral)({
640
+ liquidityAmount: this.amount,
641
+ }, {
642
+ owner: this.owner,
643
+ obligation: this.getObligationPda(),
644
+ lendingMarket: this.kaminoMarket.getAddress(),
645
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
646
+ reserve: this.reserve.address,
647
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
648
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
649
+ reserveCollateralMint: this.reserve.getCTokenMint(),
650
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
651
+ userSourceLiquidity: this.userTokenAccountAddress,
652
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
653
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
654
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
655
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
656
+ }, this.kaminoMarket.programId));
657
+ if (!this.outflowReserve) {
658
+ throw new Error(`outflowReserve not set`);
659
+ }
660
+ if (!this.additionalTokenAccountAddress) {
661
+ throw new Error(`additionalTokenAccountAddress not set`);
662
+ }
663
+ if (!this.outflowAmount) {
664
+ throw new Error(`outflowAmount not set`);
665
+ }
666
+ const depositReservesList = this.getAdditionalDepositReservesList();
667
+ if (depositReservesList.length === 0) {
668
+ depositReservesList.push(this.reserve.address);
669
+ }
670
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
671
+ return { pubkey: reserve, isSigner: false, isWritable: true };
710
672
  });
673
+ const borrowIx = (0, instructions_1.borrowObligationLiquidity)({
674
+ liquidityAmount: this.outflowAmount,
675
+ }, {
676
+ owner: this.owner,
677
+ obligation: this.getObligationPda(),
678
+ lendingMarket: this.kaminoMarket.getAddress(),
679
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
680
+ borrowReserve: this.outflowReserve.address,
681
+ borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
682
+ reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
683
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
684
+ borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
685
+ referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
686
+ tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
687
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
688
+ }, this.kaminoMarket.programId);
689
+ borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
690
+ this.lendingIxs.push(borrowIx);
711
691
  }
712
- addRepayAndWithdrawIxs() {
713
- return __awaiter(this, void 0, void 0, function* () {
714
- this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
715
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
716
- const depositReservesList = this.getAdditionalDepositReservesList();
717
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
718
- return { pubkey: reserve, isSigner: false, isWritable: true };
719
- });
720
- const repayIx = (0, instructions_1.repayObligationLiquidity)({
721
- liquidityAmount: this.amount,
722
- }, {
723
- owner: this.owner,
724
- obligation: this.getObligationPda(),
725
- lendingMarket: this.kaminoMarket.getAddress(),
726
- repayReserve: this.reserve.address,
727
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
728
- userSourceLiquidity: this.userTokenAccountAddress,
729
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
730
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
731
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
732
- }, this.kaminoMarket.programId);
733
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
734
- this.lendingIxs.push(repayIx);
735
- if (!this.outflowReserve) {
736
- throw new Error(`outflowReserve not set`);
737
- }
738
- if (!this.additionalTokenAccountAddress) {
739
- throw new Error(`additionalTokenAccountAddress not set`);
740
- }
741
- if (!this.outflowAmount) {
742
- throw new Error(`outflowAmount not set`);
743
- }
744
- const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
745
- this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
746
- collateralAmount: this.outflowAmount.eq(new bn_js_1.default(utils_1.U64_MAX))
747
- ? this.outflowAmount
748
- : new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
749
- }, {
750
- owner: this.owner,
751
- obligation: this.getObligationPda(),
752
- lendingMarket: this.kaminoMarket.getAddress(),
753
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
754
- withdrawReserve: this.outflowReserve.address,
755
- reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
756
- reserveCollateralMint: this.outflowReserve.getCTokenMint(),
757
- reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
758
- reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
759
- userDestinationLiquidity: this.additionalTokenAccountAddress,
760
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
761
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
762
- liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
763
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
764
- }, this.kaminoMarket.programId));
692
+ async addRepayAndWithdrawIxs() {
693
+ this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
694
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
695
+ const depositReservesList = this.getAdditionalDepositReservesList();
696
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
697
+ return { pubkey: reserve, isSigner: false, isWritable: true };
765
698
  });
699
+ const repayIx = (0, instructions_1.repayObligationLiquidity)({
700
+ liquidityAmount: this.amount,
701
+ }, {
702
+ owner: this.owner,
703
+ obligation: this.getObligationPda(),
704
+ lendingMarket: this.kaminoMarket.getAddress(),
705
+ repayReserve: this.reserve.address,
706
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
707
+ userSourceLiquidity: this.userTokenAccountAddress,
708
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
709
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
710
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
711
+ }, this.kaminoMarket.programId);
712
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
713
+ this.lendingIxs.push(repayIx);
714
+ if (!this.outflowReserve) {
715
+ throw new Error(`outflowReserve not set`);
716
+ }
717
+ if (!this.additionalTokenAccountAddress) {
718
+ throw new Error(`additionalTokenAccountAddress not set`);
719
+ }
720
+ if (!this.outflowAmount) {
721
+ throw new Error(`outflowAmount not set`);
722
+ }
723
+ const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
724
+ this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
725
+ collateralAmount: this.outflowAmount.eq(new bn_js_1.default(utils_1.U64_MAX))
726
+ ? this.outflowAmount
727
+ : new bn_js_1.default(new decimal_js_1.default(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
728
+ }, {
729
+ owner: this.owner,
730
+ obligation: this.getObligationPda(),
731
+ lendingMarket: this.kaminoMarket.getAddress(),
732
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
733
+ withdrawReserve: this.outflowReserve.address,
734
+ reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
735
+ reserveCollateralMint: this.outflowReserve.getCTokenMint(),
736
+ reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
737
+ reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
738
+ userDestinationLiquidity: this.additionalTokenAccountAddress,
739
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
740
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
741
+ liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
742
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
743
+ }, this.kaminoMarket.programId));
766
744
  }
767
- addWithdrawIx() {
768
- return __awaiter(this, void 0, void 0, function* () {
769
- const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
770
- const collateralAmount = this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))
771
- ? this.amount
772
- : new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
773
- this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
774
- this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
775
- collateralAmount,
776
- }, {
777
- owner: this.owner,
778
- obligation: this.getObligationPda(),
779
- lendingMarket: this.kaminoMarket.getAddress(),
780
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
781
- withdrawReserve: this.reserve.address,
782
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
783
- reserveCollateralMint: this.reserve.getCTokenMint(),
784
- reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
785
- reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
786
- userDestinationLiquidity: this.userTokenAccountAddress,
787
- placeholderUserDestinationCollateral: this.kaminoMarket.programId,
788
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
789
- liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
790
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
791
- }, this.kaminoMarket.programId));
792
- });
745
+ async addWithdrawIx() {
746
+ const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
747
+ const collateralAmount = this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))
748
+ ? this.amount
749
+ : new bn_js_1.default(new decimal_js_1.default(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
750
+ this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
751
+ this.lendingIxs.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateral)({
752
+ collateralAmount,
753
+ }, {
754
+ owner: this.owner,
755
+ obligation: this.getObligationPda(),
756
+ lendingMarket: this.kaminoMarket.getAddress(),
757
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
758
+ withdrawReserve: this.reserve.address,
759
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
760
+ reserveCollateralMint: this.reserve.getCTokenMint(),
761
+ reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
762
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
763
+ userDestinationLiquidity: this.userTokenAccountAddress,
764
+ placeholderUserDestinationCollateral: this.kaminoMarket.programId,
765
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
766
+ liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
767
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
768
+ }, this.kaminoMarket.programId));
793
769
  }
794
- addRepayIx() {
795
- return __awaiter(this, void 0, void 0, function* () {
796
- this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
797
- const depositReservesList = this.getAdditionalDepositReservesList();
798
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
799
- return { pubkey: reserve, isSigner: false, isWritable: true };
800
- });
801
- const repayIx = (0, instructions_1.repayObligationLiquidity)({
802
- liquidityAmount: this.amount,
803
- }, {
804
- owner: this.payer,
805
- obligation: this.getObligationPda(),
806
- lendingMarket: this.kaminoMarket.getAddress(),
807
- repayReserve: this.reserve.address,
808
- reserveLiquidityMint: this.reserve.getLiquidityMint(),
809
- userSourceLiquidity: this.userTokenAccountAddress,
810
- reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
811
- tokenProgram: this.reserve.getLiquidityTokenProgram(),
812
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
813
- }, this.kaminoMarket.programId);
814
- repayIx.keys =
815
- this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
816
- this.lendingIxs.push(repayIx);
770
+ async addRepayIx() {
771
+ this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
772
+ const depositReservesList = this.getAdditionalDepositReservesList();
773
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
774
+ return { pubkey: reserve, isSigner: false, isWritable: true };
817
775
  });
776
+ const repayIx = (0, instructions_1.repayObligationLiquidity)({
777
+ liquidityAmount: this.amount,
778
+ }, {
779
+ owner: this.payer,
780
+ obligation: this.getObligationPda(),
781
+ lendingMarket: this.kaminoMarket.getAddress(),
782
+ repayReserve: this.reserve.address,
783
+ reserveLiquidityMint: this.reserve.getLiquidityMint(),
784
+ userSourceLiquidity: this.userTokenAccountAddress,
785
+ reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
786
+ tokenProgram: this.reserve.getLiquidityTokenProgram(),
787
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
788
+ }, this.kaminoMarket.programId);
789
+ repayIx.keys =
790
+ this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
791
+ this.lendingIxs.push(repayIx);
818
792
  }
819
- addLiquidateIx() {
820
- return __awaiter(this, arguments, void 0, function* (maxAllowedLtvOverridePercent = 0) {
821
- this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
822
- if (!this.outflowReserve) {
823
- throw Error(`Withdraw reserve during liquidation is not defined`);
824
- }
825
- if (!this.additionalTokenAccountAddress) {
826
- throw Error(`Liquidating token account address is not defined`);
827
- }
828
- const depositReservesList = this.getAdditionalDepositReservesList();
829
- const depositReserveAccountMetas = depositReservesList.map((reserve) => {
830
- return { pubkey: reserve, isSigner: false, isWritable: true };
831
- });
832
- const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
833
- liquidityAmount: this.amount,
834
- // TODO: Configure this when updating liquidator with new interface
835
- minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
836
- maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
837
- }, {
838
- liquidator: this.owner,
839
- obligation: this.getObligationPda(),
840
- lendingMarket: this.kaminoMarket.getAddress(),
841
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
842
- repayReserve: this.reserve.address,
843
- repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
844
- repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
845
- withdrawReserve: this.outflowReserve.address,
846
- withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
847
- withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
848
- withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
849
- withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
850
- userSourceLiquidity: this.additionalTokenAccountAddress,
851
- userDestinationCollateral: this.userCollateralAccountAddress,
852
- userDestinationLiquidity: this.userTokenAccountAddress,
853
- withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
854
- collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
855
- repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
856
- withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
857
- instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
858
- }, this.kaminoMarket.programId);
859
- liquidateIx.keys =
860
- this.obligation.state.elevationGroup > 0
861
- ? liquidateIx.keys.concat([...depositReserveAccountMetas])
862
- : liquidateIx.keys;
863
- this.lendingIxs.push(liquidateIx);
793
+ async addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
794
+ this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
795
+ if (!this.outflowReserve) {
796
+ throw Error(`Withdraw reserve during liquidation is not defined`);
797
+ }
798
+ if (!this.additionalTokenAccountAddress) {
799
+ throw Error(`Liquidating token account address is not defined`);
800
+ }
801
+ const depositReservesList = this.getAdditionalDepositReservesList();
802
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
803
+ return { pubkey: reserve, isSigner: false, isWritable: true };
864
804
  });
805
+ const liquidateIx = (0, instructions_1.liquidateObligationAndRedeemReserveCollateral)({
806
+ liquidityAmount: this.amount,
807
+ // TODO: Configure this when updating liquidator with new interface
808
+ minAcceptableReceivedLiquidityAmount: this.outflowAmount || new bn_js_1.default(0),
809
+ maxAllowedLtvOverridePercent: new bn_js_1.default(maxAllowedLtvOverridePercent),
810
+ }, {
811
+ liquidator: this.owner,
812
+ obligation: this.getObligationPda(),
813
+ lendingMarket: this.kaminoMarket.getAddress(),
814
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
815
+ repayReserve: this.reserve.address,
816
+ repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
817
+ repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
818
+ withdrawReserve: this.outflowReserve.address,
819
+ withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
820
+ withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
821
+ withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
822
+ withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
823
+ userSourceLiquidity: this.additionalTokenAccountAddress,
824
+ userDestinationCollateral: this.userCollateralAccountAddress,
825
+ userDestinationLiquidity: this.userTokenAccountAddress,
826
+ withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
827
+ collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
828
+ repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
829
+ withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
830
+ instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
831
+ }, this.kaminoMarket.programId);
832
+ liquidateIx.keys =
833
+ this.obligation.state.elevationGroup > 0
834
+ ? liquidateIx.keys.concat([...depositReserveAccountMetas])
835
+ : liquidateIx.keys;
836
+ this.lendingIxs.push(liquidateIx);
865
837
  }
866
- addInBetweenIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, addInitObligationForFarm_1) {
867
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
868
- yield this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'inBetween', requestElevationGroup, addInitObligationForFarm, isClosingPosition);
869
- });
838
+ async addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
839
+ await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'inBetween', requestElevationGroup, addInitObligationForFarm, isClosingPosition);
870
840
  }
871
841
  addRefreshObligation(crank) {
872
842
  const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
@@ -878,253 +848,248 @@ class KaminoAction {
878
848
  this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
879
849
  this.addRefreshObligationIx(addAllToSetupIxns, false);
880
850
  }
881
- addSupportIxsWithoutInitObligation(action_1, includeAtaIxns_1) {
882
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false, overrideElevationGroupRequest) {
883
- var _a, _b, _c, _d;
884
- // TODO: why are we not doing this first?
885
- if (includeAtaIxns) {
886
- yield this.addAtaIxs(action);
887
- }
888
- if ([
889
- 'depositCollateral',
890
- 'deposit',
891
- 'withdraw',
892
- 'borrow',
893
- 'liquidate',
894
- 'repay',
895
- 'depositAndBorrow',
896
- 'repayAndWithdraw',
897
- 'refreshObligation',
898
- ].includes(action)) {
899
- // The support ixns in order are:
900
- // 0. Init obligation ixn
901
- // 0. Token Ata ixns
902
- // 0. Init obligation for farm
903
- // 1. Ixns to refresh the reserves of the obligation not related to the current action
904
- // 2. Ixn to refresh the reserve of the current action
905
- // 3. Ixn to refresh the obligation
906
- // 4. Ixn to refresh the `debt` farm of the obligation
907
- // 5. Ixn to refresh the `collateral` farm of the obligation
908
- // 6. The instruction itself
909
- // 7. Ixn to refresh the `debt` farm of the obligation
910
- // 8. Ixn to refresh the `collateral` farm of the obligation
911
- let currentReserves = [];
912
- if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
913
- if (!this.outflowReserve) {
914
- throw new Error('outflowReserve is undefined');
915
- }
916
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
917
- currentReserves = [this.reserve, this.outflowReserve];
918
- if (this.obligation) {
919
- if (action === 'depositAndBorrow') {
920
- const deposit = this.obligation.state.deposits.find((deposit) => deposit.depositReserve.equals(this.reserve.address));
921
- if (!deposit) {
922
- this.preLoadedDepositReservesSameTx.push(this.reserve.address);
923
- }
924
- }
925
- else {
926
- const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.equals(this.reserve.address));
927
- if (!borrow) {
928
- throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
929
- }
930
- const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
931
- const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
932
- const fullRepay = obligation_1.KaminoObligation.getBorrowAmount(borrow)
933
- .mul(cumulativeBorrowRateReserve)
934
- .div(cumulativeBorrowRateObligation);
935
- const amountDecimal = new decimal_js_1.default(this.amount.toString());
936
- if (fullRepay.lte(amountDecimal)) {
937
- this.preLoadedBorrowReservesSameTx.push(this.reserve.address);
938
- }
851
+ async addSupportIxsWithoutInitObligation(action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false, overrideElevationGroupRequest) {
852
+ // TODO: why are we not doing this first?
853
+ if (includeAtaIxns) {
854
+ await this.addAtaIxs(action);
855
+ }
856
+ if ([
857
+ 'depositCollateral',
858
+ 'deposit',
859
+ 'withdraw',
860
+ 'borrow',
861
+ 'liquidate',
862
+ 'repay',
863
+ 'depositAndBorrow',
864
+ 'repayAndWithdraw',
865
+ 'refreshObligation',
866
+ ].includes(action)) {
867
+ // The support ixns in order are:
868
+ // 0. Init obligation ixn
869
+ // 0. Token Ata ixns
870
+ // 0. Init obligation for farm
871
+ // 1. Ixns to refresh the reserves of the obligation not related to the current action
872
+ // 2. Ixn to refresh the reserve of the current action
873
+ // 3. Ixn to refresh the obligation
874
+ // 4. Ixn to refresh the `debt` farm of the obligation
875
+ // 5. Ixn to refresh the `collateral` farm of the obligation
876
+ // 6. The instruction itself
877
+ // 7. Ixn to refresh the `debt` farm of the obligation
878
+ // 8. Ixn to refresh the `collateral` farm of the obligation
879
+ let currentReserves = [];
880
+ if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
881
+ if (!this.outflowReserve) {
882
+ throw new Error('outflowReserve is undefined');
883
+ }
884
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
885
+ currentReserves = [this.reserve, this.outflowReserve];
886
+ if (this.obligation) {
887
+ if (action === 'depositAndBorrow') {
888
+ const deposit = this.obligation.state.deposits.find((deposit) => deposit.depositReserve.equals(this.reserve.address));
889
+ if (!deposit) {
890
+ this.preLoadedDepositReservesSameTx.push(this.reserve.address);
939
891
  }
940
892
  }
941
893
  else {
942
- // Obligation doesn't exist yet, so we have to preload the deposit reserve
943
- this.preLoadedDepositReservesSameTx.push(this.reserve.address);
894
+ const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.equals(this.reserve.address));
895
+ if (!borrow) {
896
+ throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
897
+ }
898
+ const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
899
+ const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
900
+ const fullRepay = obligation_1.KaminoObligation.getBorrowAmount(borrow)
901
+ .mul(cumulativeBorrowRateReserve)
902
+ .div(cumulativeBorrowRateObligation);
903
+ const amountDecimal = new decimal_js_1.default(this.amount.toString());
904
+ if (fullRepay.lte(amountDecimal)) {
905
+ this.preLoadedBorrowReservesSameTx.push(this.reserve.address);
906
+ }
944
907
  }
945
908
  }
946
- else if (action === 'liquidate' && !this.outflowReserve.address.equals(this.reserve.address)) {
947
- currentReserves = [this.outflowReserve, this.reserve];
948
- }
949
909
  else {
950
- currentReserves = [this.reserve];
910
+ // Obligation doesn't exist yet, so we have to preload the deposit reserve
911
+ this.preLoadedDepositReservesSameTx.push(this.reserve.address);
951
912
  }
952
913
  }
914
+ else if (action === 'liquidate' && !this.outflowReserve.address.equals(this.reserve.address)) {
915
+ currentReserves = [this.outflowReserve, this.reserve];
916
+ }
953
917
  else {
954
918
  currentReserves = [this.reserve];
955
919
  }
956
- const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves));
957
- const currentReserveAddresses = new utils_1.PublicKeySet(currentReserves.map((reserve) => reserve.address));
958
- // Union of addresses
959
- const allReservesExcludingCurrent = [...uniqueReserveAddresses.toArray()].filter((address) => !currentReserveAddresses.contains(address));
960
- this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
961
- if (addInitObligationForFarm) {
962
- if (action === 'liquidate') {
963
- yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
964
- yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
965
- }
966
- else if (action === 'depositAndBorrow' ||
967
- action === 'depositCollateral' ||
968
- action === 'withdraw' ||
969
- action === 'deposit') {
970
- yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
971
- if (this.outflowReserve) {
972
- yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
973
- }
974
- }
975
- else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
976
- // todo - probably don't need to add both debt and collateral for everything here
977
- yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
978
- if (this.outflowReserve) {
979
- yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
980
- }
981
- }
982
- else {
983
- yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
984
- yield this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
985
- if (this.outflowReserve) {
986
- yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
987
- yield this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
988
- }
920
+ }
921
+ else {
922
+ currentReserves = [this.reserve];
923
+ }
924
+ const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves));
925
+ const currentReserveAddresses = new utils_1.PublicKeySet(currentReserves.map((reserve) => reserve.address));
926
+ // Union of addresses
927
+ const allReservesExcludingCurrent = [...uniqueReserveAddresses.toArray()].filter((address) => !currentReserveAddresses.contains(address));
928
+ this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
929
+ if (addInitObligationForFarm) {
930
+ if (action === 'liquidate') {
931
+ await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
932
+ await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
933
+ }
934
+ else if (action === 'depositAndBorrow' ||
935
+ action === 'depositCollateral' ||
936
+ action === 'withdraw' ||
937
+ action === 'deposit') {
938
+ await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
939
+ if (this.outflowReserve) {
940
+ await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
989
941
  }
990
942
  }
991
- this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
992
- if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween' && isClosingPosition) {
993
- // addToSetupIxs === addInBetween (same thing)
994
- // If this is a repay and withdraw, and it's not the first action, and it's closing a position
995
- // we don't need to include the repay reserve in the refresh obligation
996
- // I am ashamed of this code, we need to rewrite this entire thing
997
- this.addRefreshObligationIx(addAsSupportIx, true);
943
+ else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
944
+ // todo - probably don't need to add both debt and collateral for everything here
945
+ await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
946
+ if (this.outflowReserve) {
947
+ await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
948
+ }
998
949
  }
999
950
  else {
1000
- this.addRefreshObligationIx(addAsSupportIx, false);
951
+ await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
952
+ await this.addInitObligationForFarm(this.reserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
953
+ if (this.outflowReserve) {
954
+ await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Collateral, addAsSupportIx);
955
+ await this.addInitObligationForFarm(this.outflowReserve, types_1.ReserveFarmKind.Debt, addAsSupportIx);
956
+ }
1001
957
  }
1002
- if (requestElevationGroup) {
1003
- if (action === 'repay') {
1004
- const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
1005
- if (!repayObligationLiquidity) {
1006
- throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
958
+ }
959
+ this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
960
+ if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween' && isClosingPosition) {
961
+ // addToSetupIxs === addInBetween (same thing)
962
+ // If this is a repay and withdraw, and it's not the first action, and it's closing a position
963
+ // we don't need to include the repay reserve in the refresh obligation
964
+ // I am ashamed of this code, we need to rewrite this entire thing
965
+ this.addRefreshObligationIx(addAsSupportIx, true);
966
+ }
967
+ else {
968
+ this.addRefreshObligationIx(addAsSupportIx, false);
969
+ }
970
+ if (requestElevationGroup) {
971
+ if (action === 'repay') {
972
+ const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
973
+ if (!repayObligationLiquidity) {
974
+ throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
975
+ }
976
+ if (new decimal_js_1.default(repayObligationLiquidity.amount).lte(new decimal_js_1.default(this.amount.toString())) &&
977
+ this.obligation.borrows.size === 1 &&
978
+ this.obligation?.state.elevationGroup !== 0) {
979
+ this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
980
+ // Skip the borrow reserve, since we repay in the same tx
981
+ this.addRefreshObligationIx('cleanup', true);
982
+ this.addRequestElevationIx(overrideElevationGroupRequest ?? 0, 'cleanup', true);
983
+ }
984
+ }
985
+ else if (action === 'depositAndBorrow' || action === 'borrow') {
986
+ let newElevationGroup = -1;
987
+ let addAsSupportIx = 'setup';
988
+ if (overrideElevationGroupRequest !== undefined) {
989
+ newElevationGroup = overrideElevationGroupRequest;
990
+ }
991
+ else {
992
+ let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
993
+ let emodeGroupsColl = this.reserve.state.config.elevationGroups;
994
+ let debtReserve = this.reserve.address;
995
+ if (action === 'depositAndBorrow') {
996
+ emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
997
+ debtReserve = this.outflowReserve.address;
998
+ addAsSupportIx = 'inBetween';
1007
999
  }
1008
- if (new decimal_js_1.default(repayObligationLiquidity.amount).lte(new decimal_js_1.default(this.amount.toString())) &&
1009
- this.obligation.borrows.size === 1 &&
1010
- ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0) {
1011
- this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
1012
- // Skip the borrow reserve, since we repay in the same tx
1013
- this.addRefreshObligationIx('cleanup', true);
1014
- this.addRequestElevationIx(overrideElevationGroupRequest !== null && overrideElevationGroupRequest !== void 0 ? overrideElevationGroupRequest : 0, 'cleanup', true);
1000
+ else if (action === 'borrow') {
1001
+ const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
1002
+ const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
1003
+ emodeGroupsColl = collReserve.state.config.elevationGroups;
1004
+ addAsSupportIx = 'setup';
1015
1005
  }
1016
- }
1017
- else if (action === 'depositAndBorrow' || action === 'borrow') {
1018
- let newElevationGroup = -1;
1019
- let addAsSupportIx = 'setup';
1020
- if (overrideElevationGroupRequest !== undefined) {
1021
- newElevationGroup = overrideElevationGroupRequest;
1006
+ const groups = this.kaminoMarket.state.elevationGroups;
1007
+ const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
1008
+ console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
1009
+ if (commonElevationGroups.length === 0) {
1010
+ console.log('No common elevation groups found, staying with default');
1022
1011
  }
1023
1012
  else {
1024
- let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
1025
- let emodeGroupsColl = this.reserve.state.config.elevationGroups;
1026
- let debtReserve = this.reserve.address;
1027
- if (action === 'depositAndBorrow') {
1028
- emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
1029
- debtReserve = this.outflowReserve.address;
1030
- addAsSupportIx = 'inBetween';
1031
- }
1032
- else if (action === 'borrow') {
1033
- const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
1034
- const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
1035
- emodeGroupsColl = collReserve.state.config.elevationGroups;
1036
- addAsSupportIx = 'setup';
1037
- }
1038
- const groups = this.kaminoMarket.state.elevationGroups;
1039
- const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
1040
- console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
1041
- if (commonElevationGroups.length === 0) {
1042
- console.log('No common elevation groups found, staying with default');
1043
- }
1044
- else {
1045
- const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
1046
- const prevGroup = groups.find((group) => group.id === prev);
1047
- const currGroup = groups.find((group) => group.id === curr);
1048
- return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
1049
- });
1050
- const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
1051
- console.log('Setting eModeGroup to', eModeGroup);
1052
- if (eModeGroup !== 0 && eModeGroup !== ((_b = this.obligation) === null || _b === void 0 ? void 0 : _b.state.elevationGroup)) {
1053
- newElevationGroup = eModeGroup;
1054
- }
1055
- }
1056
- }
1057
- console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
1058
- if (newElevationGroup >= 0 && newElevationGroup !== ((_c = this.obligation) === null || _c === void 0 ? void 0 : _c.state.elevationGroup)) {
1059
- this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
1060
- this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
1061
- this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
1062
- this.addRefreshObligationIx(addAsSupportIx);
1063
- if (action === 'borrow') {
1064
- this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
1013
+ const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
1014
+ const prevGroup = groups.find((group) => group.id === prev);
1015
+ const currGroup = groups.find((group) => group.id === curr);
1016
+ return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
1017
+ });
1018
+ const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
1019
+ console.log('Setting eModeGroup to', eModeGroup);
1020
+ if (eModeGroup !== 0 && eModeGroup !== this.obligation?.state.elevationGroup) {
1021
+ newElevationGroup = eModeGroup;
1065
1022
  }
1066
1023
  }
1067
1024
  }
1068
- else if (action === 'deposit' &&
1069
- overrideElevationGroupRequest !== undefined &&
1070
- overrideElevationGroupRequest !== ((_d = this.obligation) === null || _d === void 0 ? void 0 : _d.state.elevationGroup)) {
1071
- const addAsSupportIx = 'setup';
1072
- console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
1073
- this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
1025
+ console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
1026
+ if (newElevationGroup >= 0 && newElevationGroup !== this.obligation?.state.elevationGroup) {
1027
+ this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
1074
1028
  this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
1075
1029
  this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
1076
1030
  this.addRefreshObligationIx(addAsSupportIx);
1031
+ if (action === 'borrow') {
1032
+ this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
1033
+ }
1077
1034
  }
1078
1035
  }
1079
- if (addAsSupportIx === 'setup') {
1080
- // If this is an setup ixn (therefore not an in-between), it means it's either a one off action
1081
- // or the first of a two-token-action
1082
- if (action === 'liquidate') {
1083
- this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
1084
- this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
1085
- }
1086
- else if (action === 'depositAndBorrow' ||
1087
- action === 'depositCollateral' ||
1088
- action === 'withdraw' ||
1089
- action === 'deposit') {
1090
- this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
1091
- }
1092
- else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
1093
- this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
1094
- }
1095
- else {
1096
- throw new Error(`Could not decide on refresh farm for action ${action}`);
1097
- }
1036
+ else if (action === 'deposit' &&
1037
+ overrideElevationGroupRequest !== undefined &&
1038
+ overrideElevationGroupRequest !== this.obligation?.state.elevationGroup) {
1039
+ const addAsSupportIx = 'setup';
1040
+ console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
1041
+ this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
1042
+ this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
1043
+ this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
1044
+ this.addRefreshObligationIx(addAsSupportIx);
1045
+ }
1046
+ }
1047
+ if (addAsSupportIx === 'setup') {
1048
+ // If this is an setup ixn (therefore not an in-between), it means it's either a one off action
1049
+ // or the first of a two-token-action
1050
+ if (action === 'liquidate') {
1051
+ this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
1052
+ this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
1053
+ }
1054
+ else if (action === 'depositAndBorrow' ||
1055
+ action === 'depositCollateral' ||
1056
+ action === 'withdraw' ||
1057
+ action === 'deposit') {
1058
+ this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Collateral, undefined, twoTokenAction);
1059
+ }
1060
+ else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
1061
+ this.addRefreshFarmsForReserve(currentReserves, addAsSupportIx, types_1.ReserveFarmKind.Debt, undefined, twoTokenAction);
1098
1062
  }
1099
1063
  else {
1100
- // If this is an inbetween, it means it's part of a two-token-action
1101
- // so we skip the refresh farm obligation of the first reserve as that operation already happened
1102
- // add added to 'setup' ixns
1103
- if (action === 'depositAndBorrow') {
1104
- this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
1105
- }
1106
- else if (action === 'repayAndWithdraw') {
1107
- this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
1108
- }
1109
- else {
1110
- throw new Error(`Could not decide on refresh farm for action ${action}`);
1111
- }
1064
+ throw new Error(`Could not decide on refresh farm for action ${action}`);
1112
1065
  }
1113
1066
  }
1114
- });
1115
- }
1116
- addSupportIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, includeUserMetadata_1, addInitObligationForFarm_1) {
1117
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
1118
- if (!['mint', 'redeem'].includes(action)) {
1119
- const [, ownerUserMetadata] = yield this.kaminoMarket.getUserMetadata(this.owner);
1120
- if (!ownerUserMetadata && includeUserMetadata) {
1121
- yield this.addInitUserMetadataIxs();
1067
+ else {
1068
+ // If this is an inbetween, it means it's part of a two-token-action
1069
+ // so we skip the refresh farm obligation of the first reserve as that operation already happened
1070
+ // add added to 'setup' ixns
1071
+ if (action === 'depositAndBorrow') {
1072
+ this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
1073
+ }
1074
+ else if (action === 'repayAndWithdraw') {
1075
+ this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
1076
+ }
1077
+ else {
1078
+ throw new Error(`Could not decide on refresh farm for action ${action}`);
1122
1079
  }
1123
- yield this.addInitReferrerTokenStateIxs();
1124
- yield this.addInitObligationIxs();
1125
1080
  }
1126
- yield this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, false, twoTokenAction, overrideElevationGroupRequest);
1127
- });
1081
+ }
1082
+ }
1083
+ async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false, overrideElevationGroupRequest) {
1084
+ if (!['mint', 'redeem'].includes(action)) {
1085
+ const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
1086
+ if (!ownerUserMetadata && includeUserMetadata) {
1087
+ await this.addInitUserMetadataIxs();
1088
+ }
1089
+ await this.addInitReferrerTokenStateIxs();
1090
+ await this.addInitObligationIxs();
1091
+ }
1092
+ await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, 'setup', requestElevationGroup, addInitObligationForFarm, false, twoTokenAction, overrideElevationGroupRequest);
1128
1093
  }
1129
1094
  static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
1130
1095
  if ((0, utils_1.isNotNullPubkey)(pubkey)) {
@@ -1331,135 +1296,126 @@ class KaminoAction {
1331
1296
  this.cleanupIxs.splice(0, 0, ...this.refreshFarmsCleanupTxnIxs);
1332
1297
  this.cleanupIxsLabels.splice(0, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
1333
1298
  }
1334
- addInitObligationForFarm(reserve_1, mode_1) {
1335
- return __awaiter(this, arguments, void 0, function* (reserve, mode, addAsSupportIx = 'setup') {
1336
- const BASE_SEED_USER_STATE = Buffer.from('user');
1337
- const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
1338
- const farms = [];
1339
- if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
1340
- const pda = getPda(reserve.state.farmCollateral);
1341
- const account = yield this.kaminoMarket.getConnection().getAccountInfo(pda);
1342
- if (!account) {
1343
- farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
1344
- }
1299
+ async addInitObligationForFarm(reserve, mode, addAsSupportIx = 'setup') {
1300
+ const BASE_SEED_USER_STATE = Buffer.from('user');
1301
+ const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
1302
+ const farms = [];
1303
+ if (mode === types_1.ReserveFarmKind.Collateral && (0, utils_1.isNotNullPubkey)(reserve.state.farmCollateral)) {
1304
+ const pda = getPda(reserve.state.farmCollateral);
1305
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1306
+ if (!account) {
1307
+ farms.push([types_1.ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
1345
1308
  }
1346
- if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
1347
- const pda = getPda(reserve.state.farmDebt);
1348
- const account = yield this.kaminoMarket.getConnection().getAccountInfo(pda);
1349
- if (!account) {
1350
- farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, getPda(reserve.state.farmDebt)]);
1351
- }
1309
+ }
1310
+ if (mode === types_1.ReserveFarmKind.Debt && (0, utils_1.isNotNullPubkey)(reserve.state.farmDebt)) {
1311
+ const pda = getPda(reserve.state.farmDebt);
1312
+ const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
1313
+ if (!account) {
1314
+ farms.push([types_1.ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, getPda(reserve.state.farmDebt)]);
1352
1315
  }
1353
- farms.forEach((arg) => {
1354
- const args = { mode: arg[0] };
1355
- const accounts = {
1356
- owner: this.obligation ? this.obligation.state.owner : this.owner,
1357
- payer: this.owner,
1358
- obligation: this.getObligationPda(),
1359
- lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1360
- reserve: reserve.address,
1361
- reserveFarmState: arg[1],
1362
- obligationFarm: arg[2],
1363
- lendingMarket: this.kaminoMarket.getAddress(),
1364
- farmsProgram: farms_sdk_1.farmsId,
1365
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1366
- systemProgram: web3_js_1.SystemProgram.programId,
1367
- };
1368
- const initObligationForFarm = (0, instructions_1.initObligationFarmsForReserve)(args, accounts, this.kaminoMarket.programId);
1369
- if (addAsSupportIx === 'setup') {
1370
- this.setupIxs.push(initObligationForFarm);
1371
- this.setupIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
1372
- }
1373
- else if (addAsSupportIx === 'inBetween') {
1374
- this.inBetweenIxs.push(initObligationForFarm);
1375
- this.inBetweenIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
1376
- }
1377
- });
1378
- });
1379
- }
1380
- addInitObligationIxs() {
1381
- return __awaiter(this, void 0, void 0, function* () {
1382
- if (!this.obligation) {
1383
- const obligationPda = this.getObligationPda();
1384
- const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
1385
- const initObligationIx = (0, instructions_1.initObligation)({
1386
- args: {
1387
- tag: this.obligationType.toArgs().tag,
1388
- id: this.obligationType.toArgs().id,
1389
- },
1390
- }, {
1391
- obligationOwner: this.owner,
1392
- feePayer: this.payer,
1393
- obligation: obligationPda,
1394
- lendingMarket: this.kaminoMarket.getAddress(),
1395
- seed1Account: this.obligationType.toArgs().seed1,
1396
- seed2Account: this.obligationType.toArgs().seed2,
1397
- ownerUserMetadata: userMetadataAddress,
1398
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1399
- systemProgram: web3_js_1.SystemProgram.programId,
1400
- }, this.kaminoMarket.programId);
1401
- this.setupIxs.push(initObligationIx);
1402
- this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
1316
+ }
1317
+ farms.forEach((arg) => {
1318
+ const args = { mode: arg[0] };
1319
+ const accounts = {
1320
+ owner: this.obligation ? this.obligation.state.owner : this.owner,
1321
+ payer: this.owner,
1322
+ obligation: this.getObligationPda(),
1323
+ lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
1324
+ reserve: reserve.address,
1325
+ reserveFarmState: arg[1],
1326
+ obligationFarm: arg[2],
1327
+ lendingMarket: this.kaminoMarket.getAddress(),
1328
+ farmsProgram: farms_sdk_1.farmsId,
1329
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1330
+ systemProgram: web3_js_1.SystemProgram.programId,
1331
+ };
1332
+ const initObligationForFarm = (0, instructions_1.initObligationFarmsForReserve)(args, accounts, this.kaminoMarket.programId);
1333
+ if (addAsSupportIx === 'setup') {
1334
+ this.setupIxs.push(initObligationForFarm);
1335
+ this.setupIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
1336
+ }
1337
+ else if (addAsSupportIx === 'inBetween') {
1338
+ this.inBetweenIxs.push(initObligationForFarm);
1339
+ this.inBetweenIxsLabels.push(`InitObligationForFarm[${reserve.address.toString()}, ${this.getObligationPda().toString()}]`);
1403
1340
  }
1404
1341
  });
1405
1342
  }
1406
- addInitUserMetadataIxs() {
1407
- return __awaiter(this, void 0, void 0, function* () {
1408
- const [createLutIx, lookupTableAddress] = yield (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
1409
- this.setupIxs.push(createLutIx);
1410
- this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
1343
+ async addInitObligationIxs() {
1344
+ if (!this.obligation) {
1345
+ const obligationPda = this.getObligationPda();
1411
1346
  const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
1412
- const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
1413
- ? this.kaminoMarket.programId
1414
- : (0, utils_1.userMetadataPda)(this.referrer, this.kaminoMarket.programId)[0];
1415
- const initUserMetadataIx = (0, instructions_1.initUserMetadata)({
1416
- userLookupTable: lookupTableAddress,
1347
+ const initObligationIx = (0, instructions_1.initObligation)({
1348
+ args: {
1349
+ tag: this.obligationType.toArgs().tag,
1350
+ id: this.obligationType.toArgs().id,
1351
+ },
1417
1352
  }, {
1418
- owner: this.owner,
1353
+ obligationOwner: this.owner,
1419
1354
  feePayer: this.payer,
1420
- userMetadata: userMetadataAddress,
1421
- referrerUserMetadata: referrerUserMetadataAddress,
1355
+ obligation: obligationPda,
1356
+ lendingMarket: this.kaminoMarket.getAddress(),
1357
+ seed1Account: this.obligationType.toArgs().seed1,
1358
+ seed2Account: this.obligationType.toArgs().seed2,
1359
+ ownerUserMetadata: userMetadataAddress,
1422
1360
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1423
1361
  systemProgram: web3_js_1.SystemProgram.programId,
1424
1362
  }, this.kaminoMarket.programId);
1425
- this.setupIxs.push(initUserMetadataIx);
1426
- this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
1427
- });
1363
+ this.setupIxs.push(initObligationIx);
1364
+ this.setupIxsLabels.push(`InitObligation[${obligationPda.toString()}]`);
1365
+ }
1428
1366
  }
1429
- addInitReferrerTokenStateIxs() {
1430
- return __awaiter(this, arguments, void 0, function* (reservesArr = []) {
1431
- var _a;
1432
- if (this.referrer.equals(web3_js_1.PublicKey.default)) {
1433
- return;
1367
+ async addInitUserMetadataIxs() {
1368
+ const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
1369
+ this.setupIxs.push(createLutIx);
1370
+ this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
1371
+ const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
1372
+ const referrerUserMetadataAddress = this.referrer.equals(web3_js_1.PublicKey.default)
1373
+ ? this.kaminoMarket.programId
1374
+ : (0, utils_1.userMetadataPda)(this.referrer, this.kaminoMarket.programId)[0];
1375
+ const initUserMetadataIx = (0, instructions_1.initUserMetadata)({
1376
+ userLookupTable: lookupTableAddress,
1377
+ }, {
1378
+ owner: this.owner,
1379
+ feePayer: this.payer,
1380
+ userMetadata: userMetadataAddress,
1381
+ referrerUserMetadata: referrerUserMetadataAddress,
1382
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1383
+ systemProgram: web3_js_1.SystemProgram.programId,
1384
+ }, this.kaminoMarket.programId);
1385
+ this.setupIxs.push(initUserMetadataIx);
1386
+ this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
1387
+ }
1388
+ async addInitReferrerTokenStateIxs(reservesArr = []) {
1389
+ if (this.referrer.equals(web3_js_1.PublicKey.default)) {
1390
+ return;
1391
+ }
1392
+ const outflowReserve = this.outflowReserve?.address ? [this.outflowReserve.address] : [];
1393
+ const reserves = reservesArr.length !== 0
1394
+ ? reservesArr.map((reserve) => reserve.address)
1395
+ : new utils_1.PublicKeySet([this.reserve.address, ...outflowReserve]).toArray();
1396
+ const tokenStatesToCreate = [];
1397
+ for (const reserve of reserves) {
1398
+ if (!reserve) {
1399
+ continue;
1434
1400
  }
1435
- const outflowReserve = ((_a = this.outflowReserve) === null || _a === void 0 ? void 0 : _a.address) ? [this.outflowReserve.address] : [];
1436
- const reserves = reservesArr.length !== 0
1437
- ? reservesArr.map((reserve) => reserve.address)
1438
- : new utils_1.PublicKeySet([this.reserve.address, ...outflowReserve]).toArray();
1439
- const tokenStatesToCreate = [];
1440
- for (const reserve of reserves) {
1441
- if (!reserve) {
1442
- continue;
1443
- }
1444
- const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.referrer, reserve, this.kaminoMarket.programId)[0];
1445
- if (!(yield (0, utils_1.checkIfAccountExists)(this.kaminoMarket.getConnection(), referrerTokenStateAddress))) {
1446
- tokenStatesToCreate.push([referrerTokenStateAddress, reserve]);
1447
- }
1401
+ const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.referrer, reserve, this.kaminoMarket.programId)[0];
1402
+ if (!(await (0, utils_1.checkIfAccountExists)(this.kaminoMarket.getConnection(), referrerTokenStateAddress))) {
1403
+ tokenStatesToCreate.push([referrerTokenStateAddress, reserve]);
1448
1404
  }
1449
- tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
1450
- const initreferrerTokenStateIx = (0, instructions_1.initReferrerTokenState)({
1451
- referrer: this.referrer,
1452
- }, {
1453
- lendingMarket: this.kaminoMarket.getAddress(),
1454
- payer: this.owner,
1455
- reserve: reserveAddress,
1456
- referrerTokenState: referrerTokenStateAddress,
1457
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1458
- systemProgram: web3_js_1.SystemProgram.programId,
1459
- }, this.kaminoMarket.programId);
1460
- this.setupIxs.unshift(initreferrerTokenStateIx);
1461
- this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenStateAddress.toString()} res=${reserveAddress}]`);
1462
- });
1405
+ }
1406
+ tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
1407
+ const initreferrerTokenStateIx = (0, instructions_1.initReferrerTokenState)({
1408
+ referrer: this.referrer,
1409
+ }, {
1410
+ lendingMarket: this.kaminoMarket.getAddress(),
1411
+ payer: this.owner,
1412
+ reserve: reserveAddress,
1413
+ referrerTokenState: referrerTokenStateAddress,
1414
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1415
+ systemProgram: web3_js_1.SystemProgram.programId,
1416
+ }, this.kaminoMarket.programId);
1417
+ this.setupIxs.unshift(initreferrerTokenStateIx);
1418
+ this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenStateAddress.toString()} res=${reserveAddress}]`);
1463
1419
  });
1464
1420
  }
1465
1421
  addWithdrawReferrerFeesIxs() {
@@ -1482,242 +1438,232 @@ class KaminoAction {
1482
1438
  this.setupIxs.push((0, utils_1.buildComputeBudgetIx)(units));
1483
1439
  this.setupIxsLabels.push(`AddComputeBudget[${units}]`);
1484
1440
  }
1485
- addAtaIxs(action) {
1486
- return __awaiter(this, void 0, void 0, function* () {
1487
- var _a, _b;
1488
- if (this.mint.equals(utils_1.WRAPPED_SOL_MINT) || ((_a = this.secondaryMint) === null || _a === void 0 ? void 0 : _a.equals(utils_1.WRAPPED_SOL_MINT))) {
1489
- yield this.updateWSOLAccount(action);
1490
- }
1491
- if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1492
- const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1493
- if (!userTokenAccountInfo) {
1494
- const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1495
- if (this.positions === exports.POSITION_LIMIT) {
1496
- this.preTxnIxs.push(createUserTokenAccountIx);
1497
- this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
1498
- }
1499
- else {
1500
- this.setupIxs.unshift(createUserTokenAccountIx);
1501
- this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
1502
- }
1503
- }
1504
- }
1505
- if (action === 'liquidate') {
1506
- const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1507
- if (!this.outflowReserve) {
1508
- throw new Error(`Outflow reserve state not found ${this.mint}`);
1509
- }
1510
- if (!userTokenAccountInfo) {
1511
- const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1512
- if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1513
- this.preTxnIxs.push(createUserTokenAccountIx);
1514
- this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
1515
- }
1516
- else {
1517
- this.setupIxs.unshift(createUserTokenAccountIx);
1518
- this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
1519
- }
1520
- }
1521
- const userCollateralAccountInfo = yield this.kaminoMarket
1522
- .getConnection()
1523
- .getAccountInfo(this.userCollateralAccountAddress);
1524
- if (!userCollateralAccountInfo) {
1525
- const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
1526
- if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1527
- this.preTxnIxs.push(createUserCollateralAccountIx);
1528
- this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1529
- }
1530
- else {
1531
- this.setupIxs.unshift(createUserCollateralAccountIx);
1532
- this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1533
- }
1534
- }
1535
- if (!this.additionalTokenAccountAddress) {
1536
- throw new Error(`Additional token account address not found ${this.mint}`);
1537
- }
1538
- }
1539
- if (action === 'depositAndBorrow' ||
1540
- (action === 'repayAndWithdraw' && !((_b = this.secondaryMint) === null || _b === void 0 ? void 0 : _b.equals(utils_1.WRAPPED_SOL_MINT)))) {
1541
- if (!this.additionalTokenAccountAddress) {
1542
- throw new Error(`Additional token account address not found ${this.secondaryMint}`);
1543
- }
1544
- if (!this.outflowReserve) {
1545
- throw new Error(`Outflow reserve state not found ${this.mint}`);
1441
+ async addAtaIxs(action) {
1442
+ if (this.mint.equals(utils_1.WRAPPED_SOL_MINT) || this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)) {
1443
+ await this.updateWSOLAccount(action);
1444
+ }
1445
+ if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1446
+ const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1447
+ if (!userTokenAccountInfo) {
1448
+ const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1449
+ if (this.positions === exports.POSITION_LIMIT) {
1450
+ this.preTxnIxs.push(createUserTokenAccountIx);
1451
+ this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
1546
1452
  }
1547
- const additionalUserTokenAccountInfo = yield this.kaminoMarket
1548
- .getConnection()
1549
- .getAccountInfo(this.additionalTokenAccountAddress);
1550
- if (!additionalUserTokenAccountInfo) {
1551
- const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.additionalTokenAccountAddress);
1453
+ else {
1552
1454
  this.setupIxs.unshift(createUserTokenAccountIx);
1553
- this.setupIxsLabels.unshift(`CreateAdditionalUserTokenAta[${this.owner}]`);
1455
+ this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
1554
1456
  }
1555
1457
  }
1556
- if (action === 'withdraw' || action === 'mint' || action === 'deposit' || action === 'repayAndWithdraw') {
1557
- const userTokenAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1558
- // TODO: Might need to remove this
1559
- if (!userTokenAccountInfo) {
1560
- const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1458
+ }
1459
+ if (action === 'liquidate') {
1460
+ const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1461
+ if (!this.outflowReserve) {
1462
+ throw new Error(`Outflow reserve state not found ${this.mint}`);
1463
+ }
1464
+ if (!userTokenAccountInfo) {
1465
+ const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1466
+ if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1561
1467
  this.preTxnIxs.push(createUserTokenAccountIx);
1562
1468
  this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
1563
1469
  }
1470
+ else {
1471
+ this.setupIxs.unshift(createUserTokenAccountIx);
1472
+ this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
1473
+ }
1564
1474
  }
1565
- if (action === 'mint') {
1566
- const userCollateralAccountInfo = yield this.kaminoMarket
1567
- .getConnection()
1568
- .getAccountInfo(this.userCollateralAccountAddress);
1569
- if (!userCollateralAccountInfo) {
1570
- const collateralMintPubkey = this.reserve.getCTokenMint();
1571
- const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
1572
- if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1573
- this.preTxnIxs.push(createUserCollateralAccountIx);
1574
- this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1575
- }
1576
- else {
1577
- this.setupIxs.unshift(createUserCollateralAccountIx);
1578
- this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1579
- }
1475
+ const userCollateralAccountInfo = await this.kaminoMarket
1476
+ .getConnection()
1477
+ .getAccountInfo(this.userCollateralAccountAddress);
1478
+ if (!userCollateralAccountInfo) {
1479
+ const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
1480
+ if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1481
+ this.preTxnIxs.push(createUserCollateralAccountIx);
1482
+ this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1483
+ }
1484
+ else {
1485
+ this.setupIxs.unshift(createUserCollateralAccountIx);
1486
+ this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1580
1487
  }
1581
1488
  }
1582
- });
1583
- }
1584
- updateWSOLAccount(action) {
1585
- return __awaiter(this, void 0, void 0, function* () {
1586
- var _a, _b;
1587
- const preIxs = [];
1588
- const postIxs = [];
1589
- const preIxsLabels = [];
1590
- const postIxsLabels = [];
1591
- if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1592
- return;
1489
+ if (!this.additionalTokenAccountAddress) {
1490
+ throw new Error(`Additional token account address not found ${this.mint}`);
1593
1491
  }
1594
- let safeRepay = new bn_js_1.default(this.amount);
1595
- if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1596
- const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
1597
- if (!borrow) {
1598
- throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
1599
- }
1600
- const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
1601
- const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
1602
- // TODO: shouldn't this calc be added to all other stuff as well?
1603
- safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
1604
- .mul(cumulativeBorrowRateReserve)
1605
- .div(cumulativeBorrowRateObligation)
1606
- .add(new decimal_js_1.default(SOL_PADDING_FOR_INTEREST.toString()))
1607
- .toNumber()).toString());
1492
+ }
1493
+ if (action === 'depositAndBorrow' ||
1494
+ (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT))) {
1495
+ if (!this.additionalTokenAccountAddress) {
1496
+ throw new Error(`Additional token account address not found ${this.secondaryMint}`);
1608
1497
  }
1609
- let userTokenAccountAddress = this.userTokenAccountAddress;
1610
- if ((_a = this.secondaryMint) === null || _a === void 0 ? void 0 : _a.equals(utils_1.WRAPPED_SOL_MINT)) {
1611
- if (!this.additionalTokenAccountAddress) {
1612
- throw new Error(`Additional token account address not found ${this.secondaryMint}`);
1613
- }
1614
- userTokenAccountAddress = this.additionalTokenAccountAddress;
1498
+ if (!this.outflowReserve) {
1499
+ throw new Error(`Outflow reserve state not found ${this.mint}`);
1615
1500
  }
1616
- const userWSOLAccountInfo = yield this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
1617
- const rentExempt = yield this.kaminoMarket.getConnection().getMinimumBalanceForRentExemption(165);
1618
- // Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
1619
- const sendAction = action === 'deposit' ||
1620
- action === 'repay' ||
1621
- action === 'mint' ||
1622
- (action === 'liquidate' && ((_b = this.secondaryMint) === null || _b === void 0 ? void 0 : _b.equals(utils_1.WRAPPED_SOL_MINT))); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
1623
- const transferLamportsIx = web3_js_1.SystemProgram.transfer({
1624
- fromPubkey: this.owner,
1625
- toPubkey: userTokenAccountAddress,
1626
- lamports: (userWSOLAccountInfo ? 0 : rentExempt) + (sendAction ? parseInt(safeRepay.toString(), 10) : 0),
1627
- });
1628
- preIxs.push(transferLamportsIx);
1629
- preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
1630
- const closeWSOLAccountIx = (0, spl_token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, [], spl_token_1.TOKEN_PROGRAM_ID);
1631
- const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
1632
- if (userWSOLAccountInfo) {
1633
- if (sendAction) {
1634
- preIxs.push(syncIx);
1635
- preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
1501
+ const additionalUserTokenAccountInfo = await this.kaminoMarket
1502
+ .getConnection()
1503
+ .getAccountInfo(this.additionalTokenAccountAddress);
1504
+ if (!additionalUserTokenAccountInfo) {
1505
+ const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.additionalTokenAccountAddress);
1506
+ this.setupIxs.unshift(createUserTokenAccountIx);
1507
+ this.setupIxsLabels.unshift(`CreateAdditionalUserTokenAta[${this.owner}]`);
1508
+ }
1509
+ }
1510
+ if (action === 'withdraw' || action === 'mint' || action === 'deposit' || action === 'repayAndWithdraw') {
1511
+ const userTokenAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(this.userTokenAccountAddress);
1512
+ // TODO: Might need to remove this
1513
+ if (!userTokenAccountInfo) {
1514
+ const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.userTokenAccountAddress);
1515
+ this.preTxnIxs.push(createUserTokenAccountIx);
1516
+ this.preTxnIxsLabels.push(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
1517
+ }
1518
+ }
1519
+ if (action === 'mint') {
1520
+ const userCollateralAccountInfo = await this.kaminoMarket
1521
+ .getConnection()
1522
+ .getAccountInfo(this.userCollateralAccountAddress);
1523
+ if (!userCollateralAccountInfo) {
1524
+ const collateralMintPubkey = this.reserve.getCTokenMint();
1525
+ const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
1526
+ if (this.positions === exports.POSITION_LIMIT && this.mint.equals(utils_1.WRAPPED_SOL_MINT)) {
1527
+ this.preTxnIxs.push(createUserCollateralAccountIx);
1528
+ this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1636
1529
  }
1637
1530
  else {
1638
- postIxs.push(closeWSOLAccountIx);
1639
- postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
1531
+ this.setupIxs.unshift(createUserCollateralAccountIx);
1532
+ this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
1640
1533
  }
1641
1534
  }
1642
- else {
1643
- const [, createUserWSOLAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, spl_token_1.NATIVE_MINT, this.owner, spl_token_1.TOKEN_PROGRAM_ID, userTokenAccountAddress);
1644
- preIxs.push(createUserWSOLAccountIx);
1645
- preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
1535
+ }
1536
+ }
1537
+ async updateWSOLAccount(action) {
1538
+ const preIxs = [];
1539
+ const postIxs = [];
1540
+ const preIxsLabels = [];
1541
+ const postIxsLabels = [];
1542
+ if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
1543
+ return;
1544
+ }
1545
+ let safeRepay = new bn_js_1.default(this.amount);
1546
+ if (this.obligation && action === 'repay' && this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
1547
+ const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
1548
+ if (!borrow) {
1549
+ throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
1550
+ }
1551
+ const cumulativeBorrowRateObligation = obligation_1.KaminoObligation.getCumulativeBorrowRate(borrow);
1552
+ const cumulativeBorrowRateReserve = this.reserve.getEstimatedCumulativeBorrowRate(this.currentSlot, this.kaminoMarket.state.referralFeeBps);
1553
+ // TODO: shouldn't this calc be added to all other stuff as well?
1554
+ safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
1555
+ .mul(cumulativeBorrowRateReserve)
1556
+ .div(cumulativeBorrowRateObligation)
1557
+ .add(new decimal_js_1.default(SOL_PADDING_FOR_INTEREST.toString()))
1558
+ .toNumber()).toString());
1559
+ }
1560
+ let userTokenAccountAddress = this.userTokenAccountAddress;
1561
+ if (this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)) {
1562
+ if (!this.additionalTokenAccountAddress) {
1563
+ throw new Error(`Additional token account address not found ${this.secondaryMint}`);
1564
+ }
1565
+ userTokenAccountAddress = this.additionalTokenAccountAddress;
1566
+ }
1567
+ const userWSOLAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
1568
+ const rentExempt = await this.kaminoMarket.getConnection().getMinimumBalanceForRentExemption(165);
1569
+ // Add rent exemption lamports for WSOL accounts that need to be pre-funded for inflow/send transactions
1570
+ const sendAction = action === 'deposit' ||
1571
+ action === 'repay' ||
1572
+ action === 'mint' ||
1573
+ (action === 'liquidate' && this.secondaryMint?.equals(utils_1.WRAPPED_SOL_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
1574
+ const transferLamportsIx = web3_js_1.SystemProgram.transfer({
1575
+ fromPubkey: this.owner,
1576
+ toPubkey: userTokenAccountAddress,
1577
+ lamports: (userWSOLAccountInfo ? 0 : rentExempt) + (sendAction ? parseInt(safeRepay.toString(), 10) : 0),
1578
+ });
1579
+ preIxs.push(transferLamportsIx);
1580
+ preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
1581
+ const closeWSOLAccountIx = (0, spl_token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, [], spl_token_1.TOKEN_PROGRAM_ID);
1582
+ const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
1583
+ if (userWSOLAccountInfo) {
1584
+ if (sendAction) {
1646
1585
  preIxs.push(syncIx);
1647
1586
  preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
1587
+ }
1588
+ else {
1648
1589
  postIxs.push(closeWSOLAccountIx);
1649
1590
  postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
1650
1591
  }
1651
- // TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
1652
- // if (this.positions && this.positions >= POSITION_LIMIT) {
1653
- // this.preTxnIxs.push(...preIxs);
1654
- // this.preTxnIxsLabels.push(...preIxsLabels);
1655
- // this.postTxnIxs.push(...postIxs);
1656
- // this.postTxnIxsLabels.push(...postIxsLabels);
1657
- // } else {
1658
- // }
1659
- this.setupIxs.unshift(...preIxs);
1660
- this.setupIxsLabels.unshift(...preIxsLabels);
1661
- this.cleanupIxs.push(...postIxs);
1662
- this.cleanupIxsLabels.push(...postIxsLabels);
1663
- });
1592
+ }
1593
+ else {
1594
+ const [, createUserWSOLAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, spl_token_1.NATIVE_MINT, this.owner, spl_token_1.TOKEN_PROGRAM_ID, userTokenAccountAddress);
1595
+ preIxs.push(createUserWSOLAccountIx);
1596
+ preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
1597
+ preIxs.push(syncIx);
1598
+ preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
1599
+ postIxs.push(closeWSOLAccountIx);
1600
+ postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
1601
+ }
1602
+ // TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
1603
+ // if (this.positions && this.positions >= POSITION_LIMIT) {
1604
+ // this.preTxnIxs.push(...preIxs);
1605
+ // this.preTxnIxsLabels.push(...preIxsLabels);
1606
+ // this.postTxnIxs.push(...postIxs);
1607
+ // this.postTxnIxsLabels.push(...postIxsLabels);
1608
+ // } else {
1609
+ // }
1610
+ this.setupIxs.unshift(...preIxs);
1611
+ this.setupIxsLabels.unshift(...preIxsLabels);
1612
+ this.cleanupIxs.push(...postIxs);
1613
+ this.cleanupIxsLabels.push(...postIxsLabels);
1664
1614
  }
1665
- static initializeMultiTokenAction(kaminoMarket_1, action_1, inflowAmount_1, inflowTokenMint_1, outflowTokenMint_1, payer_1, obligationOwner_1, obligation_2, outflowAmount_1) {
1666
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1667
- const inflowReserve = kaminoMarket.getReserveByMint(inflowTokenMint);
1668
- const outflowReserve = kaminoMarket.getReserveByMint(outflowTokenMint);
1669
- if (!outflowReserve || !inflowReserve) {
1670
- throw new Error('reserve states are not fetched');
1671
- }
1672
- const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
1673
- const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
1674
- const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
1675
- const referrerKey = yield this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
1676
- let userTokenAccountAddress;
1677
- let userCollateralAccountAddress;
1678
- let additionalUserTokenAccountAddress;
1679
- let secondaryMint;
1680
- let primaryMint;
1681
- if (action === 'liquidate') {
1682
- userTokenAccountAddress = userOutflowTokenAccountAddress;
1683
- userCollateralAccountAddress = userOutflowCollateralAccountAddress;
1684
- additionalUserTokenAccountAddress = userInflowTokenAccountAddress;
1685
- primaryMint = outflowTokenMint;
1686
- secondaryMint = inflowTokenMint;
1687
- }
1688
- else if (action === 'depositAndBorrow') {
1689
- userTokenAccountAddress = userInflowTokenAccountAddress;
1690
- userCollateralAccountAddress = userInflowCollateralAccountAddress;
1691
- additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
1692
- primaryMint = inflowTokenMint;
1693
- secondaryMint = outflowTokenMint;
1694
- }
1695
- else if (action === 'repayAndWithdraw') {
1696
- primaryMint = inflowTokenMint;
1697
- secondaryMint = outflowTokenMint;
1698
- userTokenAccountAddress = userInflowTokenAccountAddress;
1699
- userCollateralAccountAddress = userOutflowCollateralAccountAddress;
1700
- additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
1701
- }
1702
- else {
1703
- throw new Error('Invalid action');
1704
- }
1705
- return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
1706
- });
1615
+ static async initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1616
+ const inflowReserve = kaminoMarket.getReserveByMint(inflowTokenMint);
1617
+ const outflowReserve = kaminoMarket.getReserveByMint(outflowTokenMint);
1618
+ if (!outflowReserve || !inflowReserve) {
1619
+ throw new Error('reserve states are not fetched');
1620
+ }
1621
+ const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
1622
+ const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
1623
+ const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
1624
+ const referrerKey = await this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
1625
+ let userTokenAccountAddress;
1626
+ let userCollateralAccountAddress;
1627
+ let additionalUserTokenAccountAddress;
1628
+ let secondaryMint;
1629
+ let primaryMint;
1630
+ if (action === 'liquidate') {
1631
+ userTokenAccountAddress = userOutflowTokenAccountAddress;
1632
+ userCollateralAccountAddress = userOutflowCollateralAccountAddress;
1633
+ additionalUserTokenAccountAddress = userInflowTokenAccountAddress;
1634
+ primaryMint = outflowTokenMint;
1635
+ secondaryMint = inflowTokenMint;
1636
+ }
1637
+ else if (action === 'depositAndBorrow') {
1638
+ userTokenAccountAddress = userInflowTokenAccountAddress;
1639
+ userCollateralAccountAddress = userInflowCollateralAccountAddress;
1640
+ additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
1641
+ primaryMint = inflowTokenMint;
1642
+ secondaryMint = outflowTokenMint;
1643
+ }
1644
+ else if (action === 'repayAndWithdraw') {
1645
+ primaryMint = inflowTokenMint;
1646
+ secondaryMint = outflowTokenMint;
1647
+ userTokenAccountAddress = userInflowTokenAccountAddress;
1648
+ userCollateralAccountAddress = userOutflowCollateralAccountAddress;
1649
+ additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
1650
+ }
1651
+ else {
1652
+ throw new Error('Invalid action');
1653
+ }
1654
+ return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
1707
1655
  }
1708
- static initializeWithdrawReferrerFees(mint_1, owner_1, kaminoMarket_1) {
1709
- return __awaiter(this, arguments, void 0, function* (mint, owner, kaminoMarket, currentSlot = 0) {
1710
- const reserve = kaminoMarket.getReserveByMint(mint);
1711
- if (reserve === undefined) {
1712
- throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
1713
- }
1714
- const { atas, createAtasIxns } = yield (0, utils_1.getAtasWithCreateIxnsIfMissing)(kaminoMarket.getConnection(), owner, [reserve.getLiquidityMint()], [reserve.getLiquidityTokenProgram()]);
1715
- const userTokenAccountAddress = atas[0];
1716
- return {
1717
- axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), userTokenAccountAddress, web3_js_1.PublicKey.default, mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
1718
- createAtasIxns,
1719
- };
1720
- });
1656
+ static async initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0) {
1657
+ const reserve = kaminoMarket.getReserveByMint(mint);
1658
+ if (reserve === undefined) {
1659
+ throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
1660
+ }
1661
+ const { atas, createAtasIxns } = await (0, utils_1.getAtasWithCreateIxnsIfMissing)(kaminoMarket.getConnection(), owner, [reserve.getLiquidityMint()], [reserve.getLiquidityTokenProgram()]);
1662
+ const userTokenAccountAddress = atas[0];
1663
+ return {
1664
+ axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), userTokenAccountAddress, web3_js_1.PublicKey.default, mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
1665
+ createAtasIxns,
1666
+ };
1721
1667
  }
1722
1668
  getObligationPda() {
1723
1669
  return this.obligation
@@ -1741,22 +1687,20 @@ class KaminoAction {
1741
1687
  }
1742
1688
  return depositReservesList;
1743
1689
  }
1744
- static getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer) {
1745
- return __awaiter(this, void 0, void 0, function* () {
1746
- let referrerKey = referrer;
1747
- if (!referrer || referrer.equals(web3_js_1.PublicKey.default)) {
1748
- if (kaminoObligation === null) {
1749
- const [_, userMetadata] = yield kaminoMarket.getUserMetadata(owner);
1750
- if (userMetadata) {
1751
- referrerKey = userMetadata.referrer;
1752
- }
1753
- }
1754
- else {
1755
- referrerKey = kaminoObligation.state.referrer;
1690
+ static async getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer) {
1691
+ let referrerKey = referrer;
1692
+ if (!referrer || referrer.equals(web3_js_1.PublicKey.default)) {
1693
+ if (kaminoObligation === null) {
1694
+ const [_, userMetadata] = await kaminoMarket.getUserMetadata(owner);
1695
+ if (userMetadata) {
1696
+ referrerKey = userMetadata.referrer;
1756
1697
  }
1757
1698
  }
1758
- return referrerKey;
1759
- });
1699
+ else {
1700
+ referrerKey = kaminoObligation.state.referrer;
1701
+ }
1702
+ }
1703
+ return referrerKey;
1760
1704
  }
1761
1705
  }
1762
1706
  exports.KaminoAction = KaminoAction;