@kamino-finance/klend-sdk 5.10.33 → 5.10.35-beta.0

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 (188) hide show
  1. package/dist/classes/action.d.ts +33 -26
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +614 -202
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.d.ts +4 -4
  6. package/dist/classes/manager.d.ts.map +1 -1
  7. package/dist/classes/manager.js +13 -4
  8. package/dist/classes/manager.js.map +1 -1
  9. package/dist/classes/reserve.d.ts +1 -1
  10. package/dist/classes/reserve.d.ts.map +1 -1
  11. package/dist/classes/reserve.js +2 -1
  12. package/dist/classes/reserve.js.map +1 -1
  13. package/dist/classes/types.d.ts +4 -0
  14. package/dist/classes/types.d.ts.map +1 -1
  15. package/dist/classes/utils.d.ts.map +1 -1
  16. package/dist/classes/utils.js +1 -2
  17. package/dist/classes/utils.js.map +1 -1
  18. package/dist/classes/vault.d.ts +4 -4
  19. package/dist/classes/vault.d.ts.map +1 -1
  20. package/dist/classes/vault.js +39 -26
  21. package/dist/classes/vault.js.map +1 -1
  22. package/dist/client_kamino_manager.d.ts.map +1 -1
  23. package/dist/client_kamino_manager.js +8 -3
  24. package/dist/client_kamino_manager.js.map +1 -1
  25. package/dist/idl.json +269 -156
  26. package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
  27. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  28. package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
  29. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  30. package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
  31. package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
  32. package/dist/idl_codegen/accounts/Obligation.js +8 -1
  33. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  34. package/dist/idl_codegen/errors/custom.d.ts +51 -3
  35. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  36. package/dist/idl_codegen/errors/custom.js +89 -5
  37. package/dist/idl_codegen/errors/custom.js.map +1 -1
  38. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
  39. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
  40. package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
  41. package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
  42. package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
  43. package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
  44. package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
  45. package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
  46. package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
  47. package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
  48. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
  49. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
  50. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
  51. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
  52. package/dist/idl_codegen/instructions/index.d.ts +2 -2
  53. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  54. package/dist/idl_codegen/instructions/index.js +3 -3
  55. package/dist/idl_codegen/instructions/index.js.map +1 -1
  56. package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
  57. package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
  58. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
  59. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
  60. package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
  61. package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
  62. package/dist/idl_codegen/instructions/initReserve.js +5 -0
  63. package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
  64. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
  65. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
  66. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
  67. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
  68. package/dist/idl_codegen/instructions/redeemFees.js +1 -1
  69. package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
  70. package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
  71. package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
  72. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
  73. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
  74. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
  75. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
  76. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +24 -3
  77. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
  78. package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
  79. package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
  80. package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
  81. package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
  82. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +2 -2
  83. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
  84. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +2 -2
  85. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
  86. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
  87. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  88. package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
  89. package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
  90. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
  91. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  92. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
  93. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  94. package/dist/idl_codegen/types/index.d.ts +2 -2
  95. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  96. package/dist/idl_codegen/types/index.js.map +1 -1
  97. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +12 -4
  98. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  99. package/dist/idl_codegen/zero_padding/ObligationZP.js +15 -8
  100. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  101. package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
  102. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  103. package/dist/lending_operations/repay_with_collateral_operations.js +7 -6
  104. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  105. package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
  106. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  107. package/dist/lending_operations/swap_collateral_operations.js +9 -5
  108. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  109. package/dist/leverage/instructions.d.ts +1 -2
  110. package/dist/leverage/instructions.d.ts.map +1 -1
  111. package/dist/leverage/instructions.js +2 -6
  112. package/dist/leverage/instructions.js.map +1 -1
  113. package/dist/leverage/operations.d.ts +8 -8
  114. package/dist/leverage/operations.d.ts.map +1 -1
  115. package/dist/leverage/operations.js +46 -37
  116. package/dist/leverage/operations.js.map +1 -1
  117. package/dist/leverage/types.d.ts +4 -1
  118. package/dist/leverage/types.d.ts.map +1 -1
  119. package/dist/utils/ata.d.ts +1 -1
  120. package/dist/utils/ata.d.ts.map +1 -1
  121. package/dist/utils/ata.js +2 -2
  122. package/dist/utils/ata.js.map +1 -1
  123. package/dist/utils/constants.d.ts +4 -9
  124. package/dist/utils/constants.d.ts.map +1 -1
  125. package/dist/utils/constants.js +5 -10
  126. package/dist/utils/constants.js.map +1 -1
  127. package/dist/utils/instruction.d.ts.map +1 -1
  128. package/dist/utils/instruction.js +1 -3
  129. package/dist/utils/instruction.js.map +1 -1
  130. package/dist/utils/managerTypes.d.ts +1 -0
  131. package/dist/utils/managerTypes.d.ts.map +1 -1
  132. package/dist/utils/managerTypes.js.map +1 -1
  133. package/dist/utils/seeds.d.ts +5 -0
  134. package/dist/utils/seeds.d.ts.map +1 -1
  135. package/dist/utils/seeds.js +10 -1
  136. package/dist/utils/seeds.js.map +1 -1
  137. package/dist/utils/userMetadata.d.ts.map +1 -1
  138. package/dist/utils/userMetadata.js +8 -10
  139. package/dist/utils/userMetadata.js.map +1 -1
  140. package/package.json +6 -3
  141. package/src/classes/action.ts +789 -214
  142. package/src/classes/manager.ts +18 -4
  143. package/src/classes/reserve.ts +2 -0
  144. package/src/classes/types.ts +5 -0
  145. package/src/classes/utils.ts +3 -3
  146. package/src/classes/vault.ts +49 -37
  147. package/src/client.ts +7 -3
  148. package/src/client_kamino_manager.ts +10 -3
  149. package/src/idl.json +269 -156
  150. package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
  151. package/src/idl_codegen/accounts/Obligation.ts +12 -1
  152. package/src/idl_codegen/errors/custom.ts +103 -4
  153. package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
  154. package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
  155. package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
  156. package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
  157. package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
  158. package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
  159. package/src/idl_codegen/instructions/index.ts +4 -4
  160. package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
  161. package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
  162. package/src/idl_codegen/instructions/initReserve.ts +6 -0
  163. package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
  164. package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
  165. package/src/idl_codegen/instructions/redeemFees.ts +1 -1
  166. package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
  167. package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
  168. package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +33 -3
  169. package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
  170. package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
  171. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +2 -2
  172. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +2 -2
  173. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
  174. package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
  175. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
  176. package/src/idl_codegen/types/index.ts +2 -0
  177. package/src/idl_codegen/zero_padding/ObligationZP.ts +18 -7
  178. package/src/lending_operations/repay_with_collateral_operations.ts +12 -3
  179. package/src/lending_operations/swap_collateral_operations.ts +17 -5
  180. package/src/leverage/instructions.ts +1 -6
  181. package/src/leverage/operations.ts +66 -29
  182. package/src/leverage/types.ts +4 -1
  183. package/src/utils/ata.ts +1 -1
  184. package/src/utils/constants.ts +5 -11
  185. package/src/utils/instruction.ts +1 -3
  186. package/src/utils/managerTypes.ts +1 -0
  187. package/src/utils/seeds.ts +13 -0
  188. package/src/utils/userMetadata.ts +21 -26
@@ -68,6 +68,11 @@ export interface LendingMarketFields {
68
68
  * been individually marked for auto-deleveraging (by the risk council).
69
69
  */
70
70
  individualAutodeleverageMarginCallPeriodSecs: BN
71
+ /**
72
+ * Minimum amount of deposit at creation of a reserve to prevent artificial inflation
73
+ * Note: this amount cannot be recovered, the ctoken associated are never minted
74
+ */
75
+ minInitialDepositAmount: BN
71
76
  padding1: Array<BN>
72
77
  }
73
78
 
@@ -135,6 +140,11 @@ export interface LendingMarketJSON {
135
140
  * been individually marked for auto-deleveraging (by the risk council).
136
141
  */
137
142
  individualAutodeleverageMarginCallPeriodSecs: string
143
+ /**
144
+ * Minimum amount of deposit at creation of a reserve to prevent artificial inflation
145
+ * Note: this amount cannot be recovered, the ctoken associated are never minted
146
+ */
147
+ minInitialDepositAmount: string
138
148
  padding1: Array<string>
139
149
  }
140
150
 
@@ -202,6 +212,11 @@ export class LendingMarket {
202
212
  * been individually marked for auto-deleveraging (by the risk council).
203
213
  */
204
214
  readonly individualAutodeleverageMarginCallPeriodSecs: BN
215
+ /**
216
+ * Minimum amount of deposit at creation of a reserve to prevent artificial inflation
217
+ * Note: this amount cannot be recovered, the ctoken associated are never minted
218
+ */
219
+ readonly minInitialDepositAmount: BN
205
220
  readonly padding1: Array<BN>
206
221
 
207
222
  static readonly discriminator = Buffer.from([
@@ -234,7 +249,8 @@ export class LendingMarket {
234
249
  borsh.array(borsh.u8(), 32, "name"),
235
250
  borsh.u64("minValueSkipLiquidationBfChecks"),
236
251
  borsh.u64("individualAutodeleverageMarginCallPeriodSecs"),
237
- borsh.array(borsh.u64(), 171, "padding1"),
252
+ borsh.u64("minInitialDepositAmount"),
253
+ borsh.array(borsh.u64(), 170, "padding1"),
238
254
  ])
239
255
 
240
256
  constructor(fields: LendingMarketFields) {
@@ -271,6 +287,7 @@ export class LendingMarket {
271
287
  fields.minValueSkipLiquidationBfChecks
272
288
  this.individualAutodeleverageMarginCallPeriodSecs =
273
289
  fields.individualAutodeleverageMarginCallPeriodSecs
290
+ this.minInitialDepositAmount = fields.minInitialDepositAmount
274
291
  this.padding1 = fields.padding1
275
292
  }
276
293
 
@@ -349,6 +366,7 @@ export class LendingMarket {
349
366
  minValueSkipLiquidationBfChecks: dec.minValueSkipLiquidationBfChecks,
350
367
  individualAutodeleverageMarginCallPeriodSecs:
351
368
  dec.individualAutodeleverageMarginCallPeriodSecs,
369
+ minInitialDepositAmount: dec.minInitialDepositAmount,
352
370
  padding1: dec.padding1,
353
371
  })
354
372
  }
@@ -387,6 +405,7 @@ export class LendingMarket {
387
405
  this.minValueSkipLiquidationBfChecks.toString(),
388
406
  individualAutodeleverageMarginCallPeriodSecs:
389
407
  this.individualAutodeleverageMarginCallPeriodSecs.toString(),
408
+ minInitialDepositAmount: this.minInitialDepositAmount.toString(),
390
409
  padding1: this.padding1.map((item) => item.toString()),
391
410
  }
392
411
  }
@@ -432,6 +451,7 @@ export class LendingMarket {
432
451
  individualAutodeleverageMarginCallPeriodSecs: new BN(
433
452
  obj.individualAutodeleverageMarginCallPeriodSecs
434
453
  ),
454
+ minInitialDepositAmount: new BN(obj.minInitialDepositAmount),
435
455
  padding1: obj.padding1.map((item) => new BN(item)),
436
456
  })
437
457
  }
@@ -48,6 +48,8 @@ export interface ObligationFields {
48
48
  * Only effective when `deleveraging_margin_call_started_slot != 0`.
49
49
  */
50
50
  autodeleverageTargetLtvPct: number
51
+ /** The lowest max LTV found amongst the collateral deposits */
52
+ lowestReserveDepositMaxLtvPct: number
51
53
  reserved: Array<number>
52
54
  highestBorrowFactorPct: BN
53
55
  /**
@@ -102,6 +104,8 @@ export interface ObligationJSON {
102
104
  * Only effective when `deleveraging_margin_call_started_slot != 0`.
103
105
  */
104
106
  autodeleverageTargetLtvPct: number
107
+ /** The lowest max LTV found amongst the collateral deposits */
108
+ lowestReserveDepositMaxLtvPct: number
105
109
  reserved: Array<number>
106
110
  highestBorrowFactorPct: string
107
111
  /**
@@ -157,6 +161,8 @@ export class Obligation {
157
161
  * Only effective when `deleveraging_margin_call_started_slot != 0`.
158
162
  */
159
163
  readonly autodeleverageTargetLtvPct: number
164
+ /** The lowest max LTV found amongst the collateral deposits */
165
+ readonly lowestReserveDepositMaxLtvPct: number
160
166
  readonly reserved: Array<number>
161
167
  readonly highestBorrowFactorPct: BN
162
168
  /**
@@ -191,7 +197,8 @@ export class Obligation {
191
197
  borsh.publicKey("referrer"),
192
198
  borsh.u8("borrowingDisabled"),
193
199
  borsh.u8("autodeleverageTargetLtvPct"),
194
- borsh.array(borsh.u8(), 6, "reserved"),
200
+ borsh.u8("lowestReserveDepositMaxLtvPct"),
201
+ borsh.array(borsh.u8(), 5, "reserved"),
195
202
  borsh.u64("highestBorrowFactorPct"),
196
203
  borsh.u64("autodeleverageMarginCallStartedTimestamp"),
197
204
  borsh.array(borsh.u64(), 125, "padding3"),
@@ -224,6 +231,7 @@ export class Obligation {
224
231
  this.referrer = fields.referrer
225
232
  this.borrowingDisabled = fields.borrowingDisabled
226
233
  this.autodeleverageTargetLtvPct = fields.autodeleverageTargetLtvPct
234
+ this.lowestReserveDepositMaxLtvPct = fields.lowestReserveDepositMaxLtvPct
227
235
  this.reserved = fields.reserved
228
236
  this.highestBorrowFactorPct = fields.highestBorrowFactorPct
229
237
  this.autodeleverageMarginCallStartedTimestamp =
@@ -304,6 +312,7 @@ export class Obligation {
304
312
  referrer: dec.referrer,
305
313
  borrowingDisabled: dec.borrowingDisabled,
306
314
  autodeleverageTargetLtvPct: dec.autodeleverageTargetLtvPct,
315
+ lowestReserveDepositMaxLtvPct: dec.lowestReserveDepositMaxLtvPct,
307
316
  reserved: dec.reserved,
308
317
  highestBorrowFactorPct: dec.highestBorrowFactorPct,
309
318
  autodeleverageMarginCallStartedTimestamp:
@@ -336,6 +345,7 @@ export class Obligation {
336
345
  referrer: this.referrer.toString(),
337
346
  borrowingDisabled: this.borrowingDisabled,
338
347
  autodeleverageTargetLtvPct: this.autodeleverageTargetLtvPct,
348
+ lowestReserveDepositMaxLtvPct: this.lowestReserveDepositMaxLtvPct,
339
349
  reserved: this.reserved,
340
350
  highestBorrowFactorPct: this.highestBorrowFactorPct.toString(),
341
351
  autodeleverageMarginCallStartedTimestamp:
@@ -374,6 +384,7 @@ export class Obligation {
374
384
  referrer: new PublicKey(obj.referrer),
375
385
  borrowingDisabled: obj.borrowingDisabled,
376
386
  autodeleverageTargetLtvPct: obj.autodeleverageTargetLtvPct,
387
+ lowestReserveDepositMaxLtvPct: obj.lowestReserveDepositMaxLtvPct,
377
388
  reserved: obj.reserved,
378
389
  highestBorrowFactorPct: new BN(obj.highestBorrowFactorPct),
379
390
  autodeleverageMarginCallStartedTimestamp: new BN(
@@ -115,7 +115,13 @@ export type CustomError =
115
115
  | ObligationsMustMatch
116
116
  | LendingMarketsMustMatch
117
117
  | ObligationCurrentlyMarkedForDeleveraging
118
+ | MaximumWithdrawValueZero
119
+ | ZeroMaxLtvAssetsInDeposits
120
+ | MinLtvAssetsPriority
121
+ | WorseLTVThanUnhealthyLTV
118
122
  | FarmAccountsMissing
123
+ | RepayTooSmallForFullLiquidation
124
+ | InsufficientRepayAmount
119
125
 
120
126
  export class InvalidMarketAuthority extends Error {
121
127
  static readonly code = 6000
@@ -1443,21 +1449,102 @@ export class ObligationCurrentlyMarkedForDeleveraging extends Error {
1443
1449
  static readonly code = 6115
1444
1450
  readonly code = 6115
1445
1451
  readonly name = "ObligationCurrentlyMarkedForDeleveraging"
1446
- readonly msg = "Obligation is currently marked for deleveraging"
1452
+ readonly msg = "Obligation is already marked for deleveraging"
1447
1453
 
1448
1454
  constructor(readonly logs?: string[]) {
1449
- super("6115: Obligation is currently marked for deleveraging")
1455
+ super("6115: Obligation is already marked for deleveraging")
1450
1456
  }
1451
1457
  }
1452
1458
 
1453
- export class FarmAccountsMissing extends Error {
1459
+ export class MaximumWithdrawValueZero extends Error {
1454
1460
  static readonly code = 6116
1455
1461
  readonly code = 6116
1462
+ readonly name = "MaximumWithdrawValueZero"
1463
+ readonly msg =
1464
+ "Maximum withdrawable value of this collateral is zero, LTV needs improved"
1465
+
1466
+ constructor(readonly logs?: string[]) {
1467
+ super(
1468
+ "6116: Maximum withdrawable value of this collateral is zero, LTV needs improved"
1469
+ )
1470
+ }
1471
+ }
1472
+
1473
+ export class ZeroMaxLtvAssetsInDeposits extends Error {
1474
+ static readonly code = 6117
1475
+ readonly code = 6117
1476
+ readonly name = "ZeroMaxLtvAssetsInDeposits"
1477
+ readonly msg =
1478
+ "No max LTV 0 assets allowed in deposits for repay and withdraw"
1479
+
1480
+ constructor(readonly logs?: string[]) {
1481
+ super(
1482
+ "6117: No max LTV 0 assets allowed in deposits for repay and withdraw"
1483
+ )
1484
+ }
1485
+ }
1486
+
1487
+ export class MinLtvAssetsPriority extends Error {
1488
+ static readonly code = 6118
1489
+ readonly code = 6118
1490
+ readonly name = "MinLtvAssetsPriority"
1491
+ readonly msg =
1492
+ "The operation must prioritize the collateral with the lowest LTV"
1493
+
1494
+ constructor(readonly logs?: string[]) {
1495
+ super(
1496
+ "6118: The operation must prioritize the collateral with the lowest LTV"
1497
+ )
1498
+ }
1499
+ }
1500
+
1501
+ export class WorseLTVThanUnhealthyLTV extends Error {
1502
+ static readonly code = 6119
1503
+ readonly code = 6119
1504
+ readonly name = "WorseLTVThanUnhealthyLTV"
1505
+ readonly msg = "Cannot get the obligation liquidatable"
1506
+
1507
+ constructor(readonly logs?: string[]) {
1508
+ super("6119: Cannot get the obligation liquidatable")
1509
+ }
1510
+ }
1511
+
1512
+ export class FarmAccountsMissing extends Error {
1513
+ static readonly code = 6120
1514
+ readonly code = 6120
1456
1515
  readonly name = "FarmAccountsMissing"
1457
1516
  readonly msg = "Farm accounts to refresh are missing"
1458
1517
 
1459
1518
  constructor(readonly logs?: string[]) {
1460
- super("6116: Farm accounts to refresh are missing")
1519
+ super("6120: Farm accounts to refresh are missing")
1520
+ }
1521
+ }
1522
+
1523
+ export class RepayTooSmallForFullLiquidation extends Error {
1524
+ static readonly code = 6121
1525
+ readonly code = 6121
1526
+ readonly name = "RepayTooSmallForFullLiquidation"
1527
+ readonly msg =
1528
+ "Repay amount is too small to satisfy the mandatory full liquidation"
1529
+
1530
+ constructor(readonly logs?: string[]) {
1531
+ super(
1532
+ "6121: Repay amount is too small to satisfy the mandatory full liquidation"
1533
+ )
1534
+ }
1535
+ }
1536
+
1537
+ export class InsufficientRepayAmount extends Error {
1538
+ static readonly code = 6122
1539
+ readonly code = 6122
1540
+ readonly name = "InsufficientRepayAmount"
1541
+ readonly msg =
1542
+ "Liquidator provided repay amount lower than required by liquidation rules"
1543
+
1544
+ constructor(readonly logs?: string[]) {
1545
+ super(
1546
+ "6122: Liquidator provided repay amount lower than required by liquidation rules"
1547
+ )
1461
1548
  }
1462
1549
  }
1463
1550
 
@@ -1696,7 +1783,19 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
1696
1783
  case 6115:
1697
1784
  return new ObligationCurrentlyMarkedForDeleveraging(logs)
1698
1785
  case 6116:
1786
+ return new MaximumWithdrawValueZero(logs)
1787
+ case 6117:
1788
+ return new ZeroMaxLtvAssetsInDeposits(logs)
1789
+ case 6118:
1790
+ return new MinLtvAssetsPriority(logs)
1791
+ case 6119:
1792
+ return new WorseLTVThanUnhealthyLTV(logs)
1793
+ case 6120:
1699
1794
  return new FarmAccountsMissing(logs)
1795
+ case 6121:
1796
+ return new RepayTooSmallForFullLiquidation(logs)
1797
+ case 6122:
1798
+ return new InsufficientRepayAmount(logs)
1700
1799
  }
1701
1800
 
1702
1801
  return null
@@ -43,7 +43,7 @@ export function borrowObligationLiquidity(
43
43
  {
44
44
  pubkey: accounts.borrowReserveLiquidityMint,
45
45
  isSigner: false,
46
- isWritable: true,
46
+ isWritable: false,
47
47
  },
48
48
  {
49
49
  pubkey: accounts.reserveSourceLiquidity,
@@ -66,7 +66,7 @@ export function borrowObligationLiquidityV2(
66
66
  {
67
67
  pubkey: accounts.borrowAccounts.borrowReserveLiquidityMint,
68
68
  isSigner: false,
69
- isWritable: true,
69
+ isWritable: false,
70
70
  },
71
71
  {
72
72
  pubkey: accounts.borrowAccounts.reserveSourceLiquidity,
@@ -0,0 +1,241 @@
1
+ import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface DepositAndWithdrawArgs {
8
+ liquidityAmount: BN
9
+ withdrawCollateralAmount: BN
10
+ }
11
+
12
+ export interface DepositAndWithdrawAccounts {
13
+ depositAccounts: {
14
+ owner: PublicKey
15
+ obligation: PublicKey
16
+ lendingMarket: PublicKey
17
+ lendingMarketAuthority: PublicKey
18
+ reserve: PublicKey
19
+ reserveLiquidityMint: PublicKey
20
+ reserveLiquiditySupply: PublicKey
21
+ reserveCollateralMint: PublicKey
22
+ reserveDestinationDepositCollateral: PublicKey
23
+ userSourceLiquidity: PublicKey
24
+ placeholderUserDestinationCollateral: PublicKey
25
+ collateralTokenProgram: PublicKey
26
+ liquidityTokenProgram: PublicKey
27
+ instructionSysvarAccount: PublicKey
28
+ }
29
+ withdrawAccounts: {
30
+ owner: PublicKey
31
+ obligation: PublicKey
32
+ lendingMarket: PublicKey
33
+ lendingMarketAuthority: PublicKey
34
+ withdrawReserve: PublicKey
35
+ reserveLiquidityMint: PublicKey
36
+ reserveSourceCollateral: PublicKey
37
+ reserveCollateralMint: PublicKey
38
+ reserveLiquiditySupply: PublicKey
39
+ userDestinationLiquidity: PublicKey
40
+ placeholderUserDestinationCollateral: PublicKey
41
+ collateralTokenProgram: PublicKey
42
+ liquidityTokenProgram: PublicKey
43
+ instructionSysvarAccount: PublicKey
44
+ }
45
+ depositFarmsAccounts: {
46
+ obligationFarmUserState: PublicKey
47
+ reserveFarmState: PublicKey
48
+ }
49
+ withdrawFarmsAccounts: {
50
+ obligationFarmUserState: PublicKey
51
+ reserveFarmState: PublicKey
52
+ }
53
+ farmsProgram: PublicKey
54
+ }
55
+
56
+ export const layout = borsh.struct([
57
+ borsh.u64("liquidityAmount"),
58
+ borsh.u64("withdrawCollateralAmount"),
59
+ ])
60
+
61
+ export function depositAndWithdraw(
62
+ args: DepositAndWithdrawArgs,
63
+ accounts: DepositAndWithdrawAccounts,
64
+ programId: PublicKey = PROGRAM_ID
65
+ ) {
66
+ const keys: Array<AccountMeta> = [
67
+ {
68
+ pubkey: accounts.depositAccounts.owner,
69
+ isSigner: true,
70
+ isWritable: true,
71
+ },
72
+ {
73
+ pubkey: accounts.depositAccounts.obligation,
74
+ isSigner: false,
75
+ isWritable: true,
76
+ },
77
+ {
78
+ pubkey: accounts.depositAccounts.lendingMarket,
79
+ isSigner: false,
80
+ isWritable: false,
81
+ },
82
+ {
83
+ pubkey: accounts.depositAccounts.lendingMarketAuthority,
84
+ isSigner: false,
85
+ isWritable: false,
86
+ },
87
+ {
88
+ pubkey: accounts.depositAccounts.reserve,
89
+ isSigner: false,
90
+ isWritable: true,
91
+ },
92
+ {
93
+ pubkey: accounts.depositAccounts.reserveLiquidityMint,
94
+ isSigner: false,
95
+ isWritable: false,
96
+ },
97
+ {
98
+ pubkey: accounts.depositAccounts.reserveLiquiditySupply,
99
+ isSigner: false,
100
+ isWritable: true,
101
+ },
102
+ {
103
+ pubkey: accounts.depositAccounts.reserveCollateralMint,
104
+ isSigner: false,
105
+ isWritable: true,
106
+ },
107
+ {
108
+ pubkey: accounts.depositAccounts.reserveDestinationDepositCollateral,
109
+ isSigner: false,
110
+ isWritable: true,
111
+ },
112
+ {
113
+ pubkey: accounts.depositAccounts.userSourceLiquidity,
114
+ isSigner: false,
115
+ isWritable: true,
116
+ },
117
+ {
118
+ pubkey: accounts.depositAccounts.placeholderUserDestinationCollateral,
119
+ isSigner: false,
120
+ isWritable: false,
121
+ },
122
+ {
123
+ pubkey: accounts.depositAccounts.collateralTokenProgram,
124
+ isSigner: false,
125
+ isWritable: false,
126
+ },
127
+ {
128
+ pubkey: accounts.depositAccounts.liquidityTokenProgram,
129
+ isSigner: false,
130
+ isWritable: false,
131
+ },
132
+ {
133
+ pubkey: accounts.depositAccounts.instructionSysvarAccount,
134
+ isSigner: false,
135
+ isWritable: false,
136
+ },
137
+ {
138
+ pubkey: accounts.withdrawAccounts.owner,
139
+ isSigner: true,
140
+ isWritable: true,
141
+ },
142
+ {
143
+ pubkey: accounts.withdrawAccounts.obligation,
144
+ isSigner: false,
145
+ isWritable: true,
146
+ },
147
+ {
148
+ pubkey: accounts.withdrawAccounts.lendingMarket,
149
+ isSigner: false,
150
+ isWritable: false,
151
+ },
152
+ {
153
+ pubkey: accounts.withdrawAccounts.lendingMarketAuthority,
154
+ isSigner: false,
155
+ isWritable: false,
156
+ },
157
+ {
158
+ pubkey: accounts.withdrawAccounts.withdrawReserve,
159
+ isSigner: false,
160
+ isWritable: true,
161
+ },
162
+ {
163
+ pubkey: accounts.withdrawAccounts.reserveLiquidityMint,
164
+ isSigner: false,
165
+ isWritable: false,
166
+ },
167
+ {
168
+ pubkey: accounts.withdrawAccounts.reserveSourceCollateral,
169
+ isSigner: false,
170
+ isWritable: true,
171
+ },
172
+ {
173
+ pubkey: accounts.withdrawAccounts.reserveCollateralMint,
174
+ isSigner: false,
175
+ isWritable: true,
176
+ },
177
+ {
178
+ pubkey: accounts.withdrawAccounts.reserveLiquiditySupply,
179
+ isSigner: false,
180
+ isWritable: true,
181
+ },
182
+ {
183
+ pubkey: accounts.withdrawAccounts.userDestinationLiquidity,
184
+ isSigner: false,
185
+ isWritable: true,
186
+ },
187
+ {
188
+ pubkey: accounts.withdrawAccounts.placeholderUserDestinationCollateral,
189
+ isSigner: false,
190
+ isWritable: false,
191
+ },
192
+ {
193
+ pubkey: accounts.withdrawAccounts.collateralTokenProgram,
194
+ isSigner: false,
195
+ isWritable: false,
196
+ },
197
+ {
198
+ pubkey: accounts.withdrawAccounts.liquidityTokenProgram,
199
+ isSigner: false,
200
+ isWritable: false,
201
+ },
202
+ {
203
+ pubkey: accounts.withdrawAccounts.instructionSysvarAccount,
204
+ isSigner: false,
205
+ isWritable: false,
206
+ },
207
+ {
208
+ pubkey: accounts.depositFarmsAccounts.obligationFarmUserState,
209
+ isSigner: false,
210
+ isWritable: true,
211
+ },
212
+ {
213
+ pubkey: accounts.depositFarmsAccounts.reserveFarmState,
214
+ isSigner: false,
215
+ isWritable: true,
216
+ },
217
+ {
218
+ pubkey: accounts.withdrawFarmsAccounts.obligationFarmUserState,
219
+ isSigner: false,
220
+ isWritable: true,
221
+ },
222
+ {
223
+ pubkey: accounts.withdrawFarmsAccounts.reserveFarmState,
224
+ isSigner: false,
225
+ isWritable: true,
226
+ },
227
+ { pubkey: accounts.farmsProgram, isSigner: false, isWritable: false },
228
+ ]
229
+ const identifier = Buffer.from([141, 153, 39, 15, 64, 61, 88, 84])
230
+ const buffer = Buffer.alloc(1000)
231
+ const len = layout.encode(
232
+ {
233
+ liquidityAmount: args.liquidityAmount,
234
+ withdrawCollateralAmount: args.withdrawCollateralAmount,
235
+ },
236
+ buffer
237
+ )
238
+ const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len)
239
+ const ix = new TransactionInstruction({ keys, programId, data })
240
+ return ix
241
+ }
@@ -42,7 +42,7 @@ export function depositReserveLiquidity(
42
42
  {
43
43
  pubkey: accounts.reserveLiquidityMint,
44
44
  isSigner: false,
45
- isWritable: true,
45
+ isWritable: false,
46
46
  },
47
47
  {
48
48
  pubkey: accounts.reserveLiquiditySupply,
@@ -45,7 +45,7 @@ export function depositReserveLiquidityAndObligationCollateral(
45
45
  {
46
46
  pubkey: accounts.reserveLiquidityMint,
47
47
  isSigner: false,
48
- isWritable: true,
48
+ isWritable: false,
49
49
  },
50
50
  {
51
51
  pubkey: accounts.reserveLiquiditySupply,
@@ -68,7 +68,7 @@ export function depositReserveLiquidityAndObligationCollateralV2(
68
68
  {
69
69
  pubkey: accounts.depositAccounts.reserveLiquidityMint,
70
70
  isSigner: false,
71
- isWritable: true,
71
+ isWritable: false,
72
72
  },
73
73
  {
74
74
  pubkey: accounts.depositAccounts.reserveLiquiditySupply,
@@ -117,11 +117,11 @@ export type {
117
117
  RepayAndWithdrawAndRedeemArgs,
118
118
  RepayAndWithdrawAndRedeemAccounts,
119
119
  } from "./repayAndWithdrawAndRedeem"
120
- export { repayAndWithdrawAndRedeemV2 } from "./repayAndWithdrawAndRedeemV2"
120
+ export { depositAndWithdraw } from "./depositAndWithdraw"
121
121
  export type {
122
- RepayAndWithdrawAndRedeemV2Args,
123
- RepayAndWithdrawAndRedeemV2Accounts,
124
- } from "./repayAndWithdrawAndRedeemV2"
122
+ DepositAndWithdrawArgs,
123
+ DepositAndWithdrawAccounts,
124
+ } from "./depositAndWithdraw"
125
125
  export { depositReserveLiquidityAndObligationCollateral } from "./depositReserveLiquidityAndObligationCollateral"
126
126
  export type {
127
127
  DepositReserveLiquidityAndObligationCollateralArgs,
@@ -34,7 +34,7 @@ export function initFarmsForReserve(
34
34
  {
35
35
  pubkey: accounts.lendingMarketAuthority,
36
36
  isSigner: false,
37
- isWritable: true,
37
+ isWritable: false,
38
38
  },
39
39
  { pubkey: accounts.reserve, isSigner: false, isWritable: true },
40
40
  { pubkey: accounts.farmsProgram, isSigner: false, isWritable: false },
@@ -36,7 +36,7 @@ export function initObligationFarmsForReserve(
36
36
  {
37
37
  pubkey: accounts.lendingMarketAuthority,
38
38
  isSigner: false,
39
- isWritable: true,
39
+ isWritable: false,
40
40
  },
41
41
  { pubkey: accounts.reserve, isSigner: false, isWritable: true },
42
42
  { pubkey: accounts.reserveFarmState, isSigner: false, isWritable: true },
@@ -14,6 +14,7 @@ export interface InitReserveAccounts {
14
14
  feeReceiver: PublicKey
15
15
  reserveCollateralMint: PublicKey
16
16
  reserveCollateralSupply: PublicKey
17
+ initialLiquiditySource: PublicKey
17
18
  rent: PublicKey
18
19
  liquidityTokenProgram: PublicKey
19
20
  collateralTokenProgram: PublicKey
@@ -54,6 +55,11 @@ export function initReserve(
54
55
  isSigner: false,
55
56
  isWritable: true,
56
57
  },
58
+ {
59
+ pubkey: accounts.initialLiquiditySource,
60
+ isSigner: false,
61
+ isWritable: true,
62
+ },
57
63
  { pubkey: accounts.rent, isSigner: false, isWritable: false },
58
64
  {
59
65
  pubkey: accounts.liquidityTokenProgram,
@@ -57,7 +57,7 @@ export function liquidateObligationAndRedeemReserveCollateral(
57
57
  {
58
58
  pubkey: accounts.repayReserveLiquidityMint,
59
59
  isSigner: false,
60
- isWritable: true,
60
+ isWritable: false,
61
61
  },
62
62
  {
63
63
  pubkey: accounts.repayReserveLiquiditySupply,
@@ -68,7 +68,7 @@ export function liquidateObligationAndRedeemReserveCollateral(
68
68
  {
69
69
  pubkey: accounts.withdrawReserveLiquidityMint,
70
70
  isSigner: false,
71
- isWritable: true,
71
+ isWritable: false,
72
72
  },
73
73
  {
74
74
  pubkey: accounts.withdrawReserveCollateralMint,
@@ -84,7 +84,7 @@ export function liquidateObligationAndRedeemReserveCollateralV2(
84
84
  {
85
85
  pubkey: accounts.liquidationAccounts.repayReserveLiquidityMint,
86
86
  isSigner: false,
87
- isWritable: true,
87
+ isWritable: false,
88
88
  },
89
89
  {
90
90
  pubkey: accounts.liquidationAccounts.repayReserveLiquiditySupply,
@@ -99,7 +99,7 @@ export function liquidateObligationAndRedeemReserveCollateralV2(
99
99
  {
100
100
  pubkey: accounts.liquidationAccounts.withdrawReserveLiquidityMint,
101
101
  isSigner: false,
102
- isWritable: true,
102
+ isWritable: false,
103
103
  },
104
104
  {
105
105
  pubkey: accounts.liquidationAccounts.withdrawReserveCollateralMint,
@@ -23,7 +23,7 @@ export function redeemFees(
23
23
  {
24
24
  pubkey: accounts.reserveLiquidityMint,
25
25
  isSigner: false,
26
- isWritable: true,
26
+ isWritable: false,
27
27
  },
28
28
  {
29
29
  pubkey: accounts.reserveLiquidityFeeReceiver,
@@ -42,7 +42,7 @@ export function redeemReserveCollateral(
42
42
  {
43
43
  pubkey: accounts.reserveLiquidityMint,
44
44
  isSigner: false,
45
- isWritable: true,
45
+ isWritable: false,
46
46
  },
47
47
  {
48
48
  pubkey: accounts.reserveCollateralMint,