@kamino-finance/klend-sdk 2.12.0-SNAPSHOT.3 → 2.12.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 (78) hide show
  1. package/dist/classes/action.js +103 -87
  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 +9 -10
  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 +6 -5
  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 +19 -3
  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 +1 -0
  63. package/dist/utils/instruction.js +13 -13
  64. package/dist/utils/instruction.js.map +1 -1
  65. package/dist/utils/kamino.js +24 -2
  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/token.d.ts +2 -0
  74. package/dist/utils/token.js +20 -0
  75. package/dist/utils/token.js.map +1 -0
  76. package/dist/utils/userMetadata.js +3 -3
  77. package/dist/utils/userMetadata.js.map +1 -1
  78. package/package.json +5 -5
@@ -24,6 +24,7 @@ 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");
27
28
  exports.POSITION_LIMIT = 10;
28
29
  exports.BORROWS_LIMIT = 5;
29
30
  exports.DEPOSITS_LIMIT = 8;
@@ -76,8 +77,8 @@ class KaminoAction {
76
77
  this.referrer = referrer ? referrer : web3_js_1.PublicKey.default;
77
78
  this.currentSlot = currentSlot;
78
79
  }
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) {
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* () {
81
82
  const reserve = kaminoMarket.getReserveByMint(mint);
82
83
  if (reserve === undefined) {
83
84
  throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
@@ -142,9 +143,9 @@ class KaminoAction {
142
143
  };
143
144
  });
144
145
  }
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) {
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* () {
148
149
  // placeholder for action initialization
149
150
  const firstReserve = obligation.state.deposits[0].depositReserve;
150
151
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
@@ -159,9 +160,9 @@ class KaminoAction {
159
160
  return axn;
160
161
  });
161
162
  }
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) {
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* () {
165
166
  const firstReserve = obligation.state.deposits[0].depositReserve;
166
167
  const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
167
168
  if (!firstKaminoReserve) {
@@ -176,11 +177,11 @@ class KaminoAction {
176
177
  return axn;
177
178
  });
178
179
  }
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) {
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* () {
184
185
  const axn = yield KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
185
186
  const addInitObligationForFarm = true;
186
187
  if (extraComputeBudget > 0) {
@@ -192,11 +193,11 @@ class KaminoAction {
192
193
  return axn;
193
194
  });
194
195
  }
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) {
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* () {
200
201
  const axn = yield KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, hostAta);
201
202
  const addInitObligationForFarm = true;
202
203
  if (extraComputeBudget > 0) {
@@ -208,11 +209,11 @@ class KaminoAction {
208
209
  return axn;
209
210
  });
210
211
  }
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) {
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* () {
216
217
  const axn = yield KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
217
218
  const addInitObligationForFarm = true;
218
219
  if (extraComputeBudget > 0) {
@@ -224,11 +225,11 @@ class KaminoAction {
224
225
  return axn;
225
226
  });
226
227
  }
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) {
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* () {
232
233
  const axn = yield KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
233
234
  const addInitObligationForFarm = true;
234
235
  if (extraComputeBudget > 0) {
@@ -240,11 +241,11 @@ class KaminoAction {
240
241
  return axn;
241
242
  });
242
243
  }
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) {
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* () {
248
249
  const axn = yield KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
249
250
  const addInitObligationForFarm = true;
250
251
  if (extraComputeBudget > 0) {
@@ -256,11 +257,11 @@ class KaminoAction {
256
257
  return axn;
257
258
  });
258
259
  }
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) {
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* () {
264
265
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
265
266
  const addInitObligationForFarmForDeposit = true;
266
267
  const addInitObligationForFarmForBorrow = false;
@@ -275,11 +276,11 @@ class KaminoAction {
275
276
  return axn;
276
277
  });
277
278
  }
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) {
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* () {
283
284
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
284
285
  const addInitObligationForFarmForRepay = true;
285
286
  const addInitObligationForFarmForWithdraw = false;
@@ -294,11 +295,11 @@ class KaminoAction {
294
295
  return axn;
295
296
  });
296
297
  }
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) {
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* () {
302
303
  const axn = yield KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
303
304
  const addInitObligationForFarm = true;
304
305
  if (extraComputeBudget > 0) {
@@ -325,8 +326,8 @@ class KaminoAction {
325
326
  * @param includeUserMetadata - if true it includes user metadata
326
327
  * @param referrer
327
328
  */
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) {
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* () {
330
331
  const axn = yield KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, undefined, payer);
331
332
  const addInitObligationForFarm = true;
332
333
  if (extraComputeBudget > 0) {
@@ -338,11 +339,11 @@ class KaminoAction {
338
339
  return axn;
339
340
  });
340
341
  }
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) {
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* () {
346
347
  const axn = yield KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
347
348
  const addInitObligationForFarm = true;
348
349
  if (extraComputeBudget > 0) {
@@ -354,8 +355,8 @@ class KaminoAction {
354
355
  return axn;
355
356
  });
356
357
  }
357
- static buildWithdrawReferrerFeeTxns(owner_1, tokenMint_1, kaminoMarket_1) {
358
- return __awaiter(this, arguments, void 0, function* (owner, tokenMint, kaminoMarket, currentSlot = 0) {
358
+ static buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0) {
359
+ return __awaiter(this, void 0, void 0, function* () {
359
360
  const { axn, createAtasIxns } = yield KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
360
361
  axn.preTxnIxs.push(...createAtasIxns);
361
362
  axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
@@ -445,7 +446,7 @@ class KaminoAction {
445
446
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
446
447
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
447
448
  reserveCollateralMint: this.reserve.getCTokenMint(),
448
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
449
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
449
450
  userSourceLiquidity: this.userTokenAccountAddress,
450
451
  placeholderUserDestinationCollateral: this.kaminoMarket.programId,
451
452
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -507,6 +508,7 @@ class KaminoAction {
507
508
  }, this.kaminoMarket.programId));
508
509
  }
509
510
  addBorrowIx() {
511
+ var _a;
510
512
  this.lendingIxsLabels.push(`borrowObligationLiquidity`);
511
513
  const depositReservesList = this.getAdditionalDepositReservesList();
512
514
  const depositReserveAccountMetas = depositReservesList.map((reserve) => {
@@ -528,7 +530,9 @@ class KaminoAction {
528
530
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
529
531
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
530
532
  }, this.kaminoMarket.programId);
531
- borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
533
+ borrowIx.keys = ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)
534
+ ? borrowIx.keys.concat([...depositReserveAccountMetas])
535
+ : borrowIx.keys;
532
536
  this.lendingIxs.push(borrowIx);
533
537
  }
534
538
  addDepositAndBorrowIx() {
@@ -546,7 +550,7 @@ class KaminoAction {
546
550
  reserveLiquidityMint: this.reserve.getLiquidityMint(),
547
551
  reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
548
552
  reserveCollateralMint: this.reserve.getCTokenMint(),
549
- reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
553
+ reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault,
550
554
  userSourceLiquidity: this.userTokenAccountAddress,
551
555
  placeholderUserDestinationCollateral: this.kaminoMarket.programId,
552
556
  collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -593,7 +597,11 @@ class KaminoAction {
593
597
  return __awaiter(this, void 0, void 0, function* () {
594
598
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
595
599
  this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
596
- this.lendingIxs.push((0, instructions_1.repayObligationLiquidity)({
600
+ const depositReservesList = this.getAdditionalDepositReservesList();
601
+ const depositReserveAccountMetas = depositReservesList.map((reserve) => {
602
+ return { pubkey: reserve, isSigner: false, isWritable: true };
603
+ });
604
+ const repayIx = (0, instructions_1.repayObligationLiquidity)({
597
605
  liquidityAmount: this.amount,
598
606
  }, {
599
607
  owner: this.owner,
@@ -605,7 +613,9 @@ class KaminoAction {
605
613
  reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
606
614
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
607
615
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
608
- }, this.kaminoMarket.programId));
616
+ }, this.kaminoMarket.programId);
617
+ repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
618
+ this.lendingIxs.push(repayIx);
609
619
  if (!this.outflowReserve) {
610
620
  throw new Error(`outflowReserve not set`);
611
621
  }
@@ -666,6 +676,7 @@ class KaminoAction {
666
676
  });
667
677
  }
668
678
  addRepayIx() {
679
+ var _a;
669
680
  return __awaiter(this, void 0, void 0, function* () {
670
681
  this.lendingIxsLabels.push(`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
671
682
  const depositReservesList = this.getAdditionalDepositReservesList();
@@ -685,12 +696,14 @@ class KaminoAction {
685
696
  tokenProgram: this.reserve.getLiquidityTokenProgram(),
686
697
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
687
698
  }, this.kaminoMarket.programId);
688
- repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
699
+ repayIx.keys =
700
+ ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
689
701
  this.lendingIxs.push(repayIx);
690
702
  });
691
703
  }
692
- addLiquidateIx() {
693
- return __awaiter(this, arguments, void 0, function* (maxAllowedLtvOverridePercent = 0) {
704
+ addLiquidateIx(maxAllowedLtvOverridePercent = 0) {
705
+ var _a;
706
+ return __awaiter(this, void 0, void 0, function* () {
694
707
  this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
695
708
  if (!this.outflowReserve) {
696
709
  throw Error(`Withdraw reserve during liquidation is not defined`);
@@ -729,12 +742,15 @@ class KaminoAction {
729
742
  withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
730
743
  instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
731
744
  }, this.kaminoMarket.programId);
732
- liquidateIx.keys = liquidateIx.keys.concat([...depositReserveAccountMetas]);
745
+ liquidateIx.keys =
746
+ ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0
747
+ ? liquidateIx.keys.concat([...depositReserveAccountMetas])
748
+ : liquidateIx.keys;
733
749
  this.lendingIxs.push(liquidateIx);
734
750
  });
735
751
  }
736
- addInBetweenIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, addInitObligationForFarm_1) {
737
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
752
+ addInBetweenIxs(action, includeAtaIxns, requestElevationGroup, addInitObligationForFarm, isClosingPosition = false) {
753
+ return __awaiter(this, void 0, void 0, function* () {
738
754
  yield this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, false, requestElevationGroup, addInitObligationForFarm, isClosingPosition);
739
755
  });
740
756
  }
@@ -748,9 +764,9 @@ class KaminoAction {
748
764
  this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxns, types_1.ReserveFarmKind.Debt, crank);
749
765
  this.addRefreshObligationIx(addAllToSetupIxns, false);
750
766
  }
751
- addSupportIxsWithoutInitObligation(action_1, includeAtaIxns_1) {
752
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, addToSetupIxs = true, requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false) {
753
- var _a;
767
+ addSupportIxsWithoutInitObligation(action, includeAtaIxns, addToSetupIxs = true, requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false) {
768
+ var _a;
769
+ return __awaiter(this, void 0, void 0, function* () {
754
770
  // TODO: why are we not doing this first?
755
771
  if (includeAtaIxns) {
756
772
  yield this.addAtaIxs(action);
@@ -907,18 +923,18 @@ class KaminoAction {
907
923
  const groupsColl = this.reserve.state.config.elevationGroups;
908
924
  const groupsDebt = this.outflowReserve.state.config.elevationGroups;
909
925
  const groups = this.kaminoMarket.state.elevationGroups;
910
- const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0);
926
+ const commonElevationGroups = [...groupsColl].filter((item) => groupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(this.outflowReserve.address));
911
927
  console.log('Groups of coll reserve', groupsColl, 'Groups of debt reserve', groupsDebt, 'Common groups', commonElevationGroups);
912
928
  if (commonElevationGroups.length === 0) {
913
929
  console.log('No common elevation groups found, staying with default');
914
930
  }
915
931
  else {
916
- const eModeGroupWithMaxLtv = commonElevationGroups.reduce((prev, curr) => {
932
+ const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
917
933
  const prevGroup = groups.find((group) => group.id === prev);
918
934
  const currGroup = groups.find((group) => group.id === curr);
919
935
  return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
920
936
  });
921
- const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtv).id;
937
+ const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
922
938
  console.log('Setting eModeGroup to', eModeGroup);
923
939
  if (eModeGroup !== 0 && eModeGroup !== ((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup)) {
924
940
  this.addRequestElevationIx(eModeGroup, false);
@@ -931,8 +947,8 @@ class KaminoAction {
931
947
  }
932
948
  });
933
949
  }
934
- addSupportIxs(action_1, includeAtaIxns_1, requestElevationGroup_1, includeUserMetadata_1, addInitObligationForFarm_1) {
935
- return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false) {
950
+ addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, twoTokenAction = false) {
951
+ return __awaiter(this, void 0, void 0, function* () {
936
952
  if (!['mint', 'redeem'].includes(action)) {
937
953
  const [, ownerUserMetadata] = yield this.kaminoMarket.getUserMetadata(this.owner);
938
954
  if (!ownerUserMetadata && includeUserMetadata) {
@@ -1138,8 +1154,8 @@ class KaminoAction {
1138
1154
  this.cleanupIxs.splice(this.cleanupIxs.length - 1, 0, ...this.refreshFarmsCleanupTxnIxs);
1139
1155
  this.cleanupIxsLabels.splice(this.cleanupIxsLabels.length - 1, 0, ...this.refreshFarmsCleanupTxnIxsLabels);
1140
1156
  }
1141
- addInitObligationForFarm(reserve_1, mode_1) {
1142
- return __awaiter(this, arguments, void 0, function* (reserve, mode, addToSetupIxs = true) {
1157
+ addInitObligationForFarm(reserve, mode, addToSetupIxs = true) {
1158
+ return __awaiter(this, void 0, void 0, function* () {
1143
1159
  const BASE_SEED_USER_STATE = Buffer.from('user');
1144
1160
  const getPda = (farm) => web3_js_1.PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()], farms_sdk_1.farmsId)[0];
1145
1161
  const farms = [];
@@ -1233,8 +1249,8 @@ class KaminoAction {
1233
1249
  this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
1234
1250
  });
1235
1251
  }
1236
- addInitReferrerTokenStateIxs() {
1237
- return __awaiter(this, arguments, void 0, function* (reservesArr = []) {
1252
+ addInitReferrerTokenStateIxs(reservesArr = []) {
1253
+ return __awaiter(this, void 0, void 0, function* () {
1238
1254
  if (this.referrer.equals(web3_js_1.PublicKey.default)) {
1239
1255
  return;
1240
1256
  }
@@ -1286,8 +1302,8 @@ class KaminoAction {
1286
1302
  this.setupIxsLabels.push(`AddComputeBudget[${units}]`);
1287
1303
  }
1288
1304
  addAtaIxs(action) {
1305
+ var _a, _b;
1289
1306
  return __awaiter(this, void 0, void 0, function* () {
1290
- var _a, _b;
1291
1307
  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))) {
1292
1308
  yield this.updateWSOLAccount(action);
1293
1309
  }
@@ -1385,8 +1401,8 @@ class KaminoAction {
1385
1401
  });
1386
1402
  }
1387
1403
  updateWSOLAccount(action) {
1404
+ var _a, _b;
1388
1405
  return __awaiter(this, void 0, void 0, function* () {
1389
- var _a, _b;
1390
1406
  const preIxs = [];
1391
1407
  const postIxs = [];
1392
1408
  const preIxsLabels = [];
@@ -1430,7 +1446,7 @@ class KaminoAction {
1430
1446
  });
1431
1447
  preIxs.push(transferLamportsIx);
1432
1448
  preIxsLabels.push(`TransferLamportsToUserAtaSOL[${userTokenAccountAddress}]`);
1433
- const closeWSOLAccountIx = (0, spl_token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, [], spl_token_1.TOKEN_PROGRAM_ID);
1449
+ const closeWSOLAccountIx = (0, token_1.createCloseAccountInstruction)(userTokenAccountAddress, this.owner, this.owner, spl_token_1.TOKEN_PROGRAM_ID);
1434
1450
  const syncIx = (0, utils_1.syncNative)(userTokenAccountAddress);
1435
1451
  if (userWSOLAccountInfo) {
1436
1452
  if (sendAction) {
@@ -1465,8 +1481,8 @@ class KaminoAction {
1465
1481
  this.cleanupIxsLabels.push(...postIxsLabels);
1466
1482
  });
1467
1483
  }
1468
- static initializeMultiTokenAction(kaminoMarket_1, action_1, inflowAmount_1, inflowTokenMint_1, outflowTokenMint_1, payer_1, obligationOwner_1, obligation_2, outflowAmount_1) {
1469
- return __awaiter(this, arguments, void 0, function* (kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1484
+ static initializeMultiTokenAction(kaminoMarket, action, inflowAmount, inflowTokenMint, outflowTokenMint, payer, obligationOwner, obligation, outflowAmount, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
1485
+ return __awaiter(this, void 0, void 0, function* () {
1470
1486
  const inflowReserve = kaminoMarket.getReserveByMint(inflowTokenMint);
1471
1487
  const outflowReserve = kaminoMarket.getReserveByMint(outflowTokenMint);
1472
1488
  if (!outflowReserve || !inflowReserve) {
@@ -1512,8 +1528,8 @@ class KaminoAction {
1512
1528
  return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, undefined, secondaryMint, additionalUserTokenAccountAddress, outflowReserve, outflowAmount, referrerKey);
1513
1529
  });
1514
1530
  }
1515
- static initializeWithdrawReferrerFees(mint_1, owner_1, kaminoMarket_1) {
1516
- return __awaiter(this, arguments, void 0, function* (mint, owner, kaminoMarket, currentSlot = 0, hostAta) {
1531
+ static initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0, hostAta) {
1532
+ return __awaiter(this, void 0, void 0, function* () {
1517
1533
  const reserve = kaminoMarket.getReserveByMint(mint);
1518
1534
  if (reserve === undefined) {
1519
1535
  throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);