@kamino-finance/klend-sdk 5.13.0 → 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 +74 -49
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +167 -115
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/fraction.d.ts +2 -0
- package/dist/classes/fraction.d.ts.map +1 -1
- package/dist/classes/fraction.js +6 -0
- package/dist/classes/fraction.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/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -6
- package/dist/classes/obligation.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 +71 -74
- 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 +53 -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.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +8 -8
- 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 +63 -65
- 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 +80 -87
- 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 +198 -150
- package/src/classes/fraction.ts +7 -0
- package/src/classes/index.ts +5 -2
- package/src/classes/manager.ts +54 -51
- package/src/classes/obligation.ts +2 -7
- package/src/classes/obligationOrder.ts +1 -1
- package/src/classes/reserve.ts +128 -137
- package/src/classes/shared.ts +15 -0
- package/src/classes/utils.ts +3 -52
- package/src/classes/vault.ts +56 -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 -15
- package/src/lending_operations/swap_collateral_operations.ts +87 -89
- package/src/leverage/calcs.ts +2 -6
- package/src/leverage/operations.ts +91 -97
- 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,18 +159,20 @@ 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
|
-
|
|
171
|
-
|
|
165
|
+
initUserMetadata = {
|
|
166
|
+
skipInitialization: false,
|
|
167
|
+
skipLutCreation: false,
|
|
168
|
+
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
172
169
|
) {
|
|
173
170
|
const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
174
171
|
const addInitObligationForFarm = true;
|
|
175
172
|
if (extraComputeBudget > 0) {
|
|
176
173
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
177
174
|
}
|
|
178
|
-
await axn.addSupportIxs('deposit',
|
|
175
|
+
await axn.addSupportIxs('deposit', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, undefined, overrideElevationGroupRequest);
|
|
179
176
|
if (useV2Ixs) {
|
|
180
177
|
axn.addDepositIxV2();
|
|
181
178
|
}
|
|
@@ -191,10 +188,12 @@ class KaminoAction {
|
|
|
191
188
|
feed: feed,
|
|
192
189
|
}, tokens));
|
|
193
190
|
}
|
|
194
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
195
|
-
|
|
196
|
-
requestElevationGroup = false,
|
|
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,
|
|
193
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
194
|
+
skipInitialization: false,
|
|
195
|
+
skipLutCreation: false,
|
|
196
|
+
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
198
197
|
) {
|
|
199
198
|
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
200
199
|
const addInitObligationForFarm = true;
|
|
@@ -208,7 +207,7 @@ class KaminoAction {
|
|
|
208
207
|
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
|
-
await axn.addSupportIxs('borrow',
|
|
210
|
+
await axn.addSupportIxs('borrow', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, undefined, overrideElevationGroupRequest);
|
|
212
211
|
if (useV2Ixs) {
|
|
213
212
|
axn.addBorrowIxV2();
|
|
214
213
|
}
|
|
@@ -218,42 +217,44 @@ class KaminoAction {
|
|
|
218
217
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
219
218
|
return axn;
|
|
220
219
|
}
|
|
221
|
-
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
222
|
-
|
|
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
|
|
223
222
|
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
224
223
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
225
224
|
const addInitObligationForFarm = true;
|
|
226
225
|
if (extraComputeBudget > 0) {
|
|
227
226
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
228
227
|
}
|
|
229
|
-
await axn.addSupportIxs('mint',
|
|
228
|
+
await axn.addSupportIxs('mint', includeAtaIxs, requestElevationGroup, false, addInitObligationForFarm, scopeRefreshConfig, { skipInitialization: true, skipLutCreation: true });
|
|
230
229
|
axn.addDepositReserveLiquidityIx();
|
|
231
230
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
232
231
|
return axn;
|
|
233
232
|
}
|
|
234
|
-
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
235
|
-
|
|
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
|
|
236
235
|
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
237
236
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
238
237
|
const addInitObligationForFarm = true;
|
|
239
238
|
if (extraComputeBudget > 0) {
|
|
240
239
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
241
240
|
}
|
|
242
|
-
await axn.addSupportIxs('redeem',
|
|
241
|
+
await axn.addSupportIxs('redeem', includeAtaIxs, requestElevationGroup, false, addInitObligationForFarm, scopeRefreshConfig, { skipInitialization: true, skipLutCreation: true });
|
|
243
242
|
axn.addRedeemReserveCollateralIx();
|
|
244
243
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
245
244
|
return axn;
|
|
246
245
|
}
|
|
247
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
248
|
-
|
|
249
|
-
requestElevationGroup = false,
|
|
250
|
-
|
|
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
|
|
248
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
249
|
+
skipInitialization: false,
|
|
250
|
+
skipLutCreation: false,
|
|
251
|
+
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
251
252
|
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
252
253
|
const addInitObligationForFarm = true;
|
|
253
254
|
if (extraComputeBudget > 0) {
|
|
254
255
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
255
256
|
}
|
|
256
|
-
await axn.addSupportIxs('depositCollateral',
|
|
257
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
257
258
|
if (useV2Ixs) {
|
|
258
259
|
axn.addDepositObligationCollateralIxV2();
|
|
259
260
|
}
|
|
@@ -263,10 +264,12 @@ class KaminoAction {
|
|
|
263
264
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
264
265
|
return axn;
|
|
265
266
|
}
|
|
266
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
267
|
-
|
|
268
|
-
requestElevationGroup = false,
|
|
269
|
-
|
|
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,
|
|
269
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
270
|
+
skipInitialization: false,
|
|
271
|
+
skipLutCreation: false,
|
|
272
|
+
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
270
273
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
271
274
|
const addInitObligationForFarmForDeposit = true;
|
|
272
275
|
const addInitObligationForFarmForBorrow = false;
|
|
@@ -281,16 +284,16 @@ class KaminoAction {
|
|
|
281
284
|
axn.addInitReferrerTokenStateIx(axn.outflowReserve, referrerTokenState);
|
|
282
285
|
}
|
|
283
286
|
}
|
|
284
|
-
await axn.addSupportIxs('deposit',
|
|
287
|
+
await axn.addSupportIxs('deposit', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForDeposit, useV2Ixs, undefined, initUserMetadata, twoTokenAction);
|
|
285
288
|
if (useV2Ixs) {
|
|
286
289
|
await axn.addDepositAndBorrowIxV2();
|
|
287
290
|
}
|
|
288
291
|
else {
|
|
289
292
|
await axn.addDepositAndBorrowIx();
|
|
290
293
|
}
|
|
291
|
-
await axn.addInBetweenIxs('depositAndBorrow',
|
|
294
|
+
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
292
295
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
293
|
-
// Create the scope refresh
|
|
296
|
+
// Create the scope refresh ix in here to ensure it's the first ix in the txn
|
|
294
297
|
const allReserves = new utils_1.PublicKeySet([
|
|
295
298
|
...axn.depositReserves,
|
|
296
299
|
...axn.borrowReserves,
|
|
@@ -304,40 +307,46 @@ class KaminoAction {
|
|
|
304
307
|
}
|
|
305
308
|
return axn;
|
|
306
309
|
}
|
|
307
|
-
static async buildDepositAndWithdrawV2Txns(kaminoMarket, depositAmount, depositMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
308
|
-
|
|
309
|
-
requestElevationGroup = false,
|
|
310
|
-
|
|
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,
|
|
312
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
313
|
+
skipInitialization: false,
|
|
314
|
+
skipLutCreation: false,
|
|
315
|
+
}, referrer = web3_js_1.PublicKey.default) {
|
|
311
316
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndWithdraw', depositAmount, depositMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
312
317
|
const addInitObligationForFarm = true;
|
|
313
318
|
const twoTokenAction = true;
|
|
314
319
|
if (extraComputeBudget > 0) {
|
|
315
320
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
316
321
|
}
|
|
317
|
-
await axn.addSupportIxs('depositAndWithdraw',
|
|
322
|
+
await axn.addSupportIxs('depositAndWithdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, true, scopeRefreshConfig, initUserMetadata, twoTokenAction);
|
|
318
323
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
319
324
|
axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
320
325
|
return axn;
|
|
321
326
|
}
|
|
322
|
-
static async buildRepayAndWithdrawV2Txns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
323
|
-
|
|
324
|
-
requestElevationGroup = false,
|
|
325
|
-
|
|
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,
|
|
329
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
330
|
+
skipInitialization: false,
|
|
331
|
+
skipLutCreation: false,
|
|
332
|
+
}, referrer = web3_js_1.PublicKey.default) {
|
|
326
333
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdrawV2', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
327
334
|
const addInitObligationForFarm = true;
|
|
328
335
|
const twoTokenAction = true;
|
|
329
336
|
if (extraComputeBudget > 0) {
|
|
330
337
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
331
338
|
}
|
|
332
|
-
await axn.addSupportIxs('repayAndWithdrawV2',
|
|
339
|
+
await axn.addSupportIxs('repayAndWithdrawV2', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, true, scopeRefreshConfig, initUserMetadata, twoTokenAction);
|
|
333
340
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
334
341
|
axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
335
342
|
return axn;
|
|
336
343
|
}
|
|
337
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
338
|
-
|
|
339
|
-
requestElevationGroup = false,
|
|
340
|
-
|
|
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,
|
|
346
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
347
|
+
skipInitialization: false,
|
|
348
|
+
skipLutCreation: false,
|
|
349
|
+
}, referrer = web3_js_1.PublicKey.default) {
|
|
341
350
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
342
351
|
const addInitObligationForFarmForRepay = true;
|
|
343
352
|
const addInitObligationForFarmForWithdraw = false;
|
|
@@ -345,7 +354,7 @@ class KaminoAction {
|
|
|
345
354
|
if (extraComputeBudget > 0) {
|
|
346
355
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
347
356
|
}
|
|
348
|
-
await axn.addSupportIxs('repay',
|
|
357
|
+
await axn.addSupportIxs('repay', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForRepay, useV2Ixs, undefined, initUserMetadata, twoTokenAction);
|
|
349
358
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
350
359
|
if (useV2Ixs) {
|
|
351
360
|
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
@@ -353,9 +362,9 @@ class KaminoAction {
|
|
|
353
362
|
else {
|
|
354
363
|
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
355
364
|
}
|
|
356
|
-
await axn.addInBetweenIxs('repayAndWithdraw',
|
|
365
|
+
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
357
366
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
358
|
-
// Create the scope refresh
|
|
367
|
+
// Create the scope refresh ix in here to ensure it's the first ix in the txn
|
|
359
368
|
const allReserves = new utils_1.PublicKeySet([
|
|
360
369
|
...axn.depositReserves,
|
|
361
370
|
...axn.borrowReserves,
|
|
@@ -369,12 +378,14 @@ class KaminoAction {
|
|
|
369
378
|
}
|
|
370
379
|
return axn;
|
|
371
380
|
}
|
|
372
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
373
|
-
|
|
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,
|
|
374
383
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
384
|
+
initUserMetadata = {
|
|
385
|
+
skipInitialization: false,
|
|
386
|
+
skipLutCreation: false,
|
|
387
|
+
}, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest,
|
|
388
|
+
// Optional customizations which may be needed if the obligation was mutated by some previous ix.
|
|
378
389
|
obligationCustomizations) {
|
|
379
390
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
380
391
|
const addInitObligationForFarm = true;
|
|
@@ -382,7 +393,7 @@ class KaminoAction {
|
|
|
382
393
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
383
394
|
}
|
|
384
395
|
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
385
|
-
await axn.addSupportIxs('withdraw',
|
|
396
|
+
await axn.addSupportIxs('withdraw', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, false, overrideElevationGroupRequest);
|
|
386
397
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
387
398
|
if (useV2Ixs) {
|
|
388
399
|
await axn.addWithdrawIxV2(collateralAmount);
|
|
@@ -402,19 +413,22 @@ class KaminoAction {
|
|
|
402
413
|
* @param obligation - obligation to repay or the PDA seeds
|
|
403
414
|
* @param currentSlot
|
|
404
415
|
* @param payer - if not set then owner is used
|
|
405
|
-
* @param extraComputeBudget - if > 0 then adds the
|
|
406
|
-
* @param
|
|
416
|
+
* @param extraComputeBudget - if > 0 then adds the ix
|
|
417
|
+
* @param includeAtaIxs - if true it includes create and close wsol and token atas
|
|
407
418
|
* @param requestElevationGroup
|
|
408
419
|
* @param includeUserMetadata - if true it includes user metadata
|
|
409
420
|
* @param referrer
|
|
410
421
|
*/
|
|
411
|
-
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 = {
|
|
423
|
+
skipInitialization: false,
|
|
424
|
+
skipLutCreation: false,
|
|
425
|
+
}, referrer = web3_js_1.PublicKey.default) {
|
|
412
426
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
413
427
|
const addInitObligationForFarm = true;
|
|
414
428
|
if (extraComputeBudget > 0) {
|
|
415
429
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
416
430
|
}
|
|
417
|
-
await axn.addSupportIxs('repay',
|
|
431
|
+
await axn.addSupportIxs('repay', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
418
432
|
if (useV2Ixs) {
|
|
419
433
|
await axn.addRepayIxV2();
|
|
420
434
|
}
|
|
@@ -424,16 +438,18 @@ class KaminoAction {
|
|
|
424
438
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
425
439
|
return axn;
|
|
426
440
|
}
|
|
427
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig = undefined, extraComputeBudget = 1_000_000, // if > 0 then adds the
|
|
428
|
-
|
|
429
|
-
requestElevationGroup = false,
|
|
430
|
-
|
|
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
|
|
443
|
+
requestElevationGroup = false, initUserMetadata = {
|
|
444
|
+
skipInitialization: false,
|
|
445
|
+
skipLutCreation: false,
|
|
446
|
+
}, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0) {
|
|
431
447
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
432
448
|
const addInitObligationForFarm = true;
|
|
433
449
|
if (extraComputeBudget > 0) {
|
|
434
450
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
435
451
|
}
|
|
436
|
-
await axn.addSupportIxs('liquidate',
|
|
452
|
+
await axn.addSupportIxs('liquidate', includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata);
|
|
437
453
|
if (useV2Ixs) {
|
|
438
454
|
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
439
455
|
}
|
|
@@ -675,7 +691,8 @@ class KaminoAction {
|
|
|
675
691
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
676
692
|
}, this.kaminoMarket.programId);
|
|
677
693
|
borrowIx.keys =
|
|
678
|
-
|
|
694
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) &&
|
|
695
|
+
(this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
|
|
679
696
|
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
680
697
|
: borrowIx.keys;
|
|
681
698
|
this.lendingIxs.push(borrowIx);
|
|
@@ -716,7 +733,8 @@ class KaminoAction {
|
|
|
716
733
|
farmsProgram: farms_sdk_1.farmsId,
|
|
717
734
|
}, this.kaminoMarket.programId);
|
|
718
735
|
borrowIx.keys =
|
|
719
|
-
|
|
736
|
+
(0, obligation_1.isKaminoObligation)(this.obligation) &&
|
|
737
|
+
(this.obligation.state.elevationGroup > 0 || this.obligation.refreshedStats.potentialElevationGroupUpdate > 0)
|
|
720
738
|
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
721
739
|
: borrowIx.keys;
|
|
722
740
|
this.lendingIxs.push(borrowIx);
|
|
@@ -798,7 +816,9 @@ class KaminoAction {
|
|
|
798
816
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
799
817
|
}, this.kaminoMarket.programId);
|
|
800
818
|
repayIx.keys =
|
|
801
|
-
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;
|
|
802
822
|
this.lendingIxs.push(repayIx);
|
|
803
823
|
}
|
|
804
824
|
async addRepayIxV2() {
|
|
@@ -835,7 +855,10 @@ class KaminoAction {
|
|
|
835
855
|
farmsProgram: farms_sdk_1.farmsId,
|
|
836
856
|
}, this.kaminoMarket.programId);
|
|
837
857
|
repayIx.keys =
|
|
838
|
-
|
|
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;
|
|
839
862
|
this.lendingIxs.push(repayIx);
|
|
840
863
|
}
|
|
841
864
|
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount) {
|
|
@@ -1173,6 +1196,9 @@ class KaminoAction {
|
|
|
1173
1196
|
async addRepayAndWithdrawIxsV2(withdrawCollateralAmount) {
|
|
1174
1197
|
this.lendingIxsLabels.push(`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`);
|
|
1175
1198
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1199
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1200
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1201
|
+
}
|
|
1176
1202
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1177
1203
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1178
1204
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1204,7 +1230,8 @@ class KaminoAction {
|
|
|
1204
1230
|
farmsAccounts: debtFarmsAccounts,
|
|
1205
1231
|
farmsProgram: farms_sdk_1.farmsId,
|
|
1206
1232
|
}, this.kaminoMarket.programId);
|
|
1207
|
-
repayIx.keys =
|
|
1233
|
+
repayIx.keys =
|
|
1234
|
+
this.obligation.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1208
1235
|
this.lendingIxs.push(repayIx);
|
|
1209
1236
|
if (!this.outflowReserve) {
|
|
1210
1237
|
throw new Error(`outflowReserve not set`);
|
|
@@ -1249,6 +1276,9 @@ class KaminoAction {
|
|
|
1249
1276
|
if (!this.outflowReserve) {
|
|
1250
1277
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1251
1278
|
}
|
|
1279
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1280
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1281
|
+
}
|
|
1252
1282
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1253
1283
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1254
1284
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1291,6 +1321,9 @@ class KaminoAction {
|
|
|
1291
1321
|
if (!this.outflowReserve) {
|
|
1292
1322
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1293
1323
|
}
|
|
1324
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1325
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1326
|
+
}
|
|
1294
1327
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1295
1328
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1296
1329
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1351,22 +1384,22 @@ class KaminoAction {
|
|
|
1351
1384
|
: liquidateIx.keys;
|
|
1352
1385
|
this.lendingIxs.push(liquidateIx);
|
|
1353
1386
|
}
|
|
1354
|
-
async addInBetweenIxs(action,
|
|
1355
|
-
await this.addSupportIxsWithoutInitObligation(action,
|
|
1387
|
+
async addInBetweenIxs(action, includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs) {
|
|
1388
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, 'inBetween', requestElevationGroup, addInitObligationForFarm);
|
|
1356
1389
|
}
|
|
1357
1390
|
addRefreshObligation(crank) {
|
|
1358
1391
|
const uniqueReserveAddresses = new utils_1.PublicKeySet(this.depositReserves.concat(this.borrowReserves)).toArray();
|
|
1359
|
-
const
|
|
1392
|
+
const addAllToSetupIxs = 'setup';
|
|
1360
1393
|
// Union of addresses
|
|
1361
1394
|
const allReservesExcludingCurrent = [...uniqueReserveAddresses];
|
|
1362
|
-
this.addRefreshReserveIxs(allReservesExcludingCurrent,
|
|
1363
|
-
this.addRefreshFarmsForReserve(this.depositReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)),
|
|
1364
|
-
this.addRefreshFarmsForReserve(this.borrowReserves.map((r) => this.kaminoMarket.getReserveByAddress(r)),
|
|
1365
|
-
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);
|
|
1366
1399
|
}
|
|
1367
|
-
async addSupportIxsWithoutInitObligation(action,
|
|
1400
|
+
async addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1368
1401
|
// TODO: why are we not doing this first?
|
|
1369
|
-
if (
|
|
1402
|
+
if (includeAtaIxs) {
|
|
1370
1403
|
await this.addAtaIxs(action);
|
|
1371
1404
|
}
|
|
1372
1405
|
if ([
|
|
@@ -1382,18 +1415,18 @@ class KaminoAction {
|
|
|
1382
1415
|
'refreshObligation',
|
|
1383
1416
|
'depositAndWithdraw',
|
|
1384
1417
|
].includes(action)) {
|
|
1385
|
-
// The support
|
|
1386
|
-
// 0. Init obligation
|
|
1387
|
-
// 0. Token Ata
|
|
1418
|
+
// The support ixs in order are:
|
|
1419
|
+
// 0. Init obligation ix
|
|
1420
|
+
// 0. Token Ata ixs
|
|
1388
1421
|
// 0. Init obligation for farm
|
|
1389
|
-
// 1.
|
|
1390
|
-
// 2.
|
|
1391
|
-
// 3.
|
|
1392
|
-
// 4.
|
|
1393
|
-
// 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
|
|
1394
1427
|
// 6. The instruction itself
|
|
1395
|
-
// 7.
|
|
1396
|
-
// 8.
|
|
1428
|
+
// 7. Ix to refresh the `debt` farm of the obligation
|
|
1429
|
+
// 8. Ix to refresh the `collateral` farm of the obligation
|
|
1397
1430
|
let currentReserves = [];
|
|
1398
1431
|
if (action === 'liquidate' ||
|
|
1399
1432
|
action === 'depositAndBorrow' ||
|
|
@@ -1405,7 +1438,7 @@ class KaminoAction {
|
|
|
1405
1438
|
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
1406
1439
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
1407
1440
|
if (action === 'depositAndBorrow') {
|
|
1408
|
-
if (this.obligation) {
|
|
1441
|
+
if ((0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1409
1442
|
const deposit = this.obligation.getDepositByReserve(this.reserve.address);
|
|
1410
1443
|
if (!deposit) {
|
|
1411
1444
|
this.preLoadedDepositReservesSameTx.push(this.reserve.address);
|
|
@@ -1468,6 +1501,9 @@ class KaminoAction {
|
|
|
1468
1501
|
}
|
|
1469
1502
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1470
1503
|
if (action === 'repayAndWithdraw' && addAsSupportIx === 'inBetween') {
|
|
1504
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1505
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1506
|
+
}
|
|
1471
1507
|
const repayObligationLiquidity = this.obligation.getBorrowByReserve(this.reserve.address);
|
|
1472
1508
|
if (!repayObligationLiquidity) {
|
|
1473
1509
|
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
@@ -1482,13 +1518,16 @@ class KaminoAction {
|
|
|
1482
1518
|
}
|
|
1483
1519
|
if (requestElevationGroup) {
|
|
1484
1520
|
if (action === 'repay' || action === 'repayAndWithdrawV2') {
|
|
1485
|
-
|
|
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);
|
|
1486
1525
|
if (!repayObligationLiquidity) {
|
|
1487
1526
|
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
1488
1527
|
}
|
|
1489
1528
|
if (repayObligationLiquidity.amount.lte(new decimal_js_1.default(this.amount.toString())) &&
|
|
1490
1529
|
this.obligation.borrows.size === 1 &&
|
|
1491
|
-
this.obligation
|
|
1530
|
+
this.obligation.state.elevationGroup !== 0) {
|
|
1492
1531
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
|
|
1493
1532
|
// Skip the borrow reserve, since we repay in the same tx
|
|
1494
1533
|
this.addRefreshObligationIx('cleanup', [this.reserve.address]);
|
|
@@ -1511,6 +1550,9 @@ class KaminoAction {
|
|
|
1511
1550
|
addAsSupportIx = 'inBetween';
|
|
1512
1551
|
}
|
|
1513
1552
|
else if (action === 'borrow') {
|
|
1553
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1554
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1555
|
+
}
|
|
1514
1556
|
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1515
1557
|
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1516
1558
|
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
@@ -1530,25 +1572,30 @@ class KaminoAction {
|
|
|
1530
1572
|
});
|
|
1531
1573
|
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
|
|
1532
1574
|
console.log('Setting eModeGroup to', eModeGroup);
|
|
1533
|
-
if (eModeGroup !== 0 &&
|
|
1575
|
+
if (eModeGroup !== 0 &&
|
|
1576
|
+
eModeGroup !== ((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1534
1577
|
newElevationGroup = eModeGroup;
|
|
1535
1578
|
}
|
|
1536
1579
|
}
|
|
1537
1580
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1581
|
+
if (newElevationGroup >= 0 &&
|
|
1582
|
+
newElevationGroup !== ((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1540
1583
|
this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
|
|
1541
1584
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1542
1585
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1543
1586
|
this.addRefreshObligationIx(addAsSupportIx);
|
|
1544
1587
|
if (action === 'borrow') {
|
|
1588
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1589
|
+
throw new Error(`obligation is not a KaminoObligation`);
|
|
1590
|
+
}
|
|
1545
1591
|
this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
|
|
1546
1592
|
}
|
|
1547
1593
|
}
|
|
1548
1594
|
}
|
|
1549
1595
|
else if (action === 'deposit' &&
|
|
1550
1596
|
overrideElevationGroupRequest !== undefined &&
|
|
1551
|
-
overrideElevationGroupRequest !==
|
|
1597
|
+
overrideElevationGroupRequest !==
|
|
1598
|
+
((0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.elevationGroup : 0)) {
|
|
1552
1599
|
const addAsSupportIx = 'setup';
|
|
1553
1600
|
console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
|
|
1554
1601
|
this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
|
|
@@ -1569,7 +1616,7 @@ class KaminoAction {
|
|
|
1569
1616
|
}
|
|
1570
1617
|
if (!useV2Ixs) {
|
|
1571
1618
|
if (addAsSupportIx === 'setup') {
|
|
1572
|
-
// 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
|
|
1573
1620
|
// or the first of a two-token-action
|
|
1574
1621
|
if (action === 'liquidate') {
|
|
1575
1622
|
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Collateral);
|
|
@@ -1591,7 +1638,7 @@ class KaminoAction {
|
|
|
1591
1638
|
else {
|
|
1592
1639
|
// If this is an inbetween, it means it's part of a two-token-action
|
|
1593
1640
|
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1594
|
-
// add added to 'setup'
|
|
1641
|
+
// add added to 'setup' ixs
|
|
1595
1642
|
if (action === 'depositAndBorrow') {
|
|
1596
1643
|
this.addRefreshFarmsForReserve([this.outflowReserve], addAsSupportIx, types_1.ReserveFarmKind.Debt);
|
|
1597
1644
|
}
|
|
@@ -1605,12 +1652,12 @@ class KaminoAction {
|
|
|
1605
1652
|
}
|
|
1606
1653
|
}
|
|
1607
1654
|
}
|
|
1608
|
-
async addSupportIxs(action,
|
|
1655
|
+
async addSupportIxs(action, includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1609
1656
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1610
1657
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1611
|
-
if (!ownerUserMetadata &&
|
|
1658
|
+
if (!ownerUserMetadata && !initUserMetadata.skipInitialization) {
|
|
1612
1659
|
let lookupTable = web3_js_1.PublicKey.default;
|
|
1613
|
-
if (
|
|
1660
|
+
if (!initUserMetadata.skipLutCreation) {
|
|
1614
1661
|
const [createLutIx, lookupTableAddress] = await (0, utils_1.createLookupTableIx)(this.kaminoMarket.getConnection(), this.owner);
|
|
1615
1662
|
lookupTable = lookupTableAddress;
|
|
1616
1663
|
this.setupIxs.push(createLutIx);
|
|
@@ -1620,7 +1667,7 @@ class KaminoAction {
|
|
|
1620
1667
|
}
|
|
1621
1668
|
await this.addInitObligationIxs();
|
|
1622
1669
|
}
|
|
1623
|
-
await this.addSupportIxsWithoutInitObligation(action,
|
|
1670
|
+
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxs, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1624
1671
|
const allReserves = new utils_1.PublicKeySet([
|
|
1625
1672
|
...this.depositReserves,
|
|
1626
1673
|
...this.borrowReserves,
|
|
@@ -1859,7 +1906,7 @@ class KaminoAction {
|
|
|
1859
1906
|
farms.forEach((arg) => {
|
|
1860
1907
|
const args = { mode: arg[0] };
|
|
1861
1908
|
const accounts = {
|
|
1862
|
-
owner: this.obligation ? this.obligation.state.owner : this.owner,
|
|
1909
|
+
owner: (0, obligation_1.isKaminoObligation)(this.obligation) ? this.obligation.state.owner : this.owner,
|
|
1863
1910
|
payer: this.owner,
|
|
1864
1911
|
obligation: this.getObligationPda(),
|
|
1865
1912
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
@@ -1883,21 +1930,21 @@ class KaminoAction {
|
|
|
1883
1930
|
});
|
|
1884
1931
|
}
|
|
1885
1932
|
addInitObligationIxs() {
|
|
1886
|
-
if (!this.obligation) {
|
|
1933
|
+
if (!(0, obligation_1.isKaminoObligation)(this.obligation)) {
|
|
1887
1934
|
const obligationPda = this.getObligationPda();
|
|
1888
1935
|
const [userMetadataAddress, _bump] = (0, utils_1.userMetadataPda)(this.owner, this.kaminoMarket.programId);
|
|
1889
1936
|
const initObligationIx = (0, instructions_1.initObligation)({
|
|
1890
1937
|
args: {
|
|
1891
|
-
tag: this.
|
|
1892
|
-
id: this.
|
|
1938
|
+
tag: this.obligation.toArgs().tag,
|
|
1939
|
+
id: this.obligation.toArgs().id,
|
|
1893
1940
|
},
|
|
1894
1941
|
}, {
|
|
1895
1942
|
obligationOwner: this.owner,
|
|
1896
1943
|
feePayer: this.payer,
|
|
1897
1944
|
obligation: obligationPda,
|
|
1898
1945
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1899
|
-
seed1Account: this.
|
|
1900
|
-
seed2Account: this.
|
|
1946
|
+
seed1Account: this.obligation.toArgs().seed1,
|
|
1947
|
+
seed2Account: this.obligation.toArgs().seed2,
|
|
1901
1948
|
ownerUserMetadata: userMetadataAddress,
|
|
1902
1949
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1903
1950
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
@@ -2011,7 +2058,9 @@ class KaminoAction {
|
|
|
2011
2058
|
return;
|
|
2012
2059
|
}
|
|
2013
2060
|
let safeRepay = new bn_js_1.default(this.amount);
|
|
2014
|
-
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))) {
|
|
2015
2064
|
const borrow = this.obligation.state.borrows.find((borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString());
|
|
2016
2065
|
if (!borrow) {
|
|
2017
2066
|
throw Error(`Unable to find obligation borrow to repay for ${this.obligation.state.owner.toBase58()}`);
|
|
@@ -2118,9 +2167,12 @@ class KaminoAction {
|
|
|
2118
2167
|
: new bn_js_1.default(new decimal_js_1.default(amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
2119
2168
|
}
|
|
2120
2169
|
getObligationPda() {
|
|
2121
|
-
return this.obligation
|
|
2170
|
+
return (0, obligation_1.isKaminoObligation)(this.obligation)
|
|
2122
2171
|
? this.obligation.obligationAddress
|
|
2123
|
-
: this.
|
|
2172
|
+
: this.obligation.toPda(this.kaminoMarket.getAddress(), this.owner);
|
|
2173
|
+
}
|
|
2174
|
+
isObligationInitialized() {
|
|
2175
|
+
return this.obligation instanceof obligation_1.KaminoObligation;
|
|
2124
2176
|
}
|
|
2125
2177
|
getAdditionalDepositReservesList() {
|
|
2126
2178
|
const depositReservesList = this.depositReserves;
|