@kamino-finance/klend-sdk 2.12.0 → 2.12.2

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 (78) hide show
  1. package/dist/classes/action.js +102 -88
  2. package/dist/classes/action.js.map +1 -1
  3. package/dist/classes/fraction.js.map +1 -1
  4. package/dist/classes/jupiterPerps.js.map +1 -1
  5. package/dist/classes/market.js +10 -9
  6. package/dist/classes/market.js.map +1 -1
  7. package/dist/classes/obligation.js.map +1 -1
  8. package/dist/classes/reserve.js.map +1 -1
  9. package/dist/classes/shared.js +1 -1
  10. package/dist/classes/shared.js.map +1 -1
  11. package/dist/classes/utils.js.map +1 -1
  12. package/dist/idl_codegen/accounts/LendingMarket.js +4 -4
  13. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  14. package/dist/idl_codegen/accounts/Obligation.js +4 -4
  15. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  16. package/dist/idl_codegen/accounts/ReferrerState.js +4 -4
  17. package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -1
  18. package/dist/idl_codegen/accounts/ReferrerTokenState.js +4 -4
  19. package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -1
  20. package/dist/idl_codegen/accounts/Reserve.js +4 -4
  21. package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
  22. package/dist/idl_codegen/accounts/ShortUrl.js +4 -4
  23. package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -1
  24. package/dist/idl_codegen/accounts/UserMetadata.js +4 -4
  25. package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -1
  26. package/dist/idl_codegen/accounts/UserState.js +4 -4
  27. package/dist/idl_codegen/accounts/UserState.js.map +1 -1
  28. package/dist/idl_codegen/errors/anchor.js.map +1 -1
  29. package/dist/idl_codegen/errors/custom.js.map +1 -1
  30. package/dist/idl_codegen/errors/index.js.map +1 -1
  31. package/dist/idl_codegen/types/AssetTier.js.map +1 -1
  32. package/dist/idl_codegen/types/FeeCalculation.js.map +1 -1
  33. package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -1
  34. package/dist/idl_codegen/types/ReserveStatus.js.map +1 -1
  35. package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
  36. package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -1
  37. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  38. package/dist/idl_codegen/zero_padding/ObligationZP.js +4 -4
  39. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  40. package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +4 -4
  41. package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -1
  42. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  43. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  44. package/dist/leverage/calcs.js +3 -3
  45. package/dist/leverage/calcs.js.map +1 -1
  46. package/dist/leverage/operations.js +5 -6
  47. package/dist/leverage/operations.js.map +1 -1
  48. package/dist/leverage/utils.js +3 -3
  49. package/dist/leverage/utils.js.map +1 -1
  50. package/dist/referrals/instructions.js +2 -2
  51. package/dist/referrals/instructions.js.map +1 -1
  52. package/dist/referrals/operations.d.ts +2 -2
  53. package/dist/referrals/operations.js +15 -15
  54. package/dist/referrals/operations.js.map +1 -1
  55. package/dist/utils/ObligationType.js +1 -1
  56. package/dist/utils/ObligationType.js.map +1 -1
  57. package/dist/utils/api.js +2 -2
  58. package/dist/utils/api.js.map +1 -1
  59. package/dist/utils/ata.js +3 -19
  60. package/dist/utils/ata.js.map +1 -1
  61. package/dist/utils/constants.js.map +1 -1
  62. package/dist/utils/instruction.d.ts +0 -1
  63. package/dist/utils/instruction.js +13 -13
  64. package/dist/utils/instruction.js.map +1 -1
  65. package/dist/utils/kamino.js +2 -24
  66. package/dist/utils/kamino.js.map +1 -1
  67. package/dist/utils/layout.js.map +1 -1
  68. package/dist/utils/lookupTable.js.map +1 -1
  69. package/dist/utils/oracle.js.map +1 -1
  70. package/dist/utils/pubkey.js.map +1 -1
  71. package/dist/utils/rpc.js.map +1 -1
  72. package/dist/utils/seeds.js.map +1 -1
  73. package/dist/utils/userMetadata.js +3 -3
  74. package/dist/utils/userMetadata.js.map +1 -1
  75. package/package.json +5 -5
  76. package/dist/utils/token.d.ts +0 -2
  77. package/dist/utils/token.js +0 -20
  78. package/dist/utils/token.js.map +0 -1
@@ -24,7 +24,6 @@ const types_1 = require("../idl_codegen/types");
24
24
  const farms_sdk_1 = require("@hubbleprotocol/farms-sdk");
25
25
  const ObligationType_1 = require("../utils/ObligationType");
26
26
  const lib_1 = require("../lib");
27
- const token_1 = require("../utils/token");
28
27
  exports.POSITION_LIMIT = 10;
29
28
  exports.BORROWS_LIMIT = 5;
30
29
  exports.DEPOSITS_LIMIT = 8;
@@ -77,8 +76,8 @@ class KaminoAction {
77
76
  this.referrer = referrer ? referrer : web3_js_1.PublicKey.default;
78
77
  this.currentSlot = currentSlot;
79
78
  }
80
- static initialize(action, amount, mint, owner, kaminoMarket, obligation, referrer = web3_js_1.PublicKey.default, currentSlot = 0, hostAta, payer) {
81
- return __awaiter(this, void 0, void 0, function* () {
79
+ static initialize(action_1, amount_1, mint_1, owner_1, kaminoMarket_1, obligation_2) {
80
+ return __awaiter(this, arguments, void 0, function* (action, amount, mint, owner, kaminoMarket, obligation, referrer = web3_js_1.PublicKey.default, currentSlot = 0, hostAta, payer) {
82
81
  const reserve = kaminoMarket.getReserveByMint(mint);
83
82
  if (reserve === undefined) {
84
83
  throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
@@ -143,9 +142,9 @@ class KaminoAction {
143
142
  };
144
143
  });
145
144
  }
146
- static buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
147
- currentSlot = 0) {
148
- return __awaiter(this, void 0, void 0, function* () {
145
+ static buildRefreshObligationTxns(kaminoMarket_1, payer_1, obligation_2) {
146
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
147
+ currentSlot = 0) {
149
148
  // placeholder for action initialization
150
149
  const firstReserve = obligation.state.deposits[0].depositReserve;
151
150
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
@@ -160,9 +159,9 @@ class KaminoAction {
160
159
  return axn;
161
160
  });
162
161
  }
163
- static buildRequestElevationGroupTxns(kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1000000, // if > 0 then adds the ixn
164
- currentSlot = 0) {
165
- return __awaiter(this, void 0, void 0, function* () {
162
+ static buildRequestElevationGroupTxns(kaminoMarket_1, payer_1, obligation_2, elevationGroup_1) {
163
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1000000, // if > 0 then adds the ixn
164
+ currentSlot = 0) {
166
165
  const firstReserve = obligation.state.deposits[0].depositReserve;
167
166
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
168
167
  if (!firstKaminoReserve) {
@@ -177,11 +176,11 @@ class KaminoAction {
177
176
  return axn;
178
177
  });
179
178
  }
180
- static buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
181
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
182
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
183
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
184
- return __awaiter(this, void 0, void 0, function* () {
179
+ static buildDepositTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
180
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
181
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
182
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
183
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
185
184
  const axn = yield KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
186
185
  const addInitObligationForFarm = true;
187
186
  if (extraComputeBudget > 0) {
@@ -193,11 +192,11 @@ class KaminoAction {
193
192
  return axn;
194
193
  });
195
194
  }
196
- static buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
197
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
198
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
199
- referrer = web3_js_1.PublicKey.default, currentSlot = 0, hostAta) {
200
- return __awaiter(this, void 0, void 0, function* () {
195
+ static buildBorrowTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
196
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
197
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
198
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
199
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0, hostAta) {
201
200
  const axn = yield KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, hostAta);
202
201
  const addInitObligationForFarm = true;
203
202
  if (extraComputeBudget > 0) {
@@ -209,11 +208,11 @@ class KaminoAction {
209
208
  return axn;
210
209
  });
211
210
  }
212
- static buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
213
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
214
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
215
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
216
- return __awaiter(this, void 0, void 0, function* () {
211
+ static buildDepositReserveLiquidityTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
212
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
213
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
214
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
215
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
217
216
  const axn = yield KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
218
217
  const addInitObligationForFarm = true;
219
218
  if (extraComputeBudget > 0) {
@@ -225,11 +224,11 @@ class KaminoAction {
225
224
  return axn;
226
225
  });
227
226
  }
228
- static buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
229
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
230
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
231
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
232
- return __awaiter(this, void 0, void 0, function* () {
227
+ static buildRedeemReserveCollateralTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
228
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
229
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
230
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
231
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
233
232
  const axn = yield KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
234
233
  const addInitObligationForFarm = true;
235
234
  if (extraComputeBudget > 0) {
@@ -241,11 +240,11 @@ class KaminoAction {
241
240
  return axn;
242
241
  });
243
242
  }
244
- static buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
245
- includeAtaIxns = true, // if true it includes create and close wsol and token atas
246
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
247
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
248
- return __awaiter(this, void 0, void 0, function* () {
243
+ static buildDepositObligationCollateralTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
244
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
245
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas
246
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
247
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
249
248
  const axn = yield KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
250
249
  const addInitObligationForFarm = true;
251
250
  if (extraComputeBudget > 0) {
@@ -257,11 +256,11 @@ class KaminoAction {
257
256
  return axn;
258
257
  });
259
258
  }
260
- static buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
261
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
262
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
263
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
264
- return __awaiter(this, void 0, void 0, function* () {
259
+ static buildDepositAndBorrowTxns(kaminoMarket_1, depositAmount_1, depositMint_1, borrowAmount_1, borrowMint_1, payer_1, obligation_2) {
260
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
261
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
262
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
263
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
265
264
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
266
265
  const addInitObligationForFarmForDeposit = true;
267
266
  const addInitObligationForFarmForBorrow = false;
@@ -276,11 +275,11 @@ class KaminoAction {
276
275
  return axn;
277
276
  });
278
277
  }
279
- static buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
280
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
281
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
282
- isClosingPosition = false, referrer = web3_js_1.PublicKey.default) {
283
- return __awaiter(this, void 0, void 0, function* () {
278
+ static buildRepayAndWithdrawTxns(kaminoMarket_1, repayAmount_1, repayMint_1, withdrawAmount_1, withdrawMint_1, payer_1, currentSlot_1, obligation_2) {
279
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
280
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
281
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
282
+ isClosingPosition = false, referrer = web3_js_1.PublicKey.default) {
284
283
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
285
284
  const addInitObligationForFarmForRepay = true;
286
285
  const addInitObligationForFarmForWithdraw = false;
@@ -295,11 +294,11 @@ class KaminoAction {
295
294
  return axn;
296
295
  });
297
296
  }
298
- static buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
299
- includeAtaIxns = true, // if true it includes create and close wsol and token atas,
300
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
301
- referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
302
- return __awaiter(this, void 0, void 0, function* () {
297
+ static buildWithdrawTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2) {
298
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
299
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas,
300
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
301
+ referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
303
302
  const axn = yield KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
304
303
  const addInitObligationForFarm = true;
305
304
  if (extraComputeBudget > 0) {
@@ -326,8 +325,8 @@ class KaminoAction {
326
325
  * @param includeUserMetadata - if true it includes user metadata
327
326
  * @param referrer
328
327
  */
329
- static buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1000000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default) {
330
- return __awaiter(this, void 0, void 0, function* () {
328
+ static buildRepayTxns(kaminoMarket_1, amount_1, mint_1, owner_1, obligation_2, currentSlot_1) {
329
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, mint, owner, obligation, currentSlot, payer = undefined, extraComputeBudget = 1000000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, referrer = web3_js_1.PublicKey.default) {
331
330
  const axn = yield KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, undefined, payer);
332
331
  const addInitObligationForFarm = true;
333
332
  if (extraComputeBudget > 0) {
@@ -339,11 +338,11 @@ class KaminoAction {
339
338
  return axn;
340
339
  });
341
340
  }
342
- static buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
343
- includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
344
- requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
345
- referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0) {
346
- return __awaiter(this, void 0, void 0, function* () {
341
+ static buildLiquidateTxns(kaminoMarket_1, amount_1, minCollateralReceiveAmount_1, repayTokenMint_1, withdrawTokenMint_1, liquidator_1, obligationOwner_1, obligation_2) {
342
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, extraComputeBudget = 1000000, // if > 0 then adds the ixn
343
+ includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
344
+ requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
345
+ referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0) {
347
346
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
348
347
  const addInitObligationForFarm = true;
349
348
  if (extraComputeBudget > 0) {
@@ -355,8 +354,8 @@ class KaminoAction {
355
354
  return axn;
356
355
  });
357
356
  }
358
- static buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0) {
359
- return __awaiter(this, void 0, void 0, function* () {
357
+ static buildWithdrawReferrerFeeTxns(owner_1, tokenMint_1, kaminoMarket_1) {
358
+ return __awaiter(this, arguments, void 0, function* (owner, tokenMint, kaminoMarket, currentSlot = 0) {
360
359
  const { axn, createAtasIxns } = yield KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
361
360
  axn.preTxnIxs.push(...createAtasIxns);
362
361
  axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
@@ -446,7 +445,7 @@ class KaminoAction {
446
445
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
447
446
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
448
447
  reserveCollateralMint: this.reserve.getCTokenMint(),
449
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
448
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
450
449
  userSourceLiquidity: this.userTokenAccountAddress,
451
450
  placeholderUserDestinationCollateral: this.kaminoMarket.programId,
452
451
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -508,6 +507,7 @@ class KaminoAction {
508
507
  }, this.kaminoMarket.programId));
509
508
  }
510
509
  addBorrowIx() {
510
+ var _a;
511
511
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
512
512
  const depositReservesList = this.getAdditionalDepositReservesList();
513
513
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -529,7 +529,9 @@ class KaminoAction {
529
529
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
530
530
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
531
531
  }, this.kaminoMarket.programId);
532
- borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
532
+ borrowIx.keys = ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)
533
+ ? borrowIx.keys.concat([...depositReserveAccountMetas])
534
+ : borrowIx.keys;
533
535
  this.lendingIxs.push(borrowIx);
534
536
  }
535
537
  addDepositAndBorrowIx() {
@@ -547,7 +549,7 @@ class KaminoAction {
547
549
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
548
550
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
549
551
  reserveCollateralMint: this.reserve.getCTokenMint(),
550
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
552
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
551
553
  userSourceLiquidity: this.userTokenAccountAddress,
552
554
  placeholderUserDestinationCollateral: this.kaminoMarket.programId,
553
555
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -594,7 +596,11 @@ class KaminoAction {
594
596
  return __awaiter(this, void 0, void 0, function* () {
595
597
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
596
598
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
597
- this.lendingIxs.push((0, instructions_1.repayObligationLiquidity)({
599
+ const depositReservesList = this.getAdditionalDepositReservesList();
600
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
601
+ return { pubkey: reserve, isSigner: false, isWritable: true };
602
+ });
603
+ const repayIx = (0, instructions_1.repayObligationLiquidity)({
598
604
  liquidityAmount: this.amount,
599
605
  }, {
600
606
  owner: this.owner,
@@ -606,7 +612,9 @@ class KaminoAction {
606
612
  reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
607
613
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
608
614
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
609
- }, this.kaminoMarket.programId));
615
+ }, this.kaminoMarket.programId);
616
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
617
+ this.lendingIxs.push(repayIx);
610
618
  if (!this.outflowReserve) {
611
619
  throw new Error(`outflowReserve not set`);
612
620
  }
@@ -668,6 +676,7 @@ class KaminoAction {
668
676
  }
669
677
  addRepayIx() {
670
678
  return __awaiter(this, void 0, void 0, function* () {
679
+ var _a;
671
680
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
672
681
  const depositReservesList = this.getAdditionalDepositReservesList();
673
682
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -686,12 +695,14 @@ class KaminoAction {
686
695
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
687
696
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
688
697
  }, this.kaminoMarket.programId);
689
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
698
+ repayIx.keys =
699
+ ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
690
700
  this.lendingIxs.push(repayIx);
691
701
  });
692
702
  }
693
- addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
694
- return __awaiter(this, void 0, void 0, function* () {
703
+ addLiquidateIx() {
704
+ return __awaiter(this, arguments, void 0, function* (maxAllowedLtvOverridePercent = 0) {
705
+ var _a;
695
706
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
696
707
  if (!this.outflowReserve) {
697
708
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -730,12 +741,15 @@ class KaminoAction {
730
741
  withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
731
742
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
732
743
  }, this.kaminoMarket.programId);
733
- liquidateIx.keys = liquidateIx.keys.concat([...depositReserveAccountMetas]);
744
+ liquidateIx.keys =
745
+ ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0
746
+ ? liquidateIx.keys.concat([...depositReserveAccountMetas])
747
+ : liquidateIx.keys;
734
748
  this.lendingIxs.push(liquidateIx);
735
749
  });
736
750
  }
737
- addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
738
- return __awaiter(this, void 0, void 0, function* () {
751
+ addInBetweenIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, addInitObligationForFarm_1) {
752
+ return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
739
753
  yield this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, false, requestElevationGroup, addInitObligationForFarm, isClosingPosition);
740
754
  });
741
755
  }
@@ -749,9 +763,9 @@ class KaminoAction {
749
763
  this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
750
764
  this.addRefreshObligationIx(addAllToSetupIxns, false);
751
765
  }
752
- addSupportIxsWithoutInitObligation(action, includeAtaIxns, addToSetupIxs = true, requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false) {
753
- var _a;
754
- return __awaiter(this, void 0, void 0, function* () {
766
+ addSupportIxsWithoutInitObligation(action_1, includeAtaIxns_1) {
767
+ return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, addToSetupIxs = true, requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false) {
768
+ var _a;
755
769
  // TODO: why are we not doing this first?
756
770
  if (includeAtaIxns) {
757
771
  yield this.addAtaIxs(action);
@@ -908,18 +922,18 @@ class KaminoAction {
908
922
  const groupsColl = this.reserve.state.config.elevationGroups;
909
923
  const groupsDebt = this.outflowReserve.state.config.elevationGroups;
910
924
  const groups = this.kaminoMarket.state.elevationGroups;
911
- const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0);
925
+ const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(this.outflowReserve.address));
912
926
  console.log('Groups of coll reserve', groupsColl, 'Groups of debt reserve', groupsDebt, 'Common groups', commonElevationGroups);
913
927
  if (commonElevationGroups.length === 0) {
914
928
  console.log('No common elevation groups found, staying with default');
915
929
  }
916
930
  else {
917
- const eModeGroupWithMaxLtv = commonElevationGroups.reduce((prev, curr) => {
931
+ const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
918
932
  const prevGroup = groups.find((group) => group.id === prev);
919
933
  const currGroup = groups.find((group) => group.id === curr);
920
934
  return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
921
935
  });
922
- const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtv).id;
936
+ const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
923
937
  console.log('Setting eModeGroup to', eModeGroup);
924
938
  if (eModeGroup !== 0 && eModeGroup !== ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)) {
925
939
  this.addRequestElevationIx(eModeGroup, false);
@@ -932,8 +946,8 @@ class KaminoAction {
932
946
  }
933
947
  });
934
948
  }
935
- addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false) {
936
- return __awaiter(this, void 0, void 0, function* () {
949
+ addSupportIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, includeUserMetadata_1, addInitObligationForFarm_1) {
950
+ return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false) {
937
951
  if (!['mint', 'redeem'].includes(action)) {
938
952
  const [, ownerUserMetadata] = yield this.kaminoMarket.getUserMetadata(this.owner);
939
953
  if (!ownerUserMetadata && includeUserMetadata) {
@@ -1139,8 +1153,8 @@ class KaminoAction {
1139
1153
  this.cleanupIxs.splice(this.cleanupIxs.length - 1, 0, ...this.refreshFarmsCleanupTxnIxs);
1140
1154
  this.cleanupIxsLabels.splice(this.cleanupIxsLabels.length - 1, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
1141
1155
  }
1142
- addInitObligationForFarm(reserve, mode, addToSetupIxs = true) {
1143
- return __awaiter(this, void 0, void 0, function* () {
1156
+ addInitObligationForFarm(reserve_1, mode_1) {
1157
+ return __awaiter(this, arguments, void 0, function* (reserve, mode, addToSetupIxs = true) {
1144
1158
  const BASE_SEED_USER_STATE = Buffer.from('user');
1145
1159
  const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
1146
1160
  const farms = [];
@@ -1234,8 +1248,8 @@ class KaminoAction {
1234
1248
  this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
1235
1249
  });
1236
1250
  }
1237
- addInitReferrerTokenStateIxs(reservesArr = []) {
1238
- return __awaiter(this, void 0, void 0, function* () {
1251
+ addInitReferrerTokenStateIxs() {
1252
+ return __awaiter(this, arguments, void 0, function* (reservesArr = []) {
1239
1253
  if (this.referrer.equals(web3_js_1.PublicKey.default)) {
1240
1254
  return;
1241
1255
  }
@@ -1287,8 +1301,8 @@ class KaminoAction {
1287
1301
  this.setupIxsLabels.push(`AddComputeBudget[${units}]`);
1288
1302
  }
1289
1303
  addAtaIxs(action) {
1290
- var _a, _b;
1291
1304
  return __awaiter(this, void 0, void 0, function* () {
1305
+ var _a, _b;
1292
1306
  if (this.mint.equals(utils_1.WRAPPED_SOL_MINT) || ((_a = this.secondaryMint) === null || _a === void 0 ? void 0 : _a.equals(utils_1.WRAPPED_SOL_MINT))) {
1293
1307
  yield this.updateWSOLAccount(action);
1294
1308
  }
@@ -1386,8 +1400,8 @@ class KaminoAction {
1386
1400
  });
1387
1401
  }
1388
1402
  updateWSOLAccount(action) {
1389
- var _a, _b;
1390
1403
  return __awaiter(this, void 0, void 0, function* () {
1404
+ var _a, _b;
1391
1405
  const preIxs = [];
1392
1406
  const postIxs = [];
1393
1407
  const preIxsLabels = [];
@@ -1431,7 +1445,7 @@ class KaminoAction {
1431
1445
  });
1432
1446
  preIxs.push(transferLamportsIx);
1433
1447
  preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
1434
- const closeWSOLAccountIx = (0, token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, spl_token_1.TOKEN_PROGRAM_ID);
1448
+ const closeWSOLAccountIx = (0, spl_token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, [], spl_token_1.TOKEN_PROGRAM_ID);
1435
1449
  const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
1436
1450
  if (userWSOLAccountInfo) {
1437
1451
  if (sendAction) {
@@ -1466,8 +1480,8 @@ class KaminoAction {
1466
1480
  this.cleanupIxsLabels.push(...postIxsLabels);
1467
1481
  });
1468
1482
  }
1469
- static initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1470
- return __awaiter(this, void 0, void 0, function* () {
1483
+ static initializeMultiTokenAction(kaminoMarket_1, action_1, inflowAmount_1, inflowTokenMint_1, outflowTokenMint_1, payer_1, obligationOwner_1, obligation_2, outflowAmount_1) {
1484
+ return __awaiter(this, arguments, void 0, function* (kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1471
1485
  const inflowReserve = kaminoMarket.getReserveByMint(inflowTokenMint);
1472
1486
  const outflowReserve = kaminoMarket.getReserveByMint(outflowTokenMint);
1473
1487
  if (!outflowReserve || !inflowReserve) {
@@ -1513,8 +1527,8 @@ class KaminoAction {
1513
1527
  return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, undefined, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
1514
1528
  });
1515
1529
  }
1516
- static initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0, hostAta) {
1517
- return __awaiter(this, void 0, void 0, function* () {
1530
+ static initializeWithdrawReferrerFees(mint_1, owner_1, kaminoMarket_1) {
1531
+ return __awaiter(this, arguments, void 0, function* (mint, owner, kaminoMarket, currentSlot = 0, hostAta) {
1518
1532
  const reserve = kaminoMarket.getReserveByMint(mint);
1519
1533
  if (reserve === undefined) {
1520
1534
  throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);