@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.3.10-beta.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.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +152 -139
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/configItems.d.ts +1 -6
- package/dist/classes/configItems.d.ts.map +1 -1
- package/dist/classes/configItems.js +1 -93
- package/dist/classes/configItems.js.map +1 -1
- package/dist/classes/farm_utils.d.ts +1 -1
- package/dist/classes/farm_utils.d.ts.map +1 -1
- package/dist/classes/farm_utils.js +3 -1
- package/dist/classes/farm_utils.js.map +1 -1
- package/dist/classes/market.d.ts +15 -10
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +49 -26
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +9 -9
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +48 -50
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts +7 -3
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +31 -43
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +3 -2
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +28 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +103 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/vault_types.d.ts +2 -1
- package/dist/classes/vault_types.d.ts.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/manager/client_kamino_manager.js +0 -2
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/obligation_orders/price_based.js +5 -3
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/Logger.d.ts +14 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +13 -4
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +33 -31
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/dist/utils/validations.d.ts +1 -0
- package/dist/utils/validations.d.ts.map +1 -1
- package/dist/utils/validations.js +5 -0
- package/dist/utils/validations.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +346 -372
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/configItems.ts +1 -99
- package/src/classes/farm_utils.ts +5 -1
- package/src/classes/market.ts +74 -31
- package/src/classes/obligation.ts +54 -53
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +118 -122
- package/src/classes/shared.ts +4 -2
- package/src/classes/vault.ts +160 -7
- package/src/classes/vault_types.ts +2 -1
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/manager/client_kamino_manager.ts +0 -2
- package/src/obligation_orders/price_based.ts +7 -5
- package/src/utils/Logger.ts +14 -0
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/api.ts +56 -33
- package/src/utils/userMetadata.ts +64 -30
- package/src/utils/validations.ts +5 -0
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
removeBudgetIxs,
|
|
29
29
|
uniqueAccountsWithProgramIds,
|
|
30
30
|
WRAPPED_SOL_MINT,
|
|
31
|
+
MultiplyObligationFixedRate,
|
|
32
|
+
LeverageObligationFixedRate,
|
|
31
33
|
} from '../utils';
|
|
32
34
|
import {
|
|
33
35
|
adjustDepositLeverageCalcs,
|
|
@@ -68,8 +70,8 @@ export const WITHDRAW_SLOT_OFFSET = 150; // Offset for the withdraw slot to unde
|
|
|
68
70
|
export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
69
71
|
owner,
|
|
70
72
|
kaminoMarket,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
debtReserveAddress,
|
|
74
|
+
collReserveAddress,
|
|
73
75
|
depositAmount,
|
|
74
76
|
priceDebtToColl,
|
|
75
77
|
slippagePct,
|
|
@@ -90,13 +92,20 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
90
92
|
swapInputs: SwapInputs;
|
|
91
93
|
initialInputs: DepositLeverageInitialInputs<QuoteResponse>;
|
|
92
94
|
}> {
|
|
93
|
-
const collReserve = kaminoMarket.
|
|
94
|
-
const debtReserve = kaminoMarket.
|
|
95
|
-
const
|
|
95
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
96
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
97
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
98
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
99
|
+
const solTokenReserve =
|
|
100
|
+
collReserve.getLiquidityMint() === WRAPPED_SOL_MINT
|
|
101
|
+
? collReserve
|
|
102
|
+
: debtReserve.getLiquidityMint() === WRAPPED_SOL_MINT
|
|
103
|
+
? debtReserve
|
|
104
|
+
: undefined;
|
|
96
105
|
const flashLoanFee = collReserve.getFlashLoanFee() || new Decimal(0);
|
|
97
106
|
|
|
98
|
-
const selectedTokenIsCollToken = selectedTokenMint ===
|
|
99
|
-
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint === solTokenReserve
|
|
107
|
+
const selectedTokenIsCollToken = selectedTokenMint === collReserve.getLiquidityMint();
|
|
108
|
+
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint === solTokenReserve.getLiquidityMint();
|
|
100
109
|
|
|
101
110
|
const calcs = depositLeverageCalcs({
|
|
102
111
|
depositAmount: depositAmount,
|
|
@@ -110,7 +119,12 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
110
119
|
|
|
111
120
|
console.log('Ops Calcs', toJson(calcs));
|
|
112
121
|
|
|
113
|
-
const obligationType = checkObligationType(
|
|
122
|
+
const obligationType = checkObligationType(
|
|
123
|
+
obligationTypeTagOverride,
|
|
124
|
+
collReserve.address,
|
|
125
|
+
debtReserve.address,
|
|
126
|
+
kaminoMarket
|
|
127
|
+
);
|
|
114
128
|
|
|
115
129
|
// Build the repay & withdraw collateral tx to get the number of accounts
|
|
116
130
|
const klendIxs: LeverageIxsOutput = (
|
|
@@ -187,8 +201,8 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
187
201
|
export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
188
202
|
owner,
|
|
189
203
|
kaminoMarket,
|
|
190
|
-
|
|
191
|
-
|
|
204
|
+
debtReserveAddress,
|
|
205
|
+
collReserveAddress,
|
|
192
206
|
depositAmount,
|
|
193
207
|
priceDebtToColl,
|
|
194
208
|
slippagePct,
|
|
@@ -209,8 +223,8 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
209
223
|
const { swapInputs, initialInputs } = await getDepositWithLeverageSwapInputs({
|
|
210
224
|
owner,
|
|
211
225
|
kaminoMarket,
|
|
212
|
-
|
|
213
|
-
|
|
226
|
+
debtReserveAddress,
|
|
227
|
+
collReserveAddress,
|
|
214
228
|
depositAmount,
|
|
215
229
|
priceDebtToColl,
|
|
216
230
|
slippagePct,
|
|
@@ -233,15 +247,20 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
233
247
|
|
|
234
248
|
// Strategy lookup table logic removed
|
|
235
249
|
|
|
236
|
-
const collReserve = kaminoMarket.
|
|
237
|
-
const debtReserve = kaminoMarket.
|
|
238
|
-
const solTokenReserve =
|
|
250
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
251
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
252
|
+
const solTokenReserve =
|
|
253
|
+
collReserve.getLiquidityMint() === WRAPPED_SOL_MINT
|
|
254
|
+
? collReserve
|
|
255
|
+
: debtReserve.getLiquidityMint() === WRAPPED_SOL_MINT
|
|
256
|
+
? debtReserve
|
|
257
|
+
: undefined;
|
|
239
258
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint === solTokenReserve!.getLiquidityMint();
|
|
240
259
|
|
|
241
260
|
const depositWithLeverageIxs = await buildDepositWithLeverageIxs(
|
|
242
261
|
kaminoMarket,
|
|
243
|
-
debtReserve
|
|
244
|
-
collReserve
|
|
262
|
+
debtReserve,
|
|
263
|
+
collReserve,
|
|
245
264
|
owner,
|
|
246
265
|
initialInputs.obligation,
|
|
247
266
|
referrer,
|
|
@@ -338,23 +357,23 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
338
357
|
});
|
|
339
358
|
|
|
340
359
|
// 3. Deposit initial tokens + borrowed tokens into reserve
|
|
341
|
-
const kaminoDepositAndBorrowAction = await KaminoAction.buildDepositAndBorrowTxns(
|
|
342
|
-
market,
|
|
343
|
-
toLamports(calcs.collTokenToDeposit, collReserve.stats.decimals).floor().toString(),
|
|
344
|
-
|
|
345
|
-
toLamports(calcs.debtTokenToBorrow, debtReserve.stats.decimals).ceil().toString(),
|
|
346
|
-
|
|
360
|
+
const kaminoDepositAndBorrowAction = await KaminoAction.buildDepositAndBorrowTxns({
|
|
361
|
+
kaminoMarket: market,
|
|
362
|
+
depositAmount: toLamports(calcs.collTokenToDeposit, collReserve.stats.decimals).floor().toString(),
|
|
363
|
+
depositReserveAddress: collReserve.address,
|
|
364
|
+
borrowAmount: toLamports(calcs.debtTokenToBorrow, debtReserve.stats.decimals).ceil().toString(),
|
|
365
|
+
borrowReserveAddress: debtReserve.address,
|
|
347
366
|
owner,
|
|
348
|
-
obligation!,
|
|
367
|
+
obligation: obligation!,
|
|
349
368
|
useV2Ixs,
|
|
350
|
-
undefined,
|
|
351
|
-
0,
|
|
352
|
-
false,
|
|
353
|
-
elevationGroupOverride === 0 ? false : true, // emode
|
|
354
|
-
{ skipInitialization: true, skipLutCreation: true }, // to be checked and created in a setup tx in the UI
|
|
369
|
+
scopeRefreshConfig: undefined,
|
|
370
|
+
extraComputeBudget: 0,
|
|
371
|
+
includeAtaIxs: false,
|
|
372
|
+
requestElevationGroup: elevationGroupOverride === 0 ? false : true, // emode
|
|
373
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // to be checked and created in a setup tx in the UI
|
|
355
374
|
referrer,
|
|
356
|
-
currentSlot
|
|
357
|
-
);
|
|
375
|
+
currentSlot,
|
|
376
|
+
});
|
|
358
377
|
|
|
359
378
|
return swapQuoteIxsArray.map((swapQuoteIxs) => {
|
|
360
379
|
// 4. Swap
|
|
@@ -385,8 +404,8 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
385
404
|
export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
386
405
|
owner,
|
|
387
406
|
kaminoMarket,
|
|
388
|
-
|
|
389
|
-
|
|
407
|
+
debtReserveAddress,
|
|
408
|
+
collReserveAddress,
|
|
390
409
|
deposited,
|
|
391
410
|
borrowed,
|
|
392
411
|
obligation,
|
|
@@ -408,17 +427,19 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
408
427
|
flashLoanInfo: FlashLoanInfo;
|
|
409
428
|
initialInputs: WithdrawLeverageInitialInputs<QuoteResponse>;
|
|
410
429
|
}> {
|
|
411
|
-
const collReserve = kaminoMarket.
|
|
412
|
-
const debtReserve = kaminoMarket.
|
|
430
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
431
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
432
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
433
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
413
434
|
const flashLoanFee = debtReserve!.getFlashLoanFee() || new Decimal(0);
|
|
414
|
-
const selectedTokenIsCollToken = selectedTokenMint ===
|
|
435
|
+
const selectedTokenIsCollToken = selectedTokenMint === collReserve.getLiquidityMint();
|
|
415
436
|
|
|
416
437
|
const inputTokenIsSol = selectedTokenMint === WRAPPED_SOL_MINT;
|
|
417
438
|
|
|
418
439
|
const calcs = withdrawLeverageCalcs(
|
|
419
440
|
kaminoMarket,
|
|
420
|
-
collReserve
|
|
421
|
-
debtReserve
|
|
441
|
+
collReserve,
|
|
442
|
+
debtReserve,
|
|
422
443
|
priceCollToDebt,
|
|
423
444
|
withdrawAmount,
|
|
424
445
|
deposited,
|
|
@@ -435,8 +456,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
435
456
|
const klendIxs = (
|
|
436
457
|
await buildWithdrawWithLeverageIxs(
|
|
437
458
|
kaminoMarket,
|
|
438
|
-
debtReserve
|
|
439
|
-
collReserve
|
|
459
|
+
debtReserve,
|
|
460
|
+
collReserve,
|
|
440
461
|
owner,
|
|
441
462
|
obligation,
|
|
442
463
|
referrer,
|
|
@@ -514,8 +535,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
514
535
|
export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
515
536
|
owner,
|
|
516
537
|
kaminoMarket,
|
|
517
|
-
|
|
518
|
-
|
|
538
|
+
debtReserveAddress,
|
|
539
|
+
collReserveAddress,
|
|
519
540
|
obligation,
|
|
520
541
|
deposited,
|
|
521
542
|
borrowed,
|
|
@@ -534,15 +555,15 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
534
555
|
useV2Ixs,
|
|
535
556
|
userSolBalanceLamports,
|
|
536
557
|
}: WithdrawWithLeverageProps<QuoteResponse>): Promise<Array<WithdrawLeverageIxsResponse<QuoteResponse>>> {
|
|
537
|
-
const collReserve = kaminoMarket.
|
|
538
|
-
const debtReserve = kaminoMarket.
|
|
558
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
559
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
539
560
|
|
|
540
561
|
const inputTokenIsSol = selectedTokenMint === WRAPPED_SOL_MINT;
|
|
541
562
|
const { swapInputs, initialInputs } = await getWithdrawWithLeverageSwapInputs({
|
|
542
563
|
owner,
|
|
543
564
|
kaminoMarket,
|
|
544
|
-
|
|
545
|
-
|
|
565
|
+
debtReserveAddress,
|
|
566
|
+
collReserveAddress,
|
|
546
567
|
deposited,
|
|
547
568
|
borrowed,
|
|
548
569
|
obligation,
|
|
@@ -569,8 +590,8 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
569
590
|
|
|
570
591
|
const withdrawWithLeverageIxs = await buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
571
592
|
kaminoMarket,
|
|
572
|
-
debtReserve
|
|
573
|
-
collReserve
|
|
593
|
+
debtReserve,
|
|
594
|
+
collReserve,
|
|
574
595
|
owner,
|
|
575
596
|
obligation,
|
|
576
597
|
referrer,
|
|
@@ -687,25 +708,27 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
687
708
|
});
|
|
688
709
|
|
|
689
710
|
// 3. Repay borrowed tokens and Withdraw tokens from reserve that will be swapped to repay flash loan
|
|
690
|
-
const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
|
|
691
|
-
market,
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
711
|
+
const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns({
|
|
712
|
+
kaminoMarket: market,
|
|
713
|
+
repayAmount: isClosingPosition
|
|
714
|
+
? U64_MAX
|
|
715
|
+
: toLamports(calcs.repayAmount, debtReserve.stats.decimals).floor().toString(),
|
|
716
|
+
repayReserveAddress: debtReserve.address,
|
|
717
|
+
withdrawAmount: isClosingPosition
|
|
695
718
|
? U64_MAX
|
|
696
719
|
: toLamports(calcs.depositTokenWithdrawAmount, collReserve!.stats.decimals).ceil().toString(),
|
|
697
|
-
|
|
698
|
-
owner,
|
|
720
|
+
withdrawReserveAddress: collReserve.address,
|
|
721
|
+
payer: owner,
|
|
699
722
|
currentSlot,
|
|
700
723
|
obligation,
|
|
701
724
|
useV2Ixs,
|
|
702
|
-
undefined,
|
|
703
|
-
0,
|
|
704
|
-
false,
|
|
705
|
-
false,
|
|
706
|
-
{ skipInitialization: true, skipLutCreation: true }, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
707
|
-
referrer
|
|
708
|
-
);
|
|
725
|
+
scopeRefreshConfig: undefined,
|
|
726
|
+
extraComputeBudget: 0,
|
|
727
|
+
includeAtaIxs: false,
|
|
728
|
+
requestElevationGroup: false,
|
|
729
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
730
|
+
referrer,
|
|
731
|
+
});
|
|
709
732
|
|
|
710
733
|
return swapQuoteIxsArray.map((swapQuoteIxs) => {
|
|
711
734
|
const swapInstructions = removeBudgetIxs(swapQuoteIxs.swapIxs);
|
|
@@ -733,8 +756,8 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
733
756
|
export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
734
757
|
owner,
|
|
735
758
|
kaminoMarket,
|
|
736
|
-
|
|
737
|
-
|
|
759
|
+
debtReserveAddress,
|
|
760
|
+
collReserveAddress,
|
|
738
761
|
obligation,
|
|
739
762
|
depositedLamports,
|
|
740
763
|
borrowedLamports,
|
|
@@ -756,8 +779,10 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
756
779
|
flashLoanInfo: FlashLoanInfo;
|
|
757
780
|
initialInputs: AdjustLeverageInitialInputs<QuoteResponse>;
|
|
758
781
|
}> {
|
|
759
|
-
const collReserve = kaminoMarket.
|
|
760
|
-
const debtReserve = kaminoMarket.
|
|
782
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
783
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
784
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
785
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
761
786
|
const deposited = fromLamports(depositedLamports, collReserve.stats.decimals);
|
|
762
787
|
const borrowed = fromLamports(borrowedLamports, debtReserve.stats.decimals);
|
|
763
788
|
|
|
@@ -799,8 +824,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
799
824
|
await buildIncreaseLeverageIxs(
|
|
800
825
|
owner,
|
|
801
826
|
kaminoMarket,
|
|
802
|
-
|
|
803
|
-
|
|
827
|
+
collReserveAddress,
|
|
828
|
+
debtReserveAddress,
|
|
804
829
|
obligation,
|
|
805
830
|
referrer,
|
|
806
831
|
currentSlot,
|
|
@@ -880,8 +905,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
880
905
|
await buildDecreaseLeverageIxs(
|
|
881
906
|
owner,
|
|
882
907
|
kaminoMarket,
|
|
883
|
-
|
|
884
|
-
|
|
908
|
+
collReserveAddress,
|
|
909
|
+
debtReserveAddress,
|
|
885
910
|
obligation,
|
|
886
911
|
referrer,
|
|
887
912
|
currentSlot,
|
|
@@ -966,8 +991,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
966
991
|
export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
967
992
|
owner,
|
|
968
993
|
kaminoMarket,
|
|
969
|
-
|
|
970
|
-
|
|
994
|
+
debtReserveAddress,
|
|
995
|
+
collReserveAddress,
|
|
971
996
|
obligation,
|
|
972
997
|
depositedLamports,
|
|
973
998
|
borrowedLamports,
|
|
@@ -989,8 +1014,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
989
1014
|
const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
|
|
990
1015
|
owner,
|
|
991
1016
|
kaminoMarket,
|
|
992
|
-
|
|
993
|
-
|
|
1017
|
+
debtReserveAddress,
|
|
1018
|
+
collReserveAddress,
|
|
994
1019
|
obligation,
|
|
995
1020
|
depositedLamports,
|
|
996
1021
|
borrowedLamports,
|
|
@@ -1017,8 +1042,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1017
1042
|
const increaseLeverageIxs = await buildIncreaseLeverageIxs(
|
|
1018
1043
|
owner,
|
|
1019
1044
|
kaminoMarket,
|
|
1020
|
-
|
|
1021
|
-
|
|
1045
|
+
collReserveAddress,
|
|
1046
|
+
debtReserveAddress,
|
|
1022
1047
|
obligation,
|
|
1023
1048
|
referrer,
|
|
1024
1049
|
currentSlot,
|
|
@@ -1056,8 +1081,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1056
1081
|
const decreaseLeverageIxs = await buildDecreaseLeverageIxs(
|
|
1057
1082
|
owner,
|
|
1058
1083
|
kaminoMarket,
|
|
1059
|
-
|
|
1060
|
-
|
|
1084
|
+
collReserveAddress,
|
|
1085
|
+
debtReserveAddress,
|
|
1061
1086
|
obligation,
|
|
1062
1087
|
referrer,
|
|
1063
1088
|
currentSlot,
|
|
@@ -1096,8 +1121,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1096
1121
|
async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
1097
1122
|
owner: TransactionSigner,
|
|
1098
1123
|
kaminoMarket: KaminoMarket,
|
|
1099
|
-
|
|
1100
|
-
|
|
1124
|
+
collReserveAddress: Address,
|
|
1125
|
+
debtReserveAddress: Address,
|
|
1101
1126
|
obligation: KaminoObligation,
|
|
1102
1127
|
referrer: Option<Address>,
|
|
1103
1128
|
currentSlot: Slot,
|
|
@@ -1107,8 +1132,10 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1107
1132
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
1108
1133
|
useV2Ixs: boolean
|
|
1109
1134
|
): Promise<LeverageIxsOutput[]> {
|
|
1110
|
-
const collReserve = kaminoMarket.
|
|
1111
|
-
const
|
|
1135
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
1136
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
1137
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
1138
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
1112
1139
|
const collTokenAta = await getAssociatedTokenAddress(
|
|
1113
1140
|
collTokenMint,
|
|
1114
1141
|
owner.address,
|
|
@@ -1140,38 +1167,38 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1140
1167
|
programId: kaminoMarket.programId,
|
|
1141
1168
|
});
|
|
1142
1169
|
|
|
1143
|
-
const depositAction = await KaminoAction.buildDepositTxns(
|
|
1170
|
+
const depositAction = await KaminoAction.buildDepositTxns({
|
|
1144
1171
|
kaminoMarket,
|
|
1145
|
-
toLamports(calcs.adjustDepositPosition, collReserve
|
|
1146
|
-
|
|
1172
|
+
amount: toLamports(calcs.adjustDepositPosition, collReserve.stats.decimals).floor().toString(),
|
|
1173
|
+
reserveAddress: collReserve.address,
|
|
1147
1174
|
owner,
|
|
1148
1175
|
obligation,
|
|
1149
1176
|
useV2Ixs,
|
|
1150
|
-
undefined,
|
|
1151
|
-
0,
|
|
1152
|
-
false,
|
|
1153
|
-
false,
|
|
1154
|
-
{ skipInitialization: true, skipLutCreation: true },
|
|
1177
|
+
scopeRefreshConfig: undefined,
|
|
1178
|
+
extraComputeBudget: 0,
|
|
1179
|
+
includeAtaIxs: false,
|
|
1180
|
+
requestElevationGroup: false,
|
|
1181
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true },
|
|
1155
1182
|
referrer,
|
|
1156
|
-
currentSlot
|
|
1157
|
-
);
|
|
1183
|
+
currentSlot,
|
|
1184
|
+
});
|
|
1158
1185
|
|
|
1159
1186
|
// 4. Borrow tokens in borrow token reserve that will be swapped to repay flash loan
|
|
1160
|
-
const borrowAction = await KaminoAction.buildBorrowTxns(
|
|
1187
|
+
const borrowAction = await KaminoAction.buildBorrowTxns({
|
|
1161
1188
|
kaminoMarket,
|
|
1162
|
-
toLamports(calcs.borrowAmount, debtReserve
|
|
1163
|
-
|
|
1189
|
+
amount: toLamports(calcs.borrowAmount, debtReserve.stats.decimals).ceil().toString(),
|
|
1190
|
+
reserveAddress: debtReserve.address,
|
|
1164
1191
|
owner,
|
|
1165
1192
|
obligation,
|
|
1166
1193
|
useV2Ixs,
|
|
1167
|
-
undefined,
|
|
1168
|
-
0,
|
|
1169
|
-
false,
|
|
1170
|
-
false,
|
|
1171
|
-
{ skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1194
|
+
scopeRefreshConfig: undefined,
|
|
1195
|
+
extraComputeBudget: 0,
|
|
1196
|
+
includeAtaIxs: false,
|
|
1197
|
+
requestElevationGroup: false,
|
|
1198
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1172
1199
|
referrer,
|
|
1173
|
-
currentSlot
|
|
1174
|
-
);
|
|
1200
|
+
currentSlot,
|
|
1201
|
+
});
|
|
1175
1202
|
|
|
1176
1203
|
return swapQuoteIxsArray.map((swapQuoteIxs) => {
|
|
1177
1204
|
const swapInstructions = removeBudgetIxs(swapQuoteIxs.swapIxs);
|
|
@@ -1206,8 +1233,8 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1206
1233
|
async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
1207
1234
|
owner: TransactionSigner,
|
|
1208
1235
|
kaminoMarket: KaminoMarket,
|
|
1209
|
-
|
|
1210
|
-
|
|
1236
|
+
collReserveAddress: Address,
|
|
1237
|
+
debtReserveAddress: Address,
|
|
1211
1238
|
obligation: KaminoObligation,
|
|
1212
1239
|
referrer: Option<Address>,
|
|
1213
1240
|
currentSlot: Slot,
|
|
@@ -1219,8 +1246,10 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1219
1246
|
withdrawSlotOffset: number = WITHDRAW_SLOT_OFFSET,
|
|
1220
1247
|
userSolBalanceLamports: number
|
|
1221
1248
|
): Promise<LeverageIxsOutput[]> {
|
|
1222
|
-
const collReserve = kaminoMarket.
|
|
1223
|
-
const debtReserve = kaminoMarket.
|
|
1249
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
1250
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
1251
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
1252
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
1224
1253
|
const [debtTokenAta] = await findAssociatedTokenPda({
|
|
1225
1254
|
owner: owner.address,
|
|
1226
1255
|
mint: debtTokenMint,
|
|
@@ -1282,40 +1311,40 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1282
1311
|
});
|
|
1283
1312
|
|
|
1284
1313
|
// 4. Actually do the repay of the flash borrowed amounts
|
|
1285
|
-
const repayAction = await KaminoAction.buildRepayTxns(
|
|
1314
|
+
const repayAction = await KaminoAction.buildRepayTxns({
|
|
1286
1315
|
kaminoMarket,
|
|
1287
|
-
toLamports(Decimal.abs(calcs.adjustBorrowPosition), debtReserve!.stats.decimals).floor().toString(),
|
|
1288
|
-
|
|
1316
|
+
amount: toLamports(Decimal.abs(calcs.adjustBorrowPosition), debtReserve!.stats.decimals).floor().toString(),
|
|
1317
|
+
reserveAddress: debtReserve.address,
|
|
1289
1318
|
owner,
|
|
1290
1319
|
obligation,
|
|
1291
1320
|
useV2Ixs,
|
|
1292
|
-
undefined,
|
|
1321
|
+
scopeRefreshConfig: undefined,
|
|
1293
1322
|
currentSlot,
|
|
1294
|
-
undefined,
|
|
1295
|
-
0,
|
|
1296
|
-
false,
|
|
1297
|
-
false,
|
|
1298
|
-
{ skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1299
|
-
referrer
|
|
1300
|
-
);
|
|
1323
|
+
payer: undefined,
|
|
1324
|
+
extraComputeBudget: 0,
|
|
1325
|
+
includeAtaIxs: false,
|
|
1326
|
+
requestElevationGroup: false,
|
|
1327
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1328
|
+
referrer,
|
|
1329
|
+
});
|
|
1301
1330
|
|
|
1302
1331
|
const withdrawSlot = currentSlot - BigInt(withdrawSlotOffset);
|
|
1303
1332
|
// 6. Withdraw collateral (a little bit more to be able to pay for the slippage on swap)
|
|
1304
|
-
const withdrawAction = await KaminoAction.buildWithdrawTxns(
|
|
1333
|
+
const withdrawAction = await KaminoAction.buildWithdrawTxns({
|
|
1305
1334
|
kaminoMarket,
|
|
1306
|
-
toLamports(calcs.withdrawAmountWithSlippageAndFlashLoanFee, collReserve!.stats.decimals).ceil().toString(),
|
|
1307
|
-
|
|
1335
|
+
amount: toLamports(calcs.withdrawAmountWithSlippageAndFlashLoanFee, collReserve!.stats.decimals).ceil().toString(),
|
|
1336
|
+
reserveAddress: collReserve.address,
|
|
1308
1337
|
owner,
|
|
1309
1338
|
obligation,
|
|
1310
1339
|
useV2Ixs,
|
|
1311
|
-
undefined,
|
|
1312
|
-
0,
|
|
1313
|
-
false,
|
|
1314
|
-
false,
|
|
1315
|
-
{ skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1340
|
+
scopeRefreshConfig: undefined,
|
|
1341
|
+
extraComputeBudget: 0,
|
|
1342
|
+
includeAtaIxs: false,
|
|
1343
|
+
requestElevationGroup: false,
|
|
1344
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
1316
1345
|
referrer,
|
|
1317
|
-
withdrawSlot
|
|
1318
|
-
);
|
|
1346
|
+
currentSlot: withdrawSlot,
|
|
1347
|
+
});
|
|
1319
1348
|
|
|
1320
1349
|
return swapQuoteIxsArray.map((swapQuoteIxs) => {
|
|
1321
1350
|
const swapInstructions = removeBudgetIxs(swapQuoteIxs.swapIxs);
|
|
@@ -1404,10 +1433,14 @@ export const getScopeRefreshIxForObligationAndReserves = async (
|
|
|
1404
1433
|
|
|
1405
1434
|
const checkObligationType = (
|
|
1406
1435
|
obligationTypeTag: ObligationTypeTag,
|
|
1407
|
-
|
|
1408
|
-
|
|
1436
|
+
collReserveAddress: Address,
|
|
1437
|
+
debtReserveAddress: Address,
|
|
1409
1438
|
kaminoMarket: KaminoMarket
|
|
1410
1439
|
) => {
|
|
1440
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
1441
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
1442
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
1443
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
1411
1444
|
let obligationType: ObligationType;
|
|
1412
1445
|
if (obligationTypeTag === ObligationTypeTag.Multiply) {
|
|
1413
1446
|
// multiply
|
|
@@ -1415,6 +1448,12 @@ const checkObligationType = (
|
|
|
1415
1448
|
} else if (obligationTypeTag === ObligationTypeTag.Leverage) {
|
|
1416
1449
|
// leverage
|
|
1417
1450
|
obligationType = new LeverageObligation(collTokenMint, debtTokenMint, kaminoMarket.programId);
|
|
1451
|
+
} else if (obligationTypeTag === ObligationTypeTag.MultiplyFixedRate) {
|
|
1452
|
+
// multiply fixed rate
|
|
1453
|
+
obligationType = new MultiplyObligationFixedRate(collReserveAddress, debtReserveAddress, kaminoMarket.programId);
|
|
1454
|
+
} else if (obligationTypeTag === ObligationTypeTag.LeverageFixedRate) {
|
|
1455
|
+
// leverage fixed rate
|
|
1456
|
+
obligationType = new LeverageObligationFixedRate(collReserveAddress, debtReserveAddress, kaminoMarket.programId);
|
|
1418
1457
|
} else {
|
|
1419
1458
|
throw Error('Obligation type tag not supported for leverage, please use 1 - multiply or 3 - leverage');
|
|
1420
1459
|
}
|
package/src/leverage/types.ts
CHANGED
|
@@ -65,8 +65,8 @@ export type LeverageInitialInputs<LeverageCalcsResult, QuoteResponse> = {
|
|
|
65
65
|
export interface BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
66
66
|
owner: TransactionSigner;
|
|
67
67
|
kaminoMarket: KaminoMarket;
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
debtReserveAddress: Address;
|
|
69
|
+
collReserveAddress: Address;
|
|
70
70
|
referrer: Option<Address>;
|
|
71
71
|
currentSlot: Slot;
|
|
72
72
|
slippagePct: Decimal;
|
|
@@ -537,7 +537,6 @@ async function main() {
|
|
|
537
537
|
signer,
|
|
538
538
|
[
|
|
539
539
|
instructions.updateVaultConfigIx,
|
|
540
|
-
...instructions.updateLUTIxs,
|
|
541
540
|
...getPriorityFeeAndCuIxs({
|
|
542
541
|
priorityFeeMultiplier: 2500,
|
|
543
542
|
}),
|
|
@@ -1421,7 +1420,6 @@ async function main() {
|
|
|
1421
1420
|
);
|
|
1422
1421
|
const txInstructions = [
|
|
1423
1422
|
instructions.updateReserveAllocationIx,
|
|
1424
|
-
...instructions.updateLUTIxs,
|
|
1425
1423
|
...getPriorityFeeAndCuIxs({
|
|
1426
1424
|
priorityFeeMultiplier: 2500,
|
|
1427
1425
|
}),
|
|
@@ -246,10 +246,12 @@ function collectReserveAddresses(
|
|
|
246
246
|
symbolOrMintAddresses: SymbolOrMintAddress[]
|
|
247
247
|
): Set<Address> {
|
|
248
248
|
return new Set<Address>(
|
|
249
|
-
symbolOrMintAddresses
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
symbolOrMintAddresses
|
|
250
|
+
.map((symbolOrMintAddress) =>
|
|
251
|
+
typeof symbolOrMintAddress === 'string'
|
|
252
|
+
? kaminoMarket.getExistingReservesBySymbol(symbolOrMintAddress).map((r) => r.address)
|
|
253
|
+
: kaminoMarket.getExistingReservesByMint(symbolOrMintAddress).map((r) => r.address)
|
|
254
|
+
)
|
|
255
|
+
.flat()
|
|
254
256
|
);
|
|
255
257
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
info(message: string, ...args: any[]): void;
|
|
3
|
+
warn(message: string, ...args: any[]): void;
|
|
4
|
+
error(message: string, ...args: any[]): void;
|
|
5
|
+
debug(message: string, ...args: any[]): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum LogLevel {
|
|
9
|
+
INFO = 'info',
|
|
10
|
+
WARN = 'warn',
|
|
11
|
+
ERROR = 'error',
|
|
12
|
+
DEBUG = 'debug',
|
|
13
|
+
NONE = 'none',
|
|
14
|
+
}
|