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