@kamino-finance/klend-sdk 5.10.33 → 5.10.35-beta.0
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 +33 -26
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +614 -202
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +4 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +13 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +2 -1
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types.d.ts +4 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +4 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +39 -26
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +8 -3
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +269 -156
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +8 -1
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +51 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +89 -5
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +24 -3
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +12 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +15 -8
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +7 -6
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -5
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -8
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +46 -37
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +1 -3
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +5 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +10 -1
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +8 -10
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +6 -3
- package/src/classes/action.ts +789 -214
- package/src/classes/manager.ts +18 -4
- package/src/classes/reserve.ts +2 -0
- package/src/classes/types.ts +5 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +49 -37
- package/src/client.ts +7 -3
- package/src/client_kamino_manager.ts +10 -3
- package/src/idl.json +269 -156
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +103 -4
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +33 -3
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +18 -7
- package/src/lending_operations/repay_with_collateral_operations.ts +12 -3
- package/src/lending_operations/swap_collateral_operations.ts +17 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +66 -29
- package/src/leverage/types.ts +4 -1
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/instruction.ts +1 -3
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +21 -26
|
@@ -17,11 +17,10 @@ import {
|
|
|
17
17
|
ObligationTypeTag,
|
|
18
18
|
SOL_DECIMALS,
|
|
19
19
|
U64_MAX,
|
|
20
|
-
WRAPPED_SOL_MINT,
|
|
21
20
|
createAtasIdempotent,
|
|
22
21
|
getAssociatedTokenAddress,
|
|
23
22
|
getComputeBudgetAndPriorityFeeIxns,
|
|
24
|
-
|
|
23
|
+
getTransferWsolIxns,
|
|
25
24
|
getLookupTableAccount,
|
|
26
25
|
removeBudgetAndAtaIxns,
|
|
27
26
|
uniqueAccounts,
|
|
@@ -35,7 +34,12 @@ import {
|
|
|
35
34
|
toJson,
|
|
36
35
|
withdrawLeverageCalcs,
|
|
37
36
|
} from './calcs';
|
|
38
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
NATIVE_MINT,
|
|
39
|
+
TOKEN_PROGRAM_ID,
|
|
40
|
+
createCloseAccountInstruction,
|
|
41
|
+
getAssociatedTokenAddressSync,
|
|
42
|
+
} from '@solana/spl-token';
|
|
39
43
|
import { Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
40
44
|
import { getExpectedTokenBalanceAfterBorrow, getKtokenToTokenSwapper, getTokenToKtokenSwapper } from './utils';
|
|
41
45
|
import { FullBPS } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
@@ -49,7 +53,7 @@ import {
|
|
|
49
53
|
DepositLeverageInitialInputs,
|
|
50
54
|
DepositWithLeverageProps,
|
|
51
55
|
DepositWithLeverageSwapInputsProps,
|
|
52
|
-
|
|
56
|
+
DepositLeverageIxsResponse,
|
|
53
57
|
PriceAinBProvider,
|
|
54
58
|
SwapInputs,
|
|
55
59
|
SwapIxs,
|
|
@@ -82,6 +86,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
82
86
|
priceAinB,
|
|
83
87
|
isKtoken,
|
|
84
88
|
quoter,
|
|
89
|
+
useV2Ixs,
|
|
85
90
|
elevationGroupOverride,
|
|
86
91
|
}: DepositWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
87
92
|
swapInputs: SwapInputs;
|
|
@@ -89,7 +94,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
89
94
|
}> {
|
|
90
95
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
|
|
91
96
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
|
|
92
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
97
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
93
98
|
const flashLoanFee = collReserve.getFlashLoanFee() || new Decimal(0);
|
|
94
99
|
|
|
95
100
|
const selectedTokenIsCollToken = selectedTokenMint.equals(collTokenMint);
|
|
@@ -147,6 +152,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
147
152
|
},
|
|
148
153
|
strategy,
|
|
149
154
|
collIsKtoken,
|
|
155
|
+
useV2Ixs,
|
|
150
156
|
elevationGroupOverride
|
|
151
157
|
);
|
|
152
158
|
|
|
@@ -191,7 +197,7 @@ export async function getDepositWithLeverageSwapInputs<QuoteResponse>({
|
|
|
191
197
|
|
|
192
198
|
if (collIsKtoken) {
|
|
193
199
|
let futureBalanceInAta = new Decimal(0);
|
|
194
|
-
if (debtTokenMint.equals(
|
|
200
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
195
201
|
futureBalanceInAta = futureBalanceInAta.add(
|
|
196
202
|
!collIsKtoken ? quotePriceCalcs.initDepositInSol : quotePriceCalcs.initDepositInSol
|
|
197
203
|
);
|
|
@@ -311,7 +317,8 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
311
317
|
quoter,
|
|
312
318
|
swapper,
|
|
313
319
|
elevationGroupOverride,
|
|
314
|
-
|
|
320
|
+
useV2Ixs,
|
|
321
|
+
}: DepositWithLeverageProps<QuoteResponse>): Promise<DepositLeverageIxsResponse<QuoteResponse>> {
|
|
315
322
|
const { swapInputs, initialInputs } = await getDepositWithLeverageSwapInputs({
|
|
316
323
|
owner,
|
|
317
324
|
kaminoMarket,
|
|
@@ -333,6 +340,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
333
340
|
priceAinB,
|
|
334
341
|
isKtoken,
|
|
335
342
|
quoter,
|
|
343
|
+
useV2Ixs,
|
|
336
344
|
});
|
|
337
345
|
|
|
338
346
|
let depositSwapper: SwapIxsProvider<QuoteResponse>;
|
|
@@ -366,7 +374,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
366
374
|
|
|
367
375
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
368
376
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
369
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
377
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
370
378
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
371
379
|
|
|
372
380
|
const ixs = await buildDepositWithLeverageIxns(
|
|
@@ -388,6 +396,7 @@ export async function getDepositWithLeverageIxns<QuoteResponse>({
|
|
|
388
396
|
},
|
|
389
397
|
initialInputs.strategy,
|
|
390
398
|
initialInputs.collIsKtoken,
|
|
399
|
+
useV2Ixs,
|
|
391
400
|
elevationGroupOverride
|
|
392
401
|
);
|
|
393
402
|
|
|
@@ -414,6 +423,7 @@ async function buildDepositWithLeverageIxns(
|
|
|
414
423
|
swapQuoteIxs: SwapIxs,
|
|
415
424
|
strategy: StrategyWithAddress | undefined,
|
|
416
425
|
collIsKtoken: boolean,
|
|
426
|
+
useV2Ixs: boolean,
|
|
417
427
|
elevationGroupOverride?: number
|
|
418
428
|
): Promise<TransactionInstruction[]> {
|
|
419
429
|
const budgetIxns = budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxns(3000000);
|
|
@@ -485,9 +495,9 @@ async function buildDepositWithLeverageIxns(
|
|
|
485
495
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
486
496
|
if (depositTokenIsSol) {
|
|
487
497
|
fillWsolAtaIxns.push(
|
|
488
|
-
...
|
|
498
|
+
...getTransferWsolIxns(
|
|
489
499
|
owner,
|
|
490
|
-
getAssociatedTokenAddressSync(
|
|
500
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
491
501
|
toLamports(calcs.initDepositInSol, SOL_DECIMALS).ceil()
|
|
492
502
|
)
|
|
493
503
|
);
|
|
@@ -526,10 +536,12 @@ async function buildDepositWithLeverageIxns(
|
|
|
526
536
|
debtTokenMint,
|
|
527
537
|
owner,
|
|
528
538
|
obligation!,
|
|
539
|
+
useV2Ixs,
|
|
529
540
|
0,
|
|
530
541
|
false,
|
|
531
542
|
elevationGroupOverride === 0 ? false : true, // emode
|
|
532
543
|
false, // to be checked and created in a setup tx in the UI
|
|
544
|
+
false, // to be checked and created in a setup tx in the UI
|
|
533
545
|
referrer,
|
|
534
546
|
currentSlot,
|
|
535
547
|
scopeRefresh
|
|
@@ -587,6 +599,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
587
599
|
quoteBufferBps,
|
|
588
600
|
isKtoken,
|
|
589
601
|
quoter,
|
|
602
|
+
useV2Ixs,
|
|
590
603
|
}: WithdrawWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
591
604
|
swapInputs: SwapInputs;
|
|
592
605
|
initialInputs: WithdrawLeverageInitialInputs<QuoteResponse>;
|
|
@@ -598,7 +611,7 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
598
611
|
const collIsKtoken = await isKtoken(collTokenMint);
|
|
599
612
|
const strategy = collIsKtoken ? (await kamino!.getStrategyByKTokenMint(collTokenMint))! : undefined;
|
|
600
613
|
|
|
601
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
614
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
602
615
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
603
616
|
|
|
604
617
|
const calcs = withdrawLeverageCalcs(
|
|
@@ -637,7 +650,8 @@ export async function getWithdrawWithLeverageSwapInputs<QuoteResponse>({
|
|
|
637
650
|
lookupTables: [],
|
|
638
651
|
},
|
|
639
652
|
strategy,
|
|
640
|
-
collIsKtoken
|
|
653
|
+
collIsKtoken,
|
|
654
|
+
useV2Ixs
|
|
641
655
|
);
|
|
642
656
|
|
|
643
657
|
const uniqueKlendAccounts = uniqueAccounts(klendIxs);
|
|
@@ -720,11 +734,12 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
|
|
|
720
734
|
isKtoken,
|
|
721
735
|
quoter,
|
|
722
736
|
swapper,
|
|
737
|
+
useV2Ixs,
|
|
723
738
|
}: WithdrawWithLeverageProps<QuoteResponse>): Promise<WithdrawLeverageIxsResponse<QuoteResponse>> {
|
|
724
739
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
725
740
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
726
741
|
|
|
727
|
-
const solTokenReserve = kaminoMarket.getReserveByMint(
|
|
742
|
+
const solTokenReserve = kaminoMarket.getReserveByMint(NATIVE_MINT);
|
|
728
743
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve!.getLiquidityMint());
|
|
729
744
|
const { swapInputs, initialInputs } = await getWithdrawWithLeverageSwapInputs({
|
|
730
745
|
owner,
|
|
@@ -747,6 +762,7 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
|
|
|
747
762
|
quoteBufferBps,
|
|
748
763
|
isKtoken,
|
|
749
764
|
quoter,
|
|
765
|
+
useV2Ixs,
|
|
750
766
|
});
|
|
751
767
|
|
|
752
768
|
let withdrawSwapper: SwapIxsProvider<QuoteResponse>;
|
|
@@ -797,7 +813,8 @@ export async function getWithdrawWithLeverageIxns<QuoteResponse>({
|
|
|
797
813
|
lookupTables,
|
|
798
814
|
},
|
|
799
815
|
initialInputs.strategy,
|
|
800
|
-
initialInputs.collIsKtoken
|
|
816
|
+
initialInputs.collIsKtoken,
|
|
817
|
+
useV2Ixs
|
|
801
818
|
);
|
|
802
819
|
|
|
803
820
|
// Send ixns and lookup tables
|
|
@@ -824,7 +841,8 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
824
841
|
budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
|
|
825
842
|
swapQuoteIxs: SwapIxs,
|
|
826
843
|
strategy: StrategyWithAddress | undefined,
|
|
827
|
-
collIsKtoken: boolean
|
|
844
|
+
collIsKtoken: boolean,
|
|
845
|
+
useV2Ixs: boolean
|
|
828
846
|
): Promise<TransactionInstruction[]> {
|
|
829
847
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
830
848
|
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
@@ -885,8 +903,8 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
885
903
|
const atasAndCreateIxns = createAtasIdempotent(owner, mintsToCreateAtas);
|
|
886
904
|
|
|
887
905
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
888
|
-
if (depositTokenIsSol || debtTokenMint.equals(
|
|
889
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
906
|
+
if (depositTokenIsSol || debtTokenMint.equals(NATIVE_MINT)) {
|
|
907
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
890
908
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
891
909
|
}
|
|
892
910
|
|
|
@@ -895,13 +913,13 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
895
913
|
// TODO: Might be worth removing as it's only needed for Ktokens
|
|
896
914
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
897
915
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
898
|
-
if (debtTokenMint.equals(
|
|
916
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
899
917
|
const halfSolBalance = (await market.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
900
918
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
901
919
|
fillWsolAtaIxns.push(
|
|
902
|
-
...
|
|
920
|
+
...getTransferWsolIxns(
|
|
903
921
|
owner,
|
|
904
|
-
getAssociatedTokenAddressSync(
|
|
922
|
+
getAssociatedTokenAddressSync(NATIVE_MINT, owner),
|
|
905
923
|
toLamports(balanceToWrap, SOL_DECIMALS).ceil()
|
|
906
924
|
)
|
|
907
925
|
);
|
|
@@ -936,9 +954,11 @@ export async function buildWithdrawWithLeverageIxns(
|
|
|
936
954
|
owner,
|
|
937
955
|
currentSlot,
|
|
938
956
|
obligation,
|
|
957
|
+
useV2Ixs,
|
|
939
958
|
0,
|
|
940
959
|
false,
|
|
941
960
|
false, // 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)
|
|
961
|
+
false, // 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)
|
|
942
962
|
isClosingPosition,
|
|
943
963
|
referrer,
|
|
944
964
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -980,6 +1000,7 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
980
1000
|
quoteBufferBps,
|
|
981
1001
|
isKtoken,
|
|
982
1002
|
quoter,
|
|
1003
|
+
useV2Ixs,
|
|
983
1004
|
}: AdjustLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
984
1005
|
swapInputs: SwapInputs;
|
|
985
1006
|
initialInputs: AdjustLeverageInitialInputs<QuoteResponse>;
|
|
@@ -1045,7 +1066,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1045
1066
|
swapIxs: [],
|
|
1046
1067
|
lookupTables: [],
|
|
1047
1068
|
},
|
|
1048
|
-
budgetAndPriorityFeeIxs
|
|
1069
|
+
budgetAndPriorityFeeIxs,
|
|
1070
|
+
useV2Ixs
|
|
1049
1071
|
);
|
|
1050
1072
|
|
|
1051
1073
|
const uniqueKlendAccounts = uniqueAccounts(klendIxs);
|
|
@@ -1148,7 +1170,8 @@ export async function getAdjustLeverageSwapInputs<QuoteResponse>({
|
|
|
1148
1170
|
swapIxs: [],
|
|
1149
1171
|
lookupTables: [],
|
|
1150
1172
|
},
|
|
1151
|
-
budgetAndPriorityFeeIxs
|
|
1173
|
+
budgetAndPriorityFeeIxs,
|
|
1174
|
+
useV2Ixs
|
|
1152
1175
|
);
|
|
1153
1176
|
|
|
1154
1177
|
const uniqueKlendAccounts = uniqueAccounts(klendIxs);
|
|
@@ -1234,6 +1257,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
|
|
|
1234
1257
|
isKtoken,
|
|
1235
1258
|
quoter,
|
|
1236
1259
|
swapper,
|
|
1260
|
+
useV2Ixs,
|
|
1237
1261
|
}: AdjustLeverageProps<QuoteResponse>): Promise<AdjustLeverageIxsResponse<QuoteResponse>> {
|
|
1238
1262
|
const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
|
|
1239
1263
|
owner,
|
|
@@ -1256,6 +1280,7 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
|
|
|
1256
1280
|
priceAinB,
|
|
1257
1281
|
isKtoken,
|
|
1258
1282
|
quoter,
|
|
1283
|
+
useV2Ixs,
|
|
1259
1284
|
});
|
|
1260
1285
|
|
|
1261
1286
|
// leverage increased so we need to deposit and borrow more
|
|
@@ -1303,7 +1328,8 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
|
|
|
1303
1328
|
swapIxs,
|
|
1304
1329
|
lookupTables,
|
|
1305
1330
|
},
|
|
1306
|
-
budgetAndPriorityFeeIxs
|
|
1331
|
+
budgetAndPriorityFeeIxs,
|
|
1332
|
+
useV2Ixs
|
|
1307
1333
|
);
|
|
1308
1334
|
return {
|
|
1309
1335
|
ixs,
|
|
@@ -1349,7 +1375,8 @@ export async function getAdjustLeverageIxns<QuoteResponse>({
|
|
|
1349
1375
|
swapIxs,
|
|
1350
1376
|
lookupTables,
|
|
1351
1377
|
},
|
|
1352
|
-
budgetAndPriorityFeeIxs
|
|
1378
|
+
budgetAndPriorityFeeIxs,
|
|
1379
|
+
useV2Ixs
|
|
1353
1380
|
);
|
|
1354
1381
|
|
|
1355
1382
|
return {
|
|
@@ -1377,7 +1404,8 @@ async function buildIncreaseLeverageIxns(
|
|
|
1377
1404
|
scopeFeed: string | undefined,
|
|
1378
1405
|
collIsKtoken: boolean,
|
|
1379
1406
|
swapQuoteIxs: SwapIxs,
|
|
1380
|
-
budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined
|
|
1407
|
+
budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
|
|
1408
|
+
useV2Ixs: boolean
|
|
1381
1409
|
): Promise<TransactionInstruction[]> {
|
|
1382
1410
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
1383
1411
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
@@ -1469,10 +1497,12 @@ async function buildIncreaseLeverageIxns(
|
|
|
1469
1497
|
collTokenMint,
|
|
1470
1498
|
owner,
|
|
1471
1499
|
obligation,
|
|
1500
|
+
useV2Ixs,
|
|
1472
1501
|
0,
|
|
1473
1502
|
false,
|
|
1474
1503
|
false,
|
|
1475
1504
|
false, // 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)
|
|
1505
|
+
false, // 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)
|
|
1476
1506
|
referrer,
|
|
1477
1507
|
currentSlot,
|
|
1478
1508
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1485,10 +1515,12 @@ async function buildIncreaseLeverageIxns(
|
|
|
1485
1515
|
debtTokenMint,
|
|
1486
1516
|
owner,
|
|
1487
1517
|
obligation,
|
|
1518
|
+
useV2Ixs,
|
|
1488
1519
|
0,
|
|
1489
1520
|
false,
|
|
1490
1521
|
false,
|
|
1491
1522
|
false, // 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)
|
|
1523
|
+
false, // 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)
|
|
1492
1524
|
referrer,
|
|
1493
1525
|
currentSlot,
|
|
1494
1526
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
|
@@ -1543,7 +1575,8 @@ async function buildDecreaseLeverageIxns(
|
|
|
1543
1575
|
scopeFeed: string | undefined,
|
|
1544
1576
|
collIsKtoken: boolean,
|
|
1545
1577
|
swapQuoteIxs: SwapIxs,
|
|
1546
|
-
budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined
|
|
1578
|
+
budgetAndPriorityFeeIxns: TransactionInstruction[] | undefined,
|
|
1579
|
+
useV2Ixs: boolean
|
|
1547
1580
|
): Promise<TransactionInstruction[]> {
|
|
1548
1581
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
1549
1582
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
@@ -1608,15 +1641,15 @@ async function buildDecreaseLeverageIxns(
|
|
|
1608
1641
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
1609
1642
|
const closeWsolAtaIxns: TransactionInstruction[] = [];
|
|
1610
1643
|
const fillWsolAtaIxns: TransactionInstruction[] = [];
|
|
1611
|
-
if (debtTokenMint.equals(
|
|
1612
|
-
const wsolAta = getAssociatedTokenAddress(
|
|
1644
|
+
if (debtTokenMint.equals(NATIVE_MINT)) {
|
|
1645
|
+
const wsolAta = getAssociatedTokenAddress(NATIVE_MINT, owner, false);
|
|
1613
1646
|
|
|
1614
1647
|
closeWsolAtaIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
|
|
1615
1648
|
|
|
1616
1649
|
const halfSolBalance = (await kaminoMarket.getConnection().getBalance(owner)) / LAMPORTS_PER_SOL / 2;
|
|
1617
1650
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
1618
1651
|
fillWsolAtaIxns.push(
|
|
1619
|
-
...
|
|
1652
|
+
...getTransferWsolIxns(owner, wsolAta, toLamports(balanceToWrap, debtReserve!.stats.decimals).ceil())
|
|
1620
1653
|
);
|
|
1621
1654
|
}
|
|
1622
1655
|
|
|
@@ -1643,12 +1676,14 @@ async function buildDecreaseLeverageIxns(
|
|
|
1643
1676
|
debtTokenMint,
|
|
1644
1677
|
owner,
|
|
1645
1678
|
obligation,
|
|
1679
|
+
useV2Ixs,
|
|
1646
1680
|
currentSlot,
|
|
1647
1681
|
undefined,
|
|
1648
1682
|
0,
|
|
1649
1683
|
false,
|
|
1650
1684
|
false,
|
|
1651
1685
|
false, // 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)
|
|
1686
|
+
false, // 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)
|
|
1652
1687
|
referrer,
|
|
1653
1688
|
scopeRefresh
|
|
1654
1689
|
);
|
|
@@ -1660,10 +1695,12 @@ async function buildDecreaseLeverageIxns(
|
|
|
1660
1695
|
collTokenMint,
|
|
1661
1696
|
owner,
|
|
1662
1697
|
obligation,
|
|
1698
|
+
useV2Ixs,
|
|
1663
1699
|
0,
|
|
1664
1700
|
false,
|
|
1665
1701
|
false,
|
|
1666
1702
|
false, // 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)
|
|
1703
|
+
false, // 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)
|
|
1667
1704
|
referrer,
|
|
1668
1705
|
currentSlot,
|
|
1669
1706
|
{ includeScopeRefresh: true, scopeFeed: scopeFeed! }
|
package/src/leverage/types.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type KaminoDepositSwapOverride = (
|
|
|
49
49
|
amountDebtAtaBalance: Decimal
|
|
50
50
|
) => Promise<InstructionsWithLookupTables>;
|
|
51
51
|
|
|
52
|
-
export type
|
|
52
|
+
export type DepositLeverageIxsResponse<QuoteResponse> = {
|
|
53
53
|
ixs: TransactionInstruction[];
|
|
54
54
|
lookupTables: AddressLookupTableAccount[];
|
|
55
55
|
swapInputs: SwapInputs;
|
|
@@ -90,6 +90,7 @@ export interface DepositWithLeverageSwapInputsProps<QuoteResponse> {
|
|
|
90
90
|
// currently only used to disable requesting elevation group when this value is 0
|
|
91
91
|
// to be implemented properly in the future
|
|
92
92
|
elevationGroupOverride?: number;
|
|
93
|
+
useV2Ixs: boolean;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
export interface DepositWithLeverageProps<QuoteResponse> extends DepositWithLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -146,6 +147,7 @@ export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
|
146
147
|
quoteBufferBps: Decimal;
|
|
147
148
|
isKtoken: IsKtokenProvider;
|
|
148
149
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
150
|
+
useV2Ixs: boolean;
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
export interface WithdrawWithLeverageProps<QuoteResponse> extends WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -199,6 +201,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
|
199
201
|
priceAinB: PriceAinBProvider;
|
|
200
202
|
isKtoken: IsKtokenProvider;
|
|
201
203
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
204
|
+
useV2Ixs: boolean;
|
|
202
205
|
}
|
|
203
206
|
|
|
204
207
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
package/src/utils/ata.ts
CHANGED
|
@@ -98,7 +98,7 @@ export function createAtasIdempotent(
|
|
|
98
98
|
return res;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export function
|
|
101
|
+
export function getTransferWsolIxns(owner: PublicKey, ata: PublicKey, amountLamports: Decimal) {
|
|
102
102
|
const ixns: TransactionInstruction[] = [];
|
|
103
103
|
|
|
104
104
|
ixns.push(
|
package/src/utils/constants.ts
CHANGED
|
@@ -72,22 +72,16 @@ export const SLOTS_PER_YEAR = SLOTS_PER_DAY * 365;
|
|
|
72
72
|
*/
|
|
73
73
|
export const MIN_AUTODELEVERAGE_BONUS_BPS = 50;
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* WSOL Mint
|
|
77
|
-
*/
|
|
78
|
-
export const WRAPPED_SOL_MINT = new PublicKey('So11111111111111111111111111111111111111112');
|
|
79
|
-
|
|
80
75
|
export const SOL_DECIMALS = 9;
|
|
81
76
|
|
|
82
|
-
/**
|
|
83
|
-
* USDC Mint
|
|
84
|
-
*/
|
|
85
|
-
export const USDC_MAINNET_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
86
|
-
|
|
87
77
|
export const MAINNET_BETA_CHAIN_ID = 101;
|
|
88
78
|
|
|
89
|
-
export const POSITION_LIMIT = 10;
|
|
90
79
|
export const BORROWS_LIMIT = 5;
|
|
91
80
|
export const DEPOSITS_LIMIT = 8;
|
|
92
81
|
|
|
93
82
|
export const DEFAULT_MAX_COMPUTE_UNITS = 1_400_000;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Minimum initial deposit required for the initialization of a reserve
|
|
86
|
+
*/
|
|
87
|
+
export const MIN_INITIAL_DEPOSIT = 100_000;
|
package/src/utils/instruction.ts
CHANGED
|
@@ -38,7 +38,7 @@ export async function buildAndSendTxnWithLogs(
|
|
|
38
38
|
});
|
|
39
39
|
console.log('Transaction Hash:', withDescription, sig);
|
|
40
40
|
if (withLogsIfSuccess) {
|
|
41
|
-
await sleep(
|
|
41
|
+
await sleep(1000);
|
|
42
42
|
const res = await c.getTransaction(sig, {
|
|
43
43
|
commitment: 'confirmed',
|
|
44
44
|
maxSupportedTransactionVersion: 6,
|
|
@@ -49,7 +49,6 @@ export async function buildAndSendTxnWithLogs(
|
|
|
49
49
|
} catch (e: any) {
|
|
50
50
|
console.log(e);
|
|
51
51
|
process.stdout.write(e.logs.toString());
|
|
52
|
-
await sleep(5000);
|
|
53
52
|
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
54
53
|
const res: VersionedTransactionResponse | null = await c.getTransaction(sig, {
|
|
55
54
|
commitment: 'confirmed',
|
|
@@ -115,7 +114,6 @@ export async function simulateTxn(c: Connection, tx: Transaction, owner: Keypair
|
|
|
115
114
|
} catch (e: any) {
|
|
116
115
|
console.log(e);
|
|
117
116
|
process.stdout.write(e.logs.toString());
|
|
118
|
-
await sleep(5000);
|
|
119
117
|
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
120
118
|
const res: TransactionResponse | null = await c.getTransaction(sig, {
|
|
121
119
|
commitment: 'confirmed',
|
package/src/utils/seeds.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
3
|
+
import { farmsId } from '@kamino-finance/farms-sdk';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Lending market authority seed
|
|
@@ -38,6 +39,11 @@ export const BASE_SEED_REFERRER_STATE = 'ref_state';
|
|
|
38
39
|
*/
|
|
39
40
|
export const BASE_SEED_SHORT_URL = 'short_url';
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* User farm state seed
|
|
44
|
+
*/
|
|
45
|
+
export const BASE_SEED_FARM_USER_STATE = Buffer.from('user');
|
|
46
|
+
|
|
41
47
|
/**
|
|
42
48
|
* Encapsulates all the PDAs for a given reserve
|
|
43
49
|
*/
|
|
@@ -181,3 +187,10 @@ export function referrerStatePda(referrer: PublicKey, programId: PublicKey = PRO
|
|
|
181
187
|
export function shortUrlPda(shortUrl: string, programId: PublicKey = PROGRAM_ID) {
|
|
182
188
|
return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_SHORT_URL), Buffer.from(shortUrl)], programId);
|
|
183
189
|
}
|
|
190
|
+
|
|
191
|
+
export function obligationFarmStatePda(obligation: PublicKey, farm: PublicKey, programId: PublicKey = farmsId) {
|
|
192
|
+
return PublicKey.findProgramAddressSync(
|
|
193
|
+
[Buffer.from(BASE_SEED_FARM_USER_STATE), farm.toBuffer(), obligation.toBuffer()],
|
|
194
|
+
programId
|
|
195
|
+
);
|
|
196
|
+
}
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
Connection,
|
|
7
7
|
GetProgramAccountsFilter,
|
|
8
8
|
} from '@solana/web3.js';
|
|
9
|
+
import { NATIVE_MINT } from '@solana/spl-token';
|
|
9
10
|
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
10
11
|
import {
|
|
11
12
|
LeverageObligation,
|
|
12
13
|
MultiplyObligation,
|
|
13
|
-
WRAPPED_SOL_MINT,
|
|
14
14
|
createLookupTableIx,
|
|
15
15
|
extendLookupTableIxs,
|
|
16
16
|
getAssociatedTokenAddress,
|
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
isNotNullPubkey,
|
|
21
21
|
UserMetadata,
|
|
22
22
|
PublicKeySet,
|
|
23
|
+
obligationFarmStatePda,
|
|
23
24
|
} from '../lib';
|
|
24
|
-
import { farmsId } from '@kamino-finance/farms-sdk';
|
|
25
25
|
import { KaminoReserve } from '../classes/reserve';
|
|
26
26
|
|
|
27
27
|
export type KaminoUserMetadata = {
|
|
@@ -259,26 +259,26 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
|
|
|
259
259
|
const collMintString = collMint.toString();
|
|
260
260
|
const debtMintString = debtMint.toString();
|
|
261
261
|
if (collReserve && debtReserve) {
|
|
262
|
-
const multiplyObligation = new MultiplyObligation(collMint,
|
|
262
|
+
const multiplyObligation = new MultiplyObligation(collMint, NATIVE_MINT, kaminoMarket.programId);
|
|
263
263
|
obligationPdas.push({
|
|
264
264
|
address: multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
265
265
|
log: 'multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
266
266
|
});
|
|
267
267
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
268
268
|
farmUserStates.push({
|
|
269
|
-
address:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
),
|
|
269
|
+
address: obligationFarmStatePda(
|
|
270
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
271
|
+
collReserve.state.farmCollateral!
|
|
272
|
+
)[0],
|
|
273
273
|
log: 'collReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
277
277
|
farmUserStates.push({
|
|
278
|
-
address:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
),
|
|
278
|
+
address: obligationFarmStatePda(
|
|
279
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
280
|
+
debtReserve.state.farmDebt!
|
|
281
|
+
)[0],
|
|
282
282
|
log: 'debtReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
283
283
|
});
|
|
284
284
|
}
|
|
@@ -309,19 +309,19 @@ function getLeverageObligationAndObligationFarmStateAddresses(
|
|
|
309
309
|
});
|
|
310
310
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
311
311
|
farmUserStates.push({
|
|
312
|
-
address:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
),
|
|
312
|
+
address: obligationFarmStatePda(
|
|
313
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user),
|
|
314
|
+
collReserve.state.farmCollateral!
|
|
315
|
+
)[0],
|
|
316
316
|
log: 'collReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
319
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
320
320
|
farmUserStates.push({
|
|
321
|
-
address:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
),
|
|
321
|
+
address: obligationFarmStatePda(
|
|
322
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user),
|
|
323
|
+
debtReserve.state.farmDebt!
|
|
324
|
+
)[0],
|
|
325
325
|
log: 'debtReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
326
326
|
});
|
|
327
327
|
}
|
|
@@ -342,7 +342,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
342
342
|
const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
|
|
343
343
|
if (!borrowReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
344
344
|
farmUserStates.push({
|
|
345
|
-
address:
|
|
345
|
+
address: obligationFarmStatePda(obligation.obligationAddress, borrowReserve.state.farmDebt!)[0],
|
|
346
346
|
log: 'debtReserve farmState for vanilla obligation: ' + obligationString,
|
|
347
347
|
});
|
|
348
348
|
}
|
|
@@ -352,7 +352,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
352
352
|
const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
|
|
353
353
|
if (!depositReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
354
354
|
farmUserStates.push({
|
|
355
|
-
address:
|
|
355
|
+
address: obligationFarmStatePda(obligation.obligationAddress, depositReserve.state.farmCollateral!)[0],
|
|
356
356
|
log: 'collReserve farmState for vanilla obligation' + obligationString,
|
|
357
357
|
});
|
|
358
358
|
}
|
|
@@ -361,11 +361,6 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
361
361
|
return farmUserStates;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
365
|
-
|
|
366
|
-
const getPdaFarmsUserState = (farm: PublicKey, obligation: PublicKey) =>
|
|
367
|
-
PublicKey.findProgramAddressSync([BASE_SEED_USER_STATE, farm.toBytes(), obligation.toBytes()], farmsId)[0];
|
|
368
|
-
|
|
369
364
|
export async function getAllUserMetadatasWithFilter(
|
|
370
365
|
connection: Connection,
|
|
371
366
|
filter: GetProgramAccountsFilter[],
|