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

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 (123) hide show
  1. package/dist/classes/action.d.ts +21 -91
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +152 -139
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/actionTypes.d.ts +310 -0
  6. package/dist/classes/actionTypes.d.ts.map +1 -0
  7. package/dist/classes/actionTypes.js +3 -0
  8. package/dist/classes/actionTypes.js.map +1 -0
  9. package/dist/classes/configItems.d.ts +1 -6
  10. package/dist/classes/configItems.d.ts.map +1 -1
  11. package/dist/classes/configItems.js +1 -93
  12. package/dist/classes/configItems.js.map +1 -1
  13. package/dist/classes/farm_utils.d.ts +1 -1
  14. package/dist/classes/farm_utils.d.ts.map +1 -1
  15. package/dist/classes/farm_utils.js +3 -1
  16. package/dist/classes/farm_utils.js.map +1 -1
  17. package/dist/classes/market.d.ts +5 -5
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +29 -13
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +9 -9
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +48 -50
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/obligationOrder.d.ts.map +1 -1
  26. package/dist/classes/obligationOrder.js +6 -3
  27. package/dist/classes/obligationOrder.js.map +1 -1
  28. package/dist/classes/reserve.d.ts +7 -3
  29. package/dist/classes/reserve.d.ts.map +1 -1
  30. package/dist/classes/reserve.js +31 -43
  31. package/dist/classes/reserve.js.map +1 -1
  32. package/dist/classes/shared.d.ts +3 -2
  33. package/dist/classes/shared.d.ts.map +1 -1
  34. package/dist/classes/vault.d.ts +28 -1
  35. package/dist/classes/vault.d.ts.map +1 -1
  36. package/dist/classes/vault.js +103 -6
  37. package/dist/classes/vault.js.map +1 -1
  38. package/dist/classes/vault_types.d.ts +2 -1
  39. package/dist/classes/vault_types.d.ts.map +1 -1
  40. package/dist/client/commands/borrow.d.ts +1 -1
  41. package/dist/client/commands/borrow.d.ts.map +1 -1
  42. package/dist/client/commands/borrow.js +11 -2
  43. package/dist/client/commands/borrow.js.map +1 -1
  44. package/dist/client/commands/deposit.d.ts +1 -1
  45. package/dist/client/commands/deposit.d.ts.map +1 -1
  46. package/dist/client/commands/deposit.js +11 -2
  47. package/dist/client/commands/deposit.js.map +1 -1
  48. package/dist/client/commands/printReserve.d.ts +1 -1
  49. package/dist/client/commands/printReserve.d.ts.map +1 -1
  50. package/dist/client/commands/printReserve.js +2 -4
  51. package/dist/client/commands/printReserve.js.map +1 -1
  52. package/dist/client/commands/repay.d.ts +1 -1
  53. package/dist/client/commands/repay.d.ts.map +1 -1
  54. package/dist/client/commands/repay.js +12 -2
  55. package/dist/client/commands/repay.js.map +1 -1
  56. package/dist/client/commands/withdraw.d.ts +1 -1
  57. package/dist/client/commands/withdraw.d.ts.map +1 -1
  58. package/dist/client/commands/withdraw.js +11 -2
  59. package/dist/client/commands/withdraw.js.map +1 -1
  60. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
  61. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  62. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  63. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  64. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
  65. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  66. package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
  67. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  68. package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
  69. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  70. package/dist/lending_operations/swap_collateral_operations.js +40 -21
  71. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  72. package/dist/leverage/operations.d.ts +6 -6
  73. package/dist/leverage/operations.d.ts.map +1 -1
  74. package/dist/leverage/operations.js +167 -52
  75. package/dist/leverage/operations.js.map +1 -1
  76. package/dist/leverage/types.d.ts +2 -2
  77. package/dist/leverage/types.d.ts.map +1 -1
  78. package/dist/obligation_orders/price_based.js +1 -0
  79. package/dist/obligation_orders/price_based.js.map +1 -1
  80. package/dist/utils/Logger.d.ts +14 -0
  81. package/dist/utils/Logger.d.ts.map +1 -0
  82. package/dist/utils/Logger.js +12 -0
  83. package/dist/utils/Logger.js.map +1 -0
  84. package/dist/utils/ObligationType.d.ts +33 -1
  85. package/dist/utils/ObligationType.d.ts.map +1 -1
  86. package/dist/utils/ObligationType.js +81 -2
  87. package/dist/utils/ObligationType.js.map +1 -1
  88. package/dist/utils/api.d.ts +13 -4
  89. package/dist/utils/api.d.ts.map +1 -1
  90. package/dist/utils/api.js +33 -31
  91. package/dist/utils/api.js.map +1 -1
  92. package/dist/utils/userMetadata.d.ts +2 -2
  93. package/dist/utils/userMetadata.d.ts.map +1 -1
  94. package/dist/utils/userMetadata.js +49 -25
  95. package/dist/utils/userMetadata.js.map +1 -1
  96. package/package.json +1 -1
  97. package/src/classes/action.ts +346 -372
  98. package/src/classes/actionTypes.ts +295 -0
  99. package/src/classes/configItems.ts +1 -99
  100. package/src/classes/farm_utils.ts +5 -1
  101. package/src/classes/market.ts +42 -16
  102. package/src/classes/obligation.ts +54 -53
  103. package/src/classes/obligationOrder.ts +6 -3
  104. package/src/classes/reserve.ts +118 -122
  105. package/src/classes/shared.ts +4 -2
  106. package/src/classes/vault.ts +160 -7
  107. package/src/classes/vault_types.ts +2 -1
  108. package/src/client/client.ts +17 -18
  109. package/src/client/commands/borrow.ts +10 -9
  110. package/src/client/commands/deposit.ts +10 -9
  111. package/src/client/commands/printReserve.ts +2 -4
  112. package/src/client/commands/repay.ts +11 -10
  113. package/src/client/commands/withdraw.ts +15 -9
  114. package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
  115. package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
  116. package/src/lending_operations/swap_collateral_operations.ts +47 -41
  117. package/src/leverage/operations.ts +168 -129
  118. package/src/leverage/types.ts +2 -2
  119. package/src/obligation_orders/price_based.ts +1 -0
  120. package/src/utils/Logger.ts +14 -0
  121. package/src/utils/ObligationType.ts +92 -1
  122. package/src/utils/api.ts +56 -33
  123. package/src/utils/userMetadata.ts +64 -30
@@ -82,14 +82,15 @@ class KaminoAction {
82
82
  this.referrer = referrer;
83
83
  this.currentSlot = currentSlot;
84
84
  }
85
- static async initialize(action, amount, mint, owner, kaminoMarket, obligation, referrer = (0, kit_1.none)(), currentSlot = 0n, payer = owner) {
86
- const reserve = kaminoMarket.getReserveByMint(mint);
85
+ static async initialize(props) {
86
+ const { kaminoMarket, action, amount, reserveAddress, owner, obligation, referrer = (0, kit_1.none)(), currentSlot = 0n, payer = owner, } = props;
87
+ const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
87
88
  if (reserve === undefined) {
88
- throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress()}`);
89
+ throw new Error(`Reserve ${reserveAddress} not found in market ${kaminoMarket.getAddress()}`);
89
90
  }
90
91
  const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, owner.address, reserve.address, obligation);
91
92
  const referrerKey = await this.getReferrerKey(kaminoMarket, owner.address, kaminoObligation, referrer);
92
- return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, referrerKey, payer);
93
+ return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, reserve.getLiquidityMint(), distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, referrerKey, payer);
93
94
  }
94
95
  static async getUserAccountAddresses(owner, reserve) {
95
96
  const [userTokenAccountAddress, userCollateralAccountAddress] = await Promise.all([
@@ -134,30 +135,45 @@ class KaminoAction {
134
135
  distinctReserveCount,
135
136
  };
136
137
  }
137
- static async buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
138
- currentSlot = 0n) {
138
+ static async buildRefreshObligationTxns(props) {
139
+ const { kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, currentSlot = 0n } = props;
139
140
  // placeholder for action initialization
140
141
  const firstReserve = obligation.getDeposits()[0].reserveAddress;
141
142
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
142
143
  if (!firstKaminoReserve) {
143
144
  throw new Error(`Reserve ${firstReserve} not found`);
144
145
  }
145
- const axn = await KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve?.getLiquidityMint(), (0, signer_1.noopSigner)(obligation.state.owner), // owner does not need to sign for refresh
146
- kaminoMarket, obligation, undefined, currentSlot);
146
+ const axn = await KaminoAction.initialize({
147
+ kaminoMarket,
148
+ action: 'refreshObligation',
149
+ amount: '0',
150
+ reserveAddress: firstKaminoReserve.address,
151
+ owner: (0, signer_1.noopSigner)(obligation.state.owner), // owner does not need to sign for refresh
152
+ obligation,
153
+ currentSlot,
154
+ });
147
155
  if (extraComputeBudget > 0) {
148
156
  axn.addComputeBudgetIx(extraComputeBudget);
149
157
  }
150
158
  await axn.addRefreshObligation(payer);
151
159
  return axn;
152
160
  }
153
- static async buildRequestElevationGroupTxns(kaminoMarket, owner, obligation, elevationGroup, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
154
- currentSlot = 0n) {
161
+ static async buildRequestElevationGroupTxns(props) {
162
+ const { kaminoMarket, owner, obligation, elevationGroup, extraComputeBudget = 1_000_000, currentSlot = 0n } = props;
155
163
  const firstReserve = obligation.state.deposits.find((x) => x.depositReserve !== utils_1.DEFAULT_PUBLIC_KEY).depositReserve;
156
164
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
157
165
  if (!firstKaminoReserve) {
158
166
  throw new Error(`Reserve ${firstReserve} not found`);
159
167
  }
160
- const axn = await KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve?.getLiquidityMint(), owner, kaminoMarket, obligation, undefined, currentSlot);
168
+ const axn = await KaminoAction.initialize({
169
+ kaminoMarket,
170
+ action: 'requestElevationGroup',
171
+ amount: '0',
172
+ reserveAddress: firstKaminoReserve.address,
173
+ owner,
174
+ obligation,
175
+ currentSlot,
176
+ });
161
177
  if (extraComputeBudget > 0) {
162
178
  axn.addComputeBudgetIx(extraComputeBudget);
163
179
  }
@@ -165,15 +181,18 @@ class KaminoAction {
165
181
  await axn.addRequestElevationIx(elevationGroup, 'setup');
166
182
  return axn;
167
183
  }
168
- static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
169
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
170
- requestElevationGroup = false, // to be requested *before* the deposit
171
- initUserMetadata = {
172
- skipInitialization: false,
173
- skipLutCreation: false,
174
- }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
175
- ) {
176
- const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
184
+ static async buildDepositTxns(props) {
185
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest, } = props;
186
+ const axn = await KaminoAction.initialize({
187
+ kaminoMarket,
188
+ action: 'deposit',
189
+ amount,
190
+ reserveAddress,
191
+ owner,
192
+ obligation,
193
+ referrer,
194
+ currentSlot,
195
+ });
177
196
  const addInitObligationForFarm = true;
178
197
  if (extraComputeBudget > 0) {
179
198
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -195,14 +214,18 @@ class KaminoAction {
195
214
  this.setupIxs.unshift(refreshIx);
196
215
  }
197
216
  }
198
- static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
199
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
200
- requestElevationGroup = false, initUserMetadata = {
201
- skipInitialization: false,
202
- skipLutCreation: false,
203
- }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
204
- ) {
205
- const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
217
+ static async buildBorrowTxns(props) {
218
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest, } = props;
219
+ const axn = await KaminoAction.initialize({
220
+ kaminoMarket,
221
+ action: 'borrow',
222
+ amount,
223
+ reserveAddress,
224
+ owner,
225
+ obligation,
226
+ referrer,
227
+ currentSlot,
228
+ });
206
229
  const addInitObligationForFarm = true;
207
230
  if (extraComputeBudget > 0) {
208
231
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -224,10 +247,18 @@ class KaminoAction {
224
247
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
225
248
  return axn;
226
249
  }
227
- static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
228
- includeAtaIxs = true, // if true it includes create and close wsol and token atas
229
- requestElevationGroup = false, referrer = (0, kit_1.none)(), currentSlot = 0n) {
230
- const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
250
+ static async buildDepositReserveLiquidityTxns(props) {
251
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, referrer = (0, kit_1.none)(), currentSlot = 0n, } = props;
252
+ const axn = await KaminoAction.initialize({
253
+ kaminoMarket,
254
+ action: 'mint',
255
+ amount,
256
+ reserveAddress,
257
+ owner,
258
+ obligation,
259
+ referrer,
260
+ currentSlot,
261
+ });
231
262
  const addInitObligationForFarm = true;
232
263
  if (extraComputeBudget > 0) {
233
264
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -237,10 +268,18 @@ class KaminoAction {
237
268
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
238
269
  return axn;
239
270
  }
240
- static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
241
- includeAtaIxs = true, // if true it includes create and close wsol and token atas
242
- requestElevationGroup = false, referrer = (0, kit_1.none)(), currentSlot = 0n) {
243
- const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
271
+ static async buildRedeemReserveCollateralTxns(props) {
272
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, referrer = (0, kit_1.none)(), currentSlot = 0n, } = props;
273
+ const axn = await KaminoAction.initialize({
274
+ kaminoMarket,
275
+ action: 'redeem',
276
+ amount,
277
+ reserveAddress,
278
+ owner,
279
+ obligation,
280
+ referrer,
281
+ currentSlot,
282
+ });
244
283
  const addInitObligationForFarm = true;
245
284
  if (extraComputeBudget > 0) {
246
285
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -250,13 +289,18 @@ class KaminoAction {
250
289
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
251
290
  return axn;
252
291
  }
253
- static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
254
- includeAtaIxs = true, // if true it includes create and close wsol and token atas
255
- requestElevationGroup = false, initUserMetadata = {
256
- skipInitialization: false,
257
- skipLutCreation: false,
258
- }, referrer = (0, kit_1.none)(), currentSlot = 0n) {
259
- const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
292
+ static async buildDepositObligationCollateralTxns(props) {
293
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), currentSlot = 0n, } = props;
294
+ const axn = await KaminoAction.initialize({
295
+ kaminoMarket,
296
+ action: 'depositCollateral',
297
+ amount,
298
+ reserveAddress,
299
+ owner,
300
+ obligation,
301
+ referrer,
302
+ currentSlot,
303
+ });
260
304
  const addInitObligationForFarm = true;
261
305
  if (extraComputeBudget > 0) {
262
306
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -271,13 +315,9 @@ class KaminoAction {
271
315
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
272
316
  return axn;
273
317
  }
274
- static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
275
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
276
- requestElevationGroup = false, initUserMetadata = {
277
- skipInitialization: false,
278
- skipLutCreation: false,
279
- }, referrer = (0, kit_1.none)(), currentSlot = 0n) {
280
- const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, owner, owner.address, obligation, borrowAmount, referrer, currentSlot);
318
+ static async buildDepositAndBorrowTxns(props) {
319
+ const { kaminoMarket, depositAmount, depositReserveAddress, borrowAmount, borrowReserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), currentSlot = 0n, } = props;
320
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositReserveAddress, borrowReserveAddress, owner, owner.address, obligation, borrowAmount, referrer, currentSlot);
281
321
  const addInitObligationForFarmForDeposit = true;
282
322
  const addInitObligationForFarmForBorrow = false;
283
323
  const twoTokenAction = true;
@@ -321,13 +361,9 @@ class KaminoAction {
321
361
  }
322
362
  return axn;
323
363
  }
324
- static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, owner, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
325
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
326
- requestElevationGroup = false, initUserMetadata = {
327
- skipInitialization: false,
328
- skipLutCreation: false,
329
- }, referrer = (0, kit_1.none)()) {
330
- const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndWithdraw', depositAmount, depositMint, withdrawMint, owner, owner.address, obligation, withdrawAmount, referrer, currentSlot);
364
+ static async buildDepositAndWithdrawV2Txns(props) {
365
+ const { kaminoMarket, depositAmount, depositReserveAddress, withdrawAmount, withdrawReserveAddress, owner, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), } = props;
366
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndWithdraw', depositAmount, depositReserveAddress, withdrawReserveAddress, owner, owner.address, obligation, withdrawAmount, referrer, currentSlot);
331
367
  const addInitObligationForFarm = true;
332
368
  const twoTokenAction = true;
333
369
  if (extraComputeBudget > 0) {
@@ -338,13 +374,9 @@ class KaminoAction {
338
374
  await axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
339
375
  return axn;
340
376
  }
341
- static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
342
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
343
- requestElevationGroup = false, initUserMetadata = {
344
- skipInitialization: false,
345
- skipLutCreation: false,
346
- }, referrer = (0, kit_1.none)()) {
347
- const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdrawV2', repayAmount, repayMint, withdrawMint, payer, payer.address, obligation, withdrawAmount, referrer, currentSlot);
377
+ static async buildRepayAndWithdrawV2Txns(props) {
378
+ const { kaminoMarket, repayAmount, repayReserveAddress, withdrawAmount, withdrawReserveAddress, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), } = props;
379
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdrawV2', repayAmount, repayReserveAddress, withdrawReserveAddress, payer, payer.address, obligation, withdrawAmount, referrer, currentSlot);
348
380
  const addInitObligationForFarm = true;
349
381
  const twoTokenAction = true;
350
382
  if (extraComputeBudget > 0) {
@@ -355,13 +387,9 @@ class KaminoAction {
355
387
  await axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
356
388
  return axn;
357
389
  }
358
- static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
359
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
360
- requestElevationGroup = false, initUserMetadata = {
361
- skipInitialization: false,
362
- skipLutCreation: false,
363
- }, referrer = (0, kit_1.none)()) {
364
- const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer.address, obligation, withdrawAmount, referrer, currentSlot);
390
+ static async buildRepayAndWithdrawTxns(props) {
391
+ const { kaminoMarket, repayAmount, repayReserveAddress, withdrawAmount, withdrawReserveAddress, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), } = props;
392
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayReserveAddress, withdrawReserveAddress, payer, payer.address, obligation, withdrawAmount, referrer, currentSlot);
365
393
  const addInitObligationForFarmForRepay = true;
366
394
  const addInitObligationForFarmForWithdraw = false;
367
395
  const twoTokenAction = true;
@@ -399,16 +427,18 @@ class KaminoAction {
399
427
  }
400
428
  return axn;
401
429
  }
402
- static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
403
- includeAtaIxs = true, // if true it includes create and close wsol and token atas,
404
- requestElevationGroup = false, // to be requested *after* the withdraw
405
- initUserMetadata = {
406
- skipInitialization: false,
407
- skipLutCreation: false,
408
- }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest,
409
- // Optional customizations which may be needed if the obligation was mutated by some previous ix.
410
- obligationCustomizations) {
411
- const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
430
+ static async buildWithdrawTxns(props) {
431
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), currentSlot = 0n, overrideElevationGroupRequest, obligationCustomizations, } = props;
432
+ const axn = await KaminoAction.initialize({
433
+ kaminoMarket,
434
+ action: 'withdraw',
435
+ amount,
436
+ reserveAddress,
437
+ owner,
438
+ obligation,
439
+ referrer,
440
+ currentSlot,
441
+ });
412
442
  const addInitObligationForFarm = true;
413
443
  if (extraComputeBudget > 0) {
414
444
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -426,27 +456,22 @@ class KaminoAction {
426
456
  return axn;
427
457
  }
428
458
  /**
429
- *
430
- * @param kaminoMarket
431
- * @param amount
432
- * @param mint
433
- * @param owner
434
- * @param obligation - obligation to repay or the PDA seeds
435
- * @param useV2Ixs
436
- * @param scopeRefreshConfig
437
- * @param currentSlot
438
- * @param payer - if not set then owner is used
439
- * @param extraComputeBudget - if > 0 then adds the ix
440
- * @param includeAtaIxs - if true it includes create and close wsol and token atas
441
- * @param requestElevationGroup
442
- * @param initUserMetadata
443
- * @param referrer
459
+ * Build repay transactions
460
+ * @param props - BuildRepayTxnsProps containing all required and optional parameters
444
461
  */
445
- static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, currentSlot, payer = owner, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = {
446
- skipInitialization: false,
447
- skipLutCreation: false,
448
- }, referrer = (0, kit_1.none)()) {
449
- const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
462
+ static async buildRepayTxns(props) {
463
+ const { kaminoMarket, amount, reserveAddress, owner, obligation, useV2Ixs, scopeRefreshConfig, currentSlot, payer = owner, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), } = props;
464
+ const axn = await KaminoAction.initialize({
465
+ kaminoMarket,
466
+ action: 'repay',
467
+ amount,
468
+ reserveAddress,
469
+ owner,
470
+ obligation,
471
+ referrer,
472
+ currentSlot,
473
+ payer,
474
+ });
450
475
  const addInitObligationForFarm = true;
451
476
  if (extraComputeBudget > 0) {
452
477
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -461,13 +486,9 @@ class KaminoAction {
461
486
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
462
487
  return axn;
463
488
  }
464
- static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig = undefined, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
465
- includeAtaIxs = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
466
- requestElevationGroup = false, initUserMetadata = {
467
- skipInitialization: false,
468
- skipLutCreation: false,
469
- }, referrer = (0, kit_1.none)(), maxAllowedLtvOverridePercent = 0, currentSlot = 0n) {
470
- const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
489
+ static async buildLiquidateTxns(props) {
490
+ const { kaminoMarket, amount, minCollateralReceiveAmount, repayReserveAddress, withdrawReserveAddress, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = { skipInitialization: false, skipLutCreation: false }, referrer = (0, kit_1.none)(), maxAllowedLtvOverridePercent = 0, currentSlot = 0n, } = props;
491
+ const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayReserveAddress, withdrawReserveAddress, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
471
492
  const addInitObligationForFarm = true;
472
493
  if (extraComputeBudget > 0) {
473
494
  axn.addComputeBudgetIx(extraComputeBudget);
@@ -482,8 +503,9 @@ class KaminoAction {
482
503
  axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
483
504
  return axn;
484
505
  }
485
- static async buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0n) {
486
- const { axn, createAtaIxs } = await KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
506
+ static async buildWithdrawReferrerFeeTxns(props) {
507
+ const { owner, reserveAddress, kaminoMarket, currentSlot = 0n } = props;
508
+ const { axn, createAtaIxs } = await KaminoAction.initializeWithdrawReferrerFees(reserveAddress, owner, kaminoMarket, currentSlot);
487
509
  axn.setupIxs.push(...createAtaIxs);
488
510
  axn.setupIxsLabels.push(`createAtasIxs[${axn.owner.toString()}]`);
489
511
  if ((0, kit_1.isSome)(axn.referrer)) {
@@ -2002,8 +2024,11 @@ class KaminoAction {
2002
2024
  action === 'repayAndWithdrawV2' ||
2003
2025
  action === 'mint' ||
2004
2026
  (action === 'liquidate' && this.mint === utils_1.WRAPPED_SOL_MINT); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
2027
+ const isValidTokenAccount = userWSOLAccountInfo.exists &&
2028
+ (userWSOLAccountInfo.programAddress === token_1.TOKEN_PROGRAM_ADDRESS ||
2029
+ userWSOLAccountInfo.programAddress === token_2022_1.TOKEN_2022_PROGRAM_ADDRESS);
2005
2030
  const transferLamportsIx = (0, system_1.getTransferSolInstruction)({
2006
- amount: (userWSOLAccountInfo.exists ? 0n : rentExemptLamports) + (sendAction ? BigInt(safeRepay.toString()) : 0n),
2031
+ amount: (isValidTokenAccount ? 0n : rentExemptLamports) + (sendAction ? BigInt(safeRepay.toString()) : 0n),
2007
2032
  source: this.owner,
2008
2033
  destination: userTokenAccountAddress,
2009
2034
  });
@@ -2017,33 +2042,21 @@ class KaminoAction {
2017
2042
  const syncIx = (0, token_2022_1.getSyncNativeInstruction)({
2018
2043
  account: userTokenAccountAddress,
2019
2044
  }, { programAddress: token_1.TOKEN_PROGRAM_ADDRESS });
2020
- if (userWSOLAccountInfo.exists) {
2021
- if (sendAction) {
2022
- preIxs.push(syncIx);
2023
- preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
2024
- }
2025
- else {
2026
- postIxs.push(closeWSOLAccountIx);
2027
- postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
2028
- }
2029
- }
2030
- else {
2031
- const [, createUserWSOLAccountIx] = await (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, utils_1.WRAPPED_SOL_MINT, this.owner.address, token_1.TOKEN_PROGRAM_ADDRESS, userTokenAccountAddress);
2032
- preIxs.push(createUserWSOLAccountIx);
2033
- preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
2034
- preIxs.push(syncIx);
2035
- preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
2036
- postIxs.push(closeWSOLAccountIx);
2037
- postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
2038
- }
2045
+ const [, createUserWSOLAccountIx] = await (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, utils_1.WRAPPED_SOL_MINT, this.owner.address, token_1.TOKEN_PROGRAM_ADDRESS, userTokenAccountAddress);
2046
+ preIxs.push(createUserWSOLAccountIx);
2047
+ preIxsLabels.push(`CreateUserAtaSOL[${userTokenAccountAddress}]`);
2048
+ preIxs.push(syncIx);
2049
+ preIxsLabels.push(`SyncUserAtaSOL[${userTokenAccountAddress}]`);
2050
+ postIxs.push(closeWSOLAccountIx);
2051
+ postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
2039
2052
  this.setupIxs.unshift(...preIxs);
2040
2053
  this.setupIxsLabels.unshift(...preIxsLabels);
2041
2054
  this.cleanupIxs.push(...postIxs);
2042
2055
  this.cleanupIxsLabels.push(...postIxsLabels);
2043
2056
  }
2044
- static async initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, signer, obligationOwner, obligation, outflowAmount, referrer = (0, kit_1.none)(), currentSlot = 0n) {
2045
- const inflowReserve = kaminoMarket.getExistingReserveByMint(inflowTokenMint);
2046
- const outflowReserve = kaminoMarket.getExistingReserveByMint(outflowTokenMint);
2057
+ static async initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowReserveAddress, outflowReserveAddress, signer, obligationOwner, obligation, outflowAmount, referrer = (0, kit_1.none)(), currentSlot = 0n) {
2058
+ const inflowReserve = kaminoMarket.getExistingReserveByAddress(inflowReserveAddress);
2059
+ const outflowReserve = kaminoMarket.getExistingReserveByAddress(outflowReserveAddress);
2047
2060
  const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
2048
2061
  const referrerKey = await this.getReferrerKey(kaminoMarket, signer.address, kaminoObligation, referrer);
2049
2062
  let secondaryMint;
@@ -2052,18 +2065,18 @@ class KaminoAction {
2052
2065
  action === 'depositAndBorrow' ||
2053
2066
  action === 'repayAndWithdraw' ||
2054
2067
  action === 'repayAndWithdrawV2') {
2055
- primaryMint = inflowTokenMint;
2056
- secondaryMint = outflowTokenMint;
2068
+ primaryMint = inflowReserve.getLiquidityMint();
2069
+ secondaryMint = outflowReserve.getLiquidityMint();
2057
2070
  }
2058
2071
  else {
2059
2072
  throw new Error('Invalid action');
2060
2073
  }
2061
2074
  return new KaminoAction(kaminoMarket, signer, kaminoObligation || obligation, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, outflowReserve, outflowAmount, referrerKey);
2062
2075
  }
2063
- static async initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0n) {
2064
- const reserve = kaminoMarket.getReserveByMint(mint);
2076
+ static async initializeWithdrawReferrerFees(reserveAddress, owner, kaminoMarket, currentSlot = 0n) {
2077
+ const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
2065
2078
  if (reserve === undefined) {
2066
- throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress()}`);
2079
+ throw new Error(`Reserve ${reserveAddress} not found in market ${kaminoMarket.getAddress()}`);
2067
2080
  }
2068
2081
  const [{ createAtaIx }] = await (0, utils_1.createAtasIdempotent)(owner, [
2069
2082
  {
@@ -2072,7 +2085,7 @@ class KaminoAction {
2072
2085
  },
2073
2086
  ]);
2074
2087
  return {
2075
- axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
2088
+ axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), reserve.getLiquidityMint(), 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
2076
2089
  createAtaIxs: [createAtaIx],
2077
2090
  };
2078
2091
  }