@kamino-finance/klend-sdk 7.1.5 → 7.1.7
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/manager.d.ts +2 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +3 -2
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/vault.d.ts +2 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +9 -5
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +6 -7
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +1 -2
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +3 -4
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +1 -1
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +9 -10
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +39 -42
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/manager/tx/ManagerEnv.js +1 -1
- package/dist/manager/tx/ManagerEnv.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +1 -0
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/manager.ts +3 -2
- package/src/classes/vault.ts +14 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +7 -11
- package/src/lending_operations/swap_collateral_operations.ts +6 -21
- package/src/leverage/calcs.ts +2 -2
- package/src/leverage/operations.ts +48 -65
- package/src/leverage/types.ts +4 -2
- package/src/manager/tx/ManagerEnv.ts +1 -1
- package/src/utils/userMetadata.ts +1 -0
|
@@ -79,7 +79,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
79
79
|
targetLeverage,
|
|
80
80
|
selectedTokenMint,
|
|
81
81
|
obligationTypeTagOverride,
|
|
82
|
-
|
|
82
|
+
scopeRefreshIx,
|
|
83
83
|
budgetAndPriorityFeeIxs,
|
|
84
84
|
quoteBufferBps,
|
|
85
85
|
quoter,
|
|
@@ -123,7 +123,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
123
123
|
referrer,
|
|
124
124
|
currentSlot,
|
|
125
125
|
depositTokenIsSol,
|
|
126
|
-
|
|
126
|
+
scopeRefreshIx,
|
|
127
127
|
calcs,
|
|
128
128
|
budgetAndPriorityFeeIxs,
|
|
129
129
|
[
|
|
@@ -198,7 +198,7 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
198
198
|
targetLeverage,
|
|
199
199
|
selectedTokenMint,
|
|
200
200
|
obligationTypeTagOverride,
|
|
201
|
-
|
|
201
|
+
scopeRefreshIx,
|
|
202
202
|
budgetAndPriorityFeeIxs,
|
|
203
203
|
quoteBufferBps,
|
|
204
204
|
quoter,
|
|
@@ -220,7 +220,7 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
220
220
|
targetLeverage,
|
|
221
221
|
selectedTokenMint,
|
|
222
222
|
obligationTypeTagOverride,
|
|
223
|
-
|
|
223
|
+
scopeRefreshIx,
|
|
224
224
|
budgetAndPriorityFeeIxs,
|
|
225
225
|
quoteBufferBps,
|
|
226
226
|
quoter,
|
|
@@ -247,7 +247,7 @@ export async function getDepositWithLeverageIxs<QuoteResponse>({
|
|
|
247
247
|
referrer,
|
|
248
248
|
currentSlot,
|
|
249
249
|
depositTokenIsSol,
|
|
250
|
-
|
|
250
|
+
scopeRefreshIx,
|
|
251
251
|
initialInputs.calcs,
|
|
252
252
|
budgetAndPriorityFeeIxs,
|
|
253
253
|
swapsArray.map((swap) => {
|
|
@@ -283,7 +283,7 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
283
283
|
referrer: Option<Address>,
|
|
284
284
|
currentSlot: Slot,
|
|
285
285
|
depositTokenIsSol: boolean,
|
|
286
|
-
|
|
286
|
+
scopeRefreshIx: Instruction[],
|
|
287
287
|
calcs: DepositLeverageCalcsResult,
|
|
288
288
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
289
289
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
@@ -301,15 +301,12 @@ async function buildDepositWithLeverageIxs<QuoteResponse>(
|
|
|
301
301
|
]);
|
|
302
302
|
|
|
303
303
|
// 1. Create atas & budget ixs
|
|
304
|
-
const { budgetIxs, createAtasIxs
|
|
304
|
+
const { budgetIxs, createAtasIxs } = await getSetupIxs(
|
|
305
305
|
owner,
|
|
306
|
-
market,
|
|
307
|
-
obligation,
|
|
308
306
|
collTokenMint,
|
|
309
307
|
collReserve,
|
|
310
308
|
debtTokenMint,
|
|
311
309
|
debtReserve,
|
|
312
|
-
scopeRefreshConfig,
|
|
313
310
|
budgetAndPriorityFeeIxs
|
|
314
311
|
);
|
|
315
312
|
|
|
@@ -402,10 +399,11 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
402
399
|
isClosingPosition,
|
|
403
400
|
selectedTokenMint,
|
|
404
401
|
budgetAndPriorityFeeIxs,
|
|
405
|
-
|
|
402
|
+
scopeRefreshIx,
|
|
406
403
|
quoteBufferBps,
|
|
407
404
|
quoter,
|
|
408
405
|
useV2Ixs,
|
|
406
|
+
userSolBalanceLamports,
|
|
409
407
|
}: WithdrawWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
410
408
|
swapInputs: SwapInputs;
|
|
411
409
|
flashLoanInfo: FlashLoanInfo;
|
|
@@ -446,7 +444,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
446
444
|
currentSlot,
|
|
447
445
|
isClosingPosition,
|
|
448
446
|
inputTokenIsSol,
|
|
449
|
-
|
|
447
|
+
scopeRefreshIx,
|
|
450
448
|
calcs,
|
|
451
449
|
budgetAndPriorityFeeIxs,
|
|
452
450
|
[
|
|
@@ -460,7 +458,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
460
458
|
},
|
|
461
459
|
},
|
|
462
460
|
],
|
|
463
|
-
useV2Ixs
|
|
461
|
+
useV2Ixs,
|
|
462
|
+
userSolBalanceLamports
|
|
464
463
|
)
|
|
465
464
|
)[0];
|
|
466
465
|
|
|
@@ -529,11 +528,12 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
529
528
|
isClosingPosition,
|
|
530
529
|
selectedTokenMint,
|
|
531
530
|
budgetAndPriorityFeeIxs,
|
|
532
|
-
|
|
531
|
+
scopeRefreshIx,
|
|
533
532
|
quoteBufferBps,
|
|
534
533
|
quoter,
|
|
535
534
|
swapper,
|
|
536
535
|
useV2Ixs,
|
|
536
|
+
userSolBalanceLamports,
|
|
537
537
|
}: WithdrawWithLeverageProps<QuoteResponse>): Promise<Array<WithdrawLeverageIxsResponse<QuoteResponse>>> {
|
|
538
538
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
539
539
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
@@ -555,10 +555,11 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
555
555
|
isClosingPosition,
|
|
556
556
|
selectedTokenMint,
|
|
557
557
|
budgetAndPriorityFeeIxs,
|
|
558
|
-
|
|
558
|
+
scopeRefreshIx,
|
|
559
559
|
quoteBufferBps,
|
|
560
560
|
quoter,
|
|
561
561
|
useV2Ixs,
|
|
562
|
+
userSolBalanceLamports,
|
|
562
563
|
});
|
|
563
564
|
|
|
564
565
|
const withdrawSwapper: SwapIxsProvider<QuoteResponse> = swapper;
|
|
@@ -577,7 +578,7 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
577
578
|
currentSlot,
|
|
578
579
|
isClosingPosition,
|
|
579
580
|
inputTokenIsSol,
|
|
580
|
-
|
|
581
|
+
scopeRefreshIx,
|
|
581
582
|
initialInputs.calcs,
|
|
582
583
|
budgetAndPriorityFeeIxs,
|
|
583
584
|
swapsArray.map((swap) => {
|
|
@@ -588,7 +589,8 @@ export async function getWithdrawWithLeverageIxs<QuoteResponse>({
|
|
|
588
589
|
quote: swap.quote,
|
|
589
590
|
};
|
|
590
591
|
}),
|
|
591
|
-
useV2Ixs
|
|
592
|
+
useV2Ixs,
|
|
593
|
+
userSolBalanceLamports
|
|
592
594
|
);
|
|
593
595
|
|
|
594
596
|
// Send ixs and lookup tables
|
|
@@ -614,11 +616,12 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
614
616
|
currentSlot: Slot,
|
|
615
617
|
isClosingPosition: boolean,
|
|
616
618
|
depositTokenIsSol: boolean,
|
|
617
|
-
|
|
619
|
+
scopeRefreshIx: Instruction[],
|
|
618
620
|
calcs: WithdrawLeverageCalcsResult,
|
|
619
621
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
620
622
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
621
|
-
useV2Ixs: boolean
|
|
623
|
+
useV2Ixs: boolean,
|
|
624
|
+
userSolBalanceLamports: number
|
|
622
625
|
): Promise<LeverageIxsOutput[]> {
|
|
623
626
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
624
627
|
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
@@ -629,15 +632,12 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
629
632
|
);
|
|
630
633
|
// 1. Create atas & budget txns & user metadata
|
|
631
634
|
|
|
632
|
-
const { budgetIxs, createAtasIxs
|
|
635
|
+
const { budgetIxs, createAtasIxs } = await getSetupIxs(
|
|
633
636
|
owner,
|
|
634
|
-
market,
|
|
635
|
-
obligation,
|
|
636
637
|
collTokenMint,
|
|
637
638
|
collReserve,
|
|
638
639
|
debtTokenMint,
|
|
639
640
|
debtReserve,
|
|
640
|
-
scopeRefreshConfig,
|
|
641
641
|
budgetAndPriorityFeeIxs
|
|
642
642
|
);
|
|
643
643
|
|
|
@@ -660,8 +660,7 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
660
660
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
661
661
|
const fillWsolAtaIxs: Instruction[] = [];
|
|
662
662
|
if (debtTokenMint === WRAPPED_SOL_MINT) {
|
|
663
|
-
const halfSolBalance =
|
|
664
|
-
Number.parseInt((await market.getRpc().getBalance(owner.address).send()).value.toString()) / LAMPORTS_PER_SOL / 2;
|
|
663
|
+
const halfSolBalance = userSolBalanceLamports / LAMPORTS_PER_SOL / 2;
|
|
665
664
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
666
665
|
fillWsolAtaIxs.push(
|
|
667
666
|
...getTransferWsolIxs(
|
|
@@ -684,7 +683,6 @@ export async function buildWithdrawWithLeverageIxs<QuoteResponse>(
|
|
|
684
683
|
reserve: debtReserve!,
|
|
685
684
|
amountLamports: toLamports(calcs.repayAmount, debtReserve!.stats.decimals),
|
|
686
685
|
destinationAta: debtTokenAta,
|
|
687
|
-
// TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
|
|
688
686
|
referrerAccount: none(),
|
|
689
687
|
referrerTokenState: none(),
|
|
690
688
|
programId: market.programId,
|
|
@@ -749,11 +747,12 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
749
747
|
priceDebtToColl,
|
|
750
748
|
slippagePct,
|
|
751
749
|
budgetAndPriorityFeeIxs,
|
|
752
|
-
|
|
750
|
+
scopeRefreshIx,
|
|
753
751
|
quoteBufferBps,
|
|
754
752
|
quoter,
|
|
755
753
|
useV2Ixs,
|
|
756
754
|
withdrawSlotOffset,
|
|
755
|
+
userSolBalanceLamports,
|
|
757
756
|
}: AdjustLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
758
757
|
swapInputs: SwapInputs;
|
|
759
758
|
flashLoanInfo: FlashLoanInfo;
|
|
@@ -788,7 +787,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
788
787
|
}
|
|
789
788
|
|
|
790
789
|
if (isDeposit) {
|
|
791
|
-
const calcs =
|
|
790
|
+
const calcs = adjustDepositLeverageCalcs(
|
|
792
791
|
debtReserve!,
|
|
793
792
|
adjustDepositPosition,
|
|
794
793
|
adjustBorrowPosition,
|
|
@@ -808,7 +807,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
808
807
|
referrer,
|
|
809
808
|
currentSlot,
|
|
810
809
|
calcs,
|
|
811
|
-
|
|
810
|
+
scopeRefreshIx,
|
|
812
811
|
[
|
|
813
812
|
{
|
|
814
813
|
preActionIxs: [],
|
|
@@ -848,7 +847,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
848
847
|
flashLoanFee: new Decimal(flashLoanFee),
|
|
849
848
|
});
|
|
850
849
|
|
|
851
|
-
const calcsQuotePrice =
|
|
850
|
+
const calcsQuotePrice = adjustDepositLeverageCalcs(
|
|
852
851
|
debtReserve,
|
|
853
852
|
adjustDepositPositionQuotePrice,
|
|
854
853
|
adjustBorrowPositionQuotePrice,
|
|
@@ -889,7 +888,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
889
888
|
referrer,
|
|
890
889
|
currentSlot,
|
|
891
890
|
calcs,
|
|
892
|
-
|
|
891
|
+
scopeRefreshIx,
|
|
893
892
|
[
|
|
894
893
|
{
|
|
895
894
|
preActionIxs: [],
|
|
@@ -903,7 +902,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
903
902
|
],
|
|
904
903
|
budgetAndPriorityFeeIxs,
|
|
905
904
|
useV2Ixs,
|
|
906
|
-
withdrawSlotOffset
|
|
905
|
+
withdrawSlotOffset,
|
|
906
|
+
userSolBalanceLamports
|
|
907
907
|
)
|
|
908
908
|
)[0];
|
|
909
909
|
|
|
@@ -980,12 +980,13 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
980
980
|
priceDebtToColl,
|
|
981
981
|
slippagePct,
|
|
982
982
|
budgetAndPriorityFeeIxs,
|
|
983
|
-
|
|
983
|
+
scopeRefreshIx,
|
|
984
984
|
quoteBufferBps,
|
|
985
985
|
quoter,
|
|
986
986
|
swapper,
|
|
987
987
|
useV2Ixs,
|
|
988
988
|
withdrawSlotOffset,
|
|
989
|
+
userSolBalanceLamports,
|
|
989
990
|
}: AdjustLeverageProps<QuoteResponse>): Promise<Array<AdjustLeverageIxsResponse<QuoteResponse>>> {
|
|
990
991
|
const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
|
|
991
992
|
owner,
|
|
@@ -1002,10 +1003,11 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1002
1003
|
priceDebtToColl,
|
|
1003
1004
|
slippagePct,
|
|
1004
1005
|
budgetAndPriorityFeeIxs,
|
|
1005
|
-
|
|
1006
|
+
scopeRefreshIx,
|
|
1006
1007
|
quoteBufferBps,
|
|
1007
1008
|
quoter,
|
|
1008
1009
|
useV2Ixs,
|
|
1010
|
+
userSolBalanceLamports,
|
|
1009
1011
|
});
|
|
1010
1012
|
|
|
1011
1013
|
// leverage increased so we need to deposit and borrow more
|
|
@@ -1023,7 +1025,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1023
1025
|
referrer,
|
|
1024
1026
|
currentSlot,
|
|
1025
1027
|
initialInputs.calcs,
|
|
1026
|
-
|
|
1028
|
+
scopeRefreshIx,
|
|
1027
1029
|
swapsArray.map((swap) => {
|
|
1028
1030
|
return {
|
|
1029
1031
|
preActionIxs: [],
|
|
@@ -1062,7 +1064,7 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1062
1064
|
referrer,
|
|
1063
1065
|
currentSlot,
|
|
1064
1066
|
initialInputs.calcs,
|
|
1065
|
-
|
|
1067
|
+
scopeRefreshIx,
|
|
1066
1068
|
swapsArray.map((swap) => {
|
|
1067
1069
|
return {
|
|
1068
1070
|
preActionIxs: [],
|
|
@@ -1073,7 +1075,8 @@ export async function getAdjustLeverageIxs<QuoteResponse>({
|
|
|
1073
1075
|
}),
|
|
1074
1076
|
budgetAndPriorityFeeIxs,
|
|
1075
1077
|
useV2Ixs,
|
|
1076
|
-
withdrawSlotOffset
|
|
1078
|
+
withdrawSlotOffset,
|
|
1079
|
+
userSolBalanceLamports
|
|
1077
1080
|
);
|
|
1078
1081
|
|
|
1079
1082
|
return decreaseLeverageIxs.map((ixs, index) => {
|
|
@@ -1101,7 +1104,7 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1101
1104
|
referrer: Option<Address>,
|
|
1102
1105
|
currentSlot: Slot,
|
|
1103
1106
|
calcs: AdjustLeverageCalcsResult,
|
|
1104
|
-
|
|
1107
|
+
scopeRefreshIx: Instruction[],
|
|
1105
1108
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
1106
1109
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
1107
1110
|
useV2Ixs: boolean
|
|
@@ -1115,15 +1118,12 @@ async function buildIncreaseLeverageIxs<QuoteResponse>(
|
|
|
1115
1118
|
);
|
|
1116
1119
|
|
|
1117
1120
|
// 1. Create atas & budget txns
|
|
1118
|
-
const { budgetIxs, createAtasIxs
|
|
1121
|
+
const { budgetIxs, createAtasIxs } = await getSetupIxs(
|
|
1119
1122
|
owner,
|
|
1120
|
-
kaminoMarket,
|
|
1121
|
-
obligation,
|
|
1122
1123
|
collTokenMint,
|
|
1123
1124
|
collReserve,
|
|
1124
1125
|
debtTokenMint,
|
|
1125
1126
|
debtReserve,
|
|
1126
|
-
scopeRefreshConfig,
|
|
1127
1127
|
budgetAndPriorityFeeIxs
|
|
1128
1128
|
);
|
|
1129
1129
|
|
|
@@ -1214,11 +1214,12 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1214
1214
|
referrer: Option<Address>,
|
|
1215
1215
|
currentSlot: Slot,
|
|
1216
1216
|
calcs: AdjustLeverageCalcsResult,
|
|
1217
|
-
|
|
1217
|
+
scopeRefreshIx: Instruction[],
|
|
1218
1218
|
swapQuoteIxsArray: SwapIxs<QuoteResponse>[],
|
|
1219
1219
|
budgetAndPriorityFeeIxs: Instruction[] | undefined,
|
|
1220
1220
|
useV2Ixs: boolean,
|
|
1221
|
-
withdrawSlotOffset: number = WITHDRAW_SLOT_OFFSET
|
|
1221
|
+
withdrawSlotOffset: number = WITHDRAW_SLOT_OFFSET,
|
|
1222
|
+
userSolBalanceLamports: number
|
|
1222
1223
|
): Promise<LeverageIxsOutput[]> {
|
|
1223
1224
|
const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
|
|
1224
1225
|
const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
|
|
@@ -1229,15 +1230,12 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1229
1230
|
});
|
|
1230
1231
|
|
|
1231
1232
|
// 1. Create atas & budget txns
|
|
1232
|
-
const { budgetIxs, createAtasIxs
|
|
1233
|
+
const { budgetIxs, createAtasIxs } = await getSetupIxs(
|
|
1233
1234
|
owner,
|
|
1234
|
-
kaminoMarket,
|
|
1235
|
-
obligation,
|
|
1236
1235
|
collTokenMint,
|
|
1237
1236
|
collReserve,
|
|
1238
1237
|
debtTokenMint,
|
|
1239
1238
|
debtReserve,
|
|
1240
|
-
scopeRefreshConfig,
|
|
1241
1239
|
budgetAndPriorityFeeIxs
|
|
1242
1240
|
);
|
|
1243
1241
|
|
|
@@ -1259,10 +1257,7 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1259
1257
|
)
|
|
1260
1258
|
);
|
|
1261
1259
|
|
|
1262
|
-
const halfSolBalance =
|
|
1263
|
-
Number.parseInt((await kaminoMarket.getRpc().getBalance(owner.address).send()).value.toString()) /
|
|
1264
|
-
LAMPORTS_PER_SOL /
|
|
1265
|
-
2;
|
|
1260
|
+
const halfSolBalance = userSolBalanceLamports / LAMPORTS_PER_SOL / 2;
|
|
1266
1261
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
1267
1262
|
fillWsolAtaIxs.push(
|
|
1268
1263
|
...getTransferWsolIxs(
|
|
@@ -1355,13 +1350,10 @@ async function buildDecreaseLeverageIxs<QuoteResponse>(
|
|
|
1355
1350
|
|
|
1356
1351
|
export const getSetupIxs = async (
|
|
1357
1352
|
owner: TransactionSigner,
|
|
1358
|
-
kaminoMarket: KaminoMarket,
|
|
1359
|
-
obligation: KaminoObligation | ObligationType | undefined,
|
|
1360
1353
|
collTokenMint: Address,
|
|
1361
1354
|
collReserve: KaminoReserve,
|
|
1362
1355
|
debtTokenMint: Address,
|
|
1363
1356
|
debtReserve: KaminoReserve,
|
|
1364
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1365
1357
|
budgetAndPriorityFeeIxs: Instruction[] | undefined
|
|
1366
1358
|
) => {
|
|
1367
1359
|
const budgetIxs = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(3000000);
|
|
@@ -1370,22 +1362,13 @@ export const getSetupIxs = async (
|
|
|
1370
1362
|
|
|
1371
1363
|
const createAtasIxs = (await createAtasIdempotent(owner, mintsWithTokenPrograms)).map((x) => x.createAtaIx);
|
|
1372
1364
|
|
|
1373
|
-
const scopeRefreshIx = await getScopeRefreshIx(
|
|
1374
|
-
kaminoMarket,
|
|
1375
|
-
collReserve,
|
|
1376
|
-
debtReserve,
|
|
1377
|
-
obligation,
|
|
1378
|
-
scopeRefreshConfig
|
|
1379
|
-
);
|
|
1380
|
-
|
|
1381
1365
|
return {
|
|
1382
1366
|
budgetIxs,
|
|
1383
1367
|
createAtasIxs,
|
|
1384
|
-
scopeRefreshIx,
|
|
1385
1368
|
};
|
|
1386
1369
|
};
|
|
1387
1370
|
|
|
1388
|
-
export const
|
|
1371
|
+
export const getScopeRefreshIxForObligationAndReserves = async (
|
|
1389
1372
|
market: KaminoMarket,
|
|
1390
1373
|
collReserve: KaminoReserve,
|
|
1391
1374
|
debtReserve: KaminoReserve,
|
package/src/leverage/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Account, Address, Instruction, Option, Slot, TransactionSigner } from '@solana/kit';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
4
|
-
import { ObligationType, ObligationTypeTag
|
|
4
|
+
import { ObligationType, ObligationTypeTag } from '../utils';
|
|
5
5
|
import { AddressLookupTable } from '@solana-program/address-lookup-table';
|
|
6
6
|
|
|
7
7
|
export type SwapQuoteProvider<QuoteResponse> = (
|
|
@@ -71,7 +71,7 @@ export interface BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
|
71
71
|
currentSlot: Slot;
|
|
72
72
|
slippagePct: Decimal;
|
|
73
73
|
budgetAndPriorityFeeIxs?: Instruction[];
|
|
74
|
-
|
|
74
|
+
scopeRefreshIx: Instruction[]; // no longer optional as we always pass an array (can be empty)
|
|
75
75
|
quoteBufferBps: Decimal;
|
|
76
76
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
77
77
|
useV2Ixs: boolean;
|
|
@@ -134,6 +134,7 @@ export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> extends Base
|
|
|
134
134
|
priceCollToDebt: Decimal;
|
|
135
135
|
isClosingPosition: boolean;
|
|
136
136
|
selectedTokenMint: Address;
|
|
137
|
+
userSolBalanceLamports: number;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
export interface WithdrawWithLeverageProps<QuoteResponse> extends WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -171,6 +172,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLevera
|
|
|
171
172
|
priceCollToDebt: Decimal;
|
|
172
173
|
priceDebtToColl: Decimal;
|
|
173
174
|
withdrawSlotOffset?: number;
|
|
175
|
+
userSolBalanceLamports: number;
|
|
174
176
|
}
|
|
175
177
|
|
|
176
178
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -76,7 +76,7 @@ export class ManagerEnv {
|
|
|
76
76
|
if (useVaultPendingAdmin) {
|
|
77
77
|
return matchesAdmin(this.signerConfig, vaultState.pendingAdmin)
|
|
78
78
|
? this.signerConfig.admin!
|
|
79
|
-
: noopSigner(vaultState.
|
|
79
|
+
: noopSigner(vaultState.pendingAdmin);
|
|
80
80
|
} else {
|
|
81
81
|
return matchesAdmin(this.signerConfig, vaultState.vaultAdminAuthority)
|
|
82
82
|
? this.signerConfig.admin!
|
|
@@ -78,6 +78,7 @@ export const getUserLutAddressAndSetupIxs = async (
|
|
|
78
78
|
);
|
|
79
79
|
} else {
|
|
80
80
|
userLookupTableAddress = userMetadataState.userLookupTable;
|
|
81
|
+
referrer = userMetadataState.referrer === DEFAULT_PUBLIC_KEY ? none() : some(userMetadataState.referrer);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
const setupUserMetadataIxs = [initUserMetadataIxs];
|