@kamino-finance/klend-sdk 5.13.1 → 5.13.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.
- package/dist/classes/action.d.ts +32 -31
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +126 -95
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +3 -2
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +3 -2
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +7 -7
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +46 -46
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/reserve.d.ts +2 -2
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +70 -70
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +13 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/utils.d.ts +1 -9
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +4 -51
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +5 -3
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +50 -41
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/{types.d.ts → vault_types.d.ts} +2 -15
- package/dist/classes/vault_types.d.ts.map +1 -0
- package/dist/classes/{types.js → vault_types.js} +1 -1
- package/dist/classes/vault_types.js.map +1 -0
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +25 -26
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +6 -6
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +6 -6
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +61 -61
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +0 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +5 -8
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +5 -5
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +73 -73
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +1 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +2 -2
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +5 -5
- package/dist/leverage/utils.js.map +1 -1
- package/dist/referrals/instructions.d.ts +3 -3
- package/dist/referrals/instructions.d.ts.map +1 -1
- package/dist/referrals/instructions.js +10 -10
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/referrals/operations.js +6 -6
- package/dist/referrals/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +3 -3
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +22 -22
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/instruction.d.ts +2 -2
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +12 -12
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/lookupTable.js +6 -6
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +3 -3
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +143 -102
- package/src/classes/index.ts +5 -2
- package/src/classes/manager.ts +54 -51
- package/src/classes/obligationOrder.ts +1 -1
- package/src/classes/reserve.ts +126 -132
- package/src/classes/shared.ts +15 -0
- package/src/classes/utils.ts +3 -52
- package/src/classes/vault.ts +53 -42
- package/src/classes/{types.ts → vault_types.ts} +1 -16
- package/src/client.ts +16 -16
- package/src/client_kamino_manager.ts +25 -25
- package/src/lending_operations/repay_with_collateral_operations.ts +13 -13
- package/src/lending_operations/swap_collateral_operations.ts +85 -85
- package/src/leverage/calcs.ts +2 -6
- package/src/leverage/operations.ts +84 -84
- package/src/leverage/types.ts +1 -1
- package/src/leverage/utils.ts +5 -5
- package/src/referrals/instructions.ts +6 -6
- package/src/referrals/operations.ts +9 -9
- package/src/utils/ata.ts +18 -18
- package/src/utils/instruction.ts +10 -10
- package/src/utils/lookupTable.ts +6 -6
- package/src/utils/userMetadata.ts +1 -1
- package/dist/classes/types.d.ts.map +0 -1
- package/dist/classes/types.js.map +0 -1
- package/dist/classes/types_utils.d.ts +0 -14
- package/dist/classes/types_utils.d.ts.map +0 -1
- package/dist/classes/types_utils.js +0 -50
- package/dist/classes/types_utils.js.map +0 -1
- package/src/classes/types_utils.ts +0 -49
package/dist/classes/action.js
CHANGED
|
@@ -22,7 +22,7 @@ class KaminoAction {
|
|
|
22
22
|
outflowReserve;
|
|
23
23
|
owner;
|
|
24
24
|
payer;
|
|
25
|
-
obligation
|
|
25
|
+
obligation;
|
|
26
26
|
referrer;
|
|
27
27
|
/**
|
|
28
28
|
* Null unless the obligation is not passed
|
|
@@ -50,13 +50,8 @@ class KaminoAction {
|
|
|
50
50
|
preLoadedDepositReservesSameTx;
|
|
51
51
|
currentSlot;
|
|
52
52
|
constructor(kaminoMarket, owner, obligation, mint, positions, amount, depositReserves, borrowReserves, reserveState, currentSlot, secondaryMint, outflowReserveState, outflowAmount, referrer, payer) {
|
|
53
|
-
if (obligation instanceof obligation_1.KaminoObligation) {
|
|
54
|
-
this.obligation = obligation;
|
|
55
|
-
}
|
|
56
|
-
else if (obligation !== null) {
|
|
57
|
-
this.obligationType = obligation;
|
|
58
|
-
}
|
|
59
53
|
this.kaminoMarket = kaminoMarket;
|
|
54
|
+
this.obligation = obligation;
|
|
60
55
|
this.owner = owner;
|
|
61
56
|
this.payer = payer ?? owner;
|
|
62
57
|
this.amount = new bn_js_1.default(amount);
|
|
@@ -134,7 +129,7 @@ class KaminoAction {
|
|
|
134
129
|
distinctReserveCount,
|
|
135
130
|
};
|
|
136
131
|
}
|
|
137
|
-
static async buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
132
|
+
static async buildRefreshObligationTxns(kaminoMarket, payer, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
138
133
|
currentSlot = 0) {
|
|
139
134
|
// placeholder for action initialization
|
|
140
135
|
const firstReserve = obligation.getDeposits()[0].reserveAddress;
|
|
@@ -149,7 +144,7 @@ class KaminoAction {
|
|
|
149
144
|
axn.addRefreshObligation(payer);
|
|
150
145
|
return axn;
|
|
151
146
|
}
|
|
152
|
-
static async buildRequestElevationGroupTxns(kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
147
|
+
static async buildRequestElevationGroupTxns(kaminoMarket, payer, obligation, elevationGroup, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
153
148
|
currentSlot = 0) {
|
|
154
149
|
const firstReserve = obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
155
150
|
const firstKaminoReserve = kaminoMarket.getReserveByAddress(firstReserve);
|
|
@@ -164,8 +159,8 @@ class KaminoAction {
|
|
|
164
159
|
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
165
160
|
return axn;
|
|
166
161
|
}
|
|
167
|
-
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
168
|
-
|
|
162
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
163
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
169
164
|
requestElevationGroup = false, // to be requested *before* the deposit
|
|
170
165
|
initUserMetadata = {
|
|
171
166
|
skipInitialization: false,
|
|
@@ -177,7 +172,7 @@ class KaminoAction {
|
|
|
177
172
|
if (extraComputeBudget > 0) {
|
|
178
173
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
179
174
|
}
|
|
180
|
-
await axn.addSupportIxs('deposit',
|
|
175
|
+
await axn.addSupportIxs('deposit', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, undefined, overrideElevationGroupRequest);
|
|
181
176
|
if (useV2Ixs) {
|
|
182
177
|
axn.addDepositIxV2();
|
|
183
178
|
}
|
|
@@ -193,8 +188,8 @@ class KaminoAction {
|
|
|
193
188
|
feed: feed,
|
|
194
189
|
}, tokens));
|
|
195
190
|
}
|
|
196
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
197
|
-
|
|
191
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
192
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
198
193
|
requestElevationGroup = false, initUserMetadata = {
|
|
199
194
|
skipInitialization: false,
|
|
200
195
|
skipLutCreation: false,
|
|
@@ -212,7 +207,7 @@ class KaminoAction {
|
|
|
212
207
|
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
213
208
|
}
|
|
214
209
|
}
|
|
215
|
-
await axn.addSupportIxs('borrow',
|
|
210
|
+
await axn.addSupportIxs('borrow', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, undefined, overrideElevationGroupRequest);
|
|
216
211
|
if (useV2Ixs) {
|
|
217
212
|
axn.addBorrowIxV2();
|
|
218
213
|
}
|
|
@@ -222,34 +217,34 @@ class KaminoAction {
|
|
|
222
217
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
223
218
|
return axn;
|
|
224
219
|
}
|
|
225
|
-
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
226
|
-
|
|
220
|
+
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
221
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas
|
|
227
222
|
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
228
223
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
229
224
|
const addInitObligationForFarm = true;
|
|
230
225
|
if (extraComputeBudget > 0) {
|
|
231
226
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
232
227
|
}
|
|
233
|
-
await axn.addSupportIxs('mint',
|
|
228
|
+
await axn.addSupportIxs('mint', includeAtaIxs, requestElevationGroup, false, addInitObligationForFarm, scopeRefreshConfig, { skipInitialization: true, skipLutCreation: true });
|
|
234
229
|
axn.addDepositReserveLiquidityIx();
|
|
235
230
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
236
231
|
return axn;
|
|
237
232
|
}
|
|
238
|
-
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
239
|
-
|
|
233
|
+
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
234
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas
|
|
240
235
|
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
241
236
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
242
237
|
const addInitObligationForFarm = true;
|
|
243
238
|
if (extraComputeBudget > 0) {
|
|
244
239
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
245
240
|
}
|
|
246
|
-
await axn.addSupportIxs('redeem',
|
|
241
|
+
await axn.addSupportIxs('redeem', includeAtaIxs, requestElevationGroup, false, addInitObligationForFarm, scopeRefreshConfig, { skipInitialization: true, skipLutCreation: true });
|
|
247
242
|
axn.addRedeemReserveCollateralIx();
|
|
248
243
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
249
244
|
return axn;
|
|
250
245
|
}
|
|
251
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
252
|
-
|
|
246
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
247
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas
|
|
253
248
|
requestElevationGroup = false, initUserMetadata = {
|
|
254
249
|
skipInitialization: false,
|
|
255
250
|
skipLutCreation: false,
|
|
@@ -259,7 +254,7 @@ class KaminoAction {
|
|
|
259
254
|
if (extraComputeBudget > 0) {
|
|
260
255
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
261
256
|
}
|
|
262
|
-
await axn.addSupportIxs('depositCollateral',
|
|
257
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
263
258
|
if (useV2Ixs) {
|
|
264
259
|
axn.addDepositObligationCollateralIxV2();
|
|
265
260
|
}
|
|
@@ -269,8 +264,8 @@ class KaminoAction {
|
|
|
269
264
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
270
265
|
return axn;
|
|
271
266
|
}
|
|
272
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
273
|
-
|
|
267
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
268
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
274
269
|
requestElevationGroup = false, initUserMetadata = {
|
|
275
270
|
skipInitialization: false,
|
|
276
271
|
skipLutCreation: false,
|
|
@@ -289,16 +284,16 @@ class KaminoAction {
|
|
|
289
284
|
axn.addInitReferrerTokenStateIx(axn.outflowReserve, referrerTokenState);
|
|
290
285
|
}
|
|
291
286
|
}
|
|
292
|
-
await axn.addSupportIxs('deposit',
|
|
287
|
+
await axn.addSupportIxs('deposit', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForDeposit, useV2Ixs, undefined, initUserMetadata, twoTokenAction);
|
|
293
288
|
if (useV2Ixs) {
|
|
294
289
|
await axn.addDepositAndBorrowIxV2();
|
|
295
290
|
}
|
|
296
291
|
else {
|
|
297
292
|
await axn.addDepositAndBorrowIx();
|
|
298
293
|
}
|
|
299
|
-
await axn.addInBetweenIxs('depositAndBorrow',
|
|
294
|
+
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
300
295
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
301
|
-
// Create the scope refresh
|
|
296
|
+
// Create the scope refresh ix in here to ensure it's the first ix in the txn
|
|
302
297
|
const allReserves = new utils_1.PublicKeySet([
|
|
303
298
|
...axn.depositReserves,
|
|
304
299
|
...axn.borrowReserves,
|
|
@@ -312,8 +307,8 @@ class KaminoAction {
|
|
|
312
307
|
}
|
|
313
308
|
return axn;
|
|
314
309
|
}
|
|
315
|
-
static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
316
|
-
|
|
310
|
+
static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
311
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
317
312
|
requestElevationGroup = false, initUserMetadata = {
|
|
318
313
|
skipInitialization: false,
|
|
319
314
|
skipLutCreation: false,
|
|
@@ -324,13 +319,13 @@ class KaminoAction {
|
|
|
324
319
|
if (extraComputeBudget > 0) {
|
|
325
320
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
326
321
|
}
|
|
327
|
-
await axn.addSupportIxs('depositAndWithdraw',
|
|
322
|
+
await axn.addSupportIxs('depositAndWithdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, true, scopeRefreshConfig, initUserMetadata, twoTokenAction);
|
|
328
323
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
329
324
|
axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
330
325
|
return axn;
|
|
331
326
|
}
|
|
332
|
-
static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
333
|
-
|
|
327
|
+
static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
328
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
334
329
|
requestElevationGroup = false, initUserMetadata = {
|
|
335
330
|
skipInitialization: false,
|
|
336
331
|
skipLutCreation: false,
|
|
@@ -341,13 +336,13 @@ class KaminoAction {
|
|
|
341
336
|
if (extraComputeBudget > 0) {
|
|
342
337
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
343
338
|
}
|
|
344
|
-
await axn.addSupportIxs('repayAndWithdrawV2',
|
|
339
|
+
await axn.addSupportIxs('repayAndWithdrawV2', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, true, scopeRefreshConfig, initUserMetadata, twoTokenAction);
|
|
345
340
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
346
341
|
axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
347
342
|
return axn;
|
|
348
343
|
}
|
|
349
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
350
|
-
|
|
344
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
345
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
351
346
|
requestElevationGroup = false, initUserMetadata = {
|
|
352
347
|
skipInitialization: false,
|
|
353
348
|
skipLutCreation: false,
|
|
@@ -359,7 +354,7 @@ class KaminoAction {
|
|
|
359
354
|
if (extraComputeBudget > 0) {
|
|
360
355
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
361
356
|
}
|
|
362
|
-
await axn.addSupportIxs('repay',
|
|
357
|
+
await axn.addSupportIxs('repay', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForRepay, useV2Ixs, undefined, initUserMetadata, twoTokenAction);
|
|
363
358
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
364
359
|
if (useV2Ixs) {
|
|
365
360
|
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
@@ -367,9 +362,9 @@ class KaminoAction {
|
|
|
367
362
|
else {
|
|
368
363
|
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
369
364
|
}
|
|
370
|
-
await axn.addInBetweenIxs('repayAndWithdraw',
|
|
365
|
+
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
371
366
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
372
|
-
// Create the scope refresh
|
|
367
|
+
// Create the scope refresh ix in here to ensure it's the first ix in the txn
|
|
373
368
|
const allReserves = new utils_1.PublicKeySet([
|
|
374
369
|
...axn.depositReserves,
|
|
375
370
|
...axn.borrowReserves,
|
|
@@ -383,14 +378,14 @@ class KaminoAction {
|
|
|
383
378
|
}
|
|
384
379
|
return axn;
|
|
385
380
|
}
|
|
386
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
387
|
-
|
|
381
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
382
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas,
|
|
388
383
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
389
384
|
initUserMetadata = {
|
|
390
385
|
skipInitialization: false,
|
|
391
386
|
skipLutCreation: false,
|
|
392
387
|
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest,
|
|
393
|
-
// Optional customizations which may be needed if the obligation was mutated by some previous
|
|
388
|
+
// Optional customizations which may be needed if the obligation was mutated by some previous ix.
|
|
394
389
|
obligationCustomizations) {
|
|
395
390
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
396
391
|
const addInitObligationForFarm = true;
|
|
@@ -398,7 +393,7 @@ class KaminoAction {
|
|
|
398
393
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
399
394
|
}
|
|
400
395
|
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
401
|
-
await axn.addSupportIxs('withdraw',
|
|
396
|
+
await axn.addSupportIxs('withdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, false, overrideElevationGroupRequest);
|
|
402
397
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
403
398
|
if (useV2Ixs) {
|
|
404
399
|
await axn.addWithdrawIxV2(collateralAmount);
|
|
@@ -418,13 +413,13 @@ class KaminoAction {
|
|
|
418
413
|
* @param obligation - obligation to repay or the PDA seeds
|
|
419
414
|
* @param currentSlot
|
|
420
415
|
* @param payer - if not set then owner is used
|
|
421
|
-
* @param extraComputeBudget - if > 0 then adds the
|
|
422
|
-
* @param
|
|
416
|
+
* @param extraComputeBudget - if > 0 then adds the ix
|
|
417
|
+
* @param includeAtaIxs - if true it includes create and close wsol and token atas
|
|
423
418
|
* @param requestElevationGroup
|
|
424
419
|
* @param includeUserMetadata - if true it includes user metadata
|
|
425
420
|
* @param referrer
|
|
426
421
|
*/
|
|
427
|
-
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, currentSlot, payer = undefined, extraComputeBudget = 1_000_000,
|
|
422
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxs = true, requestElevationGroup = false, initUserMetadata = {
|
|
428
423
|
skipInitialization: false,
|
|
429
424
|
skipLutCreation: false,
|
|
430
425
|
}, referrer = web3_js_1.PublicKey.default) {
|
|
@@ -433,7 +428,7 @@ class KaminoAction {
|
|
|
433
428
|
if (extraComputeBudget > 0) {
|
|
434
429
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
435
430
|
}
|
|
436
|
-
await axn.addSupportIxs('repay',
|
|
431
|
+
await axn.addSupportIxs('repay', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
437
432
|
if (useV2Ixs) {
|
|
438
433
|
await axn.addRepayIxV2();
|
|
439
434
|
}
|
|
@@ -443,8 +438,8 @@ class KaminoAction {
|
|
|
443
438
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
444
439
|
return axn;
|
|
445
440
|
}
|
|
446
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig = undefined, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
447
|
-
|
|
441
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig = undefined, extraComputeBudget = 1_000_000, // if > 0 then adds the ix
|
|
442
|
+
includeAtaIxs = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
448
443
|
requestElevationGroup = false, initUserMetadata = {
|
|
449
444
|
skipInitialization: false,
|
|
450
445
|
skipLutCreation: false,
|
|
@@ -454,7 +449,7 @@ class KaminoAction {
|
|
|
454
449
|
if (extraComputeBudget > 0) {
|
|
455
450
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
456
451
|
}
|
|
457
|
-
await axn.addSupportIxs('liquidate',
|
|
452
|
+
await axn.addSupportIxs('liquidate', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
458
453
|
if (useV2Ixs) {
|
|
459
454
|
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
460
455
|
}
|
|
@@ -696,7 +691,8 @@ class KaminoAction {
|
|
|
696
691
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
697
692
|
}, this.kaminoMarket.programId);
|
|
698
693
|
borrowIx.keys =
|
|
699
|
-
|
|
694
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) &&
|
|
695
|
+
(this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
|
|
700
696
|
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
701
697
|
: borrowIx.keys;
|
|
702
698
|
this.lendingIxs.push(borrowIx);
|
|
@@ -737,7 +733,8 @@ class KaminoAction {
|
|
|
737
733
|
farmsProgram: farms_sdk_1.farmsId,
|
|
738
734
|
}, this.kaminoMarket.programId);
|
|
739
735
|
borrowIx.keys =
|
|
740
|
-
|
|
736
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) &&
|
|
737
|
+
(this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
|
|
741
738
|
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
742
739
|
: borrowIx.keys;
|
|
743
740
|
this.lendingIxs.push(borrowIx);
|
|
@@ -819,7 +816,9 @@ class KaminoAction {
|
|
|
819
816
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
820
817
|
}, this.kaminoMarket.programId);
|
|
821
818
|
repayIx.keys =
|
|
822
|
-
this.obligation.state.elevationGroup > 0
|
|
819
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) && this.obligation.state.elevationGroup > 0
|
|
820
|
+
? repayIx.keys.concat([...depositReserveAccountMetas])
|
|
821
|
+
: repayIx.keys;
|
|
823
822
|
this.lendingIxs.push(repayIx);
|
|
824
823
|
}
|
|
825
824
|
async addRepayIxV2() {
|
|
@@ -856,7 +855,10 @@ class KaminoAction {
|
|
|
856
855
|
farmsProgram: farms_sdk_1.farmsId,
|
|
857
856
|
}, this.kaminoMarket.programId);
|
|
858
857
|
repayIx.keys =
|
|
859
|
-
|
|
858
|
+
// TODO: potential elev group update?
|
|
859
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) && this.obligation.state.elevationGroup > 0
|
|
860
|
+
? repayIx.keys.concat([...depositReserveAccountMetas])
|
|
861
|
+
: repayIx.keys;
|
|
860
862
|
this.lendingIxs.push(repayIx);
|
|
861
863
|
}
|
|
862
864
|
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount) {
|
|
@@ -1194,6 +1196,9 @@ class KaminoAction {
|
|
|
1194
1196
|
async addRepayAndWithdrawIxsV2(withdrawCollateralAmount) {
|
|
1195
1197
|
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1196
1198
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1199
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1200
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1201
|
+
}
|
|
1197
1202
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1198
1203
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1199
1204
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1225,7 +1230,8 @@ class KaminoAction {
|
|
|
1225
1230
|
farmsAccounts: debtFarmsAccounts,
|
|
1226
1231
|
farmsProgram: farms_sdk_1.farmsId,
|
|
1227
1232
|
}, this.kaminoMarket.programId);
|
|
1228
|
-
repayIx.keys =
|
|
1233
|
+
repayIx.keys =
|
|
1234
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1229
1235
|
this.lendingIxs.push(repayIx);
|
|
1230
1236
|
if (!this.outflowReserve) {
|
|
1231
1237
|
throw new Error(`outflowReserve not set`);
|
|
@@ -1270,6 +1276,9 @@ class KaminoAction {
|
|
|
1270
1276
|
if (!this.outflowReserve) {
|
|
1271
1277
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1272
1278
|
}
|
|
1279
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1280
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1281
|
+
}
|
|
1273
1282
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1274
1283
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1275
1284
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1312,6 +1321,9 @@ class KaminoAction {
|
|
|
1312
1321
|
if (!this.outflowReserve) {
|
|
1313
1322
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1314
1323
|
}
|
|
1324
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1325
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1326
|
+
}
|
|
1315
1327
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1316
1328
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1317
1329
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1372,22 +1384,22 @@ class KaminoAction {
|
|
|
1372
1384
|
: liquidateIx.keys;
|
|
1373
1385
|
this.lendingIxs.push(liquidateIx);
|
|
1374
1386
|
}
|
|
1375
|
-
async addInBetweenIxs(action,
|
|
1376
|
-
await this.addSupportIxsWithoutInitObligation(action,
|
|
1387
|
+
async addInBetweenIxs(action, includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs) {
|
|
1388
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
1377
1389
|
}
|
|
1378
1390
|
addRefreshObligation(crank) {
|
|
1379
1391
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
1380
|
-
const
|
|
1392
|
+
const addAllToSetupIxs = 'setup';
|
|
1381
1393
|
// Union of addresses
|
|
1382
1394
|
const allReservesExcludingCurrent = [...uniqueReserveAddresses];
|
|
1383
|
-
this.addRefreshReserveIxs(allReservesExcludingCurrent,
|
|
1384
|
-
this.addRefreshFarmsForReserve(this.depositReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)),
|
|
1385
|
-
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)),
|
|
1386
|
-
this.addRefreshObligationIx(
|
|
1395
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAllToSetupIxs);
|
|
1396
|
+
this.addRefreshFarmsForReserve(this.depositReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxs, types_1.ReserveFarmKind.Collateral, crank);
|
|
1397
|
+
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)), addAllToSetupIxs, types_1.ReserveFarmKind.Debt, crank);
|
|
1398
|
+
this.addRefreshObligationIx(addAllToSetupIxs);
|
|
1387
1399
|
}
|
|
1388
|
-
async addSupportIxsWithoutInitObligation(action,
|
|
1400
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1389
1401
|
// TODO: why are we not doing this first?
|
|
1390
|
-
if (
|
|
1402
|
+
if (includeAtaIxs) {
|
|
1391
1403
|
await this.addAtaIxs(action);
|
|
1392
1404
|
}
|
|
1393
1405
|
if ([
|
|
@@ -1403,18 +1415,18 @@ class KaminoAction {
|
|
|
1403
1415
|
'refreshObligation',
|
|
1404
1416
|
'depositAndWithdraw',
|
|
1405
1417
|
].includes(action)) {
|
|
1406
|
-
// The support
|
|
1407
|
-
// 0. Init obligation
|
|
1408
|
-
// 0. Token Ata
|
|
1418
|
+
// The support ixs in order are:
|
|
1419
|
+
// 0. Init obligation ix
|
|
1420
|
+
// 0. Token Ata ixs
|
|
1409
1421
|
// 0. Init obligation for farm
|
|
1410
|
-
// 1.
|
|
1411
|
-
// 2.
|
|
1412
|
-
// 3.
|
|
1413
|
-
// 4.
|
|
1414
|
-
// 5.
|
|
1422
|
+
// 1. Ixs to refresh the reserves of the obligation not related to the current action
|
|
1423
|
+
// 2. Ix to refresh the reserve of the current action
|
|
1424
|
+
// 3. Ix to refresh the obligation
|
|
1425
|
+
// 4. Ix to refresh the `debt` farm of the obligation
|
|
1426
|
+
// 5. Ix to refresh the `collateral` farm of the obligation
|
|
1415
1427
|
// 6. The instruction itself
|
|
1416
|
-
// 7.
|
|
1417
|
-
// 8.
|
|
1428
|
+
// 7. Ix to refresh the `debt` farm of the obligation
|
|
1429
|
+
// 8. Ix to refresh the `collateral` farm of the obligation
|
|
1418
1430
|
let currentReserves = [];
|
|
1419
1431
|
if (action === 'liquidate' ||
|
|
1420
1432
|
action === 'depositAndBorrow' ||
|
|
@@ -1426,7 +1438,7 @@ class KaminoAction {
|
|
|
1426
1438
|
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
1427
1439
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
1428
1440
|
if (action === 'depositAndBorrow') {
|
|
1429
|
-
if (this.obligation) {
|
|
1441
|
+
if ((0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1430
1442
|
const deposit = this.obligation.getDepositByReserve(this.reserve.address);
|
|
1431
1443
|
if (!deposit) {
|
|
1432
1444
|
this.preLoadedDepositReservesSameTx.push(this.reserve.address);
|
|
@@ -1489,6 +1501,9 @@ class KaminoAction {
|
|
|
1489
1501
|
}
|
|
1490
1502
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1491
1503
|
if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween') {
|
|
1504
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1505
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1506
|
+
}
|
|
1492
1507
|
const repayObligationLiquidity = this.obligation.getBorrowByReserve(this.reserve.address);
|
|
1493
1508
|
if (!repayObligationLiquidity) {
|
|
1494
1509
|
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
@@ -1503,13 +1518,16 @@ class KaminoAction {
|
|
|
1503
1518
|
}
|
|
1504
1519
|
if (requestElevationGroup) {
|
|
1505
1520
|
if (action === 'repay' || action === 'repayAndWithdrawV2') {
|
|
1506
|
-
|
|
1521
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1522
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1523
|
+
}
|
|
1524
|
+
const repayObligationLiquidity = this.obligation.getBorrowByReserve(this.reserve.address);
|
|
1507
1525
|
if (!repayObligationLiquidity) {
|
|
1508
1526
|
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
1509
1527
|
}
|
|
1510
1528
|
if (repayObligationLiquidity.amount.lte(new decimal_js_1.default(this.amount.toString())) &&
|
|
1511
1529
|
this.obligation.borrows.size === 1 &&
|
|
1512
|
-
this.obligation
|
|
1530
|
+
this.obligation.state.elevationGroup !== 0) {
|
|
1513
1531
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
|
|
1514
1532
|
// Skip the borrow reserve, since we repay in the same tx
|
|
1515
1533
|
this.addRefreshObligationIx('cleanup', [this.reserve.address]);
|
|
@@ -1532,6 +1550,9 @@ class KaminoAction {
|
|
|
1532
1550
|
addAsSupportIx = 'inBetween';
|
|
1533
1551
|
}
|
|
1534
1552
|
else if (action === 'borrow') {
|
|
1553
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1554
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1555
|
+
}
|
|
1535
1556
|
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1536
1557
|
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1537
1558
|
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
@@ -1551,25 +1572,30 @@ class KaminoAction {
|
|
|
1551
1572
|
});
|
|
1552
1573
|
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
|
|
1553
1574
|
console.log('Setting eModeGroup to', eModeGroup);
|
|
1554
|
-
if (eModeGroup !== 0 &&
|
|
1575
|
+
if (eModeGroup !== 0 &&
|
|
1576
|
+
eModeGroup !== ((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1555
1577
|
newElevationGroup = eModeGroup;
|
|
1556
1578
|
}
|
|
1557
1579
|
}
|
|
1558
1580
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1581
|
+
if (newElevationGroup >= 0 &&
|
|
1582
|
+
newElevationGroup !== ((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1561
1583
|
this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
|
|
1562
1584
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1563
1585
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1564
1586
|
this.addRefreshObligationIx(addAsSupportIx);
|
|
1565
1587
|
if (action === 'borrow') {
|
|
1588
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1589
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1590
|
+
}
|
|
1566
1591
|
this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
|
|
1567
1592
|
}
|
|
1568
1593
|
}
|
|
1569
1594
|
}
|
|
1570
1595
|
else if (action === 'deposit' &&
|
|
1571
1596
|
overrideElevationGroupRequest !== undefined &&
|
|
1572
|
-
overrideElevationGroupRequest !==
|
|
1597
|
+
overrideElevationGroupRequest !==
|
|
1598
|
+
((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1573
1599
|
const addAsSupportIx = 'setup';
|
|
1574
1600
|
console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
|
|
1575
1601
|
this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
|
|
@@ -1590,7 +1616,7 @@ class KaminoAction {
|
|
|
1590
1616
|
}
|
|
1591
1617
|
if (!useV2Ixs) {
|
|
1592
1618
|
if (addAsSupportIx === 'setup') {
|
|
1593
|
-
// If this is an setup
|
|
1619
|
+
// If this is an setup ix (therefore not an in-between), it means it's either a one off action
|
|
1594
1620
|
// or the first of a two-token-action
|
|
1595
1621
|
if (action === 'liquidate') {
|
|
1596
1622
|
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
@@ -1612,7 +1638,7 @@ class KaminoAction {
|
|
|
1612
1638
|
else {
|
|
1613
1639
|
// If this is an inbetween, it means it's part of a two-token-action
|
|
1614
1640
|
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1615
|
-
// add added to 'setup'
|
|
1641
|
+
// add added to 'setup' ixs
|
|
1616
1642
|
if (action === 'depositAndBorrow') {
|
|
1617
1643
|
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1618
1644
|
}
|
|
@@ -1626,7 +1652,7 @@ class KaminoAction {
|
|
|
1626
1652
|
}
|
|
1627
1653
|
}
|
|
1628
1654
|
}
|
|
1629
|
-
async addSupportIxs(action,
|
|
1655
|
+
async addSupportIxs(action, includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1630
1656
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1631
1657
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1632
1658
|
if (!ownerUserMetadata && !initUserMetadata.skipInitialization) {
|
|
@@ -1641,7 +1667,7 @@ class KaminoAction {
|
|
|
1641
1667
|
}
|
|
1642
1668
|
await this.addInitObligationIxs();
|
|
1643
1669
|
}
|
|
1644
|
-
await this.addSupportIxsWithoutInitObligation(action,
|
|
1670
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1645
1671
|
const allReserves = new utils_1.PublicKeySet([
|
|
1646
1672
|
...this.depositReserves,
|
|
1647
1673
|
...this.borrowReserves,
|
|
@@ -1880,7 +1906,7 @@ class KaminoAction {
|
|
|
1880
1906
|
farms.forEach((arg) => {
|
|
1881
1907
|
const args = { mode: arg[0] };
|
|
1882
1908
|
const accounts = {
|
|
1883
|
-
owner: this.obligation ? this.obligation.state.owner : this.owner,
|
|
1909
|
+
owner: (0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.owner : this.owner,
|
|
1884
1910
|
payer: this.owner,
|
|
1885
1911
|
obligation: this.getObligationPda(),
|
|
1886
1912
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
@@ -1904,21 +1930,21 @@ class KaminoAction {
|
|
|
1904
1930
|
});
|
|
1905
1931
|
}
|
|
1906
1932
|
addInitObligationIxs() {
|
|
1907
|
-
if (!this.obligation) {
|
|
1933
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1908
1934
|
const obligationPda = this.getObligationPda();
|
|
1909
1935
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1910
1936
|
const initObligationIx = (0, instructions_1.initObligation)({
|
|
1911
1937
|
args: {
|
|
1912
|
-
tag: this.
|
|
1913
|
-
id: this.
|
|
1938
|
+
tag: this.obligation.toArgs().tag,
|
|
1939
|
+
id: this.obligation.toArgs().id,
|
|
1914
1940
|
},
|
|
1915
1941
|
}, {
|
|
1916
1942
|
obligationOwner: this.owner,
|
|
1917
1943
|
feePayer: this.payer,
|
|
1918
1944
|
obligation: obligationPda,
|
|
1919
1945
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1920
|
-
seed1Account: this.
|
|
1921
|
-
seed2Account: this.
|
|
1946
|
+
seed1Account: this.obligation.toArgs().seed1,
|
|
1947
|
+
seed2Account: this.obligation.toArgs().seed2,
|
|
1922
1948
|
ownerUserMetadata: userMetadataAddress,
|
|
1923
1949
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1924
1950
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
@@ -2032,7 +2058,9 @@ class KaminoAction {
|
|
|
2032
2058
|
return;
|
|
2033
2059
|
}
|
|
2034
2060
|
let safeRepay = new bn_js_1.default(this.amount);
|
|
2035
|
-
if (
|
|
2061
|
+
if ((0, obligation_1.isKaminoObligation)(this.obligation) &&
|
|
2062
|
+
(action === 'repay' || action === 'repayAndWithdrawV2') &&
|
|
2063
|
+
this.amount.eq(new bn_js_1.default(utils_1.U64_MAX))) {
|
|
2036
2064
|
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
|
|
2037
2065
|
if (!borrow) {
|
|
2038
2066
|
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
@@ -2139,9 +2167,12 @@ class KaminoAction {
|
|
|
2139
2167
|
: new bn_js_1.default(new decimal_js_1.default(amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
2140
2168
|
}
|
|
2141
2169
|
getObligationPda() {
|
|
2142
|
-
return this.obligation
|
|
2170
|
+
return (0, obligation_1.isKaminoObligation)(this.obligation)
|
|
2143
2171
|
? this.obligation.obligationAddress
|
|
2144
|
-
: this.
|
|
2172
|
+
: this.obligation.toPda(this.kaminoMarket.getAddress(), this.owner);
|
|
2173
|
+
}
|
|
2174
|
+
isObligationInitialized() {
|
|
2175
|
+
return this.obligation instanceof obligation_1.KaminoObligation;
|
|
2145
2176
|
}
|
|
2146
2177
|
getAdditionalDepositReservesList() {
|
|
2147
2178
|
const depositReservesList = this.depositReserves;
|