@kamino-finance/klend-sdk 7.4.0-beta.5 → 7.4.0-beta.7

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 (80) hide show
  1. package/dist/@codegen/klend/accounts/LendingMarket.d.ts +18 -18
  2. package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
  3. package/dist/@codegen/klend/accounts/LendingMarket.js +18 -18
  4. package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
  5. package/dist/@codegen/klend/errors/custom.d.ts +73 -1
  6. package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
  7. package/dist/@codegen/klend/errors/custom.js +127 -1
  8. package/dist/@codegen/klend/errors/custom.js.map +1 -1
  9. package/dist/@codegen/klend/instructions/index.d.ts +4 -0
  10. package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
  11. package/dist/@codegen/klend/instructions/index.js +6 -2
  12. package/dist/@codegen/klend/instructions/index.js.map +1 -1
  13. package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.d.ts +36 -0
  14. package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.d.ts.map +1 -0
  15. package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.js +62 -0
  16. package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.js.map +1 -0
  17. package/dist/@codegen/klend/instructions/updateObligationConfig.d.ts +30 -0
  18. package/dist/@codegen/klend/instructions/updateObligationConfig.d.ts.map +1 -0
  19. package/dist/@codegen/klend/instructions/updateObligationConfig.js +70 -0
  20. package/dist/@codegen/klend/instructions/updateObligationConfig.js.map +1 -0
  21. package/dist/@codegen/klend/types/BorrowOrder.d.ts +62 -0
  22. package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -1
  23. package/dist/@codegen/klend/types/BorrowOrder.js +28 -1
  24. package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -1
  25. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +5 -0
  26. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -1
  27. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +8 -0
  28. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -1
  29. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.d.ts +6 -6
  30. package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.js +2 -2
  31. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +14 -14
  32. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
  33. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +23 -23
  34. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
  35. package/dist/@codegen/klend/types/UpdateObligationConfigMode.d.ts +58 -0
  36. package/dist/@codegen/klend/types/UpdateObligationConfigMode.d.ts.map +1 -0
  37. package/dist/@codegen/klend/types/UpdateObligationConfigMode.js +156 -0
  38. package/dist/@codegen/klend/types/UpdateObligationConfigMode.js.map +1 -0
  39. package/dist/@codegen/klend/types/index.d.ts +16 -2
  40. package/dist/@codegen/klend/types/index.d.ts.map +1 -1
  41. package/dist/@codegen/klend/types/index.js +3 -1
  42. package/dist/@codegen/klend/types/index.js.map +1 -1
  43. package/dist/classes/action.d.ts +5 -2
  44. package/dist/classes/action.d.ts.map +1 -1
  45. package/dist/classes/action.js +99 -3
  46. package/dist/classes/action.js.map +1 -1
  47. package/dist/classes/actionTypes.d.ts +25 -0
  48. package/dist/classes/actionTypes.d.ts.map +1 -1
  49. package/dist/classes/manager.d.ts.map +1 -1
  50. package/dist/classes/manager.js +2 -2
  51. package/dist/classes/manager.js.map +1 -1
  52. package/dist/classes/market.d.ts.map +1 -1
  53. package/dist/classes/market.js.map +1 -1
  54. package/dist/classes/reserve.d.ts +6 -4
  55. package/dist/classes/reserve.d.ts.map +1 -1
  56. package/dist/classes/reserve.js +26 -5
  57. package/dist/classes/reserve.js.map +1 -1
  58. package/dist/idl/klend.json +309 -12
  59. package/dist/utils/seeds.d.ts.map +1 -1
  60. package/dist/utils/seeds.js +5 -1
  61. package/dist/utils/seeds.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/@codegen/klend/accounts/LendingMarket.ts +36 -36
  64. package/src/@codegen/klend/errors/custom.ts +147 -0
  65. package/src/@codegen/klend/instructions/index.ts +7 -0
  66. package/src/@codegen/klend/instructions/rolloverFixedTermBorrow.ts +109 -0
  67. package/src/@codegen/klend/instructions/updateObligationConfig.ts +84 -0
  68. package/src/@codegen/klend/types/BorrowOrder.ts +69 -1
  69. package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +11 -0
  70. package/src/@codegen/klend/types/FixedTermBorrowRolloverConfig.ts +6 -6
  71. package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +26 -26
  72. package/src/@codegen/klend/types/UpdateObligationConfigMode.ts +151 -0
  73. package/src/@codegen/klend/types/index.ts +28 -4
  74. package/src/classes/action.ts +192 -5
  75. package/src/classes/actionTypes.ts +23 -0
  76. package/src/classes/manager.ts +6 -4
  77. package/src/classes/market.ts +4 -1
  78. package/src/classes/reserve.ts +32 -5
  79. package/src/idl/klend.json +309 -12
  80. package/src/utils/seeds.ts +5 -1
@@ -786,48 +786,48 @@ export class UpdateMinWithdrawQueuedLiquidityValue {
786
786
  }
787
787
  }
788
788
 
789
- export interface UpdateFixedRolloverWindowDurationSecondsJSON {
790
- kind: "UpdateFixedRolloverWindowDurationSeconds"
789
+ export interface UpdateFixedTermRolloverWindowDurationSecondsJSON {
790
+ kind: "UpdateFixedTermRolloverWindowDurationSeconds"
791
791
  }
792
792
 
793
- export class UpdateFixedRolloverWindowDurationSeconds {
793
+ export class UpdateFixedTermRolloverWindowDurationSeconds {
794
794
  static readonly discriminator = 34
795
- static readonly kind = "UpdateFixedRolloverWindowDurationSeconds"
795
+ static readonly kind = "UpdateFixedTermRolloverWindowDurationSeconds"
796
796
  readonly discriminator = 34
797
- readonly kind = "UpdateFixedRolloverWindowDurationSeconds"
797
+ readonly kind = "UpdateFixedTermRolloverWindowDurationSeconds"
798
798
 
799
- toJSON(): UpdateFixedRolloverWindowDurationSecondsJSON {
799
+ toJSON(): UpdateFixedTermRolloverWindowDurationSecondsJSON {
800
800
  return {
801
- kind: "UpdateFixedRolloverWindowDurationSeconds",
801
+ kind: "UpdateFixedTermRolloverWindowDurationSeconds",
802
802
  }
803
803
  }
804
804
 
805
805
  toEncodable() {
806
806
  return {
807
- UpdateFixedRolloverWindowDurationSeconds: {},
807
+ UpdateFixedTermRolloverWindowDurationSeconds: {},
808
808
  }
809
809
  }
810
810
  }
811
811
 
812
- export interface UpdateVariableRolloverWindowDurationSecondsJSON {
813
- kind: "UpdateVariableRolloverWindowDurationSeconds"
812
+ export interface UpdateOpenTermRolloverWindowDurationSecondsJSON {
813
+ kind: "UpdateOpenTermRolloverWindowDurationSeconds"
814
814
  }
815
815
 
816
- export class UpdateVariableRolloverWindowDurationSeconds {
816
+ export class UpdateOpenTermRolloverWindowDurationSeconds {
817
817
  static readonly discriminator = 35
818
- static readonly kind = "UpdateVariableRolloverWindowDurationSeconds"
818
+ static readonly kind = "UpdateOpenTermRolloverWindowDurationSeconds"
819
819
  readonly discriminator = 35
820
- readonly kind = "UpdateVariableRolloverWindowDurationSeconds"
820
+ readonly kind = "UpdateOpenTermRolloverWindowDurationSeconds"
821
821
 
822
- toJSON(): UpdateVariableRolloverWindowDurationSecondsJSON {
822
+ toJSON(): UpdateOpenTermRolloverWindowDurationSecondsJSON {
823
823
  return {
824
- kind: "UpdateVariableRolloverWindowDurationSeconds",
824
+ kind: "UpdateOpenTermRolloverWindowDurationSeconds",
825
825
  }
826
826
  }
827
827
 
828
828
  toEncodable() {
829
829
  return {
830
- UpdateVariableRolloverWindowDurationSeconds: {},
830
+ UpdateOpenTermRolloverWindowDurationSeconds: {},
831
831
  }
832
832
  }
833
833
  }
@@ -963,11 +963,11 @@ export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
963
963
  if ("UpdateMinWithdrawQueuedLiquidityValue" in obj) {
964
964
  return new UpdateMinWithdrawQueuedLiquidityValue()
965
965
  }
966
- if ("UpdateFixedRolloverWindowDurationSeconds" in obj) {
967
- return new UpdateFixedRolloverWindowDurationSeconds()
966
+ if ("UpdateFixedTermRolloverWindowDurationSeconds" in obj) {
967
+ return new UpdateFixedTermRolloverWindowDurationSeconds()
968
968
  }
969
- if ("UpdateVariableRolloverWindowDurationSeconds" in obj) {
970
- return new UpdateVariableRolloverWindowDurationSeconds()
969
+ if ("UpdateOpenTermRolloverWindowDurationSeconds" in obj) {
970
+ return new UpdateOpenTermRolloverWindowDurationSeconds()
971
971
  }
972
972
  if ("UpdateObligationBorrowRolloverConfigurationEnabled" in obj) {
973
973
  return new UpdateObligationBorrowRolloverConfigurationEnabled()
@@ -1082,11 +1082,11 @@ export function fromJSON(
1082
1082
  case "UpdateMinWithdrawQueuedLiquidityValue": {
1083
1083
  return new UpdateMinWithdrawQueuedLiquidityValue()
1084
1084
  }
1085
- case "UpdateFixedRolloverWindowDurationSeconds": {
1086
- return new UpdateFixedRolloverWindowDurationSeconds()
1085
+ case "UpdateFixedTermRolloverWindowDurationSeconds": {
1086
+ return new UpdateFixedTermRolloverWindowDurationSeconds()
1087
1087
  }
1088
- case "UpdateVariableRolloverWindowDurationSeconds": {
1089
- return new UpdateVariableRolloverWindowDurationSeconds()
1088
+ case "UpdateOpenTermRolloverWindowDurationSeconds": {
1089
+ return new UpdateOpenTermRolloverWindowDurationSeconds()
1090
1090
  }
1091
1091
  case "UpdateObligationBorrowRolloverConfigurationEnabled": {
1092
1092
  return new UpdateObligationBorrowRolloverConfigurationEnabled()
@@ -1130,8 +1130,8 @@ export function layout(property?: string) {
1130
1130
  borsh.struct([], "UpdateWithdrawTicketIssuanceEnabled"),
1131
1131
  borsh.struct([], "UpdateWithdrawTicketRedemptionEnabled"),
1132
1132
  borsh.struct([], "UpdateMinWithdrawQueuedLiquidityValue"),
1133
- borsh.struct([], "UpdateFixedRolloverWindowDurationSeconds"),
1134
- borsh.struct([], "UpdateVariableRolloverWindowDurationSeconds"),
1133
+ borsh.struct([], "UpdateFixedTermRolloverWindowDurationSeconds"),
1134
+ borsh.struct([], "UpdateOpenTermRolloverWindowDurationSeconds"),
1135
1135
  borsh.struct([], "UpdateObligationBorrowRolloverConfigurationEnabled"),
1136
1136
  ])
1137
1137
  if (property !== undefined) {
@@ -0,0 +1,151 @@
1
+ import { address, Address } from "@solana/kit" // 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 types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as borsh from "@coral-xyz/borsh"
5
+ import { borshAddress } from "../utils"
6
+
7
+ export interface FixedTermRolloverEnabledJSON {
8
+ kind: "FixedTermRolloverEnabled"
9
+ }
10
+
11
+ export class FixedTermRolloverEnabled {
12
+ static readonly discriminator = 0
13
+ static readonly kind = "FixedTermRolloverEnabled"
14
+ readonly discriminator = 0
15
+ readonly kind = "FixedTermRolloverEnabled"
16
+
17
+ toJSON(): FixedTermRolloverEnabledJSON {
18
+ return {
19
+ kind: "FixedTermRolloverEnabled",
20
+ }
21
+ }
22
+
23
+ toEncodable() {
24
+ return {
25
+ FixedTermRolloverEnabled: {},
26
+ }
27
+ }
28
+ }
29
+
30
+ export interface FixedTermRolloverMaxBorrowRateBpsJSON {
31
+ kind: "FixedTermRolloverMaxBorrowRateBps"
32
+ }
33
+
34
+ export class FixedTermRolloverMaxBorrowRateBps {
35
+ static readonly discriminator = 1
36
+ static readonly kind = "FixedTermRolloverMaxBorrowRateBps"
37
+ readonly discriminator = 1
38
+ readonly kind = "FixedTermRolloverMaxBorrowRateBps"
39
+
40
+ toJSON(): FixedTermRolloverMaxBorrowRateBpsJSON {
41
+ return {
42
+ kind: "FixedTermRolloverMaxBorrowRateBps",
43
+ }
44
+ }
45
+
46
+ toEncodable() {
47
+ return {
48
+ FixedTermRolloverMaxBorrowRateBps: {},
49
+ }
50
+ }
51
+ }
52
+
53
+ export interface FixedTermRolloverMinDebtTermSecondsJSON {
54
+ kind: "FixedTermRolloverMinDebtTermSeconds"
55
+ }
56
+
57
+ export class FixedTermRolloverMinDebtTermSeconds {
58
+ static readonly discriminator = 2
59
+ static readonly kind = "FixedTermRolloverMinDebtTermSeconds"
60
+ readonly discriminator = 2
61
+ readonly kind = "FixedTermRolloverMinDebtTermSeconds"
62
+
63
+ toJSON(): FixedTermRolloverMinDebtTermSecondsJSON {
64
+ return {
65
+ kind: "FixedTermRolloverMinDebtTermSeconds",
66
+ }
67
+ }
68
+
69
+ toEncodable() {
70
+ return {
71
+ FixedTermRolloverMinDebtTermSeconds: {},
72
+ }
73
+ }
74
+ }
75
+
76
+ export interface FixedTermRolloverOpenTermAllowedJSON {
77
+ kind: "FixedTermRolloverOpenTermAllowed"
78
+ }
79
+
80
+ export class FixedTermRolloverOpenTermAllowed {
81
+ static readonly discriminator = 3
82
+ static readonly kind = "FixedTermRolloverOpenTermAllowed"
83
+ readonly discriminator = 3
84
+ readonly kind = "FixedTermRolloverOpenTermAllowed"
85
+
86
+ toJSON(): FixedTermRolloverOpenTermAllowedJSON {
87
+ return {
88
+ kind: "FixedTermRolloverOpenTermAllowed",
89
+ }
90
+ }
91
+
92
+ toEncodable() {
93
+ return {
94
+ FixedTermRolloverOpenTermAllowed: {},
95
+ }
96
+ }
97
+ }
98
+
99
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
+ export function fromDecoded(obj: any): types.UpdateObligationConfigModeKind {
101
+ if (typeof obj !== "object") {
102
+ throw new Error("Invalid enum object")
103
+ }
104
+
105
+ if ("FixedTermRolloverEnabled" in obj) {
106
+ return new FixedTermRolloverEnabled()
107
+ }
108
+ if ("FixedTermRolloverMaxBorrowRateBps" in obj) {
109
+ return new FixedTermRolloverMaxBorrowRateBps()
110
+ }
111
+ if ("FixedTermRolloverMinDebtTermSeconds" in obj) {
112
+ return new FixedTermRolloverMinDebtTermSeconds()
113
+ }
114
+ if ("FixedTermRolloverOpenTermAllowed" in obj) {
115
+ return new FixedTermRolloverOpenTermAllowed()
116
+ }
117
+
118
+ throw new Error("Invalid enum object")
119
+ }
120
+
121
+ export function fromJSON(
122
+ obj: types.UpdateObligationConfigModeJSON
123
+ ): types.UpdateObligationConfigModeKind {
124
+ switch (obj.kind) {
125
+ case "FixedTermRolloverEnabled": {
126
+ return new FixedTermRolloverEnabled()
127
+ }
128
+ case "FixedTermRolloverMaxBorrowRateBps": {
129
+ return new FixedTermRolloverMaxBorrowRateBps()
130
+ }
131
+ case "FixedTermRolloverMinDebtTermSeconds": {
132
+ return new FixedTermRolloverMinDebtTermSeconds()
133
+ }
134
+ case "FixedTermRolloverOpenTermAllowed": {
135
+ return new FixedTermRolloverOpenTermAllowed()
136
+ }
137
+ }
138
+ }
139
+
140
+ export function layout(property?: string) {
141
+ const ret = borsh.rustEnum([
142
+ borsh.struct([], "FixedTermRolloverEnabled"),
143
+ borsh.struct([], "FixedTermRolloverMaxBorrowRateBps"),
144
+ borsh.struct([], "FixedTermRolloverMinDebtTermSeconds"),
145
+ borsh.struct([], "FixedTermRolloverOpenTermAllowed"),
146
+ ])
147
+ if (property !== undefined) {
148
+ return ret.replicate(property)
149
+ }
150
+ return ret
151
+ }
@@ -2,6 +2,7 @@ import * as UpdateConfigMode from "./UpdateConfigMode"
2
2
  import * as UpdateLendingMarketConfigValue from "./UpdateLendingMarketConfigValue"
3
3
  import * as UpdateLendingMarketMode from "./UpdateLendingMarketMode"
4
4
  import * as UpdateGlobalConfigMode from "./UpdateGlobalConfigMode"
5
+ import * as UpdateObligationConfigMode from "./UpdateObligationConfigMode"
5
6
  import * as FeeCalculation from "./FeeCalculation"
6
7
  import * as ReserveFarmKind from "./ReserveFarmKind"
7
8
  import * as ReserveStatus from "./ReserveStatus"
@@ -187,8 +188,8 @@ export type UpdateLendingMarketModeKind =
187
188
  | UpdateLendingMarketMode.UpdateWithdrawTicketIssuanceEnabled
188
189
  | UpdateLendingMarketMode.UpdateWithdrawTicketRedemptionEnabled
189
190
  | UpdateLendingMarketMode.UpdateMinWithdrawQueuedLiquidityValue
190
- | UpdateLendingMarketMode.UpdateFixedRolloverWindowDurationSeconds
191
- | UpdateLendingMarketMode.UpdateVariableRolloverWindowDurationSeconds
191
+ | UpdateLendingMarketMode.UpdateFixedTermRolloverWindowDurationSeconds
192
+ | UpdateLendingMarketMode.UpdateOpenTermRolloverWindowDurationSeconds
192
193
  | UpdateLendingMarketMode.UpdateObligationBorrowRolloverConfigurationEnabled
193
194
  export type UpdateLendingMarketModeJSON =
194
195
  | UpdateLendingMarketMode.UpdateOwnerJSON
@@ -225,8 +226,8 @@ export type UpdateLendingMarketModeJSON =
225
226
  | UpdateLendingMarketMode.UpdateWithdrawTicketIssuanceEnabledJSON
226
227
  | UpdateLendingMarketMode.UpdateWithdrawTicketRedemptionEnabledJSON
227
228
  | UpdateLendingMarketMode.UpdateMinWithdrawQueuedLiquidityValueJSON
228
- | UpdateLendingMarketMode.UpdateFixedRolloverWindowDurationSecondsJSON
229
- | UpdateLendingMarketMode.UpdateVariableRolloverWindowDurationSecondsJSON
229
+ | UpdateLendingMarketMode.UpdateFixedTermRolloverWindowDurationSecondsJSON
230
+ | UpdateLendingMarketMode.UpdateOpenTermRolloverWindowDurationSecondsJSON
230
231
  | UpdateLendingMarketMode.UpdateObligationBorrowRolloverConfigurationEnabledJSON
231
232
 
232
233
  export { UpdateGlobalConfigMode }
@@ -269,6 +270,29 @@ export type {
269
270
  ObligationOrderFields,
270
271
  ObligationOrderJSON,
271
272
  } from "./ObligationOrder"
273
+ export { UpdateObligationConfigMode }
274
+
275
+ /**
276
+ * A discriminator of a user-configurable piece of [Obligation].
277
+ *
278
+ * Implementation note: due to TS-side codegen quirks (and a "convention" currently seen e.g.
279
+ * within reserve and market update operations), this is not a true Rust enum. The new value of
280
+ * a config item is provided in a separate handler argument (borsh-serialized), and its expected
281
+ * type is defined by each discriminator here. Additionally, each update mode acts on a specific
282
+ * [ObligationConfigUpdateSubject] (e.g. the auto-rollover of fixed-term borrows is configured on
283
+ * a per-borrow basis), which is also specified by separate handler arguments.
284
+ */
285
+ export type UpdateObligationConfigModeKind =
286
+ | UpdateObligationConfigMode.FixedTermRolloverEnabled
287
+ | UpdateObligationConfigMode.FixedTermRolloverMaxBorrowRateBps
288
+ | UpdateObligationConfigMode.FixedTermRolloverMinDebtTermSeconds
289
+ | UpdateObligationConfigMode.FixedTermRolloverOpenTermAllowed
290
+ export type UpdateObligationConfigModeJSON =
291
+ | UpdateObligationConfigMode.FixedTermRolloverEnabledJSON
292
+ | UpdateObligationConfigMode.FixedTermRolloverMaxBorrowRateBpsJSON
293
+ | UpdateObligationConfigMode.FixedTermRolloverMinDebtTermSecondsJSON
294
+ | UpdateObligationConfigMode.FixedTermRolloverOpenTermAllowedJSON
295
+
272
296
  export { BigFractionBytes } from "./BigFractionBytes"
273
297
  export type {
274
298
  BigFractionBytesFields,
@@ -45,8 +45,11 @@ import {
45
45
  RequestElevationGroupAccounts,
46
46
  RequestElevationGroupArgs,
47
47
  setObligationOrder,
48
+ updateObligationConfig,
49
+ type UpdateObligationConfigAccounts,
48
50
  withdrawObligationCollateralAndRedeemReserveCollateral,
49
51
  withdrawObligationCollateralAndRedeemReserveCollateralV2,
52
+ withdrawObligationCollateralV2,
50
53
  withdrawQueuedLiquidity,
51
54
  withdrawReferrerFees,
52
55
  } from '../@codegen/klend/instructions';
@@ -69,10 +72,11 @@ import {
69
72
  withdrawTicketPda,
70
73
  WRAPPED_SOL_MINT,
71
74
  } from '../utils';
75
+ import { FixedRateReserveKind } from '../utils/ReserveKind';
72
76
  import { getTokenIdsForScopeRefresh, KaminoMarket } from './market';
73
77
  import { isKaminoObligation, KaminoObligation } from './obligation';
74
78
  import { KaminoReserve } from './reserve';
75
- import { ProgressCallbackType, ReserveFarmKind } from '../@codegen/klend/types';
79
+ import { ProgressCallbackType, ReserveFarmKind, UpdateObligationConfigMode } from '../@codegen/klend/types';
76
80
  import { PROGRAM_ID as FARMS_PROGRAM_ID } from '@kamino-finance/farms-sdk/dist/@codegen/farms/programId';
77
81
  import { Reserve } from '../@codegen/klend/accounts';
78
82
  import { VanillaObligation } from '../utils/ObligationType';
@@ -93,6 +97,7 @@ import {
93
97
  BuildDepositReserveLiquidityTxnsProps,
94
98
  BuildRedeemReserveCollateralTxnsProps,
95
99
  BuildWithdrawTxnsProps,
100
+ BuildWithdrawFromObligationAndEnqueueTxnsProps,
96
101
  BuildRepayTxnsProps,
97
102
  BuildDepositAndBorrowTxnsProps,
98
103
  BuildRefreshObligationTxnsProps,
@@ -121,7 +126,8 @@ export type ActionType =
121
126
  | 'requestElevationGroup'
122
127
  | 'withdrawReferrerFees'
123
128
  | 'repayAndWithdrawV2'
124
- | 'depositAndWithdraw';
129
+ | 'depositAndWithdraw'
130
+ | 'withdrawAndEnqueue';
125
131
 
126
132
  export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
127
133
 
@@ -466,6 +472,7 @@ export class KaminoAction {
466
472
  referrer = none(),
467
473
  currentSlot = 0n,
468
474
  overrideElevationGroupRequest,
475
+ rollOver = false,
469
476
  } = props;
470
477
 
471
478
  const axn = await KaminoAction.initialize({
@@ -511,6 +518,9 @@ export class KaminoAction {
511
518
  } else {
512
519
  await axn.addBorrowIx();
513
520
  }
521
+ if (rollOver && axn.reserve.getKind().isFixedRate()) {
522
+ await axn.addBorrowRolloverConfigIxs();
523
+ }
514
524
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
515
525
 
516
526
  return axn;
@@ -1006,6 +1016,72 @@ export class KaminoAction {
1006
1016
  return axn;
1007
1017
  }
1008
1018
 
1019
+ static async buildWithdrawFromObligationAndEnqueueTxns(props: BuildWithdrawFromObligationAndEnqueueTxnsProps) {
1020
+ const {
1021
+ kaminoMarket,
1022
+ collateralAmount,
1023
+ reserveAddress,
1024
+ owner,
1025
+ obligation,
1026
+ scopeRefreshConfig,
1027
+ extraComputeBudget = 1_000_000,
1028
+ includeAtaIxs = true,
1029
+ requestElevationGroup = false,
1030
+ initUserMetadata = { skipInitialization: false, skipLutCreation: false },
1031
+ referrer = none(),
1032
+ currentSlot = 0n,
1033
+ userDestinationLiquidityAta,
1034
+ progressCallbackType = new ProgressCallbackType.None(),
1035
+ progressCallbackCustomAccount0 = none(),
1036
+ progressCallbackCustomAccount1 = none(),
1037
+ } = props;
1038
+
1039
+ const axn = await KaminoAction.initialize({
1040
+ kaminoMarket,
1041
+ action: 'withdrawAndEnqueue',
1042
+ amount: collateralAmount,
1043
+ reserveAddress,
1044
+ owner,
1045
+ obligation,
1046
+ referrer,
1047
+ currentSlot,
1048
+ });
1049
+
1050
+ if (extraComputeBudget > 0) {
1051
+ axn.addComputeBudgetIx(extraComputeBudget);
1052
+ }
1053
+
1054
+ await axn.addSupportIxs(
1055
+ 'withdrawAndEnqueue',
1056
+ includeAtaIxs,
1057
+ requestElevationGroup,
1058
+ true,
1059
+ true,
1060
+ scopeRefreshConfig,
1061
+ initUserMetadata
1062
+ );
1063
+
1064
+ await axn.addWithdrawObligationCollateralIxV2(axn.amount);
1065
+
1066
+ const destinationLiquidityAta = userDestinationLiquidityAta ?? (await axn.getUserTokenAccountAddress(axn.reserve));
1067
+ const enqueueIx = await KaminoAction.buildEnqueueToWithdrawIx(
1068
+ owner,
1069
+ kaminoMarket,
1070
+ axn.reserve,
1071
+ axn.amount,
1072
+ destinationLiquidityAta,
1073
+ progressCallbackType,
1074
+ progressCallbackCustomAccount0,
1075
+ progressCallbackCustomAccount1
1076
+ );
1077
+ axn.lendingIxs.push(enqueueIx);
1078
+ axn.lendingIxsLabels.push(`enqueueToWithdraw`);
1079
+
1080
+ axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
1081
+
1082
+ return axn;
1083
+ }
1084
+
1009
1085
  /**
1010
1086
  * Build repay transactions
1011
1087
  * @param props - BuildRepayTxnsProps containing all required and optional parameters
@@ -1188,7 +1264,9 @@ export class KaminoAction {
1188
1264
  reserve: KaminoReserve,
1189
1265
  collateralAmount: BN,
1190
1266
  userDestinationLiquidityTa: Address,
1191
- progressCallbackType: ProgressCallbackType.None | ProgressCallbackType.KlendQueueAccountingHandlerOnKvault = new ProgressCallbackType.None(),
1267
+ progressCallbackType:
1268
+ | ProgressCallbackType.None
1269
+ | ProgressCallbackType.KlendQueueAccountingHandlerOnKvault = new ProgressCallbackType.None(),
1192
1270
  progressCallbackCustomAccount0: Option<Address> = none(),
1193
1271
  progressCallbackCustomAccount1: Option<Address> = none()
1194
1272
  ): Promise<Instruction> {
@@ -1560,6 +1638,73 @@ export class KaminoAction {
1560
1638
  this.lendingIxs.push(borrowIx);
1561
1639
  }
1562
1640
 
1641
+ private async addBorrowRolloverConfigIxs(): Promise<void> {
1642
+ const reserveKind = this.reserve.getKind() as FixedRateReserveKind;
1643
+ const borrowRateBps = reserveKind.borrowRateBps;
1644
+ const maxBorrowRateBpsBytes = Buffer.alloc(4);
1645
+ maxBorrowRateBpsBytes.writeUInt32LE(borrowRateBps, 0);
1646
+
1647
+ const minDebtTermSecondsBytes = Buffer.alloc(8);
1648
+ minDebtTermSecondsBytes.writeBigUInt64LE(BigInt(reserveKind.debtTermSeconds.toString()), 0);
1649
+
1650
+ const obligation = await this.getObligationPda();
1651
+ const accounts: UpdateObligationConfigAccounts = {
1652
+ owner: this.owner,
1653
+ obligation,
1654
+ borrowReserve: some(this.reserve.address),
1655
+ depositReserve: none<Address>(),
1656
+ lendingMarket: this.kaminoMarket.getAddress(),
1657
+ };
1658
+
1659
+ const updateRolloverIx = updateObligationConfig(
1660
+ {
1661
+ mode: new UpdateObligationConfigMode.FixedTermRolloverEnabled(),
1662
+ value: Uint8Array.from([1]),
1663
+ },
1664
+ accounts,
1665
+ undefined,
1666
+ this.kaminoMarket.programId
1667
+ );
1668
+ this.lendingIxs.push(updateRolloverIx);
1669
+ this.lendingIxsLabels.push('updateObligationConfig[FixedTermRolloverEnabled]');
1670
+
1671
+ const updateMaxBorrowRateIx = updateObligationConfig(
1672
+ {
1673
+ mode: new UpdateObligationConfigMode.FixedTermRolloverMaxBorrowRateBps(),
1674
+ value: maxBorrowRateBpsBytes,
1675
+ },
1676
+ accounts,
1677
+ undefined,
1678
+ this.kaminoMarket.programId
1679
+ );
1680
+ this.lendingIxs.push(updateMaxBorrowRateIx);
1681
+ this.lendingIxsLabels.push('updateObligationConfig[FixedTermRolloverMaxBorrowRateBps]');
1682
+
1683
+ const updateMinDebtTermIx = updateObligationConfig(
1684
+ {
1685
+ mode: new UpdateObligationConfigMode.FixedTermRolloverMinDebtTermSeconds(),
1686
+ value: minDebtTermSecondsBytes,
1687
+ },
1688
+ accounts,
1689
+ undefined,
1690
+ this.kaminoMarket.programId
1691
+ );
1692
+ this.lendingIxs.push(updateMinDebtTermIx);
1693
+ this.lendingIxsLabels.push('updateObligationConfig[FixedTermRolloverMinDebtTermSeconds]');
1694
+
1695
+ const updateOpenTermAllowedIx = updateObligationConfig(
1696
+ {
1697
+ mode: new UpdateObligationConfigMode.FixedTermRolloverOpenTermAllowed(),
1698
+ value: Uint8Array.from([1]),
1699
+ },
1700
+ accounts,
1701
+ undefined,
1702
+ this.kaminoMarket.programId
1703
+ );
1704
+ this.lendingIxs.push(updateOpenTermAllowedIx);
1705
+ this.lendingIxsLabels.push('updateObligationConfig[FixedTermRolloverOpenTermAllowed]');
1706
+ }
1707
+
1563
1708
  /// @deprecated -- use addWithdrawIxV2 instead
1564
1709
  async addWithdrawIx(collateralAmount: BN) {
1565
1710
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
@@ -1628,6 +1773,39 @@ export class KaminoAction {
1628
1773
  );
1629
1774
  }
1630
1775
 
1776
+ async addWithdrawObligationCollateralIxV2(collateralAmount: BN): Promise<void> {
1777
+ const obligationAddress = await this.getObligationPda();
1778
+ const { collateralFarmAccounts: farmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
1779
+ obligationAddress,
1780
+ this.reserve
1781
+ );
1782
+ this.lendingIxsLabels.push(`withdrawObligationCollateralV2`);
1783
+ this.lendingIxs.push(
1784
+ withdrawObligationCollateralV2(
1785
+ {
1786
+ collateralAmount,
1787
+ },
1788
+ {
1789
+ withdrawAccounts: {
1790
+ owner: this.owner,
1791
+ obligation: obligationAddress,
1792
+ lendingMarket: this.kaminoMarket.getAddress(),
1793
+ lendingMarketAuthority: await this.kaminoMarket.getLendingMarketAuthority(),
1794
+ withdrawReserve: this.reserve.address,
1795
+ reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
1796
+ userDestinationCollateral: await this.getUserCollateralAccountAddress(this.reserve),
1797
+ tokenProgram: TOKEN_PROGRAM_ADDRESS,
1798
+ instructionSysvarAccount: SYSVAR_INSTRUCTIONS_ADDRESS,
1799
+ },
1800
+ farmsAccounts,
1801
+ farmsProgram: FARMS_PROGRAM_ID,
1802
+ },
1803
+ undefined,
1804
+ this.kaminoMarket.programId
1805
+ )
1806
+ );
1807
+ }
1808
+
1631
1809
  /// @deprecated -- use addRepayIxV2 instead
1632
1810
  async addRepayIx() {
1633
1811
  const obligationAddress = await this.getObligationPda();
@@ -2422,6 +2600,7 @@ export class KaminoAction {
2422
2600
  'depositCollateral',
2423
2601
  'deposit',
2424
2602
  'withdraw',
2603
+ 'withdrawAndEnqueue',
2425
2604
  'borrow',
2426
2605
  'liquidate',
2427
2606
  'repay',
@@ -2496,6 +2675,7 @@ export class KaminoAction {
2496
2675
  action === 'depositAndBorrow' ||
2497
2676
  action === 'depositCollateral' ||
2498
2677
  action === 'withdraw' ||
2678
+ action === 'withdrawAndEnqueue' ||
2499
2679
  action === 'deposit' ||
2500
2680
  action === 'depositAndWithdraw'
2501
2681
  ) {
@@ -2663,6 +2843,7 @@ export class KaminoAction {
2663
2843
  action === 'depositAndBorrow' ||
2664
2844
  action === 'depositCollateral' ||
2665
2845
  action === 'withdraw' ||
2846
+ action === 'withdrawAndEnqueue' ||
2666
2847
  action === 'deposit'
2667
2848
  ) {
2668
2849
  await this.addRefreshFarmsForReserve(
@@ -3221,7 +3402,13 @@ export class KaminoAction {
3221
3402
  await this.updateWSOLAccount(action);
3222
3403
  }
3223
3404
 
3224
- if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && this.mint !== WRAPPED_SOL_MINT) {
3405
+ if (
3406
+ (action === 'withdraw' ||
3407
+ action === 'withdrawAndEnqueue' ||
3408
+ action === 'borrow' ||
3409
+ action === 'redeem') &&
3410
+ this.mint !== WRAPPED_SOL_MINT
3411
+ ) {
3225
3412
  const reserveAta = await this.getUserTokenAccountAddress(this.reserve);
3226
3413
  const [, createUserTokenAccountIx] = await createAssociatedTokenAccountIdempotentInstruction(
3227
3414
  this.owner,
@@ -3303,7 +3490,7 @@ export class KaminoAction {
3303
3490
  this.setupIxs.unshift(createUserTokenAccountIx);
3304
3491
  this.setupIxsLabels.unshift(`CreateUserAta[${reserveAta}]`);
3305
3492
  }
3306
- if (action === 'mint') {
3493
+ if (action === 'mint' || action === 'withdrawAndEnqueue') {
3307
3494
  const ctokenAta = await this.getUserCollateralAccountAddress(this.reserve);
3308
3495
  const [, createUserCollateralAccountIx] = await createAssociatedTokenAccountIdempotentInstruction(
3309
3496
  this.owner,
@@ -60,6 +60,7 @@ export interface BuildBorrowTxnsProps {
60
60
  referrer?: Option<Address>;
61
61
  currentSlot?: Slot;
62
62
  overrideElevationGroupRequest?: number;
63
+ rollOver?: boolean;
63
64
  }
64
65
 
65
66
  /**
@@ -119,6 +120,28 @@ export interface BuildWithdrawTxnsProps {
119
120
  };
120
121
  }
121
122
 
123
+ /**
124
+ * Props for KaminoAction.buildWithdrawFromObligationAndEnqueueTxns
125
+ */
126
+ export interface BuildWithdrawFromObligationAndEnqueueTxnsProps {
127
+ kaminoMarket: KaminoMarket;
128
+ collateralAmount: string | BN;
129
+ reserveAddress: Address;
130
+ owner: TransactionSigner;
131
+ obligation: KaminoObligation | ObligationType;
132
+ scopeRefreshConfig: ScopePriceRefreshConfig | undefined;
133
+ extraComputeBudget?: number;
134
+ includeAtaIxs?: boolean;
135
+ requestElevationGroup?: boolean;
136
+ initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean };
137
+ referrer?: Option<Address>;
138
+ currentSlot?: Slot;
139
+ userDestinationLiquidityAta?: Address;
140
+ progressCallbackType?: ProgressCallbackType.None | ProgressCallbackType.KlendQueueAccountingHandlerOnKvault;
141
+ progressCallbackCustomAccount0?: Option<Address>;
142
+ progressCallbackCustomAccount1?: Option<Address>;
143
+ }
144
+
122
145
  /**
123
146
  * Props for KaminoAction.buildRepayTxns
124
147
  */
@@ -538,7 +538,6 @@ export class KaminoManager {
538
538
  : (await Reserve.fetch(this._rpc, reserve, this._kaminoLendProgramId))!;
539
539
  const ixs: Instruction[] = [];
540
540
 
541
-
542
541
  ixs.push(
543
542
  ...(await parseForChangesReserveConfigAndGetIxs(
544
543
  marketWithAddress,
@@ -1790,9 +1789,12 @@ export const MARKET_UPDATER = new ConfigUpdater(UpdateLendingMarketMode.fromDeco
1790
1789
  [UpdateLendingMarketMode.UpdateWithdrawTicketIssuanceEnabled.kind]: config.withdrawTicketIssuanceEnabled,
1791
1790
  [UpdateLendingMarketMode.UpdateWithdrawTicketRedemptionEnabled.kind]: config.withdrawTicketRedemptionEnabled,
1792
1791
  [UpdateLendingMarketMode.UpdateMinWithdrawQueuedLiquidityValue.kind]: config.minWithdrawQueuedLiquidityValue,
1793
- [UpdateLendingMarketMode.UpdateFixedRolloverWindowDurationSeconds.kind]: config.fixedRolloverWindowDurationSeconds,
1794
- [UpdateLendingMarketMode.UpdateVariableRolloverWindowDurationSeconds.kind]: config.variableRolloverWindowDurationSeconds,
1795
- [UpdateLendingMarketMode.UpdateObligationBorrowRolloverConfigurationEnabled.kind]: config.obligationBorrowRolloverConfigurationEnabled,
1792
+ [UpdateLendingMarketMode.UpdateFixedTermRolloverWindowDurationSeconds.kind]:
1793
+ config.fixedTermRolloverWindowDurationSeconds,
1794
+ [UpdateLendingMarketMode.UpdateOpenTermRolloverWindowDurationSeconds.kind]:
1795
+ config.openTermRolloverWindowDurationSeconds,
1796
+ [UpdateLendingMarketMode.UpdateObligationBorrowRolloverConfigurationEnabled.kind]:
1797
+ config.obligationBorrowRolloverConfigurationEnabled,
1796
1798
  }));
1797
1799
 
1798
1800
  function parseForChangesMarketConfigAndGetIxs(