@kamino-finance/klend-sdk 7.4.0-beta.1 → 7.4.0-beta.2

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 (286) hide show
  1. package/dist/@codegen/klend/accounts/LendingMarket.d.ts +51 -3
  2. package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
  3. package/dist/@codegen/klend/accounts/LendingMarket.js +39 -6
  4. package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
  5. package/dist/@codegen/klend/accounts/Obligation.d.ts +24 -15
  6. package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
  7. package/dist/@codegen/klend/accounts/Obligation.js +24 -21
  8. package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
  9. package/dist/@codegen/klend/accounts/Reserve.js +1 -1
  10. package/dist/@codegen/klend/accounts/UserState.d.ts +0 -75
  11. package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
  12. package/dist/@codegen/klend/accounts/UserState.js +0 -25
  13. package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
  14. package/dist/@codegen/klend/errors/custom.d.ts +89 -1
  15. package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
  16. package/dist/@codegen/klend/errors/custom.js +155 -1
  17. package/dist/@codegen/klend/errors/custom.js.map +1 -1
  18. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +36 -0
  19. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +1 -0
  20. package/dist/@codegen/klend/instructions/fillBorrowOrder.js +49 -0
  21. package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +1 -0
  22. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +0 -1
  23. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
  24. package/dist/@codegen/klend/instructions/idlMissingTypes.js +0 -2
  25. package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
  26. package/dist/@codegen/klend/instructions/index.d.ts +4 -0
  27. package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
  28. package/dist/@codegen/klend/instructions/index.js +6 -1
  29. package/dist/@codegen/klend/instructions/index.js.map +1 -1
  30. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +33 -0
  31. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +1 -0
  32. package/dist/@codegen/klend/instructions/setBorrowOrder.js +66 -0
  33. package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +1 -0
  34. package/dist/@codegen/klend/types/BorrowOrder.d.ts +192 -0
  35. package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -0
  36. package/dist/@codegen/klend/types/BorrowOrder.js +194 -0
  37. package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -0
  38. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +39 -0
  39. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -0
  40. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +100 -0
  41. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -0
  42. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +35 -5
  43. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
  44. package/dist/@codegen/klend/types/ObligationLiquidity.js +17 -7
  45. package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
  46. package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
  47. package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
  48. package/dist/@codegen/klend/types/ReserveConfig.d.ts +60 -5
  49. package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
  50. package/dist/@codegen/klend/types/ReserveConfig.js +36 -7
  51. package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
  52. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +33 -7
  53. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
  54. package/dist/@codegen/klend/types/UpdateConfigMode.js +61 -13
  55. package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
  56. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +52 -0
  57. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
  58. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +97 -1
  59. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
  60. package/dist/@codegen/klend/types/index.d.ts +8 -8
  61. package/dist/@codegen/klend/types/index.d.ts.map +1 -1
  62. package/dist/@codegen/klend/types/index.js +5 -3
  63. package/dist/@codegen/klend/types/index.js.map +1 -1
  64. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +8 -5
  65. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
  66. package/dist/@codegen/klend/zero_padding/ObligationZP.js +17 -14
  67. package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
  68. package/dist/@codegen/kvault/accounts/LendingMarket.d.ts +480 -0
  69. package/dist/@codegen/kvault/accounts/LendingMarket.d.ts.map +1 -0
  70. package/dist/@codegen/kvault/accounts/LendingMarket.js +480 -0
  71. package/dist/@codegen/kvault/accounts/LendingMarket.js.map +1 -0
  72. package/dist/@codegen/kvault/accounts/Obligation.d.ts +208 -0
  73. package/dist/@codegen/kvault/accounts/Obligation.d.ts.map +1 -0
  74. package/dist/@codegen/kvault/accounts/Obligation.js +298 -0
  75. package/dist/@codegen/kvault/accounts/Obligation.js.map +1 -0
  76. package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts +51 -0
  77. package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts.map +1 -0
  78. package/dist/@codegen/kvault/accounts/ReferrerTokenState.js +137 -0
  79. package/dist/@codegen/kvault/accounts/ReferrerTokenState.js.map +1 -0
  80. package/dist/@codegen/kvault/accounts/Reserve.d.ts +6 -0
  81. package/dist/@codegen/kvault/accounts/Reserve.d.ts.map +1 -1
  82. package/dist/@codegen/kvault/accounts/Reserve.js +9 -2
  83. package/dist/@codegen/kvault/accounts/Reserve.js.map +1 -1
  84. package/dist/@codegen/kvault/accounts/VaultState.d.ts +45 -3
  85. package/dist/@codegen/kvault/accounts/VaultState.d.ts.map +1 -1
  86. package/dist/@codegen/kvault/accounts/VaultState.js +28 -4
  87. package/dist/@codegen/kvault/accounts/VaultState.js.map +1 -1
  88. package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts +144 -0
  89. package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts.map +1 -0
  90. package/dist/@codegen/kvault/accounts/WithdrawTicket.js +205 -0
  91. package/dist/@codegen/kvault/accounts/WithdrawTicket.js.map +1 -0
  92. package/dist/@codegen/kvault/accounts/index.d.ts +8 -0
  93. package/dist/@codegen/kvault/accounts/index.d.ts.map +1 -1
  94. package/dist/@codegen/kvault/accounts/index.js +9 -1
  95. package/dist/@codegen/kvault/accounts/index.js.map +1 -1
  96. package/dist/@codegen/kvault/errors/custom.d.ts +81 -1
  97. package/dist/@codegen/kvault/errors/custom.d.ts.map +1 -1
  98. package/dist/@codegen/kvault/errors/custom.js +141 -1
  99. package/dist/@codegen/kvault/errors/custom.js.map +1 -1
  100. package/dist/@codegen/kvault/instructions/index.d.ts +4 -0
  101. package/dist/@codegen/kvault/instructions/index.d.ts.map +1 -1
  102. package/dist/@codegen/kvault/instructions/index.js +5 -1
  103. package/dist/@codegen/kvault/instructions/index.js.map +1 -1
  104. package/dist/@codegen/kvault/instructions/invest.d.ts +9 -0
  105. package/dist/@codegen/kvault/instructions/invest.d.ts.map +1 -1
  106. package/dist/@codegen/kvault/instructions/invest.js +7 -0
  107. package/dist/@codegen/kvault/instructions/invest.js.map +1 -1
  108. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts +51 -0
  109. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts.map +1 -0
  110. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js +154 -0
  111. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js.map +1 -0
  112. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts +54 -0
  113. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts.map +1 -0
  114. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js +166 -0
  115. package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js.map +1 -0
  116. package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts +1 -0
  117. package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts.map +1 -0
  118. package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js +72 -0
  119. package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js.map +1 -0
  120. package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts +3 -1
  121. package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts.map +1 -1
  122. package/dist/@codegen/kvault/instructions/updateReserveAllocation.js +3 -0
  123. package/dist/@codegen/kvault/instructions/updateReserveAllocation.js.map +1 -1
  124. package/dist/@codegen/kvault/types/BorrowOrder.d.ts +192 -0
  125. package/dist/@codegen/kvault/types/BorrowOrder.d.ts.map +1 -0
  126. package/dist/@codegen/kvault/types/BorrowOrder.js +194 -0
  127. package/dist/@codegen/kvault/types/BorrowOrder.js.map +1 -0
  128. package/dist/@codegen/kvault/types/ElevationGroup.d.ts +67 -0
  129. package/dist/@codegen/kvault/types/ElevationGroup.d.ts.map +1 -0
  130. package/dist/@codegen/kvault/types/ElevationGroup.js +137 -0
  131. package/dist/@codegen/kvault/types/ElevationGroup.js.map +1 -0
  132. package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts +145 -0
  133. package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts.map +1 -0
  134. package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js +144 -0
  135. package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js.map +1 -0
  136. package/dist/@codegen/kvault/types/ObligationCollateral.d.ts +72 -0
  137. package/dist/@codegen/kvault/types/ObligationCollateral.d.ts.map +1 -0
  138. package/dist/@codegen/kvault/types/ObligationCollateral.js +119 -0
  139. package/dist/@codegen/kvault/types/ObligationCollateral.js.map +1 -0
  140. package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts +143 -0
  141. package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts.map +1 -0
  142. package/dist/@codegen/kvault/types/ObligationLiquidity.js +165 -0
  143. package/dist/@codegen/kvault/types/ObligationLiquidity.js.map +1 -0
  144. package/dist/@codegen/kvault/types/ObligationOrder.d.ts +284 -0
  145. package/dist/@codegen/kvault/types/ObligationOrder.d.ts.map +1 -0
  146. package/dist/@codegen/kvault/types/ObligationOrder.js +205 -0
  147. package/dist/@codegen/kvault/types/ObligationOrder.js.map +1 -0
  148. package/dist/@codegen/kvault/types/ReserveConfig.d.ts +60 -5
  149. package/dist/@codegen/kvault/types/ReserveConfig.d.ts.map +1 -1
  150. package/dist/@codegen/kvault/types/ReserveConfig.js +36 -7
  151. package/dist/@codegen/kvault/types/ReserveConfig.js.map +1 -1
  152. package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts +26 -8
  153. package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts.map +1 -1
  154. package/dist/@codegen/kvault/types/ReserveLiquidity.js +14 -8
  155. package/dist/@codegen/kvault/types/ReserveLiquidity.js.map +1 -1
  156. package/dist/@codegen/kvault/types/ReserveType.d.ts +32 -0
  157. package/dist/@codegen/kvault/types/ReserveType.d.ts.map +1 -0
  158. package/dist/@codegen/{klend/types/AssetTier.js → kvault/types/ReserveType.js} +24 -48
  159. package/dist/@codegen/kvault/types/ReserveType.js.map +1 -0
  160. package/dist/@codegen/kvault/types/VaultAllocation.d.ts +60 -0
  161. package/dist/@codegen/kvault/types/VaultAllocation.d.ts.map +1 -1
  162. package/dist/@codegen/kvault/types/VaultAllocation.js +38 -2
  163. package/dist/@codegen/kvault/types/VaultAllocation.js.map +1 -1
  164. package/dist/@codegen/kvault/types/WithdrawQueue.d.ts +64 -0
  165. package/dist/@codegen/kvault/types/WithdrawQueue.d.ts.map +1 -0
  166. package/dist/@codegen/kvault/types/WithdrawQueue.js +104 -0
  167. package/dist/@codegen/kvault/types/WithdrawQueue.js.map +1 -0
  168. package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts +19 -0
  169. package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts.map +1 -0
  170. package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js +82 -0
  171. package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js.map +1 -0
  172. package/dist/@codegen/kvault/types/index.d.ts +34 -0
  173. package/dist/@codegen/kvault/types/index.d.ts.map +1 -1
  174. package/dist/@codegen/kvault/types/index.js +19 -1
  175. package/dist/@codegen/kvault/types/index.js.map +1 -1
  176. package/dist/classes/manager.d.ts.map +1 -1
  177. package/dist/classes/manager.js +4 -0
  178. package/dist/classes/manager.js.map +1 -1
  179. package/dist/classes/market.d.ts +110 -10
  180. package/dist/classes/market.d.ts.map +1 -1
  181. package/dist/classes/market.js +165 -13
  182. package/dist/classes/market.js.map +1 -1
  183. package/dist/classes/obligation.d.ts +2 -2
  184. package/dist/classes/obligation.d.ts.map +1 -1
  185. package/dist/classes/obligation.js +9 -7
  186. package/dist/classes/obligation.js.map +1 -1
  187. package/dist/classes/reserve.d.ts +9 -1
  188. package/dist/classes/reserve.d.ts.map +1 -1
  189. package/dist/classes/reserve.js +23 -1
  190. package/dist/classes/reserve.js.map +1 -1
  191. package/dist/classes/utils.d.ts +2 -0
  192. package/dist/classes/utils.d.ts.map +1 -1
  193. package/dist/classes/utils.js +12 -1
  194. package/dist/classes/utils.js.map +1 -1
  195. package/dist/classes/vault.d.ts +4 -2
  196. package/dist/classes/vault.d.ts.map +1 -1
  197. package/dist/classes/vault.js +12 -2
  198. package/dist/classes/vault.js.map +1 -1
  199. package/dist/idl/klend.json +581 -54
  200. package/dist/manager/client_kamino_manager.js +12 -8
  201. package/dist/manager/client_kamino_manager.js.map +1 -1
  202. package/dist/obligation_orders/price_based.js +5 -4
  203. package/dist/obligation_orders/price_based.js.map +1 -1
  204. package/dist/utils/ReserveKind.d.ts +57 -0
  205. package/dist/utils/ReserveKind.d.ts.map +1 -0
  206. package/dist/utils/ReserveKind.js +76 -0
  207. package/dist/utils/ReserveKind.js.map +1 -0
  208. package/dist/utils/index.d.ts +1 -0
  209. package/dist/utils/index.d.ts.map +1 -1
  210. package/dist/utils/index.js +1 -0
  211. package/dist/utils/index.js.map +1 -1
  212. package/dist/utils/managerTypes.d.ts.map +1 -1
  213. package/dist/utils/managerTypes.js +3 -1
  214. package/dist/utils/managerTypes.js.map +1 -1
  215. package/dist/utils/validations.d.ts +1 -0
  216. package/dist/utils/validations.d.ts.map +1 -1
  217. package/dist/utils/validations.js +5 -0
  218. package/dist/utils/validations.js.map +1 -1
  219. package/dist/utils/vault.d.ts.map +1 -1
  220. package/dist/utils/vault.js +2 -0
  221. package/dist/utils/vault.js.map +1 -1
  222. package/package.json +1 -1
  223. package/src/@codegen/klend/accounts/LendingMarket.ts +79 -8
  224. package/src/@codegen/klend/accounts/Obligation.ts +42 -31
  225. package/src/@codegen/klend/accounts/Reserve.ts +1 -1
  226. package/src/@codegen/klend/accounts/UserState.ts +0 -75
  227. package/src/@codegen/klend/errors/custom.ts +172 -0
  228. package/src/@codegen/klend/instructions/fillBorrowOrder.ts +96 -0
  229. package/src/@codegen/klend/instructions/idlMissingTypes.ts +0 -3
  230. package/src/@codegen/klend/instructions/index.ts +7 -0
  231. package/src/@codegen/klend/instructions/setBorrowOrder.ts +81 -0
  232. package/src/@codegen/klend/types/BorrowOrder.ts +267 -0
  233. package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +87 -0
  234. package/src/@codegen/klend/types/ObligationLiquidity.ts +39 -9
  235. package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
  236. package/src/@codegen/klend/types/ReserveConfig.ts +72 -9
  237. package/src/@codegen/klend/types/UpdateConfigMode.ts +73 -13
  238. package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +120 -0
  239. package/src/@codegen/klend/types/index.ts +21 -14
  240. package/src/@codegen/klend/zero_padding/ObligationZP.ts +17 -14
  241. package/src/@codegen/kvault/accounts/LendingMarket.ts +837 -0
  242. package/src/@codegen/kvault/accounts/Obligation.ts +459 -0
  243. package/src/@codegen/kvault/accounts/ReferrerTokenState.ts +160 -0
  244. package/src/@codegen/kvault/accounts/Reserve.ts +13 -2
  245. package/src/@codegen/kvault/accounts/VaultState.ts +59 -7
  246. package/src/@codegen/kvault/accounts/WithdrawTicket.ts +280 -0
  247. package/src/@codegen/kvault/accounts/index.ts +11 -0
  248. package/src/@codegen/kvault/errors/custom.ts +152 -0
  249. package/src/@codegen/kvault/instructions/index.ts +10 -0
  250. package/src/@codegen/kvault/instructions/invest.ts +16 -0
  251. package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.ts +189 -0
  252. package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.ts +205 -0
  253. package/src/@codegen/kvault/instructions/updateKlendQueueAccounting.ts +76 -0
  254. package/src/@codegen/kvault/instructions/updateReserveAllocation.ts +4 -1
  255. package/src/@codegen/kvault/types/BorrowOrder.ts +267 -0
  256. package/src/@codegen/kvault/types/ElevationGroup.ts +134 -0
  257. package/src/@codegen/kvault/types/FixedTermBorrowRolloverConfig.ts +199 -0
  258. package/src/@codegen/kvault/types/ObligationCollateral.ts +129 -0
  259. package/src/@codegen/kvault/types/ObligationLiquidity.ts +226 -0
  260. package/src/@codegen/kvault/types/ObligationOrder.ts +348 -0
  261. package/src/@codegen/kvault/types/ReserveConfig.ts +72 -9
  262. package/src/@codegen/kvault/types/ReserveLiquidity.ts +30 -12
  263. package/src/@codegen/kvault/types/ReserveType.ts +89 -0
  264. package/src/@codegen/kvault/types/VaultAllocation.ts +74 -2
  265. package/src/@codegen/kvault/types/WithdrawQueue.ts +117 -0
  266. package/src/@codegen/kvault/types/WithdrawTicketProgressEvent.ts +59 -0
  267. package/src/@codegen/kvault/types/index.ts +52 -0
  268. package/src/classes/manager.ts +5 -0
  269. package/src/classes/market.ts +206 -14
  270. package/src/classes/obligation.ts +9 -7
  271. package/src/classes/reserve.ts +27 -1
  272. package/src/classes/utils.ts +8 -0
  273. package/src/classes/vault.ts +35 -4
  274. package/src/idl/klend.json +581 -54
  275. package/src/idl/kvault.json +2336 -299
  276. package/src/manager/client_kamino_manager.ts +12 -8
  277. package/src/obligation_orders/price_based.ts +7 -6
  278. package/src/utils/ReserveKind.ts +94 -0
  279. package/src/utils/index.ts +1 -0
  280. package/src/utils/managerTypes.ts +3 -1
  281. package/src/utils/validations.ts +5 -0
  282. package/src/utils/vault.ts +2 -0
  283. package/dist/@codegen/klend/types/AssetTier.d.ts +0 -45
  284. package/dist/@codegen/klend/types/AssetTier.d.ts.map +0 -1
  285. package/dist/@codegen/klend/types/AssetTier.js.map +0 -1
  286. package/src/@codegen/klend/types/AssetTier.ts +0 -119
@@ -56,7 +56,21 @@ export interface VaultStateFields {
56
56
  firstLossCapitalFarm: Address
57
57
  allowAllocationsInWhitelistedReservesOnly: number
58
58
  allowInvestInWhitelistedReservesOnly: number
59
- padding4: Array<number>
59
+ padding2: Array<number>
60
+ /**
61
+ * The amount of native SOL (in lamports) held by the [Self::base_vault_authority] for Klend's
62
+ * withdraw ticket(s) rent purposes.
63
+ *
64
+ * Context: in order to disinvest from a 100%-utilized reserve, we need to enter the reserve's
65
+ * withdraw queue. Klend needs to issue a ticket, and wants to cover its rent from the owner's
66
+ * (i.e. vault authority's) account. If the budget is 0, we have to transfer a single ticket's
67
+ * rent from the transaction executor (i.e. Kvault's bot). Each ticket's rent is refunded when
68
+ * the ticket is closed, so typically this budget should be available - in fact, the total sum
69
+ * transferred from the executor here will be equal to the rent for a maximum number of
70
+ * tickets that have ever been simultaneously in-flight.
71
+ */
72
+ withdrawTicketRentBudget: BN
73
+ padding4: BN
60
74
  padding3: Array<BN>
61
75
  }
62
76
 
@@ -101,7 +115,21 @@ export interface VaultStateJSON {
101
115
  firstLossCapitalFarm: string
102
116
  allowAllocationsInWhitelistedReservesOnly: number
103
117
  allowInvestInWhitelistedReservesOnly: number
104
- padding4: Array<number>
118
+ padding2: Array<number>
119
+ /**
120
+ * The amount of native SOL (in lamports) held by the [Self::base_vault_authority] for Klend's
121
+ * withdraw ticket(s) rent purposes.
122
+ *
123
+ * Context: in order to disinvest from a 100%-utilized reserve, we need to enter the reserve's
124
+ * withdraw queue. Klend needs to issue a ticket, and wants to cover its rent from the owner's
125
+ * (i.e. vault authority's) account. If the budget is 0, we have to transfer a single ticket's
126
+ * rent from the transaction executor (i.e. Kvault's bot). Each ticket's rent is refunded when
127
+ * the ticket is closed, so typically this budget should be available - in fact, the total sum
128
+ * transferred from the executor here will be equal to the rent for a maximum number of
129
+ * tickets that have ever been simultaneously in-flight.
130
+ */
131
+ withdrawTicketRentBudget: string
132
+ padding4: string
105
133
  padding3: Array<string>
106
134
  }
107
135
 
@@ -146,7 +174,21 @@ export class VaultState {
146
174
  readonly firstLossCapitalFarm: Address
147
175
  readonly allowAllocationsInWhitelistedReservesOnly: number
148
176
  readonly allowInvestInWhitelistedReservesOnly: number
149
- readonly padding4: Array<number>
177
+ readonly padding2: Array<number>
178
+ /**
179
+ * The amount of native SOL (in lamports) held by the [Self::base_vault_authority] for Klend's
180
+ * withdraw ticket(s) rent purposes.
181
+ *
182
+ * Context: in order to disinvest from a 100%-utilized reserve, we need to enter the reserve's
183
+ * withdraw queue. Klend needs to issue a ticket, and wants to cover its rent from the owner's
184
+ * (i.e. vault authority's) account. If the budget is 0, we have to transfer a single ticket's
185
+ * rent from the transaction executor (i.e. Kvault's bot). Each ticket's rent is refunded when
186
+ * the ticket is closed, so typically this budget should be available - in fact, the total sum
187
+ * transferred from the executor here will be equal to the rent for a maximum number of
188
+ * tickets that have ever been simultaneously in-flight.
189
+ */
190
+ readonly withdrawTicketRentBudget: BN
191
+ readonly padding4: BN
150
192
  readonly padding3: Array<BN>
151
193
 
152
194
  static readonly discriminator = Buffer.from([
@@ -194,8 +236,10 @@ export class VaultState {
194
236
  borshAddress("firstLossCapitalFarm"),
195
237
  borsh.u8("allowAllocationsInWhitelistedReservesOnly"),
196
238
  borsh.u8("allowInvestInWhitelistedReservesOnly"),
197
- borsh.array(borsh.u8(), 14, "padding4"),
198
- borsh.array(borsh.u128(), 238, "padding3"),
239
+ borsh.array(borsh.u8(), 14, "padding2"),
240
+ borsh.u64("withdrawTicketRentBudget"),
241
+ borsh.u64("padding4"),
242
+ borsh.array(borsh.u128(), 237, "padding3"),
199
243
  ])
200
244
 
201
245
  constructor(fields: VaultStateFields) {
@@ -243,6 +287,8 @@ export class VaultState {
243
287
  fields.allowAllocationsInWhitelistedReservesOnly
244
288
  this.allowInvestInWhitelistedReservesOnly =
245
289
  fields.allowInvestInWhitelistedReservesOnly
290
+ this.padding2 = fields.padding2
291
+ this.withdrawTicketRentBudget = fields.withdrawTicketRentBudget
246
292
  this.padding4 = fields.padding4
247
293
  this.padding3 = fields.padding3
248
294
  }
@@ -341,6 +387,8 @@ export class VaultState {
341
387
  dec.allowAllocationsInWhitelistedReservesOnly,
342
388
  allowInvestInWhitelistedReservesOnly:
343
389
  dec.allowInvestInWhitelistedReservesOnly,
390
+ padding2: dec.padding2,
391
+ withdrawTicketRentBudget: dec.withdrawTicketRentBudget,
344
392
  padding4: dec.padding4,
345
393
  padding3: dec.padding3,
346
394
  })
@@ -392,7 +440,9 @@ export class VaultState {
392
440
  this.allowAllocationsInWhitelistedReservesOnly,
393
441
  allowInvestInWhitelistedReservesOnly:
394
442
  this.allowInvestInWhitelistedReservesOnly,
395
- padding4: this.padding4,
443
+ padding2: this.padding2,
444
+ withdrawTicketRentBudget: this.withdrawTicketRentBudget.toString(),
445
+ padding4: this.padding4.toString(),
396
446
  padding3: this.padding3.map((item) => item.toString()),
397
447
  }
398
448
  }
@@ -443,7 +493,9 @@ export class VaultState {
443
493
  obj.allowAllocationsInWhitelistedReservesOnly,
444
494
  allowInvestInWhitelistedReservesOnly:
445
495
  obj.allowInvestInWhitelistedReservesOnly,
446
- padding4: obj.padding4,
496
+ padding2: obj.padding2,
497
+ withdrawTicketRentBudget: new BN(obj.withdrawTicketRentBudget),
498
+ padding4: new BN(obj.padding4),
447
499
  padding3: obj.padding3.map((item) => new BN(item)),
448
500
  })
449
501
  }
@@ -0,0 +1,280 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import {
3
+ address,
4
+ Address,
5
+ fetchEncodedAccount,
6
+ fetchEncodedAccounts,
7
+ GetAccountInfoApi,
8
+ GetMultipleAccountsApi,
9
+ Rpc,
10
+ } from "@solana/kit"
11
+ /* eslint-enable @typescript-eslint/no-unused-vars */
12
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
13
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
14
+ import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ import { PROGRAM_ID } from "../programId"
17
+
18
+ export interface WithdrawTicketFields {
19
+ /** This ticket's place in the queue; the same as used for PDA derivation. */
20
+ sequenceNumber: BN
21
+ /** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
22
+ owner: Address
23
+ /** The reserve to withdraw from. */
24
+ reserve: Address
25
+ /**
26
+ * The token account to which the finally-available liquidity should be transferred (by the
27
+ * `withdraw_queued_liquidity` handler).
28
+ */
29
+ userDestinationLiquidityTa: Address
30
+ /** The amount of collateral still waiting to be withdrawn using this ticket. */
31
+ queuedCollateralAmount: BN
32
+ /**
33
+ * The timestamp at which the queue was entered.
34
+ *
35
+ * This is currently only a piece of metadata, not used by the logic.
36
+ */
37
+ createdAtTimestamp: BN
38
+ /**
39
+ * Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
40
+ * has been repurposed) by the `withdraw_queued_liquidity` handler.
41
+ * To be specific: valid = `0`, invalid = `1`.
42
+ *
43
+ * An invalid ticket cannot be made valid again, and can only be passed to the
44
+ * `recover_invalid_ticket_collateral` handler.
45
+ */
46
+ invalid: number
47
+ /** One of the valid [ProgressCallbackType] representations. */
48
+ progressCallbackType: number
49
+ /** Inner padding, for alignment. */
50
+ alignmentPadding: Array<number>
51
+ /** The (optional) accounts to be used by [Self::progress_callback_type]s. */
52
+ progressCallbackCustomAccounts: Array<Address>
53
+ /** Trailing padding, for future developments. */
54
+ endPadding: Array<BN>
55
+ }
56
+
57
+ export interface WithdrawTicketJSON {
58
+ /** This ticket's place in the queue; the same as used for PDA derivation. */
59
+ sequenceNumber: string
60
+ /** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
61
+ owner: string
62
+ /** The reserve to withdraw from. */
63
+ reserve: string
64
+ /**
65
+ * The token account to which the finally-available liquidity should be transferred (by the
66
+ * `withdraw_queued_liquidity` handler).
67
+ */
68
+ userDestinationLiquidityTa: string
69
+ /** The amount of collateral still waiting to be withdrawn using this ticket. */
70
+ queuedCollateralAmount: string
71
+ /**
72
+ * The timestamp at which the queue was entered.
73
+ *
74
+ * This is currently only a piece of metadata, not used by the logic.
75
+ */
76
+ createdAtTimestamp: string
77
+ /**
78
+ * Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
79
+ * has been repurposed) by the `withdraw_queued_liquidity` handler.
80
+ * To be specific: valid = `0`, invalid = `1`.
81
+ *
82
+ * An invalid ticket cannot be made valid again, and can only be passed to the
83
+ * `recover_invalid_ticket_collateral` handler.
84
+ */
85
+ invalid: number
86
+ /** One of the valid [ProgressCallbackType] representations. */
87
+ progressCallbackType: number
88
+ /** Inner padding, for alignment. */
89
+ alignmentPadding: Array<number>
90
+ /** The (optional) accounts to be used by [Self::progress_callback_type]s. */
91
+ progressCallbackCustomAccounts: Array<string>
92
+ /** Trailing padding, for future developments. */
93
+ endPadding: Array<string>
94
+ }
95
+
96
+ /**
97
+ * A finite-lifecycle account representing a specific depositor's place in the withdraw queue of
98
+ * a specific reserve.
99
+ *
100
+ * The lifecycle:
101
+ * 1. The depositor holding ctokens wants to withdraw funds from the reserve, and finds out that
102
+ * the required amount is not available (due to high utilization).
103
+ * 2. The depositor calls the `enqueue_to_withdraw` handler.
104
+ * 3. The handler transfers the depositor's ctokens to the reserve's internal "pending" vault.
105
+ * 4. The handler initializes a new [WithdrawTicket] account, with the next available sequence
106
+ * number.
107
+ * 5. The depositor waits until his ticket is the next expected one for actual withdraw, and until
108
+ * the reserve has enough liquidity.
109
+ * 6. Anyone (the depositor or a bot) calls the permissionless `withdraw_queued_liquidity`
110
+ * handler. If the ticket became invalid (e.g. destination account no longer exists), then the
111
+ * depositor can call the `recover_invalid_ticket_collateral` handler instead.
112
+ * 7. The handler transfers the liquidity amount according to the current exchange rate.
113
+ * 8. The handler closes the ticket account.
114
+ */
115
+ export class WithdrawTicket {
116
+ /** This ticket's place in the queue; the same as used for PDA derivation. */
117
+ readonly sequenceNumber: BN
118
+ /** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
119
+ readonly owner: Address
120
+ /** The reserve to withdraw from. */
121
+ readonly reserve: Address
122
+ /**
123
+ * The token account to which the finally-available liquidity should be transferred (by the
124
+ * `withdraw_queued_liquidity` handler).
125
+ */
126
+ readonly userDestinationLiquidityTa: Address
127
+ /** The amount of collateral still waiting to be withdrawn using this ticket. */
128
+ readonly queuedCollateralAmount: BN
129
+ /**
130
+ * The timestamp at which the queue was entered.
131
+ *
132
+ * This is currently only a piece of metadata, not used by the logic.
133
+ */
134
+ readonly createdAtTimestamp: BN
135
+ /**
136
+ * Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
137
+ * has been repurposed) by the `withdraw_queued_liquidity` handler.
138
+ * To be specific: valid = `0`, invalid = `1`.
139
+ *
140
+ * An invalid ticket cannot be made valid again, and can only be passed to the
141
+ * `recover_invalid_ticket_collateral` handler.
142
+ */
143
+ readonly invalid: number
144
+ /** One of the valid [ProgressCallbackType] representations. */
145
+ readonly progressCallbackType: number
146
+ /** Inner padding, for alignment. */
147
+ readonly alignmentPadding: Array<number>
148
+ /** The (optional) accounts to be used by [Self::progress_callback_type]s. */
149
+ readonly progressCallbackCustomAccounts: Array<Address>
150
+ /** Trailing padding, for future developments. */
151
+ readonly endPadding: Array<BN>
152
+
153
+ static readonly discriminator = Buffer.from([
154
+ 237, 23, 164, 58, 53, 248, 240, 94,
155
+ ])
156
+
157
+ static readonly layout = borsh.struct<WithdrawTicket>([
158
+ borsh.u64("sequenceNumber"),
159
+ borshAddress("owner"),
160
+ borshAddress("reserve"),
161
+ borshAddress("userDestinationLiquidityTa"),
162
+ borsh.u64("queuedCollateralAmount"),
163
+ borsh.u64("createdAtTimestamp"),
164
+ borsh.u8("invalid"),
165
+ borsh.u8("progressCallbackType"),
166
+ borsh.array(borsh.u8(), 6, "alignmentPadding"),
167
+ borsh.array(borshAddress(), 2, "progressCallbackCustomAccounts"),
168
+ borsh.array(borsh.u64(), 40, "endPadding"),
169
+ ])
170
+
171
+ constructor(fields: WithdrawTicketFields) {
172
+ this.sequenceNumber = fields.sequenceNumber
173
+ this.owner = fields.owner
174
+ this.reserve = fields.reserve
175
+ this.userDestinationLiquidityTa = fields.userDestinationLiquidityTa
176
+ this.queuedCollateralAmount = fields.queuedCollateralAmount
177
+ this.createdAtTimestamp = fields.createdAtTimestamp
178
+ this.invalid = fields.invalid
179
+ this.progressCallbackType = fields.progressCallbackType
180
+ this.alignmentPadding = fields.alignmentPadding
181
+ this.progressCallbackCustomAccounts = fields.progressCallbackCustomAccounts
182
+ this.endPadding = fields.endPadding
183
+ }
184
+
185
+ static async fetch(
186
+ rpc: Rpc<GetAccountInfoApi>,
187
+ address: Address,
188
+ programId: Address = PROGRAM_ID
189
+ ): Promise<WithdrawTicket | null> {
190
+ const info = await fetchEncodedAccount(rpc, address)
191
+
192
+ if (!info.exists) {
193
+ return null
194
+ }
195
+ if (info.programAddress !== programId) {
196
+ throw new Error(
197
+ `WithdrawTicketFields account ${address} belongs to wrong program ${info.programAddress}, expected ${programId}`
198
+ )
199
+ }
200
+
201
+ return this.decode(Buffer.from(info.data))
202
+ }
203
+
204
+ static async fetchMultiple(
205
+ rpc: Rpc<GetMultipleAccountsApi>,
206
+ addresses: Address[],
207
+ programId: Address = PROGRAM_ID
208
+ ): Promise<Array<WithdrawTicket | null>> {
209
+ const infos = await fetchEncodedAccounts(rpc, addresses)
210
+
211
+ return infos.map((info) => {
212
+ if (!info.exists) {
213
+ return null
214
+ }
215
+ if (info.programAddress !== programId) {
216
+ throw new Error(
217
+ `WithdrawTicketFields account ${info.address} belongs to wrong program ${info.programAddress}, expected ${programId}`
218
+ )
219
+ }
220
+
221
+ return this.decode(Buffer.from(info.data))
222
+ })
223
+ }
224
+
225
+ static decode(data: Buffer): WithdrawTicket {
226
+ if (!data.slice(0, 8).equals(WithdrawTicket.discriminator)) {
227
+ throw new Error("invalid account discriminator")
228
+ }
229
+
230
+ const dec = WithdrawTicket.layout.decode(data.slice(8))
231
+
232
+ return new WithdrawTicket({
233
+ sequenceNumber: dec.sequenceNumber,
234
+ owner: dec.owner,
235
+ reserve: dec.reserve,
236
+ userDestinationLiquidityTa: dec.userDestinationLiquidityTa,
237
+ queuedCollateralAmount: dec.queuedCollateralAmount,
238
+ createdAtTimestamp: dec.createdAtTimestamp,
239
+ invalid: dec.invalid,
240
+ progressCallbackType: dec.progressCallbackType,
241
+ alignmentPadding: dec.alignmentPadding,
242
+ progressCallbackCustomAccounts: dec.progressCallbackCustomAccounts,
243
+ endPadding: dec.endPadding,
244
+ })
245
+ }
246
+
247
+ toJSON(): WithdrawTicketJSON {
248
+ return {
249
+ sequenceNumber: this.sequenceNumber.toString(),
250
+ owner: this.owner,
251
+ reserve: this.reserve,
252
+ userDestinationLiquidityTa: this.userDestinationLiquidityTa,
253
+ queuedCollateralAmount: this.queuedCollateralAmount.toString(),
254
+ createdAtTimestamp: this.createdAtTimestamp.toString(),
255
+ invalid: this.invalid,
256
+ progressCallbackType: this.progressCallbackType,
257
+ alignmentPadding: this.alignmentPadding,
258
+ progressCallbackCustomAccounts: this.progressCallbackCustomAccounts,
259
+ endPadding: this.endPadding.map((item) => item.toString()),
260
+ }
261
+ }
262
+
263
+ static fromJSON(obj: WithdrawTicketJSON): WithdrawTicket {
264
+ return new WithdrawTicket({
265
+ sequenceNumber: new BN(obj.sequenceNumber),
266
+ owner: address(obj.owner),
267
+ reserve: address(obj.reserve),
268
+ userDestinationLiquidityTa: address(obj.userDestinationLiquidityTa),
269
+ queuedCollateralAmount: new BN(obj.queuedCollateralAmount),
270
+ createdAtTimestamp: new BN(obj.createdAtTimestamp),
271
+ invalid: obj.invalid,
272
+ progressCallbackType: obj.progressCallbackType,
273
+ alignmentPadding: obj.alignmentPadding,
274
+ progressCallbackCustomAccounts: obj.progressCallbackCustomAccounts.map(
275
+ (item) => address(item)
276
+ ),
277
+ endPadding: obj.endPadding.map((item) => new BN(item)),
278
+ })
279
+ }
280
+ }
@@ -1,5 +1,16 @@
1
+ export { LendingMarket } from "./LendingMarket"
2
+ export type { LendingMarketFields, LendingMarketJSON } from "./LendingMarket"
3
+ export { Obligation } from "./Obligation"
4
+ export type { ObligationFields, ObligationJSON } from "./Obligation"
5
+ export { ReferrerTokenState } from "./ReferrerTokenState"
6
+ export type {
7
+ ReferrerTokenStateFields,
8
+ ReferrerTokenStateJSON,
9
+ } from "./ReferrerTokenState"
1
10
  export { Reserve } from "./Reserve"
2
11
  export type { ReserveFields, ReserveJSON } from "./Reserve"
12
+ export { WithdrawTicket } from "./WithdrawTicket"
13
+ export type { WithdrawTicketFields, WithdrawTicketJSON } from "./WithdrawTicket"
3
14
  export { GlobalConfig } from "./GlobalConfig"
4
15
  export type { GlobalConfigFields, GlobalConfigJSON } from "./GlobalConfig"
5
16
  export { ReserveWhitelistEntry } from "./ReserveWhitelistEntry"
@@ -55,6 +55,16 @@ export type CustomError =
55
55
  | WithdrawalFeeLamportsGreaterThanMaxAllowed
56
56
  | ReserveNotWhitelisted
57
57
  | InvalidBoolLikeValue
58
+ | MissingWithdrawQueueAccounts
59
+ | WithdrawTicketCallbackAccountingMismatch
60
+ | NotEnoughAvailableLiquidityToInvestIntoVirtual
61
+ | NotEnoughCTokensToWithdrawFromReserve
62
+ | ReserveTokenAllocationCapExceeded
63
+ | AUMDecreasedAfterInvestInVirtualReserve
64
+ | DestinationReserveIsNotVirtual
65
+ | AllSourceAccountsMustBeProvided
66
+ | InvestAndFillVaultStateMismatch
67
+ | InvestDstAndFillReserveMismatch
58
68
 
59
69
  export class DepositAmountsZero extends Error {
60
70
  static readonly code = 7000
@@ -678,6 +688,128 @@ export class InvalidBoolLikeValue extends Error {
678
688
  }
679
689
  }
680
690
 
691
+ export class MissingWithdrawQueueAccounts extends Error {
692
+ static readonly code = 7056
693
+ readonly code = 7056
694
+ readonly name = "MissingWithdrawQueueAccounts"
695
+ readonly msg =
696
+ "Withdraw queue accounts must be present when reserve has not enough freely-available liquidity"
697
+
698
+ constructor(readonly logs?: string[]) {
699
+ super(
700
+ "7056: Withdraw queue accounts must be present when reserve has not enough freely-available liquidity"
701
+ )
702
+ }
703
+ }
704
+
705
+ export class WithdrawTicketCallbackAccountingMismatch extends Error {
706
+ static readonly code = 7057
707
+ readonly code = 7057
708
+ readonly name = "WithdrawTicketCallbackAccountingMismatch"
709
+ readonly msg =
710
+ "Accounting updated by withdraw ticket callback does not match actual vault balance"
711
+
712
+ constructor(readonly logs?: string[]) {
713
+ super(
714
+ "7057: Accounting updated by withdraw ticket callback does not match actual vault balance"
715
+ )
716
+ }
717
+ }
718
+
719
+ export class NotEnoughAvailableLiquidityToInvestIntoVirtual extends Error {
720
+ static readonly code = 7058
721
+ readonly code = 7058
722
+ readonly name = "NotEnoughAvailableLiquidityToInvestIntoVirtual"
723
+ readonly msg =
724
+ "Insufficient available liquidity and no source reserve provided"
725
+
726
+ constructor(readonly logs?: string[]) {
727
+ super(
728
+ "7058: Insufficient available liquidity and no source reserve provided"
729
+ )
730
+ }
731
+ }
732
+
733
+ export class NotEnoughCTokensToWithdrawFromReserve extends Error {
734
+ static readonly code = 7059
735
+ readonly code = 7059
736
+ readonly name = "NotEnoughCTokensToWithdrawFromReserve"
737
+ readonly msg = "Reserve allocation is lower than requested ctokens"
738
+
739
+ constructor(readonly logs?: string[]) {
740
+ super("7059: Reserve allocation is lower than requested ctokens")
741
+ }
742
+ }
743
+
744
+ export class ReserveTokenAllocationCapExceeded extends Error {
745
+ static readonly code = 7060
746
+ readonly code = 7060
747
+ readonly name = "ReserveTokenAllocationCapExceeded"
748
+ readonly msg =
749
+ "Cannot invest tokens that would exceed the reserve allocation cap"
750
+
751
+ constructor(readonly logs?: string[]) {
752
+ super(
753
+ "7060: Cannot invest tokens that would exceed the reserve allocation cap"
754
+ )
755
+ }
756
+ }
757
+
758
+ export class AUMDecreasedAfterInvestInVirtualReserve extends Error {
759
+ static readonly code = 7061
760
+ readonly code = 7061
761
+ readonly name = "AUMDecreasedAfterInvestInVirtualReserve"
762
+ readonly msg = "AUM decreased after invest in virtual reserve"
763
+
764
+ constructor(readonly logs?: string[]) {
765
+ super("7061: AUM decreased after invest in virtual reserve")
766
+ }
767
+ }
768
+
769
+ export class DestinationReserveIsNotVirtual extends Error {
770
+ static readonly code = 7062
771
+ readonly code = 7062
772
+ readonly name = "DestinationReserveIsNotVirtual"
773
+ readonly msg = "Destination reserve is not virtual"
774
+
775
+ constructor(readonly logs?: string[]) {
776
+ super("7062: Destination reserve is not virtual")
777
+ }
778
+ }
779
+
780
+ export class AllSourceAccountsMustBeProvided extends Error {
781
+ static readonly code = 7063
782
+ readonly code = 7063
783
+ readonly name = "AllSourceAccountsMustBeProvided"
784
+ readonly msg = "All source accounts must be provided"
785
+
786
+ constructor(readonly logs?: string[]) {
787
+ super("7063: All source accounts must be provided")
788
+ }
789
+ }
790
+
791
+ export class InvestAndFillVaultStateMismatch extends Error {
792
+ static readonly code = 7064
793
+ readonly code = 7064
794
+ readonly name = "InvestAndFillVaultStateMismatch"
795
+ readonly msg = "Invest and fill vault state mismatch"
796
+
797
+ constructor(readonly logs?: string[]) {
798
+ super("7064: Invest and fill vault state mismatch")
799
+ }
800
+ }
801
+
802
+ export class InvestDstAndFillReserveMismatch extends Error {
803
+ static readonly code = 7065
804
+ readonly code = 7065
805
+ readonly name = "InvestDstAndFillReserveMismatch"
806
+ readonly msg = "Invest dst and fill reserve mismatch"
807
+
808
+ constructor(readonly logs?: string[]) {
809
+ super("7065: Invest dst and fill reserve mismatch")
810
+ }
811
+ }
812
+
681
813
  export function fromCode(code: number, logs?: string[]): CustomError | null {
682
814
  switch (code) {
683
815
  case 7000:
@@ -792,6 +924,26 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
792
924
  return new ReserveNotWhitelisted(logs)
793
925
  case 7055:
794
926
  return new InvalidBoolLikeValue(logs)
927
+ case 7056:
928
+ return new MissingWithdrawQueueAccounts(logs)
929
+ case 7057:
930
+ return new WithdrawTicketCallbackAccountingMismatch(logs)
931
+ case 7058:
932
+ return new NotEnoughAvailableLiquidityToInvestIntoVirtual(logs)
933
+ case 7059:
934
+ return new NotEnoughCTokensToWithdrawFromReserve(logs)
935
+ case 7060:
936
+ return new ReserveTokenAllocationCapExceeded(logs)
937
+ case 7061:
938
+ return new AUMDecreasedAfterInvestInVirtualReserve(logs)
939
+ case 7062:
940
+ return new DestinationReserveIsNotVirtual(logs)
941
+ case 7063:
942
+ return new AllSourceAccountsMustBeProvided(logs)
943
+ case 7064:
944
+ return new InvestAndFillVaultStateMismatch(logs)
945
+ case 7065:
946
+ return new InvestDstAndFillReserveMismatch(logs)
795
947
  }
796
948
 
797
949
  return null
@@ -60,3 +60,13 @@ export type {
60
60
  AddUpdateWhitelistedReserveArgs,
61
61
  AddUpdateWhitelistedReserveAccounts,
62
62
  } from "./addUpdateWhitelistedReserve"
63
+ export { investInVirtualReserveAndFillOrder } from "./investInVirtualReserveAndFillOrder"
64
+ export type {
65
+ InvestInVirtualReserveAndFillOrderArgs,
66
+ InvestInVirtualReserveAndFillOrderAccounts,
67
+ } from "./investInVirtualReserveAndFillOrder"
68
+ export { investInVirtualReserveAndFillWithdrawalTicket } from "./investInVirtualReserveAndFillWithdrawalTicket"
69
+ export type {
70
+ InvestInVirtualReserveAndFillWithdrawalTicketArgs,
71
+ InvestInVirtualReserveAndFillWithdrawalTicketAccounts,
72
+ } from "./investInVirtualReserveAndFillWithdrawalTicket"
@@ -35,7 +35,16 @@ export interface InvestAccounts {
35
35
  klendProgram: Address
36
36
  reserveCollateralTokenProgram: Address
37
37
  tokenProgram: Address
38
+ /** Required by the klend CPI. */
38
39
  instructionSysvarAccount: Address
40
+ /** The ticket to be initialized, if the klend's withdraw queue should be used for uninvesting. */
41
+ reserveWithdrawTicket: Option<Address>
42
+ /**
43
+ * The ctokens vault expected by the klend's withdraw queue.
44
+ * Must be present together with the `reserve_withdraw_ticket`.
45
+ */
46
+ ownerQueuedCollateralVault: Option<Address>
47
+ systemProgram: Address
39
48
  }
40
49
 
41
50
  export function invest(
@@ -63,6 +72,13 @@ export function invest(
63
72
  { address: accounts.reserveCollateralTokenProgram, role: 0 },
64
73
  { address: accounts.tokenProgram, role: 0 },
65
74
  { address: accounts.instructionSysvarAccount, role: 0 },
75
+ isSome(accounts.reserveWithdrawTicket)
76
+ ? { address: accounts.reserveWithdrawTicket.value, role: 1 }
77
+ : { address: programAddress, role: 0 },
78
+ isSome(accounts.ownerQueuedCollateralVault)
79
+ ? { address: accounts.ownerQueuedCollateralVault.value, role: 1 }
80
+ : { address: programAddress, role: 0 },
81
+ { address: accounts.systemProgram, role: 0 },
66
82
  ...remainingAccounts,
67
83
  ]
68
84
  const data = DISCRIMINATOR