@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
@@ -40,7 +40,7 @@ export function refreshObligationFarmsForReserve(
40
40
  {
41
41
  pubkey: accounts.baseAccounts.lendingMarketAuthority,
42
42
  isSigner: false,
43
- isWritable: true,
43
+ isWritable: false,
44
44
  },
45
45
  {
46
46
  pubkey: accounts.baseAccounts.reserve,
@@ -37,6 +37,15 @@ export interface RepayAndWithdrawAndRedeemAccounts {
37
37
  liquidityTokenProgram: PublicKey
38
38
  instructionSysvarAccount: PublicKey
39
39
  }
40
+ collateralFarmsAccounts: {
41
+ obligationFarmUserState: PublicKey
42
+ reserveFarmState: PublicKey
43
+ }
44
+ debtFarmsAccounts: {
45
+ obligationFarmUserState: PublicKey
46
+ reserveFarmState: PublicKey
47
+ }
48
+ farmsProgram: PublicKey
40
49
  }
41
50
 
42
51
  export const layout = borsh.struct([
@@ -69,7 +78,7 @@ export function repayAndWithdrawAndRedeem(
69
78
  {
70
79
  pubkey: accounts.repayAccounts.reserveLiquidityMint,
71
80
  isSigner: false,
72
- isWritable: true,
81
+ isWritable: false,
73
82
  },
74
83
  {
75
84
  pubkey: accounts.repayAccounts.reserveDestinationLiquidity,
@@ -94,7 +103,7 @@ export function repayAndWithdrawAndRedeem(
94
103
  {
95
104
  pubkey: accounts.withdrawAccounts.owner,
96
105
  isSigner: true,
97
- isWritable: false,
106
+ isWritable: true,
98
107
  },
99
108
  {
100
109
  pubkey: accounts.withdrawAccounts.obligation,
@@ -119,7 +128,7 @@ export function repayAndWithdrawAndRedeem(
119
128
  {
120
129
  pubkey: accounts.withdrawAccounts.reserveLiquidityMint,
121
130
  isSigner: false,
122
- isWritable: true,
131
+ isWritable: false,
123
132
  },
124
133
  {
125
134
  pubkey: accounts.withdrawAccounts.reserveSourceCollateral,
@@ -161,6 +170,27 @@ export function repayAndWithdrawAndRedeem(
161
170
  isSigner: false,
162
171
  isWritable: false,
163
172
  },
173
+ {
174
+ pubkey: accounts.collateralFarmsAccounts.obligationFarmUserState,
175
+ isSigner: false,
176
+ isWritable: true,
177
+ },
178
+ {
179
+ pubkey: accounts.collateralFarmsAccounts.reserveFarmState,
180
+ isSigner: false,
181
+ isWritable: true,
182
+ },
183
+ {
184
+ pubkey: accounts.debtFarmsAccounts.obligationFarmUserState,
185
+ isSigner: false,
186
+ isWritable: true,
187
+ },
188
+ {
189
+ pubkey: accounts.debtFarmsAccounts.reserveFarmState,
190
+ isSigner: false,
191
+ isWritable: true,
192
+ },
193
+ { pubkey: accounts.farmsProgram, isSigner: false, isWritable: false },
164
194
  ]
165
195
  const identifier = Buffer.from([2, 54, 152, 3, 148, 96, 109, 218])
166
196
  const buffer = Buffer.alloc(1000)
@@ -35,7 +35,7 @@ export function repayObligationLiquidity(
35
35
  {
36
36
  pubkey: accounts.reserveLiquidityMint,
37
37
  isSigner: false,
38
- isWritable: true,
38
+ isWritable: false,
39
39
  },
40
40
  {
41
41
  pubkey: accounts.reserveDestinationLiquidity,
@@ -55,7 +55,7 @@ export function repayObligationLiquidityV2(
55
55
  {
56
56
  pubkey: accounts.repayAccounts.reserveLiquidityMint,
57
57
  isSigner: false,
58
- isWritable: true,
58
+ isWritable: false,
59
59
  },
60
60
  {
61
61
  pubkey: accounts.repayAccounts.reserveDestinationLiquidity,
@@ -33,7 +33,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateral(
33
33
  programId: PublicKey = PROGRAM_ID
34
34
  ) {
35
35
  const keys: Array<AccountMeta> = [
36
- { pubkey: accounts.owner, isSigner: true, isWritable: false },
36
+ { pubkey: accounts.owner, isSigner: true, isWritable: true },
37
37
  { pubkey: accounts.obligation, isSigner: false, isWritable: true },
38
38
  { pubkey: accounts.lendingMarket, isSigner: false, isWritable: false },
39
39
  {
@@ -45,7 +45,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateral(
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.reserveSourceCollateral,
@@ -43,7 +43,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateralV2(
43
43
  {
44
44
  pubkey: accounts.withdrawAccounts.owner,
45
45
  isSigner: true,
46
- isWritable: false,
46
+ isWritable: true,
47
47
  },
48
48
  {
49
49
  pubkey: accounts.withdrawAccounts.obligation,
@@ -68,7 +68,7 @@ export function withdrawObligationCollateralAndRedeemReserveCollateralV2(
68
68
  {
69
69
  pubkey: accounts.withdrawAccounts.reserveLiquidityMint,
70
70
  isSigner: false,
71
- isWritable: true,
71
+ isWritable: false,
72
72
  },
73
73
  {
74
74
  pubkey: accounts.withdrawAccounts.reserveSourceCollateral,
@@ -33,7 +33,7 @@ export function withdrawProtocolFee(
33
33
  {
34
34
  pubkey: accounts.reserveLiquidityMint,
35
35
  isSigner: false,
36
- isWritable: true,
36
+ isWritable: false,
37
37
  },
38
38
  {
39
39
  pubkey: accounts.lendingMarketAuthority,
@@ -27,7 +27,7 @@ export function withdrawReferrerFees(
27
27
  {
28
28
  pubkey: accounts.reserveLiquidityMint,
29
29
  isSigner: false,
30
- isWritable: true,
30
+ isWritable: false,
31
31
  },
32
32
  {
33
33
  pubkey: accounts.reserveSupplyLiquidity,
@@ -486,6 +486,29 @@ export class UpdateIndividualAutodeleverageMarginCallPeriodSecs {
486
486
  }
487
487
  }
488
488
 
489
+ export interface UpdateInitialDepositAmountJSON {
490
+ kind: "UpdateInitialDepositAmount"
491
+ }
492
+
493
+ export class UpdateInitialDepositAmount {
494
+ static readonly discriminator = 21
495
+ static readonly kind = "UpdateInitialDepositAmount"
496
+ readonly discriminator = 21
497
+ readonly kind = "UpdateInitialDepositAmount"
498
+
499
+ toJSON(): UpdateInitialDepositAmountJSON {
500
+ return {
501
+ kind: "UpdateInitialDepositAmount",
502
+ }
503
+ }
504
+
505
+ toEncodable() {
506
+ return {
507
+ UpdateInitialDepositAmount: {},
508
+ }
509
+ }
510
+ }
511
+
489
512
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
490
513
  export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
491
514
  if (typeof obj !== "object") {
@@ -555,6 +578,9 @@ export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
555
578
  if ("UpdateIndividualAutodeleverageMarginCallPeriodSecs" in obj) {
556
579
  return new UpdateIndividualAutodeleverageMarginCallPeriodSecs()
557
580
  }
581
+ if ("UpdateInitialDepositAmount" in obj) {
582
+ return new UpdateInitialDepositAmount()
583
+ }
558
584
 
559
585
  throw new Error("Invalid enum object")
560
586
  }
@@ -626,6 +652,9 @@ export function fromJSON(
626
652
  case "UpdateIndividualAutodeleverageMarginCallPeriodSecs": {
627
653
  return new UpdateIndividualAutodeleverageMarginCallPeriodSecs()
628
654
  }
655
+ case "UpdateInitialDepositAmount": {
656
+ return new UpdateInitialDepositAmount()
657
+ }
629
658
  }
630
659
  }
631
660
 
@@ -652,6 +681,7 @@ export function layout(property?: string) {
652
681
  borsh.struct([], "UpdatePaddingFields"),
653
682
  borsh.struct([], "UpdateName"),
654
683
  borsh.struct([], "UpdateIndividualAutodeleverageMarginCallPeriodSecs"),
684
+ borsh.struct([], "UpdateInitialDepositAmount"),
655
685
  ])
656
686
  if (property !== undefined) {
657
687
  return ret.replicate(property)
@@ -156,6 +156,7 @@ export type UpdateLendingMarketModeKind =
156
156
  | UpdateLendingMarketMode.UpdatePaddingFields
157
157
  | UpdateLendingMarketMode.UpdateName
158
158
  | UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs
159
+ | UpdateLendingMarketMode.UpdateInitialDepositAmount
159
160
  export type UpdateLendingMarketModeJSON =
160
161
  | UpdateLendingMarketMode.UpdateOwnerJSON
161
162
  | UpdateLendingMarketMode.UpdateEmergencyModeJSON
@@ -178,6 +179,7 @@ export type UpdateLendingMarketModeJSON =
178
179
  | UpdateLendingMarketMode.UpdatePaddingFieldsJSON
179
180
  | UpdateLendingMarketMode.UpdateNameJSON
180
181
  | UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecsJSON
182
+ | UpdateLendingMarketMode.UpdateInitialDepositAmountJSON
181
183
 
182
184
  export { LastUpdate } from "./LastUpdate"
183
185
  export type { LastUpdateFields, LastUpdateJSON } from "./LastUpdate"
@@ -48,13 +48,21 @@ export class ObligationZP {
48
48
  readonly referrer: PublicKey
49
49
  /** Marked = 1 if borrowing disabled, 0 = borrowing enabled */
50
50
  readonly borrowingDisabled: number
51
- /** A target LTV set by the risk council when marking this obligation for deleveraging. Only effective when `deleveraging_margin_call_started_slot != 0`. */
51
+ /**
52
+ * A target LTV set by the risk council when marking this obligation for deleveraging.
53
+ * Only effective when `deleveraging_margin_call_started_slot != 0`.
54
+ * */
52
55
  readonly autodeleverageTargetLtvPct: number
53
- readonly reserved: Array<BN>;
56
+ /** The lowest max LTV found amongst the collateral deposits */
57
+ readonly lowestReserveDepositMaxLtvPct: number
58
+ readonly reserved: Array<number>
54
59
  readonly highestBorrowFactorPct: BN
55
- /** A timestamp at which the risk council most-recently marked this obligation for deleveraging. Zero if not currently subject to deleveraging. */
60
+ /**
61
+ * A timestamp at which the risk council most-recently marked this obligation for deleveraging.
62
+ * Zero if not currently subject to deleveraging.
63
+ * */
56
64
  readonly autodeleverageMarginCallStartedTimestamp: BN
57
- padding3: Array<BN> = new Array(0)
65
+ readonly padding3: Array<BN> = new Array(0)
58
66
 
59
67
  static readonly layout = borsh.struct([
60
68
  borsh.u64("tag"),
@@ -77,7 +85,8 @@ export class ObligationZP {
77
85
  borsh.publicKey("referrer"),
78
86
  borsh.u8("borrowingDisabled"),
79
87
  borsh.u8("autodeleverageTargetLtvPct"),
80
- borsh.array(borsh.u8(), 6, "reserved"),
88
+ borsh.u8("lowestReserveDepositMaxLtvPct"),
89
+ borsh.array(borsh.u8(), 5, "reserved"),
81
90
  borsh.u64("highestBorrowFactorPct"),
82
91
  borsh.u64("autodeleverageMarginCallStartedTimestamp"),
83
92
  ])
@@ -109,7 +118,8 @@ export class ObligationZP {
109
118
  this.referrer = fields.referrer
110
119
  this.borrowingDisabled = fields.borrowingDisabled
111
120
  this.autodeleverageTargetLtvPct = fields.autodeleverageTargetLtvPct
112
- this.reserved = fields.reserved.map((num) => new BN(num))
121
+ this.lowestReserveDepositMaxLtvPct = fields.lowestReserveDepositMaxLtvPct
122
+ this.reserved = new Array<number>(0)
113
123
  this.highestBorrowFactorPct = fields.highestBorrowFactorPct
114
124
  this.autodeleverageMarginCallStartedTimestamp = fields.autodeleverageMarginCallStartedTimestamp
115
125
  this.padding3 = new Array<BN>(0);
@@ -187,10 +197,11 @@ export class ObligationZP {
187
197
  referrer: dec.referrer,
188
198
  borrowingDisabled: dec.borrowingDisabled,
189
199
  autodeleverageTargetLtvPct: dec.autodeleverageTargetLtvPct,
200
+ lowestReserveDepositMaxLtvPct: dec.lowestReserveDepositMaxLtvPct,
190
201
  reserved: dec.reserved,
191
202
  highestBorrowFactorPct: dec.highestBorrowFactorPct,
192
203
  autodeleverageMarginCallStartedTimestamp: dec.autodeleverageMarginCallStartedTimestamp,
193
204
  padding3: [],
194
205
  })
195
206
  }
196
- }
207
+ }
@@ -52,6 +52,7 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
52
52
  isClosingPosition: boolean;
53
53
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
54
54
  scopeRefresh?: ScopeRefresh;
55
+ useV2Ixs: boolean;
55
56
  quoter: SwapQuoteProvider<QuoteResponse>;
56
57
  }
57
58
 
@@ -67,6 +68,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
67
68
  isClosingPosition,
68
69
  budgetAndPriorityFeeIxs,
69
70
  scopeRefresh,
71
+ useV2Ixs,
70
72
  }: RepayWithCollSwapInputsProps<QuoteResponse>): Promise<{
71
73
  swapInputs: SwapInputs;
72
74
  initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
@@ -132,7 +134,8 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
132
134
  },
133
135
  isClosingPosition,
134
136
  repayAmountLamports,
135
- inputAmountLamports
137
+ inputAmountLamports,
138
+ useV2Ixs
136
139
  );
137
140
  const uniqueKlendAccounts = uniqueAccounts(klendIxs);
138
141
 
@@ -189,6 +192,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
189
192
  swapper,
190
193
  referrer,
191
194
  scopeRefresh,
195
+ useV2Ixs,
192
196
  logger = console.log,
193
197
  }: RepayWithCollIxsProps<QuoteResponse>): Promise<RepayWithCollIxsResponse<QuoteResponse>> {
194
198
  const { swapInputs, initialInputs } = await getRepayWithCollSwapInputs({
@@ -203,6 +207,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
203
207
  isClosingPosition,
204
208
  budgetAndPriorityFeeIxs,
205
209
  scopeRefresh,
210
+ useV2Ixs,
206
211
  });
207
212
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
208
213
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
@@ -243,7 +248,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
243
248
  swapResponse,
244
249
  isClosingPosition,
245
250
  debtRepayAmountLamports,
246
- swapInputs.inputAmountLamports
251
+ swapInputs.inputAmountLamports,
252
+ useV2Ixs
247
253
  );
248
254
 
249
255
  return {
@@ -266,7 +272,8 @@ async function buildRepayWithCollateralIxs(
266
272
  swapQuoteIxs: SwapIxs,
267
273
  isClosingPosition: boolean,
268
274
  debtRepayAmountLamports: Decimal,
269
- collWithdrawLamports: Decimal
275
+ collWithdrawLamports: Decimal,
276
+ useV2Ixs: boolean
270
277
  ): Promise<TransactionInstruction[]> {
271
278
  // 1. Create atas & budget txns
272
279
  const budgetIxns = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxns(1_400_000);
@@ -306,10 +313,12 @@ async function buildRepayWithCollateralIxs(
306
313
  obligation.state.owner,
307
314
  currentSlot,
308
315
  obligation,
316
+ useV2Ixs,
309
317
  0,
310
318
  false,
311
319
  requestElevationGroup,
312
320
  undefined,
321
+ undefined,
313
322
  referrer,
314
323
  scopeRefresh
315
324
  );
@@ -16,11 +16,10 @@ import {
16
16
  ScopeRefresh,
17
17
  U64_MAX,
18
18
  uniqueAccounts,
19
- WRAPPED_SOL_MINT,
20
19
  } from '../utils';
21
20
  import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@solana/web3.js';
22
21
  import Decimal from 'decimal.js';
23
- import { createCloseAccountInstruction, TOKEN_PROGRAM_ID } from '@solana/spl-token';
22
+ import { createCloseAccountInstruction, NATIVE_MINT, TOKEN_PROGRAM_ID } from '@solana/spl-token';
24
23
 
25
24
  /**
26
25
  * Inputs to the `getSwapCollIxns()` operation.
@@ -63,6 +62,7 @@ export interface SwapCollIxnsInputs<QuoteResponse> {
63
62
  currentSlot: number;
64
63
  budgetAndPriorityFeeIxns?: TransactionInstruction[];
65
64
  scopeRefresh?: ScopeRefresh;
65
+ useV2Ixs: boolean;
66
66
  quoter: SwapQuoteProvider<QuoteResponse>;
67
67
  swapper: SwapIxsProvider<QuoteResponse>;
68
68
  logger?: (msg: string, ...extra: any[]) => void;
@@ -82,6 +82,11 @@ export interface SwapCollIxnsOutputs<QuoteResponse> {
82
82
  */
83
83
  lookupTables: AddressLookupTableAccount[];
84
84
 
85
+ /**
86
+ * Whether the swap is using V2 instructions.
87
+ */
88
+ useV2Ixs: boolean;
89
+
85
90
  /**
86
91
  * Informational-only details of the token amounts/fees/rates that were used during construction of `ixs`.
87
92
  */
@@ -168,6 +173,7 @@ export async function getSwapCollIxns<QuoteResponse>(
168
173
  return {
169
174
  ixs: listIxns(klendIxns, externalSwapIxns.ixns),
170
175
  lookupTables: externalSwapIxns.luts,
176
+ useV2Ixs: context.useV2Ixs,
171
177
  simulationDetails: {
172
178
  flashLoan: {
173
179
  targetCollFlashBorrowedAmount: klendIxns.simulationDetails.targetCollFlashBorrowedAmount,
@@ -198,6 +204,7 @@ type SwapCollContext<QuoteResponse> = {
198
204
  swapper: SwapIxsProvider<QuoteResponse>;
199
205
  referrer: PublicKey;
200
206
  currentSlot: number;
207
+ useV2Ixs: boolean;
201
208
  scopeRefresh: ScopeRefresh | undefined;
202
209
  logger: (msg: string, ...extra: any[]) => void;
203
210
  };
@@ -230,6 +237,7 @@ function extractArgsAndContext<QuoteResponse>(
230
237
  referrer: inputs.referrer,
231
238
  scopeRefresh: inputs.scopeRefresh,
232
239
  currentSlot: inputs.currentSlot,
240
+ useV2Ixs: inputs.useV2Ixs,
233
241
  },
234
242
  ];
235
243
  }
@@ -321,11 +329,11 @@ function getAtaCreationIxns(context: SwapCollContext<any>) {
321
329
  function getAtaCloseIxns(context: SwapCollContext<any>) {
322
330
  const ataCloseIxns: TransactionInstruction[] = [];
323
331
  if (
324
- context.sourceCollReserve.getLiquidityMint().equals(WRAPPED_SOL_MINT) ||
325
- context.targetCollReserve.getLiquidityMint().equals(WRAPPED_SOL_MINT)
332
+ context.sourceCollReserve.getLiquidityMint().equals(NATIVE_MINT) ||
333
+ context.targetCollReserve.getLiquidityMint().equals(NATIVE_MINT)
326
334
  ) {
327
335
  const owner = context.obligation.state.owner;
328
- const wsolAta = getAssociatedTokenAddress(WRAPPED_SOL_MINT, owner, false);
336
+ const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
329
337
  ataCloseIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
330
338
  }
331
339
  return ataCloseIxns;
@@ -371,10 +379,12 @@ async function getDepositTargetCollIxns(
371
379
  context.targetCollReserve.getLiquidityMint(),
372
380
  context.obligation.state.owner,
373
381
  context.obligation,
382
+ context.useV2Ixs,
374
383
  0, // no extra compute budget
375
384
  false, // we do not need ATA ixns here (we construct and close them ourselves)
376
385
  removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
377
386
  false, // we are dealing with an existing obligation, no need to create user metadata
387
+ false, // we do not need to create a lookup table, dealing with an existing obligation
378
388
  context.referrer,
379
389
  context.currentSlot,
380
390
  context.scopeRefresh,
@@ -419,10 +429,12 @@ async function getWithdrawSourceCollIxns(
419
429
  context.sourceCollReserve.getLiquidityMint(),
420
430
  context.obligation.state.owner,
421
431
  context.obligation,
432
+ context.useV2Ixs,
422
433
  0, // no extra compute budget
423
434
  false, // we do not need ATA ixns here (we construct and close them ourselves)
424
435
  requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
425
436
  false, // we are dealing with an existing obligation, no need to create user metadata
437
+ false, // we do not need to create a lookup table, dealing with an existing obligation
426
438
  context.referrer,
427
439
  context.currentSlot,
428
440
  undefined, // we have refreshed scope already, during depositing
@@ -1,4 +1,5 @@
1
1
  import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js';
2
+ import * as anchor from '@coral-xyz/anchor';
2
3
  import { KaminoReserve } from '../classes';
3
4
  import {
4
5
  FlashBorrowReserveLiquidityArgs,
@@ -9,12 +10,6 @@ import {
9
10
  flashRepayReserveLiquidity,
10
11
  } from '../lib';
11
12
  import Decimal from 'decimal.js';
12
- import * as anchor from '@coral-xyz/anchor';
13
-
14
- export const SOL_MINTS: Array<PublicKey> = [
15
- new PublicKey('So11111111111111111111111111111111111111111'),
16
- new PublicKey('So11111111111111111111111111111111111111112'),
17
- ];
18
13
 
19
14
  export const getFlashLoanInstructions = (args: {
20
15
  borrowIxnIndex: number;