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

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 (117) hide show
  1. package/dist/@codegen/klend/accounts/LendingMarket.d.ts +150 -3
  2. package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
  3. package/dist/@codegen/klend/accounts/LendingMarket.js +91 -2
  4. package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
  5. package/dist/@codegen/klend/accounts/Reserve.d.ts +6 -0
  6. package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
  7. package/dist/@codegen/klend/accounts/Reserve.js +8 -1
  8. package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
  9. package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +144 -0
  10. package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +1 -0
  11. package/dist/@codegen/klend/accounts/WithdrawTicket.js +205 -0
  12. package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +1 -0
  13. package/dist/@codegen/klend/accounts/index.d.ts +2 -0
  14. package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
  15. package/dist/@codegen/klend/accounts/index.js +3 -1
  16. package/dist/@codegen/klend/accounts/index.js.map +1 -1
  17. package/dist/@codegen/klend/errors/custom.d.ts +81 -1
  18. package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
  19. package/dist/@codegen/klend/errors/custom.js +142 -1
  20. package/dist/@codegen/klend/errors/custom.js.map +1 -1
  21. package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +62 -0
  22. package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +1 -0
  23. package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +79 -0
  24. package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +1 -0
  25. package/dist/@codegen/klend/instructions/index.d.ts +6 -0
  26. package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
  27. package/dist/@codegen/klend/instructions/index.js +8 -2
  28. package/dist/@codegen/klend/instructions/index.js.map +1 -1
  29. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +54 -0
  30. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +1 -0
  31. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +66 -0
  32. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +1 -0
  33. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +66 -0
  34. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +1 -0
  35. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +41 -0
  36. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +1 -0
  37. package/dist/@codegen/klend/types/BorrowOrder.d.ts +3 -3
  38. package/dist/@codegen/klend/types/BorrowOrder.js +1 -1
  39. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.d.ts +145 -0
  40. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.d.ts.map +1 -0
  41. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.js +144 -0
  42. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.js.map +1 -0
  43. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +29 -0
  44. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
  45. package/dist/@codegen/klend/types/ObligationLiquidity.js +15 -1
  46. package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
  47. package/dist/@codegen/klend/types/ProgressCallbackType.d.ts +32 -0
  48. package/dist/@codegen/klend/types/ProgressCallbackType.d.ts.map +1 -0
  49. package/dist/@codegen/klend/types/ProgressCallbackType.js +108 -0
  50. package/dist/@codegen/klend/types/ProgressCallbackType.js.map +1 -0
  51. package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +26 -8
  52. package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
  53. package/dist/@codegen/klend/types/ReserveLiquidity.js +14 -8
  54. package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
  55. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +7 -7
  56. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
  57. package/dist/@codegen/klend/types/UpdateConfigMode.js +12 -12
  58. package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
  59. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +78 -0
  60. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
  61. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +145 -1
  62. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
  63. package/dist/@codegen/klend/types/WithdrawQueue.d.ts +64 -0
  64. package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +1 -0
  65. package/dist/@codegen/klend/types/WithdrawQueue.js +104 -0
  66. package/dist/@codegen/klend/types/WithdrawQueue.js.map +1 -0
  67. package/dist/@codegen/klend/types/index.d.ts +23 -4
  68. package/dist/@codegen/klend/types/index.d.ts.map +1 -1
  69. package/dist/@codegen/klend/types/index.js +7 -1
  70. package/dist/@codegen/klend/types/index.js.map +1 -1
  71. package/dist/classes/action.d.ts +11 -0
  72. package/dist/classes/action.d.ts.map +1 -1
  73. package/dist/classes/action.js +66 -0
  74. package/dist/classes/action.js.map +1 -1
  75. package/dist/classes/actionTypes.d.ts +29 -0
  76. package/dist/classes/actionTypes.d.ts.map +1 -1
  77. package/dist/classes/manager.d.ts +1 -1
  78. package/dist/classes/manager.d.ts.map +1 -1
  79. package/dist/classes/manager.js +9 -8
  80. package/dist/classes/manager.js.map +1 -1
  81. package/dist/classes/reserve.d.ts +2 -1
  82. package/dist/classes/reserve.d.ts.map +1 -1
  83. package/dist/classes/reserve.js +45 -31
  84. package/dist/classes/reserve.js.map +1 -1
  85. package/dist/idl/klend.json +860 -32
  86. package/dist/manager/client_kamino_manager.js +2 -3
  87. package/dist/manager/client_kamino_manager.js.map +1 -1
  88. package/dist/utils/seeds.d.ts +24 -0
  89. package/dist/utils/seeds.d.ts.map +1 -1
  90. package/dist/utils/seeds.js +41 -1
  91. package/dist/utils/seeds.js.map +1 -1
  92. package/package.json +1 -1
  93. package/src/@codegen/klend/accounts/LendingMarket.ts +205 -4
  94. package/src/@codegen/klend/accounts/Reserve.ts +12 -1
  95. package/src/@codegen/klend/accounts/WithdrawTicket.ts +280 -0
  96. package/src/@codegen/klend/accounts/index.ts +2 -0
  97. package/src/@codegen/klend/errors/custom.ts +161 -0
  98. package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +120 -0
  99. package/src/@codegen/klend/instructions/index.ts +12 -0
  100. package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +103 -0
  101. package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +118 -0
  102. package/src/@codegen/klend/types/BorrowOrder.ts +3 -3
  103. package/src/@codegen/klend/types/FixedTermBorrowRolloverConfig.ts +199 -0
  104. package/src/@codegen/klend/types/ObligationLiquidity.ts +37 -1
  105. package/src/@codegen/klend/types/ProgressCallbackType.ts +91 -0
  106. package/src/@codegen/klend/types/ReserveLiquidity.ts +30 -12
  107. package/src/@codegen/klend/types/UpdateConfigMode.ts +13 -13
  108. package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +180 -0
  109. package/src/@codegen/klend/types/WithdrawQueue.ts +117 -0
  110. package/src/@codegen/klend/types/index.ts +42 -2
  111. package/src/classes/action.ts +115 -1
  112. package/src/classes/actionTypes.ts +31 -0
  113. package/src/classes/manager.ts +19 -27
  114. package/src/classes/reserve.ts +45 -44
  115. package/src/idl/klend.json +860 -32
  116. package/src/manager/client_kamino_manager.ts +2 -4
  117. package/src/utils/seeds.ts +49 -0
@@ -50,7 +50,10 @@ export interface LendingMarketFields {
50
50
  liquidationMaxDebtCloseFactorPct: number
51
51
  /** Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100% */
52
52
  insolvencyRiskUnhealthyLtvPct: number
53
- /** Minimum liquidation value threshold triggering full liquidation for an obligation */
53
+ /**
54
+ * Minimum liquidation value threshold triggering full liquidation for an obligation, in full
55
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
56
+ */
54
57
  minFullLiquidationValueThreshold: BN
55
58
  /** Max allowed liquidation value in one ix call */
56
59
  maxLiquidatableDebtMarketValueAtOnce: BN
@@ -120,6 +123,52 @@ export interface LendingMarketFields {
120
123
  borrowOrderExecutionEnabled: number
121
124
  /** Authority that can propose creating of new reserves but cannot enable them. */
122
125
  proposerAuthority: Address
126
+ /**
127
+ * Whether any new withdraw tickets can be issued (i.e. whether new requests can enter the
128
+ * withdraw queue).
129
+ */
130
+ withdrawTicketIssuanceEnabled: number
131
+ /**
132
+ * Whether the existing withdraw tickets can be redeemed (i.e. whether the tickets can be used
133
+ * to transfer accumulated pending liquidity to destination accounts).
134
+ */
135
+ withdrawTicketRedemptionEnabled: number
136
+ /**
137
+ * Whether the owners can enable the "fixed term borrow rollover" on their obligations.
138
+ *
139
+ * *Note 1:* the actual execution of (different kinds of) rollovers can be disabled by zeroing
140
+ * [Self::fixed_rollover_window_duration_seconds] and
141
+ * [Self::variable_rollover_window_duration_seconds].
142
+ *
143
+ * *Note 2:* when this configuration is disabled, the obligation owners can still disable their
144
+ * rollover (i.e. set the obligation's flags to zeroes).
145
+ */
146
+ obligationBorrowRolloverConfigurationEnabled: number
147
+ padding2: Array<number>
148
+ /**
149
+ * Minimum value that can be withdrawn in a single `withdraw_queued_liquidity()` call, in full
150
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
151
+ */
152
+ minWithdrawQueuedLiquidityValue: BN
153
+ /**
154
+ * A configurable time window (right before the end of a fixed debt term) during which an
155
+ * auto-rollover into another *fixed* rate/term can happen.
156
+ *
157
+ * When zeroed, this rollover mode is effectively disabled.
158
+ *
159
+ * See [FixedTermBorrowRolloverConfig].
160
+ */
161
+ fixedRolloverWindowDurationSeconds: BN
162
+ /**
163
+ * A configurable time window (right before the end of a fixed debt term) during which an
164
+ * auto-rollover into a *variable* (indefinite) rate/term can happen.
165
+ *
166
+ * When zeroed, this rollover mode is effectively disabled.
167
+ *
168
+ * This will typically be shorter than [Self::fixed_rollover_window_duration_seconds], acting
169
+ * as a fallback if a fixed reserve liquidity remains unavailable for considerable time.
170
+ */
171
+ variableRolloverWindowDurationSeconds: BN
123
172
  padding1: Array<BN>
124
173
  }
125
174
 
@@ -158,7 +207,10 @@ export interface LendingMarketJSON {
158
207
  liquidationMaxDebtCloseFactorPct: number
159
208
  /** Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100% */
160
209
  insolvencyRiskUnhealthyLtvPct: number
161
- /** Minimum liquidation value threshold triggering full liquidation for an obligation */
210
+ /**
211
+ * Minimum liquidation value threshold triggering full liquidation for an obligation, in full
212
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
213
+ */
162
214
  minFullLiquidationValueThreshold: string
163
215
  /** Max allowed liquidation value in one ix call */
164
216
  maxLiquidatableDebtMarketValueAtOnce: string
@@ -228,6 +280,52 @@ export interface LendingMarketJSON {
228
280
  borrowOrderExecutionEnabled: number
229
281
  /** Authority that can propose creating of new reserves but cannot enable them. */
230
282
  proposerAuthority: string
283
+ /**
284
+ * Whether any new withdraw tickets can be issued (i.e. whether new requests can enter the
285
+ * withdraw queue).
286
+ */
287
+ withdrawTicketIssuanceEnabled: number
288
+ /**
289
+ * Whether the existing withdraw tickets can be redeemed (i.e. whether the tickets can be used
290
+ * to transfer accumulated pending liquidity to destination accounts).
291
+ */
292
+ withdrawTicketRedemptionEnabled: number
293
+ /**
294
+ * Whether the owners can enable the "fixed term borrow rollover" on their obligations.
295
+ *
296
+ * *Note 1:* the actual execution of (different kinds of) rollovers can be disabled by zeroing
297
+ * [Self::fixed_rollover_window_duration_seconds] and
298
+ * [Self::variable_rollover_window_duration_seconds].
299
+ *
300
+ * *Note 2:* when this configuration is disabled, the obligation owners can still disable their
301
+ * rollover (i.e. set the obligation's flags to zeroes).
302
+ */
303
+ obligationBorrowRolloverConfigurationEnabled: number
304
+ padding2: Array<number>
305
+ /**
306
+ * Minimum value that can be withdrawn in a single `withdraw_queued_liquidity()` call, in full
307
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
308
+ */
309
+ minWithdrawQueuedLiquidityValue: string
310
+ /**
311
+ * A configurable time window (right before the end of a fixed debt term) during which an
312
+ * auto-rollover into another *fixed* rate/term can happen.
313
+ *
314
+ * When zeroed, this rollover mode is effectively disabled.
315
+ *
316
+ * See [FixedTermBorrowRolloverConfig].
317
+ */
318
+ fixedRolloverWindowDurationSeconds: string
319
+ /**
320
+ * A configurable time window (right before the end of a fixed debt term) during which an
321
+ * auto-rollover into a *variable* (indefinite) rate/term can happen.
322
+ *
323
+ * When zeroed, this rollover mode is effectively disabled.
324
+ *
325
+ * This will typically be shorter than [Self::fixed_rollover_window_duration_seconds], acting
326
+ * as a fallback if a fixed reserve liquidity remains unavailable for considerable time.
327
+ */
328
+ variableRolloverWindowDurationSeconds: string
231
329
  padding1: Array<string>
232
330
  }
233
331
 
@@ -266,7 +364,10 @@ export class LendingMarket {
266
364
  readonly liquidationMaxDebtCloseFactorPct: number
267
365
  /** Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100% */
268
366
  readonly insolvencyRiskUnhealthyLtvPct: number
269
- /** Minimum liquidation value threshold triggering full liquidation for an obligation */
367
+ /**
368
+ * Minimum liquidation value threshold triggering full liquidation for an obligation, in full
369
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
370
+ */
270
371
  readonly minFullLiquidationValueThreshold: BN
271
372
  /** Max allowed liquidation value in one ix call */
272
373
  readonly maxLiquidatableDebtMarketValueAtOnce: BN
@@ -336,6 +437,52 @@ export class LendingMarket {
336
437
  readonly borrowOrderExecutionEnabled: number
337
438
  /** Authority that can propose creating of new reserves but cannot enable them. */
338
439
  readonly proposerAuthority: Address
440
+ /**
441
+ * Whether any new withdraw tickets can be issued (i.e. whether new requests can enter the
442
+ * withdraw queue).
443
+ */
444
+ readonly withdrawTicketIssuanceEnabled: number
445
+ /**
446
+ * Whether the existing withdraw tickets can be redeemed (i.e. whether the tickets can be used
447
+ * to transfer accumulated pending liquidity to destination accounts).
448
+ */
449
+ readonly withdrawTicketRedemptionEnabled: number
450
+ /**
451
+ * Whether the owners can enable the "fixed term borrow rollover" on their obligations.
452
+ *
453
+ * *Note 1:* the actual execution of (different kinds of) rollovers can be disabled by zeroing
454
+ * [Self::fixed_rollover_window_duration_seconds] and
455
+ * [Self::variable_rollover_window_duration_seconds].
456
+ *
457
+ * *Note 2:* when this configuration is disabled, the obligation owners can still disable their
458
+ * rollover (i.e. set the obligation's flags to zeroes).
459
+ */
460
+ readonly obligationBorrowRolloverConfigurationEnabled: number
461
+ readonly padding2: Array<number>
462
+ /**
463
+ * Minimum value that can be withdrawn in a single `withdraw_queued_liquidity()` call, in full
464
+ * units of the quote currency (e.g. `2` means "$2", not "2 lamports of USDC").
465
+ */
466
+ readonly minWithdrawQueuedLiquidityValue: BN
467
+ /**
468
+ * A configurable time window (right before the end of a fixed debt term) during which an
469
+ * auto-rollover into another *fixed* rate/term can happen.
470
+ *
471
+ * When zeroed, this rollover mode is effectively disabled.
472
+ *
473
+ * See [FixedTermBorrowRolloverConfig].
474
+ */
475
+ readonly fixedRolloverWindowDurationSeconds: BN
476
+ /**
477
+ * A configurable time window (right before the end of a fixed debt term) during which an
478
+ * auto-rollover into a *variable* (indefinite) rate/term can happen.
479
+ *
480
+ * When zeroed, this rollover mode is effectively disabled.
481
+ *
482
+ * This will typically be shorter than [Self::fixed_rollover_window_duration_seconds], acting
483
+ * as a fallback if a fixed reserve liquidity remains unavailable for considerable time.
484
+ */
485
+ readonly variableRolloverWindowDurationSeconds: BN
339
486
  readonly padding1: Array<BN>
340
487
 
341
488
  static readonly discriminator = Buffer.from([
@@ -378,7 +525,14 @@ export class LendingMarket {
378
525
  borsh.u8("borrowOrderCreationEnabled"),
379
526
  borsh.u8("borrowOrderExecutionEnabled"),
380
527
  borshAddress("proposerAuthority"),
381
- borsh.array(borsh.u64(), 165, "padding1"),
528
+ borsh.u8("withdrawTicketIssuanceEnabled"),
529
+ borsh.u8("withdrawTicketRedemptionEnabled"),
530
+ borsh.u8("obligationBorrowRolloverConfigurationEnabled"),
531
+ borsh.array(borsh.u8(), 5, "padding2"),
532
+ borsh.u64("minWithdrawQueuedLiquidityValue"),
533
+ borsh.u64("fixedRolloverWindowDurationSeconds"),
534
+ borsh.u64("variableRolloverWindowDurationSeconds"),
535
+ borsh.array(borsh.u64(), 161, "padding1"),
382
536
  ])
383
537
 
384
538
  constructor(fields: LendingMarketFields) {
@@ -429,6 +583,18 @@ export class LendingMarket {
429
583
  this.borrowOrderCreationEnabled = fields.borrowOrderCreationEnabled
430
584
  this.borrowOrderExecutionEnabled = fields.borrowOrderExecutionEnabled
431
585
  this.proposerAuthority = fields.proposerAuthority
586
+ this.withdrawTicketIssuanceEnabled = fields.withdrawTicketIssuanceEnabled
587
+ this.withdrawTicketRedemptionEnabled =
588
+ fields.withdrawTicketRedemptionEnabled
589
+ this.obligationBorrowRolloverConfigurationEnabled =
590
+ fields.obligationBorrowRolloverConfigurationEnabled
591
+ this.padding2 = fields.padding2
592
+ this.minWithdrawQueuedLiquidityValue =
593
+ fields.minWithdrawQueuedLiquidityValue
594
+ this.fixedRolloverWindowDurationSeconds =
595
+ fields.fixedRolloverWindowDurationSeconds
596
+ this.variableRolloverWindowDurationSeconds =
597
+ fields.variableRolloverWindowDurationSeconds
432
598
  this.padding1 = fields.padding1
433
599
  }
434
600
 
@@ -523,6 +689,16 @@ export class LendingMarket {
523
689
  borrowOrderCreationEnabled: dec.borrowOrderCreationEnabled,
524
690
  borrowOrderExecutionEnabled: dec.borrowOrderExecutionEnabled,
525
691
  proposerAuthority: dec.proposerAuthority,
692
+ withdrawTicketIssuanceEnabled: dec.withdrawTicketIssuanceEnabled,
693
+ withdrawTicketRedemptionEnabled: dec.withdrawTicketRedemptionEnabled,
694
+ obligationBorrowRolloverConfigurationEnabled:
695
+ dec.obligationBorrowRolloverConfigurationEnabled,
696
+ padding2: dec.padding2,
697
+ minWithdrawQueuedLiquidityValue: dec.minWithdrawQueuedLiquidityValue,
698
+ fixedRolloverWindowDurationSeconds:
699
+ dec.fixedRolloverWindowDurationSeconds,
700
+ variableRolloverWindowDurationSeconds:
701
+ dec.variableRolloverWindowDurationSeconds,
526
702
  padding1: dec.padding1,
527
703
  })
528
704
  }
@@ -573,6 +749,17 @@ export class LendingMarket {
573
749
  borrowOrderCreationEnabled: this.borrowOrderCreationEnabled,
574
750
  borrowOrderExecutionEnabled: this.borrowOrderExecutionEnabled,
575
751
  proposerAuthority: this.proposerAuthority,
752
+ withdrawTicketIssuanceEnabled: this.withdrawTicketIssuanceEnabled,
753
+ withdrawTicketRedemptionEnabled: this.withdrawTicketRedemptionEnabled,
754
+ obligationBorrowRolloverConfigurationEnabled:
755
+ this.obligationBorrowRolloverConfigurationEnabled,
756
+ padding2: this.padding2,
757
+ minWithdrawQueuedLiquidityValue:
758
+ this.minWithdrawQueuedLiquidityValue.toString(),
759
+ fixedRolloverWindowDurationSeconds:
760
+ this.fixedRolloverWindowDurationSeconds.toString(),
761
+ variableRolloverWindowDurationSeconds:
762
+ this.variableRolloverWindowDurationSeconds.toString(),
576
763
  padding1: this.padding1.map((item) => item.toString()),
577
764
  }
578
765
  }
@@ -630,6 +817,20 @@ export class LendingMarket {
630
817
  borrowOrderCreationEnabled: obj.borrowOrderCreationEnabled,
631
818
  borrowOrderExecutionEnabled: obj.borrowOrderExecutionEnabled,
632
819
  proposerAuthority: address(obj.proposerAuthority),
820
+ withdrawTicketIssuanceEnabled: obj.withdrawTicketIssuanceEnabled,
821
+ withdrawTicketRedemptionEnabled: obj.withdrawTicketRedemptionEnabled,
822
+ obligationBorrowRolloverConfigurationEnabled:
823
+ obj.obligationBorrowRolloverConfigurationEnabled,
824
+ padding2: obj.padding2,
825
+ minWithdrawQueuedLiquidityValue: new BN(
826
+ obj.minWithdrawQueuedLiquidityValue
827
+ ),
828
+ fixedRolloverWindowDurationSeconds: new BN(
829
+ obj.fixedRolloverWindowDurationSeconds
830
+ ),
831
+ variableRolloverWindowDurationSeconds: new BN(
832
+ obj.variableRolloverWindowDurationSeconds
833
+ ),
633
834
  padding1: obj.padding1.map((item) => new BN(item)),
634
835
  })
635
836
  }
@@ -39,6 +39,8 @@ export interface ReserveFields {
39
39
  * elevation group when this reserve is part of the collaterals.
40
40
  */
41
41
  borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN>
42
+ /** The tracker of ticket-based withdrawals. */
43
+ withdrawQueue: types.WithdrawQueueFields
42
44
  padding: Array<BN>
43
45
  }
44
46
 
@@ -66,6 +68,8 @@ export interface ReserveJSON {
66
68
  * elevation group when this reserve is part of the collaterals.
67
69
  */
68
70
  borrowedAmountsAgainstThisReserveInElevationGroups: Array<string>
71
+ /** The tracker of ticket-based withdrawals. */
72
+ withdrawQueue: types.WithdrawQueueJSON
69
73
  padding: Array<string>
70
74
  }
71
75
 
@@ -93,6 +97,8 @@ export class Reserve {
93
97
  * elevation group when this reserve is part of the collaterals.
94
98
  */
95
99
  readonly borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN>
100
+ /** The tracker of ticket-based withdrawals. */
101
+ readonly withdrawQueue: types.WithdrawQueue
96
102
  readonly padding: Array<BN>
97
103
 
98
104
  static readonly discriminator = Buffer.from([
@@ -117,7 +123,8 @@ export class Reserve {
117
123
  32,
118
124
  "borrowedAmountsAgainstThisReserveInElevationGroups"
119
125
  ),
120
- borsh.array(borsh.u64(), 207, "padding"),
126
+ types.WithdrawQueue.layout("withdrawQueue"),
127
+ borsh.array(borsh.u64(), 204, "padding"),
121
128
  ])
122
129
 
123
130
  constructor(fields: ReserveFields) {
@@ -136,6 +143,7 @@ export class Reserve {
136
143
  fields.borrowedAmountOutsideElevationGroup
137
144
  this.borrowedAmountsAgainstThisReserveInElevationGroups =
138
145
  fields.borrowedAmountsAgainstThisReserveInElevationGroups
146
+ this.withdrawQueue = new types.WithdrawQueue({ ...fields.withdrawQueue })
139
147
  this.padding = fields.padding
140
148
  }
141
149
 
@@ -202,6 +210,7 @@ export class Reserve {
202
210
  dec.borrowedAmountOutsideElevationGroup,
203
211
  borrowedAmountsAgainstThisReserveInElevationGroups:
204
212
  dec.borrowedAmountsAgainstThisReserveInElevationGroups,
213
+ withdrawQueue: types.WithdrawQueue.fromDecoded(dec.withdrawQueue),
205
214
  padding: dec.padding,
206
215
  })
207
216
  }
@@ -229,6 +238,7 @@ export class Reserve {
229
238
  this.borrowedAmountsAgainstThisReserveInElevationGroups.map((item) =>
230
239
  item.toString()
231
240
  ),
241
+ withdrawQueue: this.withdrawQueue.toJSON(),
232
242
  padding: this.padding.map((item) => item.toString()),
233
243
  }
234
244
  }
@@ -257,6 +267,7 @@ export class Reserve {
257
267
  obj.borrowedAmountsAgainstThisReserveInElevationGroups.map(
258
268
  (item) => new BN(item)
259
269
  ),
270
+ withdrawQueue: types.WithdrawQueue.fromJSON(obj.withdrawQueue),
260
271
  padding: obj.padding.map((item) => new BN(item)),
261
272
  })
262
273
  }
@@ -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
+ }
@@ -19,3 +19,5 @@ export { UserMetadata } from "./UserMetadata"
19
19
  export type { UserMetadataFields, UserMetadataJSON } from "./UserMetadata"
20
20
  export { Reserve } from "./Reserve"
21
21
  export type { ReserveFields, ReserveJSON } from "./Reserve"
22
+ export { WithdrawTicket } from "./WithdrawTicket"
23
+ export type { WithdrawTicketFields, WithdrawTicketJSON } from "./WithdrawTicket"