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